agileflow 2.94.1 → 2.95.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 (74) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +3 -3
  3. package/lib/colors.generated.js +117 -0
  4. package/lib/colors.js +59 -109
  5. package/lib/generator-factory.js +333 -0
  6. package/lib/path-utils.js +49 -0
  7. package/lib/session-registry.js +25 -15
  8. package/lib/smart-json-file.js +40 -32
  9. package/lib/state-machine.js +286 -0
  10. package/package.json +1 -1
  11. package/scripts/agileflow-configure.js +7 -6
  12. package/scripts/archive-completed-stories.sh +86 -11
  13. package/scripts/babysit-context-restore.js +89 -0
  14. package/scripts/claude-tmux.sh +111 -5
  15. package/scripts/damage-control/bash-tool-damage-control.js +11 -247
  16. package/scripts/damage-control/edit-tool-damage-control.js +9 -249
  17. package/scripts/damage-control/write-tool-damage-control.js +9 -244
  18. package/scripts/generate-colors.js +314 -0
  19. package/scripts/lib/colors.generated.sh +82 -0
  20. package/scripts/lib/colors.sh +10 -70
  21. package/scripts/lib/configure-features.js +401 -0
  22. package/scripts/lib/context-loader.js +181 -52
  23. package/scripts/precompact-context.sh +54 -17
  24. package/scripts/session-coordinator.sh +2 -2
  25. package/scripts/session-manager.js +653 -10
  26. package/src/core/commands/audit.md +93 -0
  27. package/src/core/commands/auto.md +73 -0
  28. package/src/core/commands/babysit.md +169 -13
  29. package/src/core/commands/baseline.md +73 -0
  30. package/src/core/commands/batch.md +64 -0
  31. package/src/core/commands/blockers.md +60 -0
  32. package/src/core/commands/board.md +66 -0
  33. package/src/core/commands/choose.md +77 -0
  34. package/src/core/commands/ci.md +77 -0
  35. package/src/core/commands/compress.md +27 -1
  36. package/src/core/commands/configure.md +126 -10
  37. package/src/core/commands/council.md +74 -0
  38. package/src/core/commands/debt.md +72 -0
  39. package/src/core/commands/deploy.md +73 -0
  40. package/src/core/commands/deps.md +68 -0
  41. package/src/core/commands/docs.md +60 -0
  42. package/src/core/commands/feedback.md +68 -0
  43. package/src/core/commands/ideate.md +74 -0
  44. package/src/core/commands/impact.md +74 -0
  45. package/src/core/commands/install.md +529 -0
  46. package/src/core/commands/maintain.md +558 -0
  47. package/src/core/commands/metrics.md +75 -0
  48. package/src/core/commands/multi-expert.md +74 -0
  49. package/src/core/commands/packages.md +69 -0
  50. package/src/core/commands/readme-sync.md +64 -0
  51. package/src/core/commands/research/analyze.md +285 -121
  52. package/src/core/commands/research/import.md +281 -109
  53. package/src/core/commands/retro.md +76 -0
  54. package/src/core/commands/review.md +72 -0
  55. package/src/core/commands/rlm.md +83 -0
  56. package/src/core/commands/rpi.md +90 -0
  57. package/src/core/commands/session/cleanup.md +214 -12
  58. package/src/core/commands/session/end.md +155 -17
  59. package/src/core/commands/sprint.md +72 -0
  60. package/src/core/commands/story-validate.md +68 -0
  61. package/src/core/commands/template.md +69 -0
  62. package/src/core/commands/tests.md +83 -0
  63. package/src/core/commands/update.md +59 -0
  64. package/src/core/commands/validate-expertise.md +76 -0
  65. package/src/core/commands/velocity.md +74 -0
  66. package/src/core/commands/verify.md +91 -0
  67. package/src/core/commands/whats-new.md +69 -0
  68. package/src/core/commands/workflow.md +88 -0
  69. package/src/core/templates/command-documentation.md +187 -0
  70. package/tools/cli/commands/session.js +1171 -0
  71. package/tools/cli/commands/setup.js +2 -81
  72. package/tools/cli/installers/core/installer.js +0 -5
  73. package/tools/cli/installers/ide/claude-code.js +6 -0
  74. package/tools/cli/lib/config-manager.js +42 -5
@@ -710,6 +710,82 @@ OUTPUT
710
710
 
711
711
  ---
712
712
 
713
+ ## Expected Output
714
+
715
+ ### Success - Retrospective Report
716
+
717
+ ```
718
+ 🔄 Sprint 12 Retrospective
719
+ ══════════════════════════════════════════════════════════════
720
+ Period: 2026-01-15 to 2026-01-29
721
+
722
+ 📊 SPRINT METRICS
723
+ ┌────────────────────────────────────────────────────────────┐
724
+ │ Planned: 15 stories (42 points) │
725
+ │ Completed: 13 stories (38 points) │
726
+ │ Carry-over: 2 stories (4 points) │
727
+ │ Velocity: 90% of commitment │
728
+ └────────────────────────────────────────────────────────────┘
729
+
730
+ 🟢 START (What should we start doing?)
731
+ - [ ] Daily async standups in bus
732
+ - [ ] Earlier blocker escalation
733
+ - [ ] Pair programming for complex stories
734
+
735
+ 🔴 STOP (What should we stop doing?)
736
+ - [ ] Skipping AC verification before done
737
+ - [ ] Starting stories without clear requirements
738
+
739
+ 🟡 CONTINUE (What's working well?)
740
+ - [x] Test-first development (reduced bugs 40%)
741
+ - [x] Using /babysit for mentored workflows
742
+ - [x] Clear acceptance criteria format
743
+
744
+ 🎉 WINS
745
+ - Shipped OAuth integration ahead of schedule
746
+ - Zero production bugs this sprint
747
+ - Team collaboration improved significantly
748
+
749
+ 📈 PREDICTIONS
750
+ - Next sprint velocity: ~40 points
751
+ - Risk: US-0055 may need external help
752
+
753
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
754
+ ✅ Retrospective saved to docs/08-project/retrospectives/
755
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
756
+ ```
757
+
758
+ ### Success - Quick Retro
759
+
760
+ ```
761
+ 🔄 Quick Retrospective
762
+ ══════════════════════════════════════════════════════════════
763
+
764
+ Based on sprint data:
765
+ 🟢 Win: 90% velocity achieved
766
+ 🟡 Watch: 2 stories carried over
767
+ 🔴 Risk: Blocker detection was slow
768
+
769
+ Top action item:
770
+ → Add daily blocker check to routine
771
+
772
+ Full retro? /agileflow:retro DEPTH=full
773
+ ```
774
+
775
+ ### Error - No Sprint Data
776
+
777
+ ```
778
+ ❌ Error: No sprint data available
779
+
780
+ No completed stories found in the last 14 days.
781
+
782
+ Options:
783
+ 1. Start tracking: /agileflow:sprint ACTION=start
784
+ 2. Specify range: /agileflow:retro RANGE="2026-01-01..2026-01-15"
785
+ ```
786
+
787
+ ---
788
+
713
789
  ## Related Commands
714
790
 
715
791
  - `/agileflow:sprint` - Sprint planning
@@ -588,6 +588,78 @@ OUTPUT
588
588
 
589
589
  ---
590
590
 
591
+ ## Expected Output
592
+
593
+ ### Success - Code Review
594
+
595
+ ```
596
+ 🔍 Code Review: src/api/auth.js
597
+ ══════════════════════════════════════════════════════════════
598
+
599
+ Analyzing 127 lines changed across 3 files...
600
+
601
+ 📊 Quality Score: 85/100 🟢
602
+
603
+ 🔴 CRITICAL (1)
604
+ ┌──────────────────────────────────────────────────────────────┐
605
+ │ Line 45: SQL injection vulnerability │
606
+ │ `query("SELECT * FROM users WHERE id = " + userId)` │
607
+ │ │
608
+ │ Fix: Use parameterized query │
609
+ │ `query("SELECT * FROM users WHERE id = $1", [userId])` │
610
+ └──────────────────────────────────────────────────────────────┘
611
+
612
+ 🟡 WARNINGS (3)
613
+ │ Line 23: Missing error handling for async operation │
614
+ │ Line 67: Magic number - consider named constant │
615
+ │ Line 89: Duplicate logic - extract to helper │
616
+
617
+ 🟢 GOOD PRACTICES
618
+ │ ✓ Consistent naming conventions │
619
+ │ ✓ Good test coverage (87%) │
620
+ │ ✓ Clear function documentation │
621
+
622
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
623
+ Summary: 1 critical, 3 warnings, 3 good
624
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
625
+
626
+ Apply auto-fixes for non-critical issues? [Y/n]
627
+ ```
628
+
629
+ ### Success - Clean Review
630
+
631
+ ```
632
+ 🔍 Code Review: src/utils/format.js
633
+ ══════════════════════════════════════════════════════════════
634
+
635
+ 📊 Quality Score: 98/100 🟢
636
+
637
+ ✅ No issues found!
638
+
639
+ Good practices detected:
640
+ - Clean function signatures
641
+ - Comprehensive error handling
642
+ - Well-documented edge cases
643
+ - 95% test coverage
644
+
645
+ LGTM! Ready for merge.
646
+ ```
647
+
648
+ ### Error - File Not Found
649
+
650
+ ```
651
+ ❌ Error: Cannot review - file not found
652
+
653
+ Path: src/api/authh.js
654
+
655
+ Did you mean: src/api/auth.js?
656
+
657
+ Or review all changed files:
658
+ /agileflow:review SCOPE=staged
659
+ ```
660
+
661
+ ---
662
+
591
663
  ## Related Commands
592
664
 
593
665
  - `/agileflow:pr` - Generate pull request description
@@ -347,6 +347,89 @@ For smaller research notes, `/agileflow:research:view` may be sufficient.
347
347
 
348
348
  ---
349
349
 
350
+ ## Expected Output
351
+
352
+ ### Success - Document Analysis
353
+
354
+ ```
355
+ 📄 RLM Document Analysis
356
+ ══════════════════════════════════════════════════════════════
357
+
358
+ Document: docs/research/api-design-guide.pdf (156 pages)
359
+ Question: What authentication methods are recommended?
360
+
361
+ Launching RLM sub-agent...
362
+ ✓ Document loaded (2.3 MB)
363
+ ✓ Virtualized as 47 chunks
364
+ ✓ Cost estimate: $0.12
365
+
366
+ Iteration 1/5: Searching for authentication...
367
+ Found: Chapter 4 "Security", pages 45-62
368
+
369
+ Iteration 2/5: Extracting relevant sections...
370
+ Found: 3 authentication patterns described
371
+
372
+ Iteration 3/5: Synthesizing answer...
373
+
374
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
375
+ 📖 Answer
376
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
377
+
378
+ The guide recommends three authentication methods:
379
+
380
+ 1. **JWT Tokens** (Primary)
381
+ - For API-to-API communication
382
+ - 15-minute expiry with refresh tokens
383
+
384
+ 2. **OAuth 2.0** (External Users)
385
+ - For third-party integrations
386
+ - Support Google and GitHub providers
387
+
388
+ 3. **API Keys** (Internal Services)
389
+ - For trusted internal services
390
+ - Rotate every 90 days
391
+
392
+ Source: Pages 47-52, Chapter 4 "Security"
393
+ Confidence: High (direct quotes available)
394
+ Cost: $0.08 (3 iterations)
395
+ ```
396
+
397
+ ### Success - Multi-Document Synthesis
398
+
399
+ ```
400
+ 📄 RLM Cross-Document Analysis
401
+ ══════════════════════════════════════════════════════════════
402
+
403
+ Documents: 3 research papers
404
+ Question: Compare approaches to rate limiting
405
+
406
+ Processing...
407
+ [============================] 100%
408
+
409
+ Synthesis:
410
+ All three papers recommend token bucket algorithm.
411
+ Key difference: Paper A suggests per-user limits,
412
+ Paper B recommends per-endpoint limits.
413
+
414
+ See full comparison: .agileflow/research/synthesis-001.md
415
+ ```
416
+
417
+ ### Error - Document Too Large
418
+
419
+ ```
420
+ ⚠️ Document exceeds RLM budget
421
+
422
+ File: enterprise-guide.pdf (500 pages)
423
+ Estimated cost: $2.50
424
+
425
+ Options:
426
+ 1. Increase budget: BUDGET=3.00
427
+ 2. Analyze specific pages: PAGES=1-50
428
+ 3. Use summary mode: MODE=summary
429
+ ```
430
+
431
+ ---
432
+
350
433
  ## Related Commands
351
434
 
352
435
  - `/agileflow:research:analyze` - Analyze research notes (uses RLM for large docs)
@@ -502,6 +502,96 @@ Human review should focus on highest leverage points:
502
502
 
503
503
  ---
504
504
 
505
+ ## Expected Output
506
+
507
+ ### Success - RPI Workflow
508
+
509
+ ```
510
+ 🔄 RPI Workflow: User Authentication Feature
511
+ ══════════════════════════════════════════════════════════════
512
+
513
+ Phase 1: RESEARCH (Current)
514
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
515
+
516
+ Gathering context...
517
+ ✓ Read existing auth code (src/api/auth.js)
518
+ ✓ Analyzed 3 related components
519
+ ✓ Reviewed security requirements
520
+ ✓ Checked team patterns (JWT preferred)
521
+
522
+ Research Summary:
523
+ - Current: Basic session auth
524
+ - Target: JWT with refresh tokens
525
+ - Patterns: Use existing middleware structure
526
+ - Risks: Token storage, refresh logic
527
+
528
+ Ready for planning phase? [Y/n]
529
+
530
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
531
+ Phase 2: PLAN
532
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
533
+
534
+ Proposed Implementation:
535
+ 1. Add JWT generation in auth.js
536
+ 2. Create refresh token middleware
537
+ 3. Update login endpoint
538
+ 4. Add token validation
539
+ 5. Write tests (unit + integration)
540
+
541
+ Files to modify: 4
542
+ New files: 2
543
+ Estimated complexity: Medium
544
+
545
+ Approve plan and proceed to implement? [Y/n]
546
+
547
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
548
+ Phase 3: IMPLEMENT
549
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
550
+
551
+ Implementing...
552
+ ✓ Updated src/api/auth.js
553
+ ✓ Created src/middleware/jwt.js
554
+ ✓ Created src/utils/tokens.js
555
+ ✓ Added 12 tests (all passing)
556
+
557
+ 🎉 Implementation complete!
558
+ ```
559
+
560
+ ### Success - Phase Transition
561
+
562
+ ```
563
+ 🔄 RPI Phase Transition
564
+ ══════════════════════════════════════════════════════════════
565
+
566
+ Current: RESEARCH → Next: PLAN
567
+
568
+ ⚠️ Context Health: 65% (approaching threshold)
569
+
570
+ Before transitioning:
571
+ 1. Document key findings
572
+ 2. Save research notes
573
+ 3. Plan is LEVERAGE - quality > speed now
574
+
575
+ Proceed with transition? [Y/n]
576
+ ```
577
+
578
+ ### Error - Wrong Phase
579
+
580
+ ```
581
+ ❌ Error: Cannot implement without planning
582
+
583
+ Current phase: RESEARCH
584
+
585
+ Complete the workflow in order:
586
+ 1. RESEARCH ✅ (current)
587
+ 2. PLAN ⏳
588
+ 3. IMPLEMENT ⏳
589
+
590
+ Skip to plan: /agileflow:rpi PHASE=plan
591
+ ```
592
+
593
+ ---
594
+
505
595
  ## Related Documentation
506
596
 
507
597
  - [Context Engineering RPI Practice](../../docs/02-practices/context-engineering-rpi.md)
@@ -7,14 +7,20 @@ compact_context:
7
7
  - "ACTIVE COMMAND: /agileflow:session:cleanup - Review and clean up sessions"
8
8
  - "Walk through EACH session with issues one-by-one"
9
9
  - "Show file changes with AI assessment (SAFE/IMPORTANT)"
10
+ - "Check merge eligibility with: node .agileflow/scripts/session-manager.js check-merge {id}"
11
+ - "Merge options: canMerge (mergeable or hasConflicts), uncommittedInSession (cannot merge)"
10
12
  - "Use AskUserQuestion for EACH session with recommended action"
11
- - "Recommended action based on allTrivial flag from health --detailed"
12
- - "Track: deleted count, kept count, skipped count"
13
+ - "If SAFE+mergeable: Delete(Rec) / Merge&Delete / Keep / Stop"
14
+ - "If IMPORTANT+mergeable: Merge&Delete(Rec) / Keep / Delete anyway / Stop"
15
+ - "If cannot merge: show warning, offer Switch to session option"
16
+ - "Merge execution: session-manager.js integrate {id} --strategy=squash --deleteBranch=true --deleteWorktree=true"
17
+ - "Track: deleted count, merged count, kept count, skipped count"
13
18
  state_fields:
14
19
  - health_report
15
20
  - current_session_index
16
21
  - total_sessions
17
22
  - deleted_count
23
+ - merged_count
18
24
  - kept_count
19
25
  ---
20
26
 
@@ -29,8 +35,9 @@ Interactive session cleanup - review each session with health issues and decide
29
35
  When you have forgotten sessions with uncommitted changes, stale entries, or orphaned worktrees, this command:
30
36
  - Shows you what changed in each session
31
37
  - Analyzes whether changes are important or trivial
38
+ - Checks if changes can be merged to main before deletion
32
39
  - Provides AI recommendation for each session
33
- - Lets you decide one-by-one what to clean up
40
+ - Lets you decide one-by-one what to clean up (including merge-and-delete option)
34
41
 
35
42
  ---
36
43
 
@@ -87,6 +94,19 @@ For each file in `fileDetails`:
87
94
  - `??` status: ` ?? {file}` and if `existsInMain: true` add `(exists in main)`
88
95
  - Other: ` {status} {file}`
89
96
 
97
+ #### Step 3b2: Check Merge Eligibility
98
+
99
+ ```bash
100
+ node .agileflow/scripts/session-manager.js check-merge {session_id}
101
+ ```
102
+
103
+ Parse the JSON response and set flags:
104
+ - `canMerge`: true if `mergeable: true` OR `hasConflicts: true` (can attempt merge)
105
+ - `hasConflicts`: true if response contains `hasConflicts: true`
106
+ - `uncommittedInSession`: true if `reason === "uncommitted_changes"`
107
+ - `noChanges`: true if `reason === "no_changes"`
108
+ - `commitsAhead`: number of commits to merge (from response)
109
+
90
110
  #### Step 3c: Display AI Assessment
91
111
 
92
112
  If `allTrivial` is true:
@@ -101,9 +121,35 @@ If `allTrivial` is false:
101
121
  This session has unique changes that may be valuable.
102
122
  ```
103
123
 
124
+ **Add merge status line based on flags from Step 3b2:**
125
+
126
+ If `canMerge` and NOT `hasConflicts`:
127
+ ```
128
+ ✓ Can be merged to main cleanly ({commitsAhead} commit(s))
129
+ ```
130
+
131
+ If `hasConflicts`:
132
+ ```
133
+ ⚠️ Has merge conflicts (auto-resolve available)
134
+ ```
135
+
136
+ If `uncommittedInSession`:
137
+ ```
138
+ ❌ Cannot merge - has uncommitted changes in session
139
+ ```
140
+
141
+ If `noChanges`:
142
+ ```
143
+ ○ Nothing to merge - no committed changes different from main
144
+ ```
145
+
104
146
  #### Step 3d: Ask User with AskUserQuestion
105
147
 
106
- **If SAFE (allTrivial: true):**
148
+ Choose option set based on assessment (allTrivial) and merge eligibility:
149
+
150
+ ---
151
+
152
+ **Option Set A: SAFE + Mergeable (allTrivial: true AND canMerge: true)**
107
153
  ```
108
154
  AskUserQuestion:
109
155
  question: "Session {id} - What would you like to do?"
@@ -112,21 +158,87 @@ AskUserQuestion:
112
158
  options:
113
159
  - label: "Delete session (Recommended)"
114
160
  description: "Remove session and worktree - no unique work"
161
+ - label: "Merge and delete"
162
+ description: "Merge {commitsAhead} commit(s) to main, then delete session"
115
163
  - label: "Keep this session"
116
164
  description: "Leave it as-is"
117
165
  - label: "Stop cleanup"
118
166
  description: "Exit and show summary"
119
167
  ```
120
168
 
121
- **If IMPORTANT (allTrivial: false):**
169
+ ---
170
+
171
+ **Option Set B: IMPORTANT + Mergeable (allTrivial: false AND canMerge: true)**
122
172
  ```
123
173
  AskUserQuestion:
124
174
  question: "Session {id} - What would you like to do?"
125
175
  header: "Cleanup"
126
176
  multiSelect: false
127
177
  options:
128
- - label: "Keep this session (Recommended)"
129
- description: "Preserve unique work"
178
+ - label: "Merge and delete (Recommended)"
179
+ description: "Preserve {commitsAhead} commit(s) to main, then clean up session"
180
+ - label: "Keep this session"
181
+ description: "Leave session for continued work"
182
+ - label: "Delete anyway"
183
+ description: "Remove session and lose changes"
184
+ - label: "Stop cleanup"
185
+ description: "Exit and show summary"
186
+ ```
187
+
188
+ ---
189
+
190
+ **Option Set C: Cannot Merge - Uncommitted in Session (uncommittedInSession: true)**
191
+ ```
192
+ ⚠️ Session has uncommitted changes that prevent merging.
193
+ Commit or discard changes first to enable merge option.
194
+
195
+ AskUserQuestion:
196
+ question: "Session {id} cannot be merged. What would you like to do?"
197
+ header: "Cleanup"
198
+ multiSelect: false
199
+ options:
200
+ - label: "Switch to session to commit"
201
+ description: "Open this session so you can commit changes"
202
+ - label: "Keep this session"
203
+ description: "Leave it as-is for later"
204
+ - label: "Delete anyway"
205
+ description: "Remove session and lose all changes"
206
+ - label: "Stop cleanup"
207
+ description: "Exit and show summary"
208
+ ```
209
+
210
+ ---
211
+
212
+ **Option Set D: SAFE + No Merge Needed (allTrivial: true AND noChanges: true)**
213
+ ```
214
+ AskUserQuestion:
215
+ question: "Session {id} - What would you like to do?"
216
+ header: "Cleanup"
217
+ multiSelect: false
218
+ options:
219
+ - label: "Delete session (Recommended)"
220
+ description: "Remove session and worktree - nothing to preserve"
221
+ - label: "Keep this session"
222
+ description: "Leave it as-is"
223
+ - label: "Stop cleanup"
224
+ description: "Exit and show summary"
225
+ ```
226
+
227
+ ---
228
+
229
+ **Option Set E: Has Conflicts (hasConflicts: true)**
230
+ ```
231
+ ⚠️ Merge has conflicts with main branch.
232
+
233
+ AskUserQuestion:
234
+ question: "Session {id} has merge conflicts. What would you like to do?"
235
+ header: "Cleanup"
236
+ multiSelect: false
237
+ options:
238
+ - label: "Auto-resolve and merge"
239
+ description: "Attempt smart conflict resolution, then merge and delete"
240
+ - label: "Keep for manual merge"
241
+ description: "Leave session to resolve conflicts yourself"
130
242
  - label: "Delete anyway"
131
243
  description: "Remove session and lose changes"
132
244
  - label: "Stop cleanup"
@@ -135,7 +247,7 @@ AskUserQuestion:
135
247
 
136
248
  #### Step 3e: Execute User Choice
137
249
 
138
- **If "Delete" chosen:**
250
+ **If "Delete session" or "Delete anyway" chosen:**
139
251
  ```bash
140
252
  node .agileflow/scripts/session-manager.js delete {session_id} --remove-worktree
141
253
  ```
@@ -143,10 +255,83 @@ node .agileflow/scripts/session-manager.js delete {session_id} --remove-worktree
143
255
  Display: `✓ Session {id} deleted`
144
256
  Increment deleted_count.
145
257
 
146
- **If "Keep" chosen:**
258
+ ---
259
+
260
+ **If "Merge and delete" chosen:**
261
+
262
+ 1. Run integrate with cleanup flags:
263
+ ```bash
264
+ node .agileflow/scripts/session-manager.js integrate {session_id} --strategy=squash --deleteBranch=true --deleteWorktree=true
265
+ ```
266
+
267
+ 2. Parse the response to get merge result.
268
+
269
+ 3. Display result:
270
+ ```
271
+ ✓ Session {id} merged to main and deleted
272
+ Commits: {originalCount} → 1 (squashed)
273
+ Branch: {branch} (deleted)
274
+ ```
275
+
276
+ Increment merged_count.
277
+
278
+ ---
279
+
280
+ **If "Auto-resolve and merge" chosen (for conflict cases):**
281
+
282
+ 1. First run smart-merge to resolve conflicts:
283
+ ```bash
284
+ node .agileflow/scripts/session-manager.js smart-merge {session_id} --strategy=squash
285
+ ```
286
+
287
+ 2. Check result - if conflicts remain, display error and keep session:
288
+ ```
289
+ ❌ Could not auto-resolve conflicts for session {id}
290
+ Consider manual merge or delete.
291
+ ```
292
+ Increment kept_count and continue to next session.
293
+
294
+ 3. If smart-merge succeeds, run integrate:
295
+ ```bash
296
+ node .agileflow/scripts/session-manager.js integrate {session_id} --strategy=squash --deleteBranch=true --deleteWorktree=true
297
+ ```
298
+
299
+ 4. Display result:
300
+ ```
301
+ ✓ Session {id} conflicts resolved, merged to main, and deleted
302
+ Commits: {originalCount} → 1 (squashed)
303
+ Branch: {branch} (deleted)
304
+ ```
305
+
306
+ Increment merged_count.
307
+
308
+ ---
309
+
310
+ **If "Switch to session to commit" chosen:**
311
+
312
+ 1. Display instructions:
313
+ ```
314
+ Switching to session {id}...
315
+
316
+ After committing your changes, run /agileflow:session:cleanup again
317
+ to continue cleanup with merge option available.
318
+ ```
319
+
320
+ 2. Switch to the session:
321
+ ```bash
322
+ node .agileflow/scripts/session-manager.js switch {session_id}
323
+ ```
324
+
325
+ 3. Exit cleanup (do NOT continue to next session - user needs to work in session).
326
+
327
+ ---
328
+
329
+ **If "Keep this session" or "Keep for manual merge" chosen:**
147
330
  Display: `→ Session {id} kept`
148
331
  Increment kept_count.
149
332
 
333
+ ---
334
+
150
335
  **If "Stop cleanup" chosen:**
151
336
  Go to Step 6 (Final Summary).
152
337
 
@@ -219,13 +404,16 @@ git worktree remove --force "{path}"
219
404
  Session Cleanup Complete
220
405
  ═══════════════════════════════════════════════════════════════
221
406
 
222
- ✓ Deleted: {deleted_count} session(s)
223
- Kept: {kept_count} session(s)
224
- Skipped: {skipped_count} item(s)
407
+ ✓ Deleted: {deleted_count} session(s)
408
+ Merged: {merged_count} session(s) → changes preserved in main
409
+ Kept: {kept_count} session(s)
410
+ ○ Skipped: {skipped_count} item(s)
225
411
 
226
412
  Run /agileflow:session:status to see remaining sessions.
227
413
  ```
228
414
 
415
+ Note: Only display "Merged" line if merged_count > 0.
416
+
229
417
  ---
230
418
 
231
419
  ## Edge Cases
@@ -241,6 +429,20 @@ Show partial summary with what was processed.
241
429
  ### Main Session Protection
242
430
  The health check already excludes main session, so it won't appear in cleanup list.
243
431
 
432
+ ### Merge Fails
433
+ If integrate command fails (e.g., unexpected error), display:
434
+ ```
435
+ ❌ Merge failed for session {id}: {error}
436
+ Session preserved. Try manual merge with /agileflow:session:end
437
+ ```
438
+ Keep the session and continue to next.
439
+
440
+ ### check-merge Command Not Available
441
+ If the `check-merge` command is not available (older session-manager.js), fall back to original behavior without merge options. Set `canMerge: false` for all sessions.
442
+
443
+ ### Switched to Session Mid-Cleanup
444
+ When user selects "Switch to session to commit", cleanup exits immediately. The summary shows partial progress. User can run `/agileflow:session:cleanup` again after committing.
445
+
244
446
  ---
245
447
 
246
448
  ## Related Commands