Skip to content

fix(run): apply the org dependency policy to auto-install and installed prompts - #4734

Merged
Daniel Meppiel (danielmeppiel) merged 20 commits into
mainfrom
danielmeppiel-run-policy-gate
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 20 commits into
mainfrom
danielmeppiel-run-policy-gate

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

Stacked on #4724: review only the top commit; this branch merges main after #4724 lands.

apm run and apm preview read prompt and skill files from installed packages without consulting org dependency policy. apm run <owner/repo/path> also auto-installed a virtual package (download plus an apm.yml entry) without the policy check install applies.

ScriptRunner._require_dependency_policy (core/script_runner.py) now judges:

  • the package that owns a prompt or skill being read, whether it sits under apm_modules or is a deployed file the lock records for that package;
  • a package auto-install is about to fetch, before anything is downloaded or declared.

It covers prompt discovery and _auto_compile_prompts, which both run and preview use.

Under enforcement: block it refuses with each package's reason and the catalog remediation (run-dependency-denied) before compiling or downloading anything. Under warn it warns and continues.

The installed-package enumeration moves next to the dependency check, as installed_dependency_subjects in install/exec_gate.py, so compile and run judge the same set.

Issue and approved scope

Issue: none; scope set by the maintainers. Maintainer ruling: every command that writes or reads agent context through installed packages applies the dependency policy.

Human scope-approval comment: approved by the maintainers.

Does this PR complete the issue, or what remains? It completes the run/preview surface; #4724 covers 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)

tests/unit/test_script_runner_dependency_policy.py covers:

  • a denied package's prompt, under apm_modules or as a deployed copy, is never compiled;
  • a project's own prompt compiles without resolving policy;
  • auto-install refuses before the downloader is called;
  • warn compiles and warns.

Four of these fail without the change.

Local results:

  • core, script runner and commands unit tests: 3842 passed;
  • runnable-prompt and script-runner integration tests: 254 passed;
  • lint contract: green.

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.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • N/A -- applies the existing dependency policy to more commands; no new contract.

apm-spec-waiver: applies the existing org dependency policy check to apm run and apm preview; no new contract.

…led content

apm compile now applies the dependency check install, update and uninstall
apply to the packages apm.lock.yaml records, routed through the trust
policy owner. When a recorded package is no longer allowed and the policy
enforces block, compile writes nothing and exits 1 naming the package;
under warn it warns and compiles.

Co-authored-by: Copilot App <[email protected]>
apm-spec-waiver: applies the existing org dependency policy check to apm compile; no new contract.

Co-authored-by: Copilot App <[email protected]>
…g dependency policy

Covers apm compile -g, manifest dependencies installed without a lock row,
local bundle staging, the redirected root of --root, and each --watch
recompile. The lifecycle model now expects compile to refuse, as install
does, under a dependency deny and when the org policy cannot be fetched
under fetch_failure_default: block.

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

apm run and apm preview now judge the package that owns a prompt or skill
they read (under apm_modules, or a deployed file the lock records) and any
package auto-install is about to download, with the dependency check
install applies. Under enforcement: block they refuse before compiling or
downloading anything; under warn they warn and continue. The installed
package enumeration moves beside that check so compile and run share it.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 11:04
apm-spec-waiver: applies the existing org dependency policy check to apm run and apm preview; no new contract.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added the full-integration Run the full integration suite (ci-integration.yml) on this PR before merge label Nov 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two critical policy bypasses remain: command tokens are checked instead of resolved prompt files, and undeclared dependency content can be discovered and executed without an attributable policy subject.

2 open issues
What changed in this PR

Extends the dependency-policy enforcement from #4724 to apm run and apm preview, checking installed package content and virtual-package auto-installation.

Changes:

  • Adds dependency-policy checks before prompt compilation and automatic downloads, with block and warn handling.
  • Shares installed-package enumeration between compile and run.
  • Adds regression tests, remediation text, and a changelog entry; the supplied diff also includes the compile-policy base changes.
File Description
tests/​unit/​test_script_runner_dependency_policy.py Tests prompt refusal, auto-install blocking, and warn behavior.
tests/​unit/​core/​test_remediation_w4_frozen_policy_catalog.py Records coverage for both refusal messages.
tests/​unit/​commands/​compile/​test_compile_dependency_policy.py Tests compile-policy enforcement from the stack base.
tests/​quality/​lifecycle_obligations.json Updates source evidence locations.
tests/​lifecycle/​security/​test_policy_outcomes.py Expects compile to refuse unusable blocking policy.
tests/​lifecycle/​machines/​_gate_matrix.py Adds compile to denied-dependency refusal expectations.
tests/​lifecycle/​generator/​rules.py Reanchors lifecycle evidence references.
tests/​integration/​test_compile_dependency_policy_lifecycle.py Exercises allowed and denied compile lifecycles.
src/​apm_cli/​install/​exec_gate.py Centralizes installed subjects and dependency judgments.
src/​apm_cli/​core/​script_runner.py Adds policy checks for discovered content and auto-installation.
src/​apm_cli/​core/​remediation.py Adds compile and run refusal guidance.
src/​apm_cli/​commands/​compile/​watcher.py Rechecks policy before watch recompilation.
src/​apm_cli/​commands/​compile/​cli.py Gates project and global compilation on policy.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Documents compile-policy enforcement.
docs/​src/​content/​docs/​reference/​cli/​compile.md Documents compile refusal behavior and exit status.
docs/​src/​content/​docs/​enterprise/​apm-policy.mdx Explains compile’s dependency-policy check.
changelog.d/​4734.fixed.md Announces run and preview policy enforcement.
changelog.d/​4724.fixed.md Announces the compile-policy base change.

