Skip to content

Commit 864c440

Browse files
feat: wire strategy: wrap into register_commands — substitute {CORE_TEMPLATE} for all agent types
1 parent bb67923 commit 864c440

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/specify_cli/agents.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@ def register_commands(
414414
content = source_file.read_text(encoding="utf-8")
415415
frontmatter, body = self.parse_frontmatter(content)
416416

417+
if frontmatter.get("strategy") == "wrap":
418+
from .presets import _substitute_core_template
419+
short_name = cmd_name
420+
if short_name.startswith("speckit."):
421+
short_name = short_name[len("speckit."):]
422+
body = _substitute_core_template(body, short_name, project_root, self)
423+
417424
frontmatter = self._adjust_script_paths(frontmatter)
418425

419426
for key in agent_config.get("strip_frontmatter_keys", []):

tests/test_presets.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,3 +3093,53 @@ def test_substitute_core_template_no_op_when_core_missing(self, project_dir):
30933093
result = _substitute_core_template(body, "nonexistent", project_dir, registrar)
30943094
assert result == body
30953095
assert "{CORE_TEMPLATE}" in result
3096+
3097+
def test_register_commands_substitutes_core_template_for_wrap_strategy(self, project_dir):
3098+
"""register_commands substitutes {CORE_TEMPLATE} when strategy: wrap."""
3099+
from specify_cli.agents import CommandRegistrar
3100+
3101+
# Set up core command template
3102+
core_dir = project_dir / ".specify" / "templates" / "commands"
3103+
core_dir.mkdir(parents=True, exist_ok=True)
3104+
(core_dir / "specify.md").write_text(
3105+
"---\ndescription: core\n---\n\n# Core Specify\n\nCore body here.\n"
3106+
)
3107+
3108+
# Create a preset command dir with a wrap-strategy command
3109+
cmd_dir = project_dir / "preset" / "commands"
3110+
cmd_dir.mkdir(parents=True, exist_ok=True)
3111+
(cmd_dir / "speckit.specify.md").write_text(
3112+
"---\ndescription: wrap test\nstrategy: wrap\n---\n\n"
3113+
"## Pre\n\n{CORE_TEMPLATE}\n\n## Post\n"
3114+
)
3115+
3116+
commands = [{"name": "speckit.specify", "file": "commands/speckit.specify.md"}]
3117+
registrar = CommandRegistrar()
3118+
3119+
# Use a generic agent that writes markdown to commands/
3120+
agent_dir = project_dir / ".claude" / "commands"
3121+
agent_dir.mkdir(parents=True, exist_ok=True)
3122+
3123+
# Patch AGENT_CONFIGS to use a simple markdown agent pointing at our dir
3124+
import copy
3125+
original = copy.deepcopy(registrar.AGENT_CONFIGS)
3126+
registrar.AGENT_CONFIGS["test-agent"] = {
3127+
"dir": str(agent_dir.relative_to(project_dir)),
3128+
"format": "markdown",
3129+
"args": "$ARGUMENTS",
3130+
"extension": ".md",
3131+
"strip_frontmatter_keys": [],
3132+
}
3133+
try:
3134+
registrar.register_commands(
3135+
"test-agent", commands, "test-preset",
3136+
project_dir / "preset", project_dir
3137+
)
3138+
finally:
3139+
registrar.AGENT_CONFIGS = original
3140+
3141+
written = (agent_dir / "speckit.specify.md").read_text()
3142+
assert "{CORE_TEMPLATE}" not in written
3143+
assert "# Core Specify" in written
3144+
assert "## Pre" in written
3145+
assert "## Post" in written

0 commit comments

Comments
 (0)