ralphie 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,176 +1,122 @@
1
1
  ---
2
2
  name: ralphie-iterate
3
- description: Execute one Ralphie iteration - load context, explore codebase, plan implementation, write code with tests, review changes, and commit. Use this skill to run a single autonomous coding iteration following the Ralphie protocol.
3
+ description: Execute one Ralphie iteration using V2 spec format - load context, select tasks by budget, plan, implement, verify, update status, and commit.
4
4
  context: fork
5
5
  allowed-tools: Read, Write, Edit, Glob, Grep, Bash, Task, TodoWrite, LSP
6
6
  ---
7
7
 
8
- # Ralphie Iteration Protocol
8
+ # Ralphie Iteration Protocol (V2 Format)
9
9
 
10
- Execute ONE complete Ralphie iteration: read SPEC, plan, implement, test, review, commit.
10
+ Execute ONE complete Ralphie iteration: read spec, select tasks by budget, plan, implement, verify, update status, commit.
11
11
 
12
12
  **For coding standards** (language, style, testing, git, security), see `ralphie.md`.
13
13
 
14
- ## Claude Code Native Features
15
-
16
- This skill leverages Claude Code's native capabilities:
17
-
18
- | Feature | Tool | When Used |
19
- |---------|------|-----------|
20
- | **Codebase Exploration** | `Task(Explore)` | Step 2 - understand code before planning |
21
- | **Progress Tracking** | `TodoWrite` | Steps 1-6 - track sub-task completion |
22
- | **Code Review** | `Task(general-purpose)` | Step 5 - pre-commit review |
23
- | **Iteration Validation** | Stop Hook | After Step 6 - verify iteration complete |
24
-
25
- ## Creating SPECs
14
+ ## V2 Spec Format Overview
26
15
 
27
- **Use the `/create-spec` skill** for creating new SPECs. It provides:
28
- - Structured interview process
29
- - Proper task batching
30
- - LLM-based review before finalizing
16
+ V2 specs use task IDs and structured fields instead of checkboxes:
31
17
 
32
- This skill (`ralphie-iterate`) is for **executing** iterations, not creating specs.
33
-
34
- ## Writing SPECs
35
-
36
- Optimize for **iteration efficiency**. Each checkbox = one Ralphie iteration.
18
+ ```markdown
19
+ ### T001: Task title
20
+ - Status: pending | in_progress | passed | failed
21
+ - Size: S (1pt) | M (2pt) | L (4pt)
37
22
 
38
- ### Batch Related Tasks
23
+ **Deliverables:**
24
+ - Outcome 1
25
+ - Outcome 2
39
26
 
40
- ```markdown
41
- # BAD - 4 iterations
42
- - [ ] Create UserModel.ts
43
- - [ ] Create UserService.ts
44
- - [ ] Create UserController.ts
45
- - [ ] Create user.test.ts
46
-
47
- # GOOD - 1 iteration
48
- - [ ] Create User module (Model, Service, Controller) with tests
27
+ **Verify:** `npm test -- task-name`
49
28
  ```
50
29
 
51
- **Batch when:**
52
- - Same directory or tightly coupled files
53
- - Similar structure (4 similar components = 1 task)
54
- - Tests go with implementation
30
+ **Key features:**
31
+ - Task IDs (`T001`, `T002`) for tracking
32
+ - Status field tracks progress (pending in_progress passed/failed)
33
+ - Size field enables budget-based selection
34
+ - Verify section provides completion check
55
35
 
56
- **Don't batch when:**
57
- - Different areas of codebase
58
- - Complex logic needing focus
59
- - Independent failure modes
36
+ ## Claude Code Native Features
60
37
 
61
- ### What SPECs Should NOT Include
38
+ | Feature | Tool | When Used |
39
+ |---------|------|-----------|
40
+ | **Codebase Exploration** | `Task(scout)` | Step 2 - understand code before planning |
41
+ | **Progress Tracking** | `TodoWrite` | Steps 1-6 - track sub-task completion |
42
+ | **Code Review** | `Task(general-purpose)` | Step 5 - pre-commit review |
43
+ | **Iteration Validation** | Stop Hook | After Step 6 - verify iteration complete |
62
44
 
63
- SPECs describe **requirements**, not solutions. Implementation details belong in `.ai/ralphie/plan.md`.
45
+ ## Step 1: Load Context and Select Tasks
64
46
 
65
- **Never include in SPEC.md:**
66
- - Code snippets or fix approaches
67
- - Specific file:line references (e.g., `setup.ts:150`)
68
- - Root cause analysis ("The bug is in X because...")
69
- - Technical implementation notes or "Technical Notes" sections
70
- - Shell commands or CLI invocations
71
- - "How to fix" instructions
47
+ ### 1.1 Locate Spec
72
48
 
73
- **Sub-bullets are deliverables, not instructions:**
49
+ Find the active spec:
74
50
 
75
- ```markdown
76
- # BAD - prescribes implementation
77
- - [ ] Fix PR creation
78
- - Use `git rev-list` to check unpushed commits
79
- - Remove the early return at line 152
80
- - Add `--token` flag to gh command
81
-
82
- # GOOD - describes deliverables
83
- - [ ] Fix PR creation flow
84
- - Detect unpushed commits (not uncommitted changes)
85
- - Push and create PR when commits exist
86
- - Pass auth token correctly to gh CLI
51
+ ```bash
52
+ ls specs/active/*.md
87
53
  ```
88
54
 
89
- **Why this matters:**
90
- - The implementer figures out HOW during Step 2 (Explore) and Step 3 (Plan)
91
- - Over-specified SPECs constrain solutions and hide better approaches
92
- - Requirements should be testable outcomes, not implementation checklists
55
+ ### 1.2 Parse Tasks and Select by Budget
93
56
 
94
- **Run `ralphie validate` to check your SPEC for violations.**
57
+ Read the spec and identify tasks to work on:
95
58
 
96
- ## Step 1: Load Context
59
+ 1. **Find pending/in_progress tasks** - Look for `- Status: pending` or `- Status: in_progress`
60
+ 2. **Calculate budget** - Default: 4 points per iteration
61
+ 3. **Select tasks that fit** - Prioritize `in_progress` first, then `pending`
97
62
 
98
- ### 1.1 Read SPEC.md
99
-
100
- Find the next incomplete task:
101
- - Look for the first unchecked checkbox: `- [ ]`
102
- - Skip checked items: `- [x]`
103
- - A batched checkbox counts as ONE task (e.g., "Create components A, B, C" = 1 task)
63
+ **Size points:**
64
+ - S = 1 point
65
+ - M = 2 points
66
+ - L = 4 points
104
67
 
68
+ **Selection example (budget 4):**
105
69
  ```
106
- Read SPEC.md Find first `- [ ]` This is your task for this iteration
70
+ T003 (in_progress, M=2)Selected (2 pts used)
71
+ T004 (pending, S=1) → Selected (3 pts used)
72
+ T005 (pending, S=1) → Selected (4 pts used)
73
+ T006 (pending, M=2) → Skipped (would exceed budget)
107
74
  ```
108
75
 
109
- ### 1.2 Check STATE.txt (if needed)
76
+ ### 1.3 Mark Selected Tasks as in_progress
110
77
 
111
- Read `STATE.txt` when:
112
- - Unsure if a task was partially completed
113
- - Need to understand blockers from previous iterations
114
- - Want to verify what was done vs what SPEC shows
78
+ For each task you're starting, update its Status:
115
79
 
116
- Look for:
117
- - ✅ entries (completed work)
118
- - ⚠️ entries (blockers or issues)
119
- - Last completion timestamp
80
+ ```markdown
81
+ # Before
82
+ ### T004: Add input validation
83
+ - Status: pending
84
+ - Size: S
120
85
 
121
- ### 1.3 Read Recent Context
86
+ # After
87
+ ### T004: Add input validation
88
+ - Status: in_progress
89
+ - Size: S
90
+ ```
91
+
92
+ **Use Edit tool** to change `Status: pending` to `Status: in_progress`.
122
93
 
123
- Read **last 3-5 entries** from `.ai/ralphie/index.md`:
124
- - Extract file patterns (what files were recently changed)
125
- - Note "next:" hints (what the previous iteration recommended)
126
- - Understand recent architectural decisions
94
+ ### 1.4 Read Context Files
127
95
 
128
- **Don't read the entire index** — only recent entries to stay context-efficient.
96
+ **Read if they exist:**
97
+ - `specs/lessons.md` - Past learnings to apply
98
+ - `.ai/ralphie/index.md` (last 3-5 entries) - Recent changes and recommendations
99
+ - `STATE.txt` - If unsure about partial completion
129
100
 
130
- ### 1.4 Break Down with TodoWrite
101
+ ### 1.5 Break Down with TodoWrite
131
102
 
132
- If the task has **3+ steps**, use TodoWrite to track sub-tasks:
103
+ If total selected work has **3+ steps**, use TodoWrite:
133
104
 
134
105
  ```typescript
135
106
  TodoWrite({
136
107
  todos: [
137
- {
138
- content: "Read existing auth code",
139
- activeForm: "Reading existing auth code",
140
- status: "pending"
141
- },
142
- {
143
- content: "Create login endpoint",
144
- activeForm: "Creating login endpoint",
145
- status: "pending"
146
- },
147
- {
148
- content: "Add input validation",
149
- activeForm: "Adding input validation",
150
- status: "pending"
151
- },
152
- {
153
- content: "Write unit tests",
154
- activeForm: "Writing unit tests",
155
- status: "pending"
156
- }
108
+ { content: "T003: Complete user validation", activeForm: "Completing user validation", status: "in_progress" },
109
+ { content: "T004: Add input validation", activeForm: "Adding input validation", status: "pending" },
110
+ { content: "T005: Add error messages", activeForm: "Adding error messages", status: "pending" },
111
+ { content: "Run tests and verify", activeForm: "Running tests", status: "pending" },
112
+ { content: "Commit changes", activeForm: "Committing", status: "pending" }
157
113
  ]
158
114
  })
159
115
  ```
160
116
 
161
- **Required fields:**
162
- - `content`: Imperative form (what to do)
163
- - `activeForm`: Present continuous (what's happening)
164
- - `status`: "pending" | "in_progress" | "completed"
165
-
166
- **Skip TodoWrite when:**
167
- - Task is atomic (single file, single change)
168
- - Task is documentation-only
169
- - Task can be completed in under 3 steps
170
-
171
117
  ## Step 2: Explore (if needed)
172
118
 
173
- Before writing your plan, spawn parallel exploration agents to understand unfamiliar parts of the codebase. This is faster than reading files sequentially and helps you make better architectural decisions.
119
+ Before writing your plan, spawn exploration agents to understand unfamiliar code.
174
120
 
175
121
  ### 2.1 When to Explore
176
122
 
@@ -178,559 +124,272 @@ Before writing your plan, spawn parallel exploration agents to understand unfami
178
124
  - Working in a new area of the codebase
179
125
  - Task involves multiple interconnected modules
180
126
  - Unsure about existing patterns or conventions
181
- - Need to understand how similar features were implemented
182
127
 
183
128
  **Skip when:**
184
129
  - Working on files you've modified recently
185
130
  - Simple changes to isolated functions
186
- - Task specifies exact file paths in SPEC
187
131
  - Documentation-only changes
188
132
 
189
133
  ### 2.2 Spawn Parallel Agents
190
134
 
191
- Use the Task tool with `subagent_type='Explore'` to spawn agents that search the codebase in parallel. **Send all Task calls in a single message** to run them concurrently:
135
+ Use `Task(scout)` to explore in parallel:
192
136
 
193
137
  ```typescript
194
- // Example: Exploring for an authentication feature
195
- // Spawn all agents in ONE message (parallel execution)
196
-
197
138
  Task({
198
- subagent_type: 'Explore',
199
- description: 'Find auth patterns',
200
- prompt: 'Find how authentication is implemented. Look for middleware, JWT handling, session management. Report file paths and key patterns.'
139
+ subagent_type: 'scout',
140
+ description: 'Find validation patterns',
141
+ prompt: 'Find input validation patterns. Look for validation libraries, error formatting, common patterns. Report file paths and examples.'
201
142
  })
202
143
 
203
144
  Task({
204
- subagent_type: 'Explore',
145
+ subagent_type: 'scout',
205
146
  description: 'Find test patterns',
206
- prompt: 'Find testing patterns for API endpoints. Look for test setup, mocking strategies, assertion patterns. Report examples I can follow.'
207
- })
208
-
209
- Task({
210
- subagent_type: 'Explore',
211
- description: 'Find error handling',
212
- prompt: 'Find error handling patterns. Look for custom error classes, error middleware, response formatting. Report the conventions used.'
147
+ prompt: 'Find testing patterns for validation. Look for test setup, assertion patterns, error case testing.'
213
148
  })
214
149
  ```
215
150
 
216
- ### 2.3 What to Explore
217
-
218
- Tailor your exploration prompts to your task:
219
-
220
- | Need | Prompt Focus |
221
- |------|--------------|
222
- | **Architecture** | "How is [feature] structured? What files/modules are involved?" |
223
- | **Patterns** | "What patterns are used for [X]? Show me examples." |
224
- | **Dependencies** | "What does [module] depend on? What depends on it?" |
225
- | **Conventions** | "What naming/file structure conventions are used?" |
226
- | **Similar features** | "How is [existing similar feature] implemented?" |
151
+ ### 2.3 Using Exploration Results
227
152
 
228
- ### 2.4 Using Exploration Results
229
-
230
- Once all agents complete:
231
-
232
- 1. **Wait for completion** — don't proceed until all agents return
233
- 2. **Extract file paths** — incorporate discovered paths into your plan's Files section
234
- 3. **Follow patterns** — use patterns the agents identify (don't invent new ones)
235
- 4. **Note concerns** — document any blockers or risks in your plan
236
- 5. **Update sub-tasks** — add/remove TodoWrite items based on findings
237
-
238
- ```
239
- Exploration Results → Informs Plan → Guides Implementation
240
- ```
153
+ 1. Wait for all agents to complete
154
+ 2. Extract file paths for your plan
155
+ 3. Follow discovered patterns
156
+ 4. Update TodoWrite if needed
241
157
 
242
158
  ## Step 3: Plan
243
159
 
244
- Write your plan to `.ai/ralphie/plan.md` **before writing any code**. The plan is your contract for this iteration — it defines scope, prevents creep, and provides a clear completion target.
245
-
246
- ### 3.1 Write the Goal
160
+ Write your plan to `.ai/ralphie/plan.md` **before writing any code**.
247
161
 
248
- The Goal is a **single sentence** that describes what this iteration accomplishes. It should be:
249
- - **Specific**: Name the feature, component, or fix
250
- - **Completable**: Something achievable in one iteration
251
- - **Verifiable**: You can objectively confirm it's done
162
+ ### 3.1 Plan Format
252
163
 
253
- **Good goals:**
254
164
  ```markdown
255
165
  ## Goal
256
- Add JWT token refresh endpoint that returns a new access token when given a valid refresh token.
257
- ```
166
+ Single sentence: what this iteration accomplishes.
258
167
 
259
- ```markdown
260
- ## Goal
261
- Fix race condition in WebSocket reconnection that causes duplicate message handlers.
262
- ```
168
+ ## Tasks (from spec)
169
+ - T003: Complete user validation [M]
170
+ - T004: Add input validation [S]
171
+ - T005: Add error messages [S]
263
172
 
264
- **Bad goals (too vague):**
265
- ```markdown
266
- ## Goal
267
- Improve authentication. ← What specifically? Add? Fix? Refactor?
268
- ```
269
-
270
- ```markdown
271
- ## Goal
272
- Work on the API. ← Which endpoint? What change?
273
- ```
173
+ Total: 4 points
274
174
 
275
- ### 3.2 List the Files
276
-
277
- List every file you plan to create or modify with a brief note about what changes:
278
-
279
- ```markdown
280
175
  ## Files
281
- - src/auth/refresh.ts - create token refresh endpoint
282
- - src/auth/middleware.ts - add refresh token validation
283
- - src/auth/types.ts - add RefreshTokenPayload type
284
- - tests/auth/refresh.test.ts - unit tests for refresh flow
285
- ```
286
-
287
- **Guidelines:**
288
- - **Be explicit** — list actual file paths, not "auth files"
289
- - **Include tests** — every implementation file should have a corresponding test file
290
- - **Note the action** — "create", "modify", "add", "fix", "remove"
291
- - **Use exploration results** — if Step 2 found patterns in specific files, reference them
292
-
293
- If you're unsure which files need changes, your exploration in Step 2 was incomplete. Go back and explore more before planning.
176
+ - src/validation/user.ts - add validation rules
177
+ - src/errors/messages.ts - add error messages
178
+ - tests/validation/user.test.ts - unit tests
294
179
 
295
- ### 3.3 Define the Tests
296
-
297
- List specific test scenarios that prove your implementation works. These become your acceptance criteria:
298
-
299
- ```markdown
300
180
  ## Tests
301
- - Returns new access token when refresh token is valid
302
- - Returns 401 when refresh token is expired
303
- - Returns 401 when refresh token is revoked
304
- - Returns 400 when refresh token is malformed
305
- - Rotates refresh token on successful refresh (one-time use)
306
- ```
307
-
308
- **Guidelines:**
309
- - **Cover happy path** — at least one test for the success case
310
- - **Cover error cases** — invalid input, edge cases, failures
311
- - **Be specific** — "handles errors" is not a test; "returns 404 when user not found" is
312
- - **Match existing patterns** — look at how similar features are tested in the codebase
181
+ - Validates email format
182
+ - Rejects invalid phone numbers
183
+ - Returns localized error messages
184
+ - Handles edge cases (empty, null)
313
185
 
314
- **Skip when:**
315
- - Task is documentation-only
316
- - Task is configuration/setup (no logic to test)
317
- - Existing tests already cover the change
318
-
319
- ### 3.4 Set Exit Criteria
320
-
321
- Exit criteria are the **checkboxes you must check** before committing. They combine your goal, tests, and any additional requirements:
322
-
323
- ```markdown
324
186
  ## Exit Criteria
325
- - Refresh endpoint returns new tokens for valid requests
326
- - All 5 test scenarios pass
327
- - Type checking passes (`npm run type-check`)
328
- - No new linting errors
329
- - Changes committed with conventional message
330
- ```
331
-
332
- **Standard exit criteria (include most of these):**
333
- - Feature/fix works as described in Goal
334
- - Tests pass with good coverage (80%+ for new code)
335
- - Type checking passes (if TypeScript)
336
- - No linting errors
187
+ - All selected tasks pass their Verify commands
188
+ - Tests pass with 80%+ coverage
189
+ - Type check passes
337
190
  - Changes committed
191
+ ```
338
192
 
339
- **Additional criteria (when applicable):**
340
- - Documentation updated (for public APIs)
341
- - Migration added (for database changes)
342
- - Environment variables documented (for new config)
193
+ ### 3.2 Include Verify Commands
343
194
 
344
- ### Complete Plan Example
195
+ For each task, note its Verify command from the spec:
345
196
 
346
197
  ```markdown
347
- ## Goal
348
- Add JWT token refresh endpoint that returns a new access token when given a valid refresh token.
349
-
350
- ## Files
351
- - src/auth/refresh.ts - create token refresh endpoint
352
- - src/auth/middleware.ts - add refresh token validation helper
353
- - src/auth/types.ts - add RefreshTokenPayload interface
354
- - tests/auth/refresh.test.ts - unit tests
355
-
356
- ## Tests
357
- - Returns new access token when refresh token is valid
358
- - Returns 401 when refresh token is expired
359
- - Returns 401 when refresh token is revoked
360
- - Returns 400 when refresh token is malformed
361
- - Rotates refresh token on successful refresh
362
-
363
- ## Exit Criteria
364
- - Refresh endpoint works for valid requests
365
- - All 5 test scenarios pass
366
- - Type checking passes
367
- - Changes committed
198
+ ## Verification Commands
199
+ - T003: `npm test -- user-validation`
200
+ - T004: `npm test -- input-validation`
201
+ - T005: `npm test -- error-messages`
368
202
  ```
369
203
 
370
- ### After Writing the Plan
371
-
372
- 1. **Review scope** — Is this achievable in one iteration? If not, split the task.
373
- 2. **Update TodoWrite** — Add sub-tasks based on your Files list if not done in Step 1.
374
- 3. **Proceed to implementation** — Only start coding after the plan is written.
375
-
376
204
  ## Step 4: Implement
377
205
 
378
- Now execute your plan. Write the code, write the tests, and verify everything works before proceeding to review.
206
+ Execute your plan for each selected task.
379
207
 
380
- ### 4.1 Write the Code
208
+ ### 4.1 Implementation Order
381
209
 
382
- Follow your plan's Files section. For each file:
210
+ For multiple tasks, implement in order (T003 → T004 → T005):
383
211
 
384
- 1. **Read first** Understand existing code before modifying
385
- 2. **Follow patterns** Match the codebase's style, conventions, and architecture
386
- 3. **Keep it simple** — Don't over-engineer or add features beyond the plan
387
- 4. **Update TodoWrite** — Mark sub-task as `in_progress` when you start
212
+ 1. **Start task** - Update TodoWrite to `in_progress`
213
+ 2. **Read existing code** - Understand before modifying
214
+ 3. **Write code** - Follow existing patterns
215
+ 4. **Write tests** - Cover all planned scenarios
216
+ 5. **Run task's Verify command** - Confirm it passes
217
+ 6. **Complete task** - Update TodoWrite to `completed`
388
218
 
389
- ```typescript
390
- // Before starting a sub-task:
391
- TodoWrite({
392
- todos: [
393
- { content: "Create login endpoint", activeForm: "Creating login endpoint", status: "in_progress" },
394
- { content: "Add input validation", activeForm: "Adding input validation", status: "pending" },
395
- // ...
396
- ]
397
- })
398
- ```
219
+ ### 4.2 Run Verify Commands
399
220
 
400
- **Implementation order:**
401
- 1. Types/interfaces first (if TypeScript)
402
- 2. Core logic
403
- 3. Integration points (exports, routes, etc.)
404
- 4. Tests (or write alongside — see 4.2)
405
-
406
- **Avoid:**
407
- - Adding comments unless truly necessary (code should be self-documenting)
408
- - Creating new patterns when existing patterns work
409
- - Scope creep — if you discover something outside the plan, note it for the next iteration
410
-
411
- ### 4.2 Write the Tests
412
-
413
- Write tests that match your plan's Tests section. Each test scenario becomes a test case.
414
-
415
- **Test structure:**
416
- ```typescript
417
- describe('RefreshToken', () => {
418
- describe('refresh', () => {
419
- it('returns new access token when refresh token is valid', async () => {
420
- // Arrange - set up test data
421
- const refreshToken = createValidRefreshToken();
422
-
423
- // Act - call the function
424
- const result = await refresh(refreshToken);
425
-
426
- // Assert - verify the outcome
427
- expect(result.accessToken).toBeDefined();
428
- expect(result.expiresIn).toBe(3600);
429
- });
430
-
431
- it('returns 401 when refresh token is expired', async () => {
432
- const expiredToken = createExpiredRefreshToken();
433
-
434
- await expect(refresh(expiredToken))
435
- .rejects.toThrow(UnauthorizedError);
436
- });
437
- });
438
- });
439
- ```
440
-
441
- **Guidelines:**
442
- - **One assertion per test** (when practical) — easier to debug failures
443
- - **Descriptive names** — test name should describe the scenario
444
- - **Cover the plan** — every test in your Tests section should become a real test
445
- - **Match existing patterns** — look at how similar features are tested
446
-
447
- **Update TodoWrite after writing tests:**
448
- ```typescript
449
- TodoWrite({
450
- todos: [
451
- { content: "Create login endpoint", activeForm: "Creating login endpoint", status: "completed" },
452
- { content: "Add input validation", activeForm: "Adding input validation", status: "completed" },
453
- { content: "Write unit tests", activeForm: "Writing unit tests", status: "in_progress" },
454
- // ...
455
- ]
456
- })
457
- ```
458
-
459
- ### 4.3 Run Tests
460
-
461
- Run the full test suite to verify your implementation:
221
+ After implementing each task, run its Verify command:
462
222
 
463
223
  ```bash
464
- # Standard commands (use project-specific if different)
465
- npm test # Run all tests
466
- npm test -- --coverage # Run with coverage report
467
- npm test -- path/to/file # Run specific test file
224
+ # From spec: **Verify:** `npm test -- user-validation`
225
+ npm test -- user-validation
468
226
  ```
469
227
 
470
- **What to check:**
471
- - All tests pass (especially your new ones)
472
- - No regressions in existing tests
473
- - Coverage meets requirements (80%+ for new code)
474
-
475
- **If tests fail:**
476
- 1. Read the error message carefully
477
- 2. Fix the failing test or implementation
478
- 3. Re-run tests
479
- 4. Don't proceed until all tests pass
228
+ **If Verify fails:**
229
+ 1. Fix the issue
230
+ 2. Re-run Verify
231
+ 3. Don't proceed until it passes
480
232
 
481
- ### 4.4 Run Type Check
233
+ ### 4.3 Run Full Test Suite
482
234
 
483
- For TypeScript projects, verify types before proceeding:
235
+ After all tasks implemented:
484
236
 
485
237
  ```bash
486
- npm run type-check # or: npx tsc --noEmit
238
+ npm test # All tests
239
+ npm run type-check # TypeScript
487
240
  ```
488
241
 
489
- **Common type errors and fixes:**
242
+ ### 4.4 Update TodoWrite Progress
490
243
 
491
- | Error | Fix |
492
- |-------|-----|
493
- | `Property does not exist` | Add the property to the interface or check for typos |
494
- | `Type X is not assignable to Y` | Fix the type mismatch or add proper type casting |
495
- | `Cannot find module` | Check import path or add missing dependency |
496
- | `Argument of type X is not assignable` | Update function signature or caller |
497
-
498
- **Don't proceed with type errors.** They often indicate real bugs.
499
-
500
- ### 4.5 Handle Failures
501
-
502
- If tests or type checking fail repeatedly:
503
-
504
- 1. **Don't force it** — Repeated failures signal a deeper issue
505
- 2. **Check your plan** — Did you miss something in the Files section?
506
- 3. **Revisit exploration** — Maybe you need more context
507
- 4. **Scope down** — Can you complete a smaller portion of the task?
508
-
509
- **If blocked:**
510
244
  ```typescript
511
- // Update TodoWrite to reflect the blocker
512
245
  TodoWrite({
513
246
  todos: [
514
- { content: "Create login endpoint", activeForm: "Creating login endpoint", status: "completed" },
515
- { content: "Fix type error in auth middleware", activeForm: "Fixing type error", status: "in_progress" },
516
- // Don't mark as completed if you can't finish it
247
+ { content: "T003: Complete user validation", activeForm: "Completed", status: "completed" },
248
+ { content: "T004: Add input validation", activeForm: "Completed", status: "completed" },
249
+ { content: "T005: Add error messages", activeForm: "Completed", status: "completed" },
250
+ { content: "Run tests and verify", activeForm: "Running tests", status: "in_progress" },
251
+ { content: "Commit changes", activeForm: "Committing", status: "pending" }
517
252
  ]
518
253
  })
519
254
  ```
520
255
 
521
- If you can't complete the task:
522
- - Don't commit partial/broken code
523
- - Document the blocker in STATE.txt
524
- - Stop the iteration — the next iteration will pick it up
525
-
526
- ### Implementation Checklist
527
-
528
- Before proceeding to Review:
529
-
530
- - [ ] All planned files created/modified
531
- - [ ] Code follows existing patterns
532
- - [ ] Tests written for all planned scenarios
533
- - [ ] `npm test` passes
534
- - [ ] `npm run type-check` passes (TypeScript)
535
- - [ ] TodoWrite sub-tasks marked as completed
536
-
537
256
  ## Step 5: Review
538
257
 
539
- Before committing, spawn a review agent to catch bugs, verify patterns, and ensure quality. This step prevents shipping broken code and helps maintain codebase consistency.
258
+ Before committing, spawn a review agent for significant changes.
540
259
 
541
260
  ### 5.1 When to Review
542
261
 
543
262
  **Review when:**
544
- - You wrote more than 20 lines of new code
545
- - You modified existing business logic
546
- - You added or changed API endpoints
547
- - You made security-relevant changes (auth, validation, encryption)
548
- - You're uncertain about your implementation approach
263
+ - More than 20 lines of new code
264
+ - Modified business logic
265
+ - Security-relevant changes
549
266
 
550
267
  **Skip when:**
551
- - Task is documentation-only
552
- - Changes are config/setup files only
553
- - Changes are purely stylistic (formatting, renaming)
554
- - You only deleted code without adding anything new
268
+ - Documentation-only
269
+ - Config/setup only
270
+ - Purely stylistic
555
271
 
556
272
  ### 5.2 Spawn Review Agent
557
273
 
558
- Use the Task tool with `subagent_type='general-purpose'` to spawn a review agent. Provide context about the task and list the files you changed:
559
-
560
274
  ```typescript
561
275
  Task({
562
276
  subagent_type: 'general-purpose',
563
277
  description: 'Review code changes',
564
- prompt: `Review the following code changes for: [TASK DESCRIPTION]
278
+ prompt: `Review changes for tasks T003, T004, T005.
565
279
 
566
280
  ## Files Changed
567
- - [file1.ts] - [what was changed]
568
- - [file2.ts] - [what was changed]
569
- - [file.test.ts] - [tests added]
570
-
571
- ## Review Checklist
572
- Please check for:
573
- 1. **Bugs** - Logic errors, off-by-one, null handling, race conditions
574
- 2. **Test coverage** - Are edge cases tested? Any missing scenarios?
575
- 3. **Patterns** - Does the code follow existing codebase patterns?
576
- 4. **Security** - Input validation, injection risks, auth bypasses
577
- 5. **Performance** - N+1 queries, unnecessary loops, memory leaks
578
-
579
- ## Response Format
580
- Respond with ONE of:
581
- - **CRITICAL**: Must-fix issues that would cause bugs or security problems
582
- - **SUGGESTIONS**: Optional improvements (style, naming, minor optimizations)
583
- - **APPROVED**: Code is ready to commit
584
-
585
- If CRITICAL, list each issue with file:line and a brief fix description.`
586
- })
587
- ```
281
+ - src/validation/user.ts - validation rules
282
+ - src/errors/messages.ts - error messages
283
+ - tests/validation/user.test.ts - tests
588
284
 
589
- **Customize the prompt for your task:**
590
- - For API changes, emphasize validation and error handling
591
- - For database changes, emphasize migrations and query performance
592
- - For auth changes, emphasize security review
593
- - For UI changes, emphasize user experience and accessibility
285
+ ## Check for:
286
+ 1. Bugs - logic errors, null handling
287
+ 2. Test coverage - edge cases tested?
288
+ 3. Patterns - follows existing conventions?
289
+ 4. Security - input validation complete?
594
290
 
595
- ### 5.3 Handle Review Feedback
291
+ Respond: CRITICAL, SUGGESTIONS, or APPROVED`
292
+ })
293
+ ```
596
294
 
597
- The review agent will respond with one of three outcomes:
295
+ ### 5.3 Handle Feedback
598
296
 
599
297
  | Response | Action |
600
298
  |----------|--------|
601
- | **CRITICAL** | **Must fix** - Address every critical issue before committing |
602
- | **SUGGESTIONS** | **Optional** - Address if quick (<5 min), otherwise note for future |
603
- | **APPROVED** | **Proceed** - Move to Step 6 (Commit) |
604
-
605
- **Handling CRITICAL feedback:**
299
+ | **CRITICAL** | Fix all issues, re-review |
300
+ | **SUGGESTIONS** | Fix if quick, otherwise note for later |
301
+ | **APPROVED** | Proceed to commit |
606
302
 
607
- 1. **Read the issues** - Each critical issue should include file:line and description
608
- 2. **Fix in priority order** - Security > Bugs > Breaking changes
609
- 3. **Re-run tests** - Ensure fixes didn't break anything
610
- 4. **Re-run type check** - Ensure fixes don't introduce type errors
611
- 5. **Request re-review** - Spawn another review agent to verify fixes
303
+ ## Step 6: Commit and Update Status
612
304
 
613
- ```typescript
614
- // After fixing critical issues, re-review:
615
- Task({
616
- subagent_type: 'general-purpose',
617
- description: 'Re-review fixes',
618
- prompt: `Re-review after fixing critical issues.
305
+ ### 6.1 Update Task Status to Passed
619
306
 
620
- ## Original Issues (now fixed)
621
- - [Issue 1]: Fixed by [change]
622
- - [Issue 2]: Fixed by [change]
307
+ For each completed task, update Status in the spec:
623
308
 
624
- ## Files Changed
625
- - [file1.ts] - [original change + fix]
309
+ ```markdown
310
+ # Before
311
+ ### T003: Complete user validation
312
+ - Status: in_progress
313
+ - Size: M
626
314
 
627
- Verify fixes are correct. Respond: CRITICAL, SUGGESTIONS, or APPROVED.`
628
- })
315
+ # After
316
+ ### T003: Complete user validation
317
+ - Status: passed
318
+ - Size: M
629
319
  ```
630
320
 
631
- **Handling SUGGESTIONS:**
321
+ **Use Edit tool** to change `Status: in_progress` to `Status: passed`.
632
322
 
633
- Suggestions are optional but valuable:
634
- - Address if the fix is quick (< 5 minutes)
635
- - Skip if the suggestion is stylistic preference
636
- - Note valuable suggestions in your commit message or index.md for future iterations
323
+ ### 6.2 If Task Failed
637
324
 
638
- ### 5.4 Review Flow Example
325
+ If a task couldn't be completed:
639
326
 
640
- ```
641
- Implementation Complete
642
-
643
-
644
- ┌─────────────────────┐
645
- │ Spawn Review Agent │
646
- └─────────────────────┘
647
-
648
-
649
- ┌─────────┐
650
- │ RESULT? │
651
- └─────────┘
652
-
653
- ┌────┼────┬────────────┐
654
- │ │ │ │
655
- ▼ │ ▼ ▼
656
- CRITICAL │ SUGGESTIONS APPROVED
657
- │ │ │ │
658
- ▼ │ ▼ ▼
659
- Fix │ Optional Proceed
660
- Issues │ Fixes to Commit
661
- │ │ │ │
662
- ▼ │ ▼ │
663
- Re-review│ Proceed │
664
- │ │ │ │
665
- └────┴────┴────────────┘
666
-
667
-
668
- Step 6: Commit
327
+ ```markdown
328
+ ### T003: Complete user validation
329
+ - Status: failed
330
+ - Size: M
669
331
  ```
670
332
 
671
- ### 5.5 Update TodoWrite
333
+ Add a note in the spec's Notes section:
672
334
 
673
- After review completes, update your sub-tasks:
335
+ ```markdown
336
+ ## Notes
674
337
 
675
- ```typescript
676
- TodoWrite({
677
- todos: [
678
- { content: "Write implementation code", activeForm: "Writing code", status: "completed" },
679
- { content: "Write unit tests", activeForm: "Writing tests", status: "completed" },
680
- { content: "Run tests and type check", activeForm: "Running verification", status: "completed" },
681
- { content: "Code review", activeForm: "Reviewing code", status: "completed" },
682
- { content: "Commit changes", activeForm: "Committing", status: "pending" }
683
- ]
684
- })
338
+ ### T003 Failed (2026-01-18)
339
+ - Issue: Validation library incompatible with existing schema
340
+ - Attempted: Custom validation but hit type conflicts
341
+ - Next: Evaluate alternative libraries
685
342
  ```
686
343
 
687
- ### Review Checklist
344
+ ### 6.3 Update index.md
345
+
346
+ Prepare the index.md entry (use placeholder for commit SHA):
688
347
 
689
- Before proceeding to Commit:
348
+ ```markdown
349
+ ## COMMIT_SHA — feat(validation): add user input validation
690
350
 
691
- - [ ] Review agent spawned with appropriate context
692
- - [ ] All CRITICAL issues addressed
693
- - [ ] Tests still pass after any fixes
694
- - [ ] Type check still passes after any fixes
695
- - [ ] Response is APPROVED or SUGGESTIONS-only
351
+ - tasks: T003, T004, T005 (4 points)
352
+ - files: src/validation/user.ts, src/errors/messages.ts, tests/validation/user.test.ts
353
+ - tests: 12 passing
354
+ - notes: Used Zod for validation, matches existing patterns
355
+ - next: T006, T007 are ready (5 points for next iteration)
356
+ ```
696
357
 
697
- ## Step 6: Commit
358
+ ### 6.4 Update STATE.txt
698
359
 
699
- After your implementation passes review, commit your changes and update the tracking files. This step completes the iteration and leaves a clean trail for the next one.
360
+ ```markdown
361
+ ✅ 2026-01-18: Completed T003, T004, T005 (4 points)
362
+ - Added user input validation with Zod
363
+ - Added localized error messages
364
+ - Tests: 12 passing
365
+ ```
700
366
 
701
- ### 6.1 Stage Your Changes
367
+ ### 6.5 Stage and Commit Everything
702
368
 
703
- Stage only the files listed in your plan. Don't stage unrelated changes:
369
+ **Important:** Stage ALL changed files including tracking files:
704
370
 
705
371
  ```bash
706
- # Stage specific files (preferred)
707
- git add src/auth/refresh.ts src/auth/types.ts tests/auth/refresh.test.ts
372
+ # Stage implementation files
373
+ git add src/validation/ src/errors/ tests/validation/
708
374
 
709
- # Or stage all tracked changes if you're certain
710
- git add -A
711
- ```
375
+ # Stage spec with status updates
376
+ git add specs/active/*.md
712
377
 
713
- **Pre-stage checklist:**
714
- - [ ] Only files from your plan's Files section
715
- - [ ] No temporary files, logs, or build artifacts
716
- - [ ] No `.env` files or secrets
717
- - [ ] No unintended formatting changes in other files
378
+ # Stage tracking files
379
+ git add .ai/ralphie/index.md .ai/ralphie/plan.md STATE.txt
718
380
 
719
- **Check what you're committing:**
720
- ```bash
721
- git status # See staged files
722
- git diff --staged # Review staged changes
381
+ git status # Verify all files staged
723
382
  ```
724
383
 
725
- ### 6.2 Write the Commit Message
726
-
727
- Use [Conventional Commits](https://www.conventionalcommits.org/) format. Always use a HEREDOC for proper multi-line formatting:
384
+ Commit with conventional format:
728
385
 
729
386
  ```bash
730
387
  git commit -m "$(cat <<'EOF'
731
- type(scope): brief description
388
+ feat(validation): add user input validation and error messages
732
389
 
733
- Longer explanation if needed.
390
+ - T003: Complete user validation
391
+ - T004: Add input validation
392
+ - T005: Add error messages
734
393
 
735
394
  🤖 Generated with [Claude Code](https://claude.com/claude-code)
736
395
 
@@ -739,221 +398,75 @@ EOF
739
398
  )"
740
399
  ```
741
400
 
742
- **Commit types:**
743
- | Type | Use for |
744
- |------|---------|
745
- | `feat` | New feature or functionality |
746
- | `fix` | Bug fix |
747
- | `refactor` | Code change that doesn't add feature or fix bug |
748
- | `test` | Adding or updating tests |
749
- | `docs` | Documentation only |
750
- | `chore` | Maintenance tasks, dependency updates |
751
-
752
- **Examples:**
753
- ```
754
- feat(auth): add JWT token refresh endpoint
755
- fix(api): handle null response from user service
756
- refactor(utils): extract validation into shared module
757
- test(auth): add edge case tests for token expiry
758
- docs(readme): add API documentation
759
- ```
760
-
761
- **Scope guidelines:**
762
- - Use the feature area or module name: `auth`, `api`, `ui`, `db`
763
- - Keep it lowercase and short (1-2 words)
764
- - Be consistent with existing commits in the repo
401
+ ### 6.6 Update index.md with Commit SHA
765
402
 
766
- ### 6.3 Update index.md
403
+ After committing, get the SHA and update the placeholder:
767
404
 
768
- After committing, append an entry to `.ai/ralphie/index.md`. This creates a searchable history of what each iteration accomplished.
769
-
770
- **Get your commit SHA:**
771
405
  ```bash
772
- git log -1 --format='%h' # Short SHA (7 chars)
773
- ```
774
-
775
- **Entry format:**
776
- ```markdown
777
- ## {sha} — {commit message}
778
- - files: {list of changed files}
779
- - tests: {test count} passing
780
- - notes: {key decisions, patterns used, gotchas}
781
- - next: {logical follow-up task or recommendation}
782
- ```
783
-
784
- **Example entry:**
785
- ```markdown
786
- ## a1b2c3d — feat(auth): add JWT token refresh endpoint
787
- - files: src/auth/refresh.ts, src/auth/types.ts, tests/auth/refresh.test.ts
788
- - tests: 8 passing
789
- - notes: Used existing JWT library, added refresh token rotation for security
790
- - next: Add token revocation endpoint for logout
791
- ```
792
-
793
- **Guidelines:**
794
- - **Keep it concise** — 5-7 lines max per entry
795
- - **files**: List actual filenames, not directories
796
- - **tests**: Include count (get from `npm test` output)
797
- - **notes**: Capture decisions future iterations need to know
798
- - **next**: Suggest what should come next (helps the next iteration)
799
-
800
- ### 6.4 Update SPEC.md
801
-
802
- Check off the completed task in `SPEC.md`:
803
-
804
- ```markdown
805
- # Before
806
- - [ ] Add JWT token refresh endpoint with tests
807
-
808
- # After
809
- - [x] Add JWT token refresh endpoint with tests
406
+ git log -1 --format='%h'
810
407
  ```
811
408
 
812
- **Rules:**
813
- - Only check off tasks that are **fully complete**
814
- - One checkbox = one iteration (don't check multiple)
815
- - If you couldn't complete the task, leave it unchecked
816
-
817
- ### 6.5 Update STATE.txt
409
+ Use Edit tool to replace `COMMIT_SHA` with the actual hash, then amend:
818
410
 
819
- Append a completion record to `STATE.txt`:
820
-
821
- ```markdown
822
- ✅ YYYY-MM-DD: {Brief description of what was done}
823
- - {Key detail 1}
824
- - {Key detail 2}
825
- - Tests: {count} passing
826
- - Commit: {sha} {commit message}
827
- ```
828
-
829
- **Example:**
830
- ```markdown
831
- ✅ 2026-01-12: Added JWT token refresh endpoint
832
- - Created refresh.ts with token validation and rotation
833
- - Added RefreshTokenPayload interface to types.ts
834
- - Tests: 8 passing (refresh.test.ts)
835
- - Commit: a1b2c3d feat(auth): add JWT token refresh endpoint
836
- ```
837
-
838
- **If task was blocked:**
839
- ```markdown
840
- ⚠️ 2026-01-12: JWT token refresh - BLOCKED
841
- - Issue: Existing JWT library doesn't support refresh tokens
842
- - Attempted: Custom implementation but hit type conflicts
843
- - Next: Evaluate alternative JWT libraries
411
+ ```bash
412
+ git add .ai/ralphie/index.md STATE.txt
413
+ git commit --amend --no-edit
844
414
  ```
845
415
 
846
- ### 6.6 Update TodoWrite
847
-
848
- Complete all sub-tasks:
416
+ ### 6.8 Complete TodoWrite
849
417
 
850
418
  ```typescript
851
419
  TodoWrite({
852
420
  todos: [
853
- { content: "Write implementation code", activeForm: "Writing code", status: "completed" },
854
- { content: "Write unit tests", activeForm: "Writing tests", status: "completed" },
855
- { content: "Run tests and type check", activeForm: "Running verification", status: "completed" },
856
- { content: "Code review", activeForm: "Reviewing code", status: "completed" },
857
- { content: "Commit changes", activeForm: "Committing", status: "completed" }
421
+ { content: "T003: Complete user validation", status: "completed", activeForm: "Completed" },
422
+ { content: "T004: Add input validation", status: "completed", activeForm: "Completed" },
423
+ { content: "T005: Add error messages", status: "completed", activeForm: "Completed" },
424
+ { content: "Run tests and verify", status: "completed", activeForm: "Completed" },
425
+ { content: "Commit changes", status: "completed", activeForm: "Completed" }
858
426
  ]
859
427
  })
860
428
  ```
861
429
 
862
- **After updating:**
863
- - All sub-tasks should be `completed`
864
- - The TodoWrite list shows the user the iteration is done
865
- - Clear the list for the next iteration (or let the next iteration reset it)
866
-
867
- ### Commit Checklist
868
-
869
- Before considering this iteration complete:
870
-
871
- - [ ] All planned files are staged
872
- - [ ] No unintended files staged (run `git status`)
873
- - [ ] Commit message follows conventional format
874
- - [ ] Commit message uses HEREDOC (no escaping issues)
875
- - [ ] `.ai/ralphie/index.md` has new entry with correct SHA
876
- - [ ] `SPEC.md` task is checked off: `- [x]`
877
- - [ ] `STATE.txt` has completion record
878
- - [ ] TodoWrite sub-tasks marked completed
879
-
880
- ### Commit Flow Example
430
+ ## Status Transitions
881
431
 
882
432
  ```
883
- Tests Pass + Review Approved
884
-
885
-
886
- ┌────────────────────────┐
887
- │ git add [files] │
888
- │ git status (verify) │
889
- └────────────────────────┘
890
-
891
-
892
- ┌────────────────────────┐
893
- │ git commit with │
894
- │ HEREDOC message │
895
- └────────────────────────┘
896
-
897
-
898
- ┌────────────────────────┐
899
- │ Get SHA: git log -1 │
900
- │ Append to index.md │
901
- └────────────────────────┘
902
-
903
-
904
- ┌────────────────────────┐
905
- │ Update SPEC.md │
906
- │ - [ ] → - [x] │
907
- └────────────────────────┘
908
-
909
-
910
- ┌────────────────────────┐
911
- │ Update STATE.txt │
912
- │ ✅ completion record │
913
- └────────────────────────┘
914
-
915
-
916
- ┌────────────────────────┐
917
- │ TodoWrite: all │
918
- │ status: "completed" │
919
- └────────────────────────┘
920
-
921
-
922
- ITERATION DONE
433
+ pending in_progress passed
434
+ → failed
923
435
  ```
924
436
 
925
- ## Hard Rules
437
+ | Transition | When |
438
+ |------------|------|
439
+ | `pending → in_progress` | Starting work on task |
440
+ | `in_progress → passed` | Task complete, Verify passes |
441
+ | `in_progress → failed` | Task blocked, can't complete |
926
442
 
927
- - ONE task per iteration (batched checkbox = one task)
928
- - Plan BEFORE coding
929
- - Tests MUST pass before commit
930
- - No commit = no index entry
931
- - Mark SPEC task complete only after commit
932
-
933
- ## Hooks Configuration
934
-
935
- Ralphie uses a **Stop hook** to validate iteration completion. Configure in `.claude/settings.json`:
936
-
937
- ```json
938
- {
939
- "hooks": {
940
- "Stop": [
941
- {
942
- "type": "prompt",
943
- "promptFile": "scripts/validate-iteration.md"
944
- }
945
- ]
946
- }
947
- }
948
- ```
443
+ **Never skip states** - Always go through `in_progress` first.
949
444
 
950
- **What the hook validates:**
951
- 1. Task implemented (code changes made)
952
- 2. Tests pass (`npm test`)
953
- 3. Type check passes (`npm run type-check`)
954
- 4. Commit made with conventional message
955
- 5. `index.md` updated with new entry
956
- 6. `SPEC.md` task checked off
957
- 7. `STATE.txt` has completion record
445
+ ## Hard Rules
958
446
 
959
- **If validation fails:** Fix the issue before the next iteration starts.
447
+ - **Budget**: Don't exceed 4 points (or configured budget) per iteration
448
+ - **Status**: Update Status field, not checkboxes
449
+ - **Verify**: Run each task's Verify command before marking passed
450
+ - **One iteration**: Complete selected tasks, then stop
451
+ - **No partial**: Either all selected tasks pass, or mark failed ones
452
+
453
+ ## Quick Reference
454
+
455
+ | Step | V2 Action |
456
+ |------|-----------|
457
+ | **1. Load** | Find `specs/active/*.md`, select tasks by budget |
458
+ | **2. Explore** | Use `Task(scout)` for unfamiliar code |
459
+ | **3. Plan** | Write to `.ai/ralphie/plan.md` with task IDs |
460
+ | **4. Implement** | Code + tests, run Verify for each task |
461
+ | **5. Review** | Spawn review agent for significant changes |
462
+ | **6. Commit** | Update Status → update tracking files → commit all together |
463
+
464
+ ## Iteration Validation
465
+
466
+ A valid iteration:
467
+ - [ ] Selected tasks fit within budget
468
+ - [ ] All selected tasks have Status: passed (or failed with notes)
469
+ - [ ] All Verify commands pass
470
+ - [ ] Full test suite passes
471
+ - [ ] Commit includes: code + spec + index.md + STATE.txt + plan.md
472
+ - [ ] No orphaned tracking file changes after commit