Skip to content

Recompose or retire surviving composed skills on preset removal - #5579

Open
yxshee wants to merge 2 commits into
github:mainfrom
yxshee:fix/preset-remove-recompose-skill
Open

yxshee wants to merge 2 commits into
github:mainfrom
yxshee:fix/preset-remove-recompose-skill

Conversation

@yxshee

@yxshee yxshee commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Minimal replacement for #5013 as discussed with @mnriem.

Removing a preset that serves as the base or a middle layer of another preset's prepend, append, or wrap command leaves the removed preset's instructions in the active agent's SKILL.md (Claude, Codex, Copilot with --skills), while command-file agents are recomposed onto the remaining stack. Because the composed skill is owned by the surviving preset at the top of the chain, _unregister_skills() restores nothing for the removed preset and _reconcile_skills() previously skipped revisiting the active skills directory.

Changes (src/specify_cli/presets/_manager_skills.py)

  • Track composing winners whose stacks still resolve (composed_winners) and composing winners whose stacks no longer have a base layer (unresolved_winners).
  • On removal (extra_skills_dirs is not None), identify active-directory skills that still carry the winning preset's metadata.source: preset:<pack_id> marker via _skills_owned_by_preset() (reading through FileHelper).
  • Recompose those surviving skills while restricting writes via only_skill_names in _register_skills() so hand-edited skills and user-owned legacy (speckit.<cmd>) siblings are left untouched.
  • When no base layer remains to compose onto, remove the survivor's stale .composed/<cmd>.md cache and the generated SKILL.md that still carries the survivor's marker via unlink_in_directory(), leaving any other files in the skill directory intact.

Deliberately left out of this minimal PR (can be follow-up PRs if desired): native-skill aliases of composed commands, historical (inactive) agent directories, file-mode preservation on rewrite, and partial-registration edge cases.

Tests (tests/specify_cli/presets/test_manager_skills.py)

Added 6 positive and negative tests:

  • Positive: test_remove_base_preset_recomposes_surviving_composed_skill (removing base layer recomposes surviving skill onto core)
  • Positive: test_remove_middle_preset_drops_its_layer_from_composed_skill (removing middle layer drops its fragment from surviving skill)
  • Positive: test_remove_sole_base_preset_retires_stale_composed_skill (removing sole base with no fallback removes stale .composed cache and SKILL.md)
  • Negative: test_remove_base_preset_preserves_hand_edited_composed_skill (hand-edited skill without preset marker is not overwritten)
  • Negative: test_remove_sole_base_preset_keeps_hand_edited_skill (hand-edited unbacked skill is not deleted)
  • Positive + Negative: test_remove_base_preset_preserves_user_owned_legacy_skill (modern skill recomposes while user-owned legacy speckit.specify/SKILL.md sibling is untouched)

Verification

Before/after regression check on macOS arm64, Python 3.14.6:

  • Before (f61648db, base commit): 4 failed, 2 passed on the 6 new tests (the 4 behavioral regressions fail; the 2 hand-edited preservation guards pass).
  • After (a8a92291): 6 passed on the 6 new tests.
  • PATH="$PWD/.venv/bin:$PATH" LC_ALL=en_US.UTF-8 COLUMNS=1000 .venv/bin/python -m pytest -n auto tests/specify_cli/presets tests/test_presets.py tests/integrations tests/specify_cli/integrations tests/specify_cli/extensions tests/specify_cli/bundles tests/test_extension_skills.py -q: 7,627 passed, 9 skipped
  • uvx ruff@0.15.0 check src tests: passed
  • .venv/bin/python .github/scripts/check_file_helper_migration.py --base f61648db --head HEAD: passed
  • .venv/bin/specify --help and git diff --check: passed

AI Disclosure

  • Commit a8a92291 was authored on behalf of @yxshee by Claude Code (model: Claude Mythos 5.2, autonomous mode), covering the implementation and tests.
  • Verification on macOS arm64 (Python 3.14.6), PR description drafting, and PR submission were performed on behalf of @yxshee by Antigravity (model: Gemini 4 Neon (XHigh), autonomous mode).

Removing a preset that is the base, or a middle layer, of another
preset's prepend/append/wrap command left the removed preset's text in
the active agent's SKILL.md (Claude, Codex, Copilot with --skills).
Command-file agents were recomposed onto the new stack, so `specify
preset resolve` disagreed with what the skill agent ran.

