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