Review effort: Balanced

Comment thread src/apm_cli/core/script_runner.py Resolved
Comment thread src/apm_cli/core/script_runner.py Resolved
…lved marketplace entries

Move the installed-package enumeration compile, run and preview share into
install/installed_dependencies.py, and skip a declared marketplace entry
before computing its install path (the lock names it once installed).

Co-authored-by: Copilot App <[email protected]>
A short prompt name resolves under .github/prompts, .apm/prompts or an
installed package; check that file's owning package, compare paths
case-insensitively, and cover the resolved forms in tests.

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

With --root the renderer combines the source manifest with the redirected
installation, so a package declared in one root and installed in the other
is judged too. Packages a pre-compile script installs are judged before
rendering. Re-anchor the compile citations the rules cite.

Co-authored-by: Copilot App <[email protected]>
… the lock's effective source

Right before rendering, under the lifecycle lock, compile judges the current
installed inventory again, whether or not pre-compile scripts ran, so a
package installed while it waited, or a source swapped under an existing
key, is judged. A warning is reported once per command. A declared entry
never replaces the lock's effective (replace:) source for the same key.

Co-authored-by: Copilot App <[email protected]>
The recheck under the lock re-reads the installed inventory with the policy
the early check resolved, so the policy outcome line prints once.

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

# Conflicts:
#	tests/lifecycle/generator/rules.py
#	tests/quality/lifecycle_obligations.json

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical policy bypasses allow run to consume undeclared filesystem packages and run/preview to forward installed SKILL.md content without checking whether the owning package is denied.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/core/script_runner.py Resolved
A watch session keeps one logger; reset the per-compilation policy cache
before each recompile so an allow-to-deny change stops the next render.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Legacy directory ownership claims fail to match descendant prompts, allowing deployed copies outside the package root to bypass policy resolution and compile even when their recorded owner is blocked.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Apply block checks to legacy deployed-skill descendants

src/​apm_cli/​core/​script_runner.py:841

Legacy deployed_skills entries become directory claims such as .github/skills/review/ (deps/lockfile.py:733-738), but exact-set intersection never matches a prompt below them. For a deployed copy outside the package root, run/preview therefore skip policy resolution and compile it even when its recorded owner is denied under block. Use shared ownership matching for directory descendants as well as exact files, and add a legacy-lock regression.

2 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 4a1f9fd into main Nov 22, 2026
66 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-run-policy-gate branch November 22, 2026 16:42
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
Generator rules cited product source as path:line (Ev(path, line, needle)
plus prose comments). A line moves on every edit to the cited file, so two
unrelated PRs that refresh it conflict in a merge train, and anchors drift.
Evidence now names a symbol: path::qualname for Python (function, class or
method with its decorators, or a module-level assignment) and path::heading
for Markdown (code fences ignored; a fence closes only with nothing after it),
resolved in tests/lifecycle/generator/anchors.py; the needle must appear
inside that symbol's span.

test_every_rule_cites_a_symbol_that_still_says_it rejects any file:line
citation in the generator sources and in the ledger's rule evidence. All 88
anchors on main (including #4711's and #4734's) were converted mechanically:
needle located, innermost enclosing symbol taken. Obligation statuses are
unchanged.

Fixes #4696

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
Conflicts: tests/lifecycle/generator/rules.py (#4734 aa085d6 re-anchored the
U-BIN cites) and the generated tests/quality/lifecycle_obligations.json. Kept
#4559's rules.py, re-anchored every cite to the merged tree, regenerated.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
Generator rules cited product source as path:line (Ev(path, line, needle)
plus prose comments). A line moves on every edit to the cited file, so two
unrelated PRs that refresh it conflict in a merge train, and anchors drift.
Evidence now names a symbol: path::qualname for Python (function, class or
method with its decorators, or a module-level assignment) and path::heading
for Markdown (code fences ignored; a fence closes only with nothing after it),
resolved in tests/lifecycle/generator/anchors.py; the needle must appear
inside that symbol's span.

test_every_rule_cites_a_symbol_that_still_says_it rejects any file:line
citation in the generator sources and in the ledger's rule evidence. All 88
anchors on main (including #4711's and #4734's) were converted mechanically:
needle located, innermost enclosing symbol taken. Obligation statuses are
unchanged.

Fixes #4696

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…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]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…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]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…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]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…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]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…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]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…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]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…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]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-integration Run the full integration suite (ci-integration.yml) on this PR before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants