Skip to content

Tie SchemaRule's imperative and prose forms together with parity tests (closes #2629) - #3251

Merged
malibio merged 2 commits into
mainfrom
issue-2629-skill-rule-parity
Sep 28, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-2629-skill-rule-parity

Conversation

@malibio

@malibio malibio commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #2629.

The issue described three untied copies per schema rule (imperative, prose, cli.md). One link is already covered on current main: cli.md's schema-rules section sits inside <!-- BEGIN GENERATED: schema-rules --> and is rendered verbatim from prose, and checked_in_skill_md_is_up_to_date guards it. The pair that remained untied is imperative ↔ prose.

A single shared source doesn't fit that pair, because the two forms differ on purpose: they name different surface verbs (update_schema vs schema update), and some rules diverge by design (ADD_ENUM_VALUES documents why). So this adds a parity test:

  • SchemaRule::anchors: each rule lists its load-bearing names, values and phrases. schema_rule_forms_share_their_anchors asserts every anchor appears (case-insensitively) in both forms. On failure it names the rule, the form and the missing anchor.
  • schema_rule_forms_share_their_json_examples: every JSON object embedded in either form is parsed, so spacing differences don't count, and the two forms must show the same set. delete-a-schema is exempt (PROSE_ONLY_EXAMPLES) because its prose walks through complete CLI commands the imperative form has no counterpart for.
  • EXTENDS_SCHEMA_COMPOSITION's imperative example elided coreValues as [...], which is not valid JSON and did not match the prose example. It now carries the same concrete values. The stage2_candidate_block golden was regenerated for that one line.

InteractionRule is left as is: its prose isn't rendered anywhere, and skill_md_key_phrase already ties it to SKILL.md.

Test plan

  • New tests pass
  • Mutation check: dropping cannot nest from GROUPING's imperative fails the anchor test with grouping-is-collections: imperative is missing "cannot nest", and restoring [...] in EXTENDS fails the example test
  • bun run test:changed passes

🤖 Generated with Claude Code

@malibio

malibio commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #3251

Review Type: Initial Review (no prior reviews or comments on the PR)

Summary

A small change that clearly improves things. Before this PR, nothing in CI tied the two hand-written forms of a SchemaRule together. Now per-rule anchors and a JSON-example comparison do, and both tests fail with messages that say exactly what to fix. The PR's framing holds up. The schema-rules region of packages/skill/references/cli.md (lines 398–503) is generated from prose by gen_skill_md.rs (the regions() entry has file: "references/cli.md"). checked_in_skill_md_is_up_to_date runs gen_skill_md --check across every region, so the third copy the issue worried about is no longer hand-written. Reusing tools::extract_json_object rather than writing a second brace-matcher is good DRY. The EXTENDS_SCHEMA_COMPOSITION fix (replacing [...] with concrete coreValues) also fixes a real problem: the example the in-app agent sees is now valid JSON it can copy. All 10 skill_rules tests pass locally.

