agileflow 3.3.0 → 3.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.
Files changed (210) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +6 -6
  3. package/lib/skill-loader.js +0 -1
  4. package/package.json +1 -1
  5. package/scripts/agileflow-statusline.sh +81 -0
  6. package/scripts/agileflow-welcome.js +79 -0
  7. package/scripts/claude-tmux.sh +90 -23
  8. package/scripts/claude-watchdog.sh +225 -0
  9. package/scripts/generators/agent-registry.js +14 -1
  10. package/scripts/generators/inject-babysit.js +22 -9
  11. package/scripts/generators/inject-help.js +19 -9
  12. package/scripts/lib/ac-test-matcher.js +452 -0
  13. package/scripts/lib/audit-cleanup.js +250 -0
  14. package/scripts/lib/audit-registry.js +304 -0
  15. package/scripts/lib/configure-features.js +35 -0
  16. package/scripts/lib/feature-catalog.js +3 -3
  17. package/scripts/lib/gate-enforcer.js +295 -0
  18. package/scripts/lib/model-profiles.js +118 -0
  19. package/scripts/lib/quality-gates.js +163 -0
  20. package/scripts/lib/signal-detectors.js +44 -1
  21. package/scripts/lib/skill-catalog.js +557 -0
  22. package/scripts/lib/skill-recommender.js +311 -0
  23. package/scripts/lib/status-writer.js +255 -0
  24. package/scripts/lib/story-claiming.js +128 -45
  25. package/scripts/lib/task-sync.js +32 -38
  26. package/scripts/lib/tdd-phase-manager.js +455 -0
  27. package/scripts/lib/team-events.js +34 -3
  28. package/scripts/lib/tmux-audit-monitor.js +611 -0
  29. package/scripts/lib/tmux-group-colors.js +113 -0
  30. package/scripts/lib/tool-registry.yaml +241 -0
  31. package/scripts/lib/tool-shed.js +441 -0
  32. package/scripts/messaging-bridge.js +209 -1
  33. package/scripts/native-team-observer.js +219 -0
  34. package/scripts/obtain-context.js +14 -0
  35. package/scripts/ralph-loop.js +30 -5
  36. package/scripts/smart-detect.js +21 -0
  37. package/scripts/spawn-audit-sessions.js +877 -0
  38. package/scripts/team-manager.js +56 -16
  39. package/scripts/tmux-close-windows.sh +180 -0
  40. package/src/core/agents/a11y-analyzer-aria.md +155 -0
  41. package/src/core/agents/a11y-analyzer-forms.md +162 -0
  42. package/src/core/agents/a11y-analyzer-keyboard.md +175 -0
  43. package/src/core/agents/a11y-analyzer-semantic.md +153 -0
  44. package/src/core/agents/a11y-analyzer-visual.md +158 -0
  45. package/src/core/agents/a11y-consensus.md +248 -0
  46. package/src/core/agents/ads-audit-budget.md +181 -0
  47. package/src/core/agents/ads-audit-compliance.md +169 -0
  48. package/src/core/agents/ads-audit-creative.md +164 -0
  49. package/src/core/agents/ads-audit-google.md +226 -0
  50. package/src/core/agents/ads-audit-meta.md +183 -0
  51. package/src/core/agents/ads-audit-tracking.md +197 -0
  52. package/src/core/agents/ads-consensus.md +396 -0
  53. package/src/core/agents/ads-generate.md +145 -0
  54. package/src/core/agents/ads-performance-tracker.md +197 -0
  55. package/src/core/agents/api-quality-analyzer-conventions.md +148 -0
  56. package/src/core/agents/api-quality-analyzer-docs.md +176 -0
  57. package/src/core/agents/api-quality-analyzer-errors.md +183 -0
  58. package/src/core/agents/api-quality-analyzer-pagination.md +171 -0
  59. package/src/core/agents/api-quality-analyzer-versioning.md +143 -0
  60. package/src/core/agents/api-quality-consensus.md +214 -0
  61. package/src/core/agents/arch-analyzer-circular.md +148 -0
  62. package/src/core/agents/arch-analyzer-complexity.md +171 -0
  63. package/src/core/agents/arch-analyzer-coupling.md +146 -0
  64. package/src/core/agents/arch-analyzer-layering.md +151 -0
  65. package/src/core/agents/arch-analyzer-patterns.md +162 -0
  66. package/src/core/agents/arch-consensus.md +227 -0
  67. package/src/core/agents/brainstorm-analyzer-features.md +169 -0
  68. package/src/core/agents/brainstorm-analyzer-growth.md +161 -0
  69. package/src/core/agents/brainstorm-analyzer-integration.md +172 -0
  70. package/src/core/agents/brainstorm-analyzer-market.md +147 -0
  71. package/src/core/agents/brainstorm-analyzer-ux.md +167 -0
  72. package/src/core/agents/brainstorm-consensus.md +237 -0
  73. package/src/core/agents/completeness-consensus.md +5 -5
  74. package/src/core/agents/perf-consensus.md +2 -2
  75. package/src/core/agents/security-consensus.md +2 -2
  76. package/src/core/agents/seo-analyzer-content.md +167 -0
  77. package/src/core/agents/seo-analyzer-images.md +187 -0
  78. package/src/core/agents/seo-analyzer-performance.md +206 -0
  79. package/src/core/agents/seo-analyzer-schema.md +176 -0
  80. package/src/core/agents/seo-analyzer-sitemap.md +172 -0
  81. package/src/core/agents/seo-analyzer-technical.md +144 -0
  82. package/src/core/agents/seo-consensus.md +289 -0
  83. package/src/core/agents/test-consensus.md +2 -2
  84. package/src/core/commands/adr.md +1 -0
  85. package/src/core/commands/ads/audit.md +375 -0
  86. package/src/core/commands/ads/budget.md +97 -0
  87. package/src/core/commands/ads/competitor.md +112 -0
  88. package/src/core/commands/ads/creative.md +85 -0
  89. package/src/core/commands/ads/generate.md +238 -0
  90. package/src/core/commands/ads/google.md +112 -0
  91. package/src/core/commands/ads/health.md +327 -0
  92. package/src/core/commands/ads/landing.md +119 -0
  93. package/src/core/commands/ads/linkedin.md +112 -0
  94. package/src/core/commands/ads/meta.md +91 -0
  95. package/src/core/commands/ads/microsoft.md +115 -0
  96. package/src/core/commands/ads/plan.md +321 -0
  97. package/src/core/commands/ads/test-plan.md +317 -0
  98. package/src/core/commands/ads/tiktok.md +129 -0
  99. package/src/core/commands/ads/track.md +288 -0
  100. package/src/core/commands/ads/youtube.md +124 -0
  101. package/src/core/commands/ads.md +140 -0
  102. package/src/core/commands/assign.md +1 -0
  103. package/src/core/commands/audit.md +43 -6
  104. package/src/core/commands/babysit.md +315 -1266
  105. package/src/core/commands/baseline.md +1 -0
  106. package/src/core/commands/blockers.md +1 -0
  107. package/src/core/commands/board.md +1 -0
  108. package/src/core/commands/changelog.md +1 -0
  109. package/src/core/commands/choose.md +1 -0
  110. package/src/core/commands/ci.md +1 -0
  111. package/src/core/commands/code/accessibility.md +347 -0
  112. package/src/core/commands/code/api.md +297 -0
  113. package/src/core/commands/code/architecture.md +297 -0
  114. package/src/core/commands/{audit → code}/completeness.md +72 -25
  115. package/src/core/commands/{audit → code}/legal.md +63 -16
  116. package/src/core/commands/{audit → code}/logic.md +64 -16
  117. package/src/core/commands/{audit → code}/performance.md +67 -20
  118. package/src/core/commands/{audit → code}/security.md +69 -19
  119. package/src/core/commands/{audit → code}/test.md +67 -20
  120. package/src/core/commands/configure.md +1 -0
  121. package/src/core/commands/council.md +1 -0
  122. package/src/core/commands/deploy.md +1 -0
  123. package/src/core/commands/diagnose.md +1 -0
  124. package/src/core/commands/docs.md +1 -0
  125. package/src/core/commands/epic/edit.md +213 -0
  126. package/src/core/commands/epic.md +1 -0
  127. package/src/core/commands/export.md +238 -0
  128. package/src/core/commands/help.md +16 -1
  129. package/src/core/commands/{discovery → ideate}/brief.md +12 -12
  130. package/src/core/commands/{discovery/new.md → ideate/discover.md} +20 -16
  131. package/src/core/commands/ideate/features.md +496 -0
  132. package/src/core/commands/ideate/new.md +158 -124
  133. package/src/core/commands/impact.md +1 -0
  134. package/src/core/commands/learn/explain.md +118 -0
  135. package/src/core/commands/learn/glossary.md +135 -0
  136. package/src/core/commands/learn/patterns.md +138 -0
  137. package/src/core/commands/learn/tour.md +126 -0
  138. package/src/core/commands/migrate/codemods.md +151 -0
  139. package/src/core/commands/migrate/plan.md +131 -0
  140. package/src/core/commands/migrate/scan.md +114 -0
  141. package/src/core/commands/migrate/validate.md +119 -0
  142. package/src/core/commands/multi-expert.md +1 -0
  143. package/src/core/commands/pr.md +1 -0
  144. package/src/core/commands/review.md +1 -0
  145. package/src/core/commands/seo/audit.md +373 -0
  146. package/src/core/commands/seo/competitor.md +174 -0
  147. package/src/core/commands/seo/content.md +107 -0
  148. package/src/core/commands/seo/geo.md +229 -0
  149. package/src/core/commands/seo/hreflang.md +140 -0
  150. package/src/core/commands/seo/images.md +96 -0
  151. package/src/core/commands/seo/page.md +198 -0
  152. package/src/core/commands/seo/plan.md +163 -0
  153. package/src/core/commands/seo/programmatic.md +131 -0
  154. package/src/core/commands/seo/references/cwv-thresholds.md +64 -0
  155. package/src/core/commands/seo/references/eeat-framework.md +110 -0
  156. package/src/core/commands/seo/references/quality-gates.md +91 -0
  157. package/src/core/commands/seo/references/schema-types.md +102 -0
  158. package/src/core/commands/seo/schema.md +183 -0
  159. package/src/core/commands/seo/sitemap.md +97 -0
  160. package/src/core/commands/seo/technical.md +100 -0
  161. package/src/core/commands/seo.md +107 -0
  162. package/src/core/commands/skill/list.md +68 -212
  163. package/src/core/commands/skill/recommend.md +216 -0
  164. package/src/core/commands/sprint.md +1 -0
  165. package/src/core/commands/status/undo.md +191 -0
  166. package/src/core/commands/status.md +1 -0
  167. package/src/core/commands/story/edit.md +204 -0
  168. package/src/core/commands/story/view.md +29 -7
  169. package/src/core/commands/story-validate.md +1 -0
  170. package/src/core/commands/story.md +1 -0
  171. package/src/core/commands/tdd-next.md +238 -0
  172. package/src/core/commands/tdd.md +211 -0
  173. package/src/core/commands/team/start.md +10 -6
  174. package/src/core/commands/tests.md +1 -0
  175. package/src/core/commands/verify.md +27 -1
  176. package/src/core/commands/workflow.md +2 -0
  177. package/src/core/experts/_core-expertise.yaml +105 -0
  178. package/src/core/experts/analytics/expertise.yaml +5 -99
  179. package/src/core/experts/codebase-query/expertise.yaml +3 -72
  180. package/src/core/experts/compliance/expertise.yaml +6 -72
  181. package/src/core/experts/database/expertise.yaml +9 -52
  182. package/src/core/experts/documentation/expertise.yaml +7 -140
  183. package/src/core/experts/integrations/expertise.yaml +7 -127
  184. package/src/core/experts/mentor/expertise.yaml +8 -35
  185. package/src/core/experts/monitoring/expertise.yaml +7 -49
  186. package/src/core/experts/performance/expertise.yaml +1 -26
  187. package/src/core/experts/security/expertise.yaml +9 -34
  188. package/src/core/experts/ui/expertise.yaml +6 -36
  189. package/src/core/knowledge/ads/ad-audit-checklist-scoring.md +424 -0
  190. package/src/core/knowledge/ads/ad-optimization-logic.md +590 -0
  191. package/src/core/knowledge/ads/ad-technical-specifications.md +385 -0
  192. package/src/core/knowledge/ads/definitive-advertising-reference-2026.md +506 -0
  193. package/src/core/knowledge/ads/paid-advertising-research-2026.md +445 -0
  194. package/src/core/teams/backend.json +41 -0
  195. package/src/core/teams/frontend.json +41 -0
  196. package/src/core/teams/qa.json +41 -0
  197. package/src/core/teams/solo.json +35 -0
  198. package/src/core/templates/agileflow-metadata.json +20 -1
  199. package/tools/cli/commands/setup.js +85 -3
  200. package/tools/cli/commands/update.js +42 -0
  201. package/tools/cli/installers/ide/_base-ide.js +42 -5
  202. package/tools/cli/installers/ide/claude-code.js +71 -3
  203. package/tools/cli/lib/content-injector.js +160 -12
  204. package/tools/cli/lib/docs-setup.js +1 -1
  205. package/src/core/commands/skill/create.md +0 -698
  206. package/src/core/commands/skill/delete.md +0 -316
  207. package/src/core/commands/skill/edit.md +0 -359
  208. package/src/core/commands/skill/test.md +0 -394
  209. package/src/core/commands/skill/upgrade.md +0 -552
  210. package/src/core/templates/skill-template.md +0 -117
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  description: Interactive mentor for end-to-end feature implementation
3
- argument-hint: "[EPIC=<EP-ID>] [MODE=loop|once] [VISUAL=true|false] [COVERAGE=<percent>] [MAX=<iterations>]"
3
+ phase: implementation
4
+ argument-hint: "[EPIC=<EP-ID>] [MODE=loop|once] [VISUAL=true|false] [COVERAGE=<percent>] [MAX=<iterations>] [STRICT=true|false] [TDD=true|false] [VERIFY=suggest|recommend|require|block] [CI_ROUNDS=<N>]"
4
5
  compact_context:
5
6
  priority: critical
6
7
  preserve_rules:
@@ -16,11 +17,19 @@ compact_context:
16
17
  - "LOGIC AUDIT: ALWAYS suggest '🔍 Run logic audit' after ANY implementation (plan or direct) - it's a standard post-impl step, not optional"
17
18
  - "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
19
  - "OBTAIN-CONTEXT: NEVER pipe obtain-context.js through head/tail/truncation - run it bare, it has built-in smart output limits"
20
+ - "STRICT MODE: When STRICT=true, enforce gates - hide commit option until tests pass, auto-trigger code review for 5+ files, remove skip options"
21
+ - "TDD MODE: When TDD=true, start stories in RED phase via /agileflow:tdd. Follow RED→GREEN→REFACTOR phases."
22
+ - "VERIFY MODE: suggest=current behavior, recommend=show AC summary + (Recommended) framing, require=auto-run verify + AC checklist + gate commit, block=require + browser QA for UI stories. STRICT=true implies VERIFY=require."
23
+ - "CI FEEDBACK LOOP: When tests fail, auto-retry up to CI_ROUNDS (default 3) before escalating. Uses executeCIFeedbackLoop() from quality-gates.js."
19
24
  state_fields:
20
25
  - current_story
21
26
  - current_epic
22
27
  - delegation_mode
23
28
  - claimed_story_id
29
+ - strict_mode
30
+ - tdd_mode
31
+ - verify_mode
32
+ - ci_rounds
24
33
  ---
25
34
 
26
35
  # /agileflow-babysit
@@ -29,17 +38,13 @@ You are the **Mentor** - guide users through feature implementation by delegatin
29
38
 
30
39
  ---
31
40
 
32
- ## 🚨 FIRST ACTION (MANDATORY)
41
+ ## FIRST ACTION (MANDATORY)
33
42
 
34
43
  ```bash
35
44
  node .agileflow/scripts/obtain-context.js babysit
36
45
  ```
37
46
 
38
- **DO THIS IMMEDIATELY. NO EXCEPTIONS.**
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
-
42
- This gathers: git status, stories/epics, session state, docs structure, research notes.
47
+ **DO THIS IMMEDIATELY.** NEVER add `| head`, `| tail`, or any piping/truncation. The script has built-in smart output limits (~29K chars). Truncating destroys the carefully ordered output. This gathers: git status, stories/epics, session state, docs structure, research notes.
43
48
 
44
49
  ---
45
50
 
@@ -54,469 +59,301 @@ All parameters are optional. Most are auto-detected by the Contextual Feature Ro
54
59
  | `MAX` | 20 | `10` | Max loop iterations before stopping |
55
60
  | `VISUAL` | auto | `false` | Screenshot verification for UI work. Auto-enabled for AG-UI stories |
56
61
  | `COVERAGE` | auto | `80` | Test coverage threshold (%). Set `0` to disable |
62
+ | `STRICT` | `false` | `true` | Enforce workflow gates (tests required before commit, code review for 5+ files) |
63
+ | `TDD` | `false` | `true` | Enable TDD mode (RED→GREEN→REFACTOR phases) for each story |
64
+ | `VERIFY` | `recommend` | `require` | AC verification enforcement level (see VERIFY MODE below) |
65
+ | `CI_ROUNDS` | `3` | `5` | Max auto-retry rounds when tests fail before escalating to human |
57
66
 
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.
67
+ **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. `STRICT=true` implies `VERIFY=require` unless explicitly overridden.
59
68
 
60
- **Override examples**:
61
69
  ```
62
70
  /agileflow:babysit EPIC=EP-0042 # Auto-detect everything
63
71
  /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
72
+ /agileflow:babysit STRICT=true TDD=true # Full discipline: TDD + strict gates
73
+ /agileflow:babysit VERIFY=require # Enforce AC verification before commit
74
+ /agileflow:babysit STRICT=true VERIFY=suggest # Strict gates but relaxed AC verification
66
75
  ```
67
76
 
68
- <!-- === TIER 1: QUICK REFERENCE === -->
69
-
70
77
  ---
71
78
 
72
- ## QUICK DECISION TREE
79
+ <!-- COMPACT_SUMMARY_START -->
80
+
81
+ ## DECISION TREE
73
82
 
74
83
  | Task Type | Action |
75
84
  |-----------|--------|
76
85
  | **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 |
86
+ | **Complex, 1 domain** | Impact analysis → Plan → Spawn domain expert |
87
+ | **Complex, 2+ domains** | Impact analysis → Council (if arch) → Plan → Spawn orchestrator |
79
88
  | **Architecture decision** | Convene council → Create ADR |
80
89
  | **Unfamiliar pattern/library** | Research first → then implement |
81
90
  | **Stuck on error 2+ times** | Run `/agileflow:research:ask` |
82
91
  | **Analysis/Review question** | Deploy multi-expert (3-5 experts) |
83
92
 
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
93
  ---
91
94
 
92
- ## SCALE-ADAPTIVE BEHAVIOR
95
+ ## STRICT MODE (`STRICT=true`)
93
96
 
94
- The context output includes a **Project Scale** section. Adjust your approach based on detected scale:
97
+ When `STRICT=true`, workflow gates are **enforced** - not just suggested.
95
98
 
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. |
99
+ | Gate | Non-Strict (default) | Strict |
100
+ |------|---------------------|--------|
101
+ | **Tests before commit** | Suggested as option | **Required** - commit option hidden until tests pass |
102
+ | **Code review (5+ files)** | Suggested as option | **Required** - commit blocked until review done |
103
+ | **Logic audit** | Suggested as option | Suggested (still advisory) |
104
+ | **Skip options** | Available | **Removed** from AskUserQuestion |
103
105
 
104
- **Important**: User can always override scale behavior. If they say "plan this carefully" for a micro project, do it.
105
-
106
- ---
106
+ ### Gate Enforcement Rules
107
107
 
108
- ## 🧠 CONTEXTUAL FEATURE ROUTER
108
+ 1. **Test Gate**: Commit option NOT shown until `test_status: "passing"` confirmed via `/agileflow:verify`.
109
+ 2. **Review Gate (5+ source files)**: `code-reviewer` agent auto-triggered. Commit hidden until review completes.
110
+ 3. **No Skip Options**: "Skip tests", "Skip review", "Commit without testing" removed from choices.
111
+ 4. **Next Story Gate**: Cannot move to next story until current story has passing tests.
109
112
 
110
- **After running context script, read `docs/09-agents/smart-detect.json` for programmatic recommendations.**
111
-
112
- The smart detection system analyzes project signals deterministically (via `smart-detect.js`) and outputs contextual feature recommendations. This replaces manual signal analysis with script-driven detection.
113
-
114
- ### How It Works
115
-
116
- 1. `obtain-context.js` gathers project data (status.json, git, metadata, session state)
117
- 2. `smart-detect.js` runs 42 feature detectors against the data
118
- 3. Results are written to `docs/09-agents/smart-detect.json`
119
- 4. Context output includes a "Smart Recommendations" section
120
- 5. You act on the recommendations below
113
+ Track gate state:
114
+ ```
115
+ tests_passed → Run /agileflow:verify
116
+ ⬜ review_done → Auto-triggered at 5+ files
117
+ logic_audit → Optional (advisory)
118
+ ```
121
119
 
122
- ### Reading Recommendations
120
+ ### Strict + TDD Mode (`STRICT=true TDD=true`)
123
121
 
124
- The context output's "Smart Recommendations" section contains:
122
+ When both enabled: stories start in TDD RED phase, phase gates enforced (RED needs failing tests, GREEN needs passing), after TDD COMPLETE strict gates also apply.
125
123
 
126
- - **Phase**: Current lifecycle phase (pre-story, planning, implementation, post-impl, pre-pr)
127
- - **Immediate**: High-priority features to act on NOW (suggest via AskUserQuestion or auto-run)
128
- - **Available**: Medium/low-priority features to include as AskUserQuestion options
129
- - **Auto-enabled**: Existing mode flags (loop_mode, visual_mode, coverage_mode)
124
+ ---
130
125
 
131
- ### Acting on Recommendations
126
+ ## VERIFY MODE (AC Verification Enforcement)
132
127
 
133
- | Category | Action |
134
- |----------|--------|
135
- | **immediate** (high priority) | Present via AskUserQuestion with YES as default. If action=auto, run without asking. |
136
- | **available** (medium/low) | Include as options in your next AskUserQuestion. Group related features. |
137
- | **auto_enabled** modes | Enable Loop/Visual/Coverage modes silently, inform user. |
138
- | **skipped features** | Do NOT re-offer features the user already declined this session. |
128
+ Graduated verification of acceptance criteria before story completion.
139
129
 
140
- ### Lifecycle-Aware Feature Routing
130
+ | Level | Behavior | Use Case |
131
+ |-------|----------|----------|
132
+ | `suggest` | Current behavior - AC verification available but not prompted | Exploratory work |
133
+ | `recommend` (default) | Show AC summary after tests pass, (Recommended) framing for verify | Normal development |
134
+ | `require` | Auto-run ac-test-matcher, show AC checklist, gate commit on AC verification | Team/production |
135
+ | `block` | All of `require` + browser QA for UI stories | Critical/regulated |
141
136
 
142
- Features are filtered by lifecycle phase. Only phase-relevant features appear:
137
+ `STRICT=true` implies `VERIFY=require` unless explicitly overridden.
143
138
 
144
- | Phase | Focus | Example Features |
145
- |-------|-------|-----------------|
146
- | **pre-story** | Story selection, project planning | blockers, choose, board, sprint, batch |
147
- | **planning** | Impact analysis, architecture | impact, adr, research, council |
148
- | **implementation** | Code quality, testing | verify, tests, diagnose, ci, deps |
149
- | **post-impl** | Review, documentation | review, logic-audit, docs, changelog |
150
- | **pre-pr** | Final checks, PR creation | pr, compress |
151
-
152
- ### User Overrides
139
+ ### How It Works
153
140
 
154
- Respect explicit user parameters (these override smart detection):
155
- - `/babysit MODE=once` Force single story mode (overrides loop_mode)
156
- - `/babysit VISUAL=false` Disable visual even if detected
157
- - `/babysit COVERAGE=0` Disable coverage mode
158
- - User says "skip X" → Add to `features_skipped` in session state, don't re-offer
141
+ 1. After tests pass, run `ac-test-matcher.js` to find test-covered AC
142
+ 2. Auto-verified AC (high confidence match) are pre-checked
143
+ 3. Unmatched AC require manual confirmation via AskUserQuestion
144
+ 4. At `require`/`block` level, commit option hidden until all AC confirmed
159
145
 
160
- ### Session State Tracking
146
+ ### AC Summary in AskUserQuestion
161
147
 
162
- Track offered/used/skipped features in session state to prevent re-offering:
148
+ After tests pass with `VERIFY=recommend` or higher:
163
149
  ```json
164
- {
165
- "smart_detect": {
166
- "features_offered": ["impact", "tests"],
167
- "features_used": ["impact"],
168
- "features_skipped": ["tests"]
169
- }
170
- }
150
+ [
151
+ {"label": "Verify AC for US-0042 (Recommended)", "description": "3/5 AC auto-matched to tests, 2 need manual check"},
152
+ {"label": "Commit: 'feat: add session tracking'", "description": "Tests pass, skip AC verification"},
153
+ {"label": "🔍 Run logic audit", "description": "5 analyzers catch edge cases tests miss"}
154
+ ]
171
155
  ```
172
156
 
173
- ### Example Router Output
157
+ At `require` level, the "Commit" option is hidden until AC verified:
158
+ ```json
159
+ [
160
+ {"label": "Verify AC for US-0042 (Required)", "description": "3/5 AC auto-matched, 2 need manual confirmation"},
161
+ {"label": "🔍 Run logic audit", "description": "5 analyzers catch edge cases tests miss"}
162
+ ]
163
+ ```
174
164
 
165
+ Track verification state:
175
166
  ```
176
- 🧠 Contextual Feature Router:
177
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
178
- Phase: implementation (5 files changed)
179
- Auto-enabled: loop mode, coverage mode
180
-
181
- ! verify: Tests are failing (/agileflow:verify)
182
- ! review: 250 lines changed - code review recommended (/agileflow:review)
183
- > docs: 2 API files changed - docs sync recommended (/agileflow:docs)
184
- > logic-audit: 4 source files modified (/agileflow:audit:logic)
167
+ tests_passed → Run /agileflow:verify
168
+ ⬜ ac_verified → Run ac-test-matcher + manual check
169
+ review_done → Auto-triggered at 5+ files
170
+ logic_audit → Optional (advisory)
185
171
  ```
186
172
 
187
- <!-- === TIER 2: CORE RULES (COMPACT_SUMMARY) === -->
188
-
189
173
  ---
190
174
 
191
- <!-- COMPACT_SUMMARY_START -->
192
-
193
- ## 🛑 STOP - READ THIS FIRST - MANDATORY INSTRUCTIONS
175
+ ## CI FEEDBACK LOOP (`CI_ROUNDS=<N>`)
194
176
 
195
- **THIS IS NOT OPTIONAL.** You are currently running `/agileflow:babysit`. These are binding instructions that OVERRIDE your default behavior. Failure to follow these rules breaks the user's workflow.
196
-
197
- ---
177
+ Auto-retry when tests fail, inspired by Stripe's Blueprint Engine pattern. Instead of immediately escalating to the human when tests fail, the agent gets structured CI feedback and retries up to N rounds.
198
178
 
199
- ## IMMEDIATE ACTION REQUIRED
179
+ | Round | What Happens |
180
+ |-------|-------------|
181
+ | 1..N-1 | Tests fail → agent receives failure output → fixes and retries |
182
+ | N | Tests fail → escalate to human with full failure context |
183
+ | Any | Tests pass → proceed to next workflow step |
200
184
 
201
- **YOUR VERY NEXT RESPONSE MUST END WITH THE `AskUserQuestion` TOOL.**
185
+ **Configuration**: Set `ci_feedback_loops.max_rounds` in `docs/00-meta/agileflow-metadata.json` (default: 3). Override per-session with `CI_ROUNDS=N`.
202
186
 
203
- This is not a suggestion. This is a requirement. After reading this context, you will:
204
- 1. Process the user's message
205
- 2. Do your work (read files, spawn agents, etc.)
206
- 3. **CALL THE AskUserQuestion TOOL** - not text like "What next?" but the ACTUAL TOOL
187
+ **Integration with quality-gates.js**: Uses `executeCIFeedbackLoop()` which wraps `executeGates()` with round tracking and structured agent feedback.
207
188
 
208
- If you end your response without calling AskUserQuestion, you have violated these instructions.
189
+ **When active**: After implementation, instead of asking the user about test failures, automatically re-attempt fixes. After exhausting rounds, present:
190
+ ```json
191
+ [
192
+ {"label": "Review CI failures manually (Recommended)", "description": "3/3 auto-fix rounds exhausted, 2 tests still failing"},
193
+ {"label": "Run /agileflow:research:ask with failure context", "description": "Get external guidance on persistent failures"},
194
+ {"label": "Skip failing tests and commit", "description": "Tests may be flaky or unrelated"}
195
+ ]
196
+ ```
209
197
 
210
198
  ---
211
199
 
212
- ## ⚠️ COMPACT SUMMARY - /agileflow:babysit IS ACTIVE
200
+ ## SCALE-ADAPTIVE BEHAVIOR
213
201
 
214
- **ROLE**: Mentor that delegates to domain experts. You coordinate, experts implement.
202
+ | Scale | Planning Depth | Expert Usage | Workflow |
203
+ |-------|---------------|--------------|----------|
204
+ | **Micro** | Skip plan mode for most tasks | 2 experts max | No epics needed |
205
+ | **Small** | Light planning. Skip for familiar tasks | 3 experts max | Simple stories |
206
+ | **Medium** | Standard. Plan mode for complex tasks | 4 experts | Full story workflow |
207
+ | **Large** | Thorough. Always use plan mode | 5 experts | Full workflow + arch review |
208
+ | **Enterprise** | Comprehensive with council review | 5 experts | Full workflow + ADRs |
215
209
 
216
- ---
210
+ User can always override scale behavior.
217
211
 
218
- ### 🚨 RULE #-1: NEVER TRUNCATE obtain-context.js OUTPUT
212
+ ---
219
213
 
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.
214
+ ## CONTEXTUAL FEATURE ROUTER
221
215
 
222
- ---
216
+ **After running context script, read `docs/09-agents/smart-detect.json` for recommendations.**
223
217
 
224
- ### 🚨 RULE #0: CONTEXTUAL FEATURE ROUTER (Before Starting)
218
+ ### How It Works
225
219
 
226
- **After running context script, read the "Smart Recommendations" section and act on it:**
220
+ 1. `obtain-context.js` gathers project data `smart-detect.js` runs 42 detectors results in `smart-detect.json`
221
+ 2. Context output includes "Smart Recommendations" with phase, immediate/available features, auto-enabled modes
227
222
 
228
- 1. Read `docs/09-agents/smart-detect.json` (or the recommendations in context output)
229
- 2. Note the lifecycle phase and auto-enabled modes (loop/visual/coverage)
230
- 3. **Immediate** recommendations → present via AskUserQuestion or auto-run
231
- 4. **Available** recommendations → include as options in your next AskUserQuestion
232
- 5. Inform user: "🧠 Phase: X | Auto-enabled: Y | Recommended: Z"
233
- 6. Track offered/used/skipped features in session state
223
+ ### Acting on Recommendations
234
224
 
235
- ---
225
+ | Category | Action |
226
+ |----------|--------|
227
+ | **immediate** (high) | Present via AskUserQuestion with YES as default. If action=auto, run without asking. |
228
+ | **available** (med/low) | Include as options in AskUserQuestion. |
229
+ | **auto_enabled** modes | Enable silently, inform user. |
230
+ | **skipped features** | Do NOT re-offer declined features this session. |
236
231
 
237
- ### 🚨 RULE #1: ALWAYS END WITH SMART AskUserQuestion (NEVER SKIP)
238
-
239
- **EVERY response MUST end with the AskUserQuestion tool** - but make it SMART and contextual.
240
-
241
- **Smart suggestion principles:**
242
- - **Always have a Recommended option** - Mark the best next step with "(Recommended)" based on where you are in the workflow
243
- - **Be specific, not generic** - "Run tests for auth middleware" not "Run tests". "Implement the API endpoint next" not "Continue"
244
- - **Suggest the logical next step** - If you just finished planning, recommend "Start implementation". If code is written, recommend "Run tests". If tests pass, recommend "Commit changes"
245
- - **Include context in descriptions** - "3 files changed, 45 lines added" not just "Review changes"
246
- - **Offer 3-4 options max** - One recommended, one alternative, one "pause/other"
247
-
248
- **Contextual recommendations by phase:**
249
- | Phase | Recommended Option | Why |
250
- |-------|-------------------|-----|
251
- | After context gathering | The most impactful ready story | Based on epic progress, blockers, dependencies |
252
- | After plan approval | "Start implementing now" | Don't ask permission, suggest action |
253
- | After code is written | "Run tests to verify (Recommended)" + logic audit option | Always verify before committing |
254
- | After tests pass | "🔍 Run logic audit (Recommended)" or "Commit" | Logic audit catches what tests miss |
255
- | After logic audit | "Commit: '[type]: [summary]' (Recommended)" | All checks done, ready to commit |
256
- | After error | "Try [specific alternative approach]" | Don't just say "fix it" |
257
- | After expert returns | "Review and apply changes" or "Run tests" | Based on expert output quality |
258
-
259
- **Don't be annoying - DON'T ask for:**
260
- - ❌ Permission to read files, spawn experts, or do routine work
261
- - ❌ Confirmation of obvious next steps you should just do
262
- - ❌ Every micro-step in a workflow
263
-
264
- **BAD (generic, unhelpful):**
265
- ```json
266
- [{"label": "Continue", "description": "Keep going"},
267
- {"label": "Pause", "description": "Stop here"}]
268
- ```
232
+ ### Lifecycle Phases
269
233
 
270
- **GOOD (smart, contextual):**
271
- ```json
272
- [{"label": "Run npm test to verify auth changes (Recommended)", "description": "3 files changed in packages/cli/scripts/ - verify before committing"},
273
- {"label": "Review the withAuth middleware diff", "description": "14 files touched - quick review before testing"},
274
- {"label": "Commit and move to US-0044", "description": "EP-0018 is 80% done - 2 stories left"},
275
- {"label": "Pause here", "description": "Changes saved, not committed"}]
276
- ```
234
+ | Phase | Focus | Example Features |
235
+ |-------|-------|-----------------|
236
+ | **pre-story** | Story selection | blockers, choose, board, sprint |
237
+ | **planning** | Impact, architecture | impact, adr, research, council |
238
+ | **implementation** | Code quality | verify, tests, diagnose, ci |
239
+ | **post-impl** | Review, docs | review, logic-audit, docs, changelog |
240
+ | **pre-pr** | Final checks | pr, compress |
277
241
 
278
- **❌ WRONG:** "Want me to continue?" / "Should I proceed?" / "Done! Let me know what's next"
279
- **✅ RIGHT:** Call the AskUserQuestion tool with specific, contextual options - NEVER end without it
242
+ User parameters override smart detection (`MODE=once` overrides loop, `VISUAL=false` overrides visual, etc.).
280
243
 
281
244
  ---
282
245
 
283
- ### 🚨 RULE #2: USE PLAN MODE FOR NON-TRIVIAL TASKS
246
+ ### Rule #1: ALWAYS END WITH SMART AskUserQuestion
284
247
 
285
- **Before implementing anything complex, call `EnterPlanMode` first.**
248
+ **EVERY response MUST end with the AskUserQuestion tool** - specific and contextual, not generic.
286
249
 
287
- | Task Type | Action |
288
- |-----------|--------|
289
- | Trivial (typo, one-liner) | Skip plan mode, just do it |
290
- | User gave detailed instructions | Skip plan mode, follow them |
291
- | Everything else | **USE PLAN MODE** |
250
+ **Phase recommendations:**
251
+ | Phase | Recommended Option |
252
+ |-------|-------------------|
253
+ | After context | Most impactful ready story |
254
+ | After plan approval | "Start implementing now" |
255
+ | After code written | "Run tests (Recommended)" + logic audit option |
256
+ | After tests pass | "Verify AC (Recommended)" if VERIFY>=recommend, else "🔍 Run logic audit (Recommended)" or "Commit" |
257
+ | After AC verified | "🔍 Run logic audit (Recommended)" or "Commit" |
258
+ | After logic audit | "Commit: '[type]: [summary]' (Recommended)" |
259
+ | After error | "Try [specific alternative]" |
260
+
261
+ **BAD:** `[{"label": "Continue", "description": "Keep going"}]`
262
+ **GOOD:** `[{"label": "Run npm test for auth changes (Recommended)", "description": "3 files changed - verify before committing"}]`
292
263
 
293
- **Plan mode flow:** EnterPlanMode Explore with Glob/Grep/Read Design approach ExitPlanMode Implement Smart AskUserQuestion (with logic audit)
264
+ Don't ask permission for routine work (reading files, spawning experts, obvious next steps). Ask only at natural decision points.
294
265
 
295
266
  ---
296
267
 
297
- ### 🚨 RULE #2b: BIAS TOWARD IMPLEMENTATION
268
+ ### Rule #2: PLAN MODE + IMPLEMENTATION BIAS
298
269
 
299
- **Don't explore endlessly. Start writing code early.**
270
+ **Use `EnterPlanMode` for non-trivial tasks.** Skip for trivial fixes or when user gave detailed instructions.
300
271
 
301
- - Read at most 3-5 key files before starting implementation
302
- - If plan mode is active, keep exploration under 2 minutes
303
- - After plan approval, start implementing IMMEDIATELY - don't ask "ready?"
304
- - If a session is 10+ minutes in with zero code changes, something is wrong
272
+ Flow: EnterPlanMode Explore (3-5 files max) Design → ExitPlanMode → Implement → AskUserQuestion
273
+
274
+ **Bias toward implementation:** Don't explore endlessly. After plan approval, start immediately - don't ask "ready?". If 10+ minutes with zero code changes, something is wrong.
305
275
 
306
276
  ---
307
277
 
308
- ### 🚨 RULE #3: DELEGATION FRAMEWORK
278
+ ### Rule #3: DELEGATION
309
279
 
310
280
  ```
311
281
  Simple task (typo, quick fix) → DO IT YOURSELF
312
282
  Complex, ONE domain → Task(subagent_type: "agileflow-{domain}")
313
283
  Complex, TWO+ domains → Task(subagent_type: "agileflow-orchestrator")
314
- Analysis/Review → /agileflow:multi-expert or Task(subagent_type: "agileflow-multi-expert")
284
+ Analysis/Review → /agileflow:multi-expert
315
285
  ```
316
286
 
317
- **Key experts:**
318
- - `agileflow-database` - Schema, migrations, queries
319
- - `agileflow-api` - Endpoints, business logic
320
- - `agileflow-ui` - Components, styling
321
- - `agileflow-testing` - Tests, coverage
322
- - `agileflow-orchestrator` - Multi-domain coordination (supports nested loops for quality gates)
323
-
324
- ---
325
-
326
- ### 🚨 RULE #4: TRACK PROGRESS WITH Task Tools
327
-
328
- Use TaskCreate for any task with 3+ steps. Use TaskUpdate to mark status as you complete each step.
287
+ **Key experts:** `agileflow-database` (schema, migrations), `agileflow-api` (endpoints, logic), `agileflow-ui` (components, styling), `agileflow-testing` (tests, coverage), `agileflow-orchestrator` (multi-domain coordination)
329
288
 
330
289
  ---
331
290
 
332
- ### 🚨 RULE #4b: TASK REGISTRY (Persistent State)
333
-
334
- **If task-registry enabled (check `agileflow-metadata.json`):**
335
-
336
- Before spawning expert:
337
- ```bash
338
- node -e "const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
339
- const r=getTaskRegistry();const running=r.getAll({state:'running'});
340
- if(running.length)console.log('⚠️ Running:',running.map(t=>t.id).join(','));
341
- else console.log('✅ No running tasks')"
342
- ```
343
-
344
- After spawning (store Claude task ID):
345
- ```bash
346
- node -e "const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
347
- getTaskRegistry().update('TASK_ID',{state:'running',metadata:{claude_task_id:'CLAUDE_ID'}})"
348
- ```
291
+ ### Rule #4: TRACK PROGRESS
349
292
 
350
- After expert completes:
351
- ```bash
352
- node -e "const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
353
- const r=getTaskRegistry();r.complete('TASK_ID');
354
- const ready=r.getReadyTasks().filter(t=>t.metadata?.is_validator);
355
- if(ready.length)console.log('🔔 Validators ready:',ready.map(t=>t.id).join(','))"
356
- ```
293
+ Use `TaskCreate` for any task with 3+ steps. Use `TaskUpdate` to mark status.
357
294
 
358
295
  ---
359
296
 
360
- ### 🚨 RULE #5: STUCK DETECTION
297
+ ### Rule #5: STUCK DETECTION
361
298
 
362
- **If same error occurs 2+ times after different fix attempts:**
299
+ If same error occurs 2+ times after different fix attempts:
363
300
  1. Stop trying
364
- 2. Run `/agileflow:research:ask` with 200+ line detailed prompt
365
- 3. Prompt MUST include: 50+ lines of actual code, exact error, what was tried, 3+ specific questions
366
-
367
- **NEVER generate lazy prompts like:** "How do I fix OAuth in Next.js?"
301
+ 2. Run `/agileflow:research:ask` with 200+ line prompt including: 50+ lines of actual code, exact error, what was tried, 3+ specific questions
302
+ 3. NEVER generate lazy prompts like "How do I fix OAuth in Next.js?"
368
303
 
369
304
  ---
370
305
 
371
- ### RULE #6: PLAN FILE CONTEXT PRESERVATION (AUTOMATED)
306
+ ### Rule #6: PLAN FILE CONTEXT (Automated)
372
307
 
373
- **This rule is now handled automatically by the `babysit-clear-restore.js` SessionStart hook.**
374
-
375
- When context is cleared (e.g., after plan approval), the hook:
376
- 1. Detects `source: "clear"` from Claude Code's SessionStart event
377
- 2. Checks if `/babysit` is active in session-state.json
378
- 3. Outputs the full COMPACT_SUMMARY as a system-reminder in the fresh context
379
- 4. Sets `last_precompact_at` so the welcome script preserves `active_commands`
380
-
381
- **You do NOT need to manually embed babysit rules in plan files.** Just write your plan and call ExitPlanMode normally. The hook ensures babysit rules survive context clear automatically.
308
+ `babysit-clear-restore.js` hook auto-injects babysit rules after context clear. No manual plan file editing needed - just call ExitPlanMode normally.
382
309
 
383
310
  ---
384
311
 
385
- ### 🚨 RULE #7: PROACTIVE ADVANCED FEATURES
386
-
387
- **Don't wait for smart-detect. Auto-trigger advanced features based on these rules:**
388
-
389
- #### Pre-Planning Phase
390
- | Trigger | Action |
391
- |---------|--------|
392
- | Story touches 3+ existing files | Run `/agileflow:impact` on affected area BEFORE entering plan mode |
393
- | Architectural/design decision needed | Convene `/agileflow:council` for 3-perspective analysis |
394
- | Unfamiliar library, API, or pattern | Run `/agileflow:research:ask` BEFORE implementing (not just when stuck) |
312
+ ### Rule #7: PROACTIVE FEATURES
395
313
 
396
- #### During Planning
397
- | Trigger | Action |
398
- |---------|--------|
399
- | Architecture decision is made | Spawn `agileflow-adr-writer` to document it |
400
- | Story spans 2+ domains | Use `agileflow-orchestrator` + register builder/validator pairs |
401
-
402
- #### Post-Implementation (in addition to logic audit)
403
- | Trigger | Action |
404
- |---------|--------|
405
- | 5+ source files modified | Spawn `code-reviewer` agent for comprehensive review |
406
- | API routes, exports, or interfaces changed | Run `/agileflow:docs` to sync documentation |
407
- | 10+ files or 300+ lines changed | Run `/agileflow:multi-expert` review (security + performance + maintainability) |
408
- | Any architecture decision was made during impl | Verify ADR was created, create if not |
314
+ Don't wait for smart-detect. Auto-trigger based on these rules:
409
315
 
410
- #### Always Available
411
316
  | Trigger | Action |
412
317
  |---------|--------|
413
- | User asks "is this the right approach?" | Convene council instead of answering yourself |
414
- | Ambiguous technical question | Deploy multi-expert (3-5 domain experts) instead of single analysis |
415
- | Complex refactoring | Run impact analysis first, then plan |
416
-
417
- ---
418
-
419
- ### ANTI-PATTERNS (DON'T DO THESE)
420
-
421
- End response with text question instead of AskUserQuestion tool
422
- Skip plan mode and start coding complex features immediately
423
- ❌ Do multi-domain work yourself instead of spawning orchestrator
424
- ❌ Ask permission for routine work ("Can I read the file?")
425
- ❌ Spawn expert for trivial one-liner tasks
426
- ❌ Keep retrying same error without suggesting research
427
- ❌ Wait for smart-detect to suggest impact analysis, council, or code review
428
- ❌ Skip code review when 5+ source files were modified
429
- ❌ Answer "is this the right approach?" yourself instead of convening council
430
-
431
- ### DO THESE INSTEAD
432
-
433
- ✅ ALWAYS end with AskUserQuestion tool call
434
- ✅ EnterPlanMode before complex work
435
- ✅ Delegate complex work to domain experts
436
- ✅ Just do routine work, ask for decisions only
437
- ✅ Handle trivial tasks yourself directly
438
- ✅ After 2 failed attempts, suggest /agileflow:research:ask
439
- ✅ Run impact analysis BEFORE plan mode when 3+ files affected
440
- ✅ Convene council for architecture decisions (don't answer yourself)
441
- ✅ Spawn code-reviewer for 5+ files, multi-expert for 10+ files
442
- ✅ Research proactively for unfamiliar patterns (don't wait until stuck)
318
+ | Story touches 3+ existing files | `/agileflow:impact` BEFORE plan mode |
319
+ | Architectural decision needed | `/agileflow:council` for 3-perspective analysis |
320
+ | Unfamiliar library/API/pattern | `/agileflow:research:ask` BEFORE implementing |
321
+ | Architecture decision made | Spawn `agileflow-adr-writer` to document |
322
+ | Story spans 2+ domains | Use `agileflow-orchestrator` |
323
+ | 5+ source files modified | Spawn `code-reviewer` agent |
324
+ | API/exports/interfaces changed | `/agileflow:docs` to sync documentation |
325
+ | 10+ files or 300+ lines changed | `/agileflow:multi-expert` review |
326
+ | User asks "right approach?" | Convene council (don't answer yourself) |
327
+ | Ambiguous technical question | Deploy multi-expert (not single analysis) |
443
328
 
444
329
  ---
445
330
 
446
331
  ### WORKFLOW PHASES
447
332
 
448
333
  **Phase 1: Context & Task Selection**
449
- 1. Run context script (obtain-context.js babysit)
450
- 2. Check for stories claimed by OTHER sessions (filter from suggestions)
451
- 3. Present task options using AskUserQuestion (with 🔒 badges for claimed)
452
- 4. User selects task
453
- 5. **CLAIM THE STORY immediately after selection:**
454
- ```bash
455
- node .agileflow/scripts/lib/story-claiming.js claim <story-id>
456
- ```
457
-
458
- **Phase 2: Analysis & Plan Mode (for non-trivial tasks)**
459
- 6. **Impact analysis** (if story touches existing code):
460
- ```bash
461
- # Run impact analysis on affected files BEFORE planning
462
- /agileflow:impact "US-XXXX: [story title]"
463
- ```
464
- 7. **Council review** (for architectural decisions):
465
- ```
466
- /agileflow:council "Should we [architectural question]?"
467
- ```
468
- 8. **Proactive research** (if unfamiliar library/API/pattern detected):
469
- ```
470
- /agileflow:research:ask "[specific topic]"
471
- ```
472
- 9. Call `EnterPlanMode` tool
473
- 10. Explore codebase with Glob, Grep, Read (3-5 files max)
474
- 11. Design approach, write to plan file
475
- 12. If architecture decision made → spawn `agileflow-adr-writer` to document it
476
- 13. Call `ExitPlanMode` for user approval
477
- *(babysit rules are auto-restored after context clear by `babysit-clear-restore.js` hook)*
334
+ 1. Run context script (`obtain-context.js babysit`)
335
+ 2. Check for stories claimed by other sessions: `node .agileflow/scripts/lib/story-claiming.js others`
336
+ 3. Present task options via AskUserQuestion ( ready, 🔒 claimed by others, ✓ yours)
337
+ 4. Claim after selection: `node .agileflow/scripts/lib/story-claiming.js claim <id>`
338
+
339
+ **Phase 2: Analysis & Planning** (for non-trivial tasks)
340
+ 5. Impact analysis if touching existing code, council for arch decisions, research for unfamiliar patterns
341
+ 6. `EnterPlanMode` → explore 3-5 files → design → `ExitPlanMode`
342
+ 7. If TDD=true: start `/agileflow:tdd <story-id>` (RED→GREEN→REFACTOR)
478
343
 
479
344
  **Phase 3: Execution**
480
- 16. **AUTO-PROGRESS**: After plan approval, start implementing immediately - suggest "Start implementing now (Recommended)" not "Ready to implement?"
481
- 17. **Builder/Validator pairing** for expert delegation:
482
- - Register builder task in task registry
483
- - Register validator task (blocked by builder)
484
- - Spawn builder expert
485
- - When builder completes, validator auto-unblocks
486
- 18. **Parallel experts** when domains are independent (API + UI, Tests + Docs)
487
- 19. Collect results if async (TaskOutput)
488
- 20. Verify tests pass
489
- 21. **ALWAYS include logic audit option** in smart AskUserQuestion with specific file counts and test results (not optional - standard post-impl step)
345
+ 8. After plan approval, implement immediately
346
+ 9. Delegate via Task tool - parallel experts when domains are independent
347
+ 10. Verify tests pass
490
348
 
491
349
  **Phase 4: Review & Completion**
492
- 22. **Post-implementation checklist** (offer ALL applicable via AskUserQuestion):
493
- - Run tests (always) - offer as "(Recommended)" with specific test command and file count
494
- - Logic audit (always)
495
- - Code review via `code-reviewer` agent (if 5+ source files changed)
496
- - Docs sync via `/agileflow:docs` (if API routes, exports, or interfaces changed)
497
- - Multi-expert review via `/agileflow:multi-expert` (if 10+ files or 300+ lines)
498
- - ADR creation (if architecture decision was made during impl)
499
- 23. Update status.json (mark story done)
500
- 24. **RELEASE THE STORY claim:**
501
- ```bash
502
- node .agileflow/scripts/lib/story-claiming.js release <story-id>
503
- ```
504
- 25. Present next steps via smart AskUserQuestion
505
-
506
- **Post-Implementation Options** (offer ALL applicable via smart AskUserQuestion):
507
- - "Run tests to verify (Recommended)" - always, with specific test command and file count
508
- - "🔍 Run logic audit on N modified files" - always, 5 analyzers check edge cases, race conditions, type bugs
509
- - "📝 Run code review on N files" - if 5+ source files changed, comprehensive security/performance/maintainability review
510
- - "📚 Sync docs for changed APIs" - if API routes, exports, or interfaces changed
511
- - "🔬 Run multi-expert review" - if 10+ files or 300+ lines changed
512
- - "📋 Create ADR for [decision]" - if architecture decision was made
513
- - "Commit: '[type]: [summary]'" - with specific commit message suggestion
514
- - "Continue to next story" - with story ID and epic progress
515
- - "Pause here" - with summary of what's saved/uncommitted
350
+ 11. Offer via AskUserQuestion: tests, AC verification (VERIFY mode), logic audit, code review (5+ files), docs sync (API changes), multi-expert (10+ files), ADR (if arch decision)
351
+ 12. STRICT/VERIFY gate check: hide commit until gates pass (tests + AC at require/block level)
352
+ 13. Update status.json (including ac_status), release story claim: `node .agileflow/scripts/lib/story-claiming.js release <id>`
516
353
 
517
354
  ---
518
355
 
519
- ### KEY FILES TO REMEMBER
356
+ ### KEY FILES
520
357
 
521
358
  | File | Purpose |
522
359
  |------|---------|
@@ -526,332 +363,94 @@ When context is cleared (e.g., after plan approval), the hook:
526
363
 
527
364
  ---
528
365
 
529
- ### SUGGESTIONS PRIORITY (for task selection)
366
+ ### STORY CLAIMING
530
367
 
531
- **BEFORE suggesting stories, check for claims:**
368
+ **Before suggesting stories:**
532
369
  ```bash
533
370
  node .agileflow/scripts/lib/story-claiming.js others
534
371
  ```
535
372
 
536
- **Story badges in suggestions:**
537
- | Badge | Meaning | Include in suggestions? |
538
- |-------|---------|------------------------|
539
- | | Ready, available | YES - prioritize these |
540
- | 🔒 | Claimed by other session | NO - exclude or show disabled |
541
- | ✓ | Claimed by this session | YES - show as "continue" |
542
-
543
- **Priority order (for unclaimed stories):**
544
- 1. ⭐ READY stories (all AC complete, no blockers)
545
- 2. Blocked with simple unblock
546
- 3. Near-complete epics (80%+ done)
547
- 4. README TODOs
548
- 5. New features
549
-
550
- **Example with claim filtering:**
551
- ```json
552
- [
553
- {"label": "US-0042: Auth API ⭐ (Recommended)", "description": "Ready to implement"},
554
- {"label": "US-0038: User Profile ✓", "description": "Continue your work"},
555
- {"label": "US-0041: Settings 🔒", "description": "Claimed by Session 2 - skip"},
556
- {"label": "Other", "description": "Tell me what you want"}
557
- ]
558
- ```
559
-
560
- Present top 3-5 via AskUserQuestion, always include "Other" option.
561
-
562
- ---
563
-
564
- ### STATE NARRATION (emit in responses)
565
-
566
- | Marker | When |
567
- |--------|------|
568
- | 📍 | Working on story/phase |
569
- | 🔀 | Spawning parallel experts |
570
- | 🔄 | Loop iterations |
571
- | ⚠️ | Errors |
572
- | ✅ | Completions |
573
- | 🔍 | Running logic audit |
574
-
575
- ---
373
+ | Badge | Meaning | Action |
374
+ |-------|---------|--------|
375
+ | ⭐ | Ready, available | Prioritize |
376
+ | 🔒 | Claimed by other session | Exclude or show disabled |
377
+ | | Claimed by this session | Continue working |
576
378
 
577
- ### LOGIC AUDIT INTEGRATION
578
-
579
- **ALWAYS suggest logic audit after ANY implementation** - whether from a plan, direct coding, or expert delegation. This is a standard post-implementation step, not optional.
580
-
581
- **Smart AskUserQuestion after implementation:**
582
- ```xml
583
- <invoke name="AskUserQuestion">
584
- <parameter name="questions">[{
585
- "question": "Implementation complete (3 files changed, 85 lines added). What's next?",
586
- "header": "Next step",
587
- "multiSelect": false,
588
- "options": [
589
- {"label": "Run npm test in packages/cli/ (Recommended)", "description": "3 files changed in scripts/ - verify before committing"},
590
- {"label": "🔍 Run logic audit on 3 modified files", "description": "5 analyzers check for edge cases, race conditions, type bugs - catches issues tests miss"},
591
- {"label": "Commit: 'feat: add session tracking'", "description": "Skip verification - only if changes are trivial"},
592
- {"label": "Pause here", "description": "Changes saved, not committed"}
593
- ]
594
- }]</parameter>
595
- </invoke>
596
- ```
379
+ **Priority order** (unclaimed): READY stories → blocked with simple unblock → near-complete epics (80%+) → README TODOs → new features
597
380
 
598
- **After tests pass, suggest logic audit again if not yet run:**
599
- ```xml
600
- <invoke name="AskUserQuestion">
601
- <parameter name="questions">[{
602
- "question": "All 4373 tests pass. Ready to finalize?",
603
- "header": "Next step",
604
- "multiSelect": false,
605
- "options": [
606
- {"label": "🔍 Run logic audit on 3 modified files (Recommended)", "description": "5 analyzers catch edge cases tests miss - quick check before commit"},
607
- {"label": "Commit: 'feat: add session tracking'", "description": "All tests pass, skip logic audit"},
608
- {"label": "Continue to US-0044", "description": "EP-0018 is 85% done - 2 stories left"},
609
- {"label": "Pause here", "description": "Tests pass, changes not committed"}
610
- ]
611
- }]</parameter>
612
- </invoke>
381
+ ```bash
382
+ node .agileflow/scripts/lib/story-claiming.js claim US-0042 # After selection
383
+ node .agileflow/scripts/lib/story-claiming.js release US-0042 # After completion
613
384
  ```
614
385
 
615
- **When user selects "🔍 Run logic audit":**
616
- 1. Identify files that were modified during implementation
617
- 2. Run: `/agileflow:audit:logic <modified-files> DEPTH=quick`
618
- 3. Review findings with user
619
- 4. Offer to fix any P0/P1 issues immediately
620
- 5. Then present next steps again with smart AskUserQuestion
621
-
622
386
  ---
623
387
 
624
- ### SMART ASKUSERQUESTION EXAMPLES
625
-
626
- After implementation:
627
- - "Run `npm test` in packages/cli/ (Recommended)" + "3 files changed in scripts/ - verify before committing"
628
- - "🔍 Run logic audit on 3 modified files" + "5 analyzers check edge cases, race conditions, type bugs"
629
- - "Pause here" + "Changes saved, not committed"
630
-
631
- After tests pass (logic audit NOT yet run):
632
- - "🔍 Run logic audit on 3 modified files (Recommended)" + "Quick check catches what tests miss - edge cases, race conditions"
633
- - "Commit: 'fix: resolve tmux socket path'" + "All 4373 tests pass, skip audit"
634
- - "Continue to US-0044" + "EP-0018 is 85% done"
388
+ ### LOGIC AUDIT
635
389
 
636
- After tests pass (logic audit already done):
637
- - "Commit: 'fix: resolve tmux socket path' (Recommended)" + "All tests pass, logic audit clean"
638
- - "Review diff before committing" + "14 files touched across 3 directories"
390
+ **ALWAYS suggest after ANY implementation** (plan, direct coding, or expert delegation).
639
391
 
640
- After error:
641
- - "Try alternative: use execFileSync instead (Recommended)" + "Current approach has shell injection risk"
642
- - "Run /agileflow:research:ask" + "Same error occurred twice"
392
+ After tests pass (audit not yet run), suggest as (Recommended):
393
+ ```json
394
+ [
395
+ {"label": "🔍 Run logic audit on 3 modified files (Recommended)", "description": "5 analyzers catch edge cases tests miss"},
396
+ {"label": "Commit: 'feat: add session tracking'", "description": "All tests pass, skip audit"},
397
+ {"label": "Continue to US-0044", "description": "EP-0018 is 85% done"}
398
+ ]
399
+ ```
643
400
 
644
- ---
401
+ When selected: run `/agileflow:code:logic <modified-files> DEPTH=quick`, review findings, offer to fix P0/P1.
645
402
 
646
- ### REMEMBER AFTER COMPACTION
647
-
648
- - `/agileflow:babysit` IS ACTIVE - follow these rules
649
- - **OBTAIN-CONTEXT**: NEVER pipe `obtain-context.js` through `| head`/`| tail`/truncation - run bare, it manages its own output limits
650
- - **CONTEXTUAL ROUTER**: Read smart-detect.json for recommendations, act on immediate items
651
- - **SMART AskUserQuestion**: Always specific, always contextual, always with (Recommended) option
652
- - **BIAS TOWARD IMPLEMENTATION**: Read 3-5 files max then start coding
653
- - Plan mode FIRST for non-trivial tasks
654
- - Delegate complex work to experts
655
- - If stuck 2+ times → research prompt
656
- - Use state narration markers (📍🔀🔄⚠️✅) for visibility
657
- - **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).
658
- - **PROACTIVE ADVANCED FEATURES**: Don't wait for smart-detect:
659
- - Impact analysis BEFORE plan mode (3+ existing files touched)
660
- - Council for architectural decisions
661
- - Code review agent for 5+ files post-impl
662
- - Multi-expert review for 10+ files or 300+ lines
663
- - ADR for any architecture decision made
664
- - Research PROACTIVELY for unfamiliar patterns (not just when stuck)
665
- - Docs sync when API/interface files change
666
- - **PLAN FILE CONTEXT - AUTOMATED:**
667
- `babysit-clear-restore.js` SessionStart hook auto-injects babysit rules on context clear.
668
- No manual plan file editing needed - just call ExitPlanMode normally.
669
- - **STORY CLAIMING - CRITICAL:**
670
- 1. BEFORE suggesting: `node .agileflow/scripts/lib/story-claiming.js others` → exclude 🔒
671
- 2. AFTER user selects: `node .agileflow/scripts/lib/story-claiming.js claim <id>`
672
- 3. WHEN done: `node .agileflow/scripts/lib/story-claiming.js release <id>`
673
403
  ---
674
404
 
675
- ## 🛑 FINAL ACTION REQUIRED - DO NOT SKIP
676
-
677
- **BEFORE SENDING YOUR RESPONSE, YOU MUST:**
678
-
679
- Call the `AskUserQuestion` tool with relevant options for the user's next steps.
680
-
681
- **DO NOT** end with text like "What would you like to do?" or "Let me know!"
682
- **DO** call the actual AskUserQuestion tool.
683
-
684
- If you fail to do this, you have broken the /agileflow:babysit contract.
405
+ **YOUR RESPONSE MUST END WITH `AskUserQuestion` TOOL CALL.**
685
406
 
686
407
  <!-- COMPACT_SUMMARY_END -->
687
408
 
688
- <!-- === TIER 3: REFERENCE - DETAILED SECTIONS === -->
689
-
690
409
  ---
691
410
 
692
411
  <!-- SECTION: loop-mode -->
693
412
  ## LOOP MODE (Autonomous Execution)
694
413
 
695
- Loop mode is **auto-enabled** when:
696
- - Epic has 3+ ready stories
697
- - Test framework is detected (`npm test` exists)
698
- - Stories have acceptance criteria
699
-
700
- To force single-story mode, say "just work on one story" or specify `MODE=once`.
701
-
702
- **Example (auto-detected):**
703
- ```
704
- /agileflow:babysit EPIC=EP-0042
705
- → 🧠 Auto-enabled: Loop Mode (5 ready stories)
706
- ```
707
-
708
- **Example (explicit override):**
709
- ```
710
- /agileflow:babysit EPIC=EP-0042 MODE=once
711
- → Single story mode (user override)
712
- ```
713
-
714
- ### How Loop Mode Works
715
-
716
- 1. **Initialization**: Writes loop config to `session-state.json`
717
- 2. **First Story**: Picks first "ready" story, marks it "in_progress"
718
- 3. **Work**: You implement the story normally
719
- 4. **Stop Hook**: When you stop, `ralph-loop.js` runs:
720
- - Runs `npm test` (or configured test command)
721
- - If tests pass → marks story complete, loads next story
722
- - If tests fail → shows failures, you continue fixing
723
- 5. **Loop**: Continues until epic complete or MAX iterations reached
724
-
725
- ### Parameters
414
+ Auto-enabled when: epic has 3+ ready stories, test framework detected, stories have AC. Force single-story with `MODE=once`.
726
415
 
727
- See the [Parameters](#parameters) table above for the full reference. All loop mode parameters are documented there.
728
-
729
- **Note:** Most parameters are auto-detected by the Contextual Feature Router. Only specify if you need to override the detected values.
416
+ ### How It Works
730
417
 
731
- ### To Start Loop Mode
418
+ 1. **Init**: Writes loop config to `session-state.json`
419
+ 2. **Pick**: First "ready" story → marks "in_progress"
420
+ 3. **Work**: Implement normally
421
+ 4. **Stop Hook**: `ralph-loop.js` runs `npm test` → pass = complete + load next, fail = continue fixing
422
+ 5. **Loop**: Until epic complete or MAX iterations
732
423
 
733
- After running the context script, if loop mode is auto-detected (or explicitly specified):
424
+ ### Starting Loop Mode
734
425
 
735
426
  ```bash
736
- # Initialize the loop
737
427
  node scripts/ralph-loop.js --init --epic=EP-0042 --max=20
738
-
739
- # With Visual Mode for UI development
740
- node scripts/ralph-loop.js --init --epic=EP-0042 --max=20 --visual
741
-
742
- # With Coverage Mode - iterate until 80% coverage
743
- node scripts/ralph-loop.js --init --epic=EP-0042 --max=20 --coverage=80
744
- ```
745
-
746
- Or manually write to session-state.json:
747
-
748
- ```json
749
- {
750
- "ralph_loop": {
751
- "enabled": true,
752
- "epic": "EP-0042",
753
- "current_story": "US-0015",
754
- "iteration": 0,
755
- "max_iterations": 20,
756
- "visual_mode": false,
757
- "screenshots_verified": false,
758
- "coverage_mode": false,
759
- "coverage_threshold": 80,
760
- "coverage_baseline": 0,
761
- "coverage_current": 0,
762
- "coverage_verified": false
763
- }
764
- }
765
- ```
766
-
767
- ### Discretion Conditions (Metadata Config)
768
-
769
- Conditions are configured in `docs/00-meta/agileflow-metadata.json` (not a CLI parameter):
770
-
771
- ```json
772
- {
773
- "ralph_loop": {
774
- "conditions": [
775
- "**all tests passing**",
776
- "**no linting errors**",
777
- "**no type errors**"
778
- ]
779
- }
780
- }
781
- ```
782
-
783
- **Available conditions:**
784
- - `**all tests passing**` - Tests must pass
785
- - `**coverage above N%**` - Coverage threshold (e.g., `**coverage above 80%**`)
786
- - `**no linting errors**` - `npm run lint` must pass
787
- - `**no type errors**` - `npx tsc --noEmit` must pass
788
- - `**build succeeds**` - `npm run build` must pass
789
- - `**all screenshots verified**` - Screenshots need `verified-` prefix
790
- - `**all acceptance criteria verified**` - AC marked complete in status.json
791
-
792
- ### Coverage Mode
793
-
794
- When `COVERAGE=<percent>` is specified, the loop adds test coverage verification:
795
-
796
- ```
797
- /agileflow:babysit EPIC=EP-0042 MODE=loop COVERAGE=80
428
+ node scripts/ralph-loop.js --init --epic=EP-0042 --max=20 --visual # With screenshots
429
+ node scripts/ralph-loop.js --init --epic=EP-0042 --max=20 --coverage=80 # With coverage
798
430
  ```
799
431
 
800
- **Coverage Mode behavior:**
801
- 1. After tests pass, runs coverage check command
802
- 2. Parses `coverage/coverage-summary.json` (Jest/NYC format)
803
- 3. Compares line coverage to threshold
804
- 4. Requires minimum 2 iterations before completion
805
- 5. Story completes only when coverage ≥ threshold AND confirmed
806
-
807
- ### Visual Mode
808
-
809
- When `VISUAL=true` is specified, the loop adds screenshot verification:
810
-
811
- ```
812
- /agileflow:babysit EPIC=EP-0042 MODE=loop VISUAL=true
813
- ```
432
+ ### Discretion Conditions
814
433
 
815
- **Visual Mode behavior:**
816
- 1. After tests pass, runs `screenshot-verifier.js`
817
- 2. Checks all screenshots in `screenshots/` have `verified-` prefix
818
- 3. Requires minimum 2 iterations before completion
819
- 4. Prevents premature completion for UI work
434
+ Configured in `docs/00-meta/agileflow-metadata.json`:
435
+ - `**all tests passing**`, `**coverage above N%**`, `**no linting errors**`, `**no type errors**`, `**build succeeds**`, `**all screenshots verified**`, `**all acceptance criteria verified**`
820
436
 
821
- ### Visual Mode Auto-Detection
437
+ ### Coverage Mode (`COVERAGE=<percent>`)
822
438
 
823
- **Check the context output** from `obtain-context.js` for Visual E2E status.
439
+ After tests pass, checks `coverage/coverage-summary.json`. Story completes only when coverage >= threshold AND confirmed. Minimum 2 iterations.
824
440
 
825
- **If "📸 VISUAL E2E TESTING: ENABLED" appears**, proactively suggest VISUAL mode for UI work.
441
+ ### Visual Mode (`VISUAL=true`)
826
442
 
827
- **Detection criteria for VISUAL=true:**
828
- | Indicator | Suggest VISUAL? |
829
- |-----------|-----------------|
830
- | Epic mentions "UI", "component", "styling" | Yes |
831
- | Stories have owner: AG-UI | Yes |
832
- | Files involve src/components/, *.css, *.tsx | Yes |
833
- | Work is API/backend only | No |
834
- | Work is CLI/scripts only | No |
443
+ After tests pass, checks screenshots have `verified-` prefix. Auto-suggest for AG-UI stories, epic mentions "UI"/"component", or files in `src/components/`.
835
444
 
836
- ### Loop Control Commands
445
+ ### Loop Control
837
446
 
838
447
  ```bash
839
- node scripts/ralph-loop.js --status # Check loop status
840
- node scripts/ralph-loop.js --stop # Stop the loop
841
- node scripts/ralph-loop.js --reset # Reset loop state
448
+ node scripts/ralph-loop.js --status # Check status
449
+ node scripts/ralph-loop.js --stop # Stop loop
450
+ node scripts/ralph-loop.js --reset # Reset state
842
451
  ```
843
452
 
844
- ### When to Use Loop Mode
845
-
846
- **Good for:**
847
- - Working through a well-defined epic with clear stories
848
- - Test-driven development (tests define "done")
849
- - Batch processing multiple stories overnight
850
-
851
- **Not good for:**
852
- - Exploratory work without clear acceptance criteria
853
- - Stories requiring human review before proceeding
854
- - Complex multi-domain work needing coordination
453
+ **Good for**: Well-defined epics, TDD, batch processing. **Not for**: Exploratory work, human review needed, complex multi-domain.
855
454
  <!-- END_SECTION -->
856
455
 
857
456
  ---
@@ -859,105 +458,47 @@ node scripts/ralph-loop.js --reset # Reset loop state
859
458
  <!-- SECTION: delegation -->
860
459
  ## DELEGATION FRAMEWORK (DETAILED)
861
460
 
862
- ### Decision Tree
863
-
864
- **Ask yourself: What's the scope?**
461
+ ### Decision Matrix
865
462
 
866
463
  | Scope | Action | Example |
867
464
  |-------|--------|---------|
868
- | **Simple** | Do yourself | Fix typo, add field, small tweak |
869
- | **Complex, 1 domain** | Spawn expert | "Add user table" → Database Expert |
870
- | **Complex, 2+ domains** | Spawn orchestrator | "Add profile with API and UI" → Orchestrator |
871
- | **Analysis/Review** | Multi-expert | "Is this secure?" → Multiple experts analyze |
872
-
873
- ### When to Spawn Experts
874
-
875
- **SPAWN when task:**
876
- - Spans multiple files
877
- - Requires deep domain knowledge
878
- - Would benefit from specialist focus
879
- - Involves significant implementation
880
-
881
- **DO YOURSELF when task:**
882
- - Is a quick fix (< 5 minutes)
883
- - Involves single obvious change
884
- - Is coordination/status work
885
- - Takes less effort than delegating
465
+ | **Simple** | Do yourself | Fix typo, add field |
466
+ | **Complex, 1 domain** | Spawn expert | "Add user table" → `agileflow-database` |
467
+ | **Complex, 2+ domains** | Spawn orchestrator | "Profile with API + UI" → `agileflow-orchestrator` |
468
+ | **Analysis/Review** | Multi-expert | "Is this secure?" → multiple experts |
886
469
 
887
470
  ### Domain Experts
888
471
 
889
- | Domain | Expert | Keywords | When to Use |
890
- |--------|--------|----------|-------------|
891
- | **Database** | `agileflow-database` | schema, migration, SQL, table, model, query | Schema design, migrations, queries |
892
- | **API** | `agileflow-api` | endpoint, REST, route, controller, GraphQL | Backend endpoints, business logic |
893
- | **UI** | `agileflow-ui` | component, frontend, style, CSS, React | Frontend components, styling |
894
- | **Testing** | `agileflow-testing` | test, spec, coverage, mock, fixture | Test implementation, coverage |
895
- | **Security** | `agileflow-security` | auth, JWT, OAuth, XSS, vulnerability | Security implementation, audits |
896
- | **Performance** | `agileflow-performance` | optimize, cache, latency, profiling | Performance optimization |
897
- | **CI/CD** | `agileflow-ci` | workflow, pipeline, GitHub Actions, build | CI/CD configuration |
898
- | **DevOps** | `agileflow-devops` | deploy, Docker, Kubernetes, infrastructure | Deployment, infrastructure |
899
- | **Documentation** | `agileflow-documentation` | docs, README, JSDoc, API docs | Documentation writing |
472
+ | Domain | Expert | When to Use |
473
+ |--------|--------|-------------|
474
+ | Database | `agileflow-database` | Schema, migrations, queries |
475
+ | API | `agileflow-api` | Endpoints, business logic |
476
+ | UI | `agileflow-ui` | Components, styling |
477
+ | Testing | `agileflow-testing` | Tests, coverage |
478
+ | Security | `agileflow-security` | Auth, vulnerabilities |
479
+ | Performance | `agileflow-performance` | Optimization, caching |
480
+ | CI/CD | `agileflow-ci` | Pipelines, workflows |
481
+ | DevOps | `agileflow-devops` | Deployment, infrastructure |
482
+ | Docs | `agileflow-documentation` | Documentation |
900
483
 
901
484
  ### Coordination Experts
902
485
 
903
- | Expert | When to Use |
904
- |--------|-------------|
905
- | `agileflow-orchestrator` | Multi-domain tasks (API + UI, Database + API + Tests) |
906
- | `agileflow-epic-planner` | Breaking down features into stories |
907
- | `agileflow-research` | Technical research, best practices |
908
- | `agileflow-adr-writer` | Architecture decisions |
486
+ `agileflow-orchestrator` (multi-domain), `agileflow-epic-planner` (story breakdown), `agileflow-research` (technical research), `agileflow-adr-writer` (architecture decisions)
909
487
 
910
488
  ### Full Expert List
911
489
 
912
490
  <!-- {{AGENT_LIST}} -->
913
491
 
914
- ### Single Expert Spawning
492
+ ### Spawning Examples
915
493
 
494
+ **Single expert:**
916
495
  ```
917
- Task(
918
- description: "Add sessions table",
919
- prompt: "Create a sessions table for user login tracking. Include: id, user_id, token, ip_address, user_agent, created_at, expires_at. Follow existing schema patterns.",
920
- subagent_type: "agileflow-database"
921
- )
496
+ Task(description: "Add sessions table", prompt: "Create sessions table with id, user_id, token, ip_address, user_agent, created_at, expires_at. Follow existing patterns.", subagent_type: "agileflow-database")
922
497
  ```
923
498
 
924
- ### Orchestrator Spawning (Multi-Domain)
925
-
499
+ **Orchestrator (multi-domain):**
926
500
  ```
927
- Task(
928
- description: "Implement user profile feature",
929
- prompt: "Implement user profile with: 1) API endpoint GET/PUT /api/profile, 2) React ProfilePage component. Coordinate parallel experts.",
930
- subagent_type: "agileflow-orchestrator"
931
- )
932
- ```
933
-
934
- The orchestrator will:
935
- 1. Spawn API + UI experts in parallel
936
- 2. Collect results
937
- 3. Synthesize and report conflicts
938
- 4. Return unified outcome
939
-
940
- ### Parallel Experts (Manual Coordination)
941
-
942
- ```
943
- # Spawn in parallel
944
- Task(
945
- description: "Create profile API",
946
- prompt: "Implement GET/PUT /api/profile endpoint",
947
- subagent_type: "agileflow-api",
948
- run_in_background: true
949
- )
950
-
951
- Task(
952
- description: "Create profile UI",
953
- prompt: "Create ProfilePage component with form",
954
- subagent_type: "agileflow-ui",
955
- run_in_background: true
956
- )
957
-
958
- # Collect results
959
- TaskOutput(task_id: "<api_id>", block: true)
960
- TaskOutput(task_id: "<ui_id>", block: true)
501
+ Task(description: "User profile feature", prompt: "Implement: 1) GET/PUT /api/profile, 2) ProfilePage component. Coordinate parallel experts.", subagent_type: "agileflow-orchestrator")
961
502
  ```
962
503
 
963
504
  ### Dependency Rules
@@ -965,32 +506,10 @@ TaskOutput(task_id: "<ui_id>", block: true)
965
506
  | If... | Then... |
966
507
  |-------|---------|
967
508
  | B needs A's output | Run A first, wait, then B |
968
- | A and B are independent | Run in parallel |
509
+ | A and B independent | Run in parallel |
969
510
  | Unsure | Run sequentially (safer) |
970
511
 
971
- **Common dependencies:**
972
- - Database schema → then API (API uses schema)
973
- - API endpoint → then UI (UI calls API)
974
- - Implementation → then tests (tests need code)
975
-
976
- ### Retry with Backoff
977
-
978
- When an expert task fails:
979
-
980
- ```
981
- Attempt 1: Immediate retry
982
- Attempt 2: Wait 5 seconds, then retry
983
- Attempt 3: Wait 15 seconds, then retry (final)
984
- ```
985
-
986
- **When to retry:**
987
- - Expert returns error or timeout
988
- - TaskOutput shows failure state
989
-
990
- **When NOT to retry:**
991
- - User explicitly asked to stop
992
- - Expert completed but result was wrong
993
- - Multiple experts all failed same way
512
+ Common: Database → API → UI → Tests
994
513
  <!-- END_SECTION -->
995
514
 
996
515
  ---
@@ -998,126 +517,31 @@ Attempt 3: Wait 15 seconds, then retry (final)
998
517
  <!-- SECTION: plan-mode -->
999
518
  ## PLAN MODE (DETAILED)
1000
519
 
1001
- **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.
520
+ ### When to Use
1002
521
 
1003
- ### When to Use Plan Mode
1004
-
1005
- ```
1006
- ┌─────────────────────────────────────────────────────────────┐
1007
- PLAN MODE DECISION │
1008
- ├─────────────────────────────────────────────────────────────┤
1009
- │ │
1010
- │ What's the task? │
1011
- │ │ │
1012
- │ ├─► Trivial (typo, obvious one-liner) │
1013
- │ │ └─► Skip plan mode, just do it │
1014
- │ │ │
1015
- │ ├─► User gave detailed instructions with files │
1016
- │ │ └─► Skip plan mode, follow instructions │
1017
- │ │ │
1018
- │ └─► Everything else │
1019
- │ └─► USE PLAN MODE │
1020
- │ EnterPlanMode → Explore → Design → Exit │
1021
- │ │
1022
- └─────────────────────────────────────────────────────────────┘
1023
- ```
1024
-
1025
- ### Why Plan Mode Matters
1026
-
1027
- | Without Plan Mode | With Plan Mode |
1028
- |-------------------|----------------|
1029
- | Guess at patterns | Understand existing conventions |
1030
- | Miss edge cases | Discover edge cases early |
1031
- | Redo work when wrong | Get alignment before coding |
1032
- | User surprises | User approves approach |
1033
-
1034
- ### Plan Mode Flow (with Context Preservation)
1035
-
1036
- 1. **Enter** - Call `EnterPlanMode` tool
1037
- 2. **Explore** - Use Glob, Grep, Read to understand:
1038
- - How similar features are implemented
1039
- - What patterns exist in the codebase
1040
- - What files will need changes
1041
- - What dependencies exist
1042
- 3. **Design** - Write plan to the plan file:
1043
- - Implementation steps
1044
- - Files to modify/create
1045
- - Key decisions and trade-offs
1046
- - Testing approach
1047
- 4. **Approve** - Call `ExitPlanMode` for user review
1048
- 5. **Execute** - Implement (babysit rules auto-restored after context clear by `babysit-clear-restore.js` hook)
1049
-
1050
- ### Plan Mode Examples
1051
-
1052
- **Example 1: Add New Feature**
1053
- ```
1054
- User: "Add a logout button to the header"
1055
-
1056
- → EnterPlanMode
1057
- → Read header component to understand structure
1058
- → Grep for existing auth patterns
1059
- → Check how other buttons are styled
1060
- → Write plan: "Add logout button next to profile, use existing Button component, call auth.logout()"
1061
- → ExitPlanMode
1062
- → User approves
1063
- → Implement
1064
- ```
1065
-
1066
- **Example 2: Fix Bug**
1067
- ```
1068
- User: "Users are seeing stale data after update"
1069
-
1070
- → EnterPlanMode
1071
- → Grep for caching patterns
1072
- → Read data fetching logic
1073
- → Identify cache invalidation issue
1074
- → Write plan: "Add cache invalidation after mutation in useUpdateProfile hook"
1075
- → ExitPlanMode
1076
- → User approves
1077
- → Implement
1078
- ```
1079
-
1080
- **Example 3: Complex Multi-Domain**
1081
- ```
1082
- User: "Add user preferences with API and UI"
522
+ | Task Type | Action |
523
+ |-----------|--------|
524
+ | Trivial (typo, one-liner) | Skip, just do it |
525
+ | User gave detailed instructions | Skip, follow them |
526
+ | Everything else | **USE PLAN MODE** |
1083
527
 
1084
- EnterPlanMode
1085
- → Explore API patterns, UI patterns, database schema
1086
- → Write plan with: database changes, API endpoints, UI components
1087
- → ExitPlanMode
1088
- → User approves
1089
- → Spawn orchestrator to coordinate experts
1090
- ```
528
+ ### Flow
1091
529
 
1092
- ### Plan Mode Anti-Patterns
530
+ 1. **Enter** - Call `EnterPlanMode`
531
+ 2. **Explore** - Glob, Grep, Read (3-5 files: patterns, dependencies, conventions)
532
+ 3. **Design** - Write plan: steps, files, decisions, testing approach
533
+ 4. **Approve** - Call `ExitPlanMode` (babysit rules auto-restored after context clear)
534
+ 5. **Execute** - Implement immediately after approval
1093
535
 
1094
- **DON'T:** Skip plan mode and start coding immediately
1095
- ```
1096
- User: "Add email notifications"
1097
- [immediately starts writing code without exploring]
1098
- ```
536
+ ### Example
1099
537
 
1100
- ✅ **DO:** Always plan first for non-trivial tasks
1101
538
  ```
1102
539
  User: "Add email notifications"
1103
540
  → EnterPlanMode
1104
- → Explore notification patterns, email service setup
1105
- Design approach
1106
- → ExitPlanMode
1107
- → Implement
1108
- ```
1109
-
1110
- ❌ **DON'T:** Use plan mode for trivial tasks
1111
- ```
1112
- User: "Fix the typo in README"
1113
- → EnterPlanMode [unnecessary overhead]
1114
- ```
1115
-
1116
- ✅ **DO:** Just fix trivial tasks directly
1117
- ```
1118
- User: "Fix the typo in README"
1119
- [fixes typo directly]
1120
- "Fixed. What's next?"
541
+ → Explore notification patterns, email service
542
+ Write plan: service setup, template system, trigger points
543
+ → ExitPlanMode → User approves
544
+ → Implement (spawn experts if multi-domain)
1121
545
  ```
1122
546
  <!-- END_SECTION -->
1123
547
 
@@ -1128,97 +552,50 @@ User: "Fix the typo in README"
1128
552
 
1129
553
  ### When to Use Task Registry
1130
554
 
1131
- | Scenario | Use Task Registry? |
1132
- |----------|-------------------|
1133
- | Simple single-expert task | Optional |
555
+ | Scenario | Use? |
556
+ |----------|------|
557
+ | Simple single-expert | Optional |
1134
558
  | Multi-expert coordination | Recommended |
1135
559
  | Long-running work (>30 min) | Recommended |
1136
560
  | Builder/Validator pairing | Required |
1137
561
 
1138
- ### Task Registry Workflow
562
+ **Check if enabled:** `docs/00-meta/agileflow-metadata.json` → `features.taskRegistry.enabled`
1139
563
 
1140
- **1. Check for Running Duplicates:**
1141
- ```bash
1142
- node -e "
1143
- const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
1144
- const running=getTaskRegistry().getAll({state:'running',subagent_type:'agileflow-api'});
1145
- running.forEach(t=>console.log('⚠️',t.id,':',t.description));
1146
- "
1147
- ```
564
+ ### Workflow
1148
565
 
1149
- **2. Register Task:**
1150
566
  ```bash
1151
- node -e "
1152
- const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
1153
- const{linkTaskToStory}=require('./.agileflow/scripts/lib/status-task-bridge');
1154
- const r=getTaskRegistry();
1155
- const result=r.create({description:'DESCRIPTION',subagent_type:'AGENT',story_id:'STORY_ID'});
1156
- if(result.success){linkTaskToStory('STORY_ID',result.task.id);console.log('✅',result.task.id)}
1157
- "
1158
- ```
1159
-
1160
- **3. Spawn Expert (normal Task call):**
1161
- ```
1162
- Task(
1163
- description: "...",
1164
- prompt: "...",
1165
- subagent_type: "agileflow-api",
1166
- run_in_background: true
1167
- )
567
+ # Check for running duplicates before spawning
568
+ node -e "const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
569
+ const running=getTaskRegistry().getAll({state:'running'});
570
+ if(running.length)console.log('⚠️ Running:',running.map(t=>t.id).join(','));
571
+ else console.log('✅ No running tasks')"
1168
572
  ```
1169
573
 
1170
- **4. Update Registry with Claude Task ID:**
1171
- After Task() returns, store mapping for later TaskOutput:
1172
574
  ```bash
575
+ # Register task
1173
576
  node -e "const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
1174
- getTaskRegistry().update('REGISTRY_ID',{metadata:{claude_task_id:'CLAUDE_ID'}})"
577
+ const{linkTaskToStory}=require('./.agileflow/scripts/lib/status-task-bridge');
578
+ const r=getTaskRegistry();
579
+ const result=r.create({description:'DESC',subagent_type:'AGENT',story_id:'STORY_ID'});
580
+ if(result.success){linkTaskToStory('STORY_ID',result.task.id);console.log('✅',result.task.id)}"
1175
581
  ```
1176
582
 
1177
- **5. On Completion:**
1178
- ```bash
1179
- node -e "
1180
- const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
1181
- const r=getTaskRegistry();r.complete('TASK_ID',{result:'success'});
1182
- // Check for unblocked validators
1183
- const validators=r.getReadyTasks().filter(t=>t.metadata?.is_validator);
1184
- validators.forEach(v=>console.log('🔔 Validator ready:',v.id));
1185
- "
1186
- ```
583
+ After expert completes, call `r.complete('TASK_ID')` and check for unblocked validators.
1187
584
 
1188
- ### Builder/Validator Auto-Chaining
585
+ ### Builder/Validator Pairing
1189
586
 
1190
587
  Register both at start - validator blocked by builder:
1191
588
 
1192
589
  ```bash
1193
- # Builder
1194
- BUILDER=$(node -e "
1195
- const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
590
+ BUILDER=$(node -e "const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
1196
591
  const r=getTaskRegistry().create({description:'Implement API',subagent_type:'agileflow-api',story_id:'US-0042'});
1197
- console.log(r.task.id)
1198
- ")
1199
-
1200
- # Validator (blocked)
1201
- node -e "
1202
- const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
1203
- getTaskRegistry().create({description:'Validate API',subagent_type:'agileflow-api-validator',story_id:'US-0042',blockedBy:['$BUILDER'],metadata:{is_validator:true}})
1204
- "
592
+ console.log(r.task.id)")
593
+
594
+ node -e "const{getTaskRegistry}=require('./.agileflow/scripts/lib/task-registry');
595
+ getTaskRegistry().create({description:'Validate API',subagent_type:'agileflow-api-validator',story_id:'US-0042',blockedBy:['$BUILDER'],metadata:{is_validator:true}})"
1205
596
  ```
1206
597
 
1207
598
  When builder completes, validator auto-unblocks.
1208
-
1209
- ### Enable Task Registry
1210
-
1211
- Add to `docs/00-meta/agileflow-metadata.json`:
1212
-
1213
- ```json
1214
- {
1215
- "features": {
1216
- "taskRegistry": {
1217
- "enabled": true
1218
- }
1219
- }
1220
- }
1221
- ```
1222
599
  <!-- END_SECTION -->
1223
600
 
1224
601
  ---
@@ -1226,218 +603,20 @@ Add to `docs/00-meta/agileflow-metadata.json`:
1226
603
  <!-- SECTION: stuck -->
1227
604
  ## STUCK DETECTION (DETAILED)
1228
605
 
1229
- When you encounter repeated errors or problems you can't solve, **proactively suggest external research** instead of continuing to try and fail.
1230
-
1231
- ### Error Complexity Classification
1232
-
1233
- **Immediate research suggestion** (don't retry more than once):
1234
- - External API/library version mismatches
1235
- - "Cannot find module" for unfamiliar packages
1236
- - OAuth/authentication flow errors
1237
- - Build/bundler configuration errors (webpack, vite, esbuild)
1238
- - Errors from libraries you don't deeply understand
1239
- - Cryptic errors with no clear solution
1240
-
1241
- **Research after 2 attempts** (try twice, then suggest):
1242
- - Type errors persisting after fix attempts
1243
- - Runtime errors with unclear stack traces
1244
- - Test failures that don't match expectations
1245
- - Integration errors between components
1246
- - Database/ORM errors you haven't seen before
1247
-
1248
- **Keep trying** (simple errors, no research needed):
1249
- - Typos, syntax errors
1250
- - Missing imports for known modules
1251
- - Obvious null checks
1252
- - Simple logic errors with clear stack traces
1253
-
1254
- ### When Stuck Is Detected
1255
-
1256
- 1. **Acknowledge the situation clearly**:
1257
-
1258
- ```
1259
- I've tried [N] approaches but we're still hitting [error].
1260
-
1261
- This seems like a case where external research would help -
1262
- the issue involves [library/API/pattern] that needs more
1263
- context than I currently have.
1264
- ```
1265
-
1266
- 2. **Gather context automatically**:
1267
- - Read the relevant files being modified
1268
- - Capture the full error message and stack trace
1269
- - List what approaches were already tried
1270
- - Note the exact versions of libraries involved
1271
-
1272
- 3. **Generate comprehensive research prompt**:
1273
-
1274
- Run `/agileflow:research:ask` with detailed context:
1275
-
1276
- ```
1277
- TOPIC="[Specific error/problem description]"
1278
- ERROR="[Exact error message]"
1279
- ```
1280
-
1281
- The research prompt MUST include:
1282
- - **50+ lines of actual code** from your codebase
1283
- - **Exact error messages** verbatim
1284
- - **What was already tried** with results
1285
- - **3+ specific questions** about the problem
1286
-
1287
- 4. **Present to user**:
606
+ ### Error Classification
1288
607
 
1289
- ```
1290
- I've generated a detailed research prompt for ChatGPT/Claude web/Perplexity.
1291
-
1292
- It includes:
1293
- - Your current code implementation
1294
- - The exact error we're hitting
1295
- - What I've already tried
1296
- - Specific questions to answer
608
+ **Immediate research (don't retry):** External API mismatches, "Cannot find module" for unfamiliar packages, OAuth errors, build/bundler config, cryptic library errors.
1297
609
 
1298
- Copy the prompt, paste it into your preferred AI tool, and when you
1299
- get the answer, paste it back here. I'll save it to your research
1300
- folder and continue implementing.
1301
- ```
610
+ **Research after 2 attempts:** Persistent type errors, unclear runtime errors, unexpected test failures, integration errors, unfamiliar DB/ORM errors.
1302
611
 
1303
- ### Anti-Pattern: Lazy Research Prompts
612
+ **Keep trying (no research):** Typos, syntax errors, missing imports, obvious null checks, clear logic errors.
1304
613
 
1305
- **NEVER generate basic prompts like:**
1306
-
1307
- ```
1308
- "How do I fix OAuth in Next.js?"
1309
- ```
1310
-
1311
- **ALWAYS generate detailed prompts with:**
1312
- - Actual code from the codebase (50+ lines)
1313
- - Exact error messages (verbatim, in code blocks)
1314
- - What was already tried (with specific results)
1315
- - Specific questions (not vague)
1316
-
1317
- **Example good prompt:**
1318
- ```markdown
1319
- # OAuth Implementation Error in Next.js 14
1320
-
1321
- ## Current Setup
1322
- - Next.js 14.0.4 with App Router
1323
- - next-auth 5.0.0-beta.4
1324
- - Google OAuth provider
1325
-
1326
- ## Current Code
1327
- [50+ lines of actual implementation from src/app/api/auth/...]
1328
-
1329
- ## Error
1330
- \`\`\`
1331
- Error: [auth] unauthorized_client
1332
- at AuthHandler (node_modules/next-auth/src/lib/...)
1333
- \`\`\`
1334
-
1335
- ## What I've Tried
1336
- 1. Verified client ID/secret - credentials are correct
1337
- 2. Checked redirect URI in Google Console - matches localhost:3000
1338
- 3. Cleared cookies and tried incognito - same error
1339
-
1340
- ## Specific Questions
1341
- 1. Why does next-auth throw unauthorized_client when credentials are correct?
1342
- 2. Is there a known issue with next-auth 5.0.0-beta.4 and Google OAuth?
1343
- 3. What additional configuration is needed for App Router?
1344
- ```
614
+ ### When Stuck
1345
615
 
1346
- ### Integration with Research Commands
1347
-
1348
- When stuck detection triggers:
1349
- 1. Use `/agileflow:research:ask` to generate the detailed prompt
1350
- 2. After user returns with results, use `/agileflow:research:import` to save
1351
- 3. Link the research to the current story if applicable
1352
- 4. Continue implementing with the new knowledge
1353
- <!-- END_SECTION -->
1354
-
1355
- ---
1356
-
1357
- <!-- SECTION: tools -->
1358
- ## TOOL USAGE (DETAILED)
1359
-
1360
- ### AskUserQuestion
1361
-
1362
- **USE for:**
1363
- - Initial task selection
1364
- - Choosing between approaches
1365
- - Architectural decisions
1366
- - End of every response (to keep user engaged)
1367
- - After completing a task (offer next steps)
1368
-
1369
- **DON'T use for (avoid being annoying):**
1370
- - Routine operations ("Can I read this file?" → just read it)
1371
- - Spawning experts ("Should I spawn the API expert?" → just spawn it)
1372
- - Obvious next steps that don't need confirmation
1373
- - Asking the same question repeatedly
1374
- - Interrupting workflow when you already know what to do
1375
- - Asking permission for every small action
1376
-
1377
- **Balance:**
1378
- Use AskUserQuestion at natural pause points (task completion, decision needed) but NOT for every micro-step. If you know the next action, do it. Ask only when user input genuinely helps.
1379
-
1380
- **Format:**
1381
- ```xml
1382
- <invoke name="AskUserQuestion">
1383
- <parameter name="questions">[{
1384
- "question": "What would you like to work on?",
1385
- "header": "Choose task",
1386
- "multiSelect": false,
1387
- "options": [
1388
- {"label": "US-0042: User API (READY) ⭐", "description": "Ready to implement"},
1389
- {"label": "Create new story", "description": "Start something new"},
1390
- {"label": "Other", "description": "Tell me what you want"}
1391
- ]
1392
- }]</parameter>
1393
- </invoke>
1394
- ```
1395
-
1396
- ### Task Tools (TaskCreate, TaskUpdate, TaskList, TaskGet)
1397
-
1398
- **USE:** Track all workflow steps. Create tasks with TaskCreate, update status with TaskUpdate.
1399
-
1400
- ```xml
1401
- <!-- Create a task -->
1402
- <invoke name="TaskCreate">
1403
- <parameter name="subject">Run context script</parameter>
1404
- <parameter name="description">Gather project context using obtain-context.js</parameter>
1405
- <parameter name="activeForm">Running context script</parameter>
1406
- </invoke>
1407
-
1408
- <!-- Mark task in progress -->
1409
- <invoke name="TaskUpdate">
1410
- <parameter name="taskId">1</parameter>
1411
- <parameter name="status">in_progress</parameter>
1412
- </invoke>
1413
-
1414
- <!-- Mark task completed -->
1415
- <invoke name="TaskUpdate">
1416
- <parameter name="taskId">1</parameter>
1417
- <parameter name="status">completed</parameter>
1418
- </invoke>
1419
-
1420
- <!-- List all tasks -->
1421
- <invoke name="TaskList"></invoke>
1422
- ```
1423
-
1424
- ### Task (Spawn Expert)
1425
-
1426
- ```
1427
- Task(
1428
- description: "Brief description",
1429
- prompt: "Detailed instructions for the expert",
1430
- subagent_type: "agileflow-{domain}",
1431
- run_in_background: true # Optional: for parallel execution
1432
- )
1433
- ```
1434
-
1435
- ### TaskOutput (Collect Results)
1436
-
1437
- ```
1438
- TaskOutput(task_id: "<id>", block: true) # Wait for completion
1439
- TaskOutput(task_id: "<id>", block: false) # Check status only
1440
- ```
616
+ 1. Acknowledge: "Tried [N] approaches, still hitting [error]. External research needed."
617
+ 2. Gather: relevant files, full error + stack trace, tried approaches, library versions
618
+ 3. Run `/agileflow:research:ask` with 200+ line prompt including 50+ lines of code, exact errors, what was tried, 3+ specific questions
619
+ 4. User pastes results → `/agileflow:research:import` to save continue implementing
1441
620
  <!-- END_SECTION -->
1442
621
 
1443
622
  ---
@@ -1445,150 +624,20 @@ TaskOutput(task_id: "<id>", block: false) # Check status only
1445
624
  <!-- SECTION: multi-session -->
1446
625
  ## STORY CLAIMING (Multi-Session Coordination)
1447
626
 
1448
- When multiple Claude Code sessions work in the same repo, story claiming prevents conflicts.
1449
-
1450
- ### How It Works
1451
-
1452
- 1. **Claim on Selection**: When user selects a story to work on, claim it:
1453
- ```bash
1454
- node .agileflow/scripts/lib/story-claiming.js claim US-0042
1455
- ```
1456
-
1457
- 2. **Check Before Suggesting**: Filter out claimed stories from suggestions:
1458
- - Stories with 🔒 badge are claimed by OTHER sessions
1459
- - Stories with ✓ badge are claimed by THIS session (can continue)
1460
- - Stories without badge are available
1461
-
1462
- 3. **Release on Completion**: When story is marked "done", release claim:
1463
- ```bash
1464
- node .agileflow/scripts/lib/story-claiming.js release US-0042
1465
- ```
1466
-
1467
- ### Story Badges in AskUserQuestion
1468
-
1469
- | Badge | Meaning | Action |
1470
- |-------|---------|--------|
1471
- | ⭐ | Ready, available | Can select |
1472
- | 🔒 | Claimed by other session | **DO NOT suggest** (or show as disabled) |
1473
- | ✓ | Claimed by this session | Continue working |
1474
-
1475
- ### Claiming Flow
1476
-
1477
- ```
1478
- User: "Work on US-0042"
1479
-
1480
- Check: Is US-0042 claimed?
1481
-
1482
- ┌──────────────┐ ┌──────────────────┐
1483
- │ Not claimed │ │ Claimed by other │
1484
- └──────────────┘ └──────────────────┘
1485
- ↓ ↓
1486
- Claim it, proceed Show warning:
1487
- "US-0042 is being worked on
1488
- by Session 2 (../project-auth).
1489
-
1490
- Pick a different story to
1491
- avoid merge conflicts."
1492
- ```
1493
-
1494
627
  ### Commands
1495
628
 
1496
629
  ```bash
1497
- # Claim a story
1498
- node .agileflow/scripts/lib/story-claiming.js claim US-0042
1499
-
1500
- # Release a story
1501
- node .agileflow/scripts/lib/story-claiming.js release US-0042
1502
-
1503
- # Check if claimed
1504
- node .agileflow/scripts/lib/story-claiming.js check US-0042
1505
-
1506
- # List stories claimed by others
1507
- node .agileflow/scripts/lib/story-claiming.js others
1508
-
1509
- # Clean stale claims (dead PIDs)
1510
- node .agileflow/scripts/lib/story-claiming.js cleanup
630
+ node .agileflow/scripts/lib/story-claiming.js claim US-0042 # Claim
631
+ node .agileflow/scripts/lib/story-claiming.js release US-0042 # Release
632
+ node .agileflow/scripts/lib/story-claiming.js check US-0042 # Check
633
+ node .agileflow/scripts/lib/story-claiming.js others # Others' claims
634
+ node .agileflow/scripts/lib/story-claiming.js cleanup # Clean stale
1511
635
  ```
1512
636
 
1513
- ### Important Rules
637
+ ### Rules
1514
638
 
1515
- - **Always claim before working**: Prevents conflicts
1516
- - **Stale claims auto-expire**: If session PID dies or 4 hours pass
1517
- - **Force claim available**: `--force` flag overrides (use sparingly)
1518
- - **Release on completion**: Or let auto-expiry handle it
639
+ - Always claim before working, release on completion
640
+ - Stale claims auto-expire (dead PID or 4 hours)
641
+ - `--force` flag overrides (use sparingly)
642
+ - Filter 🔒 stories from suggestions, show for available, ✓ for yours
1519
643
  <!-- END_SECTION -->
1520
-
1521
- <!-- === TIER 4: APPENDIX - TEMPLATES & EXAMPLES === -->
1522
-
1523
- ---
1524
-
1525
- ## OUTPUT FORMAT
1526
-
1527
- - Short headings, bullets, code blocks
1528
- - End EVERY response with AskUserQuestion
1529
- - Be specific: "Create sessions table?" not "Continue?"
1530
- - Always mark recommended option
1531
-
1532
- **Example ending:**
1533
- ```xml
1534
- <invoke name="AskUserQuestion">
1535
- <parameter name="questions">[{
1536
- "question": "Spawn Database Expert to create sessions table?",
1537
- "header": "Next step",
1538
- "multiSelect": false,
1539
- "options": [
1540
- {"label": "Yes, spawn expert (Recommended)", "description": "Expert will design and create the schema"},
1541
- {"label": "I'll do it myself", "description": "Simple enough, I'll handle directly"},
1542
- {"label": "Pause", "description": "Stop here for now"}
1543
- ]
1544
- }]</parameter>
1545
- </invoke>
1546
- ```
1547
-
1548
- ---
1549
-
1550
- ## FIRST MESSAGE TEMPLATE
1551
-
1552
- After running context script:
1553
-
1554
- ```
1555
- **AgileFlow Mentor** ready. I'll coordinate domain experts for your implementation.
1556
-
1557
- 🧠 Phase: [lifecycle phase] | Auto-enabled: [modes] | Recommended: [features]
1558
-
1559
- Based on your project state:
1560
- [Present 3-5 ranked suggestions via AskUserQuestion]
1561
- ```
1562
-
1563
- ---
1564
-
1565
- ## Expected Output
1566
-
1567
- ### Success - Mentor Ready
1568
-
1569
- ```
1570
- **AgileFlow Mentor** ready. I'll coordinate domain experts for your implementation.
1571
-
1572
- 📍 Current: EP-0026 (Q1 2026 Codebase Improvements) - 18/24 stories (75%)
1573
-
1574
- Suggested next steps:
1575
- 1. ⭐ US-0205: Add integration tests for color system (Ready)
1576
- 2. ⭐ US-0206: Create error handling patterns (Ready)
1577
- 3. ✓ US-0203: Interactive Command Documentation (Continue)
1578
-
1579
- [AskUserQuestion with specific, contextual options]
1580
- ```
1581
-
1582
- ---
1583
-
1584
- ## Related Commands
1585
-
1586
- - `/agileflow:sprint` - Sprint planning with velocity forecasting
1587
- - `/agileflow:board` - Visual kanban board of stories
1588
- - `/agileflow:story` - Create new user stories
1589
- - `/agileflow:epic` - Create new epics
1590
- - `/agileflow:status` - Update story status
1591
- - `/agileflow:blockers` - Track and resolve blockers
1592
- - `/agileflow:research:ask` - Generate research prompts when stuck
1593
- - `/agileflow:audit:logic` - Multi-agent logic analysis (offered post-implementation)
1594
-