writing-specs

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Writing Specifications

编写规范文档

Overview

概述

A specification defines WHAT to build and WHY. It is NOT an implementation plan.
Core principle: Reference constitutions, link to docs, keep it lean. The
/plan
command handles task decomposition.
Spec = Requirements + Architecture Plan = Tasks + Dependencies
规范文档定义要构建的内容(WHAT)及构建原因(WHY),而非实现方案。
核心原则:参考章程、链接文档、保持精简。任务分解由
/plan
命令处理。
规范文档 = 需求 + 架构 计划 = 任务 + 依赖关系

When to Use

使用场景

Use this skill when:
  • Invoked from
    /spectacular:spec
    slash command
  • Creating a new feature specification from scratch
  • Need the complete spec workflow (Run ID, worktree, brainstorm, spec, validation)
Do NOT use for:
  • Implementation plans with task breakdown - Use
    /spectacular:plan
    instead
  • API documentation - Goes in code comments or separate docs
  • Runbooks or operational guides - Different document type
Announce: "I'm using the writing-specs skill to create a feature specification."
在以下场景使用此技能:
  • 通过
    /spectacular:spec
    斜杠命令调用时
  • 从零开始创建新功能规范文档时
  • 需要完整的规范工作流(Run ID、工作树、头脑风暴、规范文档、验证)时
请勿在以下场景使用:
  • 带任务分解的实现方案 - 请使用
    /spectacular:plan
  • API文档 - 应放在代码注释或独立文档中
  • 运行手册或操作指南 - 属于不同文档类型
提示语:"我正在使用编写规范文档技能来创建功能规范文档。"

Workspace Detection

工作区检测

Before starting the spec workflow, detect the workspace mode:
bash
undefined
启动规范工作流前,先检测工作区模式:
bash
undefined

Detect workspace mode

Detect workspace mode

REPO_COUNT=$(find . -maxdepth 2 -name ".git" -type d 2>/dev/null | wc -l | tr -d ' ') if [ "$REPO_COUNT" -gt 1 ]; then echo "Multi-repo workspace detected ($REPO_COUNT repos)" WORKSPACE_MODE="multi-repo" WORKSPACE_ROOT=$(pwd)

List detected repos

find . -maxdepth 2 -name ".git" -type d | xargs -I{} dirname {} | sed 's|^./||' else echo "Single-repo mode" WORKSPACE_MODE="single-repo" fi

**Single-repo mode (current behavior):**
- Specs stored in `specs/{runId}-{feature}/spec.md` at repo root
- Worktree created at `.worktrees/{runId}-main/`
- Constitution referenced from `@docs/constitutions/current/`

**Multi-repo mode (new behavior):**
- Specs stored in `./specs/{runId}-{feature}/spec.md` at WORKSPACE root
- NO worktree created (specs live at workspace level, not inside any repo)
- Each repo's constitution referenced separately
REPO_COUNT=$(find . -maxdepth 2 -name ".git" -type d 2>/dev/null | wc -l | tr -d ' ') if [ "$REPO_COUNT" -gt 1 ]; then echo "Multi-repo workspace detected ($REPO_COUNT repos)" WORKSPACE_MODE="multi-repo" WORKSPACE_ROOT=$(pwd)

List detected repos

find . -maxdepth 2 -name ".git" -type d | xargs -I{} dirname {} | sed 's|^./||' else echo "Single-repo mode" WORKSPACE_MODE="single-repo" fi

**单仓库模式(当前默认行为)**:
- 规范文档存储在仓库根目录的`specs/{runId}-{feature}/spec.md`
- 工作树创建在`.worktrees/{runId}-main/`
- 章程引用自`@docs/constitutions/current/`

**多仓库模式(新增行为)**:
- 规范文档存储在工作区根目录的`./specs/{runId}-{feature}/spec.md`
- 不创建工作树(规范文档存于工作区层级,而非任何仓库内部)
- 分别引用每个仓库的章程

Constitution Adherence

章程合规性

All specifications MUST follow: @docs/constitutions/current/
  • architecture.md - Layer boundaries, project structure
  • patterns.md - Mandatory patterns (next-safe-action, ts-pattern, etc.)
  • schema-rules.md - Database design philosophy
  • tech-stack.md - Approved libraries and versions
  • testing.md - Testing requirements
所有规范文档必须遵循:@docs/constitutions/current/
  • architecture.md - 分层边界、项目结构
  • patterns.md - 强制模式(next-safe-action、ts-pattern等)
  • schema-rules.md - 数据库设计原则
  • tech-stack.md - 已批准的库及版本
  • testing.md - 测试要求

The Process

工作流程

Step 0: Generate Run ID

步骤0:生成Run ID

First action: Generate a unique run identifier for this spec.
bash
undefined
首要操作:为此规范生成唯一的运行标识符。
bash
undefined

Generate 6-char hash from feature name + timestamp

Generate 6-char hash from feature name + timestamp

TIMESTAMP=$(date +%s) RUN_ID=$(echo "{feature-description}-$TIMESTAMP" | shasum -a 256 | head -c 6) echo "RUN_ID: $RUN_ID"

**CRITICAL**: Execute this entire block as a single multi-line Bash tool call. The comment on the first line is REQUIRED - without it, command substitution `$(...)` causes parse errors.

**Store for use in:**
- Spec directory name: `specs/{run-id}-{feature-slug}/`
- Spec frontmatter metadata
- Plan generation
- Branch naming during execution

**Announce:** "Generated RUN_ID: {run-id} for tracking this spec run"
TIMESTAMP=$(date +%s) RUN_ID=$(echo "{feature-description}-$TIMESTAMP" | shasum -a 256 | head -c 6) echo "RUN_ID: $RUN_ID"

**关键注意事项**:需将此代码块作为多行Bash工具调用整体执行。第一行的注释是必需的——缺少它时,命令替换`$(...)`会导致解析错误。

**Run ID的使用场景**:
- 规范文档目录名称:`specs/{run-id}-{feature-slug}/`
- 规范文档前置元数据
- 计划生成
- 执行阶段的分支命名

**提示语**:"已生成RUN_ID: {run-id},用于追踪此规范文档的运行流程"

Step 0.5: Create Isolated Worktree

步骤0.5:创建独立工作树

Announce: "Creating isolated worktree for this spec run..."
Multi-repo mode: Skip worktree creation. Specs live at workspace root, not inside any repo.
bash
if [ "$WORKSPACE_MODE" = "multi-repo" ]; then
  echo "Multi-repo mode: Specs stored at workspace root, no worktree needed"
  mkdir -p specs/${RUN_ID}-${FEATURE_SLUG}
  # Skip to Step 1 (brainstorming)
fi
Single-repo mode: Continue with worktree creation as normal.
Create worktree for isolated development:
  1. Create branch using git-spice:
    • Use
      using-git-spice
      skill to create branch
      {runId}-main
      from current branch
    • Branch name format:
      {runId}-main
      (e.g.,
      abc123-main
      )
  2. Create worktree:
    bash
    # Create worktree at .worktrees/{runId}-main/
    git worktree add .worktrees/${RUN_ID}-main ${RUN_ID}-main
  3. Error handling:
    • If worktree already exists: "Worktree {runId}-main already exists. Remove it first with
      git worktree remove .worktrees/{runId}-main
      or use a different feature name."
    • If worktree creation fails: Report the git error details and exit
Working directory context:
  • All subsequent file operations happen in
    .worktrees/{runId}-main/
  • Brainstorming and spec generation occur in the worktree context
  • Main repository working directory remains unchanged
Announce: "Worktree created at .worktrees/{runId}-main/ - all work will happen in isolation"
提示语:"正在为此规范运行流程创建独立工作树..."
多仓库模式:跳过工作树创建。规范文档存于工作区根目录,而非任何仓库内部。
bash
if [ "$WORKSPACE_MODE" = "multi-repo" ]; then
  echo "Multi-repo mode: Specs stored at workspace root, no worktree needed"
  mkdir -p specs/${RUN_ID}-${FEATURE_SLUG}
  # Skip to Step 1 (brainstorming)
fi
单仓库模式:按常规流程创建工作树。
创建用于独立开发的工作树
  1. 使用git-spice创建分支:
    • 使用
      using-git-spice
      技能从当前分支创建
      {runId}-main
      分支
    • 分支名称格式:
      {runId}-main
      (示例:
      abc123-main
  2. 创建工作树:
    bash
    # Create worktree at .worktrees/{runId}-main/
    git worktree add .worktrees/${RUN_ID}-main ${RUN_ID}-main
  3. 错误处理:
    • 若工作树已存在:"工作树{runId}-main已存在,请先通过
      git worktree remove .worktrees/{runId}-main
      删除,或使用其他功能名称。"
    • 若工作树创建失败:报告Git错误详情并退出
工作目录上下文:
  • 后续所有文件操作均在
    .worktrees/{runId}-main/
    中执行
  • 头脑风暴和规范文档生成在工作树上下文中进行
  • 主仓库工作目录保持不变
提示语:"工作树已创建于.worktrees/{runId}-main/ - 所有操作将在此独立环境中进行"

Step 0.6: Install Dependencies in Worktree

步骤0.6:在工作树中安装依赖

REQUIRED: Each worktree needs dependencies installed before work begins.
  1. Check CLAUDE.md for setup commands:
    Look for this pattern in the project's CLAUDE.md:
    markdown
    ## Development Commands
    
    ### Setup
    
    - **install**: `bun install`
    - **postinstall**: `npx prisma generate`
  2. If setup commands found, run installation:
    bash
    # Navigate to worktree
    cd .worktrees/${RUN_ID}-main
    
    # Check if dependencies already installed (handles resume)
    if [ ! -d node_modules ]; then
      echo "Installing dependencies..."
      {install-command}  # From CLAUDE.md (e.g., bun install)
    
      # Run postinstall if defined
      if [ -n "{postinstall-command}" ]; then
        echo "Running postinstall (codegen)..."
        {postinstall-command}  # From CLAUDE.md (e.g., npx prisma generate)
      fi
    else
      echo "Dependencies already installed"
    fi
  3. If setup commands NOT found in CLAUDE.md:
    Error and instruct user:
    markdown
    Setup Commands Required
    
    Worktrees need dependencies installed to run quality checks and codegen.
    
    Please add to your project's CLAUDE.md:
    
    ## Development Commands
    
    ### Setup
    
    - **install**: `bun install` (or npm install, pnpm install, etc.)
    - **postinstall**: `npx prisma generate` (optional - for codegen)
    
    Then re-run: /spectacular:spec {feature-description}
Announce: "Dependencies installed in worktree - ready for spec generation"
必需操作:开始工作前,每个工作树都需要安装依赖。
  1. 查看CLAUDE.md中的设置命令:
    在项目的CLAUDE.md中查找以下格式的内容:
    markdown
    ## Development Commands
    
    ### Setup
    
    - **install**: `bun install`
    - **postinstall**: `npx prisma generate`
  2. 若找到设置命令,执行安装:
    bash
    # Navigate to worktree
    cd .worktrees/${RUN_ID}-main
    
    # Check if dependencies already installed (handles resume)
    if [ ! -d node_modules ]; then
      echo "Installing dependencies..."
      {install-command}  # From CLAUDE.md (e.g., bun install)
    
      # Run postinstall if defined
      if [ -n "{postinstall-command}" ]; then
        echo "Running postinstall (codegen)..."
        {postinstall-command}  # From CLAUDE.md (e.g., npx prisma generate)
      fi
    else
      echo "Dependencies already installed"
    fi
  3. 若CLAUDE.md中未找到设置命令:
    错误提示并指导用户:
    markdown
    需要设置命令
    
    工作树需要安装依赖才能运行质量检查和代码生成。
    
    请在项目的CLAUDE.md中添加以下内容:
    
    ## Development Commands
    
    ### Setup
    
    - **install**: `bun install`(或npm install、pnpm install等)
    - **postinstall**: `npx prisma generate`(可选,用于代码生成)
    
    然后重新运行:/spectacular:spec {feature-description}
提示语:"已在工作树中安装依赖 - 准备好生成规范文档"

Step 1: Brainstorm Requirements

步骤1:头脑风暴需求

Context: All brainstorming happens in the context of the worktree (
.worktrees/{runId}-main/
)
Announce: "I'm brainstorming the design using Phases 1-3 (Understanding, Exploration, Design Presentation)."
Create TodoWrite checklist:
Brainstorming for Spec:
- [ ] Phase 1: Understanding (purpose, constraints, criteria)
- [ ] Phase 2: Exploration (2-3 approaches proposed)
- [ ] Phase 3: Design Presentation (design validated)
- [ ] Proceed to Step 2: Generate Specification
上下文:所有头脑风暴在工作树(
.worktrees/{runId}-main/
)上下文中进行
提示语:"我正在使用第1-3阶段(理解、探索、设计展示)来构思设计方案。"
创建TodoWrite检查清单:
规范文档头脑风暴:
- [ ] 阶段1:理解(目标、约束、验收标准)
- [ ] 阶段2:探索(提出2-3种实现方案)
- [ ] 阶段3:设计展示(验证设计方案)
- [ ] 进入步骤2:生成规范文档

Phase 1: Understanding

阶段1:理解

Goal: Clarify scope, constraints, and success criteria.
  1. Check current project state in working directory (note: we're in the worktree)
  2. Read @docs/constitutions/current/ to understand constraints:
    • architecture.md - Layer boundaries
    • patterns.md - Mandatory patterns
    • tech-stack.md - Approved libraries
    • schema-rules.md - Database rules
  3. Ask ONE question at a time to refine the idea
  4. Use AskUserQuestion tool for multiple choice options
  5. Gather: Purpose, constraints, success criteria
Constitution compliance:
  • All architectural decisions must follow @docs/constitutions/current/architecture.md
  • All pattern choices must follow @docs/constitutions/current/patterns.md
  • All library selections must follow @docs/constitutions/current/tech-stack.md
目标:明确范围、约束和成功标准。
  1. 检查工作目录中的当前项目状态(注意:处于工作树环境)
  2. 阅读@docs/constitutions/current/以了解约束条件:
    • architecture.md - 分层边界
    • patterns.md - 强制模式
    • tech-stack.md - 已批准的库
    • schema-rules.md - 数据库规则
  3. 一次提出一个问题以完善需求
  4. 使用AskUserQuestion工具提供多选选项
  5. 收集信息:目标、约束、成功标准
章程合规性:
  • 所有架构决策必须遵循@docs/constitutions/current/architecture.md
  • 所有模式选择必须遵循@docs/constitutions/current/patterns.md
  • 所有库选择必须遵循@docs/constitutions/current/tech-stack.md

Phase 2: Exploration

阶段2:探索

Goal: Propose and evaluate 2-3 architectural approaches.
  1. Propose 2-3 different approaches that follow constitutional constraints
  2. For each approach explain:
    • Core architecture (layers, patterns)
    • Trade-offs (complexity vs features)
    • Constitution compliance (which patterns used)
  3. Use AskUserQuestion tool to present approaches as structured choices
  4. Ask partner which approach resonates
目标:提出并评估2-3种架构方案。
  1. 提出2-3种符合章程约束的不同方案
  2. 针对每个方案说明:
    • 核心架构(分层、模式)
    • 权衡(复杂度与功能)
    • 章程合规性(使用了哪些模式)
  3. 使用AskUserQuestion工具将方案整理为结构化选项
  4. 询问协作方更倾向于哪种方案

Phase 3: Design Presentation

阶段3:设计展示

Goal: Present detailed design incrementally and validate.
  1. Present design in 200-300 word sections
  2. Cover: Architecture, components, data flow, error handling, testing
  3. After each section ask: "Does this look right so far?" (open-ended)
  4. Use open-ended questions for freeform feedback
  5. Adjust design based on feedback
After Phase 3: Mark TodoWrite complete and proceed immediately to Step 2.
目标:逐步展示详细设计并进行验证。
  1. 以200-300字的分段形式展示设计
  2. 涵盖内容:架构、组件、数据流、错误处理、测试
  3. 每段展示后询问:"目前这个设计看起来是否合理?"(开放式问题)
  4. 使用开放式问题收集自由反馈
  5. 根据反馈调整设计
完成阶段3后:标记TodoWrite为已完成,并立即进入步骤2。

Step 2: Generate Specification

步骤2:生成规范文档

Announce: "Generating the specification document..."
Task:
  • Feature: {feature-description}
  • Design context: {summary from brainstorming}
  • RUN_ID: {run-id from Step 0}
  • Output location:
    .worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md
  • Constitution: All design decisions must follow @docs/constitutions/current/
  • Analyze codebase for task-specific context:
    • Existing files to modify
    • New files to create (with exact paths per @docs/constitutions/current/architecture.md)
    • Dependencies needed (must be in @docs/constitutions/current/tech-stack.md)
    • Schema changes required (following @docs/constitutions/current/schema-rules.md)
  • Follow all Iron Laws (see below):
    • Reference constitutions, don't duplicate
    • Link to SDK docs, don't embed examples
    • No implementation plans (that's
      /spectacular:plan
      's job)
    • Keep it lean (<300 lines)
Spec frontmatter must include:
yaml
---
runId: {run-id}
feature: {feature-slug}
created: {date}
status: draft
---
Use the Spec Structure template below to generate the document.
提示语:"正在生成规范文档..."
任务:
  • 功能:{feature-description}
  • 设计上下文:{头脑风暴总结}
  • RUN_ID:{步骤0生成的run-id}
  • 输出位置:
    .worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md
  • 章程要求:所有设计决策必须遵循@docs/constitutions/current/
  • 分析代码库以获取任务特定上下文:
    • 需要修改的现有文件
    • 需要创建的新文件(路径需符合@docs/constitutions/current/architecture.md)
    • 需要的依赖(必须包含在@docs/constitutions/current/tech-stack.md中)
    • 需要的Schema变更(遵循@docs/constitutions/current/schema-rules.md)
  • 遵循所有铁则(见下文):
    • 参考章程,不重复内容
    • 链接至SDK文档,不嵌入示例
    • 不包含实现方案(这是
      /spectacular:plan
      的职责)
    • 保持精简(少于300行)
规范文档前置元数据必须包含:
yaml
---
runId: {run-id}
feature: {feature-slug}
created: {date}
status: draft
---
使用下方的规范文档结构模板生成文档。

Step 2.5: Commit Spec to Worktree

步骤2.5:将规范文档提交至工作树

After spec generation completes, commit the spec to the worktree branch:
bash
cd .worktrees/${RUN_ID}-main
git add specs/
git commit -m "spec: add ${feature-slug} specification [${RUN_ID}]"
Announce: "Spec committed to {runId}-main branch in worktree"
规范文档生成完成后,将其提交至工作树分支:
bash
cd .worktrees/${RUN_ID}-main
git add specs/
git commit -m "spec: add ${feature-slug} specification [${RUN_ID}]"
提示语:"规范文档已提交至工作树中的{runId}-main分支"

Step 3: Architecture Quality Validation

步骤3:架构质量验证

CRITICAL: Before reporting completion, validate the spec against architecture quality standards.
Announce: "Validating spec against architecture quality standards..."
Read the generated spec and check against these dimensions:
关键操作:报告完成前,必须验证规范文档是否符合架构质量标准。
提示语:"正在验证规范文档是否符合架构质量标准..."
阅读生成的规范文档,从以下维度进行检查:

3.1 Constitution Compliance

3.1 章程合规性

  • Architecture: All components follow layer boundaries (@docs/constitutions/current/architecture.md)
    • Models - Services - Actions - UI (no layer violations)
    • Server/Client component boundaries respected
  • Patterns: All mandatory patterns referenced (@docs/constitutions/current/patterns.md)
    • next-safe-action for server actions
    • ts-pattern for discriminated unions
    • Zod schemas for validation
    • routes.ts for navigation
  • Schema: Database design follows rules (@docs/constitutions/current/schema-rules.md)
    • Proper indexing strategy
    • Naming conventions
    • Relationship patterns
  • Tech Stack: All dependencies approved (@docs/constitutions/current/tech-stack.md)
    • No unapproved libraries
    • Correct versions specified
  • Testing: Testing strategy defined (@docs/constitutions/current/testing.md)
  • 架构:所有组件遵循分层边界(@docs/constitutions/current/architecture.md)
    • 模型 - 服务 - 操作 - UI(无分层违规)
    • 服务器/客户端组件边界得到尊重
  • 模式:所有强制模式均已引用(@docs/constitutions/current/patterns.md)
    • 使用next-safe-action处理服务器操作
    • 使用ts-pattern处理区分联合类型
    • 使用Zod schema进行验证
    • 使用routes.ts处理导航
  • Schema:数据库设计遵循规则(@docs/constitutions/current/schema-rules.md)
    • 合理的索引策略
    • 命名规范
    • 关系模式
  • 技术栈:所有依赖均已获批(@docs/constitutions/current/tech-stack.md)
    • 无未获批的库
    • 指定了正确的版本
  • 测试:定义了测试策略(@docs/constitutions/current/testing.md)

3.2 Specification Quality (Iron Laws)

3.2 规范文档质量(铁则)

  • No Duplication: Constitution rules referenced, not recreated
  • No Code Examples: External docs linked, not embedded
  • No Implementation Plans: Focus on WHAT/WHY, not HOW/WHEN
  • Lean: Spec < 300 lines (if longer, likely duplicating constitutions)
  • 无重复:仅引用章程规则,不重复编写
  • 无代码示例:仅链接至外部文档,不嵌入内容
  • 无实现方案:聚焦于WHAT/WHY,而非HOW/WHEN
  • 精简:规范文档少于300行(若过长,可能重复了章程内容)

3.3 Requirements Quality

3.3 需求质量

  • Completeness: All FRs and NFRs defined, no missing scenarios
  • Clarity: All requirements unambiguous and specific (no "fast", "good", "better")
  • Measurability: All requirements have testable acceptance criteria
  • Consistency: No conflicts between sections
  • Edge Cases: Boundary conditions and error handling addressed
  • Dependencies: External dependencies and assumptions documented
  • 完整性:所有功能需求(FR)和非功能需求(NFR)均已定义,无遗漏场景
  • 清晰度:所有需求明确无歧义(避免使用"快速"、"良好"、"更好"等模糊表述)
  • 可测性:所有需求均有可测试的验收标准
  • 一致性:各章节之间无冲突
  • 边界场景:已考虑边界条件和错误处理
  • 依赖关系:已记录外部依赖和假设条件

3.4 Architecture Traceability

3.4 架构可追溯性

  • File Paths: All new/modified files have exact paths per architecture.md
  • Integration Points: How feature integrates with existing system clear
  • Migration Impact: Schema changes and data migrations identified
  • Security: Auth/authz requirements explicit
  • 文件路径:所有新增/修改文件的路径均符合architecture.md的要求
  • 集成点:功能与现有系统的集成方式清晰明确
  • 迁移影响:已识别Schema变更和数据迁移需求
  • 安全性:认证/授权需求明确

3.5 Surface Issues

3.5 问题反馈

If ANY checks fail, create
.worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/clarifications.md
with:
markdown
undefined
若任何检查未通过,创建
.worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/clarifications.md
文件,内容如下:
markdown
undefined

Clarifications Needed

需要澄清的问题

[Category: Constitution/Quality/Requirements/Architecture]

[分类:章程/质量/需求/架构]

Issue: {What's wrong} Location: {Spec section reference} Severity: [BLOCKER/CRITICAL/MINOR] Question: {What needs to be resolved}
Options:
  • A: {Option with trade-offs}
  • B: {Option with trade-offs}
  • Custom: {User provides alternative}

**Iteration limit**: Maximum 3 validation cycles. If issues remain after 3 iterations, escalate to user with clarifications.md.
问题:{具体问题} 位置:{规范文档章节引用} 严重程度:[阻塞/严重/次要] 疑问:{需要解决的内容}
选项:
  • A: {带权衡的选项}
  • B: {带权衡的选项}
  • 自定义:{用户提供替代方案}

**迭代限制**:最多3次验证循环。若3次迭代后仍存在问题,通过clarifications.md将问题升级给用户。

Step 4: Report Completion

步骤4:报告完成情况

IMPORTANT: After reporting completion, STOP HERE. Do not proceed to plan generation automatically. The user must review the spec and explicitly run
/spectacular:plan
when ready.
After validation passes OR clarifications documented, report to user:
If validation passed (single-repo mode):
Feature Specification Complete & Validated

RUN_ID: {run-id}
Worktree: .worktrees/{run-id}-main/
Branch: {run-id}-main
Location: .worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md

Constitution Compliance: PASS
Architecture Quality: PASS
Requirements Quality: PASS

Note: Spec is in isolated worktree, main repo unchanged.

Next Steps (User Actions - DO NOT AUTO-EXECUTE):
1. Review the spec: .worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md
2. When ready, create implementation plan: /spectacular:plan @.worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md
If validation passed (multi-repo mode):
Feature Specification Complete & Validated

RUN_ID: {run-id}
Workspace: {workspace-root}
Location: specs/{run-id}-{feature-slug}/spec.md

Repos affected:
- backend: @backend/docs/constitutions/current/
- frontend: @frontend/docs/constitutions/current/

Constitution Compliance: PASS
Architecture Quality: PASS
Requirements Quality: PASS

Note: Spec is at workspace root, affecting multiple repos.

Next Steps (User Actions - DO NOT AUTO-EXECUTE):
1. Review the spec: specs/{run-id}-{feature-slug}/spec.md
2. When ready, create plan: /spectacular:plan @specs/{run-id}-{feature-slug}/spec.md
If clarifications needed (single-repo mode):
Feature Specification Complete - Clarifications Needed

RUN_ID: {run-id}
Worktree: .worktrees/{run-id}-main/
Branch: {run-id}-main
Location: .worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md
Clarifications: .worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/clarifications.md

Note: Spec is in isolated worktree, main repo unchanged.

Next Steps:
1. Review spec: .worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md
2. Answer clarifications: .worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/clarifications.md
3. Once resolved, re-run: /spectacular:spec {feature-description}
If clarifications needed (multi-repo mode):
Feature Specification Complete - Clarifications Needed

RUN_ID: {run-id}
Workspace: {workspace-root}
Location: specs/{run-id}-{feature-slug}/spec.md
Clarifications: specs/{run-id}-{feature-slug}/clarifications.md

Repos affected:
- backend: @backend/docs/constitutions/current/
- frontend: @frontend/docs/constitutions/current/

Note: Spec is at workspace root, affecting multiple repos.

Next Steps:
1. Review spec: specs/{run-id}-{feature-slug}/spec.md
2. Answer clarifications: specs/{run-id}-{feature-slug}/clarifications.md
3. Once resolved, re-run: /spectacular:spec {feature-description}

重要提示:报告完成后,请在此停止。请勿自动进入计划生成阶段。用户需先审核规范文档,待准备就绪后显式运行
/spectacular:plan
验证通过或问题已记录后,向用户报告:
若验证通过(单仓库模式):
功能规范文档已完成并通过验证

RUN_ID: {run-id}
工作树:.worktrees/{run-id}-main/
分支:{run-id}-main
位置:.worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md

章程合规性:通过
架构质量:通过
需求质量:通过

说明:规范文档存储在独立工作树中,主仓库未做任何修改。

下一步操作(用户执行 - 请勿自动执行):
1. 审核规范文档:.worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md
2. 准备就绪后,创建实现计划:/spectacular:plan @.worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md
若验证通过(多仓库模式):
功能规范文档已完成并通过验证

RUN_ID: {run-id}
工作区:{workspace-root}
位置:specs/{run-id}-{feature-slug}/spec.md

受影响的仓库:
- backend: @backend/docs/constitutions/current/
- frontend: @frontend/docs/constitutions/current/

章程合规性:通过
架构质量:通过
需求质量:通过

说明:规范文档存储在工作区根目录,影响多个仓库。

下一步操作(用户执行 - 请勿自动执行):
1. 审核规范文档:specs/{run-id}-{feature-slug}/spec.md
2. 准备就绪后,创建计划:/spectacular:plan @specs/{run-id}-{feature-slug}/spec.md
若需要澄清问题(单仓库模式):
功能规范文档已完成 - 需要澄清问题

RUN_ID: {run-id}
工作树:.worktrees/{run-id}-main/
分支:{run-id}-main
位置:.worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md
澄清文档:.worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/clarifications.md

说明:规范文档存储在独立工作树中,主仓库未做任何修改。

下一步操作:
1. 审核规范文档:.worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/spec.md
2. 回答澄清问题:.worktrees/{run-id}-main/specs/{run-id}-{feature-slug}/clarifications.md
3. 问题解决后,重新运行:/spectacular:spec {feature-description}
若需要澄清问题(多仓库模式):
功能规范文档已完成 - 需要澄清问题

RUN_ID: {run-id}
工作区:{workspace-root}
位置:specs/{run-id}-{feature-slug}/spec.md
澄清文档:specs/{run-id}-{feature-slug}/clarifications.md

受影响的仓库:
- backend: @backend/docs/constitutions/current/
- frontend: @frontend/docs/constitutions/current/

说明:规范文档存储在工作区根目录,影响多个仓库。

下一步操作:
1. 审核规范文档:specs/{run-id}-{feature-slug}/spec.md
2. 回答澄清问题:specs/{run-id}-{feature-slug}/clarifications.md
3. 问题解决后,重新运行:/spectacular:spec {feature-description}

Spec Structure

规范文档结构

markdown
undefined
markdown
undefined

Feature: {Feature Name}

功能:{功能名称}

Status: Draft Created: {date}
状态:草稿 创建日期:{日期}

Problem Statement

问题描述

Current State: {What exists today and what's missing/broken}
Desired State: {What we want to achieve}
Gap: {Specific problem this feature solves}
当前状态: {现有内容及缺失/问题点}
期望状态: {我们想要实现的目标}
差距: {此功能要解决的具体问题}

Requirements

需求

Note: All features must follow @docs/constitutions/current/
说明:所有功能必须遵循@docs/constitutions/current/

Functional Requirements

功能需求

  • FR1: {specific requirement}
  • FR2: {specific requirement}
  • FR1:{具体需求}
  • FR2:{具体需求}

Non-Functional Requirements

非功能需求

  • NFR1: {performance/security/DX requirement}
  • NFR2: {performance/security/DX requirement}
  • NFR1:{性能/安全/开发体验需求}
  • NFR2:{性能/安全/开发体验需求}

Architecture

架构

Layer boundaries: @docs/constitutions/current/architecture.md Required patterns: @docs/constitutions/current/patterns.md
分层边界:@docs/constitutions/current/architecture.md 必需模式:@docs/constitutions/current/patterns.md

Components

组件

New Files:
  • src/lib/models/{name}.ts
    - {purpose}
  • src/lib/services/{name}-service.ts
    - {purpose}
  • src/lib/actions/{name}-actions.ts
    - {purpose}
Modified Files:
  • {path}
    - {what changes}
新增文件:
  • src/lib/models/{name}.ts
    - {用途}
  • src/lib/services/{name}-service.ts
    - {用途}
  • src/lib/actions/{name}-actions.ts
    - {用途}
修改文件:
  • {路径}
    - {修改内容}

Dependencies

依赖

New packages:
  • {package}
    - {purpose}
  • See: {link to official docs}
Schema changes:
  • {migration name} - {purpose}
  • Rules: @docs/constitutions/current/schema-rules.md
新增包:
  • {包名}
    - {用途}
  • 参考:{官方文档链接}
Schema变更:
  • {迁移名称} - {用途}
  • 规则:@docs/constitutions/current/schema-rules.md

Integration Points

集成点

  • Auth: Uses existing Auth.js setup
  • Database: Prisma client per @docs/constitutions/current/tech-stack.md
  • Validation: Zod schemas per @docs/constitutions/current/patterns.md
  • 认证:使用现有Auth.js配置
  • 数据库:使用Prisma客户端(符合@docs/constitutions/current/tech-stack.md)
  • 验证:使用Zod schema(符合@docs/constitutions/current/patterns.md)

Acceptance Criteria

验收标准

Constitution compliance:
  • All patterns followed (@docs/constitutions/current/patterns.md)
  • Architecture boundaries respected (@docs/constitutions/current/architecture.md)
  • Testing requirements met (@docs/constitutions/current/testing.md)
Feature-specific:
  • {criterion for this feature}
  • {criterion for this feature}
  • {criterion for this feature}
Verification:
  • All tests pass
  • Linting passes
  • Feature works end-to-end
章程合规性:
  • 已遵循所有模式(@docs/constitutions/current/patterns.md)
  • 已遵守架构边界(@docs/constitutions/current/architecture.md)
  • 已满足测试要求(@docs/constitutions/current/testing.md)
功能特定标准:
  • {此功能的验收标准}
  • {此功能的验收标准}
  • {此功能的验收标准}
验证:
  • 所有测试通过
  • 代码检查通过
  • 功能端到端可用

Open Questions

待解决问题

{List any unresolved questions or decisions needed}
{列出所有未解决的问题或需要做出的决策}

References

参考文档

  • Architecture: @docs/constitutions/current/architecture.md
  • Patterns: @docs/constitutions/current/patterns.md
  • Schema Rules: @docs/constitutions/current/schema-rules.md
  • Tech Stack: @docs/constitutions/current/tech-stack.md
  • Testing: @docs/constitutions/current/testing.md
  • {External SDK}: {link to official docs}
undefined
  • 架构:@docs/constitutions/current/architecture.md
  • 模式:@docs/constitutions/current/patterns.md
  • Schema规则:@docs/constitutions/current/schema-rules.md
  • 技术栈:@docs/constitutions/current/tech-stack.md
  • 测试:@docs/constitutions/current/testing.md
  • {外部SDK}:{官方文档链接}
undefined

Multi-Repo Spec Template Addition

多仓库规范文档模板补充

For multi-repo features, add this section to the spec:
markdown
undefined
对于多仓库功能,在规范文档中添加以下章节:
markdown
undefined

Constitutions

章程

This feature must comply with constitutions from each affected repo:
backend: @backend/docs/constitutions/current/
  • architecture.md - Backend layer boundaries
  • patterns.md - Backend patterns (next-safe-action, etc.)
  • schema-rules.md - Database design rules
frontend: @frontend/docs/constitutions/current/
  • architecture.md - Frontend component structure
  • patterns.md - Frontend patterns (React Query, etc.)
shared-lib: @shared-lib/docs/constitutions/current/
  • (if applicable)

When brainstorming in multi-repo mode:
- Read constitutions from ALL relevant repos
- Note which repo each architectural decision applies to
- Ensure cross-repo consistency (e.g., API contracts)
此功能必须遵循所有受影响仓库的章程:
backend:@backend/docs/constitutions/current/
  • architecture.md - 后端分层边界
  • patterns.md - 后端模式(next-safe-action等)
  • schema-rules.md - 数据库设计规则
frontend:@frontend/docs/constitutions/current/
  • architecture.md - 前端组件结构
  • patterns.md - 前端模式(React Query等)
shared-lib:@shared-lib/docs/constitutions/current/
  • (若适用)

在多仓库模式下进行头脑风暴时:
- 阅读所有相关仓库的章程
- 记录每个架构决策适用的仓库
- 确保跨仓库一致性(如API契约)

Iron Laws

铁则

1. Reference, Don't Duplicate

1. 仅引用,不重复

NEVER recreate constitution rules in the spec
<Bad> ```markdown
切勿在规范文档中重复章程规则
<错误示例>
markdown
undefined

Layered Architecture

分层架构

The architecture has three layers:
  • Models: Data access with Prisma
  • Services: Business logic
  • Actions: Input validation with Zod
</Bad>

<Good>
```markdown
架构包含三层:
  • 模型:使用Prisma进行数据访问
  • 服务:业务逻辑
  • 操作:使用Zod进行输入验证
</错误示例>

<正确示例>
```markdown

Architecture

架构

Layer boundaries: @docs/constitutions/current/architecture.md
Components follow the established 3-layer pattern.
</Good>
分层边界:@docs/constitutions/current/architecture.md
组件遵循已确立的三层模式。
</正确示例>

2. Link to Docs, Don't Embed Examples

2. 链接至文档,不嵌入示例

NEVER include code examples from external libraries
<Bad> ```markdown
切勿包含外部库的代码示例
<错误示例>
markdown
undefined

Zod Validation

Zod验证

typescript
import { z } from 'zod';

export const schema = z.object({
  name: z.string().min(3),
  email: z.string().email()
});
</Bad>

<Good>
```markdown
typescript
import { z } from 'zod';

export const schema = z.object({
  name: z.string().min(3),
  email: z.string().email()
});
</错误示例>

<正确示例>
```markdown

Validation

验证

Use Zod schemas per @docs/constitutions/current/patterns.md
See: https://zod.dev for object schema syntax
</Good>
根据@docs/constitutions/current/patterns.md使用Zod schema
参考:https://zod.dev 获取对象schema语法
</正确示例>

3. No Implementation Plans

3. 不包含实现方案

NEVER include task breakdown or migration phases
<Bad> ```markdown
切勿包含任务分解或迁移阶段
<错误示例>
markdown
undefined

Migration Plan

迁移计划

Phase 1: Database Schema

阶段1:数据库Schema

  1. Create Prisma migration
  2. Run migration
  3. Verify indexes
  1. 创建Prisma迁移
  2. 运行迁移
  3. 验证索引

Phase 2: Backend Implementation

阶段2:后端实现

...
</Bad>

<Good>
```markdown
...
</错误示例>

<正确示例>
```markdown

Dependencies

依赖

Schema changes:
  • Migration:
    init_rooms
    - Add Room, RoomParticipant, WaitingListEntry models
Implementation order determined by
/plan
command.
</Good>
Schema变更:
  • 迁移:
    init_rooms
    - 添加Room、RoomParticipant、WaitingListEntry模型
实现顺序由
/plan
命令确定。
</正确示例>

4. No Success Metrics

4. 不包含成功指标

NEVER include adoption metrics, performance targets, or measurement strategies
<Bad> ```markdown
切勿包含采用率指标、性能目标或测量策略
<错误示例>
markdown
undefined

Success Metrics

成功指标

  1. Adoption: 80% of users use feature within first month
  2. Performance: Page loads in <500ms
  3. Engagement: <5% churn rate
</Bad>

<Good>
```markdown
  1. 采用率:上线首月内80%的用户使用此功能
  2. 性能:页面加载时间<500ms
  3. 留存率:流失率<5%
</错误示例>

<正确示例>
```markdown

Non-Functional Requirements

非功能需求

  • NFR1: Page load performance <500ms (measured per @docs/constitutions/current/testing.md)
  • NFR2: Support 1000 concurrent users
</Good>
  • NFR1:页面加载性能<500ms(根据@docs/constitutions/current/testing.md测量)
  • NFR2:支持1000并发用户
</正确示例>

Common Mistakes

常见错误

MistakeWhy It's WrongFix
Including full Prisma schemasDuplicates what goes in codeList model names + purposes, reference schema-rules.md
Writing test code examplesShows HOW not WHATList what to test, reference testing.md for how
Explaining ts-pattern syntaxAlready in patterns.mdReference patterns.md, list where pattern applies
Creating
/notes
subdirectory
Violates single-file principleKeep spec lean, remove supporting docs
Adding timeline estimatesThat's project managementFocus on requirements and architecture
错误错误原因修复方案
包含完整Prisma schema重复了代码中应有的内容列出模型名称及用途,引用schema-rules.md
编写测试代码示例展示了HOW而非WHAT列出测试内容,引用testing.md了解测试方法
解释ts-pattern语法内容已存在于patterns.md中引用patterns.md,列出模式的应用场景
创建
/notes
子目录
违反单文件原则保持规范文档精简,移除辅助文档
添加时间线估算属于项目管理范畴聚焦于需求和架构

Rationalization Table

合理性说明表

ExcuseReality
"Thorough means showing complete code"Thorough = complete requirements. Code = implementation.
"Spec needs examples so people understand"Link to docs. Don't copy-paste library examples.
"Migration plan shows full picture"
/plan
command handles decomposition. Spec = WHAT not HOW.
"Include constitutions for context"Constitutions exist to avoid duplication. Reference, don't recreate.
"Testing code shows approach"testing.md shows approach. Spec lists WHAT to test.
"Metrics demonstrate value"NFRs show requirements. Metrics = measurement strategy (different doc).
"More detail = more helpful"More detail = harder to maintain. Lean + links = durable.
借口实际情况
"详细意味着展示完整代码"详细=完整的需求。代码=实现细节。
"规范文档需要示例以便理解"链接至文档,不要复制粘贴库示例。
"迁移计划能展示完整流程"
/plan
命令负责任务分解。规范文档=WHAT而非HOW。
"包含章程内容以便上下文理解"章程的存在就是为了避免重复。请引用,不要重复编写。
"测试代码能展示实现方法"testing.md展示了方法。规范文档列出要测试的内容。
"指标能体现价值"非功能需求展示了要求。指标=测量策略(属于不同文档)。
"更多细节=更有帮助"更多细节=更难维护。精简+链接=更持久。

Red Flags - STOP and Fix

危险信号 - 立即停止并修复

Seeing any of these? Delete and reference instead:
  • Full code examples from libraries (Zod, Prisma, Socket.io, etc.)
  • Migration phases or implementation steps
  • Success metrics or adoption targets
  • Recreated architecture explanations
  • Test implementation code
  • Files in
    specs/{run-id}-{feature-slug}/notes/
    directory
  • Spec > 300 lines (probably duplicating constitutions)
All of these mean: Too much implementation detail. Focus on WHAT not HOW.
若出现以下情况,请删除相关内容并改为引用:
  • 来自库的完整代码示例(Zod、Prisma、Socket.io等)
  • 迁移阶段或实现步骤
  • 成功指标或采用率目标
  • 重复编写的架构说明
  • 测试实现代码
  • specs/{run-id}-{feature-slug}/notes/
    目录中的文件
  • 规范文档超过300行(可能重复了章程内容)
以上所有情况都意味着:实现细节过多。请聚焦于WHAT而非HOW。

Quality Checklist

质量检查清单

Before finalizing spec:
  • Problem statement shows current - desired state gap
  • All FRs and NFRs are testable/verifiable
  • Architecture section lists files (not code examples)
  • All constitution rules referenced (not recreated)
  • All external libraries linked to docs (not copied)
  • No implementation plan (saved for
    /spectacular:plan
    )
  • No success metrics or timelines
  • Single file at
    specs/{run-id}-{feature-slug}/spec.md
  • Spec < 300 lines (if longer, check for duplication)
最终确定规范文档前:
  • 问题描述明确了当前状态与期望状态的差距
  • 所有功能需求和非功能需求均可测试/验证
  • 架构章节列出了文件(而非代码示例)
  • 所有章程规则均已引用(未重复编写)
  • 所有外部库均链接至文档(未复制内容)
  • 未包含实现方案(留待
    /spectacular:plan
    处理)
  • 未包含成功指标或时间线
  • 单文件存储于
    specs/{run-id}-{feature-slug}/spec.md
  • 规范文档少于300行(若过长,检查是否存在重复内容)

Error Handling

错误处理

Worktree Creation Fails

工作树创建失败

  • Check
    .worktrees/
    is in
    .gitignore
  • Run
    git worktree prune
    to clean stale entries
  • Verify working directory is clean
  • 检查
    .worktrees/
    是否已加入
    .gitignore
  • 运行
    git worktree prune
    清理过期条目
  • 验证工作目录是否干净

Git-Spice Errors

Git-Spice错误

  • Run
    gs repo init
    to initialize repository
  • Check
    gs ls
    to view current stack
  • See
    using-git-spice
    skill for troubleshooting
  • 运行
    gs repo init
    初始化仓库
  • 运行
    gs ls
    查看当前栈
  • 参考
    using-git-spice
    技能进行故障排除

Setup Commands Missing

缺少设置命令

  • Project MUST define setup commands in CLAUDE.md
  • See error message for required format
  • Re-run spec command after adding commands
  • 项目必须在CLAUDE.md中定义设置命令
  • 查看错误消息了解所需格式
  • 添加命令后重新运行规范文档命令

Validation Failures

验证失败

  • Maximum 3 iteration cycles
  • If issues persist, escalate via clarifications.md
  • Do not skip validation - it catches real problems
  • 最多允许3次迭代循环
  • 若问题持续存在,通过clarifications.md升级问题
  • 请勿跳过验证环节 - 它能发现实际问题

The Bottom Line

核心要点

Specs define WHAT and WHY. Plans define HOW and WHEN.
Reference heavily. Link to docs. Keep it lean.
If you're copy-pasting code or recreating rules, you're writing the wrong document.
规范文档定义WHAT和WHY。计划定义HOW和WHEN。
大量引用,链接至文档,保持精简。
如果你在复制粘贴代码或重复编写规则,说明你在写错误的文档。