agileflow 2.81.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.
@@ -63,6 +63,7 @@ When invoked with `MODE=loop`, babysit runs autonomously through an epic's stori
63
63
  | `MAX` | No | Max iterations (default: 20) |
64
64
  | `VISUAL` | No | Enable Visual Mode for UI development (screenshot verification) |
65
65
  | `COVERAGE` | No | Enable Coverage Mode - iterate until N% test coverage reached |
66
+ | `CONDITIONS` | No | Semantic conditions for story completion (configured in metadata) |
66
67
 
67
68
  ### To Start Loop Mode
68
69
 
@@ -100,6 +101,36 @@ Or manually write to session-state.json:
100
101
  }
101
102
  ```
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
+
103
134
  ### Coverage Mode
104
135
 
105
136
  When `COVERAGE=<percent>` is specified, the loop adds test coverage verification:
@@ -491,6 +522,59 @@ Task(
491
522
 
492
523
  ---
493
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
+
494
578
  ### KEY FILES TO REMEMBER
495
579
 
496
580
  | File | Purpose |
@@ -558,6 +642,18 @@ Based on your project state:
558
642
 
559
643
  ---
560
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
+
561
657
  ### REMEMBER AFTER COMPACTION
562
658
 
563
659
  - `/agileflow:babysit` IS ACTIVE - follow these rules
@@ -565,11 +661,47 @@ Based on your project state:
565
661
  - Plan mode FIRST for non-trivial tasks
566
662
  - Delegate complex work to experts
567
663
  - If stuck 2+ times → research prompt
664
+ - Use state narration markers (📍🔀🔄⚠️✅) for visibility
568
665
 
569
666
  <!-- COMPACT_SUMMARY_END -->
570
667
 
571
668
  ---
572
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
+
573
705
  ## DELEGATION FRAMEWORK
574
706
 
575
707
  ### Decision Tree
@@ -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