Skip to content

Commit 08577c5

Browse files
feat(templates): add reusable spec template system (#8)
SpecBridge v0.7.0: secure, deterministic, offline-first templates for Kiro-compatible specs. - Versioned template manifest (specbridge-template.json, schema 1.0.0) with strict validation and stable error codes SBT001-SBT025 - Restricted one-pass {{variable}} renderer: no code execution, no expressions, no environment access, no network, no recursion - Ten built-in templates embedded at build time; project-local packs under .specbridge/templates with atomic script-free local install - template list/search/show/validate/preview/apply/install/uninstall/ scaffold CLI, spec new --template, append-only template records - MCP template_list/search/show/preview plus candidate-hash-bound template_apply; /specbridge:templates plugin skill (10 skills total) - Generated template gallery and embedded-pack module with CI drift checks; template documentation set and threat model
1 parent 2606000 commit 08577c5

141 files changed

Lines changed: 18046 additions & 1230 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude-plugin/marketplace.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"name": "specbridge",
1010
"source": "./integrations/claude-code-plugin/specbridge",
1111
"description": "Kiro-compatible spec workflows, verified interactive task execution, and deterministic drift checks.",
12-
"version": "0.6.1",
12+
"version": "0.7.0",
1313
"license": "MIT",
1414
"keywords": [
1515
"spec-driven-development",

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ jobs:
4545
- name: CLI smoke test against the example Kiro workspace
4646
run: node scripts/smoke.mjs
4747

48+
- name: Built-in template module matches the packs on disk
49+
run: pnpm check:builtin-templates
50+
51+
- name: Template gallery matches the built-in manifests
52+
run: pnpm check:template-gallery
53+
4854
- name: GitHub Action bundle is reproducible
4955
if: matrix.os == 'ubuntu-latest'
5056
run: git diff --exit-code integrations/github-action/dist

CHANGELOG.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,89 @@
11
# Changelog
22

3+
## 0.7.0
4+
5+
Added:
6+
7+
- Versioned template manifest (`specbridge-template.json`, schema 1.0.0)
8+
with strict validation: template IDs, semver versions, kinds, workflow
9+
modes, file sets, typed variables (string/boolean/integer/enum with
10+
constraints), compatibility ranges, and safe optional metadata.
11+
- Restricted deterministic template renderer: `{{variableName}}`
12+
substitution only — one pass, no expressions, no conditionals, no
13+
includes, no environment access, values never re-scanned.
14+
- Built-in template catalog bundled with SpecBridge (immutable at runtime,
15+
embedded at build time so every bundle ships it).
16+
- Project-local template packs under `.specbridge/templates/<id>/`.
17+
- Deterministic local template search over IDs, display names,
18+
descriptions, and tags (exact ID > ID prefix > exact tag > display-name
19+
token > description token; no model, no network).
20+
- `template list | search | show | validate | preview | apply` CLI
21+
commands; preview and `apply --dry-run` share the exact rendering path
22+
with apply and write nothing.
23+
- Local template installation and uninstallation
24+
(`template install <local-path>` / `template uninstall project:<id>`):
25+
validated, script-free, atomic (temp directory + rename), never
26+
overwriting; built-in templates cannot be uninstalled.
27+
- `template scaffold` — generates a complete community-ready template pack
28+
(manifest, README with validation instructions and a contribution
29+
checklist, plain-Markdown template files); no TypeScript required.
30+
- `spec new --template <reference> [--var key=value]`, delegating to the
31+
same template application service (existing non-template `spec new`
32+
behavior unchanged).
33+
- Append-only template operation records in
34+
`.specbridge/template-records.jsonl` (apply/install/uninstall/scaffold)
35+
storing variable names and rendered-content hashes, never values.
36+
- MCP template tools: `template_list`, `template_search`, `template_show`,
37+
`template_preview` (read-only), and `template_apply` (candidate-hash
38+
bound, acknowledgement-gated). Install/uninstall/scaffold remain
39+
CLI-only.
40+
- Claude Code `/specbridge:templates` Skill: list/search/show/preview, and
41+
apply only after explicit confirmation with the previewed candidate
42+
hash.
43+
- Generated template gallery in `docs/templates.md`
44+
(`pnpm generate:template-gallery`) with a CI drift check
45+
(`pnpm check:template-gallery`); built-in packs are likewise embedded via
46+
`pnpm generate:builtin-templates` with `pnpm check:builtin-templates`.
47+
- Template contribution workflow and documentation
48+
(`docs/creating-templates.md`, `docs/template-manifest.md`,
49+
`docs/template-rendering.md`, `docs/template-security.md`,
50+
`docs/template-installation.md`, `docs/template-contribution-guide.md`).
51+
- Stable template error codes SBT001–SBT025 with remediation in every
52+
message.
53+
54+
Built-in templates:
55+
56+
- REST API (`rest-api`)
57+
- CLI tool (`cli-tool`)
58+
- Database migration (`database-migration`)
59+
- Authentication (`authentication`)
60+
- Background job (`background-job`)
61+
- Event-driven service (`event-driven-service`)
62+
- Bugfix regression (`bugfix-regression`)
63+
- Performance optimization (`performance-optimization`)
64+
- Security hardening (`security-hardening`)
65+
- Refactoring (`refactoring`)
66+
67+
Security:
68+
69+
- No executable template code, lifecycle scripts, or shell execution.
70+
- No environment interpolation and no network access anywhere in the
71+
template system (no remote registry, no URL or npm installation).
72+
- Path traversal and symlinks rejected; targets restricted to the exact
73+
Kiro spec file set; variables never allowed in target paths.
74+
- One-pass rendering: substituted values are never re-rendered.
75+
- Bounded packs and output (20 files, 256 KB manifest, 1 MB per template
76+
file, 5 MB per pack, 1 MB per rendered document).
77+
- Candidate-hash binding and an explicit acknowledgement for MCP apply.
78+
- Atomic installation and atomic spec creation; existing specs are never
79+
overwritten; generated stages always start unapproved.
80+
81+
Deferred to v0.7.1:
82+
83+
- Extension/plugin SDK, runner SDK distribution, analyzer/verifier/exporter
84+
SDKs.
85+
- Remote extension registry and community ecosystem index.
86+
387
## 0.6.1
488

589
Added:

README.md

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,33 @@ Codex, local models, or any supported coding agent.
1414
1515
> Your `.kiro` specs remain the source of truth.
1616
17-
New in v0.6.1 — keep your existing `.kiro` specs and **choose a compatible
17+
New in v0.7.0 — **reusable spec templates, without executable generators or
18+
platform lock-in**:
19+
20+
```bash
21+
specbridge template search migration
22+
23+
specbridge template preview database-migration \
24+
--name add-payment-status-index \
25+
--var tableName=payments
26+
27+
specbridge template apply database-migration \
28+
--name add-payment-status-index \
29+
--var tableName=payments
30+
```
31+
32+
Ten built-in templates ship with SpecBridge — `rest-api`, `cli-tool`,
33+
`database-migration`, `authentication`, `background-job`,
34+
`event-driven-service`, `bugfix-regression`, `performance-optimization`,
35+
`security-hardening`, `refactoring` — plus project-local packs, local
36+
installation, and `template scaffold` for community templates. Templates
37+
are plain Markdown plus a JSON manifest: rendering is deterministic and
38+
offline (`{{variable}}` substitution only — no scripts, no network, no
39+
model), preview writes nothing, apply never overwrites an existing spec,
40+
and generated stages start unapproved like every other spec. See
41+
[docs/templates.md](docs/templates.md).
42+
43+
From v0.6.1 — keep your existing `.kiro` specs and **choose a compatible
1844
coding agent or authoring model per operation**:
1945

2046
```text
@@ -261,12 +287,16 @@ Working today (fully offline, no model, no API key):
261287
| `specbridge spec affected` | **v0.4** — which specs does this change set touch (read-only) |
262288
| `specbridge spec policy init / show / validate` | **v0.4** — per-spec verification policies (impact areas, required commands, rule overrides) |
263289
| `specbridge verify rules / explain <id>` | **v0.4** — inspect the stable rule registry SBV001–SBV025 |
264-
| `specbridge mcp serve / doctor / manifest / tools` | **v0.5** — local stdio MCP server (25 tools since v0.6.1, 7 resources, 4 prompts) |
290+
| `specbridge mcp serve / doctor / manifest / tools` | **v0.5** — local stdio MCP server (30 tools since v0.7.0, 7 resources, 4 prompts) |
265291
| `specbridge run recover-lock` | **v0.5** — diagnose and explicitly recover the interactive execution lock |
266292
| `specbridge runner list / matrix / show / doctor` | **v0.6** — profile-based runner diagnostics and the generated capability matrix (read-only) |
267293
| `specbridge runner test / conformance / models <profile>` | **v0.6** — bounded structured-output probe (`--network`), conformance suite, provider-supported model listing |
268294
| `specbridge config doctor / migrate` | **v0.6** — configuration validation and the explicit v1 → v2 migration (dry-run by default, atomic apply with backup) |
269295
| `specbridge runner doctor gemini-default / openai-compatible-local / antigravity` | **v0.6.1** — diagnostics for the new adapters; MCP `runner_list` / `runner_show` / `runner_doctor` / `runner_matrix` expose the same read-only services |
296+
| `specbridge template list / search / show / validate` | **v0.7.0** — deterministic, offline template discovery and validation (read-only) |
297+
| `specbridge template preview / apply [--dry-run]` | **v0.7.0** — one rendering path; preview writes nothing, apply is atomic and never overwrites |
298+
| `specbridge template install / uninstall / scaffold` | **v0.7.0** — local, script-free pack installation and community-template scaffolding |
299+
| `specbridge spec new <name> --template <ref> --var k=v` | **v0.7.0** — template-based spec creation through the same service |
270300

271301
Planned commands (`spec sync/export`) are registered, marked "(planned)" in
272302
`--help`, and exit with an honest error — see the [roadmap](docs/roadmap.md).
@@ -549,7 +579,7 @@ stores no credentials of any kind.
549579
secrets or environment variables.
550580
- Full model: [docs/security.md](docs/security.md).
551581

552-
## Limitations (v0.6.1)
582+
## Limitations (v0.7.0)
553583

554584
- The MCP server is stdio-only and local-only: no HTTP/SSE/WebSocket
555585
transport, no OAuth, no cloud hosting. One server process serves one
@@ -570,6 +600,13 @@ stores no credentials of any kind.
570600
references, chore-task exclusion) are labelled and never default to error.
571601
- `spec sync` and `spec export` are not implemented yet (they fail
572602
honestly). SARIF output is deferred.
603+
- Templates are local-only: there is no remote registry, no GitHub/npm/URL
604+
installation, and no signed packs in v0.7.0. Template rendering is plain
605+
`{{variable}}` substitution — no expressions, no conditionals, and
606+
literal double braces are not supported in template files. Rendered
607+
Markdown can still contain untrusted prose; SpecBridge control rules
608+
(approvals, protected paths, verification) are never overridable by
609+
template content.
573610
- Production runners are claude-code, codex-cli, gemini-cli, ollama
574611
(authoring-only), openai-compatible (authoring-only), and mock; the
575612
antigravity-cli adapter is experimental detection only. Provider usage
@@ -623,13 +660,16 @@ deterministic drift verification (rule engine SBV001–SBV025, policies,
623660
affected-spec resolution, evidence freshness, four report formats) and the
624661
production GitHub Action. v0.5: the local stdio MCP server, direct
625662
interactive task execution, and the self-contained Claude Code plugin with
626-
its repository-local marketplace. v0.6.0 (this release): the
627-
capability-driven runner platform with a frozen adapter contract, runner
628-
profiles and explicit configuration migration, deterministic selection and
629-
bounded authoring fallback, the conformance framework, and the production
630-
Codex CLI and Ollama (authoring-only) runners. Next — v0.6.1: Gemini CLI,
631-
OpenAI-compatible authoring, Antigravity, MCP runner diagnostics, and the
632-
runner-management Skill. v0.7: templates, plugin SDK, extension registry,
663+
its repository-local marketplace. v0.6.0: the capability-driven runner
664+
platform with a frozen adapter contract, runner profiles and explicit
665+
configuration migration, deterministic selection and bounded authoring
666+
fallback, the conformance framework, and the production Codex CLI and
667+
Ollama (authoring-only) runners. v0.6.1: Gemini CLI, OpenAI-compatible
668+
authoring, Antigravity, MCP runner diagnostics, and the runner-management
669+
Skill. v0.7.0 (this release): the offline template system — versioned
670+
manifests, a restricted deterministic renderer, ten built-in templates,
671+
project-local packs, local installation, scaffolding, MCP template tools,
672+
and the templates Skill. Next — v0.7.1: plugin SDK, extension registry,
633673
community ecosystem. Full detail: [docs/roadmap.md](docs/roadmap.md).
634674

635675
## Documentation
@@ -638,6 +678,13 @@ community ecosystem. Full detail: [docs/roadmap.md](docs/roadmap.md).
638678
[Kiro compatibility](docs/kiro-compatibility.md) ·
639679
[Spec authoring](docs/spec-authoring.md) ·
640680
[Spec analysis](docs/spec-analysis.md) ·
681+
[Templates](docs/templates.md) ·
682+
[Creating templates](docs/creating-templates.md) ·
683+
[Template manifest](docs/template-manifest.md) ·
684+
[Template rendering](docs/template-rendering.md) ·
685+
[Template installation](docs/template-installation.md) ·
686+
[Template security](docs/template-security.md) ·
687+
[Template contribution guide](docs/template-contribution-guide.md) ·
641688
[Approval workflow](docs/approval-workflow.md) ·
642689
[Sidecar state](docs/sidecar-state.md) ·
643690
[Runners (v0.6)](docs/runners.md) ·

docs/claude-code-plugin.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ integrations/claude-code-plugin/specbridge/
2222
│ ├── approve/SKILL.md /specbridge:approve <spec> <stage> (human-only)
2323
│ ├── implement/SKILL.md /specbridge:implement <spec> [task]
2424
│ ├── continue/SKILL.md /specbridge:continue <run-id>
25+
│ ├── runners/SKILL.md /specbridge:runners [profile]
26+
│ ├── templates/SKILL.md /specbridge:templates [query | show … | apply …]
2527
│ └── verify/SKILL.md /specbridge:verify [spec]
2628
├── bin/
2729
│ ├── specbridge POSIX wrapper → dist/cli.cjs
@@ -87,6 +89,13 @@ and controlled lifecycle operations and never duplicate core logic:
8789
never sends a network request itself, and never starts a login. The
8890
existing implementation workflow is unchanged: `task_begin` → the
8991
current Claude Code session edits → `task_complete`.
92+
- `templates` (v0.7.0) discovers templates with `template_list`/
93+
`template_search`, inspects with `template_show`, always previews with
94+
`template_preview`, and applies only after explicit user confirmation via
95+
`template_apply` with the previewed `candidateHash` and the
96+
`"apply-reviewed-template"` acknowledgement. It never installs,
97+
uninstalls, or scaffolds templates (CLI-only operations), never renders
98+
content itself, and never edits `.kiro` or `.specbridge` directly.
9099

91100
No skill uses `bypassPermissions`, `dangerously-skip-permissions`,
92101
unrestricted `Bash(*)`, or unrestricted `Write`, and no skill instructs

docs/cli-mcp-parity.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ over both. This table maps every capability to its surfaces:
1111
| List/read specs | `spec list/show` | `spec_list`, `spec_read` | `status` |
1212
| Spec status | `spec status` | `spec_status` | `status` |
1313
| Agent context | `spec context` | `spec_context` | (used internally) |
14-
| Create templates | `spec new` | `spec_create` (preview→apply) | `new` |
14+
| Create a spec | `spec new` | `spec_create` (preview→apply) | `new` |
15+
| Discover templates | `template list/search/show/validate` | `template_list`, `template_search`, `template_show` | `templates` |
16+
| Apply a template | `template preview/apply`, `spec new --template` | `template_preview` + `template_apply` (hash-bound) | `templates` (after confirmation) |
17+
| Manage template packs | `template install/uninstall/scaffold` | **no** (deliberately CLI-only) | **no** |
1518
| Analyze spec | `spec analyze` | `spec_analyze` | `author`/`status` |
1619
| Apply authored stage | `spec generate/refine` (runner-drafted) | `spec_stage_validate` + `spec_stage_apply` (session-drafted) | `author` |
1720
| **Approve stage** | `spec approve` | **no direct model tool** | `approve` (human-invoked CLI) |

docs/creating-templates.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Creating templates
2+
3+
This is the contributor happy path: scaffold a template pack, edit plain
4+
Markdown, validate, try it locally, share it. No TypeScript is ever
5+
required — a template pack is a JSON manifest plus Markdown files, and
6+
that is the whole format. For what templates are and what they cannot do,
7+
start with [the template overview](templates.md).
8+
9+
## 1. Scaffold a pack
10+
11+
```bash
12+
specbridge template scaffold my-template --kind feature --output ./my-template
13+
```
14+
15+
This generates a complete, already-valid pack:
16+
17+
```
18+
my-template/
19+
├── specbridge-template.json # the manifest
20+
├── README.md # usage, variables table, checklist
21+
└── files/
22+
├── requirements.md.template
23+
├── design.md.template
24+
└── tasks.md.template
25+
```
26+
27+
A `--kind bugfix` scaffold generates `files/bugfix.md.template` instead of
28+
`files/requirements.md.template` — the file set always mirrors the full
29+
Kiro layout for the kind, nothing more and nothing less:
30+
31+
| Kind | Rendered files |
32+
| --- | --- |
33+
| `feature` | `requirements.md`, `design.md`, `tasks.md` |
34+
| `bugfix` | `bugfix.md`, `design.md`, `tasks.md` |
35+
36+
Useful scaffold options: `--modes` (comma-separated workflow modes),
37+
`--display-name`, `--description`, `--license` (default `MIT`), and
38+
`--dry-run` to list the files without writing. Scaffolding works outside a
39+
SpecBridge workspace too — you do not need a `.kiro` project to author a
40+
template — and it never overwrites an existing directory.
41+
42+
## 2. Edit the template files and manifest
43+
44+
Template files are plain Markdown with `{{variable}}` placeholders. There
45+
are no scripts, expressions, conditionals, or loops — the
46+
[rendering rules](template-rendering.md) are deliberately small. The
47+
scaffold starts you with the built-in variables (`{{title}}`,
48+
`{{description}}`) and one example variable (`actor`); declare your own in
49+
the manifest's `variables` array. Use `<angle-bracket>` placeholders for
50+
content the spec author fills in by hand after applying.
51+
52+
Everything the manifest can say — IDs, variables, constraints, file
53+
entries, compatibility — is specified in the
54+
[manifest reference](template-manifest.md).
55+
56+
## 3. Validate
57+
58+
```bash
59+
specbridge template validate ./my-template
60+
61+
# Treat warnings (missing README, stylistic render findings) as failures:
62+
specbridge template validate ./my-template --strict
63+
```
64+
65+
Validation checks the pack structure, the manifest, every declared file,
66+
and a full render with deterministic sample values, and reports every
67+
issue at once with a stable `SBT` code and a category (`manifest`,
68+
`variables`, `rendering`, `kiro-layout`, …). Add `--json` for a
69+
machine-readable report.
70+
71+
## 4. Install and preview locally
72+
73+
```bash
74+
specbridge template install ./my-template
75+
76+
specbridge template preview project:my-template --name example-spec
77+
```
78+
79+
Install copies the validated pack into `.specbridge/templates/my-template/`
80+
(atomically, never overwriting — see
81+
[installation](template-installation.md)). Preview renders everything and
82+
writes nothing; `template apply --dry-run` does the same through the exact
83+
same rendering path. When the output looks right:
84+
85+
```bash
86+
specbridge template apply project:my-template --name my-first-real-spec
87+
```
88+
89+
The `project:` prefix is only mandatory when the same ID also exists as a
90+
built-in; an unambiguous ID works unqualified.
91+
92+
## 5. Share it
93+
94+
A template pack is just a directory of text files. To share it:
95+
96+
- **Within a team**: commit the directory to your repository (anywhere
97+
inside it) and let teammates run
98+
`specbridge template install ./path/to/my-template`. There is no remote
99+
registry, URL, or npm installation in v0.7.0 — installation reads a
100+
local directory inside the repository, and nothing else. A community
101+
index is deferred to v0.7.1+ per the [roadmap](roadmap.md).
102+
- **As a built-in**: open a pull request adding the pack under
103+
`packages/templates/builtins/` in this repository — see the
104+
[contribution guide](template-contribution-guide.md).
105+
106+
## Related documentation
107+
108+
- [Template overview](templates.md)
109+
- [Manifest reference](template-manifest.md)
110+
- [Rendering rules](template-rendering.md)
111+
- [Installation](template-installation.md)
112+
- [Security](template-security.md)
113+
- [Contribution guide](template-contribution-guide.md)

docs/mcp-server.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ specbridge mcp manifest [--json] # identity + capability counts
3232
specbridge mcp tools [--json] [--verbose] # tool/resource/prompt catalog
3333
```
3434

35+
v0.7.0 adds five template tools: read-only `template_list`,
36+
`template_search`, `template_show`, and `template_preview`, plus the
37+
candidate-hash-bound `template_apply` (acknowledgement-gated, atomic,
38+
never overwriting). Template install/uninstall/scaffold remain CLI-only.
39+
3540
v0.6.1 adds four read-only runner diagnostic tools (`runner_list`,
3641
`runner_show`, `runner_doctor`, `runner_matrix`) — thin adapters over the
3742
same shared runner services the CLI uses; see [mcp-tools.md](mcp-tools.md).

0 commit comments

Comments
 (0)