Install
openclaw skills install @xhuaustc/spec-coderStructured spec-first development workflow with multi-role expert review gates: clarify requirements, author spec documents (requirements/design/tasks), generate code from spec, verify with real tests, and iterate while keeping spec and code in sync. Use when user wants to build a feature or system with a spec-first approach, mentions "spec coding", "spec-driven development", or asks to write specs before coding.
openclaw skills install @xhuaustc/spec-coderWrite specs first, then generate code. 5 phases, each producing artifacts that feed the next. Expert review gates between phases catch issues early.
On every new session:
specs/status.md to identify current phase, active changes, and deferred items.specs/changes/archive/ — archived changes represent completed/merged work and must not be read or referenced.specs/status.md? This is a new project — start from Phase 0 (existing codebase) or Phase 1 (greenfield).Phase 0 ──→ Phase 1 ──→ ║Gate 1║ ──→ Phase 2a ──→ Phase 2b ──→ ║Gate 2║
(scan) (clarify) (req.) (design) (preview) (design)
│
┌────────────────────────────────────────────────────────────────┘
▼
Phase 2c ──→ Phase 2d ──→ ║Gate 3║ ──→ Phase 3 ──→ ║Gate 4║ ──→ Phase 4 ──→ Phase 5
(tasks) (specs) (plan) (code) (code) (verify) (iterate)
│
┌─────────────┘
▼
Re-trigger Gate
2 / 3 / 4 based
on change scope
Gates auto-approve when no Critical/Major issues. See Expert Review Protocol for details.
| Phase | Input | Output | Gate | Next |
|---|---|---|---|---|
| 0. Codebase Scan | codebase files | status.md § Codebase Context | — | Phase 1 |
| 1. Clarify & Scope | user requirements + Phase 0 context | requirements.md | Gate 1 (req.) | Phase 2a |
| 2a. Technical Design | requirements.md | design.md | — | Phase 2b |
| 2b. Design Preview | design.md | design-preview/ | Gate 2 (design) | Phase 2c |
| 2c. Task Breakdown | design.md + requirements.md | tasks.md | — | Phase 2d |
| 2d. Feature Specs | tasks.md + design.md | spec_xxx.md | Gate 3 (plan) | Phase 3 |
| 3. Generate | tasks.md + spec_xxx.md | code + tests | Gate 4 (code) | Phase 4 |
| 4. Verify | code + tests + spec_xxx.md | test results, Implementation Map | — | Phase 5 or done |
| 5. Evolve | trunk specs + user request | changes/ | scoped gate | → Phase 1–4 |
Trigger conditions:
When NOT to use: Pure bug fixes, one-line config changes, dependency updates, or tasks completable in < 15 minutes without design decisions.
Complexity triage — choose the right track:
| Track | When | Phases | Artifacts | Review Depth |
|---|---|---|---|---|
| Small | Single endpoint, field addition, < 1 hr | Spec (lite) → Generate → Verify | spec_xxx.md only | Lite (1–2 roles, skip if trivial) |
| Medium | Single feature, 1–4 hrs, 1–3 modules | Clarify (brief) → Spec → Generate → Verify | spec_xxx.md + tasks.md | Standard (2–3 roles) |
| Large | Multi-module, > 4 hrs, or new system | Full 5-phase workflow | All spec files | Full (all roles) |
Ask the user which track fits, or infer from the scope of their request.
Small track shortcut:
Skip Phase 1. Write a single spec_xxx.md (Interface + Business Rules + Test Points only), then go straight to Generate → Verify.
Medium track shortcut:
Phase 1 is a brief bullet-point confirmation (no full requirements.md). Phase 2 produces tasks.md + spec_xxx.md only (skip design.md and design-preview/ unless architecture decisions are needed).
Mid-project entry: If the user already has spec files or an existing codebase, read them first. Validate existing artifacts against the expected format, then confirm which phase to start from.
Two-layer structure: trunk (current system truth) + changes (incremental work).
specs/
├── index.md ← navigation hub: all features & recent changes
├── requirements.md ← project-level requirements (grows incrementally)
├── design.md ← system-level architecture (grows incrementally)
├── design-preview/
├── tasks.md ← active tasks only
├── status.md
├── spec_<feature_name>.md ← feature specs (current truth, one per feature)
└── changes/ ← all incremental work
├── FEAT-NNN-name/ ← new feature (full spec lifecycle)
│ ├── spec.md
│ ├── design.md
│ ├── tasks.md
│ └── delta.md ← merge instructions for trunk
├── CHG-NNN-name/ ← change/enhancement (delta only)
│ ├── spec.md ← ADDED / MODIFIED / REMOVED sections
│ ├── tasks.md
│ └── delta.md
└── archive/ ← completed & merged changes
First-time projects: Start with trunk only (no changes/ needed). The changes layer is introduced when the first post-v1 feature or modification begins.
For full lifecycle management details, see Spec Lifecycle Management.
For existing codebases, run before Phase 1: read dependency files to detect tech stack, list directory tree, identify existing interfaces/models/conventions, and summarize findings.
Output: Write results to specs/status.md under ## Codebase Context (tech stack, key conventions, existing interfaces, directory structure summary). This persists the scan across sessions. Phase 1 references this for requirements scoping; Phase 2a references it for architecture decisions.
Goal: Turn informal requirements into a confirmed, structured requirements.md.
Constraints: Do NOT write any code. Only ask questions and produce documents.
specs/requirements.md (see template): Background & Objectives, User Roles & Use Cases, Functional Requirements (FR-001...), Non-Functional Requirements, Out of Scope. If Phase 0 ran, populate the "Existing Architecture" section with requirement-relevant context from status.md § Codebase Context.Per Expert Review Protocol — Gate 1. Exit: User approves (or auto-approved).
Goal: Produce spec documents that directly drive code generation.
specs/design.mdBased on requirements.md, produce specs/design.md (see template):
For existing codebases: populate "Existing Architecture" section with architecture-relevant context from status.md § Codebase Context (what's new vs. modified).
specs/design-preview/Self-contained HTML prototype visualizing architecture, module layout, UI screens or API flows, and data models.
Constraints:
UI projects: All generated UI must follow the UI Design Guidelines to avoid AI-template aesthetics.
Per Expert Review Protocol — Gate 2. Exit: User approves (or auto-approved).
specs/tasks.mdTask table (see template). Target granularity: 30–90 min per task.
specs/spec_<feature>.mdPer feature (see template): Feature Description & Use Cases, Interface Definition, Data Model, Business Rules & Edge Cases, Test Points (≥ 5 per feature, complex: 10–20; categories: Normal / Error / Boundary / Combination).
Per Expert Review Protocol — Gate 3. Exit: User approves (or auto-approved).
Before leaving Phase 2: every interface has explicit I/O types; every business rule has ≥ 1 test point; specs describe what not how; each spec is self-contained for code generation; edge cases are explicit, not implied.
Goal: Produce implementation code + tests strictly based on the spec.
Spec adherence — tiered rules:
| Tier | Scope | Rule |
|---|---|---|
| Strict | Interfaces, data models, business rules | Follow spec exactly. Do not change signatures, field names, or behavior. |
| Flexible | Internal implementation (function names, code organization, logging, error messages) | AI decides, but must note deviations in Human-review points. |
| SPEC-GAP | Scenarios the spec doesn't cover (discovered during coding) | Implement a reasonable solution, tag it [SPEC-GAP], and continue. Collect all gaps for batch review in Phase 4. |
Never silently deviate from Strict-tier items. If a Strict item is wrong or incomplete, flag it and ask the user — but do not block on every minor gap.
feat(TASK-001): ...Blocked in tasks.md, log the reason, and continue with non-dependent tasks. Return to blocked tasks after unblocked tasks complete.tasks.md Status column (Pending → In Progress → Done / Blocked) as each task progresses.tasks.md (per execution strategy above), take its linked spec_xxx.md as input.[SPEC-GAP] items// SPEC: spec_auth.md | TASK-002 — enables reverse lookup from code to spec.For existing codebases: clearly distinguish "new file" vs. "modify existing file" and show diffs for modifications.
Per Expert Review Protocol — Gate 4. Exit: User approves (or auto-approved). Proceed to Phase 4.
Goal: Confirm generated code satisfies the spec through execution (static compliance is already covered by Gate 4).
Run the following checks in order. Stop and fix if any step fails.
pytest, npm test, go test, etc.). Map each TP-ID to pass/fail.tasks.md.requirements.md defines measurable NFRs (response time, throughput), run benchmarks and compare. Log results even if not blocking.AI-Auto: No in tasks.md, generate a manual test checklist with steps and expected results for the user to execute.For each [SPEC-GAP] from Phase 3: Accept (update spec) / Reject (fix code) / Defer (add to backlog).
After all tests pass, update the ## Implementation Map section in each spec_xxx.md with the actual code file paths and function/class names. This enables reverse lookup from spec to code.
Exit condition: All items pass, or user acknowledges remaining gaps.
Workflow completion (initial build): If this is the initial build and no further changes are planned, update status.md: mark all phases complete, remove the Initial Build Progress table, and present a summary to the user (features built, test pass rate, deferred items count).
Goal: Add new capabilities or modify existing ones while keeping all specs in sync.
Key rule: Always update the spec BEFORE updating the code. Every change goes through specs/changes/.
| Type | Criteria | Action |
|---|---|---|
| New Feature | Independent business value, new interfaces/models | Create specs/changes/FEAT-NNN-name/, run full Phase 1–4 within it |
| Change / Enhancement | Modifies existing feature behavior | Create specs/changes/CHG-NNN-name/, write delta spec, run Phase 2d–4 |
| Trivial Fix | Single spec file, single section, no interface/model change | Update trunk spec directly with changelog entry, skip change dir |
Before creating the change directory, run Overlap Check against all In-Progress changes listed in specs/index.md. If overlapping Target Specs are found, warn the user and agree on a resolution strategy before proceeding.
For Features: run the full workflow (Phase 1–4) inside specs/changes/FEAT-NNN/.
For Changes: write a delta-format spec.md (ADDED / MODIFIED / REMOVED), then run Phase 2d–4.
For Changes that add/remove screens, modify navigation structure, or alter primary interaction patterns (e.g., forms → tables): also run Phase 2b to update design-preview/.
Path rule: All Phase 1–4 outputs go into the change directory, not the trunk. For example, Phase 2a produces specs/changes/FEAT-NNN/design.md, not specs/design.md. The trunk is only updated during Step 4 (Merge to Trunk).
Nesting rule: Changes are always flat — never create a change inside another change directory. If FEAT-NNN's implementation reveals the need for an additional feature, create a sibling FEAT-NNN+1 at the top level (specs/changes/FEAT-NNN+1-name/) and add a dependency note in both tasks.md files.
Apply the same review gates as the main workflow, scoped to the change:
Before generating code, analyze impact across ALL trunk specs:
Present impact analysis to the user for confirmation.
After code is verified (Phase 4 passed):
changes/FEAT-NNN/spec.md to specs/spec_<feature>.md.delta.md — merge instructions listing every trunk file/section to update.specs/*.md): insert ADDED content, replace MODIFIED sections, remove REMOVED items.specs/index.md with the change reference.spec: merge FEAT/CHG-NNN to trunk.specs/changes/archive/.For full lifecycle details, merge rules, and scaling guidance, see Spec Lifecycle Management.
specs/status.md (see template). Update at each phase end with current phase, gate results, and deferred item counts. On session start, read specs/status.md first to restore context.spec_xxx.md + related design.md sections — not all spec files at once.specs/status.md.| Scenario | Recovery Action |
|---|---|
| Phase 3: Task fails after 2 attempts | Mark task Blocked in tasks.md, log root cause, continue with non-dependent tasks. After all other tasks complete, revisit blocked tasks — may require spec revision (back to Phase 2d). |
| Phase 4: Tests fail | Categorize: spec bug (fix spec then re-generate) vs. code bug (fix code, re-run tests). Do not loop more than 3 fix-verify cycles per task — escalate to user. |
| Phase 4: Test environment unavailable | Generate manual test checklist, document expected setup, and mark verification as Pending-Env in status.md. Proceed with remaining phases that don't require the environment. |
| SPEC-GAP: Cannot decide autonomously | Tag as [SPEC-GAP-BLOCKED], implement a safe no-op or error response as placeholder, and batch all blocked gaps for user decision before Phase 4 verification. |
| Phase 5: Delta merge conflict | Follow conflict handling in spec-lifecycle.md. Never force-overwrite trunk — always present both versions to the user. |
| Cross-session context loss | Read specs/status.md + last completed artifacts (see Session Start). If status.md is missing or stale, scan specs/ directory structure and tasks.md status to reconstruct state. |
| Phase 1: Requirements deadlock | If the user cannot decide after 3 clarification rounds, present a default recommendation with rationale. Ask for explicit approval or override. Do not loop indefinitely. |
| Phase 2: Design deadlock | If two design options are equally viable, document both in ADR format (pros/cons/consequences), provide a recommended option, and ask the user to decide. Limit to 2 discussion rounds, then adopt the recommendation if no response. |
For spec file templates, see templates.md (core) and templates-lifecycle.md (lifecycle & review).