@@ -31,21 +31,31 @@ The spec commands provide a structured approach to designing and implementing fe
3131 │ (Repeat for multiple architectural decisions)
3232 │
3333 ▼
34- Tasks.md ──────────────► /spec:tasks
35- │ /spec:approve tasks
34+ Choose by certainty ────► (prompted at /spec:approve design)
3635 │
37- ▼
38- Implementation ─────────► /spec:implement
39- │ (TDD: Tests → Code)
36+ ├── Attended ──────► /spec:tasks
37+ │ (review each /spec:approve tasks
38+ │ test) /spec:implement (sonnet; TDD: Tests → Code)
4039 │
41- ├ ── OR (unattended) ► /spec:ralph-tasks
42- │ /spec:ralph-implement [count]
43- │ scripts/ralph.sh [n] [max] [cooldown]
40+ └ ── Unattended ──── ► /spec:ralph-tasks (standalone, from approved design)
41+ (review in /spec:ralph-implement (opus + auto mode, self-driving loop)
42+ batches)
4443 │
4544 ▼
4645 Pull Request
4746```
4847
48+ ** The certainty fork.** After the design is approved, you pick * one* of two paths — and
49+ ` /spec:approve design ` prompts you to choose:
50+
51+ - ** Attended** (` /spec:tasks ` → ` /spec:implement ` ): a strict Red → ** user approval** → Green
52+ → Refactor loop in the main agent on ** sonnet** . Every test is reviewed in the IDE before
53+ implementation. Use when the work is uncertain.
54+ - ** Unattended** (` /spec:ralph-tasks ` → ` /spec:ralph-implement ` ): ` ralph-tasks.md ` is
55+ generated ** directly from the approved design** (no ` tasks.md ` , no per-test gates), then a
56+ self-driving loop on ** opus** under ** auto mode** delegates each task to a ** sonnet**
57+ sub-agent. Reviewed in batches rather than per test. Use when the work is well-understood.
58+
4959## Sub-agents & model policy
5060
5161Several commands delegate their reasoning-heavy work to a ** sub-agent** (launched via the
@@ -98,23 +108,30 @@ and gives the heavy work a focused, single-purpose context.
98108| ` /spec:tasks ` | Yes — ` Plan ` (read-only) | ** opus** | Planning / coverage mapping |
99109| ` /spec:ralph-tasks ` | Yes — ` Plan ` (read-only) | ** opus** | Planning / decomposition |
100110| ` /spec:review ` | Yes — ` general-purpose ` | ** opus** | Adversarial reasoning |
101- | ` /spec:ralph-implement ` | Yes — ` general-purpose ` , per task (writes source) | ** sonnet** | Mechanical TDD implementation |
102- | ` /spec:implement ` | No | ** sonnet** (recommended) | Implementation work; runs in the main agent, so set the session model |
111+ | ` /spec:ralph-implement ` (orchestrator) | — (the loop itself) | ** opus** | Cheap bookkeeping + ** required for auto mode** |
112+ | ` /spec:ralph-implement ` (per-task sub-agent) | Yes — ` general-purpose ` (writes source) | ** sonnet** | Mechanical TDD implementation, kept off the opus loop context for cost |
113+ | ` /spec:implement ` | No | ** sonnet** (Step 0 prompts to switch) | Implementation work; runs in the main agent, so set the session model |
103114| ` /spec:new ` , ` /spec:switch ` , ` /spec:approve ` , ` /spec:status ` | No | — | Mechanical bookkeeping |
104115
105116The planning commands use the ` Plan ` agent so the "return as text, don't write the file"
106117rule is much harder to violate accidentally (it has no ` Write ` /` Edit ` /` NotebookEdit ` ; the
107118prompt still forbids writing via ` Bash ` ). ` /spec:ralph-implement ` keeps ` general-purpose `
108119because its sub-agent must write source.
109120
121+ ` /spec:ralph-implement ` runs ** two models on purpose** : the orchestrator loop on ** opus**
122+ (required for ** auto mode** , and the policy for the unattended path) does only cheap
123+ bookkeeping — STOP-file check, task selection, marking checkboxes, committing, counting — while
124+ each task's actual test + implementation is delegated to a ** sonnet** sub-agent. That keeps the
125+ expensive per-task churn on the cheaper model and out of the opus loop's context, lowering cost
126+ without taking the orchestrator off opus.
127+
110128` /spec:implement ` is deliberately ** not** delegated: its per-behavior
111129Red → user-approval → Green → Refactor loop is interactive, and the mandatory approval gate
112130must run in the main agent where it can reach the user. Because there is no sub-agent to
113- assign a model to, run the command itself on ** sonnet** (set the session model) — it is
114- implementation work, matching the sonnet policy for ` /spec:ralph-implement ` . ** If your
115- session is not already on sonnet (e.g. it is on opus), consider switching to sonnet before
116- running ` /spec:implement ` .** This guidance is repeated at the top of ` implement.md ` itself,
117- since that is where the user reads it.
131+ assign a model to, run the command itself on ** sonnet** (the session model) — it is
132+ implementation work. ** Step 0 of ` /spec:implement ` actively checks the session model and
133+ prompts you to switch to sonnet if you are on another model** (e.g. opus). This guidance is
134+ repeated at the top of ` implement.md ` itself, since that is where the user reads it.
118135
119136## Commands
120137
@@ -217,7 +234,10 @@ Approve a specification phase or specific ADR.
217234```
218235- Updates Status from "Proposed" to "Accepted" in ALL ADRs for current spec
219236- Creates ` .design-approved ` marker
220- - Allows progression to tasks phase
237+ - ** Prompts you to choose the implementation path** (the certainty fork): the ** attended**
238+ path (` /spec:tasks ` → ` /spec:implement ` , review each test) or the ** unattended** path
239+ (` /spec:ralph-tasks ` → ` /spec:ralph-implement ` , review in batches). Either path can start
240+ straight from the approved design.
221241
222242** Approve Specific ADR:**
223243``` bash
@@ -427,23 +447,28 @@ The implement command follows a rigorous Red-Green-Refactor cycle:
427447
428448### ` /spec:ralph-tasks `
429449
430- Generate ` ralph-tasks.md ` for unattended TDD implementation via the Ralph loop.
450+ Generate ` ralph-tasks.md ` for unattended TDD implementation. ** Standalone** — the unattended
451+ peer of ` /spec:tasks ` , derived ** directly from the approved design** (requirements + ADRs). It
452+ does ** not** require ` tasks.md ` or ` .tasks-approved ` .
431453
432454``` bash
433455/spec:ralph-tasks
434456```
435457
436- Creates ` specs/{current-spec}/ralph-tasks.md ` - a variant of ` tasks.md ` reformatted for unattended execution:
458+ Creates ` specs/{current-spec}/ralph-tasks.md ` , formatted for unattended execution:
437459
438460- ** No approval gates** : No ` ⛔ STOP HERE ` or ` /test-first ` directives
439461- ** RALPH-VERIFY** : Each task includes an exact ` dotnet test --filter ` command
440462- ** References** : Each task lists files/ADRs to read (self-contained for fresh context)
441463- ** Strict atomicity** : One behavior per task, ~ 200 lines max, ordered by dependency
442464
443465** Requirements:**
444- - Tasks must be approved (` .tasks -approved ` exists)
466+ - Design must be approved (` .design -approved ` exists)
445467- All ADRs must be approved (Status: Accepted)
446468
469+ > Pick * either* ` /spec:tasks ` (attended) * or* ` /spec:ralph-tasks ` (unattended) after design
470+ > approval — they are alternative branches, not sequential steps.
471+
447472** Ralph task format:**
448473``` markdown
449474- [ ] ** [ Brief behavior description] **
@@ -462,70 +487,80 @@ Creates `specs/{current-spec}/ralph-tasks.md` - a variant of `tasks.md` reformat
462487
463488### ` /spec:ralph-implement [count] `
464489
465- Unattended TDD implementation from ` ralph-tasks.md ` . Core command invoked by the Ralph loop bash script.
490+ Unattended TDD implementation from ` ralph-tasks.md ` via a ** self-driving loop** . Run it on
491+ ** opus** with ** auto mode** enabled for a true unattended run.
466492
467493``` bash
468- # Implement next task (default)
494+ # Ask the run bound up front, then loop unattended
469495/spec:ralph-implement
470496
471- # Implement next 3 tasks
497+ # Shortcut: pre-set the tasks bound to 3 (skips the bound prompt)
472498/spec:ralph-implement 3
473499```
474500
475- ** Key difference from ` /spec:implement ` ** : No ` AskUserQuestion ` - runs completely unattended.
501+ ** Up-front setup (Step 0, the only interactive part):**
502+ - Advises that the orchestrator should be on ** opus** and that ** auto mode** should be on
503+ (auto mode is a permission mode set in Claude Code settings / ` CLAUDE_CODE_ENABLE_AUTO_MODE ` ,
504+ Opus-gated — the command can't toggle it; it advises and proceeds).
505+ - Asks (via ` AskUserQuestion ` ) which ** run bound** to use — * unless* a ` count ` was passed,
506+ which sets the tasks bound directly:
507+ - ** Tasks** — stop after N tasks complete (the ` count ` argument)
508+ - ** Turns** — stop after N loop iterations attempted (failures included)
509+ - ** Budget** — stop after ~ N output tokens consumed
510+
511+ ** Two models on purpose:** the ** opus** orchestrator does only bookkeeping; each task's test +
512+ implementation is delegated to a ** sonnet** sub-agent (cheaper, and kept off the opus loop
513+ context). The sub-agent never commits, pushes, or edits the task files.
476514
477- ** Workflow per task:**
478- 1 . Check for ` RALPH_STOP ` file (halt if present)
479- 2 . Read task references for context
480- 3 . 🔴 RED: Write test, verify it fails
481- 4 . 🟢 GREEN: Write minimum implementation, verify test passes, check for regressions
482- 5 . 🔵 REFACTOR: Apply Tidy First improvements
483- 6 . Commit and mark task complete in ` ralph-tasks.md `
515+ ** Loop per task:** check ` RALPH_STOP ` → select next ` - [ ] ` task → delegate 🔴 Red → 🟢 Green
516+ → 🔵 Refactor to a sonnet sub-agent → orchestrator marks the checkbox and commits → check
517+ continuation → repeat. Long runs can self-pace across context windows with ` ScheduleWakeup ` .
484518
485519** Stop mechanisms:**
486- - ` count ` parameter limits tasks per invocation
487- - ` RALPH_STOP ` file at repo root halts after current task
520+ - The chosen ** bound** (tasks / turns / budget)
521+ - ` RALPH_STOP ` file at repo root — the unattended kill-switch (` touch RALPH_STOP ` from another
522+ terminal); halts after the current task
523+ - ** Esc** — cancel a pending self-paced wake-up at the keyboard
488524- Automatically stops when all tasks complete
489525
490526** Error handling:** Failed tasks are marked ` - [!] ` with an explanation and skipped.
491527
492528** Requirements:**
493- - Tasks must be approved (` .tasks -approved ` exists)
529+ - Design must be approved (` .design -approved ` exists)
494530- ` ralph-tasks.md ` must exist (run ` /spec:ralph-tasks ` first)
531+ - Recommended: session on ** opus** with ** auto mode** enabled
495532
496533---
497534
498- ### Using the Ralph Loop
535+ ### Running the unattended loop
499536
500- The Ralph loop enables unattended, overnight TDD implementation by running Claude Code in a bash loop with fresh context per iteration.
537+ The loop runs ** in-session** — no external bash runner. Built-in ** auto mode** removes the
538+ per-action permission prompts and the self-driving loop (optionally self-paced with
539+ ` ScheduleWakeup ` ) replaces the old ` scripts/ralph.sh ` overnight runner.
501540
502- ** Setup:**
503541``` bash
504- # 1. Complete the spec workflow up to approved tasks
542+ # 1. Spec workflow up to an APPROVED DESIGN (no tasks step needed for this path)
505543/spec:requirements 123
506544/spec:approve requirements
507545/spec:design message-serialization
508- /spec:approve design
509- /spec:tasks
510- /spec:approve tasks
546+ /spec:approve design # ← prompts you to pick the unattended path
511547
512- # 2. Generate ralph-tasks from approved tasks
548+ # 2. Generate ralph-tasks directly from the approved design
513549/spec:ralph-tasks
514550
515551# 3. Review ralph-tasks.md in your IDE
516552
517- # 4. Run the loop
518- ./scripts/ralph.sh # defaults: 1 task/run, 50 max iterations
519- ./scripts/ ralph.sh 2 20 10 # 2 tasks/run, 20 max iterations, 10s cooldown
553+ # 4. Switch to opus and enable auto mode, then run the loop
554+ /model opus
555+ /spec: ralph-implement # choose tasks / turns / budget when prompted
520556
521557# 5. Stop the loop (if needed)
522- touch RALPH_STOP # halts after current task completes
558+ touch RALPH_STOP # unattended kill-switch (halts after current task)
559+ # …or press Esc to cancel a pending self-paced wake-up
523560```
524561
525- ** Environment variables:**
526- ``` bash
527- RALPH_MODEL=opus RALPH_BUDGET=10 ./scripts/ralph.sh
528- ```
562+ Optionally drive it with the built-in ` /loop ` instead, e.g. ` /loop /spec:ralph-implement `
563+ (self-paced) — the same command, repeated by ` /loop ` .
529564
530565---
531566
0 commit comments