Skip to content

fix(install): retire a native Claude plugin when apm.yml drops claude (#4744) - #4751

Merged
Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-fix-4744-plugin-bin-narrow
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-fix-4744-plugin-bin-narrow

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

At user scope, a Claude plugin that ships bin/ is activated natively: APM deploys the plugin root to ~/.agents/plugins/<pkg>/, registers it in ~/.claude/settings.json, and records a native_plugin row in the lockfile. When the user narrowed targets: from [copilot, claude] to [copilot], the next apm install -g --trust-bin reported "No changes" and kept the plugin root (including bin/), its Claude registration and its lock record.

Cause: _attach_native_plugins (install/phases/lockfile.py) carries the prior native_plugin record forward whenever this run's targets exclude claude. That carry-forward is correct for a one-shot install -g --target codex, where apm.yml still declares claude and the plugin must survive. It was wrong when apm.yml itself dropped claude.

Fix, in the lockfile phase, using target contraction's rule (manifest_reconcile._dropped_target_of: a target that is neither declared in apm.yml nor active this run is dropped):

  • New _retire_undeclared_native_plugins runs on the final merged lock, after _maybe_merge_partial. When apm.yml declares targets without claude and claude is not active, it clears every native_plugin record, so a partial install also retires untouched plugins. The existing registrar (reconcile_claude_plugins) then retires the plugin root, catalog entry and Claude settings declaration. claude_plugins/registrar.py and native_plugins/ are not changed, so this composes with feat(native): project-scope native plugins for Claude and Copilot (#3921, #3896) #4559.
  • apm lock (lockfile-only) skips it: it never touches deployed state, so the records stay and the roots remain owned until the next install.
  • The rule does not read manifest_targets, so a lock write that refreshed the declaration cannot hide the drop. This came from review.

Unchanged: one-shot --target runs (test_claude_native_hook_lifecycle.py keeps asserting the plugin survives install -g --target codex), auto-detect manifests (no declaration means nothing is dropped), widening, and the U-BIN pin (plugin_bin_deployable and the bin/ writer are untouched).

Issue and approved scope

Issue: Fixes #4744

Human scope-approval comment: none posted yet when this PR opened; the change follows the issue's Expected behavior exactly. The review contact is the Regent-assigned lead.

Does this PR complete the issue, or what remains? Completes the behavior. The issue names a strict known cell tests/lifecycle/scenarios/test_user_scope.py::test_a_target_change_keeps_a_plugin_bin_only_while_claude_is_declared[multi-narrowed]. That module is not on main (it lives in the unmerged QL corpus train 5), so this PR adds its own failing-before cell on main: test_ownership_siblings.py::test_target_narrow_retires_a_user_scope_plugin_bin. Once this lands, the train-5 strict cell XPASSes and must be flipped to required when that train rebases; the QL lead has been notified.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)
promise: P-OWN-target-scoped-deployed-file-contraction -- narrowing targets removes only the dropped target's deployed state (source: src/apm_cli/install/manifest_reconcile.py)
cell: OP=install|lock|partial-install SRC=git PRIM=bin SCOPE=user GATE=allowed TGT=multi-narrowed   owner: install/phases/lockfile.py with the manifest_reconcile contraction rule
instrument: target scenario -> tests/lifecycle/scenarios/test_ownership_siblings.py::test_target_narrow_retires_a_user_scope_plugin_bin (new: the issue's witness module is not on main)
oracles: [I1-I9 via the scenario kit, exact changed set, snapshot-absence of bin/, lock text, Claude settings]  decisive: not (home / _PLUGIN_BIN).exists()
failing-before: pytest <node> on main 899d17b4 -> AssertionError: dropping claude left the plugin bin ... No changes -- install state already up to date
passing-after: pytest <node> (3 params: install, lock-then-install, partial-install) -> 3 passed
guard+mutation: n/a     ledger: 4744
hints executed: none printed
Command Result
pytest tests/lifecycle/scenarios/test_ownership_siblings.py::test_target_narrow_retires_a_user_scope_plugin_bin (real binary) passed; fails on main as above
pytest -n 2 on the 69 unit, integration and lifecycle modules touching dropped_target_files, manifest_targets, native_plugin or Claude native activation 3050 passed, 3 skipped, 1 xfailed
pytest tests/quality/test_lifecycle_bug_ledger.py 2 passed
uvx [email protected] check / format --check (CI paths) clean
pylint R0801, scripts/lint-auth-signals.sh, scripts/lint-architecture-boundaries.sh clean
scripts/check_complexity_ratchet.py --base-ref <main> clean
python -m tests.quality.taxonomy --changed clean
File-length guard (max src file) 2100 lines (hook_integrator.py, untouched)
tests/spec_conformance/mode_b_detector.sh waived by commit trailer (bug fix, no new normative surface)

Bug-ledger row: tests/fixtures/lifecycle_bug_ledger/bugs/4744.json.

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)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

apm-spec-waiver: bug fix that retires a native Claude plugin when apm.yml drops claude, matching existing target contraction (#4517); no new normative surface.

apm-spec-waiver: bug fix that retires a native Claude plugin when apm.yml drops claude, matching existing target contraction (#4517); no new normative surface.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 13:52

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 findings show that removing the Claude target can leave its plugin registration untracked or enabled across lockfile-only and partial installs, while updated target records prevent later installs from detecting the contraction.

2 open issues
What changed in this PR

This PR addresses #4744 by retiring user-scope native Claude plugins when apm.yml drops claude, while preserving them for one-shot target overrides.

Changes:

  • Centralizes detection of dropped manifest targets.
  • Uses that detection to stop carrying forward native Claude plugin ownership.
  • Adds a lifecycle regression test, bug-ledger entry, and changelog fragment.
File Description
tests/​lifecycle/​scenarios/​test_ownership_siblings.py Tests plugin retirement after narrowing user-scope targets.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4744.json Records the bug and its regression test.
src/​apm_cli/​install/​phases/​lockfile.py Suppresses native plugin carry-forward when Claude is dropped.
src/​apm_cli/​install/​manifest_reconcile.py Shares prior-declaration logic for target contraction.
changelog.d/​4751.fixed.md Documents the user-visible cleanup fix.

Review effort: Balanced

Comment thread src/apm_cli/install/phases/lockfile.py Resolved
Comment thread src/apm_cli/install/phases/lockfile.py Resolved
…aude is undeclared (#4744)

Review fold: apply the target-contraction rule (claude neither declared in
apm.yml nor active) to the final merged lock, so a partial install retires
untouched plugins; apm lock keeps the records since it never touches deployed
state. Reverts the manifest_targets-based rule: a refreshed declaration must
not hide the drop.

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.

🟡 Changes recommended

Frozen installs can miss native-only target mismatches and retain stale state, while retirement lacks regression coverage for preserving user-edited plugin files.

3 open issues
2 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/install/phases/lockfile.py Resolved
Comment thread src/apm_cli/install/phases/lockfile.py Resolved
…aude plugins (#4744)

Review fold for #4751:
- target_governance.target_retired is the single dropped-target predicate;
  manifest_reconcile._dropped_target_of and the native plugin retirement in
  phases/lockfile.py both use it.
- dropped_target_files includes native Claude plugin roots, so install
  --frozen refuses and audit --ci reports a dropped claude (as for files, #4517).
- Scenario: an edited plugin bin/ is kept and reported while ownership and the
  Claude registration retire (scope control); frozen refusal changes nothing.

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.

🟡 Changes recommended

A critical lockfile reconciliation issue can hide pending native-plugin retirement from frozen preflight and audit checks, and the documented retention rule is outdated.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/install/phases/lockfile.py Resolved

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

Human assessment is needed because shared lockfile objects can lose native-plugin ownership during dependency rescue, leaving plugin roots and settings behind after their lockfile records are removed.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

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.

🟢 Approval recommended

No active review issues remain for the native Claude plugin-retirement change.

No open issues 🎉

Review effort: Balanced

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

# Conflicts:
#	docs/src/content/docs/consumer/install-plugins.md

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

A critical target-attribution bug causes frozen preflight and audit to miss retired native ownership when a Copilot-only project switches to Codex.

1 open issue

Review effort: Balanced

…lared (#4744)

Review fold: attribution prefers a harness the lock's manifest_targets
recorded, so the #4517 precedence filter in dropped_target_files keeps a
project plugin root whose only recorded harness was copilot.

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.

🟢 Approval recommended

No active review issues remain for the native-plugin cleanup change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 178b730 into main Nov 22, 2026
74 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-fix-4744-plugin-bin-narrow branch November 22, 2026 23:37
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
… regenerate

Keeps #4843's native observation (a root half plus the enabledPlugins declaration half, native_gaps). Builds _surface_hits on train 5's entry-aware surfaces (JsonEntry, MergedHooks) and _observable. projected_cells keeps #4843's native projection plus the shared-root loose skill (#4559). #4751 fixed #4744, so the user-scope bin target-change cell drops its strict known and is required (known 9 -> 8, L15).

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] install keeps a Claude plugin's bin/ under ~/.agents/plugins after claude is removed from user-scope targets

2 participants