You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[0.38] fix(compile): Claude AGENTS.md routing follow-ups from the #4005 review (#4787) - #4805
Seven follow-up defects in the Claude AGENTS.md routing that #4005 introduced, from its Copilot re-reviews:
Pack bundles unadmitted instructions.routed_claude_rule_renders now builds the canonical DeployableSourcePlan (Claude target, skill subset from effective_dependency_selection). render_agents_md_routed_rules selects sources through it, so a root-level *.instructions.md that install never deploys is never packed.
Compile reminder never clears after link rewriting, and 7. scope or body edits keep the reminder silent. After compiling, the reminder is no longer decided by a substring check against compiled text. A Claude-only compile now records, for each AGENTS.md it wrote:
the file's digest;
an exact fingerprint of each routed instruction it carries (normalized applyTo plus the normalized source body).
The record lives in APM home (compiled-agents-md/<root key>.json), not in the repository. Install compares a routed instruction's fingerprint with the record for the one AGENTS.md its scope names: the root for always-on, exactly <dir>/AGENTS.md for a directory. The file must still match its recorded digest, and its CLAUDE.md must import it. As a result:
compile's link rewriting no longer matters;
an applyTo change or a shortened body asks for apm compile again;
any later rewrite of the file by something else asks again too.
managed_section without markers. The blocker check now validates the configured markers through the managed-section owner (validate_managed_section). A hand-authored AGENTS.md whose markers are missing, duplicated or reversed keeps the rules in .claude/rules/, and install warns.
Repeated AGENTS.md reads. The integrator holds one CompiledCoverage per project root for the install. The record, each file's digest and each directory's CLAUDE.md import check are read once.
apm compile --target claude --root <dir> dropped directory placements.pin_directory_placements now checks that the directory exists under the source root and writes the placement under the output root.
Claude shims after a failed AGENTS.md write. AGENTS.md outputs are recorded only after the batch is written (or for a dry-run preview). compile() skips CLAUDE.md generation when AGENTS.md compilation failed.
The record is written outside compilation/ (core/agents_md_compile_record.py, under the routing owner's selectors), so compiled outputs still go only through CompiledOutputWriter. The routing guard pins the new wiring: _compile_distributed must call record_compiled_instructions, and _claude_rule_sources must call CompiledCoverage.
Human scope-approval comment: #4787 (apm-scope:v1 record on the issue)
Does this PR complete the issue, or what remains? It completes the issue. The missing-cache-directory case stays in #4755, as the record says.
Notes:
A project compiled before this change has no record, so the next install prints the apm compile reminder once. The compile after that writes the record and the reminder stays quiet.
With compilation.agents_md.mode: managed_section, editing the hand-authored part of AGENTS.md changes its digest, so the reminder appears once until the next compile.
Type of change
Bug fix
New feature
Documentation
Maintenance / refactor
Testing
Tested locally
All existing tests pass
Added tests for new functionality (if applicable)
New cells in tests/unit/compilation/test_claude_agents_md.py (TestRoutingFollowUps, plus test_managed_section_without_one_marker_pair_keeps_the_rules). Each asserts behaviour that main lacks:
item 1: a root-level instruction is not rendered;
item 2: no reminder after a compile rewrote a context link;
item 7: reminder after an applyTo narrowing or a shortened body;
item 4: AGENTS.md read count independent of the routed instruction count;
item 5: --root writes src/AGENTS.md and its shim;
item 6: a batch rejected by the output gate (hidden Unicode) leaves no CLAUDE.md;
item 3: missing, duplicated or reversed markers keep the rule and warn.
The existing reminder cell now compiles for real instead of using a hand-written AGENTS.md. The managed-section blocker cell adds the markers its "routes" case needs.
Validation evidence:
Local pytest is suspended on the shared host (P2 rule 17), so CI is the test gate. One earlier guarded run of the unit file passed 60 cells; the read-count cell was rewritten after that run.
ruff check / ruff format --check (0.15.12, CI paths): clean.
One fragment per section, changelog.d/<pr>.<section>.md, holding
one line: user-visible effect first, 25 words or fewer, ending with (#PR); breaking changes only under upgrade notes; no Highlights; no
new lines under ## [Unreleased]. See changelog.d/README.md and .github/instructions/changelog.instructions.md.
…ew (#4787)
- pack renders routed rules only from sources the canonical deployment
source plan admits (item 1);
- compile records each routed instruction's scope and body fingerprint per
AGENTS.md (with the file digest); install compares it through one
CompiledCoverage per root, so link rewriting stays quiet and applyTo or
body edits remind (items 2, 4, 7);
- managed_section mode validates its markers through the managed-section
owner before the route opens (item 3);
- compile --root checks directory placements under the source root (item 5);
- AGENTS.md outputs are recorded only once written, and no CLAUDE.md shim
is written after a failed AGENTS.md batch (item 6).
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved compile-record timing and multi-target coverage gaps cause repeated recompilation prompts, while missing managed-section marker validation can retire native rules for a file that compilation rejects.
…#4787)
apm-spec-waiver: Claude AGENTS.md routing, compile reminder and pack source selection are local client behaviour; no manifest, lockfile or resolver contract changes
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved marker-validation and coverage-tracking defects can retire native rules before compilation fails, repeatedly flag successful compiles as stale, and miss instructions whose bodies were cleared.
…and empty bodies (#4787)
- record coverage whenever Claude consumes the compiled AGENTS.md (multi-
target and --target all) and match fingerprints wherever the shared
optimizer placed them;
- re-pin the record after the CLI's constitution rewrite;
- compare an emptied body's fingerprint too;
- managed-section mode validates markers in a generated AGENTS.md too;
- routing verdicts and the blocker are cached per install root.
apm-spec-waiver: Claude AGENTS.md routing, compile reminder and pack source selection are local client behaviour; no manifest, lockfile or resolver contract changes
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Scope and fingerprint tracking defects can leave stale AGENTS.md guidance undetected, while invalid marker handling can retire native rules even though compilation cannot deliver their guidance.
No open issues 🎉
3 previously missed issues
In code that hasn't changed since last review
Invalid marker values can retire rules without compiling guidance
An explicit start_marker: null (or another non-string marker) falls back to the default here, but CompilationConfig.from_apm_yml preserves that configured value. If AGENTS.md contains the default markers, install therefore accepts it and retires the native rules, while compile rejects the null marker and cannot deliver the guidance. Use defaults only for absent keys, and make explicitly invalid values fail managed-section validation so install retains the rules.
Identical fingerprints across scopes can mask stale guidance
If instructions A and B both contain Use ASCII. but have scopes ** and src/**, narrowing A to src/** makes B's recorded fingerprint satisfy this lookup for both sources. Install then treats A as unchanged even though its old guidance remains global in the root AGENTS.md. Record a stable source identity alongside each fingerprint and compare the same source during install, with a regression for identical bodies at different scopes.
Scope changes can leave stale compiled guidance undetected
Changing a local instruction from applyTo: '**' to **/*.py excludes it from routed, so this check never marks it stale. A local-only reinstall then prints no compile reminder even though AGENTS.md still contains the old always-on guidance. Check previously compiled contributions before filtering out native rules, and add a regression for this scope transition.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human review is needed to assess validation and routing inconsistencies that can retire native rules before compilation rejects AGENTS.md or leave stale global guidance after routing changes.
…t instruction
#4805 makes compile record which routed instructions each Claude AGENTS.md carries under APM home (.apm/compiled-agents-md, core/agents_md_compile_record.py), so nothing new lands in the repository. I5 now admits that one prefix for a non-read-only compile only. A dry-run compile, and every other command, stays forbidden from writing it. Fixes test_claude_routes_an_always_on_instruction_to_agents_md.
On main d8b37cb (#4805), the kit packages' '**' instruction no longer reaches .claude/rules for Claude in the M-SOURCE context pass. That is the #4005 contract (always-on guidance routes to AGENTS.md through compile), so the spine's rule-evidence oracle was stale for an always-on instruction. The kit instruction is now path-scoped ('**/*.py'), like M-SOURCE's own packages, so .claude/rules/<pkg>.md stays a deterministic, strictly checked destination; test_file_routing covers the '**' route. Fixes test_source_spine_covers_every_form_and_op.
Co-authored-by: Copilot App <[email protected]>
… it was copied into
Exposed by following #4805 with a path-scoped kit instruction. With '**', install rendered the routed Claude rule for the bundle; a path-scoped rule is not routed, so nothing re-renders it. apm install <bundle> is imperative (reference/cli/install.md): it copies the bundle into the targets current at that moment. A later manifest install, after widening targets to claude, deploys nothing new for the bundle and reports no changes (reproduced with the CLI). instructions_witnessed now requires a bundle's instruction under the targets of its last bundle install that are still current (bundle_targets), not under every current target. Fixes test_source_spine_covers_every_form_and_op (install bundle p-pack-bundle: .claude/rules/p-pack.md).
Co-authored-by: Copilot App <[email protected]>
…ive controls (#4805)
The I5 allowance for compile's APM-home record now names the exact file core/agents_md_compile_record.py writes for the output root (.apm/compiled-agents-md/<sha256(root)[:32]>.json), and only for a non-dry-run compile. tests/quality/test_oracle_compile_record.py holds the negative controls: a dry-run compile, another root's record, and an install writing the record all fail I5; a compile writing its own root's record passes.
Co-authored-by: Copilot App <[email protected]>
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
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.
Description
Seven follow-up defects in the Claude AGENTS.md routing that #4005 introduced, from its Copilot re-reviews:
Pack bundles unadmitted instructions.
routed_claude_rule_rendersnow builds the canonicalDeployableSourcePlan(Claude target, skill subset fromeffective_dependency_selection).render_agents_md_routed_rulesselects sources through it, so a root-level*.instructions.mdthat install never deploys is never packed.Compile reminder never clears after link rewriting, and 7. scope or body edits keep the reminder silent. After compiling, the reminder is no longer decided by a substring check against compiled text. A Claude-only compile now records, for each AGENTS.md it wrote:
applyToplus the normalized source body).The record lives in APM home (
compiled-agents-md/<root key>.json), not in the repository. Install compares a routed instruction's fingerprint with the record for the one AGENTS.md its scope names: the root for always-on, exactly<dir>/AGENTS.mdfor a directory. The file must still match its recorded digest, and itsCLAUDE.mdmust import it. As a result:applyTochange or a shortened body asks forapm compileagain;managed_sectionwithout markers. The blocker check now validates the configured markers through the managed-section owner (validate_managed_section). A hand-authoredAGENTS.mdwhose markers are missing, duplicated or reversed keeps the rules in.claude/rules/, and install warns.Repeated AGENTS.md reads. The integrator holds one
CompiledCoverageper project root for the install. The record, each file's digest and each directory'sCLAUDE.mdimport check are read once.apm compile --target claude --root <dir>dropped directory placements.pin_directory_placementsnow checks that the directory exists under the source root and writes the placement under the output root.Claude shims after a failed AGENTS.md write. AGENTS.md outputs are recorded only after the batch is written (or for a dry-run preview).
compile()skips CLAUDE.md generation when AGENTS.md compilation failed.The record is written outside
compilation/(core/agents_md_compile_record.py, under the routing owner's selectors), so compiled outputs still go only throughCompiledOutputWriter. The routing guard pins the new wiring:_compile_distributedmust callrecord_compiled_instructions, and_claude_rule_sourcesmust callCompiledCoverage.Issue and approved scope
Issue: Fixes #4787
Human scope-approval comment: #4787 (apm-scope:v1 record on the issue)
Does this PR complete the issue, or what remains? It completes the issue. The missing-cache-directory case stays in #4755, as the record says.
Notes:
apm compilereminder once. The compile after that writes the record and the reminder stays quiet.compilation.agents_md.mode: managed_section, editing the hand-authored part ofAGENTS.mdchanges its digest, so the reminder appears once until the next compile.Type of change
Testing
New cells in
tests/unit/compilation/test_claude_agents_md.py(TestRoutingFollowUps, plustest_managed_section_without_one_marker_pair_keeps_the_rules). Each asserts behaviour that main lacks:applyTonarrowing or a shortened body;--rootwritessrc/AGENTS.mdand its shim;CLAUDE.md;The existing reminder cell now compiles for real instead of using a hand-written AGENTS.md. The managed-section blocker cell adds the markers its "routes" case needs.
Validation evidence:
ruff check/ruff format --check(0.15.12, CI paths): clean.scripts/lint_architecture_boundaries.py --root .: exit 0.pylint R0801: 10.00/10.lint-auth-signals.sh: clean.check_complexity_ratchet.py --base-ref main: clean.check_test_assertions.py: assertion-quality ratchet clean.tests.quality.taxonomy --changed: clean.Changelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated