Repository navigation
fix(deps): agree with prune on bundled skills after repo-to-subdirectory switch - #3612
Conversation
…ory switch (#2926) `apm deps list` flagged skills bundled inside a declared whole-repository skill bundle as orphaned while `apm prune` kept them, and switching that dependency to `path:` subdirectory dependencies left the old checkout in place, so its embedded skills were reported as orphaned by `deps list` and `prune` while `deps tree` showed a clean graph. - deps list routes bundled-descendant classification through the shared `_find_orphaned_packages` owner, keeping its stricter warning for a real undeclared package above a declared subdirectory. - install cleanup trims a released whole-repository copy to the retained subdirectory packages nested inside it, via the same owner, so the result matches a fresh subdirectory install. - The orphan-selection architecture guard now also covers both call sites. Reproduction by @maro114510. apm-spec-waiver: apm_modules cache-layout trim and deps list classification only; no normative lockfile, manifest or deployment behavior change Co-authored-by: Copilot App <[email protected]>
) Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved bugs can hide deeper undeclared parent packages, falsely flag bundled skills after repository-casing changes, and leave case-distinct files behind during cleanup.
3 open issues
What changed in this PR
This PR addresses #2926 by using shared orphan-selection logic for bundled skills and trimming stale repository content when dependencies switch to subdirectory installs.
Changes:
- Update
deps listto recognize skills bundled within declared packages. - Trim released repository checkouts while preserving retained subdirectory dependencies.
- Add regression tests and architecture guards, and update command documentation.
| File | Description |
|---|---|
tests/unit/install/test_repo_to_subdirectory_switch.py |
Adds project- and user-scope regressions for bundled skills and subdirectory transitions. |
tests/integration/test_architecture_owner_rule_mutations.py |
Tests that new call sites cannot bypass the shared selector. |
src/apm_cli/install/phases/cleanup.py |
Shares retained-path calculation and adds superseded-checkout trimming. |
src/apm_cli/commands/deps/cli.py |
Uses shared orphan selection when classifying installed packages. |
scripts/architecture_linter/checks/install_uninstall_and_resolution.py |
Extends selector-routing checks to listing and checkout trimming. |
packages/apm-guide/.apm/skills/apm-usage/commands.md |
Updates agent-facing dependency-listing and prune guidance. |
docs/src/content/docs/reference/cli/prune.md |
Documents cleanup during repository-to-subdirectory transitions. |
docs/src/content/docs/reference/cli/deps.md |
Documents bundled-skill orphan classification. |
CHANGELOG.md |
Records the classification and checkout-cleanup fixes. |
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]>
Copilot and the advisory panel found edge cases in the shared-selector routing introduced for #2926; all sit inside the PR's stated scope. - deps list now uses prune's installed-case lookup (preserve_installed_case=True), so a re-cased declaration such as Owner/Repo installed under owner/repo keeps its bundled skills out of the orphan list (Copilot inline on src/apm_cli/commands/deps/cli.py:397). - The real-orphan warning for an undeclared package above a declared subdirectory now holds at every depth, not only the first three path components (Copilot inline on src/apm_cli/commands/deps/cli.py:403). - The superseded-root trim groups every physical entry under its case-folded key, so case-distinct siblings (README.md / readme.md) on a case-sensitive filesystem are all removed (Copilot inline on src/apm_cli/install/phases/cleanup.py:458). - Partial installs compute released/retained install paths once and share them between the dropped-copy removal and the trim (performance-expert follow-up). - Regression tests: re-cased bundle, deeper standalone parent, case-distinct trim, selector-input fallback, and a CLI-level deps list / deps tree / prune agreement check in project and user scope (test-coverage-expert follow-ups). Co-authored-by: Copilot App <[email protected]>
Drives the #2926 reporter sequence with the apm binary: install a whole repository skill bundle, switch to two path: dependencies, run apm update, then assert the old checkout is trimmed to the requested subdirectories and deps list, deps tree and prune agree. Addresses the test-coverage-expert follow-up on lifecycle-tier coverage for the destructive trim; mutation-break verified by neutering the trim. Co-authored-by: Copilot App <[email protected]>
deps list still reports a real package installed above a declared subdirectory dependency, which prune keeps because it contains that dependency, so "orphaned only when prune would select it" overstated the agreement. Also notes that a GitHub owner/repository casing change no longer orphans bundled skills. Doc drift caused by the folded review findings. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 0 | 0 | Both new call sites route through _find_orphaned_packages; extracted helper and trim safety boundary are sound. |
| Test Coverage Expert | 0 | 3 | 0 | Component tests defend the fix with real filesystem; CLI-level and lifecycle-tier coverage and the silent fallback branch lack regression traps. |
| Performance Expert | 0 | 1 | 0 | Steady-state cost near zero; partial drops computed released/retained install paths twice. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 4 follow-ups
- [Test Coverage Expert] Add a lifecycle-binary test for
_trim_superseded_package_rootsafter a repo-to-subdirectory switch. -- Destructive-write path with component coverage only. - [Test Coverage Expert] Add a unit test for the
except Exceptionfallback in_resolve_scope_deps. -- A broken helper would silently revert deps list to the [BUG] deps list incorrectly reports embedded skills as orphaned for subdirectory dependencies #2926 bug shape. - [Test Coverage Expert] Add a CLI test proving deps list, deps tree and prune agree after the switch. -- The Done-when was proven at component tier only.
- [Performance Expert] Compute
_released_and_retained_install_pathsonce on partial installs and share it. -- Avoids doubling path construction.
Recommendation
Ship after the folds land and CI is green.
Merge-worker folds (pushed in 2c0bf6d)
All four follow-ups and all three Copilot items sit inside this PR's surface. They were folded into this PR, not deferred:
- (copilot) deps list uses prune's installed-case lookup (
preserve_installed_case=True) -- resolved in d519bc2. - (copilot) The real-orphan warning for a package above a declared subdirectory holds at every depth -- resolved in d519bc2.
- (copilot) The trim groups case-distinct entries per case-folded key and removes all of them -- resolved in d519bc2.
- (panel) Released/retained install paths are computed once and shared on partial installs -- resolved in d519bc2.
- (panel) Regression tests for the selector-input fallback, plus CLI-level deps list / deps tree / prune agreement in project and user scope -- resolved in d519bc2.
- (panel) Lifecycle-binary test of the reporter sequence (
install, switch topath:,update, thendeps list/deps tree/prune) -- resolved in 0a90953. - (doc drift) deps list docs no longer claim strict equality with prune for a real parent package above a declared subdirectory -- resolved in 48c4528.
Mutation-break: each new test fails with its guard removed (installed-case flag, uncapped ancestors, fallback branch, trim loop, per-key grouping on a case-sensitive volume) and passes once restored.
Full per-persona findings
Python Architect
No findings.
Test Coverage Expert
- [recommended] Scope-record done-when proven at component tier only; install-pipeline floor is integration-with-fixtures via CLI. at
tests/unit/install/test_repo_to_subdirectory_switch.py
No CLI-level scenario drivesapm deps list/apm pruneafter a repo-to-subdirectory switch.
Proof (missing at):tests/integration/test_wave6_deps_cli_coverage.py::test_deps_list_prune_agree_after_repo_to_subdirectory_switch[devx] - [recommended] Silent except-Exception fallback in
_resolve_scope_depshas no regression trap. atsrc/apm_cli/commands/deps/cli.py:407
If a future change breaks the helper, deps list silently reverts to the [BUG] deps list incorrectly reports embedded skills as orphaned for subdirectory dependencies #2926 bug shape.
Proof (missing at):tests/unit/install/test_repo_to_subdirectory_switch.py::test_resolve_scope_deps_fallback_on_helper_failure_preserves_pre_fix_behavior[devx] - [recommended]
_trim_superseded_package_rootsperforms destructive deletion; no lifecycle-state-machine test through the real binary. atsrc/apm_cli/install/phases/cleanup.py
Proof (missing at):tests/integration/test_required_lifecycle_state_machine.py::test_required_repo_to_subdirectory_switch_trims_only_superseded_content[devx,secure-by-default]
Performance Expert
- [recommended] Partial install calls
_released_and_retained_install_pathstwice with an identical released set. atsrc/apm_cli/install/phases/cleanup.py:186
Suggested: Compute once in_run_cleanupand pass the result to both consumers.
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.
… test CI on the PR head failed in two places: - Spec conformance: test_lockfile_reconciles_inactive_target_paths_fail_safe drives cleanup.run with a SimpleNamespace context that has no apm_modules_dir; the new released/retained path helper now reads it with getattr and skips when absent, like dependency_graph. - Lifecycle smoke: test_prune_retains_installed_ancestor_after_root_declaration_removed encoded the pre-#2926 contract in which removing the whole-repo root declaration left its full checkout as the ancestor of a still-declared nested path: dependency. That is exactly the transition #2926 scopes ("must not leave a stale whole-repository checkout"), so install now trims the released root to the nested dependency it hosts. The test is renamed and asserts the trimmed state; prune still finds nothing to remove and leaves later personal content untouched. apm-spec-waiver: cleanup-phase hardening and test contract update for the #2926 apm_modules trim; no OpenAPM-observable lockfile, manifest, or deployment change Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 0 | 0 | All four delta items are architecturally sound: single owner for released/retained paths, safe partial-context guard, grouped trim, warning-only uncapped ancestor set. |
| Test Coverage Expert | 0 | 0 | 0 | All three prior gaps closed at stated tiers; retained-root lifecycle rename is faithful; case-sensitive skip guard valid for Linux CI. |
| Performance Expert | 0 | 0 | 0 | Duplicate path computation removed on partial installs; grouped trim and uncapped ancestor set are negligible at realistic dep counts. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Recommendation
All prior follow-ups are folded and verified, the Copilot items are resolved, and CI is green. The delta panel found nothing new. The lifecycle-test rename captures the intended behavior change (install trims superseded roots instead of deferring to prune). No open items remain.
Folded in this run
- (copilot) deps list uses prune's installed-case lookup (
preserve_installed_case=True) -- resolved in d519bc2. - (copilot) The real-orphan warning for a package above a declared subdirectory holds at every depth -- resolved in d519bc2.
- (copilot) The trim groups case-distinct entries per folded key and removes every one -- resolved in d519bc2.
- (panel) Released/retained install paths computed once and shared on partial installs -- resolved in d519bc2.
- (panel) Unit test for the deps list selector-input fallback -- resolved in d519bc2.
- (panel) CLI-level deps list / deps tree / prune agreement after the switch, in project and user scope -- resolved in d519bc2.
- (panel) Lifecycle-binary test of the reporter sequence -- resolved in 0a90953.
- (doc drift) deps list docs state the stricter real-parent warning truthfully -- resolved in 48c4528.
- (CI) Partial cleanup contexts without
apm_modules_dirare tolerated (spec conformance), and the retained-root lifecycle test is updated to the [BUG] deps list incorrectly reports embedded skills as orphaned for subdirectory dependencies #2926 contract -- resolved in a6196d7.
Copilot signals reviewed
src/apm_cli/commands/deps/cli.py:397-- LEGIT: deps list did not use prune's installed-case lookup, so a re-cased bundle's skills were flagged (resolved in d519bc2).src/apm_cli/commands/deps/cli.py:403-- LEGIT: the depth-3 ancestor cap silently cleared a deeper undeclared parent package (resolved in d519bc2).src/apm_cli/install/phases/cleanup.py:458-- LEGIT: case-folded dict keys dropped case-distinct entries on case-sensitive filesystems (resolved in d519bc2).
Regression-trap evidence (mutation-break gate)
test_declared_bundle_with_changed_repo_casing_lists_skills_as_bundled-- deletedpreserve_installed_case=True; test FAILED as expected; guard restored.test_undeclared_parent_deeper_than_repo_root_stays_orphaned-- restored the depth-3 ancestor cap; test FAILED as expected; guard restored.test_deps_list_falls_back_to_declared_paths_when_selector_inputs_fail-- narrowed the fallbackexcept Exception; test FAILED as expected; guard restored.test_cli_deps_list_and_prune_agree_after_switch[project,user]andtest_required_repo_to_subdirectory_switch_trims_superseded_checkout-- neutered the trim loop; tests FAILED as expected; guard restored.test_switch_trims_case_distinct_entries_on_case_sensitive_filesystem-- kept one entry per folded key (run on a case-sensitive APFS volume); test FAILED as expected; guard restored.
Lint contract
The full CI lint mirror is silent on the merged head: ruff check and ruff format --check (src, tests, architecture linter scripts), pylint R0801 at 10.00/10, scripts/lint-auth-signals.sh, and scripts/lint-architecture-boundaries.sh.
CI
All required checks are green at d342fb7: Lint, Build & Test shards, Lifecycle Smoke shards, Spec conformance gate, Windows Compatibility Gate, Architecture Ratchet Contracts, CodeQL, and license/cla. One CI fix iteration was needed.
Mergeability status
| PR | head SHA | CEO stance | iters | folds | defers | Copilot rounds | CI | mergeable | mergeStateStatus | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3612 | d342fb7 |
ship_now | 2 | 9 | 0 | 2 | green | MERGEABLE | BLOCKED | pending required review |
Convergence
2 outer iterations; 2 Copilot rounds. Final panel stance: ship_now. Ready for maintainer review.
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.
…dir-orphans Co-authored-by: Copilot App <[email protected]>
Avoids landing-order conflicts with other queued PRs. Co-authored-by: Copilot App <[email protected]>
Lane L: main merged for landing
This comment was generated by an AI agent (Lane L landing desk) on behalf of Daniel Meppiel (@danielmeppiel). |

Description
TL;DR
apm deps listnow agrees withapm pruneon orphaned content when a dependency switches from a whole repository (yoshiko-pg/difit) to subdirectory dependencies (path: skills/difit). Two causes are fixed.deps listfalsely flagged skills bundled inside a declared whole-repo package, andinstall/updateleft the old whole-repo checkout behind the new subdirectory installs. Both decisions now go through the single registered orphan selector,_find_orphaned_packages.Thanks to Atsuki Nohira (@maro114510) for the report and for supplying the missing before-state (a repository-level install first, then the switch). That transition is what made this reproducible.
Note
Local preflight skipped by maintainer instruction (2026-11-12); CI is the gate.
Problem (WHY)
Reproduced on
main(2794714d) with the realyoshiko-pg/difit@82a765c0and an isolatedHOME:apm deps list -greports all 8 embedded skills (skills/*,.claude/skills/*,.codex/skills/*) as orphaned, whileapm prunereportsNo orphaned packages found.deps listonly knew "declared path or ancestor of one", not "content bundled inside a declared package". Prune's selector already keeps bundled descendants.path:deps +apm update -g --yes): the old checkout stays atapm_modules/yoshiko-pg/difit/as the parent of the new installs.deps listandpruneflag 6 dot-dir skills, whiledeps treeshows a clean graph.prunewould delete only those 6 marker directories and leaveREADME,src/, and other files behind.apm_modulescopy (prune owns that). When the dropped root is the parent of retained installs,_find_orphaned_packageskeeps it as an ancestor, so nothing could ever clean it.Why it matters: the scope record requires that "
deps list,deps treeandpruneagree, and no false orphan warnings"..github/instructions/architecture.instructions.mdalso requires that every call site "routes THROUGH that owner instead of re-deriving the answer locally".Approach (WHAT)
deps listasks the shared_find_orphaned_packagesowner whether a scanned package lies inside an expected install path, the same expected setprunebuilds. Its stricter warning for a real, undeclared package above a declared subdirectory is kept.owner/repohostingowner/repo/skills/a) down to those subtrees. The same owner selects what to remove, so the result matches a fresh subdirectory install.install-deployment-orphan-selectionarchitecture guard now covers both new call sites, with a mutation test for each.Implementation (HOW)
src/apm_cli/commands/deps/cli.py:_resolve_scope_depsbuilds_build_expected_install_paths(get_all_apm_dependencies(), lockfile), as prune does. A scanned package is orphaned only if the existing rule flags it and the owner selects it (or it is a strict ancestor of an expected path, which preserves the real-orphan warning). If computing expected paths fails, it falls back to the old behavior.src/apm_cli/install/phases/cleanup.py: adds_trim_superseded_package_roots, called after orphan deployed-file cleanup for full installs (released = previous keys not intended and not retained by refused cleanup) and partial installs (partial_dropped - pinned). It skips any released root that is itself retained, lies inside a retained package, or hosts nothing. Those roots keep today's contract and are left forapm prune. Entries are compared case-folded so a case-insensitive filesystem never loses a retained subtree. Deletions go throughsafe_rmtree/ensure_path_within, and a failure becomes a diagnostic warning. The retained-path computation is shared with_remove_dropped_package_dirs(no R0801 duplication).scripts/architecture_linter/checks/install_uninstall_and_resolution.py: registersdeps/cli.py::_resolve_scope_depsandcleanup.py::_trim_superseded_package_rootsas required routes through_find_orphaned_packages.reference/cli/deps.md,reference/cli/prune.md, and theapm-usageskill'scommands.md(deps listandprunerows), plus a CHANGELOG entry.Diagram
Legend: the install cleanup phase after this PR. The new trim (boxed) runs after deployed-file orphan cleanup and selects through the same owner as
prune.flowchart LR A["previous lock: yoshiko-pg/difit"] --> B["released keys"] C["new graph: difit/skills/difit, difit/skills/difit-review"] --> D["retained install paths"] B --> E{"released root hosts retained paths?"} D --> E E -->|"no"| F["untouched; apm prune owns it"] E -->|"yes"| G["NEW: _trim_superseded_package_roots"] G --> H["_find_orphaned_packages"] H --> I["apm_modules == fresh subdirectory install"] style G stroke-width:3pxTrade-offs
deps listandprune(the 6 stale skills), andapm pruneremoves them. Non-package files in that old root remain, but they are inert and never reported..apm-pinremains. The existing cache-pin self-heal (#1137) re-marks the released root after cleanup, because the directory still exists. Verified harmless: switching back toyoshiko-pg/difitre-downloads the full repository (28 entries).deps listrow shape unchanged. A marker-less whole-repo bundle still lists its embedded skills as rows, now with sourcegithubinstead oforphaned. Folding them into a single root row would drop their skill counts, so it is out of scope.Benefits
deps list,deps tree, andpruneagreeing.apm_modules/holds only the requested subdirectories, plus one pin file, instead of the 28-entry stale checkout.deps list, and the trim, guarded statically.Issue and approved scope
Issue: Fixes #2926
Human scope-approval comment: #2926 (comment) (Decision: approve, Area: project, Review contact: Daniel Meppiel (@danielmeppiel))
Does this PR complete the issue, or what remains? Yes. It meets every Done-when item: the reporter's sequence ends with all three commands agreeing; the stale checkout is cleaned by
update; the regression test covers project and user scope; and the related docs are updated. It makes no prune model, flag, or lockfile schema change.Type of change
Testing
Scenario evidence
tests/unit/install/test_repo_to_subdirectory_switch.py::test_repo_level_install_lists_embedded_skills_as_bundledpath:switch trims the stale checkout;deps list+ prune agree (project + user scope)...::test_switch_to_subdirectory_deps_trims_superseded_checkoutapm prune...::test_released_root_without_hosted_subdirectory_is_left_for_prune...::test_retained_whole_repo_package_is_never_trimmed...::test_undeclared_standalone_parent_of_declared_subdirectory_stays_orphanedtests/integration/test_architecture_owner_rule_mutations.py::test_orphan_selection_guard_rejects_{deps_list,superseded_root_trim}_bypassMutation-break: neutering the trim (
for orphan in []) fails both scope variants of the switch test. Forcing the olddeps listrule fails both repo-level variants. Dropping the ancestor clause fails the real-orphan test.Commands and results
pytest tests/unit/install/test_repo_to_subdirectory_switch.py -p no:xdistpytest tests/unit/install/phases/test_cleanup_phase.py tests/unit/install/test_partial_subtree_reconciliation.py(+ new file)pytest tests/unit/commands/test_deps_cli_{helpers,phase3,phase3w4,alias_readers,branch_coverage,cli_surface}.pypytest tests/unit/test_deps_list_tree_info.py tests/unit/test_orphan_announce_parity.py+ ancestor/standalone suitespytest tests/integration/test_architecture_owner_rule_mutations.py -k orphan_selectionruff check/ruff format --check(CI paths, ruff 0.15.12)pylint --enable=R0801 --min-similarity-lines=10 ...bash scripts/lint-auth-signals.sh,bash scripts/lint-architecture-boundaries.shstr(relative_to)guardsReal-repo end-to-end (
HOME=/tmp/...,yoshiko-pg/difit@82a765c0, this branch):How to test
export HOME=$(mktemp -d); mkdir -p ~/.apm && cd ~/.apm, then writeapm.ymlwithdependencies: {apm: [yoshiko-pg/difit]}and runapm install -g.apm deps list -g. Expect no orphan warning (onmain: 8).git: yoshiko-pg/difit/path: skills/difitandpath: skills/difit-reviewentries, then runapm update -g --yes.apm deps list -g,apm deps tree -g, andapm prune --dry-run. Expect no orphans (onmain: 6), andfind ~/.apm/apm_modules -type fshows only the two skills plus one root pin.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedapm_modulescache layout anddeps listclassification, with no lockfile, manifest, or deployment contract change. The commit carries anapm-spec-waiver:line for Mode B.Co-authored-by: Copilot [email protected]