jettypod 4.4.0 → 4.4.2

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.
@@ -5,18 +5,14 @@ description: Guide implementation of stable mode chores with comprehensive testi
5
5
 
6
6
  # Stable Mode Skill
7
7
 
8
- ```
9
- ┌─────────────────────────────────────────────────────────────────────┐
10
- │ Mode Progression Flow │
11
- │ │
12
- │ Feature Planning → Speed Mode → [STABLE MODE] → Production Mode │
13
- │ ▲▲▲▲▲▲▲▲▲▲▲▲▲ │
14
- │ YOU ARE HERE │
15
- │ │
16
- │ Next: After stable mode implementation, feature can be marked │
17
- │ complete, or elevated to production mode if needed. │
18
- └─────────────────────────────────────────────────────────────────────┘
19
- ```
8
+ **Mode Progression:**
9
+ Feature Planning → Speed Mode → **[STABLE MODE]** → Done (Internal) OR Production Mode (External)
10
+
11
+ **You are here:** Adding error handling, validation, and edge cases to speed mode implementation.
12
+
13
+ **Next steps:**
14
+ - INTERNAL projects: Feature complete after stable mode (no production mode needed)
15
+ - EXTERNAL projects: Continue to production mode for security/scale/monitoring
20
16
 
21
17
  Guides Claude Code through stable mode implementation with comprehensive testing focus. Users confirm approach but Claude Code writes the code.
22
18
 
@@ -24,13 +20,33 @@ Guides Claude Code through stable mode implementation with comprehensive testing
24
20
 
25
21
  When this skill is activated, you are helping implement a stable mode chore to add comprehensive testing and error handling. Follow this structured approach:
26
22
 
23
+ ## 🔑 Critical Context
24
+
25
+ **You are working in an isolated git worktree:**
26
+ - `work start [chore-id]` created a dedicated worktree for this chore
27
+ - All file operations must use **absolute paths** from the worktree (not relative paths)
28
+ - The worktree has its own branch - changes are isolated from main
29
+ - BDD tests and unit tests run in the worktree context
30
+
31
+ **Worktree path is available in Step 0 output** - use it for all file operations.
32
+
33
+ ---
34
+
27
35
  ### Overview
28
36
 
29
- **Stable Mode Goal:** Transform speed mode's "prove it works" implementation into production-ready code with comprehensive robustness.
37
+ **Stable Mode Goal:** Transform speed mode's "make it work" implementation into robust, reliable code with comprehensive error handling and validation.
30
38
 
31
39
  **CRITICAL DISTINCTION:**
32
- - **Speed mode implemented ALL functionality** - every feature/function is already working on the happy path
33
- - **Stable mode adds COMPLETE robustness** - NOT just error handling, but comprehensive production readiness
40
+ - **Speed mode implemented ALL functionality** - every feature/function is already working (all success scenarios)
41
+ - **Stable mode adds COMPLETE robustness** - error handling, validation, and edge cases
42
+
43
+ **Key Principles:**
44
+ - **Build on speed implementation** - do not re-implement features, ADD robustness to them
45
+ - **Autonomous execution** - Claude Code writes code, user confirms approach
46
+ - **Quality focus** - code should be stable, maintainable, and reliable (ready for internal use)
47
+
48
+ <details>
49
+ <summary><strong>📋 What Stable Mode Includes (click to expand)</strong></summary>
34
50
 
35
51
  **Stable Mode is NOT just error handling. It includes:**
36
52
 
@@ -61,34 +77,72 @@ When this skill is activated, you are helping implement a stable mode chore to a
61
77
  - Handle interrupted operations
62
78
 
63
79
  5. **All BDD Scenarios Pass**
64
- - Happy path (already passing from speed mode)
80
+ - Success scenarios (already passing from speed mode - required + optional features)
65
81
  - Error scenarios (how does it handle failures?)
66
82
  - Edge case scenarios (boundary conditions, unusual inputs)
67
83
  - Concurrent access scenarios (multiple instances)
68
84
 
69
- **Key Principles:**
70
- - **Build on speed implementation** - do not re-implement features, ADD robustness to them
71
- - **Autonomous execution** - Claude Code writes code, user confirms approach
72
- - **Quality focus** - code should be stable, maintainable, and production-ready
85
+ </details>
73
86
 
74
87
  **User Profile:** May not know how to code - Claude Code does the implementation autonomously.
75
88
 
76
89
  ---
77
90
 
91
+ ## 🧪 Unit Testing in Stable Mode - True TDD
92
+
93
+ **Unit tests are written DURING implementation, not after.**
94
+
95
+ **The TDD workflow (each iteration):**
96
+ 1. **Identify next failing BDD step** - Which error/edge case scenario step needs to pass?
97
+ 2. **Write unit test for the validation/error handling** - Test the specific error condition
98
+ 3. **Watch unit test fail (RED)** - Confirm test catches the missing validation
99
+ 4. **Write minimal code** - Add error handling, validation, or edge case handling
100
+ 5. **Run unit test (GREEN)** - Verify the validation/error handling works in isolation
101
+ 6. **Run BDD scenarios** - Check if this makes any error/edge case BDD steps pass
102
+ 7. **Next iteration** - Repeat for next failing step
103
+
104
+ **What to unit test in stable mode:**
105
+ - Validation functions (null checks, type checks, range validation)
106
+ - Error handling logic (catch blocks, error recovery)
107
+ - Edge case handling (empty arrays, boundary values)
108
+ - State consistency (transaction rollback, cleanup on failure)
109
+
110
+ **Unit test scope in stable mode:**
111
+ ```javascript
112
+ // ✅ Stable mode unit tests (error paths and edge cases)
113
+ test('createUser throws ValidationError for null email', () => {
114
+ expect(() => createUser('John', null)).toThrow(ValidationError);
115
+ expect(() => createUser('John', null)).toThrow('Email is required');
116
+ });
117
+
118
+ test('createUser handles empty string email', () => {
119
+ expect(() => createUser('John', '')).toThrow(ValidationError);
120
+ });
121
+
122
+ test('getUserById returns null for non-existent user', () => {
123
+ const user = getUserById(99999);
124
+ expect(user).toBeNull();
125
+ });
126
+ ```
127
+
128
+ ---
129
+
78
130
  ## Quick Reference: Async Boundaries
79
131
 
80
132
  **Where Claude Code MUST wait for user confirmation:**
81
133
 
82
- | Phase | Location | Why |
83
- |-------|----------|-----|
84
- | Step 3 Phase 1 | Before implementing | User confirms implementation approach |
134
+ | Phase | Location | Why | Condition |
135
+ |-------|----------|-----|-----------|
136
+ | Step 3A | Before implementing (conditional) | User confirms implementation approach | Only if approach is ambiguous or multiple valid paths |
85
137
 
86
138
  **Where Claude Code executes autonomously:**
87
- - Step 0: Create additional scenarios (if first stable chore)
139
+ - Step 0: Initialize context
88
140
  - Step 1: Scenario analysis
89
141
  - Step 2: Speed mode implementation review
90
- - Step 3 Phase 2: Autonomous execution loop
91
- - Step 4: Completion check and routing
142
+ - Step 3: Decision to skip/ask for confirmation
143
+ - Step 4: Establish RED baseline
144
+ - Step 5: RED→GREEN→REFACTOR loop (true TDD)
145
+ - Step 6: Check progress and route to next chore or completion
92
146
 
93
147
  ---
94
148
 
@@ -105,7 +159,7 @@ For external products accepting real users, stable mode is NOT the final step. P
105
159
  **Required workflow for EXTERNAL products after stable mode implementation:**
106
160
 
107
161
  1. ✅ **Complete ALL stable mode chores** - Add error handling and edge cases
108
- 2. ✅ **Generate production mode chores** - Use `jettypod work elevate <feature-id> production`
162
+ 2. ✅ **Set feature to production mode** - Use `jettypod work set-mode <feature-id> production`
109
163
  3. ✅ **Implement production mode chores** - Add performance, security, monitoring
110
164
  4. ❌ **NEVER mark feature complete in stable mode for external products** - This bypasses critical production hardening
111
165
 
@@ -114,8 +168,8 @@ For external products accepting real users, stable mode is NOT the final step. P
114
168
  **If you attempt to mark an external product feature complete while in stable mode, the system will block you with an error.**
115
169
 
116
170
  The validation will require you to either:
117
- - Generate production mode chores: `jettypod work elevate <feature-id> production`
118
- - Or explicitly skip (not recommended): `jettypod work set-mode <feature-id> production --force`
171
+ - Set feature to production mode: `jettypod work set-mode <feature-id> production`
172
+ - Or explicitly force skip (not recommended): `jettypod work set-mode <feature-id> production --force`
119
173
 
120
174
  **Remember:** Stable mode makes it robust. Production mode makes it ready for real users at scale.
121
175
 
@@ -123,48 +177,34 @@ The validation will require you to either:
123
177
 
124
178
  ## Implementation Steps
125
179
 
126
- <!-- ═══════════════════════════════════════════════════════════════════════════
127
- PHASE 1: AUTONOMOUS SETUP
128
- No user input required - Claude Code executes independently
129
- ═══════════════════════════════════════════════════════════════════════════ -->
180
+ ### Step 0: Initialize Stable Mode Context
130
181
 
131
- ### Step 0: Create Additional Scenarios (If First Stable Chore)
182
+ **You are now in stable mode,** implementing a chore to add error handling and edge case coverage.
132
183
 
133
- **CRITICAL:** If this is the FIRST stable mode chore for this feature, you must ADD edge case scenarios and step definitions.
184
+ **Get the current work context:**
134
185
 
135
- **Check if scenarios exist beyond happy path:**
136
- 1. Read the feature's `.feature` file
137
- 2. Count scenarios - if only 1 (happy path), ADD edge case scenarios
138
- 3. Update step definitions to include new scenarios
186
+ ```bash
187
+ sqlite3 .jettypod/work.db "SELECT wi.id, wi.title, wi.parent_id, parent.title as parent_title, parent.scenario_file, wt.worktree_path, wt.branch_name FROM work_items wi LEFT JOIN work_items parent ON wi.parent_id = parent.id LEFT JOIN worktrees wt ON wi.id = wt.work_item_id WHERE wi.status = 'in_progress' AND wi.type = 'chore'"
188
+ ```
139
189
 
140
- **Add to `.feature` file:**
141
- ```gherkin
142
- # Error handling scenario
143
- Scenario: [Error case title]
144
- Given [setup for error condition]
145
- When [action that triggers error]
146
- Then [expected error handling]
147
- And [system remains stable]
190
+ **Display to user:**
148
191
 
149
- # Edge case scenario
150
- Scenario: [Edge case title]
151
- Given [edge condition setup]
152
- When [action at boundary]
153
- Then [expected edge case behavior]
154
192
  ```
193
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
194
+ 🛡️ STABLE MODE: Implementing Chore #[id]
195
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
155
196
 
156
- **Add to `features/step_definitions/[feature-slug].steps.js`:**
157
- - Implement Given/When/Then steps for new scenarios
158
- - Follow existing patterns from happy path steps
159
- - Include proper error assertions
197
+ Chore: [title]
198
+ Feature: #[parent-id] [parent-title]
199
+ Worktree: [worktree_path]
200
+ Branch: [branch_name]
201
+
202
+ Analyzing stable mode BDD scenarios to determine what error handling and validation to add...
203
+ ```
160
204
 
161
- **Update unit tests with edge cases:**
162
- - Speed mode generated basic unit tests with TODO placeholders
163
- - Stable mode should fill in edge case tests for error handling
164
- - Add tests for: null/undefined inputs, invalid data, boundary conditions
165
- - Use existing test files at `test/[path]/[file].test.js`
205
+ **Then proceed to Step 1.**
166
206
 
167
- **IMPORTANT:** Only do this ONCE per feature (first stable chore). Subsequent stable chores implement existing scenarios.
207
+ ---
168
208
 
169
209
  ### Step 1: Analyze Scenario to Implement
170
210
 
@@ -172,21 +212,18 @@ Scenario: [Edge case title]
172
212
 
173
213
  **Your task:**
174
214
  1. Get current work item and parent feature's scenario file
175
- 2. Read the full scenario file (should now have happy path + edge cases)
215
+ 2. Read the full scenario file (should have success scenarios + stable mode error/edge case scenarios)
176
216
  3. Identify which scenario this chore addresses
177
217
  4. Extract requirements from the scenario's Given/When/Then steps
218
+ 5. Check chore description for breadcrumbs (implementation guidance from feature-planning)
219
+
220
+ **NOTE:** Scenarios and step definitions already exist, created by the speed-mode skill during transition to stable mode. Chore descriptions may contain breadcrumbs with implementation guidance (files to modify, patterns to follow, functions to add validation to).
178
221
 
179
222
  **To get scenario information, use these commands:**
180
223
 
181
224
  ```bash
182
- # Get current work (chore) and its parent feature
183
- jettypod work current
184
-
185
- # Get parent feature details including scenario_file
186
- jettypod work show <parent-feature-id>
187
-
188
- # Or query database directly for scenario file
189
- sqlite3 .jettypod/work.db "SELECT id, title, scenario_file, mode FROM work_items WHERE id = <parent-feature-id>"
225
+ # Get current work (chore) and its parent feature with scenario_file
226
+ sqlite3 .jettypod/work.db "SELECT wi.id, wi.title, wi.description, wi.parent_id, parent.title as parent_title, parent.scenario_file, parent.mode FROM work_items wi LEFT JOIN work_items parent ON wi.parent_id = parent.id WHERE wi.status = 'in_progress'"
190
227
  ```
191
228
 
192
229
  **Then read the scenario file** using the Read tool on the path returned by `scenario_file`.
@@ -223,6 +260,12 @@ What needs to happen:
223
260
  • [When] Action/condition: [requirement]
224
261
  • [Then] Expected behavior: [requirement]
225
262
 
263
+ [If breadcrumbs exist in chore description:]
264
+ Implementation guidance:
265
+ • Files: [files to modify]
266
+ • Patterns: [patterns to follow]
267
+ • Functions: [specific functions to add validation to]
268
+
226
269
  Now reviewing speed mode implementation...
227
270
  ```
228
271
 
@@ -266,7 +309,7 @@ Then use the Read tool to examine the implementation files.
266
309
 
267
310
  Current Implementation:
268
311
  • Files: [list]
269
- Happy path: ✅ Working
312
+ Success scenarios: ✅ Working (from speed mode)
270
313
  • Error handling: ❌ Missing [specific gaps]
271
314
  • Validation: ❌ Missing [specific gaps]
272
315
  • Edge cases: ❌ Not handled [specific gaps]
@@ -279,392 +322,286 @@ To pass the target scenario, I need to:
279
322
  Now proposing comprehensive implementation...
280
323
  ```
281
324
 
282
- **Move to Step 3 automatically.**
325
+ ### Step 3: Decide if Confirmation Needed
326
+
327
+ **Evaluate if you need user confirmation before implementing:**
328
+
329
+ **Skip confirmation (proceed directly to Step 4) if:**
330
+ - Chore description is comprehensive (specific validation/error handling described)
331
+ - Implementation approach is clear and unambiguous
332
+ - Only one reasonable way to add the error handling
333
+ - Similar patterns exist in codebase to follow
334
+
335
+ **Ask for confirmation (Step 3A) if:**
336
+ - Multiple valid error handling approaches exist
337
+ - Chore description is vague about specific validation
338
+ - Architectural choice impacts other features
339
+ - You're uncertain about the right approach
283
340
 
284
- <!-- ═══════════════════════════════════════════════════════════════════════════
285
- PHASE 2: USER CONFIRMATION REQUIRED
286
- ⚡ ASYNC BOUNDARY - Must wait for user response before proceeding
287
- ═══════════════════════════════════════════════════════════════════════════ -->
341
+ ### Step 3A: Propose Implementation Approach (Conditional)
288
342
 
289
- ### Step 3: Propose and Execute Comprehensive Implementation
343
+ **⚡ ASYNC BOUNDARY - Only execute this if confirmation needed**
290
344
 
291
- **Two phases: Propose (get user confirmation) Execute (autonomous)**
345
+ **Present your analysis and proposal to the user:**
292
346
 
293
- #### Phase 1: Propose Comprehensive Implementation
347
+ ```
348
+ 💡 Implementation Proposal
349
+
350
+ I see multiple ways to approach this error handling. Here's what I'm thinking:
294
351
 
295
- **Present your analysis and proposal:**
352
+ **Option I'm recommending:**
353
+ • Error handling strategy: [specific approach]
354
+ • Validation approach: [what to validate and how]
355
+ • Why: [rationale - why this over alternatives]
356
+
357
+ **Alternative considered:**
358
+ • [Brief description] - not choosing because [reason]
296
359
 
297
360
  ```
298
- 💡 Comprehensive Implementation Proposal
299
361
 
300
- Based on scenario and code analysis, here's how I'll add proper error handling and make the scenario pass:
362
+ **⚡ WAIT for user confirmation or adjustments.**
301
363
 
302
- **Changes needed:**
303
- 1. [File]: Add [specific error handling/validation]
304
- 2. [File]: Add [specific edge case handling]
305
- 3. [File]: Add [specific tests]
364
+ If user adjusts: revise proposal and confirm again before proceeding.
306
365
 
307
- **Error handling approach:**
308
- • [Specific errors to catch and how to handle them]
309
- • [User-friendly error messages]
310
- • [Graceful failure behavior]
366
+ **If you skipped this step:** Proceed directly to Step 4.
311
367
 
312
- **Validation approach:**
313
- • [Input validation checks]
314
- • [Boundary condition handling]
315
- • [State validation]
368
+ ---
316
369
 
317
- **Why this approach:**
318
- [Brief explanation of how this satisfies the scenario with proper quality]
370
+ ### Step 4: Establish RED Baseline
319
371
 
320
- Sound good? I'll implement this autonomously once you confirm.
372
+ **CRITICAL:** After user confirms (or skips confirmation), execute autonomously - no permission needed for code changes.
373
+
374
+ Before writing any implementation code, run tests to establish the RED state:
375
+
376
+ ```bash
377
+ # Get current work and parent feature's scenario file
378
+ sqlite3 .jettypod/work.db "SELECT wi.id, wi.parent_id, parent.scenario_file FROM work_items wi LEFT JOIN work_items parent ON wi.parent_id = parent.id WHERE wi.status = 'in_progress'"
379
+ # This gives you the chore ID, parent feature ID, and path to the .feature file
380
+
381
+ # Run BDD tests to establish RED baseline
382
+ npx cucumber-js <scenario-file-path> --format progress
321
383
  ```
322
384
 
323
- **WAIT for user confirmation or adjustments.**
385
+ Parse the output to identify:
386
+ - Total steps and how many are failing
387
+ - Which specific stable mode steps are failing (error/edge case scenarios)
388
+ - The first error message
324
389
 
325
- If user adjusts: revise proposal and confirm again.
390
+ This establishes your RED baseline - stable mode scenarios should be failing initially.
326
391
 
327
- <!-- ═══════════════════════════════════════════════════════════════════════════
328
- PHASE 3: AUTONOMOUS EXECUTION
329
- User has confirmed - Claude Code executes iteration loop independently
330
- ═══════════════════════════════════════════════════════════════════════════ -->
392
+ **Display RED baseline:**
393
+ ```
394
+ 🔴 Establishing RED baseline...
331
395
 
332
- #### Phase 2: Autonomous Execution
396
+ RED Baseline: 3 of 11 steps failing (stable mode scenarios)
333
397
 
334
- **CRITICAL:** After user confirms, Claude Code executes autonomously - no permission needed for individual code changes.
398
+ Failing steps:
399
+ ✖ Then it should throw a validation error
400
+ ✖ And the error message should be "Email is required"
401
+ ✖ When I provide an empty string as input
335
402
 
336
- **Execution loop (with iteration limits and error handling):**
403
+ First error:
404
+ Step: Then it should throw a validation error
405
+ Error: Error: Expected function to throw but it didn't
337
406
 
338
- <!-- ┌─────────────────────────────────────────────────────────────────────────┐
339
- │ 🔄 ITERATION LOOP: Stable Mode Scenario │
340
- │ │
341
- │ Progress Tracking: │
342
- │ • Display: "Iteration X/10" at start of each cycle │
343
- │ • Track: scenarios passing, steps passing, newly passing │
344
- │ • Goal: Target scenario + all scenarios pass │
345
- │ │
346
- │ Return Points: │
347
- │ • CHECKPOINT_ITERATION: Resume at specific iteration number │
348
- │ • CHECKPOINT_SCENARIO: Resume with known scenario status │
349
- │ • If session interrupted, can resume from last known iteration │
350
- └─────────────────────────────────────────────────────────────────────────┘ -->
407
+ 🎯 Goal: Make all stable mode scenarios pass
351
408
 
