agileflow 2.80.0 → 2.82.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,6 +1,6 @@
1
1
  ---
2
2
  description: Interactive mentor for end-to-end feature implementation
3
- argument-hint: "[EPIC=<id>] [MODE=loop] [MAX=<iterations>] [VISUAL=true]"
3
+ argument-hint: "[EPIC=<id>] [MODE=loop] [MAX=<iterations>] [VISUAL=true] [COVERAGE=<percent>]"
4
4
  compact_context:
5
5
  priority: critical
6
6
  preserve_rules:
@@ -62,6 +62,8 @@ When invoked with `MODE=loop`, babysit runs autonomously through an epic's stori
62
62
  | `MODE` | Yes | Must be `loop` for autonomous mode |
63
63
  | `MAX` | No | Max iterations (default: 20) |
64
64
  | `VISUAL` | No | Enable Visual Mode for UI development (screenshot verification) |
65
+ | `COVERAGE` | No | Enable Coverage Mode - iterate until N% test coverage reached |
66
+ | `CONDITIONS` | No | Semantic conditions for story completion (configured in metadata) |
65
67
 
66
68
  ### To Start Loop Mode
67
69
 
@@ -73,6 +75,9 @@ node scripts/ralph-loop.js --init --epic=EP-0042 --max=20
73
75
 
74
76
  # With Visual Mode for UI development
75
77
  node scripts/ralph-loop.js --init --epic=EP-0042 --max=20 --visual
78
+
79
+ # With Coverage Mode - iterate until 80% coverage
80
+ node scripts/ralph-loop.js --init --epic=EP-0042 --max=20 --coverage=80
76
81
  ```
77
82
 
78
83
  Or manually write to session-state.json:
@@ -86,7 +91,73 @@ Or manually write to session-state.json:
86
91
  "iteration": 0,
87
92
  "max_iterations": 20,
88
93
  "visual_mode": false,
89
- "screenshots_verified": false
94
+ "screenshots_verified": false,
95
+ "coverage_mode": false,
96
+ "coverage_threshold": 80,
97
+ "coverage_baseline": 0,
98
+ "coverage_current": 0,
99
+ "coverage_verified": false
100
+ }
101
+ }
102
+ ```
103
+
104
+ ### Discretion Conditions Mode
105
+
106
+ Configure semantic conditions in `docs/00-meta/agileflow-metadata.json`:
107
+
108
+ ```json
109
+ {
110
+ "ralph_loop": {
111
+ "conditions": [
112
+ "**all tests passing**",
113
+ "**no linting errors**",
114
+ "**no type errors**"
115
+ ]
116
+ }
117
+ }
118
+ ```
119
+
120
+ **Available conditions:**
121
+ - `**all tests passing**` - Tests must pass
122
+ - `**coverage above N%**` - Coverage threshold (e.g., `**coverage above 80%**`)
123
+ - `**no linting errors**` - `npm run lint` must pass
124
+ - `**no type errors**` - `npx tsc --noEmit` must pass
125
+ - `**build succeeds**` - `npm run build` must pass
126
+ - `**all screenshots verified**` - Screenshots need `verified-` prefix
127
+ - `**all acceptance criteria verified**` - AC marked complete in status.json
128
+
129
+ **Benefits:**
130
+ - Natural language conditions that read like requirements
131
+ - Multiple conditions can be combined
132
+ - Extensible - add custom conditions as needed
133
+
134
+ ### Coverage Mode
135
+
136
+ When `COVERAGE=<percent>` is specified, the loop adds test coverage verification:
137
+
138
+ ```
139
+ /agileflow:babysit EPIC=EP-0042 MODE=loop COVERAGE=80
140
+ ```
141
+
142
+ **Coverage Mode behavior:**
143
+ 1. After tests pass, runs coverage check command
144
+ 2. Parses `coverage/coverage-summary.json` (Jest/NYC format)
145
+ 3. Compares line coverage to threshold
146
+ 4. Requires minimum 2 iterations before completion
147
+ 5. Story completes only when coverage ≥ threshold AND confirmed
148
+
149
+ **When to use Coverage Mode:**
150
+ - Test-driven epics where coverage matters
151
+ - "Write tests until X% coverage" goals
152
+ - Batch test generation overnight
153
+
154
+ **Configuration** (optional):
155
+ Add to `docs/00-meta/agileflow-metadata.json`:
156
+ ```json
157
+ {
158
+ "ralph_loop": {
159
+ "coverage_command": "npm run test:coverage",
160
+ "coverage_report_path": "coverage/coverage-summary.json"
90
161
  }
91
162
  }
92
163
  ```
@@ -111,7 +182,7 @@ When `VISUAL=true` is specified, the loop adds screenshot verification:
111
182
  - Any work where visual appearance matters
112
183
 
113
184
  **Setup requirement:**
114
- Run `/agileflow:setup:visual-e2e` first to install Playwright and create e2e tests.
185
+ Run `/agileflow:configure` and select "Set up Visual E2E testing" to install Playwright and create e2e tests.
115
186
 
116
187
  ### Loop Control Commands
117
188
 
@@ -200,7 +271,7 @@ Analysis/Review → /agileflow:multi-expert or Task(subagent_t
200
271
  - `agileflow-api` - Endpoints, business logic
201
272
  - `agileflow-ui` - Components, styling
202
273
  - `agileflow-testing` - Tests, coverage
203
- - `agileflow-orchestrator` - Multi-domain coordination
274
+ - `agileflow-orchestrator` - Multi-domain coordination (supports nested loops for quality gates)
204
275
 
205
276
  ---
206
277
 
@@ -353,6 +424,23 @@ Task(
353
424
  )
354
425
  ```
355
426
 
427
+ **🧪 EXPERIMENTAL: Nested Loops with Quality Gates**
428
+
429
+ When you need agents to iterate until quality gates pass (coverage ≥ 80%, tests pass, etc.), the orchestrator can use **nested agent loops**. Each agent runs its own isolated loop.
430
+
431
+ ```
432
+ Task(
433
+ description: "Profile feature with quality gates",
434
+ prompt: "Implement profile with quality enforcement:
435
+ 1. API: /api/profile with COVERAGE >= 80% (agent loop)
436
+ 2. UI: ProfilePage with VISUAL verification (agent loop)
437
+ Use agent-loop.js for isolated quality iterations.",
438
+ subagent_type: "agileflow-orchestrator"
439
+ )
440
+ ```
441
+
442
+ See `orchestrator.md` → "NESTED LOOP MODE" section for full details.
443
+
356
444
  ---
357
445
 
358
446
  #### Pattern 3: Parallel Execution (Manual Coordination)
@@ -434,6 +522,59 @@ Task(
434
522
 
435
523
  ---
436
524
 
525
+ #### Retry with Backoff for Expert Spawning
526
+
527
+ When an expert task fails, apply retry logic before giving up:
528
+
529
+ **Retry Strategy:**
530
+ ```
531
+ Attempt 1: Immediate retry
532
+ Attempt 2: Wait 5 seconds, then retry
533
+ Attempt 3: Wait 15 seconds, then retry (final)
534
+ ```
535
+
536
+ **When to retry:**
537
+ - Expert returns error or timeout
538
+ - TaskOutput shows failure state
539
+ - Expert reports "unable to complete"
540
+
541
+ **When NOT to retry:**
542
+ - User explicitly asked to stop
543
+ - Expert completed but result was wrong (need different approach)
544
+ - Multiple experts all failed same way (systemic issue)
545
+
546
+ **Example retry flow:**
547
+ ```
548
+ 📍 Spawning agileflow-api expert...
549
+ ⚠️ Expert failed (timeout after 2 min)
550
+
551
+ 🔄 Retry 1/3: Retrying immediately...
552
+ ⚠️ Expert failed (same error)
553
+
554
+ 🔄 Retry 2/3: Waiting 5s, then retrying...
555
+ ⚠️ Expert failed (connection error)
556
+
557
+ 🔄 Retry 3/3: Waiting 15s, then retrying...
558
+ ✅ Expert succeeded!
559
+ ```
560
+
561
+ **On final failure:**
562
+ ```
563
+ ⚠️ Error: Expert agileflow-api failed after 3 retries
564
+
565
+ Last error: Connection timeout after 120s
566
+ Attempts: 3
567
+
568
+ Options:
569
+ 1. Try a different approach
570
+ 2. Check network/service status
571
+ 3. Manually implement the task
572
+
573
+ [Present options via AskUserQuestion]
574
+ ```
575
+
576
+ ---
577
+
437
578
  ### KEY FILES TO REMEMBER
438
579
 
439
580
  | File | Purpose |
@@ -441,8 +582,6 @@ Task(
441
582
  | `docs/09-agents/status.json` | Story tracking, WIP status |
442
583
  | `docs/09-agents/session-state.json` | Session state, active command |
443
584
  | `CLAUDE.md` | Project conventions (included in full above) |
444
- | `docs/02-practices/*.md` | Implementation patterns |
445
- | `docs/04-architecture/*.md` | System design docs |
446
585
 
447
586
  ---
448
587
 
@@ -503,6 +642,18 @@ Based on your project state:
503
642
 
504
643
  ---
505
644
 
645
+ ### STATE NARRATION (emit in responses)
646
+
647
+ | Marker | When |
648
+ |--------|------|
649
+ | 📍 | Working on story/phase |
650
+ | 🔀 | Spawning parallel experts |
651
+ | 🔄 | Loop iterations |
652
+ | ⚠️ | Errors |
653
+ | ✅ | Completions |
654
+
655
+ ---
656
+
506
657
  ### REMEMBER AFTER COMPACTION
507
658
 
508
659
  - `/agileflow:babysit` IS ACTIVE - follow these rules
@@ -510,11 +661,47 @@ Based on your project state:
510
661
  - Plan mode FIRST for non-trivial tasks
511
662
  - Delegate complex work to experts
512
663
  - If stuck 2+ times → research prompt
664
+ - Use state narration markers (📍🔀🔄⚠️✅) for visibility
513
665
 
514
666
  <!-- COMPACT_SUMMARY_END -->
515
667
 
516
668
  ---
517
669
 
670
+ ## STATE NARRATION PROTOCOL
671
+
672
+ In long sessions, track execution state visibly using emoji markers. This makes state scannable after compaction.
673
+
674
+ ### Markers
675
+
676
+ | Marker | Meaning | Example |
677
+ |--------|---------|---------|
678
+ | 📍 | Execution position | `📍 Working on: US-0042 - Add login form` |
679
+ | 📦 | Context/variables | `📦 Context: { auth: "complete", api: "pending" }` |
680
+ | 🔀 | Parallel status | `🔀 Parallel: API (done), UI (in progress)` |
681
+ | 🔄 | Loop iteration | `🔄 Iteration 3/10` |
682
+ | ⚠️ | Error state | `⚠️ Error: Test failure in auth.spec.ts` |
683
+ | ✅ | Completion | `✅ Story complete: US-0042` |
684
+ | 🔒 | Blocked | `🔒 Blocked: Waiting for API schema` |
685
+
686
+ ### When to Emit Markers
687
+
688
+ - **Start of story**: `📍 Starting: US-0042`
689
+ - **Phase transitions**: `📍 Phase: Execution (plan approved)`
690
+ - **Expert spawn**: `🔀 Spawned: agileflow-api (background)`
691
+ - **Expert complete**: `✅ Expert done: agileflow-api`
692
+ - **Loop iterations**: `🔄 Ralph Loop: 3/10`
693
+ - **Errors**: `⚠️ Test failure: 2 tests failed`
694
+ - **Completion**: `✅ Story complete: US-0042`
695
+
696
+ ### Benefits
697
+
698
+ - **Visibility**: State is inline, not hidden in files
699
+ - **Debugging**: Scan conversation for state changes
700
+ - **Resumability**: Markers help restore context after compact
701
+ - **Progress**: Clear indication of where work stands
702
+
703
+ ---
704
+
518
705
  ## DELEGATION FRAMEWORK
519
706
 
520
707
  ### Decision Tree
@@ -917,15 +1104,6 @@ After loading context, analyze and present ranked options:
917
1104
  - Session state, current story
918
1105
  - Docs structure, research notes
919
1106
 
920
- **Read manually for deep dives:**
921
-
922
- | Domain | Docs |
923
- |--------|------|
924
- | Database | `docs/04-architecture/database-*.md` |
925
- | API | `docs/04-architecture/api-*.md` |
926
- | UI | `docs/02-practices/styling.md` |
927
- | Testing | `docs/02-practices/testing.md` |
928
-
929
1107
  **State files:**
930
1108
  - `docs/09-agents/status.json` - Story tracking
931
1109
  - `docs/09-agents/bus/log.jsonl` - Agent messages
@@ -0,0 +1,362 @@
1
+ ---
2
+ description: Process multiple items with functional patterns (map/pmap/filter/reduce)
3
+ argument-hint: <operation> <pattern> [action]
4
+ compact_context:
5
+ priority: normal
6
+ preserve_rules:
7
+ - "map: Execute action on each item sequentially"
8
+ - "pmap: Execute action on each item in parallel (spawn Task agents)"
9
+ - "filter: Return items matching criteria"
10
+ - "reduce: Aggregate items into single output"
11
+ state_fields:
12
+ - batch_operation
13
+ - items_processed
14
+ - items_total
15
+ ---
16
+
17
+ # /agileflow:batch
18
+
19
+ Process multiple items with functional patterns. Enables batch operations on stories, files, or tasks.
20
+
21
+ ---
22
+
23
+ ## STEP 0: Gather Context
24
+
25
+ ```bash
26
+ node .agileflow/scripts/obtain-context.js batch
27
+ ```
28
+
29
+ ---
30
+
31
+ <!-- COMPACT_SUMMARY_START -->
32
+
33
+ ## Compact Summary
34
+
35
+ **Role**: Batch Processor - Apply functional patterns to collections
36
+
37
+ **Operations**:
38
+ - `map` - Execute action on each item sequentially
39
+ - `pmap` - Execute action in parallel (spawn agents)
40
+ - `filter` - Return items matching criteria
41
+ - `reduce` - Aggregate items into output
42
+
43
+ **Usage Examples**:
44
+ ```
45
+ /agileflow:batch map "docs/06-stories/*.md" validate
46
+ /agileflow:batch pmap "src/**/*.tsx" add-tests
47
+ /agileflow:batch filter stories status=ready
48
+ /agileflow:batch reduce "docs/06-stories/*.md" summary
49
+ ```
50
+
51
+ **Workflow**:
52
+ 1. Parse operation and pattern
53
+ 2. Resolve pattern to item list
54
+ 3. For each item: execute action based on operation type
55
+ 4. Collect and report results
56
+
57
+ <!-- COMPACT_SUMMARY_END -->
58
+
59
+ ---
60
+
61
+ ## Usage
62
+
63
+ ```
64
+ /agileflow:batch <operation> <pattern> [action]
65
+ ```
66
+
67
+ ### Operations
68
+
69
+ | Operation | Description | Parallelism |
70
+ |-----------|-------------|-------------|
71
+ | `map` | Execute action on each item | Sequential |
72
+ | `pmap` | Execute action in parallel | Parallel (agents) |
73
+ | `filter` | Return matching items | N/A |
74
+ | `reduce` | Aggregate to single output | Sequential |
75
+
76
+ ### Pattern Types
77
+
78
+ | Pattern | Resolves To | Example |
79
+ |---------|-------------|---------|
80
+ | Glob | File paths | `src/**/*.tsx` |
81
+ | `stories` | Stories from status.json | `stories status=ready` |
82
+ | `epics` | Epics from status.json | `epics status=in_progress` |
83
+
84
+ ---
85
+
86
+ ## Examples
87
+
88
+ ### 1. Validate All Stories (map)
89
+
90
+ ```
91
+ /agileflow:batch map "docs/06-stories/*.md" validate
92
+ ```
93
+
94
+ Sequentially validates each story file:
95
+ - Checks for required frontmatter
96
+ - Validates acceptance criteria format
97
+ - Reports issues
98
+
99
+ **Output:**
100
+ ```
101
+ 📦 Batch: map over 12 items
102
+
103
+ 📍 Processing: docs/06-stories/US-0042.md
104
+ ✅ Valid story format
105
+
106
+ 📍 Processing: docs/06-stories/US-0043.md
107
+ ⚠️ Missing acceptance criteria
108
+
109
+ ...
110
+
111
+ ✅ Complete: 10 passed, 2 warnings
112
+ ```
113
+
114
+ ### 2. Generate Tests in Parallel (pmap)
115
+
116
+ ```
117
+ /agileflow:batch pmap "src/components/*.tsx" add-tests
118
+ ```
119
+
120
+ Spawns parallel agents to generate tests:
121
+
122
+ **What happens:**
123
+ 1. Glob resolves to list of component files
124
+ 2. For each file, spawn Task agent:
125
+ ```
126
+ Task(
127
+ description: "Add tests for Button.tsx",
128
+ prompt: "Generate comprehensive tests for src/components/Button.tsx",
129
+ subagent_type: "agileflow-testing",
130
+ run_in_background: true
131
+ )
132
+ ```
133
+ 3. Collect results with TaskOutput
134
+ 4. Report summary
135
+
136
+ **Output:**
137
+ ```
138
+ 🔀 Batch: pmap over 8 items (parallel)
139
+
140
+ 🔀 Spawning 8 parallel agents...
141
+ 📍 task-001: Button.tsx
142
+ 📍 task-002: Input.tsx
143
+ 📍 task-003: Select.tsx
144
+ ...
145
+
146
+ ⏳ Waiting for completion...
147
+
148
+ ✅ task-001: Button.tsx - 5 tests added
149
+ ✅ task-002: Input.tsx - 4 tests added
150
+ ✅ task-003: Select.tsx - 6 tests added
151
+ ...
152
+
153
+ ✅ Complete: 8/8 successful, 38 tests added
154
+ ```
155
+
156
+ ### 3. Filter Ready Stories
157
+
158
+ ```
159
+ /agileflow:batch filter stories status=ready
160
+ ```
161
+
162
+ Returns stories matching criteria:
163
+
164
+ **Output:**
165
+ ```
166
+ 🔍 Filter: stories where status=ready
167
+
168
+ Found 3 matching stories:
169
+
170
+ 1. US-0042: Add user profile settings
171
+ Epic: EP-0009 | Priority: high
172
+
173
+ 2. US-0043: Implement password reset
174
+ Epic: EP-0009 | Priority: high
175
+
176
+ 3. US-0045: Add notification preferences
177
+ Epic: EP-0010 | Priority: medium
178
+ ```
179
+
180
+ ### 4. Reduce to Summary Report
181
+
182
+ ```
183
+ /agileflow:batch reduce "docs/06-stories/*.md" summary
184
+ ```
185
+
186
+ Aggregates stories into summary:
187
+
188
+ **Output:**
189
+ ```
190
+ 📊 Reduce: 15 stories → summary
191
+
192
+ Epic Distribution:
193
+ EP-0009: 8 stories (53%)
194
+ EP-0010: 4 stories (27%)
195
+ EP-0011: 3 stories (20%)
196
+
197
+ Status Distribution:
198
+ ready: 5 (33%)
199
+ in_progress: 3 (20%)
200
+ completed: 7 (47%)
201
+
202
+ Priority:
203
+ high: 6
204
+ medium: 7
205
+ low: 2
206
+ ```
207
+
208
+ ---
209
+
210
+ ## Actions
211
+
212
+ ### Built-in Actions
213
+
214
+ | Action | Description | Works With |
215
+ |--------|-------------|------------|
216
+ | `validate` | Check format/structure | stories, epics |
217
+ | `add-tests` | Generate tests | source files |
218
+ | `lint` | Run linter | source files |
219
+ | `format` | Apply formatting | source files |
220
+ | `summarize` | Generate summary | any |
221
+ | `count` | Count items | any |
222
+
223
+ ### Custom Actions
224
+
225
+ For pmap, action becomes the agent prompt:
226
+
227
+ ```
228
+ /agileflow:batch pmap "src/**/*.ts" "refactor to use async/await"
229
+ ```
230
+
231
+ This spawns agents with prompt: "refactor to use async/await" for each file.
232
+
233
+ ---
234
+
235
+ ## Filter Criteria
236
+
237
+ Filters use `field=value` syntax:
238
+
239
+ ```
240
+ /agileflow:batch filter stories status=ready
241
+ /agileflow:batch filter stories epic=EP-0009
242
+ /agileflow:batch filter stories priority=high
243
+ /agileflow:batch filter epics status=in_progress
244
+ ```
245
+
246
+ Multiple criteria (AND):
247
+ ```
248
+ /agileflow:batch filter stories status=ready priority=high
249
+ ```
250
+
251
+ ---
252
+
253
+ ## Implementation Details
254
+
255
+ ### Map Operation
256
+
257
+ ```javascript
258
+ // Sequential execution
259
+ for (const item of items) {
260
+ const result = await executeAction(item, action);
261
+ results.push(result);
262
+ console.log(`📍 ${item}: ${result.status}`);
263
+ }
264
+ ```
265
+
266
+ ### Pmap Operation
267
+
268
+ ```javascript
269
+ // Parallel execution with agents
270
+ const tasks = items.map(item => Task({
271
+ description: `Process ${path.basename(item)}`,
272
+ prompt: `${action} for ${item}`,
273
+ subagent_type: getAgentForAction(action),
274
+ run_in_background: true
275
+ }));
276
+
277
+ // Collect results
278
+ for (const task of tasks) {
279
+ const result = await TaskOutput(task.id, { block: true });
280
+ results.push(result);
281
+ }
282
+ ```
283
+
284
+ ### Filter Operation
285
+
286
+ ```javascript
287
+ // Load and filter status.json
288
+ const status = loadStatus();
289
+ const items = type === 'stories' ? status.stories : status.epics;
290
+
291
+ const filtered = Object.entries(items)
292
+ .filter(([id, item]) => matchesCriteria(item, criteria))
293
+ .map(([id, item]) => ({ id, ...item }));
294
+ ```
295
+
296
+ ### Reduce Operation
297
+
298
+ ```javascript
299
+ // Aggregate with accumulator
300
+ let accumulator = initialValue;
301
+ for (const item of items) {
302
+ accumulator = reducer(accumulator, item);
303
+ }
304
+ return accumulator;
305
+ ```
306
+
307
+ ---
308
+
309
+ ## Best Practices
310
+
311
+ ### When to Use Each Operation
312
+
313
+ | Use Case | Operation |
314
+ |----------|-----------|
315
+ | Sequential processing | `map` |
316
+ | Independent tasks, time-sensitive | `pmap` |
317
+ | Query/search | `filter` |
318
+ | Reports/aggregation | `reduce` |
319
+
320
+ ### Performance Considerations
321
+
322
+ - **pmap** spawns agents - each costs tokens
323
+ - Limit pmap to reasonable batch sizes (< 20 items)
324
+ - Use `map` for quick operations (validation, counting)
325
+ - Use `filter` before other operations to reduce scope
326
+
327
+ ### Error Handling
328
+
329
+ - Map/pmap continue on individual item failures
330
+ - Failed items are reported at end
331
+ - Use `--fail-fast` flag to stop on first error:
332
+ ```
333
+ /agileflow:batch map "*.ts" lint --fail-fast
334
+ ```
335
+
336
+ ---
337
+
338
+ ## State Tracking
339
+
340
+ Batch operations update session-state.json:
341
+
342
+ ```json
343
+ {
344
+ "last_batch": {
345
+ "operation": "pmap",
346
+ "pattern": "src/**/*.tsx",
347
+ "action": "add-tests",
348
+ "items_total": 8,
349
+ "items_processed": 8,
350
+ "items_failed": 0,
351
+ "completed_at": "2026-01-09T12:00:00Z"
352
+ }
353
+ }
354
+ ```
355
+
356
+ ---
357
+
358
+ ## Integration
359
+
360
+ - Works with `/agileflow:babysit` for batch story processing
361
+ - Can be used in Ralph Loop for batch operations per iteration
362
+ - Integrates with agent system for parallel work