Create a complete Spectra change proposal — from requirement to validated artifacts — in a single workflow.
If no argument is provided, the workflow will extract requirements from conversation context or ask.
-
Config 前置檢查(Project Setup Gate) ⚠️ 強制,不可跳過
目的:避免每次建立 artifact 時才發現 openspec/config.yaml 是空的,導致 AI 沒有專案背景知識、產出品質低落。
處理原則:關鍵題問用戶(互動式),不自動猜、不沉默略過。
a. 檢查 config.yaml 是否存在且有實質內容:
- 讀
openspec/config.yaml
- 若檔案不存在 → 判定為「空」
- 若檔案存在但
context: 欄位不存在 / 為空字串 / 只有註解骨架(無實質 tech stack 描述)→ 判定為「空」
- 若檔案存在但
rules: 欄位不存在 / 為空 → 判定為「缺規則」
b. 若判定為「空」→ 以 AskUserQuestion 詢問 3-5 題關鍵題(強制互動):
- Q1 產品定位:「這個專案是做什麼的?一句話 + 目標用戶。」(無選項,自由作答)
- Q2 Tech Stack:提供 4 選項 + 自由補充
- Next.js + TypeScript + Supabase(Web App 主流)
- WordPress + PHP(外掛)
- Node.js + CLI(工具)
- 其他(自由描述)
- Q3 部署方式:提供 3 選項
- Vercel(Production = main,Preview = staging)
- 自架 VPS(rsync / ssh 部署)
- GitHub Pages / 其他
- Q4 程式與註解語言規範:提供 2 選項
- 代碼英文 / 註解繁中(預設)
- 全英文(跨國協作)
- (可選 Q5)特殊約束:如「必須走 Spectra」「禁止 Emoji」等專案獨有規則
問完後,基於答案 + 自動偵測 package.json / CLAUDE.md 寫一份完整 context:,並套用預設 rules: 模板(proposal / design / specs / tasks 四類)。
c. 若判定為「缺規則」→ 不問用戶,直接套用預設 rules 模板:
- 預設模板包含 proposal / design / specs / tasks 四類的通用格式約束
- 寫入後告知用戶:「已套用預設產出規則,如需客製請手動編輯 openspec/config.yaml」
d. 若 config.yaml 完整 → 靜默通過,進入 Step 1
e. 回報:不論是否修改 config.yaml,都向用戶顯示一行狀態:
- 「✓ config.yaml 已就緒」或
- 「✓ 已為專案建立 config.yaml(基於你的回答 + 偵測結果)」或
- 「✓ 已補齊 config.yaml 的 rules 區段」
-
Determine the requirement source
a. Argument provided (e.g., "add dark mode") → use it as the requirement description, skip to deriving the change name below.
b. Plan file available:
- Check if the conversation context mentions a plan file path (plan mode system messages include the path like
~/.claude/plans/<name>.md)
- If found, check if the file exists at
~/.claude/plans/
- If a plan file is found, use the AskUserQuestion tool to ask:
- Option 1: Use the plan file
- Option 2: Use conversation context
- If conversation context has no relevant discussion, mention this when presenting the choice
- If the user picks the plan file → read it and extract:
plan_title (H1 heading) → use as requirement description
plan_context (Context section) → use as proposal Why/Motivation content
plan_stages (numbered implementation stages) → use for artifact creation
plan_files (all file paths mentioned) → use for Impact section
- If the user picks conversation context → fall through to (c)
c. Conversation context → attempt to extract requirements from conversation history
- If context is insufficient, use the AskUserQuestion tool to ask what they want to build
From the resolved description, derive a kebab-case change name (e.g., "add dark mode" → add-dark-mode).
IMPORTANT: Do NOT proceed without understanding what the user wants to build.
-
Classify the change type
Based on the requirement, classify the change into one of three types:
| Type | When to use |
|---|
| Feature | New functionality, new capabilities |
| Bug Fix | Fixing existing behavior, resolving errors |
| Refactor | Architecture improvements, performance optimization, UI adjustments |
This determines the proposal template format in step 5.
-
Scan existing specs for relevance
Before creating the change, check if any existing specs overlap:
- Use the Glob tool to list all files matching
openspec/specs/*/spec.md
- Extract directory names as the spec identifier list
- Compare against the user's description to identify related specs (max 5 candidates)
- For each candidate (max 3), read the first 10 lines to retrieve the Purpose section
- If related specs are found, display them as an informational summary
IMPORTANT:
- If related specs are found, display them but do NOT stop or ask for confirmation — continue to the next step
- If no related specs are found, silently proceed without mentioning the scan
-
Create the change directory
spectra new change "<name>" --agent claude
If a change with that name already exists, suggest continuing the existing change instead of creating a new one.
-
Write the proposal
Get instructions:
spectra instructions proposal --change "<name>" --json
Write the proposal file using the template from instructions, with the following format based on change type:
Feature
## Why
<!-- Why this functionality is needed -->
## What Changes
<!-- What will be different -->
## Non-Goals (optional)
<!-- Scope exclusions and rejected approaches. Required when design.md is skipped. -->
## Capabilities
### New Capabilities
- `<capability-name>`: <brief description>
### Modified Capabilities
(none)
## Impact
- Affected specs: <new or modified capabilities>
- Affected code: <list of affected files>
Bug Fix
## Problem
<!-- Current broken behavior -->
## Root Cause
<!-- Why it happens -->
## Proposed Solution
<!-- How to fix -->
## Non-Goals (optional)
<!-- Scope exclusions and rejected approaches. Required when design.md is skipped. -->
## Success Criteria
<!-- Expected behavior after fix, verifiable conditions -->
## Impact
- Affected code: <list of affected files>
Refactor / Enhancement
## Summary
<!-- One sentence description -->
## Motivation
<!-- Why this is needed -->
## Proposed Solution
<!-- How to do it -->
## Non-Goals (optional)
<!-- Scope exclusions and rejected approaches. Required when design.md is skipped. -->
## Alternatives Considered (optional)
<!-- Other approaches considered and why not -->
## Impact
- Affected specs: <affected capabilities>
- Affected code: <list of affected files>
-
Get the artifact build order
spectra status --change "<name>" --json
Parse the JSON to get:
applyRequires: array of artifact IDs needed before implementation
artifacts: list of all artifacts with their status and dependencies
-
Create remaining artifacts in sequence
Loop through artifacts in dependency order (skip proposal since it's already done):
a. For each artifact that is ready (dependencies satisfied):
b. Continue until all applyRequires artifacts are complete
- After creating each artifact, re-run
spectra status --change "<name>" --json
- Check if every artifact ID in
applyRequires has status: "done"
- Stop when all
applyRequires artifacts are done
c. If an artifact requires user input (unclear context):
- Use AskUserQuestion tool to clarify
- Then continue with creation
-
Inline Self-Review (before CLI analysis)
After creating all artifacts, scan them manually. Fix issues inline, then proceed to the CLI analyzer.
Check 1: No Placeholders
These patterns are artifact failures — fix each one before proceeding:
- "TBD", "TODO", "FIXME", "implement later", "details to follow"
- Vague instructions: "Add appropriate error handling", "Handle edge cases", "Write tests for the above"
- Delegation by reference: "Similar to Task N" without repeating specifics
- Steps describing WHAT without HOW: "Implement the authentication flow" (what flow? what steps?)
- Empty template sections left unfilled
- Weasel quantities: "some", "various", "several" when a specific number or list is needed
Check 2: Internal Consistency
- Does every capability in the proposal have a corresponding spec?
- Does the design reference only capabilities from the proposal?
- Do tasks cover all design decisions, and nothing outside proposal scope?
- Are file paths consistent across proposal Impact, design, and tasks?
Check 3: Scope Check
- More than 15 pending tasks → consider decomposing into multiple changes
- Any single task would take more than 1 hour → split it
- Touches more than 3 unrelated subsystems → consider splitting
Check 4: Ambiguity Check
- Are success/failure conditions testable and specific?
- Are boundary conditions defined (empty input, max limits, error cases)?
- Could "the system" refer to multiple components? Be explicit.