Repository navigation
[0.38] fix(install): install -g records user-root primitives in the user lockfile (#3772) - #4684
Conversation
…kfile (#3772) User scope now persists self-entry claims for files deployed from user-root primitives, as project scope does, so a later install -g updates APM-owned files when the source changes. A pre-0.38 receipt bound to no lock claim is adopted on the first upgraded install while the file still holds the receipted bytes. Co-authored-by: Copilot App <[email protected]>
…er row, docs Move the lockless user-root receipt adoption into DeploymentMaterializationSession and the pure deployment row validator into deployment_state.py to stay within the module length cap. Record the bug-ledger row, document the user-scope claims and align the ownership snapshot test with root-local claims at user scope. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Receipt migration can restore overwrite authority for files whose lock claims were deliberately removed, bypassing the guarded-write requirement for ownership changes.
3 open issues
What changed in this PR
This PR addresses #3772 by recording user-root primitive deployments in the user lockfile, allowing later apm install -g runs to apply source edits while preserving unowned files.
Changes:
- Persist root-local deployment claims at user scope and add migration for legacy lockless receipts.
- Extract deployment-row validation while preserving the existing codec API.
- Add lifecycle coverage, update ownership expectations, and document the behavior.
| File | Description |
|---|---|
tests/unit/install/test_pipeline_ownership_snapshot.py |
Expect root-local claims at both install scopes. |
tests/integration/test_user_root_primitives_lockfile_lifecycle.py |
Cover lock creation, updates, migration, idempotency, and file protection. |
tests/fixtures/lifecycle_bug_ledger/bugs/3772.json |
Link the reported bug to regression coverage. |
src/apm_cli/install/pipeline.py |
Adopt legacy receipts before integration. |
src/apm_cli/install/phases/post_deps_local.py |
Enable user-scope local deployment persistence. |
src/apm_cli/core/deployment_state.py |
House the extracted deployment-row validator. |
src/apm_cli/core/deployment_ledger.py |
Implement receipt adoption and preserve the validator API. |
docs/src/content/docs/reference/cli/install.md |
Describe user-root lock tracking and source updates. |
CHANGELOG.md |
Add a release note for the global-install fix. |
Review effort: Balanced
… rule citation (#3772) The lockless receipt migration now merges the prior root-local claims itself and skips frozen replays, so the pipeline calls it in one line. The generator rule citing class DeploymentLedgerCodec follows its new line. Co-authored-by: Copilot App <[email protected]>
…gacy receipts (#3772) - Audit replays the user-scope self package from $HOME, where install reads root primitives, so recorded user-root files are not orphaned. - At user scope a file a dependency of the same install claims stays that dependency's ($HOME also holds dependency sources), so the root adds no second claim; the ownership snapshot test returns to main. - Migration adopts only the legacy unbound root receipt, keys the claim by the compatibility path (relocated roots such as CLAUDE_CONFIG_DIR), and rebinds migrated receipts to the committed lock claims. - Hash validators move to deployment_state.py for the module length cap. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…3772) pipeline.py was at its 1005-line budget on main, and the user-root receipt migration adds a line. The --dry-run preview stop (preview_install) moves to pipeline_entry.py, which already owns PipelinePreview and the preview entry; the pipeline keeps its pinned call. The release note moves to changelog.d/4684.fixed.md. Co-authored-by: Copilot App <[email protected]>
apm-spec-waiver: user-scope root-local claims reuse the existing self-entry lockfile fields; no new OpenAPM-observable schema or behavior Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Active migration and replay issues can leave upgraded skills with stale content and incorrectly report user-root scripted hook configurations as modified after installation.
2 open issues
3 resolved since last review
Review effort: Balanced
#3772) A 0.37 receipt migrates per file, so the skill directory gate now treats a directory with a verified managed member as managed (each unclaimed member stays protected). Audit replay at user scope renders hooks with user-scope semantics anchored on the live user root while writing into scratch, so install -g then audit --ci reports no drift. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Active issues cause false audit drift reports after clean installs using an external CLAUDE_CONFIG_DIR and O(S × M) inventory checks during skill integration.
2 open issues
2 resolved since last review
Review effort: Balanced
…ion (#3772) The skill directory gate builds the ancestor-directory index of the managed inventory at most once per promotion call, and only on a collision, so membership is O(1) instead of an O(S*M) prefix scan. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because lockfile replay can omit inline-only user-root hooks, causing audit --ci to falsely report freshly installed Claude settings as modified.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
…3772) Reverts the skill-gate member scan: another owner's managed file (a local bundle) must not open an authored skill's directory. The migration owner instead adopts the skill directory entry beside a migrated member, as a normal lock records it (user scope only). Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The predicate change leaves the replay-root-predicate mutation test matching zero occurrences, so its fragment and replacement must be updated to let the test reach the architecture guard.
2 open issues
Review effort: Balanced
…tion cells (#3772) Replay now synthesizes the root self-entry from the user source root, so the drift cell pins that root (with and without .apm/) and the replay-root-predicate mutation targets the self_source_root predicate. Co-authored-by: Copilot App <[email protected]>
…user lockfile A root-only install -g writes no user lockfile on main (#3772, landing in #4684), so the cell no longer reads it; it asserts the deployed script under the Claude root and the settings entry naming it. Co-authored-by: Copilot App <[email protected]>
…e user hooks to #4837 (#3772) Synthesizing the replay self-entry from the user source root made test_global_update_then_audit_passes_for_released_user_lockfiles report drift. Restore the project-scope-only self-entry, its guard, drift cell and mutation case, and track the user-root inline hook case in #4837. Co-authored-by: Copilot App <[email protected]>
…yment frame (#4832) UnifiedLinkResolver._resolve_context_link computed context and memory links from the replay's scratch target directory, so after a clean apm install -g a user-root agent linking ../context/notes.context.md drifted under audit --ci. Context links now map the target through the deployment frame, as asset links already did; init_link_resolver sets the frame for every package (the $HOME user root included), and a lock self-entry (claimed root files) replays with the frame and its live source root. No self-entry is synthesized. Writes stay in scratch. Stacked on #4684 (a668d29). apm-spec-waiver: audit replay link text only; no manifest, lockfile or resolver contract changes Co-authored-by: Copilot App <[email protected]>
Main (#4730) moved is_canonical_bundle_hash into core/receipt_history; this branch had moved it into core/deployment_state. Keep receipt_history as the single owner (deployment_state imports it) and drop the duplicate ledger helper. Co-authored-by: Copilot App <[email protected]>
…ain merge (#3772) Inline the user-scope hook predicate at both call sites; behaviour unchanged. Co-authored-by: Copilot App <[email protected]>
…yment frame (#4832) UnifiedLinkResolver._resolve_context_link computed context and memory links from the replay's scratch target directory, so after a clean apm install -g a user-root agent linking ../context/notes.context.md drifted under audit --ci. Context links now map the target through the deployment frame, as asset links already did; init_link_resolver sets the frame for every package (the $HOME user root included), and a lock self-entry (claimed root files) replays with the frame and its live source root. No self-entry is synthesized. Writes stay in scratch. Stacked on #4684 (a668d29). apm-spec-waiver: audit replay link text only; no manifest, lockfile or resolver contract changes Co-authored-by: Copilot App <[email protected]>
…yment frame (#4832) UnifiedLinkResolver._resolve_context_link computed context and memory links from the replay's scratch target directory, so after a clean apm install -g a user-root agent linking ../context/notes.context.md drifted under audit --ci. Context links now map the target through the deployment frame, as asset links already did; init_link_resolver sets the frame for every package (the $HOME user root included), and a lock self-entry (claimed root files) replays with the frame and its live source root. No self-entry is synthesized. Writes stay in scratch. Stacked on #4684 (a668d29). apm-spec-waiver: audit replay link text only; no manifest, lockfile or resolver contract changes Co-authored-by: Copilot App <[email protected]>
…yment frame (#4832) UnifiedLinkResolver._resolve_context_link computed context and memory links from the replay's scratch target directory, so after a clean apm install -g a user-root agent linking ../context/notes.context.md drifted under audit --ci. Context links now map the target through the deployment frame, as asset links already did; init_link_resolver sets the frame for every package (the $HOME user root included), and a lock self-entry (claimed root files) replays with the frame and its live source root. No self-entry is synthesized. Writes stay in scratch. Stacked on #4684 (a668d29). apm-spec-waiver: audit replay link text only; no manifest, lockfile or resolver contract changes Co-authored-by: Copilot App <[email protected]>


Description
apm install -gwith only user-root primitives (for example~/.apm/agents/*.agent.md, no dependencies) wrote no~/.apm/apm.lock.yaml. With no record of APM owning its deployed files, a laterinstall -gafter a source edit skipped APM's own file as user content and printed "No changes".install/phases/post_deps_local.py) now persists self-entry claims at user scope as it does at project scope, so a laterinstall -gupdates APM-owned files. Files APM did not deploy are still skipped.DeploymentMaterializationSession.adopt_lockless_root_receiptsaccepts that receipt for the self-entry claim. It does so only at user scope, only for the root owner., only for a path the lock does not claim, and only while the file still holds the receipted bytes. A hand-edited file never qualifies.deployment_ledger.pyunder the 2100-line cap, the pure row validatorvalidate_rowsmoved todeployment_state.validate_deployment_rows.DeploymentLedgerCodec.validate_rowsstill works under the same name.Issue and approved scope
Issue: Fixes #3772
Human scope-approval comment: the
apm-scope:v1approval comment on #3772 from Daniel Meppiel (@danielmeppiel) (Decision: approve; Area: project; Review contact: Daniel Meppiel (@danielmeppiel)).Does this PR complete the issue, or what remains? It completes it. All five "Done when" cases have installed-CLI lifecycle tests. Out of scope per the record: receipt trust without a lock claim, dependency and MCP flows,
-gpolicy, #4562, and new lockfile fields.Type of change
Testing
New:
tests/integration/test_user_root_primitives_lockfile_lifecycle.py(installed CLI, isolated HOME and APM_HOME, policy on). It covers the scope record's cases:install -gwith only~/.apm/agentswrites the user lockfile claiming the agent.install -gdeploys the new bytes and does not print "No changes". A repeat install changes no bytes.Evidence:
69c01b43):.venv/bin/python -m pytest tests/integration/test_user_root_primitives_lockfile_lifecycle.py -p no:xdist-> 3 failed, 1 passed. Cases 1-4 failed; case 5 is the protected control and passed both before and after.11f8f585): the lifecycle file,tests/unit/install/test_pipeline_ownership_snapshot.pyandtests/quality/test_lifecycle_bug_ledger.py-> 25 passed.tests/unit/core/,tests/unit/deps/, the global/scope e2e tests, the receipt and global-adoption lifecycles, and the pipeline orchestration tests -> 4386 passed. The only earlier failure was intest_pipeline_ownership_snapshot.py, which asserted the old behavior (local_deployed_files == []at user scope); it now expects root-local claims at both scopes.tests/integration/test_architecture_owner_rule_mutations.pyandtests/unit/scripts/test_architecture_runner.py-> 1327 passed.uvx [email protected] checkandformat --check(src, tests, architecture scripts), pylint R0801,scripts/lint-auth-signals.sh,scripts/check_complexity_ratchet.py --base-ref origin/main,tests.quality.taxonomy --changed,scripts/check_test_assertions.py,scripts/lint_architecture_boundaries.py --root ., and the file-length guard.Lifecycle evidence row:
Changelog
## [Unreleased]inCHANGELOG.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated