spec-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Spec 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 workflows
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 workflows

Key Design Principles

核心设计原则

  1. Document Chain: Each phase builds on previous outputs, creating a traceable specification chain from idea to executable stories
  2. Multi-Perspective Analysis: CLI tools (Gemini/Codex/Claude) provide product, technical, and user perspectives in parallel
  3. Interactive by Default: Each phase offers user confirmation points;
    -y
    flag enables full auto mode
  4. Resumable Sessions:
    spec-config.json
    tracks completed phases;
    -c
    flag resumes from last checkpoint
  5. Template-Driven: All documents generated from standardized templates with YAML frontmatter
  6. Pure Documentation: No code generation or execution - clean handoff to existing execution workflows

  1. 文档链:每个阶段基于前一阶段的输出构建,形成从想法到可执行故事的可追溯规格说明链
  2. 多视角分析:CLI工具(Gemini/Codex/Claude)并行提供产品、技术和用户视角
  3. 默认交互式:每个阶段提供用户确认节点;
    -y
    标志启用全自动模式
  4. 可恢复会话
    spec-config.json
    跟踪已完成阶段;
    -c
    标志从最后一个检查点恢复
  5. 模板驱动:所有文档均从带有YAML前置元数据的标准化模板生成
  6. 纯文档生成:不涉及代码生成或执行环节,干净交接至现有执行工作流

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)

规格说明文档(必读)

DocumentPurposePriority
specs/document-standards.mdDocument format, frontmatter, naming conventionsP0 - Must read before execution
specs/quality-gates.mdPer-phase quality gate criteria and scoringP0 - Must read before execution
文档用途优先级
specs/document-standards.md文档格式、前置元数据、命名规范P0 - 执行前必读
specs/quality-gates.md各阶段质量门标准和评分规则P0 - 执行前必读

Template Files (Must read before generation)

模板文件(生成前必读)

DocumentPurpose
templates/product-brief.mdProduct brief document template
templates/requirements-prd.mdPRD document template
templates/architecture-doc.mdArchitecture document template
templates/epics-template.mdEpic/Story document template

文档用途
templates/product-brief.md产品简报文档模板
templates/requirements-prd.mdPRD文档模板
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:
-c|--continue
flag reads
spec-config.json.phasesCompleted
, resumes from first incomplete phase.
spec-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|--continue
标志读取
spec-config.json.phasesCompleted
,从第一个未完成阶段恢复。

Core Rules

核心规则

  1. Start Immediately: First action is TaskCreate initialization, then Phase 0 (spec study), then Phase 1
  2. Progressive Phase Loading: Read phase docs ONLY when that phase is about to execute
  3. Auto-Continue: All phases run autonomously; check TaskList to execute next pending phase
  4. Parse Every Output: Extract required data from each phase for next phase context
  5. DO NOT STOP: Continuous 6-phase pipeline until all phases complete or user exits
  6. Respect -y Flag: When auto mode, skip all AskUserQuestion calls, use recommended defaults
  7. Respect -c Flag: When continue mode, load spec-config.json and resume from checkpoint
  1. 立即启动:首个操作是初始化TaskCreate,然后执行Phase 0(规格学习),再进入Phase 1
  2. 渐进式阶段加载:仅当即将执行某个阶段时,才读取该阶段的文档
  3. 自动继续:所有阶段自动运行;检查TaskList以执行下一个待处理阶段
  4. 解析所有输出:从每个阶段提取所需数据,作为下一阶段的上下文
  5. 请勿停止:持续执行6阶段流水线,直至所有阶段完成或用户退出
  6. 尊重-y标志:在自动模式下,跳过所有AskUserQuestion调用,使用推荐默认值
  7. 尊重-c标志:在继续模式下,加载spec-config.json并从检查点恢复

Reference Documents by Phase

各阶段参考文档

Phase 1: Discovery

Phase 1: 发现

DocumentPurposeWhen to Use
phases/01-discovery.mdSeed analysis and session setupPhase start
specs/document-standards.mdFrontmatter format for spec-config.jsonConfig generation
文档用途使用时机
phases/01-discovery.md种子分析与会话设置阶段开始时
specs/document-standards.mdspec-config.json的前置元数据格式配置生成时

Phase 2: Product Brief

Phase 2: 产品简报

DocumentPurposeWhen to Use
phases/02-product-brief.mdMulti-CLI analysis orchestrationPhase start
templates/product-brief.mdDocument templateDocument generation
文档用途使用时机
phases/02-product-brief.md多CLI分析编排阶段开始时
templates/product-brief.md文档模板文档生成时

Phase 3: Requirements

Phase 3: 需求

DocumentPurposeWhen to Use
phases/03-requirements.mdPRD generation workflowPhase start
templates/requirements-prd.mdDocument templateDocument generation
文档用途使用时机
phases/03-requirements.mdPRD生成工作流阶段开始时
templates/requirements-prd.md文档模板文档生成时

Phase 4: Architecture

Phase 4: 架构设计

DocumentPurposeWhen to Use
phases/04-architecture.mdArchitecture decision workflowPhase start
templates/architecture-doc.mdDocument templateDocument generation
文档用途使用时机
phases/04-architecture.md架构决策工作流阶段开始时
templates/architecture-doc.md文档模板文档生成时

Phase 5: Epics & Stories

Phase 5: 史诗与用户故事

DocumentPurposeWhen to Use
phases/05-epics-stories.mdEpic/Story decompositionPhase start
templates/epics-template.mdDocument templateDocument generation
文档用途使用时机
phases/05-epics-stories.mdEpic/用户故事拆分阶段开始时
templates/epics-template.md文档模板文档生成时

Phase 6: Readiness Check

Phase 6: 就绪检查

DocumentPurposeWhen to Use
phases/06-readiness-check.mdCross-document validationPhase start
specs/quality-gates.mdQuality scoring criteriaValidation
文档用途使用时机
phases/06-readiness-check.md跨文档验证阶段开始时
specs/quality-gates.md质量评分标准验证时

Debugging & Troubleshooting

调试与故障排除

IssueSolution Document
Phase execution failedRefer to the relevant Phase documentation
Output does not meet expectationsspecs/quality-gates.md
Document format issuesspecs/document-standards.md
问题解决方案文档
阶段执行失败参考对应阶段的文档
输出不符合预期specs/quality-gates.md
文档格式问题specs/document-standards.md

Error Handling

错误处理

PhaseErrorBlocking?Action
Phase 1Empty inputYesError and exit
Phase 1CLI seed analysis failsNoUse basic parsing fallback
Phase 2Single CLI perspective failsNoContinue with available perspectives
Phase 2All CLI calls failNoGenerate basic brief from seed analysis
Phase 3Gemini CLI failsNoUse codex fallback
Phase 4Architecture review failsNoSkip review, proceed with initial analysis
Phase 5Story generation failsNoGenerate epics without detailed stories
Phase 6Validation CLI failsNoGenerate partial report with available data
阶段错误是否阻塞操作
Phase 1输入为空报错并退出
Phase 1CLI种子分析失败使用基础解析作为回退
Phase 2单个CLI视角分析失败使用可用视角继续
Phase 2所有CLI调用失败基于种子分析生成基础简报
Phase 3Gemini 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 -> 降级模式(仅本地分析)