ai-flow-dev 1.0.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 (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +408 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +791 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/fs-utils.d.ts +2 -0
  8. package/dist/fs-utils.d.ts.map +1 -0
  9. package/dist/fs-utils.js +46 -0
  10. package/dist/fs-utils.js.map +1 -0
  11. package/package.json +71 -0
  12. package/prompts/backend/flow-dev-feature.md +1318 -0
  13. package/prompts/backend/flow-dev-fix.md +903 -0
  14. package/prompts/backend/flow-dev-refactor.md +715 -0
  15. package/prompts/backend/flow-dev-review.md +401 -0
  16. package/prompts/backend/flow-dev-work.md +1129 -0
  17. package/prompts/backend/flow-docs-gen-phase-0.md +1840 -0
  18. package/prompts/backend/flow-docs-gen-phase-1.md +435 -0
  19. package/prompts/backend/flow-docs-gen-phase-2.md +460 -0
  20. package/prompts/backend/flow-docs-gen-phase-3.md +684 -0
  21. package/prompts/backend/flow-docs-gen-phase-4.md +516 -0
  22. package/prompts/backend/flow-docs-gen-phase-5.md +637 -0
  23. package/prompts/backend/flow-docs-gen-phase-6.md +465 -0
  24. package/prompts/backend/flow-docs-gen-phase-7.md +1207 -0
  25. package/prompts/backend/flow-docs-gen.md +820 -0
  26. package/prompts/backend/flow-docs-sync.md +526 -0
  27. package/prompts/backend/flow-project-init.md +248 -0
  28. package/prompts/backend/flow-project-roadmap.md +1159 -0
  29. package/prompts/frontend/flow-docs-gen-phase-0.md +494 -0
  30. package/prompts/frontend/flow-docs-gen-phase-1.md +449 -0
  31. package/prompts/frontend/flow-docs-gen-phase-2.md +983 -0
  32. package/prompts/frontend/flow-docs-gen-phase-3.md +685 -0
  33. package/prompts/frontend/flow-docs-gen-phase-4.md +480 -0
  34. package/prompts/frontend/flow-docs-gen-phase-5.md +483 -0
  35. package/prompts/frontend/flow-docs-gen-phase-6.md +570 -0
  36. package/prompts/frontend/flow-docs-gen-phase-7.md +582 -0
  37. package/prompts/frontend/flow-docs-gen.md +413 -0
  38. package/prompts/frontend/flow-docs-sync.md +561 -0
  39. package/prompts/mobile/flow-docs-gen-phase-0.md +387 -0
  40. package/prompts/mobile/flow-docs-gen-phase-1.md +530 -0
  41. package/prompts/mobile/flow-docs-gen-phase-2.md +584 -0
  42. package/prompts/mobile/flow-docs-gen-phase-3.md +659 -0
  43. package/prompts/mobile/flow-docs-gen-phase-4.md +363 -0
  44. package/prompts/mobile/flow-docs-gen-phase-5.md +369 -0
  45. package/prompts/mobile/flow-docs-gen-phase-6.md +490 -0
  46. package/prompts/mobile/flow-docs-gen-phase-7.md +407 -0
  47. package/prompts/mobile/flow-docs-gen.md +430 -0
  48. package/prompts/mobile/flow-docs-sync.md +634 -0
  49. package/templates/backend/.clauderules.template +111 -0
  50. package/templates/backend/.cursorrules.template +102 -0
  51. package/templates/backend/.env.example.template +122 -0
  52. package/templates/backend/README.template.md +200 -0
  53. package/templates/backend/ai-instructions.template.md +354 -0
  54. package/templates/backend/copilot-instructions.template.md +160 -0
  55. package/templates/backend/docs/api.template.md +251 -0
  56. package/templates/backend/docs/architecture.template.md +612 -0
  57. package/templates/backend/docs/business-flows.template.md +109 -0
  58. package/templates/backend/docs/code-standards.template.md +828 -0
  59. package/templates/backend/docs/contributing.template.md +163 -0
  60. package/templates/backend/docs/data-model.template.md +416 -0
  61. package/templates/backend/docs/operations.template.md +591 -0
  62. package/templates/backend/docs/testing.template.md +762 -0
  63. package/templates/backend/project-brief.template.md +176 -0
  64. package/templates/backend/specs/configuration.template.md +133 -0
  65. package/templates/backend/specs/security.template.md +422 -0
  66. package/templates/frontend/README.template.md +121 -0
  67. package/templates/frontend/ai-instructions.template.md +368 -0
  68. package/templates/frontend/docs/api-integration.template.md +390 -0
  69. package/templates/frontend/docs/components.template.md +567 -0
  70. package/templates/frontend/docs/error-handling.template.md +385 -0
  71. package/templates/frontend/docs/operations.template.md +123 -0
  72. package/templates/frontend/docs/performance.template.md +140 -0
  73. package/templates/frontend/docs/pwa.template.md +135 -0
  74. package/templates/frontend/docs/state-management.template.md +394 -0
  75. package/templates/frontend/docs/styling.template.md +779 -0
  76. package/templates/frontend/docs/testing.template.md +736 -0
  77. package/templates/frontend/project-brief.template.md +55 -0
  78. package/templates/frontend/specs/accessibility.template.md +111 -0
  79. package/templates/frontend/specs/configuration.template.md +520 -0
  80. package/templates/frontend/specs/security.template.md +197 -0
  81. package/templates/fullstack/README.template.md +282 -0
  82. package/templates/fullstack/ai-instructions.template.md +487 -0
  83. package/templates/fullstack/project-brief.template.md +197 -0
  84. package/templates/fullstack/specs/configuration.template.md +380 -0
  85. package/templates/mobile/AGENT.template.md +251 -0
  86. package/templates/mobile/README.template.md +195 -0
  87. package/templates/mobile/ai-instructions.template.md +221 -0
  88. package/templates/mobile/docs/app-store.template.md +163 -0
  89. package/templates/mobile/docs/architecture.template.md +100 -0
  90. package/templates/mobile/docs/native-features.template.md +137 -0
  91. package/templates/mobile/docs/navigation.template.md +81 -0
  92. package/templates/mobile/docs/offline-strategy.template.md +90 -0
  93. package/templates/mobile/docs/permissions.template.md +70 -0
  94. package/templates/mobile/docs/state-management.template.md +116 -0
  95. package/templates/mobile/docs/testing.template.md +146 -0
  96. package/templates/mobile/project-brief.template.md +97 -0
  97. package/templates/mobile/specs/build-configuration.template.md +116 -0
  98. package/templates/mobile/specs/deployment.template.md +114 -0
  99. package/templates/shared/AGENT.template.md +252 -0
@@ -0,0 +1,903 @@
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
+
7
+ ---
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
+
23
+ ---
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
+
42
+ ---
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
+
110
+ ---
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
+
205
+ ---
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
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
+ Fix plan:
243
+ 1. Add socket.removeAllListeners() on disconnect
244
+ 2. Delete from activeConnections Map on disconnect
245
+ 3. Call redisClient.unsubscribe() on disconnect
246
+ 4. Add heartbeat mechanism
247
+ 5. Add connection monitoring
248
+
249
+ Proceed with fix? (Y/n)
250
+ ```
251
+
252
+ **After implementing fix:**
253
+
254
+ ```bash
255
+ # ✅ Fix implementation complete
256
+
257
+ 🔧 Git Commit
258
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
259
+
260
+ Pre-commit validation:
261
+ ✓ Lint passed
262
+ ✓ Type check passed
263
+ ✓ Tests passed (3 new, 45 total)
264
+
265
+ Ready to commit changes:
266
+
267
+ Commit message:
268
+ fix(websocket): prevent memory leak on disconnect
269
+
270
+ Root cause: Event listeners and Redis subscriptions were not being
271
+ cleaned up when WebSocket connections closed, causing heap to grow
272
+ unbounded over time.
273
+
274
+ Solution:
275
+ - Add removeAllListeners() on disconnect
276
+ - Clear from activeConnections Map
277
+ - Unsubscribe from Redis channels
278
+ - Add heartbeat mechanism for stale detection
279
+
280
+ Tests:
281
+ - Memory leak test (1000 connections)
282
+ - Disconnect cleanup validation
283
+ - Heartbeat timeout test
284
+
285
+ Closes #456
286
+
287
+ Files changed: 3
288
+ - src/websocket/notificationSocket.ts
289
+ - src/app.ts
290
+ - src/services/ConnectionManager.ts
291
+
292
+ Commit this change? (Y/n)
293
+ ```
294
+
295
+ **User confirms → Create commit:**
296
+
297
+ ```bash
298
+ git add src/websocket/ src/app.ts src/services/
299
+ git commit -m "fix(websocket): prevent memory leak on disconnect
300
+
301
+ Root cause: Event listeners and Redis subscriptions were not being
302
+ cleaned up when WebSocket connections closed, causing heap to grow
303
+ unbounded over time.
304
+
305
+ Solution:
306
+ - Add removeAllListeners() on disconnect
307
+ - Clear from activeConnections Map
308
+ - Unsubscribe from Redis channels
309
+ - Add heartbeat mechanism for stale detection
310
+
311
+ Tests:
312
+ - Memory leak test (1000 connections)
313
+ - Disconnect cleanup validation
314
+ - Heartbeat timeout test
315
+
316
+ Closes #456"
317
+
318
+ # ✅ Committed as: a7f3d19
319
+ ```
320
+
321
+ **Update status.json:**
322
+
323
+ ```json
324
+ {
325
+ "git": {
326
+ "enabled": true,
327
+ "autoCommit": "end",
328
+ "branchCreated": true,
329
+ "branchName": "fix/websocket-memory-leak",
330
+ "sourceBranch": "main",
331
+ "commits": [
332
+ {
333
+ "sha": "a7f3d19",
334
+ "type": "fix",
335
+ "scope": "websocket",
336
+ "message": "prevent memory leak on disconnect",
337
+ "phase": "fix-implementation",
338
+ "timestamp": "2025-12-04T14:30:00Z",
339
+ "filesChanged": 3
340
+ }
341
+ ],
342
+ "lastCommitSha": "a7f3d19",
343
+ "uncommittedChanges": false,
344
+ "readyForPR": false,
345
+ "prSuggested": false
346
+ }
347
+ }
348
+ ```
349
+
350
+ **If documentation was updated (architecture.md, operations.md, etc.):**
351
+
352
+ ```bash
353
+ 🔧 Documentation Commit
354
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
355
+
356
+ Commit message:
357
+ docs(architecture): document WebSocket cleanup strategy
358
+
359
+ Added cleanup lifecycle documentation for WebSocket connections
360
+ to prevent memory leaks. Includes heartbeat mechanism and
361
+ connection monitoring patterns.
362
+
363
+ Files changed: 2
364
+ - docs/architecture.md
365
+ - docs/operations.md
366
+
367
+ Commit this change? (Y/n)
368
+ ```
369
+
370
+ **User confirms → Create documentation commit:**
371
+
372
+ ```bash
373
+ git add docs/
374
+ git commit -m "docs(architecture): document WebSocket cleanup strategy
375
+
376
+ Added cleanup lifecycle documentation for WebSocket connections
377
+ to prevent memory leaks. Includes heartbeat mechanism and
378
+ connection monitoring patterns."
379
+
380
+ # ✅ Committed as: b8c4e20
381
+
382
+ # Update status.json
383
+ ```
384
+
385
+ **Final Git summary and PR suggestion:**
386
+
387
+ ```bash
388
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
389
+ 📦 Git Summary
390
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
391
+
392
+ Branch: fix/websocket-memory-leak (from main)
393
+ Commits: 2
394
+
395
+ a7f3d19 fix(websocket): prevent memory leak on disconnect
396
+ b8c4e20 docs(architecture): document WebSocket cleanup strategy
397
+
398
+ Files changed: 5
399
+ Tests added: 3
400
+ All validations passed ✅
401
+
402
+ 🚀 Ready to create Pull Request
403
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
404
+
405
+ Suggested PR command:
406
+
407
+ gh pr create \
408
+ --title "fix(websocket): Prevent memory leak on disconnect" \
409
+ --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" \
410
+ --base main
411
+
412
+ Or open in browser:
413
+ https://github.com/yourorg/yourrepo/compare/main...fix/websocket-memory-leak
414
+
415
+ ⚠️ Note: PR creation is manual. Review commits before creating PR.
416
+ ```
417
+
418
+ **Update status.json final state:**
419
+
420
+ ```json
421
+ {
422
+ "git": {
423
+ "readyForPR": true,
424
+ "prSuggested": true
425
+ }
426
+ }
427
+ ```
428
+
429
+ ---
430
+
431
+ ## Files Generated
432
+
433
+ ### Simple Bug:
434
+
435
+ ```
436
+ .ai-flow/archive/YYYY-MM/fix-[name]/
437
+ └── summary.md # Brief summary only
438
+ ```
439
+
440
+ ### Complex Bug:
441
+
442
+ ```
443
+ .ai-flow/work/fix-[name]/ # During work
444
+ ├── analysis.md # Root cause analysis
445
+ ├── solution.md # Detailed fix
446
+ ├── test-results.md # Tests + validation
447
+ └── status.json # Metadata
448
+
449
+ .ai-flow/archive/YYYY-MM/fix-[name]/ # After completion
450
+ ├── analysis.md
451
+ ├── solution.md
452
+ └── test-results.md
453
+ ```
454
+
455
+ ---
456
+
457
+ ## Complexity Detection Criteria
458
+
459
+ Use these guidelines to automatically determine complexity:
460
+
461
+ ### 🟢 SIMPLE Bug Indicators:
462
+
463
+ - Single file affected
464
+ - Clear, obvious root cause
465
+ - Straightforward fix (null check, typo, validation)
466
+ - No architectural changes needed
467
+ - Fix in <10 lines of code
468
+ - No expected side effects
469
+ - Tests already exist, just need new case
470
+
471
+ ### 🔴 COMPLEX Bug Indicators:
472
+
473
+ - Multiple files or modules affected
474
+ - Non-obvious root cause requiring investigation
475
+ - Requires refactoring or architectural changes
476
+ - Possible side effects on other functionality
477
+ - Performance or memory issues
478
+ - Security vulnerabilities
479
+ - Race conditions or concurrency issues
480
+ - Missing tests need to be written
481
+
482
+ ---
483
+
484
+ ## Git Integration
485
+
486
+ ### Overview
487
+
488
+ The `/fix` command integrates with Git to:
489
+
490
+ - Create isolated branches for **complex bugs only** (simple bugs work on current branch)
491
+ - Automatically commit fixes with **Conventional Commits** format
492
+ - Include root cause analysis in commit body
493
+ - Reference issue numbers (Closes #123)
494
+ - Suggest Pull Request creation after fix
495
+ - **Never push automatically** (always manual review)
496
+
497
+ ### When Git is Used
498
+
499
+ **Simple Bugs (1 file, obvious fix):**
500
+
501
+ - ✅ Work on current branch (no branch creation)
502
+ - ✅ Single commit after fix
503
+ - ✅ Quick workflow (~3 min)
504
+
505
+ **Complex Bugs (multiple files, investigation needed):**
506
+
507
+ - ✅ Create dedicated branch: `fix/[issue-name]`
508
+ - ✅ Commit after fix implementation
509
+ - ✅ Commit after documentation updates (if docs changed)
510
+ - ✅ Suggest PR with comprehensive description
511
+
512
+ ### Conventional Commits Format
513
+
514
+ All bug fix commits follow this structure:
515
+
516
+ ```
517
+ fix(scope): brief description of fix
518
+
519
+ Root cause: [Detailed explanation of what caused the bug]
520
+
521
+ Solution:
522
+ - [Change 1]
523
+ - [Change 2]
524
+ - [Change 3]
525
+
526
+ Testing:
527
+ - [Test 1]
528
+ - [Test 2]
529
+
530
+ Closes #[issue-number]
531
+ ```
532
+
533
+ **Commit Types:**
534
+
535
+ - `fix` - Bug fixes (always used for this command)
536
+ - `docs` - Documentation updates (if architecture/operations docs changed)
537
+ - `test` - Test-only changes (rarely)
538
+ - `perf` - Performance improvements (if fix improves performance)
539
+
540
+ **Scopes (examples):**
541
+
542
+ - `auth` - Authentication/authorization
543
+ - `api` - API endpoints
544
+ - `database` - Database queries/models
545
+ - `websocket` - WebSocket connections
546
+ - `validation` - Input validation
547
+ - `security` - Security vulnerabilities
548
+
549
+ ### Pre-Commit Validation
550
+
551
+ Before every commit, the following checks run automatically:
552
+
553
+ ```bash
554
+ 1. Lint check (npm run lint)
555
+ 2. Type check (npm run type-check or tsc --noEmit)
556
+ 3. Tests (npm test)
557
+ ```
558
+
559
+ **If validation fails:**
560
+
561
+ - Fix is NOT committed
562
+ - User sees clear error message
563
+ - Must fix validation issues before retrying
564
+ - Can skip validation with explicit confirmation (not recommended)
565
+
566
+ ### Edge Cases
567
+
568
+ #### 1. Uncommitted Changes Before Starting
569
+
570
+ ```
571
+ ⚠️ You have uncommitted changes:
572
+ M src/utils/logger.ts
573
+ M src/app.ts
574
+
575
+ Options:
576
+ 1. Stash changes (recommended): git stash
577
+ 2. Commit them first: git add . && git commit
578
+ 3. Continue anyway (not recommended)
579
+
580
+ What would you like to do? (1/2/3)
581
+ ```
582
+
583
+ #### 2. Branch Already Exists
584
+
585
+ ```
586
+ ⚠️ Branch fix/login-500 already exists.
587
+
588
+ Options:
589
+ 1. Use existing branch (recommended)
590
+ 2. Create fix/login-500-v2
591
+ 3. Delete and recreate (⚠️ loses history)
592
+
593
+ What would you like to do? (1/2/3)
594
+ ```
595
+
596
+ #### 3. Behind Remote Branch
597
+
598
+ ```
599
+ ⚠️ Your branch is behind origin/main by 3 commits.
600
+
601
+ Options:
602
+ 1. Pull latest: git pull origin main
603
+ 2. Continue anyway (may cause conflicts)
604
+ 3. Abort fix
605
+
606
+ What would you like to do? (1/2/3)
607
+ ```
608
+
609
+ #### 4. Validation Fails
610
+
611
+ ```
612
+ ❌ Pre-commit validation failed:
613
+
614
+ ✗ Lint errors:
615
+ src/auth/AuthController.ts:45:12 - Missing semicolon
616
+ src/auth/AuthController.ts:67:8 - Unused variable 'response'
617
+
618
+ Please fix these issues before committing.
619
+
620
+ Options:
621
+ 1. Fix issues and retry
622
+ 2. Skip validation (⚠️ not recommended)
623
+ 3. Abort commit
624
+
625
+ What would you like to do? (1/2/3)
626
+ ```
627
+
628
+ #### 5. Not in a Git Repository
629
+
630
+ ```
631
+ ℹ️ Not a Git repository. Skipping version control.
632
+
633
+ Continuing without Git integration...
634
+ ```
635
+
636
+ #### 6. Detached HEAD State
637
+
638
+ ```
639
+ ⚠️ You are in detached HEAD state.
640
+
641
+ Options:
642
+ 1. Create branch from current commit
643
+ 2. Checkout existing branch first
644
+ 3. Continue without Git (not recommended)
645
+
646
+ What would you like to do? (1/2/3)
647
+ ```
648
+
649
+ #### 7. Merge Conflicts
650
+
651
+ ```
652
+ ⚠️ Merge conflicts detected in fix branch.
653
+
654
+ You must resolve conflicts manually:
655
+ 1. git status (see conflicted files)
656
+ 2. Edit conflicted files
657
+ 3. git add <resolved-files>
658
+ 4. Run /fix again to continue
659
+
660
+ Abort for now? (Y/n)
661
+ ```
662
+
663
+ #### 8. No Tests Available
664
+
665
+ ```
666
+ ℹ️ No test framework detected.
667
+
668
+ Pre-commit validation will skip test execution.
669
+ Consider setting up tests to prevent regressions.
670
+
671
+ Continue? (Y/n)
672
+ ```
673
+
674
+ #### 9. Large Changeset
675
+
676
+ ```
677
+ ⚠️ Large changeset detected (47 files changed).
678
+
679
+ Consider breaking this into smaller fixes:
680
+ - Commit core fix first
681
+ - Commit refactoring separately
682
+ - Commit test additions separately
683
+
684
+ Continue with single commit? (Y/n)
685
+ ```
686
+
687
+ ### Workflow Example (Complex Bug)
688
+
689
+ ```bash
690
+ # User runs: /fix "WebSocket memory leak"
691
+
692
+ # 1. Detect complexity → COMPLEX (multiple files, investigation needed)
693
+ # 2. Prompt for branch creation:
694
+ Create Git branch? fix/websocket-memory-leak (Y/n)
695
+
696
+ # 3. User confirms → Create branch
697
+ git checkout -b fix/websocket-memory-leak
698
+
699
+ # 4. Analyze root cause...
700
+ # 5. Implement fix...
701
+ # 6. Run tests...
702
+
703
+ # 7. After fix complete → Prompt for commit:
704
+ 🔧 Git Commit
705
+ Pre-commit validation:
706
+ ✓ Lint passed
707
+ ✓ Type check passed
708
+ ✓ Tests passed
709
+
710
+ Commit message:
711
+ fix(websocket): prevent memory leak on disconnect
712
+
713
+ Root cause: Event listeners not cleaned up...
714
+ ...
715
+
716
+ Closes #456
717
+
718
+ Commit this change? (Y/n)
719
+
720
+ # 8. User confirms → Commit
721
+ git commit -m "..."
722
+ # ✅ Committed as: a7f3d19
723
+
724
+ # 9. Update documentation...
725
+
726
+ # 10. Commit documentation:
727
+ 🔧 Documentation Commit
728
+ Commit this change? (Y/n)
729
+
730
+ # 11. User confirms → Commit docs
731
+ git commit -m "docs(architecture): document WebSocket cleanup"
732
+ # ✅ Committed as: b8c4e20
733
+
734
+ # 12. Show Git summary + suggest PR:
735
+ 📦 Git Summary
736
+ Branch: fix/websocket-memory-leak
737
+ Commits: 2
738
+ a7f3d19 fix(websocket): prevent memory leak on disconnect
739
+ b8c4e20 docs(architecture): document WebSocket cleanup
740
+
741
+ 🚀 Ready to create Pull Request
742
+ gh pr create --title "fix(websocket): Prevent memory leak" ...
743
+ ```
744
+
745
+ ### Configuration
746
+
747
+ Git integration can be configured in `.ai-flow/core/config.json`:
748
+
749
+ ```json
750
+ {
751
+ "git": {
752
+ "enabled": true,
753
+ "autoCommit": "end",
754
+ "branchPrefix": "fix/",
755
+ "requireTests": true,
756
+ "requireLint": true,
757
+ "allowSkipValidation": false,
758
+ "autoPush": false
759
+ }
760
+ }
761
+ ```
762
+
763
+ **Options:**
764
+
765
+ - `enabled` - Enable/disable Git integration (default: true)
766
+ - `autoCommit` - When to commit: "end" = after fix, "off" = manual only
767
+ - `branchPrefix` - Prefix for fix branches (default: "fix/")
768
+ - `requireTests` - Fail if tests don't pass (default: true)
769
+ - `requireLint` - Fail if lint errors exist (default: true)
770
+ - `allowSkipValidation` - Allow skipping validation (default: false)
771
+ - `autoPush` - **Never enable** (default: false, not recommended)
772
+
773
+ ### Commit Message Style
774
+
775
+ **Good commit message:**
776
+
777
+ ```
778
+ fix(auth): prevent JWT token expiry race condition
779
+
780
+ Root cause: Token refresh logic had race condition where multiple
781
+ concurrent requests could refresh token simultaneously, causing
782
+ some requests to use expired tokens.
783
+
784
+ Solution:
785
+ - Add token refresh mutex to prevent concurrent refreshes
786
+ - Implement exponential backoff for refresh retries
787
+ - Add token cache with 30-second buffer before expiry
788
+
789
+ Testing:
790
+ - Load test with 100 concurrent requests
791
+ - Token expiry simulation test
792
+ - Refresh retry test
793
+
794
+ Closes #789
795
+ ```
796
+
797
+ **Bad commit message:**
798
+
799
+ ```
800
+ fix: fixed bug
801
+ ```
802
+
803
+ **Why good messages matter:**
804
+
805
+ - Future developers understand WHY the fix was needed
806
+ - Easier code archaeology (git blame)
807
+ - Better PR reviews
808
+ - Helps prevent similar bugs
809
+
810
+ ---
811
+
812
+ ## Important Rules
813
+
814
+ ### 1. Always Analyze First
815
+
816
+ - Never assume - always read the relevant code
817
+ - Identify exact root cause before proposing fix
818
+ - Consider side effects and edge cases
819
+
820
+ ### 2. Add Tests
821
+
822
+ - Every bug fix MUST include a test
823
+ - Test should reproduce the bug before fix
824
+ - Test should pass after fix
825
+ - Prevents regression
826
+
827
+ ### 3. Minimal Changes
828
+
829
+ - Fix only what's necessary
830
+ - Don't refactor unrelated code
831
+ - Keep scope focused on the bug
832
+
833
+ ### 4. Clear Communication
834
+
835
+ - Explain root cause clearly
836
+ - Show before/after code
837
+ - Specify what tests were added
838
+
839
+ ---
840
+
841
+ ## Example Outputs
842
+
843
+ ### Simple Bug Complete:
844
+
845
+ ```
846
+ ✅ BUG FIXED
847
+
848
+ Root cause: Missing null check in AuthController.login()
849
+ Files changed: 1 (AuthController.ts)
850
+ Tests added: 1
851
+ Time: 3 minutes
852
+ ```
853
+
854
+ ### Complex Bug Complete:
855
+
856
+ ```
857
+ ✅ BUG FIXED
858
+
859
+ Root cause: WebSocket connections not cleaned up on disconnect
860
+ Files changed: 3
861
+ - src/websocket/notificationSocket.ts (major refactor)
862
+ - src/app.ts (cleanup logic)
863
+ - src/services/ConnectionManager.ts (new service)
864
+
865
+ Tests added: 5
866
+ - Memory leak test
867
+ - Load test (1000 connections)
868
+ - Heartbeat test
869
+ - Disconnect cleanup test
870
+ - Connection monitoring test
871
+
872
+ Impact:
873
+ - Before: 1.8 GB heap (crashed after 6h)
874
+ - After: 180 MB heap (stable)
875
+
876
+ 📦 Work archived with complete analysis
877
+ Time: 14 minutes
878
+ ```
879
+
880
+ ---
881
+
882
+ ## Auto-Archive Process
883
+
884
+ ### For Simple Bugs:
885
+
886
+ 1. Create summary in archive folder
887
+ 2. No documentation update needed (unless API changed)
888
+ 3. Quick archival
889
+
890
+ ### For Complex Bugs:
891
+
892
+ 1. Move all work files to archive
893
+ 2. Update relevant documentation:
894
+ - `docs/architecture.md` if architecture changed
895
+ - `docs/api.md` if API behavior changed
896
+ - `specs/security.md` if security fix
897
+ 3. Include metrics and test results
898
+ 4. Generate comprehensive summary
899
+
900
+ ---
901
+
902
+ **BEGIN EXECUTION when user runs `/fix` or `/fix "description"`**
903
+