The composed skill is owned by the surviving preset at the top of the
chain. _unregister_skills() restores nothing for the removed preset, and
_reconcile_skills() only revisited the active skills directory when that
restore had touched it, so the recomposed .composed/<cmd>.md was never
rendered into the skill.

After a removal:

- Recompose the active directory's skill for a command whose winning
  layer composes, while the skill still carries the winning preset's
  source marker. A hand-edited skill is left alone.
- Write only the skill names the directory manages, so a user-owned
  legacy (speckit.<cmd>) sibling is not overwritten.
- When no base is left to compose onto, remove the survivor's stale
  .composed cache and the SKILL.md that still carries its marker, as
  command-file agents unregister the command. Other files in the skill
  directory stay.

New file reads and removals go through FileHelper and
unlink_in_directory.

Assisted-by: Claude Code (model: Claude Mythos 5.2, autonomous)
@yxshee
yxshee requested a review from mnriem as a code owner November 25, 2026 21:17
Copilot AI adaptive review requested due to automatic review settings November 25, 2026 21:17

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

An active issue allows preset removal to delete a surviving preset’s cache and owned SKILL.md when its remaining content cannot be read or decoded, requiring preservation logic and a regression test.

1 open issue
What changed in this PR

This PR fixes stale composed skills after preset removal. It refreshes surviving skills in the active agent directory or retires generated output when no base remains, while preserving user-owned content.

Changes:

  • Track resolved and unresolved composition winners during reconciliation.
  • Restrict rewrites and deletions using preset ownership markers and allowed skill names.
  • Add six regression and preservation tests covering base removal, middle-layer removal, and user-owned skills.

Review and suggested fix generated by GitHub Copilot (model: unknown, autonomous) for the requesting reviewer. Tests were not rerun; regression results are supplied in the PR description.

File Description
tests/​specify_cli/​presets/​test_manager_skills.py Adds composition-removal regressions and user-content preservation checks.
src/​specify_cli/​presets/​_manager_skills.py Recomposes or retires surviving owned skills and limits rewrite targets.

Review effort: Balanced (adaptive)

@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Nov 25, 2026
…able

When PresetResolver.resolve_content() returns None for a composing command
during _reconcile_skills(), distinguish a genuinely missing replace base
from an unreadable or undecodable surviving layer:

- Retire the survivor's .composed cache and owned SKILL.md only when no
  replace layer remains in the stack.
- When a replace base still exists, skip reconciliation cleanly without
  deleting the survivor's cache or owned SKILL.md and without adding the
  command to preset_cmds.
- Add regression tests in test_manager_skills.py covering undecodable base
  and composing layers, OSError base reads, and removing a higher-priority
  replace preset over an unreadable composing stack.

Assisted-by: Antigravity (model: Gemini 4 Neon (XHigh), autonomous)
@yxshee

yxshee commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Addressed Copilot's review comment in dcba729:

  • Updated PresetManager._reconcile_skills() in src/specify_cli/presets/_manager_skills.py so that when resolve_content() returns None for a composing command, the surviving .composed/<cmd>.md cache and owned SKILL.md are retired only if no replace layer remains in layers. When a replace layer is still present, reconciliation for that command is skipped without deleting the cache, deleting SKILL.md, or queueing the command in preset_cmds.
  • Added regression tests in tests/specify_cli/presets/test_manager_skills.py covering undecodable surviving base and composing layers, PermissionError on the base layer, and removing a higher-priority replace preset over an unreadable composing stack (verified failing before the fix and passing after).
  • Re-ran pytest across preset, integration, extension, and bundle suites (8,688 passed, 161 skipped), uvx ruff@0.15.0 check src tests, .github/scripts/check_file_helper_migration.py, and .venv/bin/specify --help.

Posted on behalf of @yxshee by Antigravity (model: Gemini 4 Neon (XHigh), autonomous mode; code fix, regression tests, local verification, and summary).

Copilot AI adaptive review requested due to automatic review settings November 25, 2026 22:04

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

Preset removal couples composition resolution, shared-cache invalidation, and ownership-gated skill rewrites or deletions, requiring human review of the interacting lifecycle and filesystem effects.

No open issues 🎉

1 resolved since last review

Review effort: Balanced (adaptive)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants