agileflow 2.74.0 → 2.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +3 -3
  2. package/package.json +1 -1
  3. package/scripts/agileflow-configure.js +105 -27
  4. package/scripts/agileflow-welcome.js +95 -2
  5. package/scripts/auto-self-improve.js +301 -0
  6. package/scripts/ralph-loop.js +491 -0
  7. package/src/core/agents/accessibility.md +1 -1
  8. package/src/core/agents/adr-writer.md +6 -6
  9. package/src/core/agents/analytics.md +1 -1
  10. package/src/core/agents/api.md +130 -41
  11. package/src/core/agents/ci.md +3 -3
  12. package/src/core/agents/compliance.md +1 -1
  13. package/src/core/agents/database.md +121 -36
  14. package/src/core/agents/datamigration.md +1 -1
  15. package/src/core/agents/design.md +2 -2
  16. package/src/core/agents/devops.md +2 -2
  17. package/src/core/agents/documentation.md +2 -2
  18. package/src/core/agents/epic-planner.md +4 -4
  19. package/src/core/agents/integrations.md +4 -4
  20. package/src/core/agents/mentor.md +6 -6
  21. package/src/core/agents/mobile.md +2 -2
  22. package/src/core/agents/monitoring.md +2 -2
  23. package/src/core/agents/performance.md +2 -2
  24. package/src/core/agents/product.md +3 -3
  25. package/src/core/agents/qa.md +1 -1
  26. package/src/core/agents/refactor.md +1 -1
  27. package/src/core/agents/security.md +4 -4
  28. package/src/core/agents/testing.md +2 -2
  29. package/src/core/agents/ui.md +129 -44
  30. package/src/core/commands/babysit.md +210 -0
  31. package/src/core/commands/blockers.md +3 -3
  32. package/src/core/commands/configure.md +50 -7
  33. package/src/core/commands/context/export.md +99 -0
  34. package/src/core/commands/context/full.md +172 -0
  35. package/src/core/commands/context/note.md +128 -0
  36. package/src/core/commands/research/ask.md +453 -0
  37. package/src/core/commands/research/import.md +287 -0
  38. package/src/core/commands/research/list.md +93 -0
  39. package/src/core/commands/research/view.md +113 -0
  40. package/src/core/experts/documentation/expertise.yaml +4 -0
  41. package/src/core/experts/research/expertise.yaml +4 -4
  42. package/tools/cli/lib/docs-setup.js +1 -1
  43. package/src/core/commands/context.md +0 -417
  44. package/src/core/commands/research.md +0 -124
@@ -282,7 +282,7 @@ COORDINATION WITH EPIC-PLANNER
282
282
 
283
283
  SLASH COMMANDS
284
284
 
285
- - `/agileflow:context MODE=research TOPIC=...` → Research user needs, competitive analysis
285
+ - `/agileflow:research:ask TOPIC=...` → Research user needs, competitive analysis
286
286
  - `/agileflow:adr-new` → Document product decisions
287
287
  - `/agileflow:tech-debt` → Document product debt (unclear requirements, scope creep)
288
288
  - `/agileflow:status STORY=... STATUS=...` → Update status
@@ -296,8 +296,8 @@ RESEARCH INTEGRATION
296
296
  4. Research industry standards
297
297
 
298
298
  **Suggest Research**:
299
- - `/agileflow:context MODE=research TOPIC="Best practices for [feature type]"`
300
- - `/agileflow:context MODE=research TOPIC="User needs analysis for [user type]"`
299
+ - `/agileflow:research:ask TOPIC="Best practices for [feature type]"`
300
+ - `/agileflow:research:ask TOPIC="User needs analysis for [user type]"`
301
301
 
302
302
  WORKFLOW
303
303
 
@@ -650,7 +650,7 @@ COORDINATION WITH OTHER AGENTS
650
650
 
651
651
  SLASH COMMANDS
652
652
 
653
- - `/agileflow:context MODE=research TOPIC=...` → Research QA best practices
653
+ - `/agileflow:research:ask TOPIC=...` → Research QA best practices
654
654
  - `/agileflow:ai-code-review` → Review test strategy for completeness
655
655
  - `/agileflow:adr-new` → Document QA decisions
656
656
  - `/agileflow:status STORY=... STATUS=...` → Update status
@@ -453,7 +453,7 @@ COORDINATION WITH OTHER AGENTS
453
453
 
454
454
  SLASH COMMANDS
455
455
 
456
- - `/agileflow:context MODE=research TOPIC=...` → Research refactoring patterns, modern approaches
456
+ - `/agileflow:research:ask TOPIC=...` → Research refactoring patterns, modern approaches
457
457
  - `/agileflow:ai-code-review` → Review refactored code for quality
458
458
  - `/agileflow:adr-new` → Document refactoring decisions
459
459
  - `/agileflow:tech-debt` → Track and manage technical debt
@@ -332,9 +332,9 @@ RESEARCH INTEGRATION
332
332
  4. Research common vulnerabilities in that tech stack
333
333
 
334
334
  **Suggest Research**:
335
- - `/agileflow:context MODE=research TOPIC="OWASP Top 10 for [framework] and how to prevent"`
336
- - `/agileflow:context MODE=research TOPIC="JWT best practices and token refresh strategy"`
337
- - `/agileflow:context MODE=research TOPIC="Input validation patterns for [language]"`
335
+ - `/agileflow:research:ask TOPIC="OWASP Top 10 for [framework] and how to prevent"`
336
+ - `/agileflow:research:ask TOPIC="JWT best practices and token refresh strategy"`
337
+ - `/agileflow:research:ask TOPIC="Input validation patterns for [language]"`
338
338
 
339
339
  THREAT MODELING (for major features)
340
340
 
@@ -349,7 +349,7 @@ When implementing significant features, consider:
349
349
  SLASH COMMANDS (Proactive Use)
350
350
 
351
351
  **Security Research & Analysis**:
352
- - `/agileflow:context MODE=research TOPIC=...` → Research security patterns, vulnerabilities, compliance
352
+ - `/agileflow:research:ask TOPIC=...` → Research security patterns, vulnerabilities, compliance
353
353
  - `/agileflow:impact-analysis` → Analyze security impact of code changes
354
354
 
355
355
  **Quality & Review**:
@@ -110,7 +110,7 @@ If tests failing but must proceed:
110
110
  - `/agileflow:verify US-XXXX` → Run tests for story (updates test_status)
111
111
  - `/agileflow:session:resume` → Load context and verify environment
112
112
  - `/agileflow:baseline "message"` → Create known-good baseline (requires passing tests)
113
- - `/agileflow:context MODE=research TOPIC=...` → Research test patterns
113
+ - `/agileflow:research:ask TOPIC=...` → Research test patterns
114
114
  - `/agileflow:ai-code-review` → Review test code for anti-patterns
115
115
  - `/agileflow:adr-new` → Document testing decisions
116
116
 
@@ -421,7 +421,7 @@ COORDINATION WITH OTHER AGENTS
421
421
 
422
422
  SLASH COMMANDS
423
423
 
424
- - `/agileflow:context MODE=research TOPIC=...` → Research test patterns, best practices
424
+ - `/agileflow:research:ask TOPIC=...` → Research test patterns, best practices
425
425
  - `/agileflow:ai-code-review` → Review test code for anti-patterns
426
426
  - `/agileflow:adr-new` → Document testing decisions
427
427
  - `/agileflow:tech-debt` → Document test debt (low coverage areas, flaky tests)
@@ -79,7 +79,7 @@ node .agileflow/scripts/obtain-context.js ui
79
79
  - AG-API: Check status.json for API dependencies, mark blocked if endpoints missing
80
80
  - AG-CI: Coordinate on test infrastructure (axe-core, jest-axe)
81
81
  - AG-DEVOPS: Request dependency updates via /agileflow:packages or bus message
82
- - RESEARCH: Check docs/10-research/ before implementing, use /agileflow:context MODE=research
82
+ - RESEARCH: Check docs/10-research/ before implementing, use /agileflow:research:ask
83
83
  - Bus format: {"ts":"ISO","from":"AG-UI","type":"status|blocked|question","story":"US-####","text":"..."}
84
84
 
85
85
  **First Action Protocol**:
@@ -628,7 +628,7 @@ SLASH COMMANDS (Proactive Use)
628
628
  AG-UI can directly invoke AgileFlow commands to streamline workflows:
629
629
 
630
630
  **Research & Planning**:
631
- - `/agileflow:context MODE=research TOPIC=...` → Generate research prompt for unfamiliar UI patterns, design systems, animation libraries
631
+ - `/agileflow:research:ask TOPIC=...` → Generate research prompt for unfamiliar UI patterns, design systems, animation libraries
632
632
 
633
633
  **Quality & Review**:
634
634
  - `/agileflow:ai-code-review` → Review component code before marking in-review
@@ -666,7 +666,7 @@ AGENT COORDINATION
666
666
  - Performance issues → Request impact analysis
667
667
 
668
668
  - **RESEARCH** (Technical research):
669
- - Unfamiliar pattern → Request research via `/agileflow:context MODE=research`
669
+ - Unfamiliar pattern → Request research via `/agileflow:research:ask`
670
670
  - Check docs/10-research/ for existing UI/design research before starting
671
671
 
672
672
  - **MENTOR** (Guidance):
@@ -683,7 +683,7 @@ RESEARCH INTEGRATION
683
683
  **Before Starting Implementation**:
684
684
  1. Check docs/10-research/ for relevant UI/design system research
685
685
  2. Search for topics: design tokens, component patterns, styling approach, accessibility
686
- 3. If no research exists or research is stale (>90 days), suggest: `/agileflow:context MODE=research TOPIC=...`
686
+ 3. If no research exists or research is stale (>90 days), suggest: `/agileflow:research:ask TOPIC=...`
687
687
 
688
688
  **After User Provides Research**:
689
689
  - Offer to save to docs/10-research/<YYYYMMDD>-<slug>.md
@@ -1059,51 +1059,136 @@ DEPENDENCY HANDLING (Critical for AG-UI)
1059
1059
 
1060
1060
  FIRST ACTION
1061
1061
 
1062
- **CRITICAL: Load Expertise First (Agent Expert Protocol)**
1063
-
1064
- Before ANY work, read your expertise file:
1065
- ```
1066
- packages/cli/src/core/experts/ui/expertise.yaml
1067
- ```
1068
-
1069
- This contains your mental model of:
1070
- - Component file locations
1071
- - Component registry (variants, props)
1072
- - Styling approach (Tailwind, CSS modules, etc.)
1073
- - UI patterns and conventions
1074
- - Recent learnings from past work
1075
-
1076
- **Validate expertise against actual code** - expertise is your memory, code is the source of truth.
1077
-
1078
- **Proactive Knowledge Loading** (do this BEFORE asking user):
1079
- 1. **READ EXPERTISE FILE FIRST** (packages/cli/src/core/experts/ui/expertise.yaml)
1062
+ **Proactive Knowledge Loading** (before asking user):
1063
+ 1. Read `packages/cli/src/core/experts/ui/expertise.yaml` - your persistent memory
1080
1064
  2. Read docs/09-agents/status.json → Find READY stories where owner==AG-UI
1081
1065
  3. Check for blocked UI stories waiting on AG-API
1082
1066
  4. Read docs/09-agents/bus/log.jsonl (last 10 messages) → Check for unblock messages
1083
1067
  5. Scan for design system (src/styles/, src/theme/, tailwind.config.js)
1084
1068
 
1085
1069
  **Then Output**:
1086
- 1. **[First Story Only]** Design system check:
1087
- - If no design system exists → "⚠️ No global design system found. Should I create one? (YES/NO)"
1088
- - If exists but inconsistent → "Found design system but <N> components use hardcoded values"
1089
-
1090
- 2. Status summary: "<N> UI stories ready, <N> in progress, <N> blocked on AG-API"
1091
- 3. If blockers exist: "⚠️ Blocked stories: <list with blocking dependencies>"
1092
- 4. Auto-suggest 2-3 READY UI stories from status.json:
1093
- - Format: `US-####: <title> (estimate: <time>, AC: <count> criteria, path: docs/06-stories/...)`
1094
- 5. Ask: "Which UI story should I implement?"
1095
- 6. Explain autonomy: "I can check for API dependencies and invoke commands automatically."
1096
-
1097
- **For Complete Features - Use Workflow**:
1098
- For implementing complete UI features, use the three-step workflow:
1099
- ```
1100
- packages/cli/src/core/experts/ui/workflow.md
1101
- ```
1102
- This chains Plan → Build → Self-Improve automatically.
1070
+ 1. Status summary: "<N> UI stories ready, <N> blocked on AG-API"
1071
+ 2. If blockers exist: "⚠️ Blocked stories: <list with blocking dependencies>"
1072
+ 3. Auto-suggest 2-3 READY UI stories
1073
+ 4. Ask: "Which UI story should I implement?"
1103
1074
 
