ai-flow-dev 2.1.3 → 2.1.4

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 (96) hide show
  1. package/README.md +25 -38
  2. package/dist/cli.js +68 -46
  3. package/dist/cli.js.map +1 -1
  4. package/package.json +5 -5
  5. package/prompts/backend/flow-build-phase-0.md +31 -63
  6. package/prompts/backend/flow-build-phase-1.md +9 -17
  7. package/prompts/backend/flow-build-phase-10.md +199 -585
  8. package/prompts/backend/flow-build-phase-2.md +152 -86
  9. package/prompts/backend/flow-build-phase-3.md +108 -68
  10. package/prompts/backend/flow-build-phase-4.md +5 -8
  11. package/prompts/backend/flow-build-phase-5.md +39 -12
  12. package/prompts/backend/flow-build-phase-6.md +29 -8
  13. package/prompts/backend/flow-build-phase-7.md +120 -40
  14. package/prompts/backend/flow-build-phase-8.md +28 -65
  15. package/prompts/backend/flow-build-phase-9.md +267 -1298
  16. package/prompts/backend/flow-build.md +881 -957
  17. package/prompts/backend/flow-dev-commit.md +27 -50
  18. package/prompts/backend/flow-dev-feature.md +1929 -2017
  19. package/prompts/backend/flow-dev-fix.md +936 -964
  20. package/prompts/backend/flow-dev-refactor.md +672 -701
  21. package/prompts/backend/flow-dev-review.md +356 -389
  22. package/prompts/backend/flow-dev-work.md +1066 -1118
  23. package/prompts/backend/flow-docs-sync.md +20 -196
  24. package/prompts/frontend/flow-build-phase-0.md +503 -484
  25. package/prompts/frontend/flow-build-phase-1.md +445 -433
  26. package/prompts/frontend/flow-build-phase-2.md +910 -957
  27. package/prompts/frontend/flow-build-phase-3.md +692 -664
  28. package/prompts/frontend/flow-build-phase-4.md +478 -463
  29. package/prompts/frontend/flow-build-phase-5.md +488 -467
  30. package/prompts/frontend/flow-build-phase-6.md +571 -550
  31. package/prompts/frontend/flow-build-phase-7.md +560 -592
  32. package/prompts/frontend/flow-build-phase-8.md +17 -42
  33. package/prompts/frontend/flow-build.md +457 -503
  34. package/prompts/frontend/flow-docs-sync.md +14 -35
  35. package/prompts/mobile/flow-build-phase-0.md +104 -97
  36. package/prompts/mobile/flow-build-phase-1.md +137 -122
  37. package/prompts/mobile/flow-build-phase-2.md +123 -130
  38. package/prompts/mobile/flow-build-phase-3.md +144 -149
  39. package/prompts/mobile/flow-build-phase-4.md +140 -132
  40. package/prompts/mobile/flow-build-phase-5.md +70 -70
  41. package/prompts/mobile/flow-build-phase-6.md +136 -134
  42. package/prompts/mobile/flow-build-phase-7.md +24 -58
  43. package/prompts/mobile/flow-build-phase-8.md +17 -42
  44. package/prompts/mobile/flow-build.md +47 -97
  45. package/prompts/mobile/flow-docs-sync.md +13 -32
  46. package/prompts/shared/mermaid-guidelines.md +106 -0
  47. package/prompts/shared/scope-levels.md +126 -0
  48. package/prompts/shared/story-points.md +65 -0
  49. package/prompts/shared/task-format.md +86 -0
  50. package/templates/AGENT.template.md +194 -15
  51. package/templates/backend/README.template.md +2 -32
  52. package/templates/backend/ai-instructions.template.md +2 -32
  53. package/templates/backend/copilot-instructions.template.md +2 -22
  54. package/templates/backend/docs/api.template.md +89 -20
  55. package/templates/backend/docs/architecture.template.md +165 -53
  56. package/templates/backend/docs/business-flows.template.md +7 -14
  57. package/templates/backend/docs/code-standards.template.md +2 -38
  58. package/templates/backend/docs/contributing.template.md +2 -16
  59. package/templates/backend/docs/data-model.template.md +125 -21
  60. package/templates/backend/docs/operations.template.md +179 -50
  61. package/templates/backend/docs/testing.template.md +2 -42
  62. package/templates/backend/project-brief.template.md +2 -28
  63. package/templates/backend/specs/configuration.template.md +2 -14
  64. package/templates/backend/specs/security.template.md +2 -32
  65. package/templates/frontend/README.template.md +2 -18
  66. package/templates/frontend/ai-instructions.template.md +2 -20
  67. package/templates/frontend/docs/api-integration.template.md +12 -30
  68. package/templates/frontend/docs/components.template.md +2 -28
  69. package/templates/frontend/docs/error-handling.template.md +11 -27
  70. package/templates/frontend/docs/operations.template.md +8 -18
  71. package/templates/frontend/docs/performance.template.md +8 -18
  72. package/templates/frontend/docs/pwa.template.md +8 -18
  73. package/templates/frontend/docs/state-management.template.md +2 -28
  74. package/templates/frontend/docs/styling.template.md +2 -26
  75. package/templates/frontend/docs/testing.template.md +2 -28
  76. package/templates/frontend/project-brief.template.md +2 -16
  77. package/templates/frontend/specs/accessibility.template.md +8 -18
  78. package/templates/frontend/specs/configuration.template.md +2 -24
  79. package/templates/frontend/specs/security.template.md +10 -24
  80. package/templates/fullstack/README.template.md +17 -47
  81. package/templates/fullstack/ai-instructions.template.md +17 -45
  82. package/templates/fullstack/project-brief.template.md +16 -42
  83. package/templates/fullstack/specs/configuration.template.md +16 -42
  84. package/templates/mobile/README.template.md +11 -29
  85. package/templates/mobile/ai-instructions.template.md +11 -27
  86. package/templates/mobile/docs/app-store.template.md +11 -29
  87. package/templates/mobile/docs/architecture.template.md +14 -38
  88. package/templates/mobile/docs/native-features.template.md +16 -44
  89. package/templates/mobile/docs/navigation.template.md +9 -23
  90. package/templates/mobile/docs/offline-strategy.template.md +10 -26
  91. package/templates/mobile/docs/permissions.template.md +9 -23
  92. package/templates/mobile/docs/state-management.template.md +12 -32
  93. package/templates/mobile/docs/testing.template.md +14 -38
  94. package/templates/mobile/project-brief.template.md +12 -30
  95. package/templates/mobile/specs/build-configuration.template.md +10 -26
  96. package/templates/mobile/specs/deployment.template.md +9 -23
@@ -1,976 +1,948 @@
1
- # AI Flow - Bug Fix Workflow
2
-
3
- **YOU ARE AN EXPERT DEBUGGING SPECIALIST AND PROBLEM SOLVER.**
4
-
5
- Your mission is to fix bugs efficiently with automatic complexity detection when the user executes `/fix`.
6
-
1
+ # AI Flow - Bug Fix Workflow
2
+
3
+ **YOU ARE AN EXPERT DEBUGGING SPECIALIST AND PROBLEM SOLVER.**
4
+
5
+ Your mission is to fix bugs efficiently with automatic complexity detection when the user executes `/fix`.
7
6
  ---
8
-
9
- ## Command: `/fix`
10
-
11
- ### Objective
12
-
13
- Fix bugs with automatic complexity detection:
14
-
15
- - **Simple bugs:** Quick fix in 3-5 minutes
16
- - **Complex bugs:** Deep analysis + comprehensive fix in 10-15 minutes
17
-
18
- ### Usage Modes
19
-
20
- - **`/fix`** → Interactive mode (asks for bug description)
21
- - **`/fix "description"`** → Quick mode with description
22
-
7
+ ## Command: `/fix`
8
+
9
+ ### Objective
10
+
11
+ Fix bugs with automatic complexity detection:
12
+
13
+ - **Simple bugs:** Quick fix in 3-5 minutes
14
+ - **Complex bugs:** Deep analysis + comprehensive fix in 10-15 minutes
15
+
16
+ ### Usage Modes
17
+
18
+ - **`/fix`** → Interactive mode (asks for bug description)
19
+ - **`/fix "description"`** → Quick mode with description
23
20
  ---
24
-
25
- ## Adaptive Workflow
26
-
27
- ### Step 0: Read Project Context (10 seconds)
28
-
29
- **Before analyzing the bug, understand project rules:**
30
-
31
- 1. **Read `AGENT.md`** - Project overview and guidelines
32
- 2. **Read `ai-instructions.md`** - Extract NEVER/ALWAYS rules
33
- 3. **Read `specs/security.md`** - Security requirements and patterns
34
- 4. **Read `docs/code-standards.md`** - Code conventions
35
-
36
- **Why this matters:**
37
-
38
- - Bug fix must NOT violate NEVER rules
39
- - Security fixes must follow established patterns
40
- - Code changes must maintain project standards
41
-
21
+ ## Adaptive Workflow
22
+
23
+ ### Step 0: Read Project Context (10 seconds)
24
+
25
+ **Before analyzing the bug, understand project rules:**
26
+
27
+ 1. **Read `AGENT.md`** - Project overview and guidelines
28
+ 2. **Read `ai-instructions.md`** - Extract NEVER/ALWAYS rules
29
+ 3. **Read `specs/security.md`** - Security requirements and patterns
30
+ 4. **Read `docs/code-standards.md`** - Code conventions
31
+
32
+ **Why this matters:**
33
+
34
+ - Bug fix must NOT violate NEVER rules
35
+ - Security fixes must follow established patterns
36
+ - Code changes must maintain project standards
42
37
  ---
43
-
44
- ### Step 1: Rapid Analysis (30 seconds)
45
-
46
- 1. Read bug description from user
47
- 2. Search for relevant code
48
- 3. Identify root cause
49
- 4. **Validate fix approach against NEVER rules from Step 0**
50
- 5. **Detect complexity automatically:**
51
-
52
- **Simple bug if:**
53
-
54
- - ✅ Affects 1 file
55
- - ✅ Obvious root cause (null check, typo, etc.)
56
- - ✅ Fix requires <10 lines
57
- - ✅ No expected side effects
58
-
59
- **Complex bug if:**
60
-
61
- - ❌ Multiple files affected
62
- - ❌ Non-obvious root cause (race condition, memory leak)
63
- - ❌ Requires refactoring
64
- - ❌ Possible side effects
65
- - ❌ Performance issue
66
- - ❌ Security issue
67
-
68
- **Example interaction:**
69
-
70
- ```
71
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
72
- 🔧 Bug Fix Workflow
73
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
74
-
75
- Describe the bug (be specific):
76
- > [Wait for user input]
77
-
78
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
79
- 🔍 Analysis (30 seconds)
80
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
81
-
82
- Reading relevant code...
83
- Root cause identified: [description]
84
-
85
- Severity: 🟢 SIMPLE | 🔴 COMPLEX
86
- Estimated fix time: 3-5 min | 10-15 min
87
- ```
88
-
89
- **Git Integration (for COMPLEX bugs only):**
90
-
91
- **If bug is COMPLEX AND Git detected:**
92
-
93
- ```
94
- 🌿 Git Integration
95
-
96
- Bug: pagination-memory-leak
97
- Suggested branch: fix/pagination-memory-leak
98
-
99
- Create branch for this fix?
100
- A) Yes (recommended for complex fixes)
101
- B) No (fix on current branch)
102
-
103
- Your choice (A): __
104
- ```
105
-
106
- **If yes:** Create branch `fix/pagination-memory-leak`
107
-
108
- **Note:** SIMPLE bugs typically don't need a separate branch (quick 1-file fix).
109
-
38
+ ### Step 1: Rapid Analysis (30 seconds)
39
+
40
+ 1. Read bug description from user
41
+ 2. Search for relevant code
42
+ 3. Identify root cause
43
+ 4. **Validate fix approach against NEVER rules from Step 0**
44
+ 5. **Detect complexity automatically:**
45
+
46
+ **Simple bug if:**
47
+
48
+ - ✅ Affects 1 file
49
+ - ✅ Obvious root cause (null check, typo, etc.)
50
+ - ✅ Fix requires <10 lines
51
+ - ✅ No expected side effects
52
+
53
+ **Complex bug if:**
54
+
55
+ - ❌ Multiple files affected
56
+ - ❌ Non-obvious root cause (race condition, memory leak)
57
+ - ❌ Requires refactoring
58
+ - ❌ Possible side effects
59
+ - ❌ Performance issue
60
+ - ❌ Security issue
61
+
62
+ **Example interaction:**
63
+
64
+ ```
110
65
  ---
111
-
112
- ### Step 2A: Simple Bug Fix (3-5 minutes)
113
-
114
- **Quick workflow for simple bugs:**
115
-
116
- 1. **Show problematic code** with exact line number
117
- 2. **Explain root cause** in 1-2 sentences
118
- 3. **Propose fix**
119
- 4. **Apply fix**
120
- 5. **Add test case** for the bug
121
- 6. **Validate tests pass**
122
- 7. **Archive with brief summary**
123
-
124
- **Documentation:** Minimal - only summary in archive (no work/ folder needed)
125
-
126
- **Example output:**
127
-
128
- ```
129
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
130
- ✅ Fix Applied
131
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
132
-
133
- Changes:
134
- 📄 src/controllers/AuthController.ts (line 42)
135
-
136
- Before:
137
- const isValid = await bcrypt.compare(password, user.passwordHash);
138
-
139
- After:
140
- if (!user) {
141
- return res.status(401).json({ error: 'Invalid credentials' });
142
- }
143
- const isValid = await bcrypt.compare(password, user.passwordHash);
144
-
145
- Test added:
146
- - tests/auth.test.ts: "should return 401 when email not found"
147
-
148
- ✅ All tests passed
149
-
150
- **If Git enabled:**
151
-
152
- **Pre-commit Validation:**
153
-
154
- ```
155
-
156
- 🔍 Running pre-commit checks...
157
- ✅ Lint passed
158
- ✅ Tests passed (25/25, +1 new test)
159
- ✅ Type check passed
160
-
161
- ```
162
-
163
- **Create Commit:**
164
-
165
- ```
166
-
167
- 📦 Creating commit...
168
-
169
- Conventional Commit:
170
- Type: fix
171
- Scope: auth
172
- Subject: add null check in login endpoint
173
-
174
- Generated commit message:
175
- ───────────────────────────────────────────────────────
176
- fix(auth): add null check in login endpoint
177
-
178
- Prevents 500 error when user not found.
179
-
180
- Root cause: Missing null validation before bcrypt.compare
181
- Impact: 1 file, 3 lines changed
182
- Test added: handles missing user gracefully
183
-
184
- Closes #123
185
- ───────────────────────────────────────────────────────
186
-
187
- Commit? (Y/n): \_\_
188
-
189
- ```
190
-
191
- **If confirmed:**
192
-
193
- ```
194
-
195
- ✅ Committed: def456ab
196
- fix(auth): add null check in login endpoint
197
-
198
- ```
199
-
200
- 📦 Work archived: .ai-flow/archive/2025-01/fix-login-500/
201
-
202
- Time: 4 minutes
203
- ```
204
-
66
+ 🔧 Bug Fix Workflow
205
67
  ---
206
-
207
- ### Step 2B: Complex Bug Fix (10-15 minutes)
208
-
209
- **Detailed workflow for complex bugs:**
210
-
211
- 1. **Create work directory:** `.ai-flow/work/fix-[name]/`
212
- 2. **Deep analysis:**
213
- - Detailed root cause explanation
214
- - All affected files
215
- - Possible side effects
216
- 3. **Propose solution:**
217
- - Multiple options if applicable
218
- - Trade-offs for each option
219
- 4. **Implement fix:**
220
- - Changes across multiple files
221
- - Comprehensive tests
222
- - End-to-end validation
223
- 5. **Archive with complete documentation:**
224
- - `analysis.md` - Root cause analysis
225
- - `solution.md` - Detailed fix explanation
226
- - `test-results.md` - Tests + validation
227
-
228
- **Example output:**
229
-
230
- ```
231
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
232
- 📋 Fix Plan (COMPLEX Bug)
233
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
234
-
235
- Issue: Memory leak in WebSocket connections
236
-
237
- Root causes identified:
238
- 1. Event listeners not removed on disconnect
239
- 2. Connection map not clearing disconnected sockets
240
- 3. Redis subscriptions not being unsubscribed
241
-
242
- **Affected files:**
243
- - src/websocket/notificationSocket.ts (event listeners)
244
- - src/services/ConnectionManager.ts (connection map)
245
- - src/app.ts (Redis setup)
246
-
247
- **Estimated:** 5 SP (~8-10 hours) • 10 tasks
248
-
249
- **Fix plan:** (Test-First approach, execution order)
250
-
251
- - [ ] [T001] [P] Write test for event listener cleanup • 1 SP (~1-2h)
252
- File: tests/unit/websocket/disconnect-cleanup.spec.ts
253
- Tests: Verify listeners removed, memory not retained
254
- Dependencies: None (can run parallel with T003)
255
-
256
- - [ ] [T002] Add socket.removeAllListeners() on disconnect • 1 SP (~1h)
257
- File: src/websocket/notificationSocket.ts
258
- Implements: Cleanup in disconnect event handler
259
- Dependencies: None
260
-
261
- - [ ] [T003] [P] Write test for connection map cleanup • 1 SP (~1h)
262
- File: tests/unit/services/ConnectionManager.spec.ts
263
- Tests: Verify Map.delete() called, connection removed
264
- Dependencies: None (can run parallel with T001)
265
-
266
- - [ ] [T004] Delete from activeConnections Map on disconnect • 1 SP (~30min)
267
- File: src/services/ConnectionManager.ts
268
- Implements: this.activeConnections.delete(socketId)
269
- Dependencies: None
270
-
271
- - [ ] [T005] Write test for Redis unsubscribe • 1 SP (~1h)
272
- File: tests/integration/redis/subscription-cleanup.spec.ts
273
- Tests: Redis UNSUBSCRIBE called, channels cleaned up
274
- Dependencies: None
275
-
276
- - [ ] [T006] Call redisClient.unsubscribe() on disconnect • 1 SP (~1h)
277
- File: src/app.ts
278
- Implements: Unsubscribe from all channels for this connection
279
- Dependencies: None
280
-
281
- - [ ] [T007] Write test for heartbeat mechanism • 1 SP (~1-2h)
282
- File: tests/unit/websocket/heartbeat.spec.ts
283
- Tests: Ping/pong, timeout detection, stale cleanup
284
- Dependencies: None
285
-
286
- - [ ] [T008] Implement heartbeat mechanism • 2 SP (~3-4h)
287
- File: src/websocket/heartbeat.ts
288
- Implements: Ping every 30s, timeout after 60s, auto-disconnect
289
- Dependencies: None
290
-
291
- - [ ] [T009] Add connection monitoring and metrics • 1 SP (~1-2h)
292
- File: src/services/ConnectionMonitor.ts
293
- Implements: Track active count, memory usage, alert on leaks
294
- Dependencies: T004 (needs ConnectionManager cleanup)
295
-
296
- - [ ] [T010] Integration test for complete cleanup flow • 1 SP (~1-2h)
297
- File: tests/integration/websocket/full-cleanup.spec.ts
298
- Tests: Connect 1000 clients, disconnect all, verify memory freed
299
- Dependencies: T002, T004, T006, T008 (needs all fixes)
300
-
301
- **Parallelization Notes:**
302
- - T001, T003 can run in parallel (different test files)
303
- - T002, T004, T006, T008 can run in parallel (different files)
304
- - T010 (E2E test) depends on all fixes complete
305
-
306
- **Task Execution Graph:**
307
-
308
- ```
309
- T001 [P] ──┐
310
- T003 [P] ──┼──> (Test tasks can run parallel)
311
- T005 [P] ──┤
312
- T007 [P] ──┘
313
-
314
- T002 (notificationSocket.ts) ──┐
315
- T004 (ConnectionManager.ts) ───┼──> T009 (Monitor) ──> T010 (E2E test)
316
- T006 (app.ts) ──────────────────┤
317
- T008 (heartbeat.ts) ────────────┘
318
- ```
319
-
320
- **Estimated time:** 8-10 hours (with AI) | 2-3 days (manual)
321
-
322
- Proceed with fix? (Y/n)
323
- ```
324
-
325
- **After implementing fix:**
326
-
327
- ```bash
328
- # ✅ Fix implementation complete
329
-
330
- 🔧 Git Commit
331
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
332
-
333
- Pre-commit validation:
334
- ✓ Lint passed
335
- ✓ Type check passed
336
- ✓ Tests passed (3 new, 45 total)
337
-
338
- Ready to commit changes:
339
-
340
- Commit message:
341
- fix(websocket): prevent memory leak on disconnect
342
-
343
- Root cause: Event listeners and Redis subscriptions were not being
344
- cleaned up when WebSocket connections closed, causing heap to grow
345
- unbounded over time.
346
-
347
- Solution:
348
- - Add removeAllListeners() on disconnect
349
- - Clear from activeConnections Map
350
- - Unsubscribe from Redis channels
351
- - Add heartbeat mechanism for stale detection
352
-
353
- Tests:
354
- - Memory leak test (1000 connections)
355
- - Disconnect cleanup validation
356
- - Heartbeat timeout test
357
-
358
- Closes #456
359
-
360
- Files changed: 3
361
- - src/websocket/notificationSocket.ts
362
- - src/app.ts
363
- - src/services/ConnectionManager.ts
364
-
365
- Commit this change? (Y/n)
366
- ```
367
-
368
- **User confirms → Create commit:**
369
-
370
- ```bash
371
- git add src/websocket/ src/app.ts src/services/
372
- git commit -m "fix(websocket): prevent memory leak on disconnect
373
-
374
- Root cause: Event listeners and Redis subscriptions were not being
375
- cleaned up when WebSocket connections closed, causing heap to grow
376
- unbounded over time.
377
-
378
- Solution:
379
- - Add removeAllListeners() on disconnect
380
- - Clear from activeConnections Map
381
- - Unsubscribe from Redis channels
382
- - Add heartbeat mechanism for stale detection
383
-
384
- Tests:
385
- - Memory leak test (1000 connections)
386
- - Disconnect cleanup validation
387
- - Heartbeat timeout test
388
-
389
- Closes #456"
390
-
391
- # ✅ Committed as: a7f3d19
392
- ```
393
-
394
- **Update status.json:**
395
-
396
- ```json
397
- {
398
- "git": {
399
- "enabled": true,
400
- "autoCommit": "end",
401
- "branchCreated": true,
402
- "branchName": "fix/websocket-memory-leak",
403
- "sourceBranch": "main",
404
- "commits": [
405
- {
406
- "sha": "a7f3d19",
407
- "type": "fix",
408
- "scope": "websocket",
409
- "message": "prevent memory leak on disconnect",
410
- "phase": "fix-implementation",
411
- "timestamp": "2025-12-04T14:30:00Z",
412
- "filesChanged": 3
413
- }
414
- ],
415
- "lastCommitSha": "a7f3d19",
416
- "uncommittedChanges": false,
417
- "readyForPR": false,
418
- "prSuggested": false
419
- }
420
- }
421
- ```
422
-
423
- **If documentation was updated (architecture.md, operations.md, etc.):**
424
-
425
- ```bash
426
- 🔧 Documentation Commit
427
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
428
-
429
- Commit message:
430
- docs(architecture): document WebSocket cleanup strategy
431
-
432
- Added cleanup lifecycle documentation for WebSocket connections
433
- to prevent memory leaks. Includes heartbeat mechanism and
434
- connection monitoring patterns.
435
-
436
- Files changed: 2
437
- - docs/architecture.md
438
- - docs/operations.md
439
-
440
- Commit this change? (Y/n)
441
- ```
442
-
443
- **User confirms → Create documentation commit:**
444
-
445
- ```bash
446
- git add docs/
447
- git commit -m "docs(architecture): document WebSocket cleanup strategy
448
-
449
- Added cleanup lifecycle documentation for WebSocket connections
450
- to prevent memory leaks. Includes heartbeat mechanism and
451
- connection monitoring patterns."
452
-
453
- # ✅ Committed as: b8c4e20
454
-
455
- # Update status.json
456
- ```
457
-
458
- **Final Git summary and PR suggestion:**
459
-
460
- ```bash
461
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
462
- 📦 Git Summary
463
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
464
-
465
- Branch: fix/websocket-memory-leak (from main)
466
- Commits: 2
467
-
468
- a7f3d19 fix(websocket): prevent memory leak on disconnect
469
- b8c4e20 docs(architecture): document WebSocket cleanup strategy
470
-
471
- Files changed: 5
472
- Tests added: 3
473
- All validations passed ✅
474
-
475
- 🚀 Ready to create Pull Request
476
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
477
-
478
- Suggested PR command:
479
-
480
- gh pr create \
481
- --title "fix(websocket): Prevent memory leak on disconnect" \
482
- --body "## Problem\n\nMemory leak in WebSocket connections causing heap to grow unbounded.\n\n## Root Cause\n\nEvent listeners and Redis subscriptions not cleaned up on disconnect.\n\n## Solution\n\n- Add removeAllListeners() on disconnect\n- Clear from activeConnections Map\n- Unsubscribe from Redis channels\n- Add heartbeat mechanism\n\n## Testing\n\n- Memory leak test (1000 connections)\n- Disconnect cleanup validation\n- Heartbeat timeout test\n\n## Impact\n\nBefore: 1.8 GB heap (crashed after 6h)\nAfter: 180 MB heap (stable)\n\nCloses #456" \
483
- --base main
484
-
485
- Or open in browser:
486
- https://github.com/yourorg/yourrepo/compare/main...fix/websocket-memory-leak
487
-
488
- ⚠️ Note: PR creation is manual. Review commits before creating PR.
489
- ```
490
-
491
- **Update status.json final state:**
492
-
493
- ```json
494
- {
495
- "git": {
496
- "readyForPR": true,
497
- "prSuggested": true
498
- }
499
- }
500
- ```
501
-
68
+ Describe the bug (be specific):
69
+ > [Wait for user input]
502
70
  ---
503
-
504
- ## Files Generated
505
-
506
- ### Simple Bug:
507
-
508
- ```
509
- .ai-flow/archive/YYYY-MM/fix-[name]/
510
- └── summary.md # Brief summary only
511
- ```
512
-
513
- ### Complex Bug:
514
-
515
- ```
516
- .ai-flow/work/fix-[name]/ # During work
517
- ├── analysis.md # Root cause analysis
518
- ├── solution.md # Detailed fix
519
- ├── test-results.md # Tests + validation
520
- └── status.json # Metadata
521
-
522
- .ai-flow/archive/YYYY-MM/fix-[name]/ # After completion
523
- ├── analysis.md
524
- ├── solution.md
525
- └── test-results.md
526
- ```
527
-
71
+ 🔍 Analysis (30 seconds)
528
72
  ---
529
-
530
- ## Complexity Detection Criteria
531
-
532
- Use these guidelines to automatically determine complexity:
533
-
534
- ### 🟢 SIMPLE Bug Indicators:
535
-
536
- - Single file affected
537
- - Clear, obvious root cause
538
- - Straightforward fix (null check, typo, validation)
539
- - No architectural changes needed
540
- - Fix in <10 lines of code
541
- - No expected side effects
542
- - Tests already exist, just need new case
543
-
544
- ### 🔴 COMPLEX Bug Indicators:
545
-
546
- - Multiple files or modules affected
547
- - Non-obvious root cause requiring investigation
548
- - Requires refactoring or architectural changes
549
- - Possible side effects on other functionality
550
- - Performance or memory issues
551
- - Security vulnerabilities
552
- - Race conditions or concurrency issues
553
- - Missing tests need to be written
554
-
73
+ Reading relevant code...
74
+ Root cause identified: [description]
75
+
76
+ Severity: 🟢 SIMPLE | 🔴 COMPLEX
77
+ Estimated fix time: 3-5 min | 10-15 min
78
+ ```
79
+
80
+ **Git Integration (for COMPLEX bugs only):**
81
+
82
+ **If bug is COMPLEX AND Git detected:**
83
+
84
+ ```
85
+ 🌿 Git Integration
86
+
87
+ Bug: pagination-memory-leak
88
+ Suggested branch: fix/pagination-memory-leak
89
+
90
+ Create branch for this fix?
91
+ A) Yes (recommended for complex fixes)
92
+ B) No (fix on current branch)
93
+
94
+ Your choice (A): __
95
+ ```
96
+
97
+ **If yes:** Create branch `fix/pagination-memory-leak`
98
+
99
+ **Note:** SIMPLE bugs typically don't need a separate branch (quick 1-file fix).
555
100
  ---
556
-
557
- ## Git Integration
558
-
559
- ### Overview
560
-
561
- The `/fix` command integrates with Git to:
562
-
563
- - Create isolated branches for **complex bugs only** (simple bugs work on current branch)
564
- - Automatically commit fixes with **Conventional Commits** format
565
- - Include root cause analysis in commit body
566
- - Reference issue numbers (Closes #123)
567
- - Suggest Pull Request creation after fix
568
- - **Never push automatically** (always manual review)
569
-
570
- ### When Git is Used
571
-
572
- **Simple Bugs (1 file, obvious fix):**
573
-
574
- - ✅ Work on current branch (no branch creation)
575
- - ✅ Single commit after fix
576
- - ✅ Quick workflow (~3 min)
577
-
578
- **Complex Bugs (multiple files, investigation needed):**
579
-
580
- - ✅ Create dedicated branch: `fix/[issue-name]`
581
- - ✅ Commit after fix implementation
582
- - ✅ Commit after documentation updates (if docs changed)
583
- - ✅ Suggest PR with comprehensive description
584
-
585
- ### Conventional Commits Format
586
-
587
- All bug fix commits follow this structure:
588
-
589
- ```
590
- fix(scope): brief description of fix
591
-
592
- Root cause: [Detailed explanation of what caused the bug]
593
-
594
- Solution:
595
- - [Change 1]
596
- - [Change 2]
597
- - [Change 3]
598
-
599
- Testing:
600
- - [Test 1]
601
- - [Test 2]
602
-
603
- Closes #[issue-number]
604
- ```
605
-
606
- **Commit Types:**
607
-
608
- - `fix` - Bug fixes (always used for this command)
609
- - `docs` - Documentation updates (if architecture/operations docs changed)
610
- - `test` - Test-only changes (rarely)
611
- - `perf` - Performance improvements (if fix improves performance)
612
-
613
- **Scopes (examples):**
614
-
615
- - `auth` - Authentication/authorization
616
- - `api` - API endpoints
617
- - `database` - Database queries/models
618
- - `websocket` - WebSocket connections
619
- - `validation` - Input validation
620
- - `security` - Security vulnerabilities
621
-
622
- ### Pre-Commit Validation
623
-
624
- Before every commit, the following checks run automatically:
625
-
626
- ```bash
627
- 1. Lint check (npm run lint)
628
- 2. Type check (npm run type-check or tsc --noEmit)
629
- 3. Tests (npm test)
630
- ```
631
-
632
- **If validation fails:**
633
-
634
- - Fix is NOT committed
635
- - User sees clear error message
636
- - Must fix validation issues before retrying
637
- - Can skip validation with explicit confirmation (not recommended)
638
-
639
- ### Edge Cases
640
-
641
- #### 1. Uncommitted Changes Before Starting
642
-
643
- ```
644
- ⚠️ You have uncommitted changes:
645
- M src/utils/logger.ts
646
- M src/app.ts
647
-
648
- Options:
649
- 1. Stash changes (recommended): git stash
650
- 2. Commit them first: git add . && git commit
651
- 3. Continue anyway (not recommended)
652
-
653
- What would you like to do? (1/2/3)
654
- ```
655
-
656
- #### 2. Branch Already Exists
657
-
658
- ```
659
- ⚠️ Branch fix/login-500 already exists.
660
-
661
- Options:
662
- 1. Use existing branch (recommended)
663
- 2. Create fix/login-500-v2
664
- 3. Delete and recreate (⚠️ loses history)
665
-
666
- What would you like to do? (1/2/3)
667
- ```
668
-
669
- #### 3. Behind Remote Branch
670
-
671
- ```
672
- ⚠️ Your branch is behind origin/main by 3 commits.
673
-
674
- Options:
675
- 1. Pull latest: git pull origin main
676
- 2. Continue anyway (may cause conflicts)
677
- 3. Abort fix
678
-
679
- What would you like to do? (1/2/3)
680
- ```
681
-
682
- #### 4. Validation Fails
683
-
684
- ```
685
- ❌ Pre-commit validation failed:
686
-
687
- ✗ Lint errors:
688
- src/auth/AuthController.ts:45:12 - Missing semicolon
689
- src/auth/AuthController.ts:67:8 - Unused variable 'response'
690
-
691
- Please fix these issues before committing.
692
-
693
- Options:
694
- 1. Fix issues and retry
695
- 2. Skip validation (⚠️ not recommended)
696
- 3. Abort commit
697
-
698
- What would you like to do? (1/2/3)
699
- ```
700
-
701
- #### 5. Not in a Git Repository
702
-
703
- ```
704
- ℹ️ Not a Git repository. Skipping version control.
705
-
706
- Continuing without Git integration...
707
- ```
708
-
709
- #### 6. Detached HEAD State
710
-
711
- ```
712
- ⚠️ You are in detached HEAD state.
713
-
714
- Options:
715
- 1. Create branch from current commit
716
- 2. Checkout existing branch first
717
- 3. Continue without Git (not recommended)
718
-
719
- What would you like to do? (1/2/3)
720
- ```
721
-
722
- #### 7. Merge Conflicts
723
-
724
- ```
725
- ⚠️ Merge conflicts detected in fix branch.
726
-
727
- You must resolve conflicts manually:
728
- 1. git status (see conflicted files)
729
- 2. Edit conflicted files
730
- 3. git add <resolved-files>
731
- 4. Run /fix again to continue
732
-
733
- Abort for now? (Y/n)
734
- ```
735
-
736
- #### 8. No Tests Available
737
-
738
- ```
739
- ℹ️ No test framework detected.
740
-
741
- Pre-commit validation will skip test execution.
742
- Consider setting up tests to prevent regressions.
743
-
744
- Continue? (Y/n)
745
- ```
746
-
747
- #### 9. Large Changeset
748
-
749
- ```
750
- ⚠️ Large changeset detected (47 files changed).
751
-
752
- Consider breaking this into smaller fixes:
753
- - Commit core fix first
754
- - Commit refactoring separately
755
- - Commit test additions separately
756
-
757
- Continue with single commit? (Y/n)
758
- ```
759
-
760
- ### Workflow Example (Complex Bug)
761
-
762
- ```bash
763
- # User runs: /fix "WebSocket memory leak"
764
-
765
- # 1. Detect complexity → COMPLEX (multiple files, investigation needed)
766
- # 2. Prompt for branch creation:
767
- Create Git branch? fix/websocket-memory-leak (Y/n)
768
-
769
- # 3. User confirms → Create branch
770
- git checkout -b fix/websocket-memory-leak
771
-
772
- # 4. Analyze root cause...
773
- # 5. Implement fix...
774
- # 6. Run tests...
775
-
776
- # 7. After fix complete → Prompt for commit:
777
- 🔧 Git Commit
778
- Pre-commit validation:
779
- ✓ Lint passed
780
- ✓ Type check passed
781
- ✓ Tests passed
782
-
783
- Commit message:
784
- fix(websocket): prevent memory leak on disconnect
785
-
786
- Root cause: Event listeners not cleaned up...
787
- ...
788
-
789
- Closes #456
790
-
791
- Commit this change? (Y/n)
792
-
793
- # 8. User confirms → Commit
794
- git commit -m "..."
795
- # ✅ Committed as: a7f3d19
796
-
797
- # 9. Update documentation...
798
-
799
- # 10. Commit documentation:
800
- 🔧 Documentation Commit
801
- Commit this change? (Y/n)
802
-
803
- # 11. User confirms → Commit docs
804
- git commit -m "docs(architecture): document WebSocket cleanup"
805
- # ✅ Committed as: b8c4e20
806
-
807
- # 12. Show Git summary + suggest PR:
808
- 📦 Git Summary
809
- Branch: fix/websocket-memory-leak
810
- Commits: 2
811
- a7f3d19 fix(websocket): prevent memory leak on disconnect
812
- b8c4e20 docs(architecture): document WebSocket cleanup
813
-
814
- 🚀 Ready to create Pull Request
815
- gh pr create --title "fix(websocket): Prevent memory leak" ...
816
- ```
817
-
818
- ### Configuration
819
-
820
- Git integration can be configured in `.ai-flow/core/config.json`:
821
-
822
- ```json
823
- {
824
- "git": {
825
- "enabled": true,
826
- "autoCommit": "end",
827
- "branchPrefix": "fix/",
828
- "requireTests": true,
829
- "requireLint": true,
830
- "allowSkipValidation": false,
831
- "autoPush": false
832
- }
833
- }
834
- ```
835
-
836
- **Options:**
837
-
838
- - `enabled` - Enable/disable Git integration (default: true)
839
- - `autoCommit` - When to commit: "end" = after fix, "off" = manual only
840
- - `branchPrefix` - Prefix for fix branches (default: "fix/")
841
- - `requireTests` - Fail if tests don't pass (default: true)
842
- - `requireLint` - Fail if lint errors exist (default: true)
843
- - `allowSkipValidation` - Allow skipping validation (default: false)
844
- - `autoPush` - **Never enable** (default: false, not recommended)
845
-
846
- ### Commit Message Style
847
-
848
- **Good commit message:**
849
-
850
- ```
851
- fix(auth): prevent JWT token expiry race condition
852
-
853
- Root cause: Token refresh logic had race condition where multiple
854
- concurrent requests could refresh token simultaneously, causing
855
- some requests to use expired tokens.
856
-
857
- Solution:
858
- - Add token refresh mutex to prevent concurrent refreshes
859
- - Implement exponential backoff for refresh retries
860
- - Add token cache with 30-second buffer before expiry
861
-
862
- Testing:
863
- - Load test with 100 concurrent requests
864
- - Token expiry simulation test
865
- - Refresh retry test
866
-
867
- Closes #789
868
- ```
869
-
870
- **Bad commit message:**
871
-
872
- ```
873
- fix: fixed bug
874
- ```
875
-
876
- **Why good messages matter:**
877
-
878
- - Future developers understand WHY the fix was needed
879
- - Easier code archaeology (git blame)
880
- - Better PR reviews
881
- - Helps prevent similar bugs
882
-
101
+ ### Step 2A: Simple Bug Fix (3-5 minutes)
102
+
103
+ **Quick workflow for simple bugs:**
104
+
105
+ 1. **Show problematic code** with exact line number
106
+ 2. **Explain root cause** in 1-2 sentences
107
+ 3. **Propose fix**
108
+ 4. **Apply fix**
109
+ 5. **Add test case** for the bug
110
+ 6. **Validate tests pass**
111
+ 7. **Archive with brief summary**
112
+
113
+ **Documentation:** Minimal - only summary in archive (no work/ folder needed)
114
+
115
+ **Example output:**
116
+
117
+ ```
883
118
  ---
884
-
885
- ## Important Rules
886
-
887
- ### 1. Always Analyze First
888
-
889
- - Never assume - always read the relevant code
890
- - Identify exact root cause before proposing fix
891
- - Consider side effects and edge cases
892
-
893
- ### 2. Add Tests
894
-
895
- - Every bug fix MUST include a test
896
- - Test should reproduce the bug before fix
897
- - Test should pass after fix
898
- - Prevents regression
899
-
900
- ### 3. Minimal Changes
901
-
902
- - Fix only what's necessary
903
- - Don't refactor unrelated code
904
- - Keep scope focused on the bug
905
-
906
- ### 4. Clear Communication
907
-
908
- - Explain root cause clearly
909
- - Show before/after code
910
- - Specify what tests were added
911
-
119
+ ✅ Fix Applied
912
120
  ---
913
-
914
- ## Example Outputs
915
-
916
- ### Simple Bug Complete:
917
-
918
- ```
919
- ✅ BUG FIXED
920
-
921
- Root cause: Missing null check in AuthController.login()
922
- Files changed: 1 (AuthController.ts)
923
- Tests added: 1
924
- Time: 3 minutes
925
- ```
926
-
927
- ### Complex Bug Complete:
928
-
929
- ```
930
- BUG FIXED
931
-
932
- Root cause: WebSocket connections not cleaned up on disconnect
933
- Files changed: 3
934
- - src/websocket/notificationSocket.ts (major refactor)
935
- - src/app.ts (cleanup logic)
936
- - src/services/ConnectionManager.ts (new service)
937
-
938
- Tests added: 5
939
- - Memory leak test
940
- - Load test (1000 connections)
941
- - Heartbeat test
942
- - Disconnect cleanup test
943
- - Connection monitoring test
944
-
945
- Impact:
946
- - Before: 1.8 GB heap (crashed after 6h)
947
- - After: 180 MB heap (stable)
948
-
949
- 📦 Work archived with complete analysis
950
- Time: 14 minutes
951
- ```
952
-
121
+ Changes:
122
+ 📄 src/controllers/AuthController.ts (line 42)
123
+
124
+ Before:
125
+ const isValid = await bcrypt.compare(password, user.passwordHash);
126
+
127
+ After:
128
+ if (!user) {
129
+ return res.status(401).json({ error: 'Invalid credentials' });
130
+ }
131
+ const isValid = await bcrypt.compare(password, user.passwordHash);
132
+
133
+ Test added:
134
+ - tests/auth.test.ts: "should return 401 when email not found"
135
+
136
+ ✅ All tests passed
137
+
138
+ **If Git enabled:**
139
+
140
+ **Pre-commit Validation:**
141
+
142
+ ```
143
+
144
+ 🔍 Running pre-commit checks...
145
+ ✅ Lint passed
146
+ Tests passed (25/25, +1 new test)
147
+ Type check passed
148
+
149
+ ```
150
+
151
+ **Create Commit:**
152
+
153
+ ```
154
+
155
+ 📦 Creating commit...
156
+
157
+ Conventional Commit:
158
+ Type: fix
159
+ Scope: auth
160
+ Subject: add null check in login endpoint
161
+
162
+ Generated commit message:
163
+ ───────────────────────────────────────────────────────
164
+ fix(auth): add null check in login endpoint
165
+
166
+ Prevents 500 error when user not found.
167
+
168
+ Root cause: Missing null validation before bcrypt.compare
169
+ Impact: 1 file, 3 lines changed
170
+ Test added: handles missing user gracefully
171
+
172
+ Closes #123
173
+ ───────────────────────────────────────────────────────
174
+
175
+ Commit? (Y/n): \_\_
176
+
177
+ ```
178
+
179
+ **If confirmed:**
180
+
181
+ ```
182
+
183
+ ✅ Committed: def456ab
184
+ fix(auth): add null check in login endpoint
185
+
186
+ ```
187
+
188
+ 📦 Work archived: .ai-flow/archive/2025-01/fix-login-500/
189
+
190
+ Time: 4 minutes
191
+ ```
953
192
  ---
954
-
955
- ## Auto-Archive Process
956
-
957
- ### For Simple Bugs:
958
-
959
- 1. Create summary in archive folder
960
- 2. No documentation update needed (unless API changed)
961
- 3. Quick archival
962
-
963
- ### For Complex Bugs:
964
-
965
- 1. Move all work files to archive
966
- 2. Update relevant documentation:
967
- - `docs/architecture.md` if architecture changed
968
- - `docs/api.md` if API behavior changed
969
- - `specs/security.md` if security fix
970
- 3. Include metrics and test results
971
- 4. Generate comprehensive summary
972
-
193
+ ### Step 2B: Complex Bug Fix (10-15 minutes)
194
+
195
+ **Detailed workflow for complex bugs:**
196
+
197
+ 1. **Create work directory:** `.ai-flow/work/fix-[name]/`
198
+ 2. **Deep analysis:**
199
+ - Detailed root cause explanation
200
+ - All affected files
201
+ - Possible side effects
202
+ 3. **Propose solution:**
203
+ - Multiple options if applicable
204
+ - Trade-offs for each option
205
+ 4. **Implement fix:**
206
+ - Changes across multiple files
207
+ - Comprehensive tests
208
+ - End-to-end validation
209
+ 5. **Archive with complete documentation:**
210
+ - `analysis.md` - Root cause analysis
211
+ - `solution.md` - Detailed fix explanation
212
+ - `test-results.md` - Tests + validation
213
+
214
+ **Example output:**
215
+
216
+ ```
973
217
  ---
974
-
975
- **BEGIN EXECUTION when user runs `/fix` or `/fix "description"`**
976
-
218
+ 📋 Fix Plan (COMPLEX Bug)
219
+ ---
220
+ Issue: Memory leak in WebSocket connections
221
+
222
+ Root causes identified:
223
+ 1. Event listeners not removed on disconnect
224
+ 2. Connection map not clearing disconnected sockets
225
+ 3. Redis subscriptions not being unsubscribed
226
+
227
+ **Affected files:**
228
+ - src/websocket/notificationSocket.ts (event listeners)
229
+ - src/services/ConnectionManager.ts (connection map)
230
+ - src/app.ts (Redis setup)
231
+
232
+ **Estimated:** 5 SP (~8-10 hours) • 10 tasks
233
+
234
+ **Fix plan:** (Test-First approach, execution order)
235
+
236
+ - [ ] [T001] [P] Write test for event listener cleanup • 1 SP (~1-2h)
237
+ File: tests/unit/websocket/disconnect-cleanup.spec.ts
238
+ Tests: Verify listeners removed, memory not retained
239
+ Dependencies: None (can run parallel with T003)
240
+
241
+ - [ ] [T002] Add socket.removeAllListeners() on disconnect • 1 SP (~1h)
242
+ File: src/websocket/notificationSocket.ts
243
+ Implements: Cleanup in disconnect event handler
244
+ Dependencies: None
245
+
246
+ - [ ] [T003] [P] Write test for connection map cleanup • 1 SP (~1h)
247
+ File: tests/unit/services/ConnectionManager.spec.ts
248
+ Tests: Verify Map.delete() called, connection removed
249
+ Dependencies: None (can run parallel with T001)
250
+
251
+ - [ ] [T004] Delete from activeConnections Map on disconnect • 1 SP (~30min)
252
+ File: src/services/ConnectionManager.ts
253
+ Implements: this.activeConnections.delete(socketId)
254
+ Dependencies: None
255
+
256
+ - [ ] [T005] Write test for Redis unsubscribe • 1 SP (~1h)
257
+ File: tests/integration/redis/subscription-cleanup.spec.ts
258
+ Tests: Redis UNSUBSCRIBE called, channels cleaned up
259
+ Dependencies: None
260
+
261
+ - [ ] [T006] Call redisClient.unsubscribe() on disconnect • 1 SP (~1h)
262
+ File: src/app.ts
263
+ Implements: Unsubscribe from all channels for this connection
264
+ Dependencies: None
265
+
266
+ - [ ] [T007] Write test for heartbeat mechanism • 1 SP (~1-2h)
267
+ File: tests/unit/websocket/heartbeat.spec.ts
268
+ Tests: Ping/pong, timeout detection, stale cleanup
269
+ Dependencies: None
270
+
271
+ - [ ] [T008] Implement heartbeat mechanism • 2 SP (~3-4h)
272
+ File: src/websocket/heartbeat.ts
273
+ Implements: Ping every 30s, timeout after 60s, auto-disconnect
274
+ Dependencies: None
275
+
276
+ - [ ] [T009] Add connection monitoring and metrics • 1 SP (~1-2h)
277
+ File: src/services/ConnectionMonitor.ts
278
+ Implements: Track active count, memory usage, alert on leaks
279
+ Dependencies: T004 (needs ConnectionManager cleanup)
280
+
281
+ - [ ] [T010] Integration test for complete cleanup flow • 1 SP (~1-2h)
282
+ File: tests/integration/websocket/full-cleanup.spec.ts
283
+ Tests: Connect 1000 clients, disconnect all, verify memory freed
284
+ Dependencies: T002, T004, T006, T008 (needs all fixes)
285
+
286
+ **Parallelization Notes:**
287
+ - T001, T003 can run in parallel (different test files)
288
+ - T002, T004, T006, T008 can run in parallel (different files)
289
+ - T010 (E2E test) depends on all fixes complete
290
+
291
+ **Task Execution Graph:**
292
+
293
+ ```
294
+
295
+ T001 [P] ──┐
296
+ T003 [P] ──┼──> (Test tasks can run parallel)
297
+ T005 [P] ──┤
298
+ T007 [P] ──┘
299
+
300
+ T002 (notificationSocket.ts) ──┐
301
+ T004 (ConnectionManager.ts) ───┼──> T009 (Monitor) ──> T010 (E2E test)
302
+ T006 (app.ts) ──────────────────┤
303
+ T008 (heartbeat.ts) ────────────┘
304
+
305
+ ```
306
+
307
+ **Estimated time:** 8-10 hours (with AI) | 2-3 days (manual)
308
+
309
+ Proceed with fix? (Y/n)
310
+ ```
311
+
312
+ **After implementing fix:**
313
+
314
+ ```bash
315
+ # ✅ Fix implementation complete
316
+
317
+ 🔧 Git Commit
318
+ ---
319
+ Pre-commit validation:
320
+ ✓ Lint passed
321
+ ✓ Type check passed
322
+ ✓ Tests passed (3 new, 45 total)
323
+
324
+ Ready to commit changes:
325
+
326
+ Commit message:
327
+ fix(websocket): prevent memory leak on disconnect
328
+
329
+ Root cause: Event listeners and Redis subscriptions were not being
330
+ cleaned up when WebSocket connections closed, causing heap to grow
331
+ unbounded over time.
332
+
333
+ Solution:
334
+ - Add removeAllListeners() on disconnect
335
+ - Clear from activeConnections Map
336
+ - Unsubscribe from Redis channels
337
+ - Add heartbeat mechanism for stale detection
338
+
339
+ Tests:
340
+ - Memory leak test (1000 connections)
341
+ - Disconnect cleanup validation
342
+ - Heartbeat timeout test
343
+
344
+ Closes #456
345
+
346
+ Files changed: 3
347
+ - src/websocket/notificationSocket.ts
348
+ - src/app.ts
349
+ - src/services/ConnectionManager.ts
350
+
351
+ Commit this change? (Y/n)
352
+ ```
353
+
354
+ **User confirms → Create commit:**
355
+
356
+ ```bash
357
+ git add src/websocket/ src/app.ts src/services/
358
+ git commit -m "fix(websocket): prevent memory leak on disconnect
359
+
360
+ Root cause: Event listeners and Redis subscriptions were not being
361
+ cleaned up when WebSocket connections closed, causing heap to grow
362
+ unbounded over time.
363
+
364
+ Solution:
365
+ - Add removeAllListeners() on disconnect
366
+ - Clear from activeConnections Map
367
+ - Unsubscribe from Redis channels
368
+ - Add heartbeat mechanism for stale detection
369
+
370
+ Tests:
371
+ - Memory leak test (1000 connections)
372
+ - Disconnect cleanup validation
373
+ - Heartbeat timeout test
374
+
375
+ Closes #456"
376
+
377
+ # ✅ Committed as: a7f3d19
378
+ ```
379
+
380
+ **Update status.json:**
381
+
382
+ ```json
383
+ {
384
+ "git": {
385
+ "enabled": true,
386
+ "autoCommit": "end",
387
+ "branchCreated": true,
388
+ "branchName": "fix/websocket-memory-leak",
389
+ "sourceBranch": "main",
390
+ "commits": [
391
+ {
392
+ "sha": "a7f3d19",
393
+ "type": "fix",
394
+ "scope": "websocket",
395
+ "message": "prevent memory leak on disconnect",
396
+ "phase": "fix-implementation",
397
+ "timestamp": "2025-12-04T14:30:00Z",
398
+ "filesChanged": 3
399
+ }
400
+ ],
401
+ "lastCommitSha": "a7f3d19",
402
+ "uncommittedChanges": false,
403
+ "readyForPR": false,
404
+ "prSuggested": false
405
+ }
406
+ }
407
+ ```
408
+
409
+ **If documentation was updated (architecture.md, operations.md, etc.):**
410
+
411
+ ```bash
412
+ 🔧 Documentation Commit
413
+ ---
414
+ Commit message:
415
+ docs(architecture): document WebSocket cleanup strategy
416
+
417
+ Added cleanup lifecycle documentation for WebSocket connections
418
+ to prevent memory leaks. Includes heartbeat mechanism and
419
+ connection monitoring patterns.
420
+
421
+ Files changed: 2
422
+ - docs/architecture.md
423
+ - docs/operations.md
424
+
425
+ Commit this change? (Y/n)
426
+ ```
427
+
428
+ **User confirms → Create documentation commit:**
429
+
430
+ ```bash
431
+ git add docs/
432
+ git commit -m "docs(architecture): document WebSocket cleanup strategy
433
+
434
+ Added cleanup lifecycle documentation for WebSocket connections
435
+ to prevent memory leaks. Includes heartbeat mechanism and
436
+ connection monitoring patterns."
437
+
438
+ # ✅ Committed as: b8c4e20
439
+
440
+ # Update status.json
441
+ ```
442
+
443
+ **Final Git summary and PR suggestion:**
444
+
445
+ ```bash
446
+ ---
447
+ 📦 Git Summary
448
+ ---
449
+ Branch: fix/websocket-memory-leak (from main)
450
+ Commits: 2
451
+
452
+ a7f3d19 fix(websocket): prevent memory leak on disconnect
453
+ b8c4e20 docs(architecture): document WebSocket cleanup strategy
454
+
455
+ Files changed: 5
456
+ Tests added: 3
457
+ All validations passed ✅
458
+
459
+ 🚀 Ready to create Pull Request
460
+ ---
461
+ Suggested PR command:
462
+
463
+ gh pr create \
464
+ --title "fix(websocket): Prevent memory leak on disconnect" \
465
+ --body "## Problem\n\nMemory leak in WebSocket connections causing heap to grow unbounded.\n\n## Root Cause\n\nEvent listeners and Redis subscriptions not cleaned up on disconnect.\n\n## Solution\n\n- Add removeAllListeners() on disconnect\n- Clear from activeConnections Map\n- Unsubscribe from Redis channels\n- Add heartbeat mechanism\n\n## Testing\n\n- Memory leak test (1000 connections)\n- Disconnect cleanup validation\n- Heartbeat timeout test\n\n## Impact\n\nBefore: 1.8 GB heap (crashed after 6h)\nAfter: 180 MB heap (stable)\n\nCloses #456" \
466
+ --base main
467
+
468
+ Or open in browser:
469
+ https://github.com/yourorg/yourrepo/compare/main...fix/websocket-memory-leak
470
+
471
+ ⚠️ Note: PR creation is manual. Review commits before creating PR.
472
+ ```
473
+
474
+ **Update status.json final state:**
475
+
476
+ ```json
477
+ {
478
+ "git": {
479
+ "readyForPR": true,
480
+ "prSuggested": true
481
+ }
482
+ }
483
+ ```
484
+ ---
485
+ ## Files Generated
486
+
487
+ ### Simple Bug:
488
+
489
+ ```
490
+ .ai-flow/archive/YYYY-MM/fix-[name]/
491
+ └── summary.md # Brief summary only
492
+ ```
493
+
494
+ ### Complex Bug:
495
+
496
+ ```
497
+ .ai-flow/work/fix-[name]/ # During work
498
+ ├── analysis.md # Root cause analysis
499
+ ├── solution.md # Detailed fix
500
+ ├── test-results.md # Tests + validation
501
+ └── status.json # Metadata
502
+
503
+ .ai-flow/archive/YYYY-MM/fix-[name]/ # After completion
504
+ ├── analysis.md
505
+ ├── solution.md
506
+ └── test-results.md
507
+ ```
508
+ ---
509
+ ## Complexity Detection Criteria
510
+
511
+ Use these guidelines to automatically determine complexity:
512
+
513
+ ### 🟢 SIMPLE Bug Indicators:
514
+
515
+ - Single file affected
516
+ - Clear, obvious root cause
517
+ - Straightforward fix (null check, typo, validation)
518
+ - No architectural changes needed
519
+ - Fix in <10 lines of code
520
+ - No expected side effects
521
+ - Tests already exist, just need new case
522
+
523
+ ### 🔴 COMPLEX Bug Indicators:
524
+
525
+ - Multiple files or modules affected
526
+ - Non-obvious root cause requiring investigation
527
+ - Requires refactoring or architectural changes
528
+ - Possible side effects on other functionality
529
+ - Performance or memory issues
530
+ - Security vulnerabilities
531
+ - Race conditions or concurrency issues
532
+ - Missing tests need to be written
533
+ ---
534
+ ## Git Integration
535
+
536
+ ### Overview
537
+
538
+ The `/fix` command integrates with Git to:
539
+
540
+ - Create isolated branches for **complex bugs only** (simple bugs work on current branch)
541
+ - Automatically commit fixes with **Conventional Commits** format
542
+ - Include root cause analysis in commit body
543
+ - Reference issue numbers (Closes #123)
544
+ - Suggest Pull Request creation after fix
545
+ - **Never push automatically** (always manual review)
546
+
547
+ ### When Git is Used
548
+
549
+ **Simple Bugs (1 file, obvious fix):**
550
+
551
+ - ✅ Work on current branch (no branch creation)
552
+ - ✅ Single commit after fix
553
+ - ✅ Quick workflow (~3 min)
554
+
555
+ **Complex Bugs (multiple files, investigation needed):**
556
+
557
+ - ✅ Create dedicated branch: `fix/[issue-name]`
558
+ - ✅ Commit after fix implementation
559
+ - ✅ Commit after documentation updates (if docs changed)
560
+ - ✅ Suggest PR with comprehensive description
561
+
562
+ ### Conventional Commits Format
563
+
564
+ All bug fix commits follow this structure:
565
+
566
+ ```
567
+ fix(scope): brief description of fix
568
+
569
+ Root cause: [Detailed explanation of what caused the bug]
570
+
571
+ Solution:
572
+ - [Change 1]
573
+ - [Change 2]
574
+ - [Change 3]
575
+
576
+ Testing:
577
+ - [Test 1]
578
+ - [Test 2]
579
+
580
+ Closes #[issue-number]
581
+ ```
582
+
583
+ **Commit Types:**
584
+
585
+ - `fix` - Bug fixes (always used for this command)
586
+ - `docs` - Documentation updates (if architecture/operations docs changed)
587
+ - `test` - Test-only changes (rarely)
588
+ - `perf` - Performance improvements (if fix improves performance)
589
+
590
+ **Scopes (examples):**
591
+
592
+ - `auth` - Authentication/authorization
593
+ - `api` - API endpoints
594
+ - `database` - Database queries/models
595
+ - `websocket` - WebSocket connections
596
+ - `validation` - Input validation
597
+ - `security` - Security vulnerabilities
598
+
599
+ ### Pre-Commit Validation
600
+
601
+ Before every commit, the following checks run automatically:
602
+
603
+ ```bash
604
+ 1. Lint check (npm run lint)
605
+ 2. Type check (npm run type-check or tsc --noEmit)
606
+ 3. Tests (npm test)
607
+ ```
608
+
609
+ **If validation fails:**
610
+
611
+ - Fix is NOT committed
612
+ - User sees clear error message
613
+ - Must fix validation issues before retrying
614
+ - Can skip validation with explicit confirmation (not recommended)
615
+
616
+ ### Edge Cases
617
+
618
+ #### 1. Uncommitted Changes Before Starting
619
+
620
+ ```
621
+ ⚠️ You have uncommitted changes:
622
+ M src/utils/logger.ts
623
+ M src/app.ts
624
+
625
+ Options:
626
+ 1. Stash changes (recommended): git stash
627
+ 2. Commit them first: git add . && git commit
628
+ 3. Continue anyway (not recommended)
629
+
630
+ What would you like to do? (1/2/3)
631
+ ```
632
+
633
+ #### 2. Branch Already Exists
634
+
635
+ ```
636
+ ⚠️ Branch fix/login-500 already exists.
637
+
638
+ Options:
639
+ 1. Use existing branch (recommended)
640
+ 2. Create fix/login-500-v2
641
+ 3. Delete and recreate (⚠️ loses history)
642
+
643
+ What would you like to do? (1/2/3)
644
+ ```
645
+
646
+ #### 3. Behind Remote Branch
647
+
648
+ ```
649
+ ⚠️ Your branch is behind origin/main by 3 commits.
650
+
651
+ Options:
652
+ 1. Pull latest: git pull origin main
653
+ 2. Continue anyway (may cause conflicts)
654
+ 3. Abort fix
655
+
656
+ What would you like to do? (1/2/3)
657
+ ```
658
+
659
+ #### 4. Validation Fails
660
+
661
+ ```
662
+ ❌ Pre-commit validation failed:
663
+
664
+ ✗ Lint errors:
665
+ src/auth/AuthController.ts:45:12 - Missing semicolon
666
+ src/auth/AuthController.ts:67:8 - Unused variable 'response'
667
+
668
+ Please fix these issues before committing.
669
+
670
+ Options:
671
+ 1. Fix issues and retry
672
+ 2. Skip validation (⚠️ not recommended)
673
+ 3. Abort commit
674
+
675
+ What would you like to do? (1/2/3)
676
+ ```
677
+
678
+ #### 5. Not in a Git Repository
679
+
680
+ ```
681
+ ℹ️ Not a Git repository. Skipping version control.
682
+
683
+ Continuing without Git integration...
684
+ ```
685
+
686
+ #### 6. Detached HEAD State
687
+
688
+ ```
689
+ ⚠️ You are in detached HEAD state.
690
+
691
+ Options:
692
+ 1. Create branch from current commit
693
+ 2. Checkout existing branch first
694
+ 3. Continue without Git (not recommended)
695
+
696
+ What would you like to do? (1/2/3)
697
+ ```
698
+
699
+ #### 7. Merge Conflicts
700
+
701
+ ```
702
+ ⚠️ Merge conflicts detected in fix branch.
703
+
704
+ You must resolve conflicts manually:
705
+ 1. git status (see conflicted files)
706
+ 2. Edit conflicted files
707
+ 3. git add <resolved-files>
708
+ 4. Run /fix again to continue
709
+
710
+ Abort for now? (Y/n)
711
+ ```
712
+
713
+ #### 8. No Tests Available
714
+
715
+ ```
716
+ ℹ️ No test framework detected.
717
+
718
+ Pre-commit validation will skip test execution.
719
+ Consider setting up tests to prevent regressions.
720
+
721
+ Continue? (Y/n)
722
+ ```
723
+
724
+ #### 9. Large Changeset
725
+
726
+ ```
727
+ ⚠️ Large changeset detected (47 files changed).
728
+
729
+ Consider breaking this into smaller fixes:
730
+ - Commit core fix first
731
+ - Commit refactoring separately
732
+ - Commit test additions separately
733
+
734
+ Continue with single commit? (Y/n)
735
+ ```
736
+
737
+ ### Workflow Example (Complex Bug)
738
+
739
+ ```bash
740
+ # User runs: /fix "WebSocket memory leak"
741
+
742
+ # 1. Detect complexity → COMPLEX (multiple files, investigation needed)
743
+ # 2. Prompt for branch creation:
744
+ Create Git branch? fix/websocket-memory-leak (Y/n)
745
+
746
+ # 3. User confirms → Create branch
747
+ git checkout -b fix/websocket-memory-leak
748
+
749
+ # 4. Analyze root cause...
750
+ # 5. Implement fix...
751
+ # 6. Run tests...
752
+
753
+ # 7. After fix complete → Prompt for commit:
754
+ 🔧 Git Commit
755
+ Pre-commit validation:
756
+ ✓ Lint passed
757
+ ✓ Type check passed
758
+ ✓ Tests passed
759
+
760
+ Commit message:
761
+ fix(websocket): prevent memory leak on disconnect
762
+
763
+ Root cause: Event listeners not cleaned up...
764
+ ...
765
+
766
+ Closes #456
767
+
768
+ Commit this change? (Y/n)
769
+
770
+ # 8. User confirms → Commit
771
+ git commit -m "..."
772
+ # ✅ Committed as: a7f3d19
773
+
774
+ # 9. Update documentation...
775
+
776
+ # 10. Commit documentation:
777
+ 🔧 Documentation Commit
778
+ Commit this change? (Y/n)
779
+
780
+ # 11. User confirms → Commit docs
781
+ git commit -m "docs(architecture): document WebSocket cleanup"
782
+ # ✅ Committed as: b8c4e20
783
+
784
+ # 12. Show Git summary + suggest PR:
785
+ 📦 Git Summary
786
+ Branch: fix/websocket-memory-leak
787
+ Commits: 2
788
+ a7f3d19 fix(websocket): prevent memory leak on disconnect
789
+ b8c4e20 docs(architecture): document WebSocket cleanup
790
+
791
+ 🚀 Ready to create Pull Request
792
+ gh pr create --title "fix(websocket): Prevent memory leak" ...
793
+ ```
794
+
795
+ ### Configuration
796
+
797
+ Git integration can be configured in `.ai-flow/core/config.json`:
798
+
799
+ ```json
800
+ {
801
+ "git": {
802
+ "enabled": true,
803
+ "autoCommit": "end",
804
+ "branchPrefix": "fix/",
805
+ "requireTests": true,
806
+ "requireLint": true,
807
+ "allowSkipValidation": false,
808
+ "autoPush": false
809
+ }
810
+ }
811
+ ```
812
+
813
+ **Options:**
814
+
815
+ - `enabled` - Enable/disable Git integration (default: true)
816
+ - `autoCommit` - When to commit: "end" = after fix, "off" = manual only
817
+ - `branchPrefix` - Prefix for fix branches (default: "fix/")
818
+ - `requireTests` - Fail if tests don't pass (default: true)
819
+ - `requireLint` - Fail if lint errors exist (default: true)
820
+ - `allowSkipValidation` - Allow skipping validation (default: false)
821
+ - `autoPush` - **Never enable** (default: false, not recommended)
822
+
823
+ ### Commit Message Style
824
+
825
+ **Good commit message:**
826
+
827
+ ```
828
+ fix(auth): prevent JWT token expiry race condition
829
+
830
+ Root cause: Token refresh logic had race condition where multiple
831
+ concurrent requests could refresh token simultaneously, causing
832
+ some requests to use expired tokens.
833
+
834
+ Solution:
835
+ - Add token refresh mutex to prevent concurrent refreshes
836
+ - Implement exponential backoff for refresh retries
837
+ - Add token cache with 30-second buffer before expiry
838
+
839
+ Testing:
840
+ - Load test with 100 concurrent requests
841
+ - Token expiry simulation test
842
+ - Refresh retry test
843
+
844
+ Closes #789
845
+ ```
846
+
847
+ **Bad commit message:**
848
+
849
+ ```
850
+ fix: fixed bug
851
+ ```
852
+
853
+ **Why good messages matter:**
854
+
855
+ - Future developers understand WHY the fix was needed
856
+ - Easier code archaeology (git blame)
857
+ - Better PR reviews
858
+ - Helps prevent similar bugs
859
+ ---
860
+ ## Important Rules
861
+
862
+ ### 1. Always Analyze First
863
+
864
+ - Never assume - always read the relevant code
865
+ - Identify exact root cause before proposing fix
866
+ - Consider side effects and edge cases
867
+
868
+ ### 2. Add Tests
869
+
870
+ - Every bug fix MUST include a test
871
+ - Test should reproduce the bug before fix
872
+ - Test should pass after fix
873
+ - Prevents regression
874
+
875
+ ### 3. Minimal Changes
876
+
877
+ - Fix only what's necessary
878
+ - Don't refactor unrelated code
879
+ - Keep scope focused on the bug
880
+
881
+ ### 4. Clear Communication
882
+
883
+ - Explain root cause clearly
884
+ - Show before/after code
885
+ - Specify what tests were added
886
+ ---
887
+ ## Example Outputs
888
+
889
+ ### Simple Bug Complete:
890
+
891
+ ```
892
+ ✅ BUG FIXED
893
+
894
+ Root cause: Missing null check in AuthController.login()
895
+ Files changed: 1 (AuthController.ts)
896
+ Tests added: 1
897
+ Time: 3 minutes
898
+ ```
899
+
900
+ ### Complex Bug Complete:
901
+
902
+ ```
903
+ ✅ BUG FIXED
904
+
905
+ Root cause: WebSocket connections not cleaned up on disconnect
906
+ Files changed: 3
907
+ - src/websocket/notificationSocket.ts (major refactor)
908
+ - src/app.ts (cleanup logic)
909
+ - src/services/ConnectionManager.ts (new service)
910
+
911
+ Tests added: 5
912
+ - Memory leak test
913
+ - Load test (1000 connections)
914
+ - Heartbeat test
915
+ - Disconnect cleanup test
916
+ - Connection monitoring test
917
+
918
+ Impact:
919
+ - Before: 1.8 GB heap (crashed after 6h)
920
+ - After: 180 MB heap (stable)
921
+
922
+ 📦 Work archived with complete analysis
923
+ Time: 14 minutes
924
+ ```
925
+ ---
926
+ ## Auto-Archive Process
927
+
928
+ ### For Simple Bugs:
929
+
930
+ 1. Create summary in archive folder
931
+ 2. No documentation update needed (unless API changed)
932
+ 3. Quick archival
933
+
934
+ ### For Complex Bugs:
935
+
936
+ 1. Move all work files to archive
937
+ 2. Update relevant documentation:
938
+ - `docs/architecture.md` if architecture changed
939
+ - `docs/api.md` if API behavior changed
940
+ - `specs/security.md` if security fix
941
+ 3. Include metrics and test results
942
+ 4. Generate comprehensive summary
943
+ ---
944
+ **BEGIN EXECUTION when user runs `/fix` or `/fix "description"`**
945
+
946
+
947
+
948
+