Requirements Check (#2629)

  • ✅ A mechanism ties imperative ↔ prose: the anchor test plus the JSON-example test
  • ✅ prose ↔ cli.md is already tied: the region is generated and held by gen_skill_md --check / checked_in_skill_md_is_up_to_date (verified)
  • ✅ The concrete case the issue names (GROUPING_IS_COLLECTIONS) is covered by 19 anchors
  • ✅ A future wording fix in one form that drops a fact or changes an example fails a test
  • ⚠️ Content that exists in only one form has no tie at all. This is inherent to the approach and noted below, not a blocker

Code Review Findings

🟡 The PROSE_ONLY_EXAMPLES exemption skips both directions of the check
📁 packages/agent/src/skill_rules.rs (schema_rule_forms_share_their_json_examples, the continue on PROSE_ONLY_EXAMPLES)
delete-a-schema is exempt because its prose shows 3 CLI payloads that the imperative form has no counterpart for (the imperative form has 0 today). But continue drops the check in both directions. If someone later adds a JSON example to the imperative form of that rule, nothing compares it with the prose. The exemption should cover only the fact it describes: for exempt rules, skip only the "only the prose form shows" direction and still require imperative ⊆ prose. The fix is one extra condition in the second loop. Principle: keep an exemption as narrow as its reason (least privilege, applied to test waivers).

🟡 An example that stops being valid JSON is silently dropped
📁 packages/agent/src/skill_rules.rs (json_examples, if let Ok(value @ Object(_)))
Every brace that fails to parse is skipped, so the placeholders {name} and {first_name} {last_name} are ignored, which is intended. The same path also swallows a real example that was broken, such as the [...] elision this PR just removed. That case was caught only because the other form still had the full object. If both forms elide the same way, or a single-form example (under the exemption above) breaks, the test still passes. The inner objects still get compared, so it looks like coverage. A cheap way to tell the two cases apart: a candidate that starts with {" is a wire example and must parse (assert on it), while {identifier} is a placeholder. Principle: a test should fail loudly on input it cannot interpret, not treat it as absent.

🟢 Some single-word anchors are weak signals
📁 packages/agent/src/skill_rules.rs (anchors on ENUM_EDGE_FIELDS, ADD_ENUM_VALUES, DELETE_A_SCHEMA, TARGET_TYPE_MUST_EXIST)
Matching is a case-insensitive substring search within one rule's text, so most anchors are fine. A few appear several times in each form: "default" 4/4, "label" 4/4, "enum" 3/3, "extends" 6/8, "reverseName" 7/7. Deleting the sentence that carries the fact still leaves other hits, so those anchors catch almost nothing. "child" also adds nothing next to "has_child", which contains it. Swapping these for the distinguishing phrase would sharpen them, e.g. the phrase around default in the edge-field rule. Optional, since most of these words also sit inside JSON examples that the second test already compares.

🟢 One-sided content still drifts freely (inherent, and worth knowing)
📁 RELATIONSHIP_VS_FIELD (imperative 1164 chars vs. prose 105, one anchor), SCHEMA_ALREADY_EXISTS (511 vs. 143)
The "RECOGNITION IS THE HARD PART" guidance lives only in the imperative form. External PTY agents never see it, and anchors can only tie facts that both forms share. The module doc says the divergence is deliberate, so this is not a defect in this PR. Whether external agents should get the recognition guidance is a content question for a separate pass.

🟢 Nit: test-only metadata lives on the shipped struct
📁 packages/agent/src/skill_rules.rs (SchemaRule::anchors)
anchors is read only by tests but compiles into every build. Keeping it next to the text is the right trade-off, because whoever edits a rule sees the anchors in the same place. Just noting it. No change suggested.

Project standards: no issue numbers in code comments ✅, no lint suppression ✅, the comments explain why (drift intent, the reason for the exemption) ✅, and the golden was regenerated rather than hand-edited ✅.

Recommendation

APPROVE. Both 🟡 items are small tightenings to the test harness (narrow the exemption; assert that {"-prefixed candidates parse) and fit in this PR. Neither blocks the merge.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed

✅ 🟡 Exemption scope: PROSE_ONLY_EXAMPLES now skips only the prose→imperative direction, so an example later added to delete-a-schema's imperative form is still compared.
✅ 🟢 Weak anchors: "default" is replaced by "must be one of the declared values", and "child" is dropped because has_child already contains it.
⏭️ 🟡 Must-parse {" candidates: skipped. Both forms of EXTENDS_SCHEMA_COMPOSITION deliberately show the elided rejected shape {"relationships": [{"name": "extends", ...}]}. Making every {" candidate parse would need an elision exemption, which reopens the same hole. The rationale is now documented on json_examples.
⏭️ 🟢 One-sided content / anchors visibility: no change. The review itself calls these inherent to the approach, not defects.

skill_rules tests: 10/10 pass.

Re-review: not needed. The changes are a narrowed condition in one test plus two anchor strings.

malibio and others added 2 commits September 28, 2026 19:00
closes #2629)

Each SchemaRule now declares `anchors` — the load-bearing names, values and
phrases both forms must carry — and two tests enforce that the imperative
form (in-app agent prompt) and prose form (rendered verbatim into the shipped
skill) contain every anchor and show the same JSON examples. The prose → skill
link was already held by gen_skill_md --check, so this closes the remaining
untied pair.

EXTENDS_SCHEMA_COMPOSITION's imperative example elided its coreValues as
`[...]`; it now carries the same concrete values as the prose form, so the
example is valid JSON and matches (golden regenerated).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…hors

- PROSE_ONLY_EXAMPLES now exempts only the prose->imperative direction, so an
  example added to delete-a-schema's imperative form is still checked.
- Replaced the generic "default" anchor with "must be one of the declared
  values" and dropped "child" (subsumed by has_child).
- Skipped: making every {" candidate must-parse. Both forms of
  EXTENDS_SCHEMA_COMPOSITION intentionally show an elided rejected shape
  ({"relationships": [{... ...}]}); a must-parse rule would need an elision
  exemption that reopens the same hole. Documented on json_examples.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio
malibio force-pushed the issue-2629-skill-rule-parity branch from 85c17bc to 1116f19 Compare September 28, 2026 17:00
@malibio
malibio merged commit e193401 into main Sep 28, 2026
@malibio
malibio deleted the issue-2629-skill-rule-parity branch September 28, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No automated check ties skill_rules.rs's imperative/prose fields to cli.md's hand-written prose

1 participant