-
Notifications
You must be signed in to change notification settings - Fork 7.7k
feat: implement preset wrap strategy #2189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bb67923
864c440
df00038
6a24268
49c83d2
9b32c61
3336fd4
1007dcb
7a11b37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| description: "Self-test wrap command — pre/post around core" | ||
| strategy: wrap | ||
| --- | ||
|
|
||
| ## Preset Pre-Logic | ||
|
|
||
| preset:self-test wrap-pre | ||
|
|
||
| {CORE_TEMPLATE} | ||
|
|
||
| ## Preset Post-Logic | ||
|
|
||
| preset:self-test wrap-post |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,10 @@ | |
| import shutil | ||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
| from typing import Optional, Dict, List, Any | ||
| from typing import TYPE_CHECKING, Optional, Dict, List, Any | ||
|
|
||
| if TYPE_CHECKING: | ||
| from .agents import CommandRegistrar | ||
| from datetime import datetime, timezone | ||
| import re | ||
|
|
||
|
|
@@ -27,6 +30,48 @@ | |
| from .extensions import ExtensionRegistry, normalize_priority | ||
|
|
||
|
|
||
| def _substitute_core_template( | ||
| body: str, | ||
| cmd_name: str, | ||
| project_root: "Path", | ||
| registrar: "CommandRegistrar", | ||
| ) -> "tuple[str, dict]": | ||
| """Substitute {CORE_TEMPLATE} with the body of the installed core command template. | ||
|
|
||
| Args: | ||
| body: Preset command body (may contain {CORE_TEMPLATE} placeholder). | ||
| cmd_name: Full command name (e.g. "speckit.git.feature" or "speckit.specify"). | ||
| project_root: Project root path. | ||
| registrar: CommandRegistrar instance for parse_frontmatter. | ||
|
|
||
| Returns: | ||
| A tuple of (body, core_frontmatter) where body has {CORE_TEMPLATE} replaced | ||
| by the core template body and core_frontmatter holds the core template's parsed | ||
| frontmatter (so callers can inherit scripts/agent_scripts from it). Both are | ||
| unchanged / empty when the placeholder is absent or the core template file does | ||
| not exist. | ||
| """ | ||
| if "{CORE_TEMPLATE}" not in body: | ||
| return body, {} | ||
|
|
||
| # Derive the short name (strip "speckit." prefix) used by core command templates. | ||
| short_name = cmd_name | ||
| if short_name.startswith("speckit."): | ||
| short_name = short_name[len("speckit."):] | ||
|
|
||
| resolver = PresetResolver(project_root) | ||
| # Try the full command name first so extension commands | ||
| # (e.g. speckit.git.feature -> extensions/git/commands/speckit.git.feature.md) | ||
| # are found before falling back to the short name used by core commands | ||
|
kennedy-whytech marked this conversation as resolved.
|
||
| # (e.g. specify -> templates/commands/specify.md). | ||
| core_file = resolver.resolve(cmd_name, "command") or resolver.resolve(short_name, "command") | ||
| if core_file is None: | ||
|
Comment on lines
+62
to
+68
|
||
| return body, {} | ||
|
|
||
| core_frontmatter, core_body = registrar.parse_frontmatter(core_file.read_text(encoding="utf-8")) | ||
| return body.replace("{CORE_TEMPLATE}", core_body), core_frontmatter | ||
|
|
||
|
|
||
| @dataclass | ||
| class PresetCatalogEntry: | ||
| """Represents a single entry in the preset catalog stack.""" | ||
|
|
@@ -759,6 +804,13 @@ def _register_skills( | |
| content = source_file.read_text(encoding="utf-8") | ||
| frontmatter, body = registrar.parse_frontmatter(content) | ||
|
|
||
| if frontmatter.get("strategy") == "wrap": | ||
| body, core_frontmatter = _substitute_core_template(body, cmd_name, self.project_root, registrar) | ||
| frontmatter = dict(frontmatter) | ||
| for key in ("scripts", "agent_scripts"): | ||
| if key not in frontmatter and key in core_frontmatter: | ||
| frontmatter[key] = core_frontmatter[key] | ||
|
|
||
| original_desc = frontmatter.get("description", "") | ||
| enhanced_desc = SKILL_DESCRIPTIONS.get( | ||
| short_name, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.