enhance(ai): make it.contextType() discoverable to the rule agent - #760
Merged
Conversation
AI-authored rules for custom frameworks probed the context kind with
Groovy meta-programming (`it.respondsTo('containingClass')`) instead
of the built-in discriminator, producing non-idiomatic rules that
would break silently if a class context ever grew a method named
containingClass().
Root cause: the official discriminator was invisible to the model —
contextType() appeared only as a bare signature among 100+ reflected
methods, the system prompt never mentioned it, and nothing warned
against respondsTo().
Solution: get_rule_context now states the discriminator in the it
binding description whenever a key accepts several context kinds
("Discriminate with it.contextType(), which returns 'class'/
'method'/…"); the agent prompt documents contextType() in the
class-identity section; and the proposal validator emits a soft
warning on respondsTo( suggesting contextType().
Impact: generated rules become idiomatic and robust; existing
proposals only gain a soft warning and are never blocked. The
ScriptMethodApi description field from the issue's longer-term item
is deliberately not included.
Fixes: #756
Contributor
|
📦 Plugin has been packaged for this PR. You can download |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #760 +/- ##
=============================================
+ Coverage 66.795% 66.821% +0.026%
=============================================
Files 442 442
Lines 25936 25947 +11
Branches 6191 6193 +2
=============================================
+ Hits 17324 17338 +14
+ Misses 6291 6289 -2
+ Partials 2321 2320 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the three concrete changes requested in #756 so the AI rule-authoring agent uses the built-in
it.contextType()discriminator instead of Groovy MOP probing:RuleScriptContextCatalog— when a binding can hold more than one context kind (e.g.custom.method.is.apiruns withitas a class or a method), its description now states the discriminator explicitly: "Discriminate with it.contextType(), which returns 'method'/'class'." The values are derived from a newItKind.contextTypeproperty that mirrors theScriptItContexthierarchy ("unknown"for empty contexts,"param"for parameters).agent-base.md— the "Class identity in Groovy is context-sensitive" section now documentscontextType()and its return values, and tells the model not to probe the method surface withrespondsTo('containingClass').RuleProposalValidator— new soft warning (never blocks) when a proposal usesrespondsTo(, suggestingit.contextType()instead. Shares the line-mapping helper with the existingname()warning.The issue's longer-term item (a
descriptionfield onScriptMethodApi/ few-shot examples of built-in extension scripts) is deliberately out of scope.Fixes #756
Testing
RuleScriptContextCatalogTest— 3 new cases: multi-kinditbinding carries the hint with correct runtime values; single-kind binding carries none;custom.method.*keys state'method'/'class'.RuleProposalValidatorTest— 4 new cases: inlinerespondsTo(warns;respondsTo(inside a groovy value-block warns with the right line number;respondsTo(in a comment does not warn; a cleancontextType()rule does not warn.AgentBaseCatalogIdGuardTest,RuleAuthoringKnowledgeSemanticsTest,PerceptionToolsTest,RuleProposalValidatorDisabledSourceTest,CustomRuleKeysTestall green.Risks / rollback