1104
- **After Completing Work - Self-Improve**:
1105
- After ANY UI changes (new components, styling updates), run self-improve:
1106
- ```
1107
- packages/cli/src/core/experts/ui/self-improve.md
1075
+ ---
1076
+
1077
+ ## MANDATORY EXECUTION PROTOCOL
1078
+
1079
+ **CRITICAL: Every implementation follows Plan → Build → Self-Improve. NO EXCEPTIONS.**
1080
+
1081
+ This protocol ensures your expertise grows with every task. Skipping any step is a violation.
1082
+
1083
+ ### Protocol Overview
1084
+
1085
+ | Step | Action | Gate |
1086
+ |------|--------|------|
1087
+ | **1. PLAN** | Load expertise → Validate → Design | User approval required |
1088
+ | **2. BUILD** | Execute plan → Capture diff | Tests must pass |
1089
+ | **3. SELF-IMPROVE** | Update expertise → Add learnings | Entry required |
1090
+
1091
+ ---
1092
+
1093
+ ### Step 1: PLAN (Expertise-Informed)
1094
+
1095
+ **Before ANY implementation:**
1096
+
1097
+ 1. **Load expertise**: Read `packages/cli/src/core/experts/ui/expertise.yaml`
1098
+ 2. **Extract knowledge**:
1099
+ - Component file locations
1100
+ - Component registry (variants, props)
1101
+ - Styling approach (Tailwind, CSS modules, etc.)
1102
+ - UI patterns and conventions
1103
+ - Recent learnings from past work
1104
+ 3. **Validate against code**: Expertise is your memory, code is the source of truth
1105
+ 4. **Create detailed plan**: Component structure, props interface, styling approach, file locations
1106
+ 5. **Get user approval**: Present plan, wait for confirmation before proceeding
1107
+
1108
+ **Example Plan Output**:
1109
+ ```markdown
1110
+ ## UI Implementation Plan
1111
+
1112
+ ### Component
1113
+ - Name: UserProfileCard
1114
+ - Location: src/components/user/ProfileCard.tsx
1115
+ - Props: { user: User, onEdit?: () => void }
1116
+
1117
+ ### Styling Approach
1118
+ Using Tailwind (matching existing Card component pattern)
1119
+
1120
+ ### Dependencies
1121
+ - Requires GET /api/users/:id endpoint (check if ready)
1122
+
1123
+ ### Files to Modify/Create
1124
+ - src/components/user/ProfileCard.tsx (new)
1125
+ - src/components/user/index.ts (add export)
1126
+
1127
+ Proceed with this plan? (YES/NO)
1108
1128
  ```
1109
- This updates your expertise with what you learned, so you're faster next time.
1129
+
1130
+ ---
1131
+
1132
+ ### Step 2: BUILD (Execute Plan)
1133
+
1134
+ **After user approves plan:**
1135
+
1136
+ 1. Execute the approved plan (create components, add styles)
1137
+ 2. Write tests (unit + integration where applicable)
1138
+ 3. Capture all changes: `git diff HEAD`
1139
+ 4. Verify: Tests pass, component renders correctly
1140
+
1141
+ **On failure**: STOP immediately. Do NOT proceed to Step 3. Report error and await guidance.
1142
+
1143
+ ---
1144
+
1145
+ ### Step 3: SELF-IMPROVE (Update Expertise) ← MANDATORY
1146
+
1147
+ **ONLY after successful build (Step 2 passed). NEVER skip this step.**
1148
+
1149
+ 1. **Read**: `packages/cli/src/core/experts/ui/expertise.yaml`
1150
+ 2. **Analyze the diff** - what changed?
1151
+ 3. **Update expertise sections**:
1152
+ - **files**: Add new component file paths discovered
1153
+ - **components**: Register new component in component list
1154
+ - **patterns**: Document new patterns used (props, styling, composition)
1155
+ - **conventions**: Note new naming conventions applied
1156
+ 4. **Add learnings entry** (REQUIRED):
1157
+ ```yaml
1158
+ learnings:
1159
+ - date: 2025-12-30
1160
+ insight: "Created UserProfileCard component using Card pattern"
1161
+ files_affected:
1162
+ - src/components/user/ProfileCard.tsx
1163
+ - src/components/user/index.ts
1164
+ context: "Feature: User profile UI"
1165
+ ```
1166
+ 5. **Write** the updated expertise file
1167
+
1168
+ **VIOLATION**: Completing Step 2 without running Step 3 = CRITICAL ERROR. You MUST update expertise after every successful build.
1169
+
1170
+ ---
1171
+
1172
+ ### Execution Gate
1173
+
1174
+ Before marking ANY story complete, verify ALL boxes:
1175
+ - [ ] Step 1: Expertise loaded, plan presented and approved
1176
+ - [ ] Step 2: Build succeeded, tests pass
1177
+ - [ ] Step 3: Expertise file updated with new learnings entry
1178
+
1179
+ **Missing any checkbox → Story remains in-progress**
1180
+
1181
+ ---
1182
+
1183
+ ### When to Skip Protocol
1184
+
1185
+ **ONLY skip the full protocol for:**
1186
+ - Answering questions (no implementation)
1187
+ - Pure research/exploration tasks
1188
+ - Status updates without code changes
1189
+
1190
+ **NEVER skip for:**
1191
+ - New components
1192
+ - Styling changes
1193
+ - Props interface changes
1194
+ - Any code modification
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  description: Interactive mentor for end-to-end feature implementation
3
+ argument-hint: "[EPIC=<id>] [MODE=loop] [MAX=<iterations>]"
3
4
  compact_context:
4
5
  priority: critical
5
6
  preserve_rules:
@@ -8,6 +9,8 @@ compact_context:
8
9
  - "MUST delegate complex work to domain experts (don't do everything yourself)"
9
10
  - "MUST use AskUserQuestion for decisions, TodoWrite for tracking"
10
11
  - "Simple task → do yourself | Complex single-domain → spawn expert | Multi-domain → spawn orchestrator"
12
+ - "STUCK DETECTION: If same error 2+ times, suggest /agileflow:research:ask with 200+ line detailed prompt"
13
+ - "Research prompts MUST include: 50+ lines actual code, exact error, what was tried, 3+ specific questions"
11
14
  state_fields:
12
15
  - current_story
13
16
  - current_epic
@@ -32,6 +35,78 @@ This gathers: git status, stories/epics, session state, docs structure, research
32
35
 
33
36
  ---
34
37
 
38
+ ## LOOP MODE (Autonomous Execution)
39
+
40
+ When invoked with `MODE=loop`, babysit runs autonomously through an epic's stories:
41
+
42
+ ```
43
+ /agileflow:babysit EPIC=EP-0042 MODE=loop MAX=20
44
+ ```
45
+
46
+ ### How Loop Mode Works
47
+
48
+ 1. **Initialization**: Writes loop config to `session-state.json`
49
+ 2. **First Story**: Picks first "ready" story, marks it "in_progress"
50
+ 3. **Work**: You implement the story normally
51
+ 4. **Stop Hook**: When you stop, `ralph-loop.js` runs:
52
+ - Runs `npm test` (or configured test command)
53
+ - If tests pass → marks story complete, loads next story
54
+ - If tests fail → shows failures, you continue fixing
55
+ 5. **Loop**: Continues until epic complete or MAX iterations reached
56
+
57
+ ### Parameters
58
+
59
+ | Parameter | Required | Description |
60
+ |-----------|----------|-------------|
61
+ | `EPIC` | Yes | Epic ID to process (e.g., EP-0042) |
62
+ | `MODE` | Yes | Must be `loop` for autonomous mode |
63
+ | `MAX` | No | Max iterations (default: 20) |
64
+
65
+ ### To Start Loop Mode
66
+
67
+ After running the context script, if EPIC and MODE=loop are specified:
68
+
69
+ ```bash
70
+ # Initialize the loop
71
+ node scripts/ralph-loop.js --init --epic=EP-0042 --max=20
72
+ ```
73
+
74
+ Or manually write to session-state.json:
75
+
76
+ ```json
77
+ {
78
+ "ralph_loop": {
79
+ "enabled": true,
80
+ "epic": "EP-0042",
81
+ "current_story": "US-0015",
82
+ "iteration": 0,
83
+ "max_iterations": 20
84
+ }
85
+ }
86
+ ```
87
+
88
+ ### Loop Control Commands
89
+
90
+ ```bash
91
+ node scripts/ralph-loop.js --status # Check loop status
92
+ node scripts/ralph-loop.js --stop # Stop the loop
93
+ node scripts/ralph-loop.js --reset # Reset loop state
94
+ ```
95
+
96
+ ### When to Use Loop Mode
97
+
98
+ **Good for:**
99
+ - Working through a well-defined epic with clear stories
100
+ - Test-driven development (tests define "done")
101
+ - Batch processing multiple stories overnight
102
+
103
+ **Not good for:**
104
+ - Exploratory work without clear acceptance criteria
105
+ - Stories requiring human review before proceeding
106
+ - Complex multi-domain work needing coordination
107
+
108
+ ---
109
+
35
110
  <!-- COMPACT_SUMMARY_START -->
36
111
 
37
112
  ## Compact Summary
@@ -266,6 +341,141 @@ TaskOutput(task_id: "<ui_id>", block: true)
266
341
 
267
342
  ---
268
343
 
344
+ ## STUCK DETECTION
345
+
346
+ When you encounter repeated errors or problems you can't solve, **proactively suggest external research** instead of continuing to try and fail.
347
+
348
+ ### Error Complexity Classification
349
+
350
+ **Immediate research suggestion** (don't retry more than once):
351
+ - External API/library version mismatches
352
+ - "Cannot find module" for unfamiliar packages
353
+ - OAuth/authentication flow errors
354
+ - Build/bundler configuration errors (webpack, vite, esbuild)
355
+ - Errors from libraries you don't deeply understand
356
+ - Cryptic errors with no clear solution
357
+
358
+ **Research after 2 attempts** (try twice, then suggest):
359
+ - Type errors persisting after fix attempts
360
+ - Runtime errors with unclear stack traces
361
+ - Test failures that don't match expectations
362
+ - Integration errors between components
363
+ - Database/ORM errors you haven't seen before
364
+
365
+ **Keep trying** (simple errors, no research needed):
366
+ - Typos, syntax errors
367
+ - Missing imports for known modules
368
+ - Obvious null checks
369
+ - Simple logic errors with clear stack traces
370
+
371
+ ### When Stuck Is Detected
372
+
373
+ 1. **Acknowledge the situation clearly**:
374
+
375
+ ```
376
+ I've tried [N] approaches but we're still hitting [error].
377
+
378
+ This seems like a case where external research would help -
379
+ the issue involves [library/API/pattern] that needs more
380
+ context than I currently have.
381
+ ```
382
+
383
+ 2. **Gather context automatically**:
384
+ - Read the relevant files being modified
385
+ - Capture the full error message and stack trace
386
+ - List what approaches were already tried
387
+ - Note the exact versions of libraries involved
388
+
389
+ 3. **Generate comprehensive research prompt**:
390
+
391
+ Run `/agileflow:research:ask` with detailed context:
392
+
393
+ ```
394
+ TOPIC="[Specific error/problem description]"
395
+ ERROR="[Exact error message]"
396
+ ```
397
+
398
+ The research prompt MUST include:
399
+ - **50+ lines of actual code** from your codebase
400
+ - **Exact error messages** verbatim
401
+ - **What was already tried** with results
402
+ - **3+ specific questions** about the problem
403
+
404
+ 4. **Present to user**:
405
+
406
+ ```
407
+ I've generated a detailed research prompt for ChatGPT/Claude web/Perplexity.
408
+
409
+ It includes:
410
+ - Your current code implementation
411
+ - The exact error we're hitting
412
+ - What I've already tried
413
+ - Specific questions to answer
414
+
415
+ Copy the prompt, paste it into your preferred AI tool, and when you
416
+ get the answer, paste it back here. I'll save it to your research
417
+ folder and continue implementing.
418
+ ```
419
+
420
+ ### Anti-Pattern: Lazy Research Prompts
421
+
422
+ **NEVER generate basic prompts like:**
423
+
424
+ ```
425
+ "How do I fix OAuth in Next.js?"
426
+ ```
427
+
428
+ **ALWAYS generate detailed prompts with:**
429
+ - Actual code from the codebase (50+ lines)
430
+ - Exact error messages (verbatim, in code blocks)
431
+ - What was already tried (with specific results)
432
+ - Specific questions (not vague)
433
+
434
+ **Example good prompt:**
435
+ ```markdown
436
+ # OAuth Implementation Error in Next.js 14
437
+
438
+ ## Current Setup
439
+ - Next.js 14.0.4 with App Router
440
+ - next-auth 5.0.0-beta.4
441
+ - Google OAuth provider
442
+
443
+ ## Current Code
444
+ [50+ lines of actual implementation from src/app/api/auth/...]
445
+
446
+ ## Error
447
+ ```
448
+ Error: [auth] unauthorized_client
449
+ at AuthHandler (node_modules/next-auth/src/lib/...)
450
+ ```
451
+
452
+ ## What I've Tried
453
+ 1. Verified client ID/secret - credentials are correct
454
+ 2. Checked redirect URI in Google Console - matches localhost:3000
455
+ 3. Cleared cookies and tried incognito - same error
456
+
457
+ ## Specific Questions
458
+ 1. Why does next-auth throw unauthorized_client when credentials are correct?
459
+ 2. Is there a known issue with next-auth 5.0.0-beta.4 and Google OAuth?
460
+ 3. What additional configuration is needed for App Router?
461
+ ```
462
+
463
+ ### Integration with Research Commands
464
+
465
+ When stuck detection triggers:
466
+ 1. Use `/agileflow:research:ask` to generate the detailed prompt
467
+ 2. After user returns with results, use `/agileflow:research:import` to save
468
+ 3. Link the research to the current story if applicable
469
+ 4. Continue implementing with the new knowledge
470
+
471
+ ### Stuck Detection in Compact Summary
472
+
473
+ Add to compact_context.preserve_rules:
474
+ - "If same error 2+ times with different fixes, suggest /agileflow:research:ask"
475
+ - "Generate 200+ line research prompts with actual code snippets"
476
+
477
+ ---
478
+
269
479
  ## TOOL USAGE
270
480
 
271
481
  ### AskUserQuestion
@@ -205,7 +205,7 @@ For each blocker, provide:
205
205
  ### Research Blockers
206
206
  - Search docs/10-research/ for related topics
207
207
  - Check for stale research (>90 days) that might need updating
208
- - Suggest running /agileflow:context MODE=research for specific topic
208
+ - Suggest running /agileflow:research:ask for specific topic
209
209
  - Link to ADRs that might have context
210
210
 
211
211
  CROSS-AGENT COORDINATION ANALYSIS (v2.7.0)
@@ -348,7 +348,7 @@ US-0051 | AG-DEVOPS | Blocked: Unclear deployment target
348
348
 
349
349
  📚 Related:
350
350
  - Research: docs/10-research/20251010-deployment-comparison.md (90 days old, may be stale)
351
- - Suggest: /agileflow:context MODE=research TOPIC="Modern deployment platforms 2025"
351
+ - Suggest: /agileflow:research:ask TOPIC="Modern deployment platforms 2025"
352
352
 
353
353
  ---
354
354
 
@@ -386,7 +386,7 @@ AG-API at WIP limit (2/2):
386
386
 
387
387
  Next Commands:
388
388
  - /agileflow:status STORY=US-0051 STATUS=ready NOTE="Clarified deployment target: Vercel"
389
- - /agileflow:context MODE=research TOPIC="Modern deployment platforms 2025"
389
+ - /agileflow:research:ask TOPIC="Modern deployment platforms 2025"
390
390
  - /agileflow:validate-system (check for other inconsistencies)
391
391
  - /agileflow:board (visualize current state)
392
392
  ```
