Skip to content

feat: implement preset wrap strategy#2189

Open
kennedy-whytech wants to merge 5 commits intogithub:mainfrom
kennedy-whytech:kennedy-whytech-feat-preset-wrap-strategy
Open

feat: implement preset wrap strategy#2189
kennedy-whytech wants to merge 5 commits intogithub:mainfrom
kennedy-whytech:kennedy-whytech-feat-preset-wrap-strategy

Conversation

@kennedy-whytech
Copy link
Copy Markdown

@kennedy-whytech kennedy-whytech commented Apr 12, 2026

Description

Implements strategy: wrap for preset commands, which was listed as a roadmap
item in presets/README.md. When a preset command sets strategy: wrap, the
{CORE_TEMPLATE} placeholder in its body is substituted with the body of the
installed core speckit command template at install time.

This lets preset authors add pre/post logic around core commands without
copy-pasting the entire command body — useful for extending frequently-updated
templates like /speckit.specify or /speckit.tasks. Personally, I find it neccessary.

Changes

  • src/specify_cli/presets.py — adds _substitute_core_template() helper;
    wires substitution into _register_skills (skills-backed agents like Claude)
  • src/specify_cli/agents.py — wires substitution into register_commands
    (all other agent types)
  • presets/self-test/ — adds a speckit.wrap-test command for E2E coverage
  • presets/README.md — marks wrap as implemented for command/template types

Test results

184 tests pass (tests/test_presets.py), including a new TestWrapStrategy
class with unit tests for the helper and an end-to-end install test.

Manual test results

Agent: Claude Code | OS/Shell: macOS/zsh

Command tested Notes
specify preset install with strategy: wrap command {CORE_TEMPLATE} correctly substituted in written skill/command file

AI assistance disclosure

This PR was implemented with AI assistance (Claude Code) for code generation,
test writing, and commit messages. All changes were reviewed and verified
manually.

Testing

  • Tested locally with uv run specify --help
  • Ran existing tests with uv sync && uv run pytest
  • Tested with a sample project (if applicable)

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (describe below)

@kennedy-whytech kennedy-whytech requested a review from mnriem as a code owner April 12, 2026 14:35
@kennedy-whytech kennedy-whytech force-pushed the kennedy-whytech-feat-preset-wrap-strategy branch from 604b585 to 444daef Compare April 12, 2026 15:47
@mnriem mnriem requested a review from Copilot April 13, 2026 12:28
@mnriem mnriem self-assigned this Apr 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for strategy: wrap on preset-provided commands, enabling preset authors to inject pre/post content around an existing “core” command body via a {CORE_TEMPLATE} placeholder during command/skill registration.

Changes:

  • Introduces _substitute_core_template() and applies it during preset skill registration (_register_skills) and generic agent command registration (CommandRegistrar.register_commands).
  • Extends the self-test preset with a new speckit.wrap-test command and updates docs to mark wrap as implemented for commands.
  • Adds unit + E2E-style tests covering placeholder substitution and install behavior.
Show a summary per file
File Description
tests/test_presets.py Updates self-test manifest expectations; adds new TestWrapStrategy coverage.
src/specify_cli/presets.py Adds _substitute_core_template() and wires it into preset skill generation.
src/specify_cli/agents.py Wires wrap substitution into agent command registration.
presets/self-test/preset.yml Adds a new wrap-strategy command entry to the self-test preset.
presets/self-test/commands/speckit.wrap-test.md Adds a wrap command template using {CORE_TEMPLATE}.
presets/README.md Updates roadmap/docs to reflect wrap implemented for commands/artifacts.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 6/6 changed files
  • Comments generated: 1

Comment on lines +51 to +58
from specify_cli import _locate_core_pack
core_pack = _locate_core_pack()
if core_pack is not None:
core_file = core_pack / "commands" / f"{short_name}.md"
else:
# Source / editable install: look relative to the package root
repo_root = Path(__file__).parent.parent.parent
core_file = repo_root / "templates" / "commands" / f"{short_name}.md"
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

_substitute_core_template() doesn’t use project_root to locate the project’s installed core command templates under .specify/templates/commands (it only checks the packaged core_pack/commands or repo templates/commands). This breaks the stated behavior of wrapping the installed core template and will fail for commands that exist only in the project (e.g. wrap-test in the new tests). Consider resolving the core template path from project_root/.specify/templates/commands/<short_name>.md first (falling back to core_pack/repo only if missing), or otherwise remove/rename the project_root parameter/docstring to match actual behavior.

Suggested change
from specify_cli import _locate_core_pack
core_pack = _locate_core_pack()
if core_pack is not None:
core_file = core_pack / "commands" / f"{short_name}.md"
else:
# Source / editable install: look relative to the package root
repo_root = Path(__file__).parent.parent.parent
core_file = repo_root / "templates" / "commands" / f"{short_name}.md"
core_file = project_root / ".specify" / "templates" / "commands" / f"{short_name}.md"
if not core_file.exists():
from specify_cli import _locate_core_pack
core_pack = _locate_core_pack()
if core_pack is not None:
core_file = core_pack / "commands" / f"{short_name}.md"
else:
# Source / editable install: look relative to the package root
repo_root = Path(__file__).parent.parent.parent
core_file = repo_root / "templates" / "commands" / f"{short_name}.md"

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

@mnriem mnriem left a comment

Choose a reason for hiding this comment

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

Please address Copilot feedback. If not applicable, please explain why

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.

3 participants