agileflow 3.1.0 → 3.2.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.
Files changed (101) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +57 -85
  3. package/lib/dashboard-automations.js +130 -0
  4. package/lib/dashboard-git.js +254 -0
  5. package/lib/dashboard-inbox.js +64 -0
  6. package/lib/dashboard-protocol.js +1 -0
  7. package/lib/dashboard-server.js +114 -924
  8. package/lib/dashboard-session.js +136 -0
  9. package/lib/dashboard-status.js +72 -0
  10. package/lib/dashboard-terminal.js +354 -0
  11. package/lib/dashboard-websocket.js +88 -0
  12. package/lib/drivers/codex-driver.ts +4 -4
  13. package/lib/logger.js +106 -0
  14. package/package.json +4 -2
  15. package/scripts/agileflow-configure.js +2 -2
  16. package/scripts/agileflow-welcome.js +409 -434
  17. package/scripts/claude-tmux.sh +80 -2
  18. package/scripts/context-loader.js +4 -9
  19. package/scripts/lib/command-prereqs.js +280 -0
  20. package/scripts/lib/configure-detect.js +92 -2
  21. package/scripts/lib/configure-features.js +295 -1
  22. package/scripts/lib/context-formatter.js +468 -233
  23. package/scripts/lib/context-loader.js +27 -15
  24. package/scripts/lib/damage-control-utils.js +8 -1
  25. package/scripts/lib/feature-catalog.js +321 -0
  26. package/scripts/lib/portable-tasks-cli.js +274 -0
  27. package/scripts/lib/portable-tasks.js +479 -0
  28. package/scripts/lib/signal-detectors.js +1 -1
  29. package/scripts/lib/team-events.js +86 -1
  30. package/scripts/obtain-context.js +28 -4
  31. package/scripts/smart-detect.js +17 -0
  32. package/scripts/strip-ai-attribution.js +63 -0
  33. package/scripts/team-manager.js +7 -2
  34. package/scripts/welcome-deferred.js +437 -0
  35. package/src/core/agents/perf-analyzer-assets.md +174 -0
  36. package/src/core/agents/perf-analyzer-bundle.md +165 -0
  37. package/src/core/agents/perf-analyzer-caching.md +160 -0
  38. package/src/core/agents/perf-analyzer-compute.md +165 -0
  39. package/src/core/agents/perf-analyzer-memory.md +182 -0
  40. package/src/core/agents/perf-analyzer-network.md +157 -0
  41. package/src/core/agents/perf-analyzer-queries.md +155 -0
  42. package/src/core/agents/perf-analyzer-rendering.md +156 -0
  43. package/src/core/agents/perf-consensus.md +280 -0
  44. package/src/core/agents/security-analyzer-api.md +199 -0
  45. package/src/core/agents/security-analyzer-auth.md +160 -0
  46. package/src/core/agents/security-analyzer-authz.md +168 -0
  47. package/src/core/agents/security-analyzer-deps.md +147 -0
  48. package/src/core/agents/security-analyzer-infra.md +176 -0
  49. package/src/core/agents/security-analyzer-injection.md +148 -0
  50. package/src/core/agents/security-analyzer-input.md +191 -0
  51. package/src/core/agents/security-analyzer-secrets.md +175 -0
  52. package/src/core/agents/security-consensus.md +276 -0
  53. package/src/core/agents/test-analyzer-assertions.md +181 -0
  54. package/src/core/agents/test-analyzer-coverage.md +183 -0
  55. package/src/core/agents/test-analyzer-fragility.md +185 -0
  56. package/src/core/agents/test-analyzer-integration.md +155 -0
  57. package/src/core/agents/test-analyzer-maintenance.md +173 -0
  58. package/src/core/agents/test-analyzer-mocking.md +178 -0
  59. package/src/core/agents/test-analyzer-patterns.md +189 -0
  60. package/src/core/agents/test-analyzer-structure.md +177 -0
  61. package/src/core/agents/test-consensus.md +294 -0
  62. package/src/core/commands/{legal/audit.md → audit/legal.md} +13 -13
  63. package/src/core/commands/{logic/audit.md → audit/logic.md} +12 -12
  64. package/src/core/commands/audit/performance.md +443 -0
  65. package/src/core/commands/audit/security.md +443 -0
  66. package/src/core/commands/audit/test.md +442 -0
  67. package/src/core/commands/babysit.md +505 -463
  68. package/src/core/commands/configure.md +8 -8
  69. package/src/core/commands/research/ask.md +42 -9
  70. package/src/core/commands/research/import.md +14 -8
  71. package/src/core/commands/research/list.md +17 -16
  72. package/src/core/commands/research/synthesize.md +8 -8
  73. package/src/core/commands/research/view.md +28 -4
  74. package/src/core/commands/whats-new.md +2 -2
  75. package/src/core/experts/devops/expertise.yaml +13 -2
  76. package/src/core/experts/documentation/expertise.yaml +26 -4
  77. package/src/core/profiles/COMPARISON.md +170 -0
  78. package/src/core/profiles/README.md +178 -0
  79. package/src/core/profiles/claude-code.yaml +111 -0
  80. package/src/core/profiles/codex.yaml +103 -0
  81. package/src/core/profiles/cursor.yaml +134 -0
  82. package/src/core/profiles/examples.js +250 -0
  83. package/src/core/profiles/loader.js +235 -0
  84. package/src/core/profiles/windsurf.yaml +159 -0
  85. package/src/core/teams/logic-audit.json +6 -0
  86. package/src/core/teams/perf-audit.json +71 -0
  87. package/src/core/teams/security-audit.json +71 -0
  88. package/src/core/teams/test-audit.json +71 -0
  89. package/src/core/templates/command-prerequisites.yaml +169 -0
  90. package/src/core/templates/damage-control-patterns.yaml +9 -0
  91. package/tools/cli/installers/ide/_base-ide.js +33 -3
  92. package/tools/cli/installers/ide/claude-code.js +2 -69
  93. package/tools/cli/installers/ide/codex.js +9 -9
  94. package/tools/cli/installers/ide/cursor.js +165 -4
  95. package/tools/cli/installers/ide/windsurf.js +237 -6
  96. package/tools/cli/lib/content-transformer.js +234 -9
  97. package/tools/cli/lib/docs-setup.js +1 -1
  98. package/tools/cli/lib/ide-generator.js +357 -0
  99. package/tools/cli/lib/ide-registry.js +2 -2
  100. package/scripts/tmux-task-name.sh +0 -105
  101. package/scripts/tmux-task-watcher.sh +0 -344
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  description: Interactive mentor for end-to-end feature implementation
3
- argument-hint: "[EPIC=<EP-ID>]"
3
+ argument-hint: "[EPIC=<EP-ID>] [MODE=loop|once] [VISUAL=true|false] [COVERAGE=<percent>] [MAX=<iterations>]"
4
4
  compact_context:
5
5
  priority: critical
6
6
  preserve_rules:
@@ -14,6 +14,8 @@ compact_context:
14
14
  - "PLAN FILE CONTEXT: BEFORE ExitPlanMode, EDIT plan file to add babysit rules header at TOP - rules survive context clear"
15
15
  - "STORY CLAIMING: claim after selection, release after completion, check others before suggesting"
16
16
  - "LOGIC AUDIT: ALWAYS suggest '🔍 Run logic audit' after ANY implementation (plan or direct) - it's a standard post-impl step, not optional"
17
+ - "PROACTIVE FEATURES: Impact analysis before plan mode (3+ files). Council for arch decisions. Code review for 5+ source files. Multi-expert for 10+ files. ADR for arch decisions. Research proactively for unfamiliar patterns. Docs sync when API/interface/exports change."
18
+ - "OBTAIN-CONTEXT: NEVER pipe obtain-context.js through head/tail/truncation - run it bare, it has built-in smart output limits"
17
19
  state_fields:
18
20
  - current_story
19
21
  - current_epic
@@ -35,10 +37,74 @@ node .agileflow/scripts/obtain-context.js babysit
35
37
 
36
38
  **DO THIS IMMEDIATELY. NO EXCEPTIONS.**
37
39
 
40
+ **⚠️ NEVER truncate the output.** Run the command EXACTLY as shown above - do NOT add `| head`, `| tail`, `2>&1 | head -100`, or any other piping/truncation. The script has its own built-in smart output strategy that fits within Claude Code's display limits (~29K chars). Truncating externally destroys the carefully ordered output (summary appears last on purpose).
41
+
38
42
  This gathers: git status, stories/epics, session state, docs structure, research notes.
39
43
 
40
44
  ---
41
45
 
46
+ ## Parameters
47
+
48
+ All parameters are optional. Most are auto-detected by the Contextual Feature Router.
49
+
50
+ | Parameter | Default | Example | Description |
51
+ |-----------|---------|---------|-------------|
52
+ | `EPIC` | none | `EP-0042` | Target epic for loop mode |
53
+ | `MODE` | auto | `once` | `loop` (auto when 3+ ready stories) or `once` (single story) |
54
+ | `MAX` | 20 | `10` | Max loop iterations before stopping |
55
+ | `VISUAL` | auto | `false` | Screenshot verification for UI work. Auto-enabled for AG-UI stories |
56
+ | `COVERAGE` | auto | `80` | Test coverage threshold (%). Set `0` to disable |
57
+
58
+ **Auto-detection**: When `EPIC` is specified with 3+ ready stories, `MODE=loop` is auto-enabled. `VISUAL` auto-enables for UI-tagged stories. `COVERAGE` auto-enables when a coverage baseline exists.
59
+
60
+ **Override examples**:
61
+ ```
62
+ /agileflow:babysit EPIC=EP-0042 # Auto-detect everything
63
+ /agileflow:babysit EPIC=EP-0042 MODE=once # Single story only
64
+ /agileflow:babysit EPIC=EP-0042 VISUAL=false # Skip screenshots
65
+ /agileflow:babysit EPIC=EP-0042 COVERAGE=90 MAX=30 # Strict coverage, more iterations
66
+ ```
67
+
68
+ <!-- === TIER 1: QUICK REFERENCE === -->
69
+
70
+ ---
71
+
72
+ ## QUICK DECISION TREE
73
+
74
+ | Task Type | Action |
75
+ |-----------|--------|
76
+ | **Simple** (typo, one-liner) | Do it yourself |
77
+ | **Complex, 1 domain** | Impact analysis → Plan → Spawn domain expert (with validator) |
78
+ | **Complex, 2+ domains** | Impact analysis → Council (if arch decision) → Plan → Spawn orchestrator |
79
+ | **Architecture decision** | Convene council → Create ADR |
80
+ | **Unfamiliar pattern/library** | Research first → then implement |
81
+ | **Stuck on error 2+ times** | Run `/agileflow:research:ask` |
82
+ | **Analysis/Review question** | Deploy multi-expert (3-5 experts) |
83
+
84
+ **Key Rules:**
85
+ 1. ALWAYS end responses with `AskUserQuestion` tool (not text questions)
86
+ 2. Use `EnterPlanMode` before non-trivial implementation
87
+ 3. Use `TaskCreate`/`TaskUpdate` to track multi-step tasks
88
+ 4. Proactively trigger advanced features (Rule #7) - don't wait for smart-detect
89
+
90
+ ---
91
+
92
+ ## SCALE-ADAPTIVE BEHAVIOR
93
+
94
+ The context output includes a **Project Scale** section. Adjust your approach based on detected scale:
95
+
96
+ | Scale | Planning Depth | Expert Usage | Workflow |
97
+ |-------|---------------|--------------|----------|
98
+ | **Micro** | Skip plan mode for most tasks. Implement directly. | 2 experts max | No epics needed. Quick stories or direct implementation. |
99
+ | **Small** | Light planning. Skip plan mode for familiar tasks. | 3 experts max | Simple stories. Epics optional. |
100
+ | **Medium** | Standard planning. Use plan mode for complex tasks. | 4 experts | Full story workflow with epics. |
101
+ | **Large** | Thorough planning. Always use plan mode. | 5 experts | Full workflow with architecture review. |
102
+ | **Enterprise** | Comprehensive planning with council review. | 5 experts | Full workflow with ADRs and multi-expert analysis. |
103
+
104
+ **Important**: User can always override scale behavior. If they say "plan this carefully" for a micro project, do it.
105
+
106
+ ---
107
+
42
108
  ## 🧠 CONTEXTUAL FEATURE ROUTER
43
109
 
44
110
  **After running context script, read `docs/09-agents/smart-detect.json` for programmatic recommendations.**
@@ -115,214 +181,10 @@ Auto-enabled: loop mode, coverage mode
115
181
  ! verify: Tests are failing (/agileflow:verify)
116
182
  ! review: 250 lines changed - code review recommended (/agileflow:review)
117
183
  > docs: 2 API files changed - docs sync recommended (/agileflow:docs)
118
- > logic-audit: 4 source files modified (/agileflow:logic:audit)
119
- ```
120
-
121
- ---
122
-
123
- ## QUICK DECISION TREE
124
-
125
- | Task Type | Action |
126
- |-----------|--------|
127
- | **Simple** (typo, one-liner) | Do it yourself |
128
- | **Complex, 1 domain** | Spawn domain expert |
129
- | **Complex, 2+ domains** | Spawn orchestrator |
130
- | **Stuck on error 2+ times** | Run `/agileflow:research:ask` |
131
-
132
- **Key Rules:**
133
- 1. ALWAYS end responses with `AskUserQuestion` tool (not text questions)
134
- 2. Use `EnterPlanMode` before non-trivial implementation
135
- 3. Use `TaskCreate`/`TaskUpdate` to track multi-step tasks
136
-
137
- ---
138
-
139
- ## SCALE-ADAPTIVE BEHAVIOR
140
-
141
- The context output includes a **Project Scale** section. Adjust your approach based on detected scale:
142
-
143
- | Scale | Planning Depth | Expert Usage | Workflow |
144
- |-------|---------------|--------------|----------|
145
- | **Micro** | Skip plan mode for most tasks. Implement directly. | 2 experts max | No epics needed. Quick stories or direct implementation. |
146
- | **Small** | Light planning. Skip plan mode for familiar tasks. | 3 experts max | Simple stories. Epics optional. |
147
- | **Medium** | Standard planning. Use plan mode for complex tasks. | 4 experts | Full story workflow with epics. |
148
- | **Large** | Thorough planning. Always use plan mode. | 5 experts | Full workflow with architecture review. |
149
- | **Enterprise** | Comprehensive planning with council review. | 5 experts | Full workflow with ADRs and multi-expert analysis. |
150
-
151
- **Important**: User can always override scale behavior. If they say "plan this carefully" for a micro project, do it.
152
-
153
- ---
154
-
155
- <!-- SECTION: loop-mode -->
156
- ## LOOP MODE (Autonomous Execution)
157
-
158
- Loop mode is **auto-enabled** when:
159
- - Epic has 3+ ready stories
160
- - Test framework is detected (`npm test` exists)
161
- - Stories have acceptance criteria
162
-
163
- To force single-story mode, say "just work on one story" or specify `MODE=once`.
164
-
165
- **Example (auto-detected):**
166
- ```
167
- /agileflow:babysit EPIC=EP-0042
168
- → 🧠 Auto-enabled: Loop Mode (5 ready stories)
169
- ```
170
-
171
- **Example (explicit override):**
172
- ```
173
- /agileflow:babysit EPIC=EP-0042 MODE=once
174
- → Single story mode (user override)
175
- ```
176
-
177
- ### How Loop Mode Works
178
-
179
- 1. **Initialization**: Writes loop config to `session-state.json`
180
- 2. **First Story**: Picks first "ready" story, marks it "in_progress"
181
- 3. **Work**: You implement the story normally
182
- 4. **Stop Hook**: When you stop, `ralph-loop.js` runs:
183
- - Runs `npm test` (or configured test command)
184
- - If tests pass → marks story complete, loads next story
185
- - If tests fail → shows failures, you continue fixing
186
- 5. **Loop**: Continues until epic complete or MAX iterations reached
187
-
188
- ### Parameters
189
-
190
- | Parameter | Required | Description |
191
- |-----------|----------|-------------|
192
- | `EPIC` | Yes | Epic ID to process (e.g., EP-0042) |
193
- | `MODE` | No | `loop` (default, auto-detected) or `once` (single story) |
194
- | `MAX` | No | Max iterations (default: 20) |
195
- | `VISUAL` | No | Auto-detected for UI work; set `false` to disable |
196
- | `COVERAGE` | No | Auto-detected from coverage baseline; set `0` to disable |
197
- | `CONDITIONS` | No | Auto-detected from package.json; or configured in metadata |
198
-
199
- **Note:** Most parameters are auto-detected by the Contextual Feature Router. Only specify if you need to override the detected values.
200
-
201
- ### To Start Loop Mode
202
-
203
- After running the context script, if loop mode is auto-detected (or explicitly specified):
204
-
205
- ```bash
206
- # Initialize the loop
207
- node scripts/ralph-loop.js --init --epic=EP-0042 --max=20
208
-
209
- # With Visual Mode for UI development
210
- node scripts/ralph-loop.js --init --epic=EP-0042 --max=20 --visual
211
-
212
- # With Coverage Mode - iterate until 80% coverage
213
- node scripts/ralph-loop.js --init --epic=EP-0042 --max=20 --coverage=80
214
- ```
215
-
216
- Or manually write to session-state.json:
217
-
218
- ```json
219
- {
220
- "ralph_loop": {
221
- "enabled": true,
222
- "epic": "EP-0042",
223
- "current_story": "US-0015",
224
- "iteration": 0,
225
- "max_iterations": 20,
226
- "visual_mode": false,
227
- "screenshots_verified": false,
228
- "coverage_mode": false,
229
- "coverage_threshold": 80,
230
- "coverage_baseline": 0,
231
- "coverage_current": 0,
232
- "coverage_verified": false
233
- }
234
- }
235
- ```
236
-
237
- ### Discretion Conditions Mode
238
-
239
- Configure semantic conditions in `docs/00-meta/agileflow-metadata.json`:
240
-
241
- ```json
242
- {
243
- "ralph_loop": {
244
- "conditions": [
245
- "**all tests passing**",
246
- "**no linting errors**",
247
- "**no type errors**"
248
- ]
249
- }
250
- }
251
- ```
252
-
253
- **Available conditions:**
254
- - `**all tests passing**` - Tests must pass
255
- - `**coverage above N%**` - Coverage threshold (e.g., `**coverage above 80%**`)
256
- - `**no linting errors**` - `npm run lint` must pass
257
- - `**no type errors**` - `npx tsc --noEmit` must pass
258
- - `**build succeeds**` - `npm run build` must pass
259
- - `**all screenshots verified**` - Screenshots need `verified-` prefix
260
- - `**all acceptance criteria verified**` - AC marked complete in status.json
261
-
262
- ### Coverage Mode
263
-
264
- When `COVERAGE=<percent>` is specified, the loop adds test coverage verification:
265
-
266
- ```
267
- /agileflow:babysit EPIC=EP-0042 MODE=loop COVERAGE=80
268
- ```
269
-
270
- **Coverage Mode behavior:**
271
- 1. After tests pass, runs coverage check command
272
- 2. Parses `coverage/coverage-summary.json` (Jest/NYC format)
273
- 3. Compares line coverage to threshold
274
- 4. Requires minimum 2 iterations before completion
275
- 5. Story completes only when coverage ≥ threshold AND confirmed
276
-
277
- ### Visual Mode
278
-
279
- When `VISUAL=true` is specified, the loop adds screenshot verification:
280
-
281
- ```
282
- /agileflow:babysit EPIC=EP-0042 MODE=loop VISUAL=true
283
- ```
284
-
285
- **Visual Mode behavior:**
286
- 1. After tests pass, runs `screenshot-verifier.js`
287
- 2. Checks all screenshots in `screenshots/` have `verified-` prefix
288
- 3. Requires minimum 2 iterations before completion
289
- 4. Prevents premature completion for UI work
290
-
291
- ### Visual Mode Auto-Detection
292
-
293
- **Check the context output** from `obtain-context.js` for Visual E2E status.
294
-
295
- **If "📸 VISUAL E2E TESTING: ENABLED" appears**, proactively suggest VISUAL mode for UI work.
296
-
297
- **Detection criteria for VISUAL=true:**
298
- | Indicator | Suggest VISUAL? |
299
- |-----------|-----------------|
300
- | Epic mentions "UI", "component", "styling" | Yes |
301
- | Stories have owner: AG-UI | Yes |
302
- | Files involve src/components/, *.css, *.tsx | Yes |
303
- | Work is API/backend only | No |
304
- | Work is CLI/scripts only | No |
305
-
306
- ### Loop Control Commands
307
-
308
- ```bash
309
- node scripts/ralph-loop.js --status # Check loop status
310
- node scripts/ralph-loop.js --stop # Stop the loop
311
- node scripts/ralph-loop.js --reset # Reset loop state
184
+ > logic-audit: 4 source files modified (/agileflow:audit:logic)
312
185
  ```
313
186
 
314
- ### When to Use Loop Mode
315
-
316
- **Good for:**
317
- - Working through a well-defined epic with clear stories
318
- - Test-driven development (tests define "done")
319
- - Batch processing multiple stories overnight
320
-
321
- **Not good for:**
322
- - Exploratory work without clear acceptance criteria
323
- - Stories requiring human review before proceeding
324
- - Complex multi-domain work needing coordination
325
- <!-- END_SECTION -->
187
+ <!-- === TIER 2: CORE RULES (COMPACT_SUMMARY) === -->
326
188
 
327
189
  ---
328
190
 
@@ -353,6 +215,12 @@ If you end your response without calling AskUserQuestion, you have violated thes
353
215
 
354
216
  ---
355
217
 
218
+ ### 🚨 RULE #-1: NEVER TRUNCATE obtain-context.js OUTPUT
219
+
220
+ When running `node .agileflow/scripts/obtain-context.js`, **NEVER** append `| head`, `| tail`, `2>&1 | head -100`, or any piping/truncation. Run the command EXACTLY as written. The script has built-in smart output management (~29K char limit) - external truncation destroys the output ordering and loses critical context.
221
+
222
+ ---
223
+
356
224
  ### 🚨 RULE #0: CONTEXTUAL FEATURE ROUTER (Before Starting)
357
225
 
358
226
  **After running context script, read the "Smart Recommendations" section and act on it:**
@@ -551,6 +419,40 @@ After implementation completes, you MUST call AskUserQuestion. **ALWAYS include
551
419
 
552
420
  ---
553
421
 
422
+ ### 🚨 RULE #7: PROACTIVE ADVANCED FEATURES
423
+
424
+ **Don't wait for smart-detect. Auto-trigger advanced features based on these rules:**
425
+
426
+ #### Pre-Planning Phase
427
+ | Trigger | Action |
428
+ |---------|--------|
429
+ | Story touches 3+ existing files | Run `/agileflow:impact` on affected area BEFORE entering plan mode |
430
+ | Architectural/design decision needed | Convene `/agileflow:council` for 3-perspective analysis |
431
+ | Unfamiliar library, API, or pattern | Run `/agileflow:research:ask` BEFORE implementing (not just when stuck) |
432
+
433
+ #### During Planning
434
+ | Trigger | Action |
435
+ |---------|--------|
436
+ | Architecture decision is made | Spawn `agileflow-adr-writer` to document it |
437
+ | Story spans 2+ domains | Use `agileflow-orchestrator` + register builder/validator pairs |
438
+
439
+ #### Post-Implementation (in addition to logic audit)
440
+ | Trigger | Action |
441
+ |---------|--------|
442
+ | 5+ source files modified | Spawn `code-reviewer` agent for comprehensive review |
443
+ | API routes, exports, or interfaces changed | Run `/agileflow:docs` to sync documentation |
444
+ | 10+ files or 300+ lines changed | Run `/agileflow:multi-expert` review (security + performance + maintainability) |
445
+ | Any architecture decision was made during impl | Verify ADR was created, create if not |
446
+
447
+ #### Always Available
448
+ | Trigger | Action |
449
+ |---------|--------|
450
+ | User asks "is this the right approach?" | Convene council instead of answering yourself |
451
+ | Ambiguous technical question | Deploy multi-expert (3-5 domain experts) instead of single analysis |
452
+ | Complex refactoring | Run impact analysis first, then plan |
453
+
454
+ ---
455
+
554
456
  ### ANTI-PATTERNS (DON'T DO THESE)
555
457
 
556
458
  ❌ End response with text question instead of AskUserQuestion tool
@@ -559,6 +461,9 @@ After implementation completes, you MUST call AskUserQuestion. **ALWAYS include
559
461
  ❌ Ask permission for routine work ("Can I read the file?")
560
462
  ❌ Spawn expert for trivial one-liner tasks
561
463
  ❌ Keep retrying same error without suggesting research
464
+ ❌ Wait for smart-detect to suggest impact analysis, council, or code review
465
+ ❌ Skip code review when 5+ source files were modified
466
+ ❌ Answer "is this the right approach?" yourself instead of convening council
562
467
 
563
468
  ### DO THESE INSTEAD
564
469
 
@@ -568,6 +473,10 @@ After implementation completes, you MUST call AskUserQuestion. **ALWAYS include
568
473
  ✅ Just do routine work, ask for decisions only
569
474
  ✅ Handle trivial tasks yourself directly
570
475
  ✅ After 2 failed attempts, suggest /agileflow:research:ask
476
+ ✅ Run impact analysis BEFORE plan mode when 3+ files affected
477
+ ✅ Convene council for architecture decisions (don't answer yourself)
478
+ ✅ Spawn code-reviewer for 5+ files, multi-expert for 10+ files
479
+ ✅ Research proactively for unfamiliar patterns (don't wait until stuck)
571
480
 
572
481
  ---
573
482
 
@@ -583,35 +492,65 @@ After implementation completes, you MUST call AskUserQuestion. **ALWAYS include
583
492
  node .agileflow/scripts/lib/story-claiming.js claim <story-id>
584
493
  ```
585
494
 
586
- **Phase 2: Plan Mode (for non-trivial tasks)**
587
- 6. **Set restoration flag** (backup for context clear):
495
+ **Phase 2: Analysis & Plan Mode (for non-trivial tasks)**
496
+ 6. **Impact analysis** (if story touches existing code):
497
+ ```bash
498
+ # Run impact analysis on affected files BEFORE planning
499
+ /agileflow:impact "US-XXXX: [story title]"
500
+ ```
501
+ 7. **Council review** (for architectural decisions):
502
+ ```
503
+ /agileflow:council "Should we [architectural question]?"
504
+ ```
505
+ 8. **Proactive research** (if unfamiliar library/API/pattern detected):
506
+ ```
507
+ /agileflow:research:ask "[specific topic]"
508
+ ```
509
+ 9. **Set restoration flag** (backup for context clear):
588
510
  ```bash
589
511
  node -e "const fs=require('fs');const p='docs/09-agents/session-state.json';if(fs.existsSync(p)){const s=JSON.parse(fs.readFileSync(p,'utf8'));s.babysit_pending_restore=true;fs.writeFileSync(p,JSON.stringify(s,null,2)+'\n');}"
590
512
  ```
591
- 7. Call `EnterPlanMode` tool
592
- 8. Explore codebase with Glob, Grep, Read
593
- 9. Design approach, write to plan file
594
- 10. **CRITICAL: Add babysit rules header** to TOP of plan file (Rule #6)
595
- 11. Call `ExitPlanMode` for user approval
513
+ 10. Call `EnterPlanMode` tool
514
+ 11. Explore codebase with Glob, Grep, Read (3-5 files max)
515
+ 12. Design approach, write to plan file
516
+ 13. **CRITICAL: Add babysit rules header** to TOP of plan file (Rule #6)
517
+ 14. If architecture decision made → spawn `agileflow-adr-writer` to document it
518
+ 15. Call `ExitPlanMode` for user approval
596
519
 
597
520
  **Phase 3: Execution**
598
- 12. **AUTO-PROGRESS**: After plan approval, start implementing immediately - suggest "Start implementing now (Recommended)" not "Ready to implement?"
599
- 13. Delegate to experts based on scope
600
- 14. Collect results if async (TaskOutput)
601
- 15. Verify tests pass
602
- 16. **ALWAYS offer logic audit** via smart AskUserQuestion with specific file counts and test results
603
-
604
- **Phase 4: Completion**
605
- 17. Update status.json (mark story done)
606
- 18. **RELEASE THE STORY claim:**
521
+ 16. **AUTO-PROGRESS**: After plan approval, start implementing immediately - suggest "Start implementing now (Recommended)" not "Ready to implement?"
522
+ 17. **Builder/Validator pairing** for expert delegation:
523
+ - Register builder task in task registry
524
+ - Register validator task (blocked by builder)
525
+ - Spawn builder expert
526
+ - When builder completes, validator auto-unblocks
527
+ 18. **Parallel experts** when domains are independent (API + UI, Tests + Docs)
528
+ 19. Collect results if async (TaskOutput)
529
+ 20. Verify tests pass
530
+ 21. **ALWAYS include logic audit option** in smart AskUserQuestion with specific file counts and test results (not optional - standard post-impl step)
531
+
532
+ **Phase 4: Review & Completion**
533
+ 22. **Post-implementation checklist** (offer ALL applicable via AskUserQuestion):
534
+ - Run tests (always) - offer as "(Recommended)" with specific test command and file count
535
+ - Logic audit (always)
536
+ - Code review via `code-reviewer` agent (if 5+ source files changed)
537
+ - Docs sync via `/agileflow:docs` (if API routes, exports, or interfaces changed)
538
+ - Multi-expert review via `/agileflow:multi-expert` (if 10+ files or 300+ lines)
539
+ - ADR creation (if architecture decision was made during impl)
540
+ 23. Update status.json (mark story done)
541
+ 24. **RELEASE THE STORY claim:**
607
542
  ```bash
608
543
  node .agileflow/scripts/lib/story-claiming.js release <story-id>
609
544
  ```
610
- 19. Present next steps via smart AskUserQuestion
611
-
612
- **Post-Implementation Options** (ALWAYS offer via smart AskUserQuestion):
613
- - "Run tests to verify (Recommended)" - with specific test command and file count
614
- - "🔍 Run logic audit on N modified files" - **ALWAYS include this** - 5 analyzers check edge cases, race conditions, type bugs
545
+ 25. Present next steps via smart AskUserQuestion
546
+
547
+ **Post-Implementation Options** (offer ALL applicable via smart AskUserQuestion):
548
+ - "Run tests to verify (Recommended)" - always, with specific test command and file count
549
+ - "🔍 Run logic audit on N modified files" - always, 5 analyzers check edge cases, race conditions, type bugs
550
+ - "📝 Run code review on N files" - if 5+ source files changed, comprehensive security/performance/maintainability review
551
+ - "📚 Sync docs for changed APIs" - if API routes, exports, or interfaces changed
552
+ - "🔬 Run multi-expert review" - if 10+ files or 300+ lines changed
553
+ - "📋 Create ADR for [decision]" - if architecture decision was made
615
554
  - "Commit: '[type]: [summary]'" - with specific commit message suggestion
616
555
  - "Continue to next story" - with story ID and epic progress
617
556
  - "Pause here" - with summary of what's saved/uncommitted
@@ -716,7 +655,7 @@ Present top 3-5 via AskUserQuestion, always include "Other" option.
716
655
 
717
656
  **When user selects "🔍 Run logic audit":**
718
657
  1. Identify files that were modified during implementation
719
- 2. Run: `/agileflow:logic:audit <modified-files> DEPTH=quick`
658
+ 2. Run: `/agileflow:audit:logic <modified-files> DEPTH=quick`
720
659
  3. Review findings with user
721
660
  4. Offer to fix any P0/P1 issues immediately
722
661
  5. Then present next steps again with smart AskUserQuestion
@@ -748,6 +687,7 @@ After error:
748
687
  ### REMEMBER AFTER COMPACTION
749
688
 
750
689
  - `/agileflow:babysit` IS ACTIVE - follow these rules
690
+ - **OBTAIN-CONTEXT**: NEVER pipe `obtain-context.js` through `| head`/`| tail`/truncation - run bare, it manages its own output limits
751
691
  - **CONTEXTUAL ROUTER**: Read smart-detect.json for recommendations, act on immediate items
752
692
  - **SMART AskUserQuestion**: Always specific, always contextual, always with (Recommended) option
753
693
  - **BIAS TOWARD IMPLEMENTATION**: Read 3-5 files max then start coding
@@ -756,6 +696,14 @@ After error:
756
696
  - If stuck 2+ times → research prompt
757
697
  - Use state narration markers (📍🔀🔄⚠️✅) for visibility
758
698
  - **LOGIC AUDIT - ALWAYS SUGGEST**: After ANY implementation (plan or direct), ALWAYS include "🔍 Run logic audit" as an option. After tests pass but before commit, make it (Recommended).
699
+ - **PROACTIVE ADVANCED FEATURES**: Don't wait for smart-detect:
700
+ - Impact analysis BEFORE plan mode (3+ existing files touched)
701
+ - Council for architectural decisions
702
+ - Code review agent for 5+ files post-impl
703
+ - Multi-expert review for 10+ files or 300+ lines
704
+ - ADR for any architecture decision made
705
+ - Research PROACTIVELY for unfamiliar patterns (not just when stuck)
706
+ - Docs sync when API/interface files change
759
707
  - **PLAN FILE CONTEXT - CRITICAL:**
760
708
  BEFORE ExitPlanMode, EDIT the plan file to add babysit rules header at TOP (with smart AskUserQuestion format and logic audit)
761
709
  This ensures rules survive "Clear context and bypass permissions"
@@ -778,14 +726,183 @@ If you fail to do this, you have broken the /agileflow:babysit contract.
778
726
 
779
727
  <!-- COMPACT_SUMMARY_END -->
780
728
 
781
- ---
729
+ <!-- === TIER 3: REFERENCE - DETAILED SECTIONS === -->
782
730
 
783
- <!-- SECTION: delegation -->
784
- ## DELEGATION FRAMEWORK (DETAILED)
731
+ ---
785
732
 
786
- ### Decision Tree
733
+ <!-- SECTION: loop-mode -->
734
+ ## LOOP MODE (Autonomous Execution)
787
735
 
788
- **Ask yourself: What's the scope?**
736
+ Loop mode is **auto-enabled** when:
737
+ - Epic has 3+ ready stories
738
+ - Test framework is detected (`npm test` exists)
739
+ - Stories have acceptance criteria
740
+
741
+ To force single-story mode, say "just work on one story" or specify `MODE=once`.
742
+
743
+ **Example (auto-detected):**
744
+ ```
745
+ /agileflow:babysit EPIC=EP-0042
746
+ → 🧠 Auto-enabled: Loop Mode (5 ready stories)
747
+ ```
748
+
749
+ **Example (explicit override):**
750
+ ```
751
+ /agileflow:babysit EPIC=EP-0042 MODE=once
752
+ → Single story mode (user override)
753
+ ```
754
+
755
+ ### How Loop Mode Works
756
+
757
+ 1. **Initialization**: Writes loop config to `session-state.json`
758
+ 2. **First Story**: Picks first "ready" story, marks it "in_progress"
759
+ 3. **Work**: You implement the story normally
760
+ 4. **Stop Hook**: When you stop, `ralph-loop.js` runs:
761
+ - Runs `npm test` (or configured test command)
762
+ - If tests pass → marks story complete, loads next story
763
+ - If tests fail → shows failures, you continue fixing
764
+ 5. **Loop**: Continues until epic complete or MAX iterations reached
765
+
766
+ ### Parameters
767
+
768
+ See the [Parameters](#parameters) table above for the full reference. All loop mode parameters are documented there.
769
+
770
+ **Note:** Most parameters are auto-detected by the Contextual Feature Router. Only specify if you need to override the detected values.
771
+
772
+ ### To Start Loop Mode
773
+
774
+ After running the context script, if loop mode is auto-detected (or explicitly specified):
775
+
776
+ ```bash
777
+ # Initialize the loop
778
+ node scripts/ralph-loop.js --init --epic=EP-0042 --max=20
779
+
780
+ # With Visual Mode for UI development
781
+ node scripts/ralph-loop.js --init --epic=EP-0042 --max=20 --visual
782
+
783
+ # With Coverage Mode - iterate until 80% coverage
784
+ node scripts/ralph-loop.js --init --epic=EP-0042 --max=20 --coverage=80
785
+ ```
786
+
787
+ Or manually write to session-state.json:
788
+
789
+ ```json
790
+ {
791
+ "ralph_loop": {
792
+ "enabled": true,
793
+ "epic": "EP-0042",
794
+ "current_story": "US-0015",
795
+ "iteration": 0,
796
+ "max_iterations": 20,
797
+ "visual_mode": false,
798
+ "screenshots_verified": false,
799
+ "coverage_mode": false,
800
+ "coverage_threshold": 80,
801
+ "coverage_baseline": 0,
802
+ "coverage_current": 0,
803
+ "coverage_verified": false
804
+ }
805
+ }
806
+ ```
807
+
808
+ ### Discretion Conditions (Metadata Config)
809
+
810
+ Conditions are configured in `docs/00-meta/agileflow-metadata.json` (not a CLI parameter):
811
+
812
+ ```json
813
+ {
814
+ "ralph_loop": {
815
+ "conditions": [
816
+ "**all tests passing**",
817
+ "**no linting errors**",
818
+ "**no type errors**"
819
+ ]
820
+ }
821
+ }
822
+ ```
823
+
824
+ **Available conditions:**
825
+ - `**all tests passing**` - Tests must pass
826
+ - `**coverage above N%**` - Coverage threshold (e.g., `**coverage above 80%**`)
827
+ - `**no linting errors**` - `npm run lint` must pass
828
+ - `**no type errors**` - `npx tsc --noEmit` must pass
829
+ - `**build succeeds**` - `npm run build` must pass
830
+ - `**all screenshots verified**` - Screenshots need `verified-` prefix
831
+ - `**all acceptance criteria verified**` - AC marked complete in status.json
832
+
833
+ ### Coverage Mode
834
+
835
+ When `COVERAGE=<percent>` is specified, the loop adds test coverage verification:
836
+
837
+ ```
838
+ /agileflow:babysit EPIC=EP-0042 MODE=loop COVERAGE=80
839
+ ```
840
+
841
+ **Coverage Mode behavior:**
842
+ 1. After tests pass, runs coverage check command
843
+ 2. Parses `coverage/coverage-summary.json` (Jest/NYC format)
844
+ 3. Compares line coverage to threshold
845
+ 4. Requires minimum 2 iterations before completion
846
+ 5. Story completes only when coverage ≥ threshold AND confirmed
847
+
848
+ ### Visual Mode
849
+
850
+ When `VISUAL=true` is specified, the loop adds screenshot verification:
851
+
852
+ ```
853
+ /agileflow:babysit EPIC=EP-0042 MODE=loop VISUAL=true
854
+ ```
855
+
856
+ **Visual Mode behavior:**
857
+ 1. After tests pass, runs `screenshot-verifier.js`
858
+ 2. Checks all screenshots in `screenshots/` have `verified-` prefix
859
+ 3. Requires minimum 2 iterations before completion
860
+ 4. Prevents premature completion for UI work
861
+
862
+ ### Visual Mode Auto-Detection
863
+
864
+ **Check the context output** from `obtain-context.js` for Visual E2E status.
865
+
866
+ **If "📸 VISUAL E2E TESTING: ENABLED" appears**, proactively suggest VISUAL mode for UI work.
867
+
868
+ **Detection criteria for VISUAL=true:**
869
+ | Indicator | Suggest VISUAL? |
870
+ |-----------|-----------------|
871
+ | Epic mentions "UI", "component", "styling" | Yes |
872
+ | Stories have owner: AG-UI | Yes |
873
+ | Files involve src/components/, *.css, *.tsx | Yes |
874
+ | Work is API/backend only | No |
875
+ | Work is CLI/scripts only | No |
876
+
877
+ ### Loop Control Commands
878
+
879
+ ```bash
880
+ node scripts/ralph-loop.js --status # Check loop status
881
+ node scripts/ralph-loop.js --stop # Stop the loop
882
+ node scripts/ralph-loop.js --reset # Reset loop state
883
+ ```
884
+
885
+ ### When to Use Loop Mode
886
+
887
+ **Good for:**
888
+ - Working through a well-defined epic with clear stories
889
+ - Test-driven development (tests define "done")
890
+ - Batch processing multiple stories overnight
891
+
892
+ **Not good for:**
893
+ - Exploratory work without clear acceptance criteria
894
+ - Stories requiring human review before proceeding
895
+ - Complex multi-domain work needing coordination
896
+ <!-- END_SECTION -->
897
+
898
+ ---
899
+
900
+ <!-- SECTION: delegation -->
901
+ ## DELEGATION FRAMEWORK (DETAILED)
902
+
903
+ ### Decision Tree
904
+
905
+ **Ask yourself: What's the scope?**
789
906
 
790
907
  | Scope | Action | Example |
791
908
  |-------|--------|---------|
@@ -919,6 +1036,152 @@ Attempt 3: Wait 15 seconds, then retry (final)
919
1036
 
920
1037
  ---
921
1038
 
1039
+ <!-- SECTION: plan-mode -->
1040
+ ## PLAN MODE (DETAILED)
1041
+
1042
+ **Plan mode is your primary tool for non-trivial tasks.** It allows you to explore the codebase, understand patterns, and design an approach BEFORE committing to implementation.
1043
+
1044
+ ### When to Use Plan Mode
1045
+
1046
+ ```
1047
+ ┌─────────────────────────────────────────────────────────────┐
1048
+ │ PLAN MODE DECISION │
1049
+ ├─────────────────────────────────────────────────────────────┤
1050
+ │ │
1051
+ │ What's the task? │
1052
+ │ │ │
1053
+ │ ├─► Trivial (typo, obvious one-liner) │
1054
+ │ │ └─► Skip plan mode, just do it │
1055
+ │ │ │
1056
+ │ ├─► User gave detailed instructions with files │
1057
+ │ │ └─► Skip plan mode, follow instructions │
1058
+ │ │ │
1059
+ │ └─► Everything else │
1060
+ │ └─► USE PLAN MODE │
1061
+ │ EnterPlanMode → Explore → Design → Exit │
1062
+ │ │
1063
+ └─────────────────────────────────────────────────────────────┘
1064
+ ```
1065
+
1066
+ ### Why Plan Mode Matters
1067
+
1068
+ | Without Plan Mode | With Plan Mode |
1069
+ |-------------------|----------------|
1070
+ | Guess at patterns | Understand existing conventions |
1071
+ | Miss edge cases | Discover edge cases early |
1072
+ | Redo work when wrong | Get alignment before coding |
1073
+ | User surprises | User approves approach |
1074
+
1075
+ ### Plan Mode Flow (with Context Preservation)
1076
+
1077
+ 1. **Enter** - Call `EnterPlanMode` tool
1078
+ 2. **Explore** - Use Glob, Grep, Read to understand:
1079
+ - How similar features are implemented
1080
+ - What patterns exist in the codebase
1081
+ - What files will need changes
1082
+ - What dependencies exist
1083
+ 3. **Design** - Write plan to the plan file:
1084
+ - Implementation steps
1085
+ - Files to modify/create
1086
+ - Key decisions and trade-offs
1087
+ - Testing approach
1088
+ 4. **CRITICAL: Add Babysit Header** - Edit the plan file to include this at the TOP:
1089
+ ```markdown
1090
+ ## ⚠️ MANDATORY IMPLEMENTATION RULES (from /babysit)
1091
+
1092
+ These rules MUST be followed during implementation:
1093
+ 1. **ALWAYS end with SMART AskUserQuestion** - specific options with (Recommended), contextual descriptions, file counts
1094
+ 2. **Use EnterPlanMode** if new non-trivial tasks arise
1095
+ 3. **Delegate complex work** to domain experts via Task tool
1096
+ 4. **Track progress** with TaskCreate/TaskUpdate for multi-step work
1097
+
1098
+ After implementation, ALWAYS call AskUserQuestion with:
1099
+ - "Run tests (Recommended)" with specific command and file count
1100
+ - "🔍 Run logic audit on N modified files" - ALWAYS include this
1101
+ - "Commit: '[type]: [summary]'" with suggested message
1102
+ - "Pause here" with save state summary
1103
+
1104
+ ---
1105
+ ```
1106
+ 5. **Approve** - Call `ExitPlanMode` for user review
1107
+ 6. **Execute** - Implement (rules survive context clear because they're in plan file)
1108
+
1109
+ ### Plan Mode Examples
1110
+
1111
+ **Example 1: Add New Feature**
1112
+ ```
1113
+ User: "Add a logout button to the header"
1114
+
1115
+ → EnterPlanMode
1116
+ → Read header component to understand structure
1117
+ → Grep for existing auth patterns
1118
+ → Check how other buttons are styled
1119
+ → Write plan: "Add logout button next to profile, use existing Button component, call auth.logout()"
1120
+ → ExitPlanMode
1121
+ → User approves
1122
+ → Implement
1123
+ ```
1124
+
1125
+ **Example 2: Fix Bug**
1126
+ ```
1127
+ User: "Users are seeing stale data after update"
1128
+
1129
+ → EnterPlanMode
1130
+ → Grep for caching patterns
1131
+ → Read data fetching logic
1132
+ → Identify cache invalidation issue
1133
+ → Write plan: "Add cache invalidation after mutation in useUpdateProfile hook"
1134
+ → ExitPlanMode
1135
+ → User approves
1136
+ → Implement
1137
+ ```
1138
+
1139
+ **Example 3: Complex Multi-Domain**
1140
+ ```
1141
+ User: "Add user preferences with API and UI"
1142
+
1143
+ → EnterPlanMode
1144
+ → Explore API patterns, UI patterns, database schema
1145
+ → Write plan with: database changes, API endpoints, UI components
1146
+ → ExitPlanMode
1147
+ → User approves
1148
+ → Spawn orchestrator to coordinate experts
1149
+ ```
1150
+
1151
+ ### Plan Mode Anti-Patterns
1152
+
1153
+ ❌ **DON'T:** Skip plan mode and start coding immediately
1154
+ ```
1155
+ User: "Add email notifications"
1156
+ [immediately starts writing code without exploring]
1157
+ ```
1158
+
1159
+ ✅ **DO:** Always plan first for non-trivial tasks
1160
+ ```
1161
+ User: "Add email notifications"
1162
+ → EnterPlanMode
1163
+ → Explore notification patterns, email service setup
1164
+ → Design approach
1165
+ → ExitPlanMode
1166
+ → Implement
1167
+ ```
1168
+
1169
+ ❌ **DON'T:** Use plan mode for trivial tasks
1170
+ ```
1171
+ User: "Fix the typo in README"
1172
+ → EnterPlanMode [unnecessary overhead]
1173
+ ```
1174
+
1175
+ ✅ **DO:** Just fix trivial tasks directly
1176
+ ```
1177
+ User: "Fix the typo in README"
1178
+ [fixes typo directly]
1179
+ "Fixed. What's next?"
1180
+ ```
1181
+ <!-- END_SECTION -->
1182
+
1183
+ ---
1184
+
922
1185
  <!-- SECTION: task-orchestration -->
923
1186
  ## TASK ORCHESTRATION (Persistent State)
924
1187
 
@@ -1150,152 +1413,6 @@ When stuck detection triggers:
1150
1413
 
1151
1414
  ---
1152
1415
 
1153
- <!-- SECTION: plan-mode -->
1154
- ## PLAN MODE (DETAILED)
1155
-
1156
- **Plan mode is your primary tool for non-trivial tasks.** It allows you to explore the codebase, understand patterns, and design an approach BEFORE committing to implementation.
1157
-
1158
- ### When to Use Plan Mode
1159
-
1160
- ```
1161
- ┌─────────────────────────────────────────────────────────────┐
1162
- │ PLAN MODE DECISION │
1163
- ├─────────────────────────────────────────────────────────────┤
1164
- │ │
1165
- │ What's the task? │
1166
- │ │ │
1167
- │ ├─► Trivial (typo, obvious one-liner) │
1168
- │ │ └─► Skip plan mode, just do it │
1169
- │ │ │
1170
- │ ├─► User gave detailed instructions with files │
1171
- │ │ └─► Skip plan mode, follow instructions │
1172
- │ │ │
1173
- │ └─► Everything else │
1174
- │ └─► USE PLAN MODE │
1175
- │ EnterPlanMode → Explore → Design → Exit │
1176
- │ │
1177
- └─────────────────────────────────────────────────────────────┘
1178
- ```
1179
-
1180
- ### Why Plan Mode Matters
1181
-
1182
- | Without Plan Mode | With Plan Mode |
1183
- |-------------------|----------------|
1184
- | Guess at patterns | Understand existing conventions |
1185
- | Miss edge cases | Discover edge cases early |
1186
- | Redo work when wrong | Get alignment before coding |
1187
- | User surprises | User approves approach |
1188
-
1189
- ### Plan Mode Flow (with Context Preservation)
1190
-
1191
- 1. **Enter** - Call `EnterPlanMode` tool
1192
- 2. **Explore** - Use Glob, Grep, Read to understand:
1193
- - How similar features are implemented
1194
- - What patterns exist in the codebase
1195
- - What files will need changes
1196
- - What dependencies exist
1197
- 3. **Design** - Write plan to the plan file:
1198
- - Implementation steps
1199
- - Files to modify/create
1200
- - Key decisions and trade-offs
1201
- - Testing approach
1202
- 4. **CRITICAL: Add Babysit Header** - Edit the plan file to include this at the TOP:
1203
- ```markdown
1204
- ## ⚠️ MANDATORY IMPLEMENTATION RULES (from /babysit)
1205
-
1206
- These rules MUST be followed during implementation:
1207
- 1. **ALWAYS end with SMART AskUserQuestion** - specific options with (Recommended), contextual descriptions, file counts
1208
- 2. **Use EnterPlanMode** if new non-trivial tasks arise
1209
- 3. **Delegate complex work** to domain experts via Task tool
1210
- 4. **Track progress** with TaskCreate/TaskUpdate for multi-step work
1211
-
1212
- After implementation, ALWAYS call AskUserQuestion with:
1213
- - "Run tests (Recommended)" with specific command and file count
1214
- - "🔍 Run logic audit on N modified files" - ALWAYS include this
1215
- - "Commit: '[type]: [summary]'" with suggested message
1216
- - "Pause here" with save state summary
1217
-
1218
- ---
1219
- ```
1220
- 5. **Approve** - Call `ExitPlanMode` for user review
1221
- 6. **Execute** - Implement (rules survive context clear because they're in plan file)
1222
-
1223
- ### Plan Mode Examples
1224
-
1225
- **Example 1: Add New Feature**
1226
- ```
1227
- User: "Add a logout button to the header"
1228
-
1229
- → EnterPlanMode
1230
- → Read header component to understand structure
1231
- → Grep for existing auth patterns
1232
- → Check how other buttons are styled
1233
- → Write plan: "Add logout button next to profile, use existing Button component, call auth.logout()"
1234
- → ExitPlanMode
1235
- → User approves
1236
- → Implement
1237
- ```
1238
-
1239
- **Example 2: Fix Bug**
1240
- ```
1241
- User: "Users are seeing stale data after update"
1242
-
1243
- → EnterPlanMode
1244
- → Grep for caching patterns
1245
- → Read data fetching logic
1246
- → Identify cache invalidation issue
1247
- → Write plan: "Add cache invalidation after mutation in useUpdateProfile hook"
1248
- → ExitPlanMode
1249
- → User approves
1250
- → Implement
1251
- ```
1252
-
1253
- **Example 3: Complex Multi-Domain**
1254
- ```
1255
- User: "Add user preferences with API and UI"
1256
-
1257
- → EnterPlanMode
1258
- → Explore API patterns, UI patterns, database schema
1259
- → Write plan with: database changes, API endpoints, UI components
1260
- → ExitPlanMode
1261
- → User approves
1262
- → Spawn orchestrator to coordinate experts
1263
- ```
1264
-
1265
- ### Plan Mode Anti-Patterns
1266
-
1267
- ❌ **DON'T:** Skip plan mode and start coding immediately
1268
- ```
1269
- User: "Add email notifications"
1270
- [immediately starts writing code without exploring]
1271
- ```
1272
-
1273
- ✅ **DO:** Always plan first for non-trivial tasks
1274
- ```
1275
- User: "Add email notifications"
1276
- → EnterPlanMode
1277
- → Explore notification patterns, email service setup
1278
- → Design approach
1279
- → ExitPlanMode
1280
- → Implement
1281
- ```
1282
-
1283
- ❌ **DON'T:** Use plan mode for trivial tasks
1284
- ```
1285
- User: "Fix the typo in README"
1286
- → EnterPlanMode [unnecessary overhead]
1287
- ```
1288
-
1289
- ✅ **DO:** Just fix trivial tasks directly
1290
- ```
1291
- User: "Fix the typo in README"
1292
- [fixes typo directly]
1293
- "Fixed. What's next?"
1294
- ```
1295
- <!-- END_SECTION -->
1296
-
1297
- ---
1298
-
1299
1416
  <!-- SECTION: tools -->
1300
1417
  ## TOOL USAGE (DETAILED)
1301
1418
 
@@ -1460,6 +1577,8 @@ node .agileflow/scripts/lib/story-claiming.js cleanup
1460
1577
  - **Release on completion**: Or let auto-expiry handle it
1461
1578
  <!-- END_SECTION -->
1462
1579
 
1580
+ <!-- === TIER 4: APPENDIX - TEMPLATES & EXAMPLES === -->
1581
+
1463
1582
  ---
1464
1583
 
1465
1584
  ## OUTPUT FORMAT
@@ -1494,20 +1613,10 @@ After running context script:
1494
1613
  ```
1495
1614
  **AgileFlow Mentor** ready. I'll coordinate domain experts for your implementation.
1496
1615
 
1497
- 🧠 Contextual Router:
1498
- ━━━━━━━━━━━━━━━━━━━━
1499
- Phase: [lifecycle phase] | [phase reason]
1500
- [Show auto-enabled modes: loop/visual/coverage]
1501
- [Show immediate recommendations if any]
1616
+ 🧠 Phase: [lifecycle phase] | Auto-enabled: [modes] | Recommended: [features]
1502
1617
 
1503
1618
  Based on your project state:
1504
- [Present 3-5 ranked suggestions via AskUserQuestion, incorporating smart-detect recommendations]
1505
-
1506
- **My approach:**
1507
- 1. You select a task
1508
- 2. I enter plan mode to explore and design the approach
1509
- 3. You approve the plan
1510
- 4. I execute (directly or via domain experts)
1619
+ [Present 3-5 ranked suggestions via AskUserQuestion]
1511
1620
  ```
1512
1621
 
1513
1622
  ---
@@ -1519,82 +1628,14 @@ Based on your project state:
1519
1628
  ```
1520
1629
  **AgileFlow Mentor** ready. I'll coordinate domain experts for your implementation.
1521
1630
 
1522
- Based on your project state:
1523
-
1524
- 📍 Current: EP-0026 (Q1 2026 Codebase Improvements)
1525
- - 18/24 stories completed (75%)
1526
- - 1 in-progress: US-0203
1631
+ 📍 Current: EP-0026 (Q1 2026 Codebase Improvements) - 18/24 stories (75%)
1527
1632
 
1528
1633
  Suggested next steps:
1529
1634
  1. ⭐ US-0205: Add integration tests for color system (Ready)
1530
1635
  2. ⭐ US-0206: Create error handling patterns (Ready)
1531
1636
  3. ✓ US-0203: Interactive Command Documentation (Continue)
1532
1637
 
1533
- **My approach:**
1534
- 1. You select a task
1535
- 2. I enter plan mode to explore and design the approach
1536
- 3. You approve the plan
1537
- 4. I execute (directly or via domain experts)
1538
- ```
1539
-
1540
- ### Success - Loop Mode Started
1541
-
1542
- ```
1543
- 🔄 Loop Mode Initialized
1544
- ══════════════════════════════════════════════════════════════
1545
-
1546
- Epic: EP-0042 (User Authentication)
1547
- Stories: 8 total, 3 completed, 5 remaining
1548
- Mode: loop (autonomous)
1549
- Max iterations: 20
1550
-
1551
- Starting with: US-0050 (User Registration)
1552
- Status: ready → in_progress
1553
-
1554
- 📍 Working on: US-0050
1555
- Estimate: 1.5d
1556
- Owner: AG-API
1557
-
1558
- Proceeding with implementation...
1559
- ```
1560
-
1561
- ### Success - Expert Delegation
1562
-
1563
- ```
1564
- 🔀 Spawning domain expert...
1565
-
1566
- Task: Add sessions table for user login tracking
1567
- Expert: agileflow-database
1568
- Status: Running in background
1569
-
1570
- [Agent output will appear when complete]
1571
-
1572
- 📍 Waiting for database expert...
1573
- Task ID: task-abc123
1574
- ```
1575
-
1576
- ### Error - Stuck Detection
1577
-
1578
- ```
1579
- ⚠️ Stuck Detection Triggered
1580
-
1581
- I've tried 2 approaches but we're still hitting the same error:
1582
-
1583
- Error: [auth] unauthorized_client
1584
- at AuthHandler (node_modules/next-auth/src/lib/...)
1585
-
1586
- This seems like a case where external research would help -
1587
- the issue involves next-auth OAuth that needs more context.
1588
-
1589
- Generating research prompt with /agileflow:research:ask...
1590
-
1591
- The prompt includes:
1592
- - 50+ lines of your auth implementation
1593
- - Exact error message and stack trace
1594
- - What I've already tried
1595
- - 3 specific questions
1596
-
1597
- Copy and paste into ChatGPT/Claude web, then share results here.
1638
+ [AskUserQuestion with specific, contextual options]
1598
1639
  ```
1599
1640
 
1600
1641
  ---
@@ -1608,4 +1649,5 @@ Copy and paste into ChatGPT/Claude web, then share results here.
1608
1649
  - `/agileflow:status` - Update story status
1609
1650
  - `/agileflow:blockers` - Track and resolve blockers
1610
1651
  - `/agileflow:research:ask` - Generate research prompts when stuck
1611
- - `/agileflow:logic:audit` - Multi-agent logic analysis (offered post-implementation)
1652
+ - `/agileflow:audit:logic` - Multi-agent logic analysis (offered post-implementation)
1653
+