Skip to content

Commit 69ee7a8

Browse files
Copilotmnriem
andauthored
feat(presets): Pluggable preset system with catalog, resolver, and skills propagation (#1787)
* Initial plan * feat(templates): add pluggable template system with packs, catalog, resolver, and CLI commands Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com> * test(templates): add comprehensive unit tests for template pack system Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com> * feat(presets): pluggable preset system with template/command overrides, catalog, and resolver - Rename 'template packs' to 'presets' to avoid naming collision with core templates - PresetManifest, PresetRegistry, PresetManager, PresetCatalog, PresetResolver in presets.py - Extract CommandRegistrar to agents.py as shared infrastructure - CLI: specify preset list/add/remove/search/resolve/info - CLI: specify preset catalog list/add/remove - --preset option on specify init - Priority-based preset stacking (--priority, lower = higher precedence) - Command overrides registered into all detected agent directories (17+ agents) - Extension command safety: skip registration if target extension not installed - Multi-catalog support: env var, project config, user config, built-in defaults - resolve_template() / Resolve-Template in bash/PowerShell scripts - Self-test preset: overrides all 6 core templates + 1 command - Scaffold with 4 examples: core/extension template and command overrides - Preset catalog (catalog.json, catalog.community.json) - Documentation: README.md, ARCHITECTURE.md, PUBLISHING.md - 110 preset tests, 253 total tests passing * feat(presets): propagate command overrides to skills via init-options - Add save_init_options() / load_init_options() helpers that persist CLI flags from 'specify init' to .specify/init-options.json - PresetManager._register_skills() overwrites SKILL.md files when --ai-skills was used during init and corresponding skill dirs exist - PresetManager._unregister_skills() restores core template content on preset removal - registered_skills stored in preset registry metadata - 8 new tests covering skill override, skip conditions, and restore * fix: address PR check failures (ruff F541, CodeQL URL substring) - Remove extraneous f-prefix from two f-strings without placeholders - Replace substring URL check in test with startswith/endswith assertions to satisfy CodeQL incomplete URL substring sanitization rule * fix: address Copilot PR review comments - Move save_init_options() before preset install so skills propagation works during 'specify init --preset --ai-skills' - Clean up downloaded ZIP after successful preset install during init - Validate --from URL scheme (require HTTPS, HTTP only for localhost) - Expose unregister_commands() on extensions.py CommandRegistrar wrapper instead of reaching into private _registrar field - Use _get_merged_packs() for search() and get_pack_info() so all active catalogs are searched, not just the highest-priority one - Fix fetch_catalog() cache to verify cached URL matches current URL - Fix PresetResolver: script resolution uses .sh extension, consistent file extensions throughout resolve(), and resolve_with_source() delegates to resolve() to honor template_type parameter - Fix bash common.sh: fall through to directory scan when python3 returns empty preset list - Fix PowerShell Resolve-Template: filter out dot-folders and sort extensions deterministically * fix: narrow empty except blocks and add explanatory comments * fix: address Copilot PR review comments (round 2) - Fix init --preset error masking: distinguish "not found" from real errors - Fix bash resolve_template: skip hidden dirs in extensions (match Python/PS) - Fix temp dir leaks in tests: use temp_dir fixture instead of mkdtemp - Fix self-test catalog entry: add note that it's local-only (no download_url) - Fix Windows path issue in resolve_with_source: use Path.relative_to() - Fix skill restore path: use project's .specify/templates/commands/ not source tree - Add encoding="utf-8" to all file read/write in agents.py - Update test to set up core command templates for skill restoration * fix: remove self-test from catalog.json (local-only preset) * fix: address Copilot PR review comments (round 3) - Fix PS Resolve-Template fallback to skip dot-prefixed dirs (.cache) - Rename _catalog to _catalog_name for consistency with extension system - Enforce install_allowed policy in CLI preset add and download_pack() - Fix shell injection: pass registry path via env var instead of string interpolation * fix: correct PresetError docstring from template to preset * Removed CHANGELOG requirement * Applying review recommendations * Applying review recommendations * Applying review recommendations * Applying review recommendations --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com>
1 parent c883952 commit 69ee7a8

32 files changed

+5446
-403
lines changed

β€ŽAGENTS.mdβ€Ž

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ The toolkit supports multiple AI coding assistants, allowing teams to use their
1010

1111
---
1212

13-
## General practices
14-
15-
- Any changes to `__init__.py` for the Specify CLI require a version rev in `pyproject.toml` and addition of entries to `CHANGELOG.md`.
16-
1713
## Adding New Agent Support
1814

1915
This section explains how to add support for new AI agents/assistants to the Specify CLI. Use this guide as a reference when integrating new AI tools into the Spec-Driven Development workflow.

β€ŽCHANGELOG.mdβ€Ž

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ Recent changes to the Specify CLI and templates are documented here.
77
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
99

10+
## [Unreleased]
11+
12+
### Added
13+
14+
- feat(presets): Pluggable preset system with preset catalog and template resolver
15+
- Preset manifest (`preset.yml`) with validation for artifact, command, and script types
16+
- `PresetManifest`, `PresetRegistry`, `PresetManager`, `PresetCatalog`, `PresetResolver` classes in `src/specify_cli/presets.py`
17+
- CLI commands: `specify preset search`, `specify preset add`, `specify preset list`, `specify preset remove`, `specify preset resolve`, `specify preset info`
18+
- CLI commands: `specify preset catalog list`, `specify preset catalog add`, `specify preset catalog remove` for multi-catalog management
19+
- `PresetCatalogEntry` dataclass and multi-catalog support mirroring the extension catalog system
20+
- `--preset` option for `specify init` to install presets during initialization
21+
- Priority-based preset resolution: presets with lower priority number win (`--priority` flag)
22+
- `resolve_template()` / `Resolve-Template` helpers in bash and PowerShell common scripts
23+
- Template resolution priority stack: overrides β†’ presets β†’ extensions β†’ core
24+
- Preset catalog files (`presets/catalog.json`, `presets/catalog.community.json`)
25+
- Preset scaffold directory (`presets/scaffold/`)
26+
- Scripts updated to use template resolution instead of hardcoded paths
27+
- feat(presets): Preset command overrides now propagate to agent skills when `--ai-skills` was used during init
28+
- feat: `specify init` persists CLI options to `.specify/init-options.json` for downstream operations
29+
- feat(extensions): support `.extensionignore` to exclude files/folders during `specify extension add` (#1781)
30+
1031
## [0.2.1] - 2026-03-11
1132

1233
### Changed
@@ -51,13 +72,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5172
- fix: release-trigger uses release branch + PR instead of direct push to main (#1733)
5273
- fix: Split release process to sync pyproject.toml version with git tags (#1732)
5374

54-
55-
## [Unreleased]
56-
57-
### Added
58-
59-
- feat(extensions): support `.extensionignore` to exclude files/folders during `specify extension add` (#1781)
60-
6175
## [0.2.0] - 2026-03-09
6276

6377
### Changed

β€Žpresets/ARCHITECTURE.mdβ€Ž

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Preset System Architecture
2+
3+
This document describes the internal architecture of the preset system β€” how template resolution, command registration, and catalog management work under the hood.
4+
5+
For usage instructions, see [README.md](README.md).
6+
7+
## Template Resolution
8+
9+
When Spec Kit needs a template (e.g. `spec-template`), the `PresetResolver` walks a priority stack and returns the first match:
10+
11+
```mermaid
12+
flowchart TD
13+
A["resolve_template('spec-template')"] --> B{Override exists?}
14+
B -- Yes --> C[".specify/templates/overrides/spec-template.md"]
15+
B -- No --> D{Preset provides it?}
16+
D -- Yes --> E[".specify/presets/β€Ήpreset-idβ€Ί/templates/spec-template.md"]
17+
D -- No --> F{Extension provides it?}
18+
F -- Yes --> G[".specify/extensions/β€Ήext-idβ€Ί/templates/spec-template.md"]
19+
F -- No --> H[".specify/templates/spec-template.md"]
20+
21+
E -- "multiple presets?" --> I["lowest priority number wins"]
22+
I --> E
23+
24+
style C fill:#4caf50,color:#fff
25+
style E fill:#2196f3,color:#fff
26+
style G fill:#ff9800,color:#fff
27+
style H fill:#9e9e9e,color:#fff
28+
```
29+
30+
| Priority | Source | Path | Use case |
31+
|----------|--------|------|----------|
32+
| 1 (highest) | Override | `.specify/templates/overrides/` | One-off project-local tweaks |
33+
| 2 | Preset | `.specify/presets/<id>/templates/` | Shareable, stackable customizations |
34+
| 3 | Extension | `.specify/extensions/<id>/templates/` | Extension-provided templates |
35+
| 4 (lowest) | Core | `.specify/templates/` | Shipped defaults |
36+
37+
When multiple presets are installed, they're sorted by their `priority` field (lower number = higher precedence). This is set via `--priority` on `specify preset add`.
38+
39+
The resolution is implemented three times to ensure consistency:
40+
- **Python**: `PresetResolver` in `src/specify_cli/presets.py`
41+
- **Bash**: `resolve_template()` in `scripts/bash/common.sh`
42+
- **PowerShell**: `Resolve-Template` in `scripts/powershell/common.ps1`
43+
44+
## Command Registration
45+
46+
When a preset is installed with `type: "command"` entries, the `PresetManager` registers them into all detected agent directories using the shared `CommandRegistrar` from `src/specify_cli/agents.py`.
47+
48+
```mermaid
49+
flowchart TD
50+
A["specify preset add my-preset"] --> B{Preset has type: command?}
51+
B -- No --> Z["done (templates only)"]
52+
B -- Yes --> C{Extension command?}
53+
C -- "speckit.myext.cmd\n(3+ dot segments)" --> D{Extension installed?}
54+
D -- No --> E["skip (extension not active)"]
55+
D -- Yes --> F["register command"]
56+
C -- "speckit.specify\n(core command)" --> F
57+
F --> G["detect agent directories"]
58+
G --> H[".claude/commands/"]
59+
G --> I[".gemini/commands/"]
60+
G --> J[".github/agents/"]
61+
G --> K["... (17+ agents)"]
62+
H --> L["write .md (Markdown format)"]
63+
I --> M["write .toml (TOML format)"]
64+
J --> N["write .agent.md + .prompt.md"]
65+
66+
style E fill:#ff5722,color:#fff
67+
style L fill:#4caf50,color:#fff
68+
style M fill:#4caf50,color:#fff
69+
style N fill:#4caf50,color:#fff
70+
```
71+
72+
### Extension safety check
73+
74+
Command names follow the pattern `speckit.<ext-id>.<cmd-name>`. When a command has 3+ dot segments, the system extracts the extension ID and checks if `.specify/extensions/<ext-id>/` exists. If the extension isn't installed, the command is skipped β€” preventing orphan files referencing non-existent extensions.
75+
76+
Core commands (e.g. `speckit.specify`, with only 2 segments) are always registered.
77+
78+
### Agent format rendering
79+
80+
The `CommandRegistrar` renders commands differently per agent:
81+
82+
| Agent | Format | Extension | Arg placeholder |
83+
|-------|--------|-----------|-----------------|
84+
| Claude, Cursor, opencode, Windsurf, etc. | Markdown | `.md` | `$ARGUMENTS` |
85+
| Copilot | Markdown | `.agent.md` + `.prompt.md` | `$ARGUMENTS` |
86+
| Gemini, Qwen, Tabnine | TOML | `.toml` | `{{args}}` |
87+
88+
### Cleanup on removal
89+
90+
When `specify preset remove` is called, the registered commands are read from the registry metadata and the corresponding files are deleted from each agent directory, including Copilot companion `.prompt.md` files.
91+
92+
## Catalog System
93+
94+
```mermaid
95+
flowchart TD
96+
A["specify preset search"] --> B["PresetCatalog.get_active_catalogs()"]
97+
B --> C{SPECKIT_PRESET_CATALOG_URL set?}
98+
C -- Yes --> D["single custom catalog"]
99+
C -- No --> E{.specify/preset-catalogs.yml exists?}
100+
E -- Yes --> F["project-level catalog stack"]
101+
E -- No --> G{"~/.specify/preset-catalogs.yml exists?"}
102+
G -- Yes --> H["user-level catalog stack"]
103+
G -- No --> I["built-in defaults"]
104+
I --> J["default (install allowed)"]
105+
I --> K["community (discovery only)"]
106+
107+
style D fill:#ff9800,color:#fff
108+
style F fill:#2196f3,color:#fff
109+
style H fill:#2196f3,color:#fff
110+
style J fill:#4caf50,color:#fff
111+
style K fill:#9e9e9e,color:#fff
112+
```
113+
114+
Catalogs are fetched with a 1-hour cache (per-URL, SHA256-hashed cache files). Each catalog entry has a `priority` (for merge ordering) and `install_allowed` flag.
115+
116+
## Repository Layout
117+
118+
```
119+
presets/
120+
β”œβ”€β”€ ARCHITECTURE.md # This file
121+
β”œβ”€β”€ PUBLISHING.md # Guide for submitting presets to the catalog
122+
β”œβ”€β”€ README.md # User guide
123+
β”œβ”€β”€ catalog.json # Official preset catalog
124+
β”œβ”€β”€ catalog.community.json # Community preset catalog
125+
β”œβ”€β”€ scaffold/ # Scaffold for creating new presets
126+
β”‚ β”œβ”€β”€ preset.yml # Example manifest
127+
β”‚ β”œβ”€β”€ README.md # Guide for customizing the scaffold
128+
β”‚ β”œβ”€β”€ commands/
129+
β”‚ β”‚ β”œβ”€β”€ speckit.specify.md # Core command override example
130+
β”‚ β”‚ └── speckit.myext.myextcmd.md # Extension command override example
131+
β”‚ └── templates/
132+
β”‚ β”œβ”€β”€ spec-template.md # Core template override example
133+
β”‚ └── myext-template.md # Extension template override example
134+
└── self-test/ # Self-test preset (overrides all core templates)
135+
β”œβ”€β”€ preset.yml
136+
β”œβ”€β”€ commands/
137+
β”‚ └── speckit.specify.md
138+
└── templates/
139+
β”œβ”€β”€ spec-template.md
140+
β”œβ”€β”€ plan-template.md
141+
β”œβ”€β”€ tasks-template.md
142+
β”œβ”€β”€ checklist-template.md
143+
β”œβ”€β”€ constitution-template.md
144+
└── agent-file-template.md
145+
```
146+
147+
## Module Structure
148+
149+
```
150+
src/specify_cli/
151+
β”œβ”€β”€ agents.py # CommandRegistrar β€” shared infrastructure for writing
152+
β”‚ # command files to agent directories
153+
β”œβ”€β”€ presets.py # PresetManifest, PresetRegistry, PresetManager,
154+
β”‚ # PresetCatalog, PresetCatalogEntry, PresetResolver
155+
└── __init__.py # CLI commands: specify preset list/add/remove/search/
156+
# resolve/info, specify preset catalog list/add/remove
157+
```

0 commit comments

Comments
Β (0)