Skip to content

Commit abf4aeb

Browse files
committed
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
1 parent 6003a23 commit abf4aeb

32 files changed

Lines changed: 4671 additions & 2458 deletions

β€ŽCHANGELOG.mdβ€Ž

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ 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-
## [0.2.1] - 2026-03-09
10+
## [0.2.1] - 2026-03-10
1111

1212
### Added
1313

14-
- feat(templates): Pluggable template system with template packs, catalog, and resolver
15-
- Template pack manifest (`template-pack.yml`) with validation for artifact, command, and script types
16-
- `TemplatePackManifest`, `TemplatePackRegistry`, `TemplatePackManager`, `TemplateCatalog`, `TemplateResolver` classes in `src/specify_cli/templates.py`
17-
- CLI commands: `specify template search`, `specify template add`, `specify template list`, `specify template remove`, `specify template resolve`
18-
- `--template` option for `specify init` to install template packs during initialization
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)
1922
- `resolve_template()` / `Resolve-Template` helpers in bash and PowerShell common scripts
20-
- Template resolution priority stack: overrides β†’ packs β†’ extensions β†’ core
21-
- Template catalog files (`templates/catalog.json`, `templates/catalog.community.json`)
22-
- Template pack scaffold directory (`templates/template/`)
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/`)
2326
- Scripts updated to use template resolution instead of hardcoded paths
2427

2528
## [0.2.0] - 2026-03-09

β€Ž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)