Repository navigation
fix(install): register local plugin bundle hooks through the hook integrator - #3897
Conversation
…egrator apm install <bundle> now stages the verified bundle, loads it with the canonical Claude-plugin normalization and registers its hooks through HookIntegrator.integrate_hooks_for_target under the exact-content executables gate. Bundle hook entries carry a local-bundle/<slug> marker owned by hook_ownership.py, are excluded from drift replay projection, and survive dependency cleanup; reconcile_deployed_block no longer sweeps local-bundle claims on a later dependency install. Refs #3700 Co-authored-by: Copilot App <[email protected]>
apm-spec-waiver: local bundle hook registration reuses the existing hook integrator and executables gate; no OpenAPM normative requirement changes Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unverified manifest hooks can execute under an existing approval, while ownership and reinstall flaws can preserve stale commands, replace dependency hooks, or overwrite local edits.
5 open issues
Clear stale hooks when replacing a bundle with a hook-free version · New Bind hook directives to verified manifest bytes · New Protect locally edited hook scripts during reinstall · New Use collision-safe source markers for bundle hooks · New Normalize global hook claims before collision checks · New
What changed in this PR
Addresses #3700 by routing local Claude plugin bundle hooks through APM’s existing hook integrator and exact-content approval gate. Local-bundle uninstall remains out of scope.
Changes:
- Stages bundle content for canonical hook normalization and target-specific registration.
- Adds bundle ownership markers and preserves local-bundle deployments during dependency reconciliation.
- Adds lifecycle and architecture regression coverage, and updates usage and security documentation.
| File | Description |
|---|---|
tests/unit/install/test_install_local_bundle.py |
Updates expectations for integrator-owned hook routing. |
tests/integration/test_marketplace_pack_producer_refs_lifecycle.py |
Removes the obsolete skipped-hooks test. |
tests/integration/test_local_bundle_hooks_lifecycle.py |
Covers approval, registration, execution, reinstall, and unrelated dependency cleanup. |
tests/integration/test_architecture_owner_rule_mutations.py |
Tests canonical marker and integrator enforcement. |
src/apm_cli/models/apm_package.py |
Adds local-bundle identity to package information. |
src/apm_cli/integration/hook_ownership.py |
Defines bundle markers and adjusts cleanup and drift filtering. |
src/apm_cli/integration/hook_integrator.py |
Uses bundle markers and preserves bundle-owned hook entries. |
src/apm_cli/install/services.py |
Invokes bundle hook integration and records deployed scripts. |
src/apm_cli/install/manifest_reconcile.py |
Retains local-bundle claims during dropped-path reconciliation. |
src/apm_cli/install/local_bundle_paths.py |
Delegates plugin hooks instead of issuing unsupported-hook warnings. |
src/apm_cli/install/local_bundle_hooks.py |
Adds approval-gated staging, normalization, and hook registration. |
scripts/architecture_linter/checks/mutation_hook_contract.py |
Guards canonical bundle marker and registration paths. |
packages/apm-guide/.apm/skills/apm-usage/package-authoring.md |
Documents approval requirements for bundle hooks. |
docs/src/content/docs/reference/cli/install.md |
Explains registration and local-bundle uninstall limitations. |
docs/src/content/docs/producer/pack-a-bundle.md |
Describes installing approved packed hooks. |
docs/src/content/docs/enterprise/security.md |
Documents plugin hooks under the executable trust gate. |
docs/src/content/docs/consumer/deploy-a-bundle.md |
Explains hook approval and reinstall behavior. |
CHANGELOG.md |
Adds the bundle-hook fix and restores earlier release-note entries. |
.apm/architecture/owners/hooks-integrations.json |
Extends the canonical hook ownership registry. |
Review effort: Balanced
Use an unforgeable local-bundle:: hook marker so a dependency owned by a 'local-bundle' org cannot keep its hooks past uninstall or escape drift checks (architect, security). Stage only integrity-listed bundle files and re-verify them, so plugin.json hooks are bound by the approval key (security). Treat only bundle claims as overwritable (architect nit). Add dry-run, Copilot and user-scope lifecycle coverage and a marker-namespace unit test (test coverage). Restore main's CHANGELOG after a merge artifact and align docs (doc writer). Keep install modules within LOC budgets. apm-spec-waiver: local bundle hook registration reuses the existing hook integrator and executables gate; no OpenAPM normative requirement changes Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 1 | 1 | 1 | Hooks have one writer: everything goes through HookIntegrator. The 'local-bundle/' marker prefix overlaps real dependency names, so those hooks survive uninstall. |
| Test Coverage Expert | 0 | 3 | 0 | Lifecycle test traps park/approve/reinstall/unrelated-dep survival and audit; gaps: marker namespace, copilot/--global, approved dry-run. |
| Supply Chain Security Expert | 1 | 2 | 0 | Consent gate holds for apm-packed bundles, but the marker namespace is forgeable and root plugin.json is not bound by integrity or the approval key. |
| Doc Writer | 0 | 2 | 1 | Docs now say bundle hooks register; fix the CHANGELOG merge artifact, an overstated parity claim and hook-less approval lists. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 5 follow-ups
- [Supply Chain Security Expert] (blocking-severity) Replace the 'local-bundle/' marker prefix with one no canonical dependency string can produce, and add a unit test that github.com/local-bundle/* and gitlab.com/local-bundle/x dependencies stay dependency-owned. -- At the reviewed head, any dependency under a 'local-bundle' owner gets hooks that survive uninstall and skip drift; the python-architect independently confirmed it.
- [Supply Chain Security Expert] Stage only integrity-listed bundle files, including root plugin.json, and re-verify them after staging. -- The approval key is the consent contract; inline plugin.json hooks must not register content the key did not cover.
- [Test Coverage Expert] Extend lifecycle coverage to the copilot target and --global scope, and assert an approved-bundle --dry-run writes no hook config. -- Only claude project scope is covered; regressions in the target loop and dry-run on an executables surface would go unnoticed.
- [Supply Chain Security Expert] Follow-up: bind bundle-owned hook entries to a lockfile hash of the owned hook slice; in this PR, state the limitation in enterprise/security.md. -- Excluding these entries from drift means settings.json tampering goes undetected; the fix is a lockfile schema change.
- [Python Architect] Follow-up: centralize the local-bundle retention rule into DeploymentIntent. Fold now: CHANGELOG merge-artifact cleanup and the bundle-only _prior_bundle_claims filter. -- Duplicated ownership rules drift; centralizing changes the owner contract, so it belongs in its own PR.
Architecture
classDiagram
direction LR
class HookIntegrator {
<<CanonicalOwner>>
+integrate_hooks_for_target(target, package_info, project_root)
+_get_hook_source_marker(package_info, project_root, name) str
+_clean_apm_entries_from_json(path, sidecar)
}
class hook_ownership {
<<VocabularyOwner>>
+LOCAL_BUNDLE_HOOK_SOURCE_PREFIX
+local_bundle_hook_source_marker(bundle_id) str
+is_local_bundle_hook_source(marker) bool
+dependency_hook_source_marker(dep_ref) str
+drop_dependency_owned_entries(hooks) bool
+project_apm_owned_hook_entries(cfg, sidecar) bytes
+canonicalize_hook_sidecar(bytes) bytes
}
class local_bundle_hooks {
<<Adapter>>
+integrate_local_bundle_hooks(bundle_info, pack_files) BundleHookResult
-_bundle_hook_package() PackageInfo
-_prior_bundle_claims(root) set
}
class PackageInfo {
<<Dataclass>>
+install_path Path
+local_bundle_id str
}
class services_integrate_local_bundle {
+integrate_local_bundle(bundle_info, root) dict
}
class manifest_reconcile {
<<Chokepoint>>
+reconcile_deployed_block()
}
class DeploymentLedgerCodec {
+local_bundle_values(ledger) frozenset
+local_bundle_scope(values, bundles) frozenset
}
services_integrate_local_bundle ..> local_bundle_hooks : calls after file deploy
local_bundle_hooks ..> HookIntegrator : delegates write
local_bundle_hooks ..> PackageInfo : builds hook view
HookIntegrator ..> hook_ownership : marker and cleanup
manifest_reconcile ..> DeploymentLedgerCodec : bundle scope
class local_bundle_hooks:::touched
class hook_ownership:::touched
class HookIntegrator:::touched
class manifest_reconcile:::touched
class PackageInfo:::touched
class services_integrate_local_bundle:::touched
classDef touched fill:#fff3b0,stroke:#d47600
flowchart TD
A[apm install ./bundle] --> B[integrate_local_bundle]
B --> C[deploy loop skips plugin hook paths]
C --> D[integrate_local_bundle_hooks]
D -->|not approved| W[one warning with exact approval key]
D -->|approved| F[stage pack_files in tempdir]
F --> G[validate_legacy_marketplace_plugin to PackageInfo]
G --> H[HookIntegrator.integrate_hooks_for_target per target]
H --> J[merge settings.json, sidecar, copy scripts]
J --> L[record scripts as local-bundle claims]
M[apm install other-pkg] --> O[reconcile_deployed_block]
O --> P[local_bundle_scope keeps bundle claims]
T[apm uninstall dep] --> U[_clean_apm_entries_from_json keeps bundle entries]
Recommendation
The direction is right and the lifecycle test proves the main promise. Merge once the in-scope folds land: a marker prefix that cannot collide (with its negative unit test), integrity-checked staging of plugin.json, copilot/--global/dry-run coverage, the CHANGELOG cleanup, and the docs corrections including the settings.json tampering limitation in enterprise/security.md. Track lockfile hash-binding of bundle hook entries as the top post-merge follow-up, and DeploymentIntent centralization after it.
Full per-persona findings
Python Architect
- [blocking] The 'local-bundle/' hook marker prefix can be produced by a real GitHub dependency, so that dependency's hooks are never cleaned up or drift-checked. at
src/apm_cli/integration/hook_ownership.py:247
dependency_hook_source_marker returns 'owner/repo'; 'local-bundle' is a valid org name, so DependencyReference.parse('local-bundle/hooks-pack') yields a marker is_local_bundle_hook_source accepts. The linter guard checks the literal lives in one place, not that the namespaces are disjoint.
Suggested: use a prefix no canonical dependency string can produce and add a negative unit test. - [recommended] The bundle-retention rule is now applied at three sites, and its protection depends on the ledger slice each caller passes. at
src/apm_cli/install/manifest_reconcile.py:695
Suggested: compute bundle values once and pass them through DeploymentIntent, or limit the new step to the local block. - [nit] _prior_bundle_claims passes all local_deployed_files as managed_files instead of bundle-only claims. at
src/apm_cli/install/local_bundle_hooks.py:152
Test Coverage Expert
- [recommended] No negative test proves a dependency whose owner is literally 'local-bundle' stays dependency-owned for hook cleanup and drift. at
src/apm_cli/integration/hook_ownership.py:247
Proof (missing at):tests/unit/integration/test_hook_integrator.py::test_dependency_owner_named_local_bundle_is_not_bundle_owned - [recommended] Bundle hook registration is proven only for claude in project scope; copilot per-file hooks and --global have no coverage. at
tests/integration/test_local_bundle_hooks_lifecycle.py - [recommended] No test shows an approved-bundle --dry-run writes no hook config or scripts. at
src/apm_cli/install/local_bundle_hooks.py:83
Supply Chain Security Expert
- [blocking] Remote dependencies can produce the 'local-bundle/' marker, so their hook entries skip drift checks and survive uninstall cleanup. at
src/apm_cli/integration/hook_ownership.py:247
Verified: 'local-bundle/evil', 'gitlab.com/local-bundle/evil' and 'ghe.corp.com/local-bundle/x' all yield markers treated as local-bundle.
Suggested: a marker containing a character no canonical repo string can contain, plus a regression test. - [recommended] Staged root plugin.json is unverified when bundle_files omits it, and inline plugin.json hooks override the approved hooks.json; staging re-reads files after the integrity check. at
src/apm_cli/install/local_bundle_hooks.py:127
Suggested: stage only integrity-listed files and re-hash them after the copy. - [recommended] Local-bundle hook entries are excluded from drift and kept on every cleanup with no content binding, and enterprise/security.md does not disclose it. at
src/apm_cli/integration/hook_ownership.py:168
Suggested: hash-bind the owned hook slice in the lockfile (follow-up); document the limitation now.
Doc Writer
- [recommended] The CHANGELOG [Unreleased] Fixed section gained 21 duplicate long-form entries from a merge resolution; the fix(install): register local plugin bundle hooks through the hook integrator #3897 line is over the length guideline. at
CHANGELOG.md:44 - [recommended] deploy-a-bundle.md says hooks merge 'exactly as a source install does', but the bundle script path differs; only events and commands match. at
docs/src/content/docs/reference/cli/install.md:413 - [nit] governance.md, enterprise/security.md, reference/cli/approve.md and reference/policy-schema.md list only MCP, LSP and canvas for local-bundle exact-key approvals; commands.md's local-bundle paragraph mentions neither hooks nor uninstall. at
packages/apm-guide/.apm/skills/apm-usage/governance.md:264
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
Addresses Copilot inline review on src/apm_cli/install/local_bundle_hooks.py: a reinstall that ships no hooks now removes the bundle's merged entries through HookIntegrator.reconcile_package_target_restriction; only unedited bundle claims, in the integrator's project-relative form, may be overwritten, so a locally edited script survives without --force and a user-scope reinstall updates changed scripts. Lifecycle traps cover all three and fail without the guards. apm-spec-waiver: local bundle hook registration reuses the existing hook integrator and executables gate; no OpenAPM normative requirement changes Co-authored-by: Copilot App <[email protected]>
Addresses delta panel findings: HookIntegrator.retire_local_bundle_hooks owns removal of one bundle's merged entries (no placeholder PackageInfo), and a reinstall whose hooks are unapproved or lack an integrity manifest now retires the earlier version's entries instead of leaving them active. Adds traps for a co-resident dependency's hooks, hook-free dry run, user-scope retirement and the no-manifest skip, and a Copilot per-file caveat in deploy-a-bundle.md. apm-spec-waiver: local bundle hook registration reuses the existing hook integrator and executables gate; no OpenAPM normative requirement changes Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 3 | 0 | Marker collision fixed; deferral accepted; retirement should go through an owner method and cover skipped reinstalls (folded in eefc531). |
| Supply Chain Security Expert | 0 | 1 | 0 | All prior findings resolved; unapproved reinstalls must retire earlier entries (folded in eefc531). |
| Test Coverage Expert | 0 | 3 | 0 | Prior gaps closed; co-resident, hook-free dry-run and no-manifest traps requested (folded in eefc531). |
| Doc Writer | 0 | 1 | 0 | Prior findings fixed; Copilot per-file caveat requested (folded in eefc531). |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 4 follow-ups
- [Supply Chain Security Expert] Track that
apm install -gapplies no executables gate when the user-scope config has no executables block (source packages and local bundles alike). -- A pre-existing secure-by-default gap in user scope, confirmed with a hooked source package. - [Supply Chain Security Expert] Bind local-bundle hook entries to hashes in the lockfile and bring them into audit drift detection. -- An edited hook entry in settings.json is not seen by
apm audittoday; needs a lockfile schema change. - [Python Architect] Move bundle retention into the DeploymentIntent owner contract, covering all four readers including
_prior_bundle_claims. -- Retention logic is spread across call sites;_retire_source_markersis a first consolidation. - [Doc Writer] Give local bundles per-bundle ownership so a reinstall removes stale Copilot per-file hook files and
apm uninstallworks for local bundles. -- The docs caveat is honest, but cleanup is manual today.
Recommendation
Merge once CI on 4e2268f is green. All delta findings were folded, and exact-head lifecycle tests show each fix works and fails without its guard. Track the -g gate gap, lockfile hash-binding, DeploymentIntent centralization and per-bundle ownership as next steps.
Full per-persona findings
Python Architect
- [recommended]
_retire_bundle_hooksbuilt a placeholder PackageInfo to recover the bundle id. atsrc/apm_cli/install/local_bundle_hooks.py:173
Suggested: aHookIntegrator.retire_local_bundle_hooks(bundle_id, project_root, targets)owner method. Folded in eefc531. - [recommended] Retirement ran only on a hook-free reinstall; no
-gretire trap; skipped reinstalls left prior entries active. atsrc/apm_cli/install/local_bundle_hooks.py:53
Folded in eefc531 (retire on unapproved and no-manifest reinstalls;-ghook-free retire trap). - [recommended] The three-site retention rule stays deferred; the follow-up should list all four readers including
_prior_bundle_claims. atsrc/apm_cli/install/manifest_reconcile.py:671
Supply Chain Security Expert
- [recommended] An unapproved or manifest-less hook-bearing reinstall left the previously approved entries active. at
src/apm_cli/install/local_bundle_hooks.py:57
Folded in eefc531, with a lifecycle trap that keeps a co-resident dependency's hook.
Test Coverage Expert
- [recommended] The hook-free retirement trap ran with no co-resident hooks. at
tests/integration/test_local_bundle_hooks_lifecycle.py:190-- folded in eefc531. - [recommended] No hook-free
--dry-runtrap. attests/integration/test_local_bundle_hooks_lifecycle.py:191-- folded in eefc531. - [recommended] No test for the no-integrity-manifest skip. -- folded in eefc531 (
tests/unit/install/test_install_local_bundle.py::test_bundle_without_integrity_manifest_skips_hooks).
Doc Writer
- [recommended] "Reinstalling the bundle replaces them" is untrue for Copilot per-file hook files after a hook-free reinstall. at
docs/src/content/docs/consumer/deploy-a-bundle.md:104-- folded in eefc531.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.


Description
apm install ./build/<bundle>(a Claude plugin bundle fromapm pack) skipped the bundle'shooks.jsonandhooks/files with a warning, so hooks never deployed from a local bundle although they did from a source install.Now the bundle path routes hooks through the one canonical hook owner instead of a bundle-specific writer:
install/local_bundle_hooks.pystages the integrity-verified bundle bytes, loads them with the canonical Claude-plugin normalization (validate_legacy_marketplace_plugin, the same interpretation a source install of a plugin uses), and callsHookIntegrator.integrate_hooks_for_targetfor each hook-capable target. It writes no hook config itself.executables: {}(or no approval) the hooks are parked with one warning that prints the bundle'sname#version@sha256:<digest>key; once approved they merge into.claude/settings.json/apm-hooks.jsonexactly as a source install does, and reinstalling replaces them.local-bundle::<slug>marker owned byhook_ownership.py. Drift replay excludes them (replay has no source to rebuild them, like other local-bundle files, whose scripts stay hash-bound inlocal_deployed_file_hashes), and dependency cleanup keeps them.HookIntegrator.retire_local_bundle_hooks; locally edited bundle scripts are kept unless--force. Staging copies only integrity-listed files and re-verifies them.apm install <other-pkg>after a bundle install swept the bundle's files as stale (reconcile_deployed_blockonly protected local-bundle claims in the generic sweep). With hooks registered this would leave a dangling hook command, so the reconciler now keeps local-bundle claims in the dropped set too.Before:
[!] Skipped packed bundle hook file 'hooks.json': local bundle install does not register plugin hooks yet.After: parked under the executables gate, then registered like a source install once the key is approved;
apm audit --cigreen.Issue and approved scope
Issue: Refs #3700
Human scope-approval comment: #3700 (comment)
Does this PR complete the issue, or what remains? It delivers the approved scope. Not covered (out of scope in the record):
apm uninstallfor local bundles (no per-bundle ownership exists today for any bundle content), the--format apmdeployed-layout lowering of.claude/hooks/<pkg>/scripts/x.shtox.sh.json, and the own-project.apm/skills/symlink summary diagnostic.Type of change
Testing
Validation evidence (exact head
4e2268fccc7d8e0ed2aabe3bd784a6e1d04e7936, merged with currentmain):APM_BINARY_PATH=.venv/bin/apm .venv/bin/python -m pytest -p no:xdist tests/integration/test_local_bundle_hooks_lifecycle.pySkipped packed bundle hook file 'hooks.json').venv/bin/python -m pytest -p no:xdist tests/unit/install/test_install_local_bundle.py.venv/bin/python -m pytest -p no:xdist "tests/unit/integration/test_hook_integrator.py::test_dependency_named_local_bundle_stays_dependency_owned"local-bundle/prefix).venv/bin/python -m pytest -p no:xdist tests/unit/install/phases/test_lockfile_union.py tests/unit/test_apm_package.pyAPM_BINARY_PATH=.venv/bin/apm .venv/bin/python -m pytest -p no:xdiston the 7 existing local-bundle / pack lifecycle files.venv/bin/python -m pytest -p no:xdist tests/integration/test_architecture_owner_rule_mutations.py -k "local_bundle_hooks_must or neutral_hook or covers_every or order_is"uvx [email protected] check/format --check(CI paths), pylint R0801,lint-auth-signals.sh,lint-architecture-boundaries.sh, file-length guardgh pr checks 3897Review: panel advisories #3897 (comment) (full) and #3897 (comment) (delta); all in-scope findings and 5 Copilot inline comments folded.
Deferred (scope-crossing): lockfile hash-binding of bundle hook entries; centralizing local-bundle retention in DeploymentIntent; per-bundle ownership (
apm uninstallfor local bundles, stale Copilot per-file hook files);apm install -ghas no executables gate without a user-scope executables block (pre-existing, source installs alike).Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedapm-spec-waiver:line.)