352
- ```javascript
353
- // --- Imports ---
354
- const {
355
- MAX_ITERATIONS, TEST_TIMEOUT, runBddTestWithTimeout,
356
- runBddScenarioWithTimeout, getScenarioLineByName,
357
- parseTestProgress, extractErrors, findNewlyPassingSteps
358
- } = require('../../.claude/skills/speed-mode/test-runner');
359
-
360
- // --- Find scenario line number ---
361
- const scenarioLine = getScenarioLineByName(feature.scenario_file, targetScenario.title);
362
- if (!scenarioLine) {
363
- console.error('❌ Cannot find scenario line number for:', targetScenario.title);
364
- return;
365
- }
366
-
367
- let iteration = 0;
368
- let scenarioPasses = false;
369
- let previousResult = null;
370
-
371
- // --- Main iteration loop ---
372
- // 📊 PROGRESS: Iteration {iteration}/{MAX_ITERATIONS} | Scenario: {scenarioPasses ? 'PASS' : 'FAIL'}
373
- while (!scenarioPasses && iteration < MAX_ITERATIONS) {
374
- iteration++;
375
- console.log(`\n🔄 Iteration ${iteration}/${MAX_ITERATIONS}`);
376
-
377
- // --- Make code changes ---
378
- try {
379
- console.log('✍️ Adding error handling to [file]...');
380
- // ... use Edit tool ...
381
- console.log('✅ Updated [file]');
382
- } catch (editErr) {
383
- console.error('❌ Error modifying files:', editErr.message);
384
- continue;
385
- }
386
-
387
- // --- Run tests ---
388
- console.log('🧪 Running tests...');
389
- const result = await runBddScenarioWithTimeout(feature.scenario_file, scenarioLine, TEST_TIMEOUT);
390
-
391
- // --- Handle timeout ---
392
- if (result.timedOut) {
393
- console.error('❌ Tests timed out after 60 seconds');
394
- console.log('Suggestion: Check for blocking operations or missing async/await');
395
- break;
396
- }
397
-
398
- // --- Parse and track progress ---
399
- const currentResult = parseTestProgress(result.stdout);
400
- const newlyPassing = findNewlyPassingSteps(previousResult, currentResult);
401
-
402
- console.log(`\n📊 Progress: ${currentResult.passed}/${currentResult.total} steps passing`);
403
-
404
- if (newlyPassing.length > 0) {
405
- console.log(`\n✅ Newly passing:`);
406
- newlyPassing.forEach(step => console.log(` • ${step}`));
407
- }
408
-
409
- // --- Check for success ---
410
- if (currentResult.passed === currentResult.total && currentResult.total > 0) {
411
- console.log('\n✅ Target scenario passing!');
412
-
413
- // --- Run full verification ---
414
- console.log('\n🔍 Running full verification (all scenarios)...');
415
- const fullResult = await runBddTestWithTimeout(feature.scenario_file, TEST_TIMEOUT);
416
-
417
- if (fullResult.timedOut) {
418
- console.log('⚠️ Full verification timed out');
419
- } else if (fullResult.exitCode !== 0) {
420
- const fullProgress = parseTestProgress(fullResult.stdout + fullResult.stderr);
421
- console.log(`⚠️ Regressions found: ${fullProgress.total - fullProgress.passed} scenarios failing`);
422
- scenarioPasses = false;
423
- } else {
424
- console.log('✅ Full verification passed!');
425
- scenarioPasses = true;
426
- }
427
- } else {
428
- // --- Display errors ---
429
- console.log(`\n❌ ${currentResult.total - currentResult.passed} scenarios still failing`);
430
- const errors = extractErrors(result.stdout + result.stderr);
431
- if (errors.errors.length > 0) {
432
- console.log('\n🔧 Next failure to address:');
433
- console.log(` Step: ${errors.errors[0].step}`);
434
- console.log(` Error: ${errors.errors[0].message}`);
435
- }
436
- }
437
-
438
- previousResult = currentResult;
439
- }
440
-
441
- // --- Handle max iterations reached ---
442
- if (!scenarioPasses && iteration >= MAX_ITERATIONS) {
443
- console.error('\n❌ Maximum iterations reached without passing scenario');
444
- console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
445
- console.log('🛑 Unable to make scenario pass automatically');
446
- console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
447
- console.log('\nPossible reasons:');
448
- console.log('• Scenario requirements may need clarification');
449
- console.log('• Implementation approach may need rethinking');
450
- console.log('• External dependencies may be missing');
451
- console.log('\nHow would you like to proceed?');
452
- console.log(' 1. Review changes made so far');
453
- console.log(' 2. Try a different approach');
454
- console.log(' 3. Debug manually');
455
- return;
456
- }
457
- ```
458
-
459
- **Display progress:**
460
- ```
461
- 🔄 Iteration 1/10
462
-
463
- ✍️ Adding error handling to [file]...
464
- ✅ Updated [file]
465
-
466
- 🧪 Running tests...
467
- ✅ Target scenario passes!
468
- ✅ All scenarios still passing!
469
- ```
470
-
471
- **Stable mode focus:**
472
- - **Add to existing implementation** - speed mode already implemented all features
473
- - **Comprehensive error handling** - wrap existing code with try/catch, handle failures gracefully
474
- - **Input validation** - add checks before existing logic (null checks, type checks, range validation)
475
- - **Edge case handling** - handle empty arrays, missing properties, boundary values, concurrent access
476
- - **Clear error messages** - user-friendly, actionable feedback for all failure modes
477
- - **All BDD scenarios pass** - happy path (already passing from speed) AND error/edge scenarios
478
-
479
- **When all scenarios pass:**
480
-
481
- ```
482
- 🎉 Stable mode scenario passes!
483
-
484
- Implementation complete:
485
- • Modified: [list files]
486
- • Error handling: ✅ Comprehensive
487
- • Validation: ✅ Complete
488
- • All scenarios: ✅ Passing
489
- ```
490
-
491
- **Run unit test coverage (if configured):**
492
- ```bash
493
- # If project has coverage configured, run it:
494
- npm run test:coverage
495
- # Or with Jest:
496
- npx jest --coverage
409
+ Now implementing...
497
410
  ```
498
411
 
499
- Note: Coverage tracking is project-specific. Check your package.json for the appropriate coverage command.
412
+ ---
413
+
414
+ ### Step 5: RED→GREEN→REFACTOR Loop
415
+
416
+ **Execute autonomously** - iterate until tests pass (max 10 iterations).
417
+
418
+ **Each iteration (True TDD):**
419
+
420
+ 1. **Identify next failing BDD step** - Which error/edge case scenario step to tackle?
421
+ 2. **Write unit test** - Test the validation/error handling needed (watch it fail - RED)
422
+ 3. **Write minimal implementation** - Add error handling, validation, or edge case code
423
+ 4. **Run unit test** - Verify it passes (GREEN)
424
+ 5. **Run BDD scenarios** - Check if BDD step now passes
425
+ 6. **Display progress** - Show what's passing, what's next
426
+ 7. **Continue or exit** - If all BDD scenarios pass → REFACTOR. Otherwise, repeat.
427
+
428
+ **Show progress each iteration:**
429
+ ```
430
+ ━━━ Iteration 3/10 ━━━
431
+ 📝 Unit test: test/user.test.js - validates email format
432
+ RED: Test fails - no validation exists yet
433
+ ✍️ Implementation: src/user.js - added email format validation
434
+ GREEN: Unit test passes
435
+ 🧪 Running BDD scenarios...
436
+ 📊 Progress: 9/11 BDD steps passing
437
+ ✅ Newly passing: Then it should throw a validation error
438
+ 🔧 Next failure: And the error message should be user-friendly
439
+ BDD step: Then the error message should be "Email format is invalid"
440
+ ```
500
441
 
501
- **Display coverage summary:**
442
+ **When GREEN achieved:**
502
443
  ```
503
- 📊 Unit Test Coverage Report
504
- ─────────────────────────────
505
- Statements: ✅ 85.23%
506
- Branches: ✅ 82.15%
507
- Functions: ✅ 88.50%
508
- Lines: ✅ 84.90%
509
- ─────────────────────────────
510
- ✅ All coverage metrics meet 80% threshold
444
+ 🎉 GREEN: All stable mode scenarios passing!
511
445
  ```
512
446
 
513
- <!-- ═══════════════════════════════════════════════════════════════════════════
514
- PHASE 4: COMPLETION AND ROUTING
515
- Conditional phase - route based on project state (internal vs external)
516
- ═══════════════════════════════════════════════════════════════════════════ -->
447
+ **Then REFACTOR (quick pass, 5 min max):**
448
+ - Extract duplicated validation logic
449
+ - Rename unclear error variables
450
+ - Simplify complex error handling
451
+ - Remove dead code
517
452
 
518
- ### Step 4: Check for Production Mode (When All Stable Chores Complete)
453
+ **Re-run tests after refactor** to ensure nothing broke.
519
454
 
520
- **CRITICAL: This step ONLY happens when ALL stable chores for the feature are complete. Otherwise skip to marking chore as done.**
455
+ <details>
456
+ <summary><strong>📋 TDD Loop Guidelines (click to expand)</strong></summary>
521
457
 
522
- <!-- ┌─────────────────────────────────────────────────────────────────────────┐
523
- 🔍 COMPLETION CHECK: Stable Chores │
524
- │ │
525
- Progress Tracking: │
526
- Query: Count incomplete chores for feature │
527
- │ • Display: "X chores remaining" or "All complete" │
528
- │ • Action: Route based on project state (internal vs external) │
529
- │ │
530
- │ Return Point: │
531
- │ • CHECKPOINT_CHORE_COUNT: Known incomplete count from last check │
532
- │ • CHECKPOINT_PROJECT_STATE: Known project state for routing │
533
- │ • If session interrupted, re-query to get current counts │
534
- └─────────────────────────────────────────────────────────────────────────┘ -->
458
+ **Iteration strategy:**
459
+ - Start with first failing stable mode step
460
+ - Make minimal change to pass that step
461
+ - Run tests immediately
462
+ - Move to next failure
535
463
 
536
- **Check completion status and project state:**
464
+ **If stuck after 5 iterations:**
465
+ - Review approach - is there a simpler validation?
466
+ - Check assumptions - are you handling the right error?
467
+ - Break down the change - can you add validation incrementally?
468
+
469
+ **Max 10 iterations:**
470
+ - If you hit max without GREEN, stop
471
+ - Display final progress and suggest next steps
472
+ - Consider breaking chore into smaller pieces
473
+
474
+ </details>
475
+
476
+ ---
477
+
478
+ **CRITICAL: Check if ALL stable mode chores are complete. Route to next chore if any remain.**
479
+
480
+ **Check for incomplete stable chores:**
537
481
 
538
482
  ```bash
539
483
  # Get current work to find parent feature ID
540
- jettypod work current
484
+ sqlite3 .jettypod/work.db "SELECT wi.parent_id FROM work_items wi WHERE wi.status = 'in_progress'"
541
485
 
542
- # Count incomplete chores for the feature
543
- sqlite3 .jettypod/work.db "SELECT COUNT(*) FROM work_items WHERE parent_id = <feature-id> AND type = 'chore' AND status NOT IN ('done', 'cancelled')"
486
+ # Get list of remaining stable chores (excluding current chore)
487
+ sqlite3 .jettypod/work.db "SELECT id, title FROM work_items WHERE parent_id = <feature-id> AND type = 'chore' AND mode = 'stable' AND status != 'done' AND id != <current-chore-id> ORDER BY created_at LIMIT 1"
488
+ ```
489
+
490
+ **If stable chores remain, display and start next chore:**
544
491
 
545
- # Check project state
546
- sqlite3 .jettypod/work.db "SELECT project_state FROM project_config WHERE id = 1"
547
492
  ```
493
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
494
+ 🎯 Stable Mode Chore Complete
495
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
496
+
497
+ ✅ Error handling and validation scenarios pass for this chore
548
498
 
549
- Based on the results:
550
- - If incomplete_count > 0: More stable chores remain
551
- - If incomplete_count = 0 AND project_state = 'internal': Feature is complete
552
- - If incomplete_count = 0 AND project_state = 'external': Need to generate production chores
499
+ More stable mode chores remain. Starting next chore:
500
+ #[next-chore-id]: [next-chore-title]
501
+ ```
553
502
 
554
- **CRITICAL: Check project state to determine next step:**
503
+ **Then immediately merge current chore and start next:**
555
504
 
556
- Check if project is internal or external:
557
505
  ```bash
558
- # Check project_state in database
559
- node jettypod.js work show 1 | grep "Project state:"
560
- # OR read CLAUDE.md <project_state> tag
506
+ # Commit changes in the worktree
507
+ git add . && git commit -m "feat: [brief description of error handling added]"
508
+
509
+ # Merge current chore - this automatically marks it as done
510
+ jettypod work merge
511
+
512
+ # Start next stable chore
513
+ jettypod work start [next-chore-id]
561
514
  ```
562
515
 
516
+ **CRITICAL: Use ONLY `jettypod work merge` to complete chores.**
517
+ - ❌ DO NOT use `jettypod work status <id> done`
518
+ - ❌ DO NOT use `jettypod work complete <id>`
519
+ - ❌ DO NOT use `jettypod work set-mode <id> done`
520
+ - ✅ ONLY use `jettypod work merge`
521
+
522
+ The merge command handles everything: pushes branch, merges to main, marks chore done, cleans up worktree.
523
+
524
+ The stable-mode skill will automatically re-invoke for the next chore.
525
+
526
+ **If all stable chores are done (count = 0), continue to Step 6 below.**
527
+
563
528
  ---
564
529
 
565
- ### Option A: Project is INTERNAL
530
+ ### Step 6: Route to Completion (After All Stable Chores Complete)
566
531
 
567
- **For internal projects, stable mode is the FINAL state.**
532
+ **CRITICAL: This step ONLY happens when ALL stable chores for the feature are complete.**
533
+
534
+ **Check project state:**
568
535
 
569
- **ACTION REQUIRED:** Mark the feature as done:
570
536
  ```bash
571
- node jettypod.js work status [feature-id] done
537
+ # Check project_state in database (RECOMMENDED - always up to date)
538
+ sqlite3 .jettypod/work.db "SELECT project_state FROM project_config WHERE id = 1"
539
+
540
+ # OR read CLAUDE.md from git root (NOT from CWD - worktrees may have stale copies)
541
+ grep -A1 "<project_state>" "$(git rev-parse --show-toplevel)/CLAUDE.md" | tail -1
572
542
  ```
573
543
 
574
- Then display to user:
544
+ ⚠️ **CRITICAL:** If reading CLAUDE.md, always read from git root using `$(git rev-parse --show-toplevel)/CLAUDE.md`, NOT from current directory. Worktrees branch from main and may have stale project_state values.
575
545
 
546
+ **Route based on project state:**
547
+
548
+ **If project_state = 'internal':**
549
+
550
+ Mark the feature as done:
551
+ ```bash
552
+ node jettypod.js work status [feature-id] done
553
+ ```
554
+
555
+ Display:
576
556
  ```
577
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
578
557
  ✅ FEATURE #[id] COMPLETE!
579
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
580
558
 
581
559
  Feature: [Feature Title]
582
560
  Status: ✅ DONE
583
561
 
584
562
  What we accomplished:
585
- ✅ All BDD scenarios passing (happy path + error handling + edge cases)
563
+ ✅ All BDD scenarios passing (success + error handling + edge cases)
586
564
  ✅ Comprehensive error handling and validation
587
565
  ✅ Input validation and edge case coverage
588
566
  ✅ State consistency and data integrity
589
- ✅ All code merged to main and pushed to GitHub
590
567
 
591
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
592
568
  📝 INTERNAL PROJECT - STABLE MODE IS COMPLETE
593
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
594
569
 
595
570
  This is an internal project - stable mode is the end state.
596
- No production hardening needed.
597
-
598
571
  Feature is complete and ready to use!
599
572
 
600
- Note: If you later transition to external state (accepting real users),
601
- you can run the external-transition skill to generate production chores.
602
-
603
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
573
+ Note: If you later transition to external (accepting real users),
574
+ run the external-transition skill to generate production chores.
604
575
  ```
605
576
 
606
- **End skill.** The feature is DONE.
577
+ **End skill.** Feature is DONE.
607
578
 
608
579
  ---
609
580
 
610
- ### Option B: Project is EXTERNAL
611
-
612
- **For external projects, continue to production mode.**
613
-
614
- Use the Skill tool to invoke the production-mode skill:
581
+ **If project_state = 'external':**
615
582
 
616
- ```javascript
617
- // Use Skill tool to invoke: production-mode
618
- // The production-mode skill will:
619
- // 1. Detect feature context (Scenario A/B/C)
620
- // 2. Generate production scenarios from standards
621
- // 3. Append scenarios to feature file
622
- // 4. Create production chores
623
- ```
624
-
625
- Display to user:
583
+ Use Skill tool to invoke production-mode:
626
584
 
585
+ Display:
627
586
  ```
628
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
629
587
  ✅ ALL STABLE MODE CHORES COMPLETE!
630
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
631
588
 
632
589
  What we accomplished:
633
- ✅ All BDD scenarios passing (happy path + error handling + edge cases)
590
+ ✅ All BDD scenarios passing (success + error handling + edge cases)
634
591
  ✅ Comprehensive error handling and validation
635
592
  ✅ Feature stable and ready for production hardening
636
593
 
637
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
638
594
  🚀 AUTO-GENERATING PRODUCTION CHORES
639
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
640
595
 
641
596
  This project is external - invoking production-mode skill to:
642
597
  • Detect feature context (authentication/data/general)
643
598
  • Generate production scenarios from standards
644
599
  • Create production chores with proper scope
645
-
646
- [Invoke production-mode skill - it handles the rest autonomously]
647
600
  ```
648
601
 
649
- **If stable chores remain:**
602
+ Then invoke production-mode skill. **End skill.**
650
603
 
651
- ```
652
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
653
- 🎯 Stable Mode Chore Complete!
654
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
655
-
656
- What we accomplished:
657
- ✅ Scenario passes with proper error handling
658
- ✅ Input validation added
659
- ✅ Edge cases handled
660
-
661
- Remaining stable mode chores: [count]
662
-
663
- **Next step:** Continue with next stable mode chore
664
- jettypod work start [next-stable-chore-id]
665
- ```
666
-
667
- **Mark current chore as done:**
604
+ ---
668
605
 
669
606
  ⚠️ **CRITICAL: Exclude CLAUDE.md from commits in worktrees**
670
607
 
@@ -682,6 +619,17 @@ Then use the merge command to merge to main (which auto-marks chore as done via
682
619
  jettypod work merge
683
620
  ```
684
621
 
622
+ <details>
623
+ <summary>💡 Multi-instance coordination (click to expand)</summary>
624
+
625
+ The merge command uses a merge lock to prevent conflicts when multiple instances complete work simultaneously:
626
+ - First instance acquires lock → merges → releases lock
627
+ - Second instance waits → then acquires lock → merges
628
+ - No manual coordination needed - happens automatically
629
+
630
+ If you see "Acquiring merge lock..." message, another instance is merging. Wait 30-60 seconds.
631
+ </details>
632
+
685
633
  The post-merge hook will automatically mark the chore as done when merged to main.
686
634
 
687
635
  ---
@@ -713,15 +661,15 @@ After completing EACH stable chore:
713
661
  **Example correct flow:**
714
662
  ```bash
715
663
  # Complete chore #1854
716
- git add . && git commit && git push
717
- jettypod work merge
664
+ git add . && git commit -m "feat: [description]"
665
+ jettypod work merge # Automatically pushes, merges, and cleans up
718
666
 
719
667
  # NOW start chore #1855 (main has #1854's changes)
720
668
  jettypod work start 1855
721
669
 
722
670
  # Complete chore #1855
723
- git add . && git commit && git push
724
- jettypod work merge
671
+ git add . && git commit -m "feat: [description]"
672
+ jettypod work merge # Automatically pushes, merges, and cleans up
725
673
 
726
674
  # NOW start chore #1856 (main has #1854 + #1855's changes)
727
675
  jettypod work start 1856