Spec-Driven Feature Development
Overview
This skill enforces a Plan-Before-Code Gating Protocol. Autonomous coding agents often fail by leaping directly into file edits, leading to context drift, hallucinated APIs, and wasted tokens on trial-and-error debugging.
When this skill activates, no application code may be modified until a formal specification (SPEC.md or .specs/<feature-slug>.md) is drafted, verified against repository constraints, and approved.
1. Phase 1: Context & Constraint Scouting
Before drafting the specification:
- Identify existing conventions, data models, and API utilities in the project.
- Locate type definitions or schema files (e.g.,
schema.prisma,drizzle/schema.ts, Zod schemas, OpenAPI specs). - Do not read entire files unless necessary; inspect exports, interface headers, and types.
2. Phase 2: Draft SPEC.md
Read ./references/spec_template.md and create .specs/<feature-slug>.md (or SPEC.md in the repository root if requested) following that exact structure:
- Objective, Success Criteria & Explicit Non-Goals: Clear 2-sentence problem statement, deterministic pass criteria, and explicit out-of-scope boundaries.
- Data Contracts & Signatures: Exact TypeScript interfaces, database column types, or API schemas.
- File Modification Boundary Matrix: Explicit
Create,Modify(with target functions/lines), andForbiddenpaths. - Implementation Checklist & Verification Protocol: Exact test commands, linter checks, and edge cases.
3. Phase 3: The Gating Checkpoint (MANDATORY)
Once the specification is generated:
- Interactive Mode (User Session): Present a concise summary linking to the spec file, surface any architectural tradeoffs (using
ask_questionif multiple valid approaches exist), and ask for confirmation before writing code:"I have drafted the specification in
SPEC.md. Please review the proposed data contracts and file boundary matrix. Shall I proceed with implementation?" - Autonomous Subagent Mode: If invoked by a parent Lead Orchestrator (e.g., from
code-audit-orchestrator) that already provided an approved Remediation Plan, verify that the File Boundary Matrix has zero conflicts withForbiddenpaths and proceed to Phase 4. - HARD STOP: In interactive sessions, wait for approval or feedback. Do not touch source files until given the green light.
4. Phase 4: Phased Execution & Mid-Flight Amendment Protocol
Upon approval:
- Optional Sandbox Isolation: For multi-file changes or when the primary working tree has unrelated changes, provision an isolated worktree via
git-worktree-isolatorbefore modifying files. - Implement the feature in discrete, atomic milestones (e.g., Schema $\to$ Core Logic $\to$ API Handlers $\to$ UI/Integration).
- Mark off progress checkboxes in the spec file as milestones complete.
- Keep git commits scoped to individual milestones.
Escape Hatch: Mid-Flight Spec Amendment
If implementation uncovers an unforeseen constraint (e.g., a Forbidden file must be modified, an upstream SDK type mismatches the drafted contract, or the user amends requirements mid-flight):
- Halt edits immediately on the affected milestone.
- Append an entry to
## 6. Spec Amendments (Delta Log)in the spec file documenting:- Trigger / Blocker: Why the original contract cannot hold.
- Amended Section & Delta: Exact changes to Data Contracts or the File Modification Boundary Matrix.
- If the delta touches a previously
Forbiddenfile or alters a public API/schema contract, pause and request fast-track user confirmation before resuming. If the delta is purely internal (e.g., extracting an internal helper file), log the delta in the spec and continue.
5. Phase 5: Verification & Archive
- Run the deterministic test suite specified in Phase 2.
- Verify all type-checks and linters pass cleanly.
- Update the spec status to
Completedand archive it to.specs/completed/YYYY-MM-DD-<feature-name>.md(or remove temporary spec files if the repository does not track.specs/).