Skip to content

fix(presets): reconcile command files after priority changes - #5113

Open
mikamikasuki wants to merge 4 commits into
github:mainfrom
mikamikasuki:fix/5087-reconcile-command-priority
Open

mikamikasuki wants to merge 4 commits into
github:mainfrom
mikamikasuki:fix/5087-reconcile-command-priority

Conversation

@mikamikasuki

Copy link
Copy Markdown
Contributor

Description

When a preset priority changes, the resolver can select a different command layer while the generated agent command file still contains the previous winner. Reconcile the affected command and skill artifacts against the full priority stack after updating the registry.

Closes #5087

Testing

  • The regression fails against main at 67e0f72 and passes with this change.
  • Preset tests: 744 passed, 1 skipped.
  • Ruff check and format checks pass for both changed files.
  • The regression invokes specify preset set-priority in a temporary Gemini project and verifies the generated command switches to the new winner.

AI Disclosure

  • I did use AI assistance (fill in the disclosure below)

AI disclosure: OpenAI Codex (GPT-6; reasoning effort not exposed in this task; autonomous); issue analysis, reproduction, code and regression-test generation, and validation.

@mikamikasuki
mikamikasuki requested a review from mnriem as a code owner October 25, 2026 02:38
@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Oct 25, 2026
@mnriem
mnriem requested a max review from Copilot October 26, 2026 13:56

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

Priority changes can still produce incorrect agent artifacts for disabled presets and convention-provided command layers.

3 open issues
What changed in this PR

Addresses #5087 by refreshing generated agent artifacts when preset set-priority changes command precedence.

Changes:

  • Reconciles affected commands and skills against the updated priority stack.
  • Adds best-effort failure warnings and a Gemini CLI regression verifying that generated command content switches winners.

Validation relies on the reported before-and-after results; tests were not rerun.

AI disclosure: GitHub Copilot (model unknown; automated review) generated this review for the requesting contributor.

File Description
tests/​specify_cli/​presets/​test_command_set_priority.py Adds a CLI regression for generated command refresh.
src/​specify_cli/​presets/​command_set_priority.py Adds command and skill reconciliation after priority updates.

Review effort: Max

@mnriem

mnriem commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

@mnriem mnriem added the author-awaiting Waiting on author response label Oct 26, 2026
Copilot AI max review requested due to automatic review settings November 16, 2026 01:43
@mikamikasuki

Copy link
Copy Markdown
Contributor Author

Review follow-up by @mikamikasuki with OpenAI Codex (GPT-6, autonomous). AI authored the review analysis, implementation, regression tests, and this summary.

Updated priority reconciliation to include convention-based command files and to leave artifacts untouched when the target preset is disabled. Added coverage for skills-mode rematerialization and for command reconciliation failures while preserving the saved priority and constitution reconciliation.

Validation: test_command_set_priority.py — 11 passed; git diff --check passed. Ruff was unavailable in the local environment.

Commit: 826038047afc22a3bab012f47038ab2e5d2b56f9.

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.

Comment on lines +82 to +84
command_names.extend(
path.stem for path in convention_commands.glob("*.md")
)
command_names = list(dict.fromkeys(command_names))
if command_names:
manager._reconcile_composed_commands(command_names)
manager._reconcile_skills(command_names)
@mnriem

mnriem commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

Copilot AI max review requested due to automatic review settings November 17, 2026 12:33
mac and others added 3 commits November 17, 2026 04:50
Assisted-by: OpenAI Codex (model: GPT-6, autonomous)
Assisted-by: OpenAI Codex (model: GPT-6, autonomous)
Assisted-by: OpenAI Codex (model: GPT-6, autonomous)
@mikamikasuki
mikamikasuki force-pushed the fix/5087-reconcile-command-priority branch from ac0093a to 8293cf4 Compare November 17, 2026 12:50

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

Composed-command cache writes can follow project-controlled symlinks and overwrite files outside the project when no lifecycle observer is installed.

9 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Convention overrides cannot replace existing core skills

src/​specify_cli/​presets/​_manager_skills.py:349

A convention-only override of an existing core skill is filtered out before this new rendering path: no preset has recorded its name in registered_skills, so dir_cmds is empty. In an initialized Claude project, changing the priority of an undeclared commands/speckit.specify.md therefore leaves the core skill unchanged. Admit existing skills in the active directory before this filter, while keeping historical directories restricted to tracked names, and cover the case without a manifest-declared competitor.

AI-generated review for the review requester by GitHub Copilot (model: unknown; autonomous); analysis and comment generation.

2 resolved since last review

Review effort: Max

Comment on lines +1163 to +1166
composed_dir = pack_dir / ".composed"
composed_dir.mkdir(parents=True, exist_ok=True)
composed_file = composed_dir / f"{cmd_name}.md"
_write_text(composed_file, composed, encoding="utf-8")
Comment on lines +1051 to +1052
record_written(written)
self._merge_pack_registered_commands(owner_id, written)
Comment on lines +368 to +373
convention_templates.append(
{
"name": cmd_name,
"type": "command",
"file": source_path.relative_to(pack_dir).as_posix(),
}
Comment on lines +1155 to +1158
if not layers[0]["path"].is_relative_to(pack_dir):
continue
for tmpl in manifest.templates:
if tmpl.get("name") == cmd_name and tmpl.get("type") == "command":
composed_dir = pack_dir / ".composed"
composed_dir.mkdir(parents=True, exist_ok=True)
composed_file = composed_dir / f"{cmd_name}.md"
_write_text(composed_file, composed, encoding="utf-8")
written = self._register_for_non_skill_agents(
registrar,
[{**tmpl, "file": f".composed/{cmd_name}.md"}],
manifest.id, pack_dir,
only_agent=only_agent, extra_agents=extra_agents,
)
record_written(written)
self._merge_pack_registered_commands(manifest.id, written)
registered = True
break
else:
owned_template = preset_template_for_path(
pack_id, pack_dir, layers[0]["path"], cmd_name
Comment on lines +101 to +103
if command_names:
manager._reconcile_composed_commands(command_names)
manager._reconcile_skills(command_names)
Comment on lines +204 to +218
manager.install_from_directory(convention, "0.1.5", priority=20)
manager.install_from_directory(declared, "0.1.5", priority=30)
command_file = commands_dir / "speckit.demo.toml"

with patch.object(Path, "cwd", return_value=project_dir):
result = CliRunner().invoke(
app,
["preset", "set-priority", "priority-convention-owner", "1"],
)
assert result.exit_code == 0, result.output
assert "BODY-A" in command_file.read_text()
registered = manager.registry.get("priority-convention-owner")[
"registered_commands"
]
assert "speckit.demo" in registered.get("gemini", [])
Comment on lines +254 to +256
manager.install_from_directory(convention, "0.1.5", priority=20)
manager.install_from_directory(declared, "0.1.5", priority=30)
skill_file = project_dir / ".claude" / "skills" / "speckit-demo" / "SKILL.md"
Copilot AI max review requested due to automatic review settings November 17, 2026 12:55
Track convention-based commands through install, priority changes, and removal, refresh active core skills safely, and guard composed cache writes against symlinks. Add regressions for reinstall, fallback restoration, core skill overrides, and cache traversal.

Assisted-by: OpenAI Codex (model: GPT-6, autonomous)

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

author-awaiting Waiting on author response 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.

[Bug]: specify preset set-priority does not update agent command files that are already written

3 participants