Brain Spec — Spec Lifecycle Management
Create, interview, view, update, delete, and archive feature specifications stored in .brain-spec/specs/.
Usage
/brain-spec <subcommand> [arguments]
Subcommands:
create <name>— Create a blank spec or start an interviewinterview <name>— Start/resume a guided interview for a speclist [--status <status>]— List all specs with status and task countsget <slug>— Display a spec's content and metadataupdate <slug>— Interactively update spec content or statusvalidate <slug>— Check a spec for completeness, EARS acceptance criteria, and task coveragedelete <slug>— Delete a spec (requires confirmation)archive <slug>— Move a spec to the archive
Instructions
Parse $ARGUMENTS to determine the subcommand and its parameters. The first word is the subcommand; remaining words are arguments.
Reference: Slug Rules
Slugs are generated from spec names:
- Lowercase the name
- Replace any sequence of non-alphanumeric characters with a single hyphen
- Strip leading/trailing hyphens
- Truncate to 100 characters
- Valid slug pattern:
^[a-z0-9]([a-z0-9-]*[a-z0-9])?$
Example: "User Authentication Flow" → user-authentication-flow
Reference: SpecMeta Schema
Each spec has a {slug}.meta.json file in .brain-spec/specs/:
{
"specSlug": "string",
"name": "string (original name)",
"description": "string",
"status": "draft | active | completed | archived",
"interview": {
"currentCategory": "string (one of 8 categories)",
"questionsAsked": "number",
"answers": [
{
"category": "string",
"question": "string",
"answer": "string"
}
],
"coverageMap": {
"functional": 0.0,
"technical": 0.0,
"data-model": 0.0,
"edge-cases": 0.0,
"security": 0.0,
"testing": 0.0,
"nonfunctional": 0.0,
"implementation": 0.0
}
},
"createdAt": "ISO 8601 timestamp",
"updatedAt": "ISO 8601 timestamp"
}
Reference: Interview Question Bank
8 categories, 5 questions each (40 total):
Functional Requirements:
- What is the primary purpose of this feature/system? What problem does it solve?
- Who are the target users? Describe the key user personas.
- What are the main user flows? Walk through the critical path.
- What inputs does the system accept and what outputs does it produce?
- What business rules or constraints govern the behavior?
Technical Constraints:
- What programming language and framework will be used?
- Are there existing codebase patterns or conventions that must be followed?
- What external dependencies or third-party services are required?
- What are the version requirements or compatibility constraints?
- How will this integrate with the existing system architecture?
Data Model:
- What are the core data entities and their relationships?
- How will data be stored (database type, schema structure)?
- How will the schema evolve over time? Migration strategy?
- What data validation rules apply?
- Are there data retention or cleanup requirements?
Edge Cases & Error Handling:
- What happens when the system receives invalid or unexpected input?
- How should the system handle network failures or timeouts?
- What are the rate limiting and throttling requirements?
- How should concurrent access or race conditions be handled?
- What are the failure modes and recovery strategies?
Security:
- What authentication and authorization mechanisms are needed?
- How will user input be sanitized to prevent injection attacks?
- What secrets management approach will be used?
- Are there OWASP concerns specific to this feature?
- What audit logging or compliance requirements exist?
Testing Strategy:
- What testing strategy will be used (unit, integration, e2e)?
- What are the critical test scenarios that must be covered?
- What is the target code coverage percentage?
- How will edge cases and error paths be tested?
- Are there performance or load testing requirements?
Non-Functional Requirements:
- What are the performance targets (response time, throughput)?
- What are the scalability expectations?
- Are there accessibility (a11y) requirements?
- Are there internationalization (i18n) requirements?
- What monitoring and observability is needed?
Implementation Approach:
- What is the suggested task breakdown for implementation?
- What is the dependency ordering between tasks?
- What is the estimated complexity (simple, moderate, complex)?
- Are there any tasks that should be parallelized?
- What are the key milestones or checkpoints?
Category display names:
- functional → "Functional Requirements"
- technical → "Technical Constraints"
- data-model → "Data Model"
- edge-cases → "Edge Cases & Error Handling"
- security → "Security Considerations"
- testing → "Testing Strategy"
- nonfunctional → "Non-Functional Requirements"
- implementation → "Implementation Approach"
Reference: Spec Template (blank)
# Spec: {{name}}
## Overview
{{description}}
## Functional Requirements
- [ ] TODO: Define functional requirements
## Technical Constraints
- TODO: Define technical constraints
## Data Model
TODO: Define data models and relationships
## Edge Cases & Error Handling
- TODO: Define edge cases
## Security Considerations
- TODO: Define security requirements
## Testing Strategy
- TODO: Define testing approach
## Non-Functional Requirements
- TODO: Define performance, scalability requirements
## Implementation Checklist
- [ ] TODO: Break down into tasks
## Acceptance Criteria
<!-- EARS notation: WHEN <event/condition> THE SYSTEM SHALL <observable behavior> -->
- [ ] WHEN TODO: define trigger THE SYSTEM SHALL TODO: define observable behavior
Reference: EARS Acceptance Criteria
Acceptance criteria use EARS (Easy Approach to Requirements Syntax) so each criterion is unambiguous and testable. The core template is:
WHEN <event or condition> THE SYSTEM SHALL <observable behavior>
Common EARS forms:
- Event-driven:
WHEN a user submits an empty form THE SYSTEM SHALL display a validation error - State-driven:
WHILE the account is locked THE SYSTEM SHALL reject login attempts - Unwanted behavior:
IF the payment gateway times out THEN THE SYSTEM SHALL retry once before failing - Ubiquitous (always true):
THE SYSTEM SHALL store passwords hashed with bcrypt
Each criterion should map to at least one testable behavior. During the
interview and in validate, criteria that do not follow an EARS form are
flagged so they can be rewritten into a checkable shape.
Reference: Archive Metadata Schema
{
"specSlug": "string",
"archivedAt": "ISO 8601 timestamp",
"reason": "completed | deprecated | superseded",
"supersededBy": "string | null",
"summary": "string",
"finalStatus": {
"totalTasks": 0,
"completedTasks": 0,
"specStatus": "string"
}
}
Subcommand: create
Usage: /brain-spec create My Feature Name
- Verify
.brain-spec/specs/directory exists. If not, tell the user to run/brain-initfirst. - Generate the slug from the name (everything after "create ").
- Check if
.brain-spec/specs/{slug}.meta.jsonalready exists. If so, error with "Spec '{slug}' already exists." - Ask the user: "How do you want to create this spec?"
- Interview (recommended) — Guided Q&A that builds the spec interactively
- Blank template — Creates a spec with TODO placeholders to fill in manually
- If Blank template: Write
{slug}.meta.jsonand{slug}.mdusing the templates above, with status "draft". Display the file path and suggest next steps. - If Interview: Write
{slug}.meta.jsonwith status "draft" and empty interview state, then immediately begin the interview flow (seeinterviewsubcommand below).
Subcommand: interview
Usage: /brain-spec interview my-feature-name
Runs a guided interview to build a spec. Can be started fresh or resumed.
Read
.brain-spec/specs/{slug}.meta.json. If not found, error.Check the
interviewfield:- If null or missing: Initialize interview state with
currentCategory: "functional",questionsAsked: 0, empty answers, all coverage at 0.0. Save the meta file. - If exists with
questionsAsked > 0: Resume from where we left off. Tell the user: "Resuming interview for '{name}' — {questionsAsked} questions answered so far."
- If null or missing: Initialize interview state with
Read steering context: If
.brain-spec/steering/has any documents, read them to provide context for the interview. Mention relevant steering context when asking questions.Interview loop: For each question:
- Determine the current category and find the next unanswered question in that category.
- Present the question to the user, prefixed with the category name in brackets:
[Functional Requirements] What is the primary purpose... - Wait for the user's response.
- Record the answer in the interview state:
{ category, question, answer }. - Update
questionsAskedcounter. - Update coverage for the category:
categoryAnswers.length / 5(5 questions per category). - If coverage for current category >= 0.6 (3+ answers), advance to the next uncovered category.
- Save the meta file after each answer.
- After each answer, show a brief progress indicator:
[{questionsAsked} answered | {currentCategory} | coverage: {percentage}%] - If
questionsAsked >= 3, offer the option to finish early: "You can continue answering or type 'done' to compile the spec now."
Category advancement: When advancing categories, go in order: functional → technical → data-model → edge-cases → security → testing → nonfunctional → implementation. Skip categories already at >= 0.6 coverage. If all categories are covered, tell the user all categories are covered and offer to compile.
Compiling the spec (when user says "done" or all categories covered):
- Build the spec markdown from interview answers:
- Title:
# Spec: {name} - Description as blockquote if present
## Overviewsection using the first functional answer- One
## {Category Display Name}section per category that has answers - Within each section, one
### {question}subsection per answer - Skip the first functional answer in the Functional Requirements section (already in Overview)
## Acceptance Criteriawith a TODO checkbox## Implementation Checklistwith a TODO checkbox (only if implementation answers exist)- Footer:
---then italicized generation metadata (questions asked, categories covered)
- Title:
- Write the compiled markdown to
.brain-spec/specs/{slug}.md - Update meta: set
statusto "active", updateupdatedAt - Display: "Spec compiled and saved to .brain-spec/specs/{slug}.md" with a summary of coverage
- Build the spec markdown from interview answers:
Subcommand: list
Usage: /brain-spec list or /brain-spec list --status active
- Use Glob to find all
.brain-spec/specs/*.meta.jsonfiles. - Read each meta file.
- If
--statusis provided, filter by that status. - For each spec, also check if
.brain-spec/tasks/{slug}/tasks.jsonexists and count tasks. - Display a formatted table:
Slug Status Tasks Created
───────────────── ───────── ─────── ──────────
user-auth-flow active 3/5 2025-01-15
api-redesign draft 0/0 2025-01-20
If no specs exist, display: "No specs found. Create one with /brain-spec create <name>"
Subcommand: get
Usage: /brain-spec get my-feature-name
- Read
.brain-spec/specs/{slug}.meta.json. If not found, error. - Read
.brain-spec/specs/{slug}.md. If not found, show metadata only. - Display metadata summary (status, created, updated, interview coverage if present).
- Display the full spec markdown content.
Subcommand: update
Usage: /brain-spec update my-feature-name
- Read
.brain-spec/specs/{slug}.meta.json. If not found, error. - Ask the user what they want to update. Present these choices and wait for their response:
- Status — Change spec status (draft/active/completed)
- Content — Edit the spec markdown
- Description — Update the spec description
- For Status: Ask which status to set. Update meta, save.
- For Content: Read current
.brain-spec/specs/{slug}.md, show it, ask what to change. Apply edits using the Edit tool. UpdateupdatedAtin meta. - For Description: Ask for the new description, update meta, save.
Subcommand: validate
Usage: /brain-spec validate my-feature-name
Checks a spec for completeness, EARS-formed acceptance criteria, and task coverage, then reports a pass / warn / fail verdict. Read-only: it never edits the spec or tasks.
Read
.brain-spec/specs/{slug}.meta.json. If not found, error: "No spec '{slug}'. Run /brain-spec list to see specs."Read
.brain-spec/specs/{slug}.md.Completeness check. Flag every section whose body still contains a
TODO:placeholder. Required sections: Overview, Functional Requirements, Acceptance Criteria. ATODO:in a required section is a FAIL; in any other section it is a WARN.EARS check. For each line under Acceptance Criteria, flag any criterion that does not match an EARS form (contains
THE SYSTEM SHALL, optionally led byWHEN/WHILE/IF ... THEN). A non-EARS criterion is a WARN; zero acceptance criteria is a FAIL.Task coverage check. Read
.brain-spec/tasks/{slug}/tasks.jsonif it exists. If the spec has acceptance criteria but no tasks, WARN "no tasks cover this spec." Iftasks.jsonis missing entirely, WARN "run /brain-task create to break this spec into tasks."Report. Print a verdict line (
PASS,WARN (n), orFAIL (n)) followed by each finding as[FAIL|WARN] <section>: <message>. End with the single highest-severity verdict so the result is scriptable. Exit without writing.Read
.brain-spec/specs/{slug}.meta.json. If not found, error.Ask for confirmation: "Are you sure you want to delete spec '{name}' ({slug})? This will remove the spec file, metadata, and all associated tasks. This cannot be undone."
If confirmed:
- Delete
.brain-spec/specs/{slug}.md - Delete
.brain-spec/specs/{slug}.meta.json - Delete
.brain-spec/tasks/{slug}/directory if it exists - Confirm deletion: "Spec '{slug}' deleted."
- Delete
If not confirmed: "Deletion cancelled."
Subcommand: archive
Usage: /brain-spec archive my-feature-name
- Read
.brain-spec/specs/{slug}.meta.json. If not found, error. - Ask the user for:
- Reason: completed / deprecated / superseded (ask the user to choose)
- Summary: Brief summary of what was accomplished
- If superseded: Superseded by: slug of the replacement spec
- Count tasks from
.brain-spec/tasks/{slug}/tasks.jsonif it exists. - Create archive directory:
.brain-spec/archive/{slug}/ - Write
.brain-spec/archive/{slug}/archive-metadata.jsonusing the Archive Metadata Schema. - Move (copy then delete) these files into the archive directory:
.brain-spec/specs/{slug}.md→.brain-spec/archive/{slug}/{slug}.md.brain-spec/specs/{slug}.meta.json→.brain-spec/archive/{slug}/{slug}.meta.json.brain-spec/tasks/{slug}/→.brain-spec/archive/{slug}/tasks/(if exists)
- Confirm: "Spec '{slug}' archived to .brain-spec/archive/{slug}/"