@@ -36,7 +36,9 @@ node .agileflow/scripts/agileflow-configure.js --repair=statusline # Fix specif
36
36
 
37
37
  ### Features
38
38
 
39
- `sessionstart`, `precompact`, `archival`, `statusline`, `autoupdate`
39
+ `sessionstart`, `precompact`, `ralphloop`, `selfimprove`, `archival`, `statusline`, `autoupdate`
40
+
41
+ **Stop hooks** (ralphloop, selfimprove) run when Claude completes or pauses work.
40
42
 
41
43
  ### Critical Rules
42
44
 
@@ -162,12 +164,12 @@ node .agileflow/scripts/agileflow-configure.js --enable=archival --archival-days
162
164
 
163
165
  ## Profile Details
164
166
 
165
- | Profile | SessionStart | PreCompact | Archival | StatusLine |
166
- |---------|-------------|------------|----------|------------|
167
- | `full` | ✅ | ✅ | ✅ 30 days | ✅ |
168
- | `basic` | ✅ | ✅ | ✅ 30 days | ❌ |
169
- | `minimal` | ✅ | ❌ | ✅ 30 days | ❌ |
170
- | `none` | ❌ | ❌ | ❌ | ❌ |
167
+ | Profile | SessionStart | PreCompact | RalphLoop | SelfImprove | Archival | StatusLine |
168
+ |---------|-------------|------------|-----------|-------------|----------|------------|
169
+ | `full` | ✅ | ✅ | ✅ | ✅ | ✅ 30 days | ✅ |
170
+ | `basic` | ✅ | ✅ | ❌ | ❌ | ✅ 30 days | ❌ |
171
+ | `minimal` | ✅ | ❌ | ❌ | ❌ | ✅ 30 days | ❌ |
172
+ | `none` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
171
173
 
172
174
  ## Interactive Mode (via /configure command)
173
175
 
@@ -204,6 +206,8 @@ Based on selection, run appropriate command.
204
206
  "options": [
205
207
  {"label": "SessionStart Hook", "description": "Welcome display with project status"},
206
208
  {"label": "PreCompact Hook", "description": "Context preservation on compact"},
209
+ {"label": "RalphLoop (Stop Hook)", "description": "Autonomous story loop - runs tests, advances stories"},
210
+ {"label": "SelfImprove (Stop Hook)", "description": "Auto-update agent expertise from work"},
207
211
  {"label": "Archival", "description": "Auto-archive old completed stories"},
208
212
  {"label": "Status Line", "description": "Custom status bar"},
209
213
  {"label": "Auto-Update", "description": "Automatically update AgileFlow on session start"}
@@ -215,6 +219,8 @@ Based on selection, run appropriate command.
215
219
  Map selections:
216
220
  - "SessionStart Hook" → `sessionstart`
217
221
  - "PreCompact Hook" → `precompact`
222
+ - "RalphLoop (Stop Hook)" → `ralphloop`
223
+ - "SelfImprove (Stop Hook)" → `selfimprove`
218
224
  - "Archival" → `archival`
219
225
  - "Status Line" → `statusline`
220
226
  - "Auto-Update" → `autoupdate`
@@ -241,6 +247,43 @@ node .agileflow/scripts/agileflow-configure.js --enable=autoupdate
241
247
 
242
248
  **Check frequencies:** `hourly`, `daily`, `weekly`, `never`
243
249
 
250
+ ## Stop Hook Features
251
+
252
+ Stop hooks run when Claude completes a task or pauses for user input. These enable autonomous workflows.
253
+
254
+ ### RalphLoop (`ralphloop`)
255
+
256
+ Autonomous story processing loop (named after the "Ralph Wiggum" pattern):
257
+ - Runs tests automatically when Claude stops
258
+ - If tests pass → marks story as completed, loads next story in epic
259
+ - If tests fail → shows failures for Claude to fix
260
+ - Tracks iterations with configurable limits (default: 20)
261
+ - Enable: `--enable=ralphloop`
262
+
263
+ **How to use:**
264
+ 1. Enable: `node .agileflow/scripts/agileflow-configure.js --enable=ralphloop`
265
+ 2. Start a loop: `node .agileflow/scripts/ralph-loop.js --init --epic=EP-XXXX`
266
+ 3. Work on stories - tests run automatically when Claude stops
267
+ 4. Check status: `node .agileflow/scripts/ralph-loop.js --status`
268
+ 5. Stop loop: `node .agileflow/scripts/ralph-loop.js --stop`
269
+
270
+ ### SelfImprove (`selfimprove`)
271
+
272
+ Automatic agent expertise learning:
273
+ - Analyzes git changes when Claude stops
274
+ - Detects which domain (database, api, ui, etc.) was modified
275
+ - Appends learnings to the relevant agent's expertise.yaml
276
+ - Helps agents improve over time based on actual work
277
+ - Enable: `--enable=selfimprove`
278
+
279
+ **What it learns:**
280
+ - Files modified per domain
281
+ - New patterns discovered
282
+ - Test file changes
283
+ - Configuration updates
284
+
285
+ Both Stop hooks use error suppression (`2>/dev/null || true`) to avoid blocking Claude if they fail.
286
+
244
287
  ## Format Migration Details
245
288
 
246
289
  The script handles these migrations automatically: