# Spec-driven development with Bernstein: a walkthrough

Canonical URL: https://bernstein.run/spec-driven

Loop: `spec -> checklist -> tasks -> implement -> review`. Decomposing a free-text goal is one LLM call; starting from a hand-written `plan.yaml` makes the entire chain deterministic Python. All state lives on disk under `.sdd/`.

## Stage 1: Spec - state the intent
```bash
bernstein init && bernstein run --goal "<goal>"
```

## Stage 2: Checklist - review the decomposed plan
```bash
bernstein run --plan-only   # or --dry-run for scheduling + cost preview
```

## Stage 3: Tasks - the graph the scheduler builds
```bash
bernstein run --from-plan plan.yaml
```

## Stage 4: Implement - one agent per worktree
Each eligible task runs in an isolated git worktree under `.sdd/worktrees/` with role-based model routing (or `--routing bandit`).

## Stage 5: Review - gates, then the merge decision
```bash
bernstein approve <task-id>   # or bernstein reject
bernstein wrap-up
```

State directories: `.sdd/runtime/` (backlog, tokens, WAL), `.sdd/audit/` (opt-in HMAC-chained JSONL log), `.sdd/metrics/` (cost ledger for `bernstein cost`).
