Skip to content

Commit 43ec10a

Browse files
authored
Merge branch 'master' into add.messing-gateway.generated.tests
2 parents 133d46f + 6e06be0 commit 43ec10a

8 files changed

Lines changed: 261 additions & 447 deletions

File tree

.agent_instructions/skills_overview.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ Skills are slash commands that automate multi-step workflows and enforce Brighte
8585
/spec:approve <phase> → Approve phase
8686
8787
🔄 RALPH LOOP (UNATTENDED)
88-
/spec:ralph-tasks → Generate ralph tasks
89-
/spec:ralph-implement [count] → Unattended TDD
90-
scripts/ralph.sh [n] [max] → Run the loop
88+
/spec:ralph-tasks → Generate ralph tasks (standalone, from approved design)
89+
/spec:ralph-implement [count] → Unattended self-driving loop (opus + auto mode)
9190
```
9291

9392
## Decision Tree: Which Skill Should I Use?
@@ -238,19 +237,19 @@ Each skill enforces specific practices from `.agent_instructions/`:
238237
### Workflow 5: Ralph Loop (Unattended)
239238

240239
```bash
241-
# 1. Complete spec workflow up to approved tasks (Workflows 3 steps 1-4)
240+
# 1. Complete spec workflow up to an APPROVED DESIGN (no tasks step needed for this path)
242241

243-
# 2. Generate ralph-tasks from approved tasks
242+
# 2. Generate ralph-tasks directly from the approved design
244243
/spec:ralph-tasks
245244

246245
# 3. Review ralph-tasks.md in your IDE
247246

248-
# 4. Run the unattended loop
249-
./scripts/ralph.sh # 1 task/run, 50 max iterations
250-
./scripts/ralph.sh 2 20 10 # 2 tasks/run, 20 max, 10s cooldown
247+
# 4. Switch to opus + enable auto mode, then run the self-driving loop
248+
/model opus
249+
/spec:ralph-implement # choose the bound: tasks / turns / budget
251250

252251
# 5. Stop if needed
253-
touch RALPH_STOP
252+
touch RALPH_STOP # unattended kill-switch (or press Esc for a pending wake-up)
254253

255254
# 6. Review results
256255
git log --oneline

.claude/commands/spec/README.md

Lines changed: 84 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5161
Several 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

105116
The planning commands use the `Plan` agent so the "return as text, don't write the file"
106117
rule is much harder to violate accidentally (it has no `Write`/`Edit`/`NotebookEdit`; the
107118
prompt still forbids writing via `Bash`). `/spec:ralph-implement` keeps `general-purpose`
108119
because 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
111129
Red → user-approval → Green → Refactor loop is interactive, and the mandatory approval gate
112130
must 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

.claude/commands/spec/approve.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
allowed-tools: Bash(cat:*), Bash(test:*), Bash(touch:*), Bash(ls:*), Bash(echo:*), Bash(grep:*), Read, Write, Edit, Glob
2+
allowed-tools: Bash(cat:*), Bash(test:*), Bash(touch:*), Bash(ls:*), Bash(echo:*), Bash(grep:*), Read, Write, Edit, Glob, AskUserQuestion
33
description: Approve a specification phase
44
argument-hint: requirements|design [adr-number]|tasks
55
---
@@ -48,10 +48,26 @@ Parse $ARGUMENTS to extract phase and optional ADR number:
4848
4949
5. Create approval marker: `touch specs/{current-spec}/.design-approved`
5050
6. Show user which ADRs were approved
51-
7. Inform user about next steps:
52-
- If more ADRs needed: Run `/spec:design [another-focus-area]`
53-
- If all ADRs complete: Proceed to `/spec:tasks` to create implementation task list
54-
- Reminder: Commit approved ADRs to git
51+
7. Remind the user to commit the approved ADRs to git.
52+
8. **Choose the implementation path (the certainty fork).** If more ADRs are still
53+
needed, tell the user to run `/spec:design [another-focus-area]` first and stop here.
54+
Otherwise the design is complete and there are **two** ways to break the work down — use
55+
`AskUserQuestion` to let the user pick:
56+
57+
- **Attended — review each test** (`/spec:tasks` → `/spec:approve tasks` →
58+
`/spec:implement`): generates `tasks.md`, then a strict Red → **user approval** → Green
59+
→ Refactor loop in the main agent on **sonnet**. Use this when the work is uncertain and
60+
each test should be reviewed in the IDE before implementation.
61+
- **Unattended — review in batches** (`/spec:ralph-tasks` → `/spec:ralph-implement`):
62+
generates `ralph-tasks.md` directly from this approved design (no `tasks.md` step, no
63+
per-test approval gates), then a self-driving loop on **opus** (auto mode) that delegates
64+
each task to a **sonnet** sub-agent. Use this when the work is well-understood and can be
65+
reviewed after a batch of tasks rather than at every test.
66+
67+
This is "choose by certainty": some work warrants reviewing every test; other work can be
68+
reviewed at the end of a batch. Present both, let the user choose, and point them at the
69+
first command of the path they pick. Do **not** run that command yourself — just direct
70+
them to it.
5571
5672
### For "tasks" Phase
5773

.claude/commands/spec/implement.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ Current spec directory: specs/
1515
> **Recommended model: `sonnet`.** Unlike the other `/spec:*` commands, `/spec:implement`
1616
> does its work in the **main agent** (the interactive approval gate must reach the user),
1717
> so there is no sub-agent to assign a model to — the session model is what runs. This is
18-
> implementation work, which the model policy puts on **sonnet** (matching
19-
> `/spec:ralph-implement`). **If your session is not already on sonnet, consider switching
20-
> before you start** (e.g. a non-sonnet model such as opus). See
18+
> implementation work, which the model policy puts on **sonnet**. Step 0 below actively
19+
> prompts you to switch if the session is on another model. See
2120
> `.claude/commands/spec/README.md` → "Sub-agents & model policy".
2221
2322
## Critical Guidelines
@@ -28,6 +27,21 @@ Current spec directory: specs/
2827

2928
## Your Task
3029

30+
### Step 0: Confirm the Session Model
31+
32+
`/spec:implement` is interactive implementation work and the model policy puts it on
33+
**sonnet**. Check the session's current model:
34+
35+
- **If already on sonnet**: continue silently to Step 1.
36+
- **If on any other model** (e.g. opus, haiku): use `AskUserQuestion` to ask whether to
37+
switch to sonnet before starting — e.g. "This session is on {model}. `/spec:implement` is
38+
recommended on sonnet. Switch to sonnet first?" with options to **switch** (tell the user to
39+
run `/model sonnet`, since a command can't change the session model itself) or **continue on
40+
the current model**. Respect the choice; do not switch on their behalf, and do not block if
41+
they decline.
42+
43+
This is a one-time check at the start of the command.
44+
3145
### Step 1: Gather Context
3246

3347
1. Read `specs/.current-spec` to determine the active specification directory

0 commit comments

Comments
 (0)