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
fix(install): apply manifest.scripts, unmanaged_files and max_depth deny at install - #4853
TL;DR.apm install now applies three org-policy fields that only apm audit --ci enforced. Under enforcement: block it refuses and leaves durable state as it found it; under warn it warns. Each refusal names the policy field and the fix, and is reported through the same policy reporter as dependency violations.
A scripts: block in the manifest install acts on (--root and -g included) is refused before resolution fetches anything, also when there is no APM dependency work (e.g. an MCP-only manifest).
commit_gate.refuse_denied_scripts, on the parsed manifest; called by the install command and check_before_resolve
dependencies.max_depth
Under a blocking policy the resolver stops at the limit and the cut chains are refused. The policy gate judges the resolved graph, not the lockfile being replaced, so a stale lock no longer refuses a compliant graph. An edge to a node already resolved no deeper is reused, not cut.
An install that would leave a governed file no lockfile row claims is refused after local .apm/ content records its claims, while the deploy journal can still restore every deployed file and discard the staged lockfile. --dry-run previews the verdict.
commit_gate.check_before_release (pipeline, after post_deps_local)
Violations go through emit_check_violations. CheckResult.violation_subjects (policy/models.py) owns the category → (policy field, fix) map, so there is no second projection. The audit checks (_check_scripts_policy, _check_unmanaged_files, _check_transitive_depth) are unchanged, so install and audit reach one verdict.
Note
Scope authority: the apm-scope record on #4826 (Regent ruling, option A). PGM rulings: resolver stop plus a full-graph gate check for max_depth; plan-claimed paths excluded for unmanaged files; scripts enforced at install only. apm run is out of scope and is a follow-up.
Important
unmanaged_files is judged after deploy, then rolled back (accepted deviation from "before any write"). Deciding pre-write would need the full write plan, but only prompts/agents/commands/instructions can be planned without touching disk (commit_gate._GATED_PRIMITIVES, #4381). Skills, hooks and merged configs cannot. A pre-write scan would therefore refuse legitimate adoptions (for example, reinstalling after a lost lockfile) or miss skipped files.
Rollback is exact.InstallTransaction journals the prior state of every path at the write seam (install: lazy pre-write snapshot at the integrator write chokepoint #4282). On refusal it restores those bytes, removes the target roots it created and discards the staged lockfile. The hash and content-scan gates already rely on this same journal.
A failed restore is loud.DeployJournal.restore returns each path it could not restore; the transaction warns Deploy restore path <path>: could not restore: ..., keeps the pre-install copies, and the command still exits 1.
Known limit: a process killed between deploy and restore leaves deployed files unrecorded, because the next install reaps the abandoned journal instead of replaying it. This applies to every post-deploy gate. It is documented in policy-schema.md and tracked in [BUG] Replay an abandoned deploy journal on the next install #4863.
Trade-offs
The scripts and depth refusals use the blocking policy known before resolution (the same one the identity preflight uses to refuse a denied dependency unfetched). The policy is only looked up when the manifest has scripts or the resolver needs a limit.
The git checkout cache (APM_CACHE_DIR/git) may keep entries after an unmanaged or max_depth refusal, as after every post-acquisition refusal. It is content-addressed, shared across concurrent installs, and never trusted without the lockfile hash. deploy_v1 and the rest of the cache stay byte-identical (QL ruling). policy_v1 stays byte-identical when the policy is already cached; a cold or expired read caches the policy, as every policy-enforced command does.
Human scope-approval comment: apm-scope:v1 record on #4826.
Does this PR complete the issue? Yes, except apm run (follow-up, outside the ruled scope).
Type of change
Bug fix
New feature
Documentation
Maintenance / refactor
Testing
Tested locally (targeted rows; the full mirror and suites run in CI)
All existing tests pass
Added tests for new functionality
tests/integration/test_install_policy_fields_lifecycle.py (installed CLI, lifecycle world, P-INV-I7). Every offending row first seeds a compliant install under the policy, so a lockfile, its deployment ledger and the policy cache exist. It then asserts project, HOME, APM_HOME and cache byte-identical after the refusal; only cache/git/ is excluded, and only where noted.
Row
Oracle
scripts block (+ control)
refused before fetch; whole cache unchanged
scripts under --root
refused; manifest read from the source root
scripts, no dependency work
refused (the command path that skips the pipeline)
unmanaged hand-written file (+ control)
refused, file named; audit --ci agrees
root .apm/ local content
installs (own local deploys are claimed); audit --ci passes
--dry-run unmanaged
previews "Would be blocked by policy", writes nothing
max_depth too deep (+ control)
refused naming dependencies.max_depth and the chain
max_depth stale lock
a compliant resolved graph installs despite an over-depth old lock
Unit rows in tests/unit/install/test_commit_gate.py cover project and -g scripts refusal with no apm.yml at the deploy root. test_apm_resolver_edge_cases.py covers the diamond (A, B direct; A → B) under max_depth: 1.
Follow-ups (Copilot threads answered): run the max_depth cutoff before marketplace expansion; recompute unselected packages' depths on selective installs (pre-existing); scan pre-existing drift on installs with no APM work (audit covers it today); apm run and manifest.scripts.
Validation commands and results
uvx [email protected] check src/ tests/ -> All checks passed!
uvx [email protected] format --check src/ tests/ -> 2960 files already formatted
check_complexity_ratchet --base-ref <merge-base> -> clean (192 grandfathered)
lint-auth-signals -> clean
tests.lifecycle.generator --check -> up to date
tests.quality.taxonomy --changed -> 4 changed modules carry marker and promise
S1 rows (red-first): commit_gate reverted -> 2 failed / 2 passed; with fix -> 4 passed
The full lint mirror, unit suites and the lifecycle module run in CI. Local runs were limited by the host load rule.
dependencies: {max_depth: 1} + a package with a transitive dependency → refused naming dependencies.max_depth and the chain.
unmanaged_files: {action: deny} + a hand-written .github/instructions/x.instructions.md → refused naming the file; --dry-run previews it; nothing changes.
Changelog
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.
…all (#4826)
apm install now judges two org-policy fields it left to apm audit --ci,
through the commit-order owner and the audit's own checks:
- manifest.scripts: deny, before the first deployed byte;
- unmanaged_files.action: deny, on the built lockfile, so a governed file
no row claims refuses the install and the transaction restores every
file it deployed.
Each refusal names the policy field and the fix; enforcement: warn warns.
apm-spec-waiver: install-time enforcement of existing org policy fields that audit already enforces; no new OpenAPM contract.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The gate can bypass scripts-deny policies in global or redirected installs, reject compliant first installs, and omit unmanaged-file policy refusals from dry-run.
This PR addresses #4826 by reusing audit policy checks during installation to enforce script restrictions and unmanaged-file denial. Install-time dependencies.max_depth enforcement remains pending in this slice.
Changes:
Adds commit-gate checks with blocking refusals or warnings that name the policy field and remediation.
Adds lifecycle policy fixtures and tests for refusals, rollback, and compliant installs.
Updates policy documentation, usage guidance, and upgrade notes.
File
Description
tests/lifecycle/world/test_world.py
Adds expected outcomes for the new policy variants.
The kill-window condition on this PR (a process killed after deploy and before the gate's restore) is tracked and scoped in #4863: the next install replays the abandoned deploy journal, restoring only bytes that match both the journal and the ledger.
…efore fetch (#4826)
- manifest.scripts: deny is judged on the manifest install acts on
(ctx.apm_package, so --root and -g agree), before resolution fetches
anything.
- dependencies.max_depth: under a blocking policy the resolver stops at
the limit and the cut chains are refused as policy violations; the
policy gate judges the resolved graph, not the lockfile being replaced.
- unmanaged_files.action: deny is judged after local .apm/ content records
its claims, while the deploy journal can still restore every file;
--dry-run previews it.
- Install refusals report through emit_check_violations; the check
category -> (policy field, fix) map lives in CheckResult.violation_subjects.
- Lifecycle rows assert project, lockfile and ledger, HOME, APM_HOME and
the cache byte-identical after a refusal (only cache/git/ excluded where
the verdict needs acquired content). Known kill-window limit: #4863.
apm-spec-waiver: install-time enforcement of existing org policy fields that audit already enforces; no new OpenAPM contract.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical dependency-free and MCP-only install paths bypass scripts and unmanaged-files policy checks, with additional depth-enforcement errors and policy-cache writes that persist after refusal.
The policy gate now judges dependencies.max_depth on the graph the
install resolved, so stand-ins for InstallContext carry dependency_graph
and the row fields it builds from.
Co-authored-by: Copilot App <[email protected]>
Positional marketplace validation fetches before the scripts gate
src/apm_cli/install/commit_gate.py:263
For apm install plugin@marketplace, positional validation resolves and fetches the catalog before this scripts gate runs (commands/install.py:343-349). An uncached catalog can therefore be fetched and persisted even when manifest.scripts: deny later refuses the install, violating the promised pre-fetch refusal and unchanged-cache behavior. Invoke the canonical scripts check before positional validation, and cover an uncached marketplace install in the refusal-state regression.
Depth cutoff runs after marketplace resolution
src/apm_cli/install/phases/resolve.py:757
With max_depth: 1, a depth-1 parent declaring a marketplace dependency still fetches that catalog: apm_resolver.py:1198-1208 resolves the declaration before queueing it for the depth check. If catalog resolution fails, the dependency is never queued, so install reports a marketplace error instead of the depth-policy refusal. Apply the depth check before transitive marketplace resolution and record the rejected chain for the existing policy reporter.
…llower reuse (#4826)
- manifest.scripts: deny is judged in the install command before it
decides whether any APM work exists, so an MCP-only or dependency-free
manifest with a scripts: block is refused too (the commit-order owner
exposes refuse_denied_scripts; the pipeline keeps its own call).
- The resolver reuses a node already resolved no deeper before applying
max_depth, so A -> B with B also direct at depth 1 is not cut.
apm-spec-waiver: install-time enforcement of existing org policy fields that audit already enforces; no new OpenAPM contract.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical policy checks allow denied installs to mutate durable state and miss service-created files that subsequently fail audit, while the depth-limit test incorrectly expects rejection of a compliant dependency graph.
…the chain (#4826)
- The too-deep row seeded p-child directly, so p-parent -> p-child
correctly reused the depth-1 node; seed it with an unrelated package.
- That diamond is now its own installed-CLI row (installs, audit agrees),
replacing the component resolver test the assertion ratchet rejects.
- The scripts pre-fetch check returns before reading the context when
the manifest has no scripts.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The scripts refusal occurs after hook reconciliation can delete deployed files and update lock rows outside the deploy journal, leaving destructive changes that rollback cannot restore.
…4826)
Without dependencies.max_depth below its default, _check_transitive_depth
reads no rows, so the policy gate no longer builds them for every
install. A stand-in dependency list (MagicMock) made that build grow
without bound and killed the Linux unit shard.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The scripts-policy check runs too late, allowing a refused install to permanently remove existing hooks and perform remote package or marketplace requests before denial.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Admission checks omit later hook and Kiro MCP configuration writes, allowing installs to violate blocking unmanaged-file policy and leave a final state that audit rejects.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
MCP configuration writes occur after unmanaged-files checks, allowing installs to succeed under blocking policies while leaving unclaimed files that fail audit.
…k.py
Keeps policy_checks.py within the module length limit after the merge with
main; no behaviour change.
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The resolver can incorrectly reject valid mixed-ref dependency graphs at the depth limit because its reuse lookup checks the declared ref rather than the canonical first-wins package selection.
#4826 is fixed on main (#4853): its strict xfail becomes a required install refusal naming the policy field and the file.
Co-authored-by: Copilot App <[email protected]>
…C, v0.38 sweep)
Stacked on corpus train 6 (51e2e65, main f53aa79). Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
deny, self_defined, max_depth, require_resolution, source_attribution,
unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
transitive MCP trust, content types); the #4826 install refusal is required
now that #4853 fixed it on main.
- strict known cells for an MCP entry of a runtime no longer targeted (#4784)
and a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
install writes nothing (#4790), hook bundle approval pin (#4688), a registry
URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
provenance-unknown x denied-executable (#4767), audit --ci judges locked
content with apm_modules gone, merged-hook entry detection end to end (#4798).
Ledger regenerated (baseline 3, known-failing 1, required 2419).
Co-authored-by: Copilot App <[email protected]>
…C, v0.38 sweep)
Stacked on corpus train 6 (2e8592d, main acb0423). Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
deny, self_defined, max_depth, require_resolution, source_attribution,
unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
transitive MCP trust, content types); the #4826 install refusal is required
now that #4853 fixed it on main.
- strict known cells for an MCP entry of a runtime no longer targeted (#4784)
and a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
install writes nothing (#4790), hook bundle approval pin (#4688), a registry
URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
provenance-unknown x denied-executable (#4767), audit --ci judges locked
content with apm_modules gone, merged-hook entry detection end to end (#4798).
Ledger regenerated (baseline 3, known-failing 1, required 2419).
Co-authored-by: Copilot App <[email protected]>
…C, v0.38 sweep)
Stacked on corpus train 6 (2e8592d) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
deny, self_defined, max_depth, require_resolution, source_attribution,
unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
transitive MCP trust, content types); the #4826 install refusal is required
now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
install writes nothing (#4790), hook bundle approval pin (#4688), a registry
URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
provenance-unknown x denied-executable (#4767), audit --ci judges locked
content with apm_modules gone, merged-hook entry detection end to end (#4798).
Ledger regenerated (baseline 3, known-failing 1, required 2419).
Co-authored-by: Copilot App <[email protected]>
…C, v0.38 sweep)
Stacked on corpus train 6 (699e837) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
deny, self_defined, max_depth, require_resolution, source_attribution,
unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
transitive MCP trust, content types); the #4826 install refusal is required
now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
install writes nothing (#4790), hook bundle approval pin (#4688), a registry
URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
provenance-unknown x denied-executable (#4767), audit --ci judges locked
content with apm_modules gone, merged-hook entry detection end to end (#4798).
Review folds: I5 admits the compile record only as a regular file and its
newly created ancestor directories; run/preview, content-types, plugin-root
hook, lane C fresh twin and source-machine bundle identity oracles tightened.
Ledger regenerated (baseline 3, known-failing 1, required 2419).
Co-authored-by: Copilot App <[email protected]>
…C, v0.38 sweep)
Stacked on corpus train 6 (699e837) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
deny, self_defined, max_depth, require_resolution, source_attribution,
unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
transitive MCP trust, content types); the #4826 install refusal is required
now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
install writes nothing (#4790), hook bundle approval pin (#4688), a registry
URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
provenance-unknown x denied-executable (#4767), audit --ci judges locked
content with apm_modules gone, merged-hook entry detection end to end (#4798).
Review folds: I5 admits the compile record only as a regular file and its
newly created ancestor directories; run/preview, content-types, plugin-root
hook, lane C fresh twin, source-machine bundle identity, self_defined warn and
hook bundle update oracles tightened. U-USER-SCOPE-ORG-POLICY removes explicit
user-scope cells only: the four scope-free T1 bin x denied-dependency cells are
required, witnessed by the project matrix refusals.
Ledger regenerated (baseline 3, known-failing 1, required 2423).
Co-authored-by: Copilot App <[email protected]>
…C, v0.38 sweep)
Stacked on corpus train 6 (699e837) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
deny, self_defined, max_depth, require_resolution, source_attribution,
unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
transitive MCP trust, content types); the #4826 install refusal is required
now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
install writes nothing (#4790), hook bundle approval pin (#4688), a registry
URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
provenance-unknown x denied-executable (#4767), audit --ci judges locked
content with apm_modules gone, merged-hook entry detection end to end (#4798).
Review folds: I5 admits the compile record only as a regular file and its
newly created ancestor directories; run/preview, content-types, plugin-root
hook, lane C fresh twin, source-machine bundle identity, self_defined warn and
hook bundle update oracles tightened; the self_defined warn row is a real
warn-mode policy now and is strict known on #5070. U-USER-SCOPE-ORG-POLICY removes explicit
user-scope cells only: the four scope-free T1 bin x denied-dependency cells are
required, witnessed by the project matrix refusals.
Ledger regenerated (baseline 3, known-failing 1, required 2423).
Co-authored-by: Copilot App <[email protected]>
…C, v0.38 sweep)
Stacked on corpus train 6 (699e837) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
deny, self_defined, max_depth, require_resolution, source_attribution,
unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
transitive MCP trust, content types); the #4826 install refusal is required
now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
install writes nothing (#4790), hook bundle approval pin (#4688), a registry
URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
provenance-unknown x denied-executable (#4767), audit --ci judges locked
content with apm_modules gone, merged-hook entry detection end to end (#4798).
Review folds: I5 admits the compile record only as a regular file and its
newly created ancestor directories; run/preview, content-types, plugin-root
hook, lane C fresh twin, source-machine bundle identity, self_defined warn and
hook bundle update oracles tightened; the self_defined warn row is a real
warn-mode policy now and is strict known on #5070; the #4826 refusal row checks rollback. U-USER-SCOPE-ORG-POLICY removes explicit
user-scope cells only: the four scope-free T1 bin x denied-dependency cells are
required, witnessed by the project matrix refusals.
Ledger regenerated (baseline 3, known-failing 1, required 2423).
Co-authored-by: Copilot App <[email protected]>
…C, v0.38 sweep)
Stacked on corpus train 6 (699e837) and merged with main fc1866b. Cars:
- policy promise rows in test_policy_promises.py with a control each (scripts
deny, self_defined, max_depth, require_resolution, source_attribution,
unmanaged_files, fail_on_drift, pinned constraint, explicit includes,
transitive MCP trust, content types); the #4826 install refusal is required
now that #4853 fixed it on main.
- an MCP entry of a runtime no longer targeted (#4784) takes main's required
row (its fix landed); a strict known cell for a codex hook copy that cannot read its plugin's skill (#2824).
- lane C incremental deploy differential (kit from #4849).
- v0.38.0 sweep: compile dependency-policy run and preview (#4734), a converged
install writes nothing (#4790), hook bundle approval pin (#4688), a registry
URL on a local host (#4521).
- burndown: a denied local bundle is refused unwritten (#4646), present-
provenance-unknown x denied-executable (#4767), audit --ci judges locked
content with apm_modules gone, merged-hook entry detection end to end (#4798).
Review folds: I5 admits the compile record only as a regular file and its
newly created ancestor directories; run/preview, content-types, plugin-root
hook, lane C fresh twin, source-machine bundle identity, self_defined warn and
hook bundle update oracles tightened; the self_defined warn row is a real
warn-mode policy now and is strict known on #5070; the #4826 refusal row checks rollback; no-write stamps add the POSIX change time. U-USER-SCOPE-ORG-POLICY removes explicit
user-scope cells only: the four scope-free T1 bin x denied-dependency cells are
required, witnessed by the project matrix refusals.
Ledger regenerated (baseline 3, known-failing 1, required 2423).
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
TL;DR.
apm installnow applies three org-policy fields that onlyapm audit --cienforced. Underenforcement: blockit refuses and leaves durable state as it found it; underwarnit warns. Each refusal names the policy field and the fix, and is reported through the same policy reporter as dependency violations.Fixes #4826
manifest.scripts: denyscripts:block in the manifest install acts on (--rootand-gincluded) is refused before resolution fetches anything, also when there is no APM dependency work (e.g. an MCP-only manifest).commit_gate.refuse_denied_scripts, on the parsed manifest; called by the install command andcheck_before_resolvedependencies.max_depthphases/resolve.py,apm_resolver.depth_limit_chains,policy_gate(depth_lockfile)unmanaged_files.action: deny.apm/content records its claims, while the deploy journal can still restore every deployed file and discard the staged lockfile.--dry-runpreviews the verdict.commit_gate.check_before_release(pipeline, afterpost_deps_local)Violations go through
emit_check_violations.CheckResult.violation_subjects(policy/models.py) owns the category → (policy field, fix) map, so there is no second projection. The audit checks (_check_scripts_policy,_check_unmanaged_files,_check_transitive_depth) are unchanged, so install and audit reach one verdict.Note
Scope authority: the apm-scope record on #4826 (Regent ruling, option A). PGM rulings: resolver stop plus a full-graph gate check for max_depth; plan-claimed paths excluded for unmanaged files; scripts enforced at install only.
apm runis out of scope and is a follow-up.Important
unmanaged_files is judged after deploy, then rolled back (accepted deviation from "before any write"). Deciding pre-write would need the full write plan, but only prompts/agents/commands/instructions can be planned without touching disk (
commit_gate._GATED_PRIMITIVES, #4381). Skills, hooks and merged configs cannot. A pre-write scan would therefore refuse legitimate adoptions (for example, reinstalling after a lost lockfile) or miss skipped files.InstallTransactionjournals the prior state of every path at the write seam (install: lazy pre-write snapshot at the integrator write chokepoint #4282). On refusal it restores those bytes, removes the target roots it created and discards the staged lockfile. The hash and content-scan gates already rely on this same journal.DeployJournal.restorereturns each path it could not restore; the transaction warnsDeploy restore path <path>: could not restore: ..., keeps the pre-install copies, and the command still exits 1.Trade-offs
APM_CACHE_DIR/git) may keep entries after an unmanaged or max_depth refusal, as after every post-acquisition refusal. It is content-addressed, shared across concurrent installs, and never trusted without the lockfile hash.deploy_v1and the rest of the cache stay byte-identical (QL ruling).policy_v1stays byte-identical when the policy is already cached; a cold or expired read caches the policy, as every policy-enforced command does.Issue and approved scope
Issue: Fixes #4826
Human scope-approval comment: apm-scope:v1 record on #4826.
Does this PR complete the issue? Yes, except
apm run(follow-up, outside the ruled scope).Type of change
Testing
tests/integration/test_install_policy_fields_lifecycle.py(installed CLI, lifecycle world, P-INV-I7). Every offending row first seeds a compliant install under the policy, so a lockfile, its deployment ledger and the policy cache exist. It then asserts project, HOME, APM_HOME and cache byte-identical after the refusal; onlycache/git/is excluded, and only where noted.--rootaudit --ciagrees.apm/local contentaudit --cipasses--dry-rununmanageddependencies.max_depthand the chainUnit rows in
tests/unit/install/test_commit_gate.pycover project and-gscripts refusal with noapm.ymlat the deploy root.test_apm_resolver_edge_cases.pycovers the diamond (A, B direct; A → B) undermax_depth: 1.Follow-ups (Copilot threads answered): run the max_depth cutoff before marketplace expansion; recompute unselected packages' depths on selective installs (pre-existing); scan pre-existing drift on installs with no APM work (audit covers it today);
apm runandmanifest.scripts.Validation commands and results
The full lint mirror, unit suites and the lifecycle module run in CI. Local runs were limited by the host load rule.
How to test
manifest: {scripts: deny}+ ascripts:block →apm install <pkg>exits 1 namingmanifest.scripts: deny; nothing fetched.dependencies: {max_depth: 1}+ a package with a transitive dependency → refused namingdependencies.max_depthand the chain.unmanaged_files: {action: deny}+ a hand-written.github/instructions/x.instructions.md→ refused naming the file;--dry-runpreviews it; nothing changes.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}regeneratedCo-authored-by: Copilot [email protected]