jettypod 4.3.0 → 4.4.1

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,14 +5,18 @@ description: Guide implementation of stable mode chores with comprehensive testi
5
5
 
6
6
  # Stable Mode Skill
7
7
 
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
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
+ ```
16
20
 
17
21
  Guides Claude Code through stable mode implementation with comprehensive testing focus. Users confirm approach but Claude Code writes the code.
18
22
 
@@ -20,33 +24,13 @@ Guides Claude Code through stable mode implementation with comprehensive testing
20
24
 
21
25
  When this skill is activated, you are helping implement a stable mode chore to add comprehensive testing and error handling. Follow this structured approach:
22
26
 
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
-
35
27
  ### Overview
36
28
 
37
- **Stable Mode Goal:** Transform speed mode's "make it work" implementation into robust, reliable code with comprehensive error handling and validation.
29
+ **Stable Mode Goal:** Transform speed mode's "prove it works" implementation into production-ready code with comprehensive robustness.
38
30
 
39
31
  **CRITICAL DISTINCTION:**
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>
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
50
34
 
51
35
  **Stable Mode is NOT just error handling. It includes:**
52
36
 
@@ -77,72 +61,34 @@ When this skill is activated, you are helping implement a stable mode chore to a
77
61
  - Handle interrupted operations
78
62
 
79
63
  5. **All BDD Scenarios Pass**
80
- - Success scenarios (already passing from speed mode - required + optional features)
64
+ - Happy path (already passing from speed mode)
81
65
  - Error scenarios (how does it handle failures?)
82
66
  - Edge case scenarios (boundary conditions, unusual inputs)
83
67
  - Concurrent access scenarios (multiple instances)
84
68
 
85
- </details>
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
86
73
 
87
74
  **User Profile:** May not know how to code - Claude Code does the implementation autonomously.
88
75
 
89
76
  ---
90
77
 
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
-
130
78
  ## Quick Reference: Async Boundaries
131
79
 
132
80
  **Where Claude Code MUST wait for user confirmation:**
133
81
 
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 |
82
+ | Phase | Location | Why |
83
+ |-------|----------|-----|
84
+ | Step 3 Phase 1 | Before implementing | User confirms implementation approach |
137
85
 
138
86
  **Where Claude Code executes autonomously:**
139
- - Step 0: Initialize context
87
+ - Step 0: Create additional scenarios (if first stable chore)
140
88
  - Step 1: Scenario analysis
141
89
  - Step 2: Speed mode implementation review
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
90
+ - Step 3 Phase 2: Autonomous execution loop
91
+ - Step 4: Completion check and routing
146
92
 
147
93
  ---
148
94
 
@@ -159,7 +105,7 @@ For external products accepting real users, stable mode is NOT the final step. P
159
105
  **Required workflow for EXTERNAL products after stable mode implementation:**
160
106
 
161
107
  1. ✅ **Complete ALL stable mode chores** - Add error handling and edge cases
162
- 2. ✅ **Set feature to production mode** - Use `jettypod work set-mode <feature-id> production`
108
+ 2. ✅ **Generate production mode chores** - Use `jettypod work elevate <feature-id> production`
163
109
  3. ✅ **Implement production mode chores** - Add performance, security, monitoring
164
110
  4. ❌ **NEVER mark feature complete in stable mode for external products** - This bypasses critical production hardening
165
111
 
@@ -168,8 +114,8 @@ For external products accepting real users, stable mode is NOT the final step. P
168
114
  **If you attempt to mark an external product feature complete while in stable mode, the system will block you with an error.**
169
115
 
170
116
  The validation will require you to either:
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`
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`
173
119
 
174
120
  **Remember:** Stable mode makes it robust. Production mode makes it ready for real users at scale.
175
121
 
@@ -177,34 +123,48 @@ The validation will require you to either:
177
123
 
178
124
  ## Implementation Steps
179
125
 
180
- ### Step 0: Initialize Stable Mode Context
126
+ <!-- ═══════════════════════════════════════════════════════════════════════════
127
+ PHASE 1: AUTONOMOUS SETUP
128
+ No user input required - Claude Code executes independently
129
+ ═══════════════════════════════════════════════════════════════════════════ -->
181
130
 
182
- **You are now in stable mode,** implementing a chore to add error handling and edge case coverage.
131
+ ### Step 0: Create Additional Scenarios (If First Stable Chore)
183
132
 
184
- **Get the current work context:**
133
+ **CRITICAL:** If this is the FIRST stable mode chore for this feature, you must ADD edge case scenarios and step definitions.
185
134
 
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
- ```
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
189
139
 
190
- **Display to user:**
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]
191
148
 
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]
192
154
  ```
193
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
194
- 🛡️ STABLE MODE: Implementing Chore #[id]
195
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
196
155
 
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
- ```
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
204
160
 
205
- **Then proceed to Step 1.**
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`
206
166
 
207
- ---
167
+ **IMPORTANT:** Only do this ONCE per feature (first stable chore). Subsequent stable chores implement existing scenarios.
208
168
 
209
169
  ### Step 1: Analyze Scenario to Implement
210
170
 
@@ -212,18 +172,21 @@ Analyzing stable mode BDD scenarios to determine what error handling and validat
212
172
 
213
173
  **Your task:**
214
174
  1. Get current work item and parent feature's scenario file
215
- 2. Read the full scenario file (should have success scenarios + stable mode error/edge case scenarios)
175
+ 2. Read the full scenario file (should now have happy path + edge cases)
216
176
  3. Identify which scenario this chore addresses
217
177
  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).
221
178
 
222
179
  **To get scenario information, use these commands:**
223
180
 
224
181
  ```bash
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'"
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>"
227
190
  ```
228
191
 
229
192
  **Then read the scenario file** using the Read tool on the path returned by `scenario_file`.
@@ -260,12 +223,6 @@ What needs to happen:
260
223
  • [When] Action/condition: [requirement]
261
224
  • [Then] Expected behavior: [requirement]
262
225
 
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
-
269
226
  Now reviewing speed mode implementation...
270
227
  ```
271
228
 
@@ -309,7 +266,7 @@ Then use the Read tool to examine the implementation files.
309
266
 
310
267
  Current Implementation:
311
268
  • Files: [list]
312
- Success scenarios: ✅ Working (from speed mode)
269
+ Happy path: ✅ Working
313
270
  • Error handling: ❌ Missing [specific gaps]
314
271
  • Validation: ❌ Missing [specific gaps]
315
272
  • Edge cases: ❌ Not handled [specific gaps]
@@ -322,286 +279,392 @@ To pass the target scenario, I need to:
322
279
  Now proposing comprehensive implementation...
323
280
  ```
324
281
 
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
282
+ **Move to Step 3 automatically.**
340
283
 
341
- ### Step 3A: Propose Implementation Approach (Conditional)
284
+ <!-- ═══════════════════════════════════════════════════════════════════════════
285
+ PHASE 2: USER CONFIRMATION REQUIRED
286
+ ⚡ ASYNC BOUNDARY - Must wait for user response before proceeding
287
+ ═══════════════════════════════════════════════════════════════════════════ -->
342
288
 
343
- **⚡ ASYNC BOUNDARY - Only execute this if confirmation needed**
289
+ ### Step 3: Propose and Execute Comprehensive Implementation
344
290
 
345
- **Present your analysis and proposal to the user:**
291
+ **Two phases: Propose (get user confirmation) Execute (autonomous)**
346
292
 
347
- ```
348
- 💡 Implementation Proposal
349
-
350
- I see multiple ways to approach this error handling. Here's what I'm thinking:
293
+ #### Phase 1: Propose Comprehensive Implementation
351
294
 
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]
295
+ **Present your analysis and proposal:**
359
296
 
360
297
  ```
298
+ 💡 Comprehensive Implementation Proposal
361
299
 
362
- **⚡ WAIT for user confirmation or adjustments.**
300
+ Based on scenario and code analysis, here's how I'll add proper error handling and make the scenario pass:
363
301
 
364
- If user adjusts: revise proposal and confirm again before proceeding.
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]
365
306
 
366
- **If you skipped this step:** Proceed directly to Step 4.
307
+ **Error handling approach:**
308
+ • [Specific errors to catch and how to handle them]
309
+ • [User-friendly error messages]
310
+ • [Graceful failure behavior]
367
311
 
368
- ---
312
+ **Validation approach:**
313
+ • [Input validation checks]
314
+ • [Boundary condition handling]
315
+ • [State validation]
369
316
 
370
- ### Step 4: Establish RED Baseline
317
+ **Why this approach:**
318
+ [Brief explanation of how this satisfies the scenario with proper quality]
371
319
 
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
320
+ Sound good? I'll implement this autonomously once you confirm.
383
321
  ```
384
322
 
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
323
+ **WAIT for user confirmation or adjustments.**
389
324
 
390
- This establishes your RED baseline - stable mode scenarios should be failing initially.
325
+ If user adjusts: revise proposal and confirm again.
391
326
 
392
- **Display RED baseline:**
393
- ```
394
- 🔴 Establishing RED baseline...
327
+ <!-- ═══════════════════════════════════════════════════════════════════════════
328
+ PHASE 3: AUTONOMOUS EXECUTION
329
+ User has confirmed - Claude Code executes iteration loop independently
330
+ ═══════════════════════════════════════════════════════════════════════════ -->
395
331
 
396
- RED Baseline: 3 of 11 steps failing (stable mode scenarios)
332
+ #### Phase 2: Autonomous Execution
397
333
 
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
334
+ **CRITICAL:** After user confirms, Claude Code executes autonomously - no permission needed for individual code changes.
402
335
 
403
- First error:
404
- Step: Then it should throw a validation error
405
- Error: Error: Expected function to throw but it didn't
336
+ **Execution loop (with iteration limits and error handling):**
406
337
 
407
- 🎯 Goal: Make all stable mode scenarios pass
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
+ └─────────────────────────────────────────────────────────────────────────┘ -->
408
351
 
409
- Now implementing...
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
410
497
  ```
411
498
 
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
- ```
499
+ Note: Coverage tracking is project-specific. Check your package.json for the appropriate coverage command.
441
500
 
442
- **When GREEN achieved:**
501
+ **Display coverage summary:**
443
502
  ```
444
- 🎉 GREEN: All stable mode scenarios passing!
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
445
511
  ```
446
512
 
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
513
+ <!-- ═══════════════════════════════════════════════════════════════════════════
514
+ PHASE 4: COMPLETION AND ROUTING
515
+ Conditional phase - route based on project state (internal vs external)
516
+ ═══════════════════════════════════════════════════════════════════════════ -->
452
517
 
453
- **Re-run tests after refactor** to ensure nothing broke.
518
+ ### Step 4: Check for Production Mode (When All Stable Chores Complete)
454
519
 
455
- <details>
456
- <summary><strong>📋 TDD Loop Guidelines (click to expand)</strong></summary>
520
+ **CRITICAL: This step ONLY happens when ALL stable chores for the feature are complete. Otherwise skip to marking chore as done.**
457
521
 
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
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
+ └─────────────────────────────────────────────────────────────────────────┘ -->
463
535
 
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:**
536
+ **Check completion status and project state:**
481
537
 
482
538
  ```bash
483
539
  # Get current work to find parent feature ID
484
- sqlite3 .jettypod/work.db "SELECT wi.parent_id FROM work_items wi WHERE wi.status = 'in_progress'"
485
-
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
- ```
540
+ jettypod work current
489
541
 
490
- **If stable chores remain, display and start next chore:**
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')"
491
544
 
545
+ # Check project state
546
+ sqlite3 .jettypod/work.db "SELECT project_state FROM project_config WHERE id = 1"
492
547
  ```
493
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
494
- 🎯 Stable Mode Chore Complete
495
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
496
-
497
- ✅ Error handling and validation scenarios pass for this chore
498
548
 
499
- More stable mode chores remain. Starting next chore:
500
- #[next-chore-id]: [next-chore-title]
501
- ```
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
502
553
 
503
- **Then immediately merge current chore and start next:**
554
+ **CRITICAL: Check project state to determine next step:**
504
555
 
556
+ Check if project is internal or external:
505
557
  ```bash
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]
558
+ # Check project_state in database
559
+ node jettypod.js work show 1 | grep "Project state:"
560
+ # OR read CLAUDE.md <project_state> tag
514
561
  ```
515
562
 
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
-
528
563
  ---
529
564
 
530
- ### Step 6: Route to Completion (After All Stable Chores Complete)
565
+ ### Option A: Project is INTERNAL
531
566
 
532
- **CRITICAL: This step ONLY happens when ALL stable chores for the feature are complete.**
533
-
534
- **Check project state:**
567
+ **For internal projects, stable mode is the FINAL state.**
535
568
 
536
- ```bash
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
542
- ```
543
-
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.
545
-
546
- **Route based on project state:**
547
-
548
- **If project_state = 'internal':**
549
-
550
- Mark the feature as done:
569
+ **ACTION REQUIRED:** Mark the feature as done:
551
570
  ```bash
552
571
  node jettypod.js work status [feature-id] done
553
572
  ```
554
573
 
555
- Display:
574
+ Then display to user:
575
+
556
576
  ```
577
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
557
578
  ✅ FEATURE #[id] COMPLETE!
579
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
558
580
 
559
581
  Feature: [Feature Title]
560
582
  Status: ✅ DONE
561
583
 
562
584
  What we accomplished:
563
- ✅ All BDD scenarios passing (success + error handling + edge cases)
585
+ ✅ All BDD scenarios passing (happy path + error handling + edge cases)
564
586
  ✅ Comprehensive error handling and validation
565
587
  ✅ Input validation and edge case coverage
566
588
  ✅ State consistency and data integrity
589
+ ✅ All code merged to main and pushed to GitHub
567
590
 
591
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
568
592
  📝 INTERNAL PROJECT - STABLE MODE IS COMPLETE
593
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
569
594
 
570
595
  This is an internal project - stable mode is the end state.
596
+ No production hardening needed.
597
+
571
598
  Feature is complete and ready to use!
572
599
 
573
- Note: If you later transition to external (accepting real users),
574
- run the external-transition skill to generate production chores.
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
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
575
604
  ```
576
605
 
577
- **End skill.** Feature is DONE.
606
+ **End skill.** The feature is DONE.
578
607
 
579
608
  ---
580
609
 
581
- **If project_state = 'external':**
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:
582
615
 
583
- Use Skill tool to invoke production-mode:
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:
584
626
 
585
- Display:
586
627
  ```
628
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
587
629
  ✅ ALL STABLE MODE CHORES COMPLETE!
630
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
588
631
 
589
632
  What we accomplished:
590
- ✅ All BDD scenarios passing (success + error handling + edge cases)
633
+ ✅ All BDD scenarios passing (happy path + error handling + edge cases)
591
634
  ✅ Comprehensive error handling and validation
592
635
  ✅ Feature stable and ready for production hardening
593
636
 
637
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
594
638
  🚀 AUTO-GENERATING PRODUCTION CHORES
639
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
595
640
 
596
641
  This project is external - invoking production-mode skill to:
597
642
  • Detect feature context (authentication/data/general)
598
643
  • Generate production scenarios from standards
599
644
  • Create production chores with proper scope
645
+
646
+ [Invoke production-mode skill - it handles the rest autonomously]
600
647
  ```
601
648
 
602
- Then invoke production-mode skill. **End skill.**
649
+ **If stable chores remain:**
603
650
 
604
- ---
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:**
605
668
 
606
669
  ⚠️ **CRITICAL: Exclude CLAUDE.md from commits in worktrees**
607
670
 
@@ -619,17 +682,6 @@ Then use the merge command to merge to main (which auto-marks chore as done via
619
682
  jettypod work merge
620
683
  ```
621
684
 
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
-
633
685
  The post-merge hook will automatically mark the chore as done when merged to main.
634
686
 
635
687
  ---
@@ -661,15 +713,15 @@ After completing EACH stable chore:
661
713
  **Example correct flow:**
662
714
  ```bash
663
715
  # Complete chore #1854
664
- git add . && git commit -m "feat: [description]"
665
- jettypod work merge # Automatically pushes, merges, and cleans up
716
+ git add . && git commit && git push
717
+ jettypod work merge
666
718
 
667
719
  # NOW start chore #1855 (main has #1854's changes)
668
720
  jettypod work start 1855
669
721
 
670
722
  # Complete chore #1855
671
- git add . && git commit -m "feat: [description]"
672
- jettypod work merge # Automatically pushes, merges, and cleans up
723
+ git add . && git commit && git push
724
+ jettypod work merge
673
725
 
674
726
  # NOW start chore #1856 (main has #1854 + #1855's changes)
675
727
  jettypod work start 1856