Skip to content

[0.38] feat(bundle): Claude bundle installs converge on AGENTS.md (#4034) - #4071

Closed
Daniel Meppiel (danielmeppiel) wants to merge 8 commits into
mainfrom
danielmeppiel-4034-bundle-agents-md
Closed

Daniel Meppiel (danielmeppiel) wants to merge 8 commits into
mainfrom
danielmeppiel-4034-bundle-agents-md

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

TL;DR. On a project-scope Claude target, apm install <bundle> now places instructions the way a package install does since #3939. Always-on and directory instructions are staged as apm compile input, so they land in the AGENTS.md that CLAUDE.md imports. Path-scoped instructions become .claude/rules/ files with paths:, rendered by the existing Claude rule projection instead of copied verbatim with applyTo:. A hand-authored CLAUDE.md without @AGENTS.md keeps the legacy layout and gets the #3939 warning.

Important

Fixes #4034; lands after #4005 and #4007. Stacked PR: the base is danielmeppiel-bookish-funicular (#4005 @ d01029a5, the #3939 routing); retarget to main once #4005 lands. The branch merges the final #4007 head 7d9015b5 (the per-target bundle render seam), so until #4007 lands this diff also shows #4007's commits. This PR's own work is the commits after merge ea204822.

Problem.

Issue and approved scope

Issue: Fixes #4034

Human scope-approval comment: #4034 (comment) (scripts/governance/eligibility.cjs at trusted main 67936cd7: record-present, contact_confirmation_needed: false)

This PR completes the issue. Outside it, per the record: routing semantics (#3939), #3686, agent rendering (#3714/#4007), multi-target placement (pending Daniel), user scope, lockfile schema, and apm pack output.

Record interpretation

The record's Done-when says "apm prune stay byte-stable". This PR reads it through the existing, tested compile-only bundle contract (#1207/#3705; test_local_bundle_compile_only_targets_lifecycle.py: "apm prune still clears it"). It is not a new contract. Proposed amended phrase:

reinstall and install --frozen stay byte-stable, and apm prune keeps deployed and compiled files byte-identical while clearing staging like other compile-only bundle targets

The lifecycle test asserts exactly that: .claude/rules/py.md, AGENTS.md, src/AGENTS.md and CLAUDE.md are unchanged after prune, and the lockfile drops only local_staged_files.

Note

Rebuilt on #4005 @ d01029a5 + #4007 @ 7d9015b5 (head 9dbfac68). The 3 #4034 commits were replayed on top; conflicts in services.py (the _render_fmt dispatch now carries #4007's final Codex branch) and reference/cli/install.md were resolved. #4005's newer rule (a directory instruction routes only where compile can deliver <dir>/AGENTS.md) applies to bundles unchanged, because the bundle routing calls the same routes_to_agents_md(apply_to, project_root) owner; the install doc now says so. #4007's two bypass mutations were repointed to the _render_fmt seam. The earlier services.py LOC and $APM_HOME lifecycle failures were fixed in #4007.

Local evidence on 9dbfac68: lint chain clean (ruff 0.15.12 check/format, pylint R0801, auth signals, complexity ratchet, taxonomy --changed, architecture boundaries, assertion-quality ratchet). pytest local-bundle, Claude AGENTS.md, agent integrator, owner-rule and bypass mutations, architecture runner: all passed. Lifecycle test_local_bundle_claude_agents_md_lifecycle.py, test_local_bundle_codex_agents_lifecycle.py, test_local_bundle_manifest_targets_lifecycle.py: 17 passed. CONFORMANCE regenerated.

Approach

Decision Choice
Who decides routing The #3939 owner only: routes_to_agents_md(applyTo, live project root) plus claude_agents_md_blocker (warned once per install). User scope never routes.
Where routed files go The existing #1207 staging path apm_modules/<slug>/.apm/instructions/<source name>, recorded in local_staged_files with hashes (#3718), so drift, --frozen and prune follow the compile-only contract.
How kept rules render InstructionIntegrator._convert_to_claude_rules (applyTo -> paths:), dispatched through #4007's bundle_render_format_id seam (claude_rules added to _RENDERED_PLUGIN_FORMAT_IDS).
Sources already in Claude rule format A Claude-packed bundle ships its .claude/rules/ files as instructions/<n>.md. Any source with paths: is copied as packed (byte-identical to main), never re-rendered or staged, even next to applyTo: Claude Code reads only paths:, and re-rendering would strip or replace it. APM-format sources (no paths:), with or without applyTo, keep #3939 routing.
Names compile cannot discover Only instructions/<n>.instructions.md (flat) is staged. Any other name keeps its rendered rule, so content is never lost.

Implementation

File Change
install/local_bundle_instructions.py (new) ClaudeBundleRouting: per-install blocker, staged(), stage_tail(), rendered(). render_claude_bundle_rule() delegates to the integrator projection.
install/services.py integrate_local_bundle asks ClaudeBundleRouting whether to stage, and stages under the source name (not the lowered rules/ path). The Codex dispatch reuses the computed render format. The LOC budget (1205) is still met.
install/local_bundle_paths.py claude_rules is a rendered format.
compilation/claude_agents_md.py, integration/instruction_integrator.py claude_agents_md_blocker_warning() is shared by package and bundle installs (same text).
install_claude_agents_md_routing.py guard + install-deployment.json 4 new contracts: integrate_local_bundle -> _ClaudeBundleRouting; _stages -> routes_to_agents_md; __init__ -> claude_agents_md_blocker; renderer -> _convert_to_claude_rules. The owner record lists the new consumer, and a mutation case removes the owner verdict.
marketplace_package_and_registration.py (#4007 guard) Pinned fragments updated to the 2-format set and the _render_fmt dispatch.

Trade-offs

Validation

Check Result
Done-when test on base 6ff4188c src (test_local_bundle_claude_agents_md_lifecycle.py) red: assert ['py.md', 'src.md', 'style.md'] == ['py.md']; the hand-authored control is also red (verbatim applyTo: copy, no warning). The Copilot/Cursor/Codex controls are green on base (unchanged behavior).
Same file on head 7 passed
Bundle + install suites (tests/integration/test_*bundle*, test_pack*, test_unpack*, tests/unit/bundle, tests/unit/install) 3497 passed, 1 skipped (excluding test_unix_install_ownership.py and test_cache_pin, which are root/gpg environment-only)
Integration sweep: 88 bundle/Claude/compile/pack/prune files, APM_E2E_TESTS=1 905 passed, 2 skipped, 1 xfailed, 1 failed. The failure is test_compile_permission_denied (chmod does not deny as uid 0 in this sandbox).
tests/unit + tests/spec_conformance 28725 passed. The 81 failures are git-transport, network, installer and gpg tests that fail identically on base 6ff4188c (same IDs, re-run in a base worktree).
Owner-guard mutations (-k "claude or matrix or order or registry or bundle") 89 passed
Lint mirror: ruff check, ruff format --check, pylint R0801, lint-auth-signals.sh, file length clean, 10.00/10
scripts/lint_architecture_boundaries.py --root . exit 0

Scenario evidence

User promise Test Principle
A bundle and a package give Claude the same instruction layout test_claude_bundle_install_then_compile_converges_on_agents_md One artifact, every harness
Hand-authored CLAUDE.md is never broken or overwritten test_hand_authored_claude_md_keeps_rendered_bundle_rules Never overwrite user content
Reinstall, --frozen, audit --ci and prune are deterministic same test (full-tree digest including staging; prune keeps deployed and compiled bytes) Reproducible installs
A Claude-packed bundle keeps its rule path scoping test_claude_packed_bundle_rules_deploy_byte_identical[paths-only, paths-and-applyTo] (red on 8c0ed150 and 015a5679 respectively) No silent drift
Other harnesses are unchanged test_other_targets_deploy_the_bundle_as_before[copilot,cursor,codex] (exact file sets; green on base) No silent drift

Updated tests (intended behavior change)

Test Why
test_local_bundle_manifest_targets_lifecycle.py The bundle's applyTo: "**" instruction is now staged at apm_modules/bundler/.apm/instructions/glob.instructions.md instead of .claude/rules/glob.md. The path-scoped py rule stays in .claude/rules/py.md, and the test asserts glob.md is absent. No assertion was removed.

How to test

  • APM_E2E_TESTS=1 uv run --extra dev pytest tests/integration/test_local_bundle_claude_agents_md_lifecycle.py
  • Build a plugin bundle with instructions/{style,src,py}.instructions.md (**, src/**, **/*.py). Install it into a targets: [claude] project that has a src/ directory; only .claude/rules/py.md appears and install prints the apm compile hint.
  • Run apm compile: AGENTS.md and src/AGENTS.md carry style and src, and each CLAUDE.md is @AGENTS.md.
  • Add a hand-authored CLAUDE.md and reinstall: all 3 rules land in .claude/rules/ with paths:, with the [FEATURE] Claude target: converge instructions on AGENTS.md #3939 warning.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass (except known environment-only local failures; see Validation)
  • Added tests for new functionality (if applicable)

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md (bottom of ### Changed).
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

Docs re-home after #3996

Page (current main layout) Intent Target in #3996's layout
consumer/deploy-a-bundle.md New paragraph: Claude bundle instructions route like a package install (staged for compile, path-scoped to .claude/rules/ with paths:, hand-authored CLAUDE.md keeps legacy plus warning) reference/cli/install.md (bundle install section; this page is removed in #3996)
producer/pack-a-bundle.md One sentence: install routes Claude instructions through AGENTS.md, so pack output is the same for every consumer reference/cli/pack.md, ## Description (this page is removed in #3996)
reference/cli/install.md One sentence on Claude bundle routing after the Codex agents note reference/cli/install.md (same page)
link producer/compile/#claude-code-deduplication Cross-link to the #3939 routing explanation reference/targets-matrix.md (Claude rows), since producer/compile.md is removed in #3996
apm-usage/commands.md, apm-usage/package-authoring.md One sentence each on Claude bundle routing same files

Co-authored-by: Copilot [email protected]

…am for #4034

Co-authored-by: Copilot App <[email protected]>

# Conflicts:
#	CONFORMANCE.md
`apm install <bundle>` into a project-scope Claude target routes each
plugin-native instruction through the #3939 owner (routes_to_agents_md with
the live project root, claude_agents_md_blocker): routed instructions are
staged as compile input under apm_modules/<slug>/.apm/instructions/ (the
the Claude rule projection (applyTo -> paths:) through the #4007 per-target
render seam. A hand-authored CLAUDE.md without the import keeps every rule
with the #3939 warning; non-discoverable names keep their rendered rule.
The install-deployment-claude-agents-md-routing guard and owner record
cover the bundle consumer, with a mutation case.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
(cherry picked from commit 4a6b858)
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
(cherry picked from commit 5a919a8)
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
(cherry picked from commit 24b4c47)
@danielmeppiel
Daniel Meppiel (danielmeppiel) force-pushed the danielmeppiel-4034-bundle-agents-md branch from 24b4c47 to 9dbfac6 Compare November 21, 2026 12:13
Co-authored-by: Copilot App <[email protected]>
Base automatically changed from danielmeppiel-bookish-funicular to main November 22, 2026 18:39
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Closing per the 0.38 feature-cut ruling (no draft PRs, rule 16): this feature is not in 0.38.0. The branch is kept; it reopens as a ready PR when resumed.

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.

Bundle installs keep the legacy .claude/rules layout instead of converging on AGENTS.md

1 participant