spec-generator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSpec Generator
规格说明书生成器
Structured specification document generator producing a complete specification package (Product Brief, PRD, Architecture, Epics) through 6 sequential phases with multi-CLI analysis and interactive refinement. Document generation only - execution handoff to existing workflows (lite-plan, plan, req-plan).
结构化的规格说明书文档生成器,通过6个连续阶段结合多CLI分析和交互式优化,生成完整的规格说明包(产品简报、PRD、架构文档、史诗故事)。仅生成文档——执行环节交接至现有工作流(lite-plan、plan、req-plan)。
Architecture Overview
架构概述
Phase 0: Specification Study (Read specs/ + templates/ - mandatory prerequisite)
|
Phase 1: Discovery -> spec-config.json + discovery-context.json
|
Phase 2: Product Brief -> product-brief.md (multi-CLI parallel analysis)
|
Phase 3: Requirements (PRD) -> requirements/ (_index.md + REQ-*.md + NFR-*.md)
|
Phase 4: Architecture -> architecture/ (_index.md + ADR-*.md, multi-CLI review)
|
Phase 5: Epics & Stories -> epics/ (_index.md + EPIC-*.md)
|
Phase 6: Readiness Check -> readiness-report.md + spec-summary.md
|
Handoff to execution workflowsPhase 0: Specification Study (Read specs/ + templates/ - mandatory prerequisite)
|
Phase 1: Discovery -> spec-config.json + discovery-context.json
|
Phase 2: Product Brief -> product-brief.md (multi-CLI parallel analysis)
|
Phase 3: Requirements (PRD) -> requirements/ (_index.md + REQ-*.md + NFR-*.md)
|
Phase 4: Architecture -> architecture/ (_index.md + ADR-*.md, multi-CLI review)
|
Phase 5: Epics & Stories -> epics/ (_index.md + EPIC-*.md)
|
Phase 6: Readiness Check -> readiness-report.md + spec-summary.md
|
Handoff to execution workflowsKey Design Principles
核心设计原则
- Document Chain: Each phase builds on previous outputs, creating a traceable specification chain from idea to executable stories
- Multi-Perspective Analysis: CLI tools (Gemini/Codex/Claude) provide product, technical, and user perspectives in parallel
- Interactive by Default: Each phase offers user confirmation points; flag enables full auto mode
-y - Resumable Sessions: tracks completed phases;
spec-config.jsonflag resumes from last checkpoint-c - Template-Driven: All documents generated from standardized templates with YAML frontmatter
- Pure Documentation: No code generation or execution - clean handoff to existing execution workflows
- 文档链:每个阶段基于前一阶段的输出构建,形成从想法到可执行故事的可追溯规格说明链
- 多视角分析:CLI工具(Gemini/Codex/Claude)并行提供产品、技术和用户视角
- 默认交互式:每个阶段提供用户确认节点;标志启用全自动模式
-y - 可恢复会话:跟踪已完成阶段;
spec-config.json标志从最后一个检查点恢复-c - 模板驱动:所有文档均从带有YAML前置元数据的标准化模板生成
- 纯文档生成:不涉及代码生成或执行环节,干净交接至现有执行工作流
Mandatory Prerequisites
强制前提条件
Do NOT skip: Before performing any operations, you must completely read the following documents. Proceeding without reading the specifications will result in outputs that do not meet quality standards.
请勿跳过:在执行任何操作前,你必须完整阅读以下文档。未阅读规格说明就继续操作将导致输出不符合质量标准。
Specification Documents (Required Reading)
规格说明文档(必读)
| Document | Purpose | Priority |
|---|---|---|
| specs/document-standards.md | Document format, frontmatter, naming conventions | P0 - Must read before execution |
| specs/quality-gates.md | Per-phase quality gate criteria and scoring | P0 - Must read before execution |
| 文档 | 用途 | 优先级 |
|---|---|---|
| specs/document-standards.md | 文档格式、前置元数据、命名规范 | P0 - 执行前必读 |
| specs/quality-gates.md | 各阶段质量门标准和评分规则 | P0 - 执行前必读 |
Template Files (Must read before generation)
模板文件(生成前必读)
| Document | Purpose |
|---|---|
| templates/product-brief.md | Product brief document template |
| templates/requirements-prd.md | PRD document template |
| templates/architecture-doc.md | Architecture document template |
| templates/epics-template.md | Epic/Story document template |
| 文档 | 用途 |
|---|---|
| templates/product-brief.md | 产品简报文档模板 |
| templates/requirements-prd.md | PRD文档模板 |
| templates/architecture-doc.md | 架构文档模板 |
| templates/epics-template.md | 史诗/用户故事文档模板 |
Execution Flow
执行流程
Input Parsing:
|- Parse $ARGUMENTS: extract idea/topic, flags (-y, -c, -m)
|- Detect mode: new | continue
|- If continue: read spec-config.json, resume from first incomplete phase
|- If new: proceed to Phase 1
Phase 1: Discovery & Seed Analysis
|- Ref: phases/01-discovery.md
|- Generate session ID: SPEC-{slug}-{YYYY-MM-DD}
|- Parse input (text or file reference)
|- Gemini CLI seed analysis (problem, users, domain, dimensions)
|- Codebase exploration (conditional, if project detected)
|- User confirmation (interactive, -y skips)
|- Output: spec-config.json, discovery-context.json (optional)
Phase 2: Product Brief
|- Ref: phases/02-product-brief.md
|- 3 parallel CLI analyses: Product (Gemini) + Technical (Codex) + User (Claude)
|- Synthesize perspectives: convergent themes + conflicts
|- Interactive refinement (-y skips)
|- Output: product-brief.md (from template)
Phase 3: Requirements / PRD
|- Ref: phases/03-requirements.md
|- Gemini CLI: expand goals into functional + non-functional requirements
|- Generate acceptance criteria per requirement
|- User priority sorting: MoSCoW (interactive, -y auto-assigns)
|- Output: requirements/ directory (_index.md + REQ-*.md + NFR-*.md, from template)
Phase 4: Architecture
|- Ref: phases/04-architecture.md
|- Gemini CLI: core components, tech stack, ADRs
|- Codebase integration mapping (conditional)
|- Codex CLI: architecture challenge + review
|- Interactive ADR decisions (-y auto-accepts)
|- Output: architecture/ directory (_index.md + ADR-*.md, from template)
Phase 5: Epics & Stories
|- Ref: phases/05-epics-stories.md
|- Gemini CLI: requirement grouping into Epics, MVP subset tagging
|- Story generation: As a...I want...So that...
|- Dependency mapping (Mermaid)
|- Interactive validation (-y skips)
|- Output: epics/ directory (_index.md + EPIC-*.md, from template)
Phase 6: Readiness Check
|- Ref: phases/06-readiness-check.md
|- Cross-document validation (completeness, consistency, traceability)
|- Quality scoring per dimension
|- Output: readiness-report.md, spec-summary.md
|- Handoff options: lite-plan, req-plan, plan, issue:new, export only, iterate
Complete: Full specification package ready for execution
Phase 6 → Handoff Bridge (conditional, based on user selection):
├─ lite-plan: Extract first MVP Epic description → direct text input
├─ plan / req-plan: Create WFS session + .brainstorming/ bridge files
│ ├─ guidance-specification.md (synthesized from spec outputs)
│ ├─ feature-specs/feature-index.json (Epic → Feature mapping)
│ └─ feature-specs/F-{num}-{slug}.md (one per Epic)
├─ issue:new: Create issues per Epic
└─ context-search-agent auto-discovers .brainstorming/
→ context-package.json.brainstorm_artifacts populated
→ action-planning-agent consumes: guidance_spec (P1) → feature_index (P2)输入解析:
|- 解析$ARGUMENTS:提取想法/主题、标志位(-y, -c, -m)
|- 检测模式:新建 | 继续
|- 若为继续模式:读取spec-config.json,从第一个未完成阶段恢复
|- 若为新建模式:进入Phase 1
Phase 1: 发现与种子分析
|- 参考:phases/01-discovery.md
|- 生成会话ID:SPEC-{slug}-{YYYY-MM-DD}
|- 解析输入(文本或文件引用)
|- Gemini CLI种子分析(问题、用户、领域、维度)
|- 代码库探索(可选,仅在检测到项目时执行)
|- 用户确认(交互式,-y标志跳过)
|- 输出:spec-config.json、discovery-context.json(可选)
Phase 2: 产品简报
|- 参考:phases/02-product-brief.md
|- 3个并行CLI分析:产品视角(Gemini) + 技术视角(Codex) + 用户视角(Claude)
|- 综合视角:收敛共识主题 + 冲突点
|- 交互式优化(-y标志跳过)
|- 输出:product-brief.md(基于模板)
Phase 3: 需求/PRD
|- 参考:phases/03-requirements.md
|- Gemini CLI:将目标扩展为功能性 + 非功能性需求
|- 为每个需求生成验收标准
|- 用户优先级排序:MoSCoW法则(交互式,-y标志自动分配)
|- 输出:requirements/目录(_index.md + REQ-*.md + NFR-*.md,基于模板)
Phase 4: 架构设计
|- 参考:phases/04-architecture.md
|- Gemini CLI:核心组件、技术栈、ADR
|- 代码库集成映射(可选)
|- Codex CLI:架构挑战 + 评审
|- 交互式ADR决策(-y标志自动接受)
|- 输出:architecture/目录(_index.md + ADR-*.md,基于模板)
Phase 5: 史诗与用户故事
|- 参考:phases/05-epics-stories.md
|- Gemini CLI:将需求分组为Epic,标记MVP子集
|- 生成用户故事:As a...I want...So that...格式
|- 依赖关系映射(Mermaid格式)
|- 交互式验证(-y标志跳过)
|- 输出:epics/目录(_index.md + EPIC-*.md,基于模板)
Phase 6: 就绪检查
|- 参考:phases/06-readiness-check.md
|- 跨文档验证(完整性、一致性、可追溯性)
|- 各维度质量评分
|- 输出:readiness-report.md、spec-summary.md
|- 交接选项:lite-plan、req-plan、plan、issue:new、仅导出、迭代
完成:完整规格说明包已准备好进入执行环节
Phase 6 → 交接桥接(可选,基于用户选择):
├─ lite-plan:提取首个MVP Epic描述 → 直接文本输入
├─ plan / req-plan:创建WFS会话 + .brainstorming/桥接文件
│ ├─ guidance-specification.md(从规格输出合成)
│ ├─ feature-specs/feature-index.json(Epic → 功能映射)
│ └─ feature-specs/F-{num}-{slug}.md(每个Epic对应一个文件)
├─ issue:new:为每个Epic创建议题
└─ context-search-agent自动发现.brainstorming/
→ context-package.json.brainstorm_artifacts被填充
→ action-planning-agent消费:guidance_spec (P1) → feature_index (P2)Directory Setup
目录设置
javascript
// Session ID generation
const slug = topic.toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g, '-').slice(0, 40);
const date = new Date().toISOString().slice(0, 10);
const sessionId = `SPEC-${slug}-${date}`;
const workDir = `.workflow/.spec/${sessionId}`;
Bash(`mkdir -p "${workDir}"`);javascript
// Session ID generation
const slug = topic.toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g, '-').slice(0, 40);
const date = new Date().toISOString().slice(0, 10);
const sessionId = `SPEC-${slug}-${date}`;
const workDir = `.workflow/.spec/${sessionId}`;
Bash(`mkdir -p "${workDir}"`);Output Structure
输出结构
.workflow/.spec/SPEC-{slug}-{YYYY-MM-DD}/
├── spec-config.json # Session configuration + phase state
├── discovery-context.json # Codebase exploration results (optional)
├── product-brief.md # Phase 2: Product brief
├── requirements/ # Phase 3: Detailed PRD (directory)
│ ├── _index.md # Summary, MoSCoW table, traceability, links
│ ├── REQ-NNN-{slug}.md # Individual functional requirement
│ └── NFR-{type}-NNN-{slug}.md # Individual non-functional requirement
├── architecture/ # Phase 4: Architecture decisions (directory)
│ ├── _index.md # Overview, components, tech stack, links
│ └── ADR-NNN-{slug}.md # Individual Architecture Decision Record
├── epics/ # Phase 5: Epic/Story breakdown (directory)
│ ├── _index.md # Epic table, dependency map, MVP scope
│ └── EPIC-NNN-{slug}.md # Individual Epic with Stories
├── readiness-report.md # Phase 6: Quality report
└── spec-summary.md # Phase 6: One-page executive summary.workflow/.spec/SPEC-{slug}-{YYYY-MM-DD}/
├── spec-config.json # 会话配置 + 阶段状态
├── discovery-context.json # 代码库探索结果(可选)
├── product-brief.md # Phase 2: 产品简报
├── requirements/ # Phase 3: 详细PRD(目录)
│ ├── _index.md # 摘要、MoSCoW表格、可追溯性、链接
│ ├── REQ-NNN-{slug}.md # 单个功能性需求
│ └── NFR-{type}-NNN-{slug}.md # 单个非功能性需求
├── architecture/ # Phase 4: 架构决策(目录)
│ ├── _index.md # 概述、组件、技术栈、链接
│ └── ADR-NNN-{slug}.md # 单个架构决策记录
├── epics/ # Phase 5: Epic/用户故事拆分(目录)
│ ├── _index.md # Epic表格、依赖图、MVP范围
│ └── EPIC-NNN-{slug}.md # 包含用户故事的单个Epic
├── readiness-report.md # Phase 6: 质量报告
└── spec-summary.md # Phase 6: 单页执行摘要State Management
状态管理
spec-config.json serves as core state file:
json
{
"session_id": "SPEC-xxx-2026-02-11",
"seed_input": "User input text",
"input_type": "text",
"timestamp": "ISO8601",
"mode": "interactive",
"complexity": "moderate",
"depth": "standard",
"focus_areas": [],
"seed_analysis": {
"problem_statement": "...",
"target_users": [],
"domain": "...",
"constraints": [],
"dimensions": []
},
"has_codebase": false,
"phasesCompleted": [
{ "phase": 1, "name": "discovery", "output_file": "spec-config.json", "completed_at": "ISO8601" },
{ "phase": 3, "name": "requirements", "output_dir": "requirements/", "output_index": "requirements/_index.md", "file_count": 8, "completed_at": "ISO8601" }
]
}Resume mechanism: flag reads , resumes from first incomplete phase.
-c|--continuespec-config.json.phasesCompletedspec-config.json作为核心状态文件:
json
{
"session_id": "SPEC-xxx-2026-02-11",
"seed_input": "User input text",
"input_type": "text",
"timestamp": "ISO8601",
"mode": "interactive",
"complexity": "moderate",
"depth": "standard",
"focus_areas": [],
"seed_analysis": {
"problem_statement": "...",
"target_users": [],
"domain": "...",
"constraints": [],
"dimensions": []
},
"has_codebase": false,
"phasesCompleted": [
{ "phase": 1, "name": "discovery", "output_file": "spec-config.json", "completed_at": "ISO8601" },
{ "phase": 3, "name": "requirements", "output_dir": "requirements/", "output_index": "requirements/_index.md", "file_count": 8, "completed_at": "ISO8601" }
]
}恢复机制:标志读取,从第一个未完成阶段恢复。
-c|--continuespec-config.json.phasesCompletedCore Rules
核心规则
- Start Immediately: First action is TaskCreate initialization, then Phase 0 (spec study), then Phase 1
- Progressive Phase Loading: Read phase docs ONLY when that phase is about to execute
- Auto-Continue: All phases run autonomously; check TaskList to execute next pending phase
- Parse Every Output: Extract required data from each phase for next phase context
- DO NOT STOP: Continuous 6-phase pipeline until all phases complete or user exits
- Respect -y Flag: When auto mode, skip all AskUserQuestion calls, use recommended defaults
- Respect -c Flag: When continue mode, load spec-config.json and resume from checkpoint
- 立即启动:首个操作是初始化TaskCreate,然后执行Phase 0(规格学习),再进入Phase 1
- 渐进式阶段加载:仅当即将执行某个阶段时,才读取该阶段的文档
- 自动继续:所有阶段自动运行;检查TaskList以执行下一个待处理阶段
- 解析所有输出:从每个阶段提取所需数据,作为下一阶段的上下文
- 请勿停止:持续执行6阶段流水线,直至所有阶段完成或用户退出
- 尊重-y标志:在自动模式下,跳过所有AskUserQuestion调用,使用推荐默认值
- 尊重-c标志:在继续模式下,加载spec-config.json并从检查点恢复
Reference Documents by Phase
各阶段参考文档
Phase 1: Discovery
Phase 1: 发现
| Document | Purpose | When to Use |
|---|---|---|
| phases/01-discovery.md | Seed analysis and session setup | Phase start |
| specs/document-standards.md | Frontmatter format for spec-config.json | Config generation |
| 文档 | 用途 | 使用时机 |
|---|---|---|
| phases/01-discovery.md | 种子分析与会话设置 | 阶段开始时 |
| specs/document-standards.md | spec-config.json的前置元数据格式 | 配置生成时 |
Phase 2: Product Brief
Phase 2: 产品简报
| Document | Purpose | When to Use |
|---|---|---|
| phases/02-product-brief.md | Multi-CLI analysis orchestration | Phase start |
| templates/product-brief.md | Document template | Document generation |
| 文档 | 用途 | 使用时机 |
|---|---|---|
| phases/02-product-brief.md | 多CLI分析编排 | 阶段开始时 |
| templates/product-brief.md | 文档模板 | 文档生成时 |
Phase 3: Requirements
Phase 3: 需求
| Document | Purpose | When to Use |
|---|---|---|
| phases/03-requirements.md | PRD generation workflow | Phase start |
| templates/requirements-prd.md | Document template | Document generation |
| 文档 | 用途 | 使用时机 |
|---|---|---|
| phases/03-requirements.md | PRD生成工作流 | 阶段开始时 |
| templates/requirements-prd.md | 文档模板 | 文档生成时 |
Phase 4: Architecture
Phase 4: 架构设计
| Document | Purpose | When to Use |
|---|---|---|
| phases/04-architecture.md | Architecture decision workflow | Phase start |
| templates/architecture-doc.md | Document template | Document generation |
| 文档 | 用途 | 使用时机 |
|---|---|---|
| phases/04-architecture.md | 架构决策工作流 | 阶段开始时 |
| templates/architecture-doc.md | 文档模板 | 文档生成时 |
Phase 5: Epics & Stories
Phase 5: 史诗与用户故事
| Document | Purpose | When to Use |
|---|---|---|
| phases/05-epics-stories.md | Epic/Story decomposition | Phase start |
| templates/epics-template.md | Document template | Document generation |
| 文档 | 用途 | 使用时机 |
|---|---|---|
| phases/05-epics-stories.md | Epic/用户故事拆分 | 阶段开始时 |
| templates/epics-template.md | 文档模板 | 文档生成时 |
Phase 6: Readiness Check
Phase 6: 就绪检查
| Document | Purpose | When to Use |
|---|---|---|
| phases/06-readiness-check.md | Cross-document validation | Phase start |
| specs/quality-gates.md | Quality scoring criteria | Validation |
| 文档 | 用途 | 使用时机 |
|---|---|---|
| phases/06-readiness-check.md | 跨文档验证 | 阶段开始时 |
| specs/quality-gates.md | 质量评分标准 | 验证时 |
Debugging & Troubleshooting
调试与故障排除
| Issue | Solution Document |
|---|---|
| Phase execution failed | Refer to the relevant Phase documentation |
| Output does not meet expectations | specs/quality-gates.md |
| Document format issues | specs/document-standards.md |
| 问题 | 解决方案文档 |
|---|---|
| 阶段执行失败 | 参考对应阶段的文档 |
| 输出不符合预期 | specs/quality-gates.md |
| 文档格式问题 | specs/document-standards.md |
Error Handling
错误处理
| Phase | Error | Blocking? | Action |
|---|---|---|---|
| Phase 1 | Empty input | Yes | Error and exit |
| Phase 1 | CLI seed analysis fails | No | Use basic parsing fallback |
| Phase 2 | Single CLI perspective fails | No | Continue with available perspectives |
| Phase 2 | All CLI calls fail | No | Generate basic brief from seed analysis |
| Phase 3 | Gemini CLI fails | No | Use codex fallback |
| Phase 4 | Architecture review fails | No | Skip review, proceed with initial analysis |
| Phase 5 | Story generation fails | No | Generate epics without detailed stories |
| Phase 6 | Validation CLI fails | No | Generate partial report with available data |
| 阶段 | 错误 | 是否阻塞 | 操作 |
|---|---|---|---|
| Phase 1 | 输入为空 | 是 | 报错并退出 |
| Phase 1 | CLI种子分析失败 | 否 | 使用基础解析作为回退 |
| Phase 2 | 单个CLI视角分析失败 | 否 | 使用可用视角继续 |
| Phase 2 | 所有CLI调用失败 | 否 | 基于种子分析生成基础简报 |
| Phase 3 | Gemini CLI失败 | 否 | 使用Codex作为回退 |
| Phase 4 | 架构评审失败 | 否 | 跳过评审,基于初始分析继续 |
| Phase 5 | 用户故事生成失败 | 否 | 生成不含详细故事的Epic |
| Phase 6 | 验证CLI失败 | 否 | 基于可用数据生成部分报告 |
CLI Fallback Chain
CLI回退链
Gemini -> Codex -> Claude -> degraded mode (local analysis only)
Gemini -> Codex -> Claude -> 降级模式(仅本地分析)