Skip to content

Commit de2288b

Browse files
committed
feat: add sub-spec template system documentation to README
1 parent bc405a9 commit de2288b

File tree

2 files changed

+320
-154
lines changed

2 files changed

+320
-154
lines changed

specs/073-template-engine-agents-md/README.md

Lines changed: 17 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ related:
1212
- '025'
1313
- '072'
1414
- '074'
15+
- '078'
1516
created_at: '2025-11-13T08:35:40.229Z'
1617
updated_at: '2025-11-13T10:32:28.046Z'
1718
transitions:
@@ -54,14 +55,15 @@ completed: '2025-11-13'
5455

5556
**Goal**: Use template engine to generate AGENTS.md from shared components, eliminate duplication, prevent drift.
5657

57-
**Related Issue**: `.lean-spec/templates/` system also needs redesign - currently only generates main spec file, should support optional sub-specs (DESIGN.md, TESTING.md, etc.).
58+
**Scope**: This spec covers Phase 1 only (AGENTS.md template engine). Phase 2 (sub-spec template system) was split into spec 078.
5859

5960
**Related Specs**:
6061
- `012-sub-spec-files` (archived) - Original sub-spec design (implemented)
6162
- `013-custom-spec-templates` (archived) - Template system v1
6263
- `025-template-config-updates` - Config format updates
6364
- `072-ai-agent-first-use-workflow` - Current AGENTS.md improvement driving this
6465
- `074-content-at-creation` - Spec creation with content flags (similar AI-first approach)
66+
- `078-sub-spec-template-system` - Phase 2 split into separate spec (sub-spec generation)
6567

6668
## Design
6769

@@ -149,87 +151,15 @@ npm run build:agents-templates
149151
- ✅ Prevents drift automatically
150152
- ✅ Can version control both source and generated files
151153

152-
#### Part 2: Redesign `.lean-spec/templates/` System (Future)
153-
154-
**Current Problem**: Templates only generate main spec file (README.md), but specs often need sub-files.
155-
156-
**Proposed Design**:
157-
```
158-
.lean-spec/
159-
└── templates/
160-
├── default/
161-
│ ├── README.md # Main spec template (required)
162-
│ ├── DESIGN.md.opt # Optional sub-spec
163-
│ └── TESTING.md.opt # Optional sub-spec
164-
└── api/
165-
├── README.md
166-
├── API.md.opt
167-
└── SCHEMAS.md.opt
168-
```
169-
170-
**Convention**:
171-
- `{name}.md` - Always generated
172-
- `{name}.md.opt` - Generate only if requested (flag or prompt)
173-
- `{name}.md.req` - Always generated (for templates requiring sub-specs)
174-
175-
**Usage** (AI-first, flag-based by default):
176-
```bash
177-
# Standard: generates README.md only
178-
lean-spec create my-feature
179-
180-
# With explicit sub-spec flags (AI-friendly)
181-
lean-spec create my-feature --design --testing
182-
183-
# Human interactive mode (opt-in)
184-
lean-spec create my-feature --with-subs
185-
? Include optional sub-specs? (space to select)
186-
[ ] DESIGN.md
187-
[x] TESTING.md
188-
[ ] IMPLEMENTATION.md
189-
190-
# Rationale: AI agents primarily use CLI, prefer declarative flags over interactive prompts
191-
```
192-
193-
**Config Enhancement**:
194-
```json
195-
{
196-
"templates": {
197-
"default": {
198-
"main": "README.md",
199-
"optional": ["DESIGN.md", "TESTING.md", "IMPLEMENTATION.md"],
200-
"required": [],
201-
"flags": {
202-
"--design": "DESIGN.md",
203-
"--testing": "TESTING.md",
204-
"--implementation": "IMPLEMENTATION.md"
205-
}
206-
},
207-
"api": {
208-
"main": "README.md",
209-
"optional": ["SCHEMAS.md"],
210-
"required": ["API.md"],
211-
"flags": {
212-
"--schemas": "SCHEMAS.md"
213-
}
214-
}
215-
}
216-
}
217-
```
218-
219154
### Technical Approach
220155

221-
**Phase 1**: AGENTS.md Template Engine
156+
**AGENTS.md Template Engine**:
222157
- Tool: Handlebars.js (lightweight, widely used)
223158
- Build script: `scripts/build-agents-templates.ts`
224159
- Runs during: `pnpm build` or `pnpm build:templates`
225160
- Generated files committed to repo (easier distribution)
226161

227-
**Phase 2**: Sub-Spec Template System (AI-First Design)
228-
- Extend existing template resolution in `src/commands/creator.ts`
229-
- Add explicit sub-spec flags (`--design`, `--testing`, etc.) - primary interface
230-
- Add `--with-subs` interactive prompt - opt-in for human users
231-
- Support `.opt` and `.req` file conventions
232-
- Update config schema for template metadata and flag mappings
162+
**Note**: Originally this spec included Phase 2 (Sub-Spec Template System) for generating optional sub-spec files. That has been split into spec 078 for clearer separation of concerns
233163

234164
### Alternative Approaches Considered
235165

@@ -288,31 +218,7 @@ lean-spec create my-feature --with-subs
288218
- [x] Update CI to fail if generated files out of sync
289219
- [ ] Add pre-commit hook to regenerate if source changed (deferred - CI validation sufficient)
290220

291-
### Phase 2: Sub-Spec Template System
292-
293-
- [ ] **Design & Planning**
294-
- [ ] Define `.opt` / `.req` file convention
295-
- [ ] Design config schema for template metadata and flag mappings
296-
- [ ] Design flag-based interface (primary) + interactive mode (opt-in)
297-
- [ ] Document sub-spec template authoring guide
298-
299-
- [ ] **Implementation**
300-
- [ ] Extend `creator.ts` to handle sub-spec templates
301-
- [ ] Add explicit sub-spec flags (`--design`, `--testing`, etc.)
302-
- [ ] Add `--with-subs` interactive mode (opt-in for humans)
303-
- [ ] Implement file filtering logic (opt/req/flags)
304-
- [ ] Update template resolution and variable substitution
305-
306-
- [ ] **Template Updates**
307-
- [ ] Create example templates with sub-specs
308-
- [ ] Update existing templates with `.opt` convention
309-
- [ ] Add template metadata to config.json files
310-
311-
- [ ] **Documentation & Testing**
312-
- [ ] Update docs for sub-spec usage
313-
- [ ] Create examples in templates
314-
- [ ] Test all combinations of sub-spec generation
315-
- [ ] Add integration tests
221+
**Note**: Phase 2 (Sub-Spec Template System) has been moved to spec 078-sub-spec-template-system
316222

317223
## Test
318224

@@ -342,38 +248,6 @@ pnpm build:templates
342248
# Verify all AGENTS.md files updated
343249
```
344250

345-
**Phase 2: Sub-Spec Template System**
346-
347-
- [ ] **Basic Sub-Spec Generation**: `lean-spec create feat --design` generates README.md + DESIGN.md
348-
- [ ] **Interactive Selection**: Prompt allows selecting multiple optional sub-specs
349-
- [ ] **Required Sub-Spec**: Templates with `.req` files always generate those files
350-
- [ ] **Variable Substitution**: Variables work in sub-spec templates
351-
- [ ] **No Sub-Specs**: Default behavior (no flags) generates only README.md
352-
353-
**Test Protocol**:
354-
```bash
355-
# 1. Test required sub-spec
356-
lean-spec create api-endpoint --template api
357-
# Should generate README.md + API.md (required)
358-
359-
# 2. Test explicit flags (AI-first interface)
360-
lean-spec create feature --design --testing
361-
# Should generate README.md + DESIGN.md + TESTING.md
362-
363-
# 3. Test interactive mode (human opt-in)
364-
lean-spec create feature --with-subs
365-
# Interactive prompt, select TESTING.md only
366-
# Should generate README.md + TESTING.md
367-
368-
# 4. Test default (no sub-specs)
369-
lean-spec create simple-fix
370-
# Should generate only README.md
371-
372-
# 5. AI agent usage test
373-
# AI should prefer: lean-spec create feature --design --implementation
374-
# Not: lean-spec create feature --with-subs (requires interaction)
375-
```
376-
377251
## Notes
378252

379253
### Why This Matters
@@ -399,26 +273,15 @@ lean-spec create simple-fix
399273
- ✅ Always fresh
400274
- ❌ Template engine in runtime deps
401275
- ❌ More complex error handling
402-
- ❌ Harder to debug
403-
404-
### AI-First Design Rationale
405-
406-
**Why flag-based over interactive by default?**
407-
408-
In AI-human co-op spec writing mode:
409-
- **AI agents primarily use the CLI**, not humans
410-
- **Interactive prompts block automation** - AI can't respond to prompts effectively
411-
- **Flags are declarative** - AI can determine needed sub-specs and invoke with explicit flags
412-
- **Humans can opt-in** - `--with-subs` flag preserves interactive experience when desired
276+
**Decision**: Build-time generation with Handlebars is the sweet spot - simple, reliable, works everywhere.
413277

414-
**Example AI workflow**:
415-
```
416-
AI analyzes task → determines needs DESIGN + TESTING sub-specs
417-
→ runs: lean-spec create feature --design --testing
418-
→ no interaction needed, continues working
419-
```
278+
### Phase 2 Split Decision
420279

421-
This aligns with `072-ai-agent-first-use-workflow` principles: optimize for AI, accommodate humans.
280+
**Why split into separate spec (078)?**
281+
- Phase 1 (AGENTS.md template engine) is complete and independent
282+
- Phase 2 (sub-spec template system) is a different feature with different scope
283+
- Cleaner separation allows independent planning and archiving
284+
- Phase 1 can be archived when appropriate while Phase 2 continues as spec 078
422285

423286
### Related Specs
424287

@@ -430,17 +293,17 @@ See Overview section for full list of related specs.
430293
- ~~Do we need a `lean-spec templates validate` command?~~ ✅ Implemented as `pnpm validate:templates`
431294
- ~~Should CI auto-regenerate and commit, or just fail?~~ ✅ CI fails on drift (regeneration is manual)
432295
- Can we detect if AGENTS.md was manually edited and warn?
296+
- ~~Should we support optional sub-specs?~~ ✅ Moved to spec 078
433297

434298
### Success Metrics
435299

436300
- **Maintenance Time**: Adding new rule takes 1 file edit + build (not 4 file edits) ✅ **Achieved**
437301
- **Consistency**: No drift between templates (verified by tests) ✅ **Achieved** (CI validation in place)
438302
- **Flexibility**: Easy to create new templates with different combinations ✅ **Achieved**
439-
- **Adoption**: Sub-spec templates used in 20%+ of new specs within 2 months (Phase 2)
440303

441-
## Phase 1 Completion Summary
304+
## Completion Summary
442305

443-
**Status**: Phase 1 Complete ✅
306+
**Status**: Complete ✅
444307

445308
**Completed Work**:
446309
1. ✅ Template infrastructure created with component-based architecture
@@ -457,4 +320,4 @@ See Overview section for full list of related specs.
457320
- Easy maintenance: update once, propagates to all templates
458321
- CI ensures quality and consistency
459322

460-
**Next Steps**: Phase 2 - Sub-Spec Template System (separate implementation)
323+
**Note**: Originally planned Phase 2 (Sub-Spec Template System) has been split into spec 078-sub-spec-template-system for clearer separation of concerns

0 commit comments

Comments
 (0)