ai-sprint-kit 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +299 -0
  2. package/bin/cli.js +135 -0
  3. package/lib/installer.js +205 -0
  4. package/lib/scanner.js +341 -0
  5. package/package.json +55 -0
  6. package/templates/.claude/.env.example +13 -0
  7. package/templates/.claude/agents/debugger.md +667 -0
  8. package/templates/.claude/agents/devops.md +727 -0
  9. package/templates/.claude/agents/docs.md +661 -0
  10. package/templates/.claude/agents/implementer.md +235 -0
  11. package/templates/.claude/agents/planner.md +243 -0
  12. package/templates/.claude/agents/researcher.md +448 -0
  13. package/templates/.claude/agents/reviewer.md +610 -0
  14. package/templates/.claude/agents/security.md +202 -0
  15. package/templates/.claude/agents/tester.md +604 -0
  16. package/templates/.claude/commands/auto.md +85 -0
  17. package/templates/.claude/commands/code.md +301 -0
  18. package/templates/.claude/commands/debug.md +449 -0
  19. package/templates/.claude/commands/deploy.md +475 -0
  20. package/templates/.claude/commands/docs.md +519 -0
  21. package/templates/.claude/commands/plan.md +57 -0
  22. package/templates/.claude/commands/review.md +412 -0
  23. package/templates/.claude/commands/scan.md +146 -0
  24. package/templates/.claude/commands/secure.md +88 -0
  25. package/templates/.claude/commands/test.md +352 -0
  26. package/templates/.claude/commands/validate.md +238 -0
  27. package/templates/.claude/settings.json +27 -0
  28. package/templates/.claude/skills/codebase-context/SKILL.md +68 -0
  29. package/templates/.claude/skills/codebase-context/references/reading-context.md +68 -0
  30. package/templates/.claude/skills/codebase-context/references/refresh-triggers.md +82 -0
  31. package/templates/.claude/skills/implementation/SKILL.md +70 -0
  32. package/templates/.claude/skills/implementation/references/error-handling.md +106 -0
  33. package/templates/.claude/skills/implementation/references/security-patterns.md +73 -0
  34. package/templates/.claude/skills/implementation/references/validation-patterns.md +107 -0
  35. package/templates/.claude/skills/memory/SKILL.md +67 -0
  36. package/templates/.claude/skills/memory/references/decisions-format.md +68 -0
  37. package/templates/.claude/skills/memory/references/learning-format.md +74 -0
  38. package/templates/.claude/skills/planning/SKILL.md +72 -0
  39. package/templates/.claude/skills/planning/references/plan-templates.md +81 -0
  40. package/templates/.claude/skills/planning/references/research-phase.md +62 -0
  41. package/templates/.claude/skills/planning/references/solution-design.md +66 -0
  42. package/templates/.claude/skills/quality-assurance/SKILL.md +79 -0
  43. package/templates/.claude/skills/quality-assurance/references/review-checklist.md +72 -0
  44. package/templates/.claude/skills/quality-assurance/references/security-checklist.md +70 -0
  45. package/templates/.claude/skills/quality-assurance/references/testing-strategy.md +85 -0
  46. package/templates/.claude/statusline.sh +126 -0
  47. package/templates/.claude/workflows/development-rules.md +97 -0
  48. package/templates/.claude/workflows/orchestration-protocol.md +194 -0
  49. package/templates/.mcp.json.example +36 -0
  50. package/templates/CLAUDE.md +409 -0
  51. package/templates/README.md +331 -0
  52. package/templates/ai_context/codebase/.gitkeep +0 -0
  53. package/templates/ai_context/memory/active.md +15 -0
  54. package/templates/ai_context/memory/decisions.md +18 -0
  55. package/templates/ai_context/memory/learning.md +22 -0
  56. package/templates/ai_context/plans/.gitkeep +0 -0
  57. package/templates/ai_context/reports/.gitkeep +0 -0
  58. package/templates/docs/user-guide-th.md +454 -0
  59. package/templates/docs/user-guide.md +595 -0
@@ -0,0 +1,449 @@
1
+ ---
2
+ description: Investigate and fix bugs with root cause analysis
3
+ argument-hint: [bug description or error message]
4
+ ---
5
+
6
+ ## Command: /debug
7
+
8
+ Systematically investigate bugs, perform root cause analysis, and provide fixes with regression tests.
9
+
10
+ ## Usage
11
+
12
+ ```
13
+ /debug "users can't login"
14
+ /debug "500 error on checkout"
15
+ /debug "memory leak in WebSocket handler"
16
+ /debug "database query is slow"
17
+ ```
18
+
19
+ ## Workflow
20
+
21
+ ### 0. Initialize Context
22
+ - Get timestamp: `date "+%y%m%d-%H%M"` (DO NOT guess dates)
23
+ - Check `ai_context/memory/learning.md` for known bug patterns
24
+
25
+ ### 1. Understand the Problem
26
+ - What's the expected behavior?
27
+ - What's the actual behavior?
28
+ - When did it start?
29
+ - Can it be reproduced?
30
+ - Any error messages/stack traces?
31
+
32
+ ### 2. Reproduce the Bug
33
+ - Find minimal reproduction steps
34
+ - Document exact conditions
35
+ - Identify patterns (timing, data, environment)
36
+
37
+ ### 3. Investigate Root Cause
38
+ - Analyze error messages
39
+ - Check logs (app, server, database)
40
+ - Review recent changes
41
+ - Use debugging tools
42
+
43
+ ### 4. Fix the Bug
44
+ - Implement minimal fix
45
+ - Test thoroughly
46
+ - Add regression test
47
+ - Document the fix
48
+
49
+ ## Debugging Process
50
+
51
+ ### Phase 1: Gather Information
52
+ ```markdown
53
+ ## Bug Report
54
+
55
+ **Error:** "Cannot read property 'name' of undefined"
56
+
57
+ **Expected:** User profile displays name
58
+ **Actual:** Application crashes
59
+
60
+ **Reproduction:**
61
+ 1. Go to /profile
62
+ 2. Click "Edit Profile"
63
+ 3. Error occurs
64
+
65
+ **Stack Trace:**
66
+ ```
67
+ Error: Cannot read property 'name' of undefined
68
+ at ProfilePage (app/profile/page.tsx:45)
69
+ at renderComponent (react.js:123)
70
+ ```
71
+
72
+ **Logs:**
73
+ ```
74
+ [ERROR] User data undefined for ID: user_123
75
+ [DEBUG] Database query returned null
76
+ ```
77
+ ```
78
+
79
+ ### Phase 2: Analyze Root Cause
80
+ ```typescript
81
+ // Bug location: app/profile/page.tsx:45
82
+ function ProfilePage() {
83
+ const user = await getUser(userId);
84
+ return <div>{user.name}</div>; // ← Crashes here if user is null
85
+ }
86
+ ```
87
+
88
+ **Root Cause:** No null check after database query.
89
+
90
+ ### Phase 3: Implement Fix
91
+ ```typescript
92
+ // Fixed version
93
+ async function ProfilePage() {
94
+ const user = await getUser(userId);
95
+
96
+ if (!user) {
97
+ throw new NotFoundError('User not found');
98
+ }
99
+
100
+ return <div>{user.name}</div>;
101
+ }
102
+ ```
103
+
104
+ ### Phase 4: Add Regression Test
105
+ ```typescript
106
+ test('handles missing user gracefully', async () => {
107
+ const response = await request(app)
108
+ .get('/profile/invalid-user-id');
109
+
110
+ expect(response.status).toBe(404);
111
+ expect(response.body.error).toContain('User not found');
112
+ });
113
+ ```
114
+
115
+ ## Common Bug Patterns
116
+
117
+ ### 1. Null/Undefined Errors
118
+ ```typescript
119
+ // Bug
120
+ function getUser(id) {
121
+ const user = users.find(u => u.id === id);
122
+ return user.name; // Error if user is undefined
123
+ }
124
+
125
+ // Fix
126
+ function getUser(id) {
127
+ const user = users.find(u => u.id === id);
128
+ if (!user) {
129
+ throw new NotFoundError(`User ${id} not found`);
130
+ }
131
+ return user.name;
132
+ }
133
+ ```
134
+
135
+ ### 2. Race Conditions
136
+ ```typescript
137
+ // Bug
138
+ let count = 0;
139
+ async function increment() {
140
+ const current = count;
141
+ await delay(10);
142
+ count = current + 1; // Race condition
143
+ }
144
+
145
+ // Fix (use atomic operations)
146
+ let count = 0;
147
+ const lock = new AsyncLock();
148
+
149
+ async function increment() {
150
+ await lock.acquire('count', async () => {
151
+ count++;
152
+ });
153
+ }
154
+ ```
155
+
156
+ ### 3. Memory Leaks
157
+ ```typescript
158
+ // Bug - event listener not removed
159
+ class Component {
160
+ constructor() {
161
+ window.addEventListener('resize', this.handleResize);
162
+ }
163
+ }
164
+
165
+ // Fix - cleanup in destructor
166
+ class Component {
167
+ constructor() {
168
+ this.handleResize = this.handleResize.bind(this);
169
+ window.addEventListener('resize', this.handleResize);
170
+ }
171
+
172
+ destroy() {
173
+ window.removeEventListener('resize', this.handleResize);
174
+ }
175
+ }
176
+ ```
177
+
178
+ ### 4. Type Errors
179
+ ```typescript
180
+ // Bug - type coercion
181
+ function add(a, b) {
182
+ return a + b;
183
+ }
184
+
185
+ add("10", 20); // "1020" (string concatenation)
186
+
187
+ // Fix - proper types
188
+ function add(a: number, b: number): number {
189
+ return Number(a) + Number(b);
190
+ }
191
+ ```
192
+
193
+ ### 5. SQL N+1 Queries
194
+ ```typescript
195
+ // Bug - N+1 queries
196
+ const posts = await db.posts.findMany();
197
+ for (const post of posts) {
198
+ post.author = await db.users.findUnique({ where: { id: post.authorId } });
199
+ }
200
+
201
+ // Fix - single query with join
202
+ const posts = await db.posts.findMany({
203
+ include: { author: true }
204
+ });
205
+ ```
206
+
207
+ ## Debugging Tools
208
+
209
+ ### Console Logging
210
+ ```typescript
211
+ // Strategic logging
212
+ console.log('Before API call:', { userId, timestamp: Date.now() });
213
+ const user = await fetchUser(userId);
214
+ console.log('After API call:', { user, timestamp: Date.now() });
215
+ ```
216
+
217
+ ### Debugger Breakpoints
218
+ ```typescript
219
+ function calculateTotal(items) {
220
+ debugger; // Pauses execution here
221
+ return items.reduce((sum, item) => sum + item.price, 0);
222
+ }
223
+ ```
224
+
225
+ ### Stack Trace Analysis
226
+ ```
227
+ Error: Cannot read property 'name' of undefined
228
+ at getUser (app.js:45:12) ← Problem here
229
+ at handleRequest (server.js:89:5) ← Called from here
230
+ ```
231
+
232
+ ### Log Analysis
233
+ ```bash
234
+ # Find errors
235
+ grep "ERROR" app.log
236
+
237
+ # Count error types
238
+ grep "ERROR" app.log | sort | uniq -c
239
+
240
+ # Track specific user
241
+ grep "userId:12345" app.log
242
+ ```
243
+
244
+ ## Memory Integration
245
+
246
+ Before debugging:
247
+ - Check `ai_context/memory/learning.md` for past bug patterns
248
+
249
+ After debugging:
250
+ - Update `ai_context/memory/learning.md` with new bug pattern
251
+ - Save report to `ai_context/reports/debug-{timestamp}-{slug}.md`
252
+
253
+ ## Debug Report
254
+
255
+ Save to: `ai_context/reports/debug-YYMMDD-slug.md`
256
+
257
+ ```markdown
258
+ # Bug Fix Report
259
+
260
+ **Date:** {use bash: date "+%Y-%m-%d"}
261
+ **Bug:** Users unable to login
262
+ **Severity:** Critical
263
+ **Status:** Fixed
264
+
265
+ ## Problem
266
+
267
+ **Expected:** User logs in with valid credentials
268
+ **Actual:** Login fails with "Invalid token" error
269
+
270
+ **Reproduction:**
271
+ 1. Go to /login
272
+ 2. Enter email: test@example.com
273
+ 3. Enter password: correct-password
274
+ 4. Error: "Invalid token"
275
+
276
+ ## Investigation
277
+
278
+ **Stack Trace:**
279
+ ```
280
+ Error: Invalid token
281
+ at validateToken (auth.ts:45)
282
+ at loginUser (api/auth.ts:23)
283
+ ```
284
+
285
+ **Logs:**
286
+ ```
287
+ [ERROR] Token verification failed: jwt malformed
288
+ [DEBUG] Token received: undefined
289
+ ```
290
+
291
+ **Root Cause:**
292
+ JWT token generated but not included in API response.
293
+
294
+ ## Fix
295
+
296
+ ```typescript
297
+ // Before (bug)
298
+ const token = generateJWT(user);
299
+ return { user }; // Token not returned!
300
+
301
+ // After (fixed)
302
+ const token = generateJWT(user);
303
+ return { user, token };
304
+ ```
305
+
306
+ ## Verification
307
+
308
+ - ✅ Login now works
309
+ - ✅ Token present in response
310
+ - ✅ No regressions
311
+ - ✅ Regression test added
312
+
313
+ ## Regression Test
314
+
315
+ ```typescript
316
+ test('login returns JWT token', async () => {
317
+ const response = await request(app)
318
+ .post('/api/auth/login')
319
+ .send({ email: 'test@example.com', password: 'password' });
320
+
321
+ expect(response.body).toHaveProperty('token');
322
+ expect(response.body.token).toMatch(/^eyJ/);
323
+ });
324
+ ```
325
+
326
+ ## Prevention
327
+
328
+ Added similar fix to `/api/auth/register`.
329
+ Updated docs to always return auth tokens.
330
+ ```
331
+
332
+ ## Performance Debugging
333
+
334
+ ### Slow Queries
335
+ ```sql
336
+ -- Find slow queries (PostgreSQL)
337
+ SELECT query, calls, mean_time
338
+ FROM pg_stat_statements
339
+ WHERE mean_time > 100
340
+ ORDER BY mean_time DESC;
341
+
342
+ -- Check for missing indexes
343
+ EXPLAIN ANALYZE
344
+ SELECT * FROM users WHERE email = 'test@example.com';
345
+ ```
346
+
347
+ ### Memory Profiling
348
+ ```javascript
349
+ // Node.js heap snapshot
350
+ const v8 = require('v8');
351
+ v8.writeHeapSnapshot('./heap-snapshot.heapsnapshot');
352
+ ```
353
+
354
+ ### Performance Timing
355
+ ```typescript
356
+ console.time('operation');
357
+ await expensiveOperation();
358
+ console.timeEnd('operation'); // operation: 1234ms
359
+ ```
360
+
361
+ ## Git Bisect (Find When Bug Was Introduced)
362
+ ```bash
363
+ git bisect start
364
+ git bisect bad # Current commit has bug
365
+ git bisect good v1.2.0 # v1.2.0 was working
366
+ # Git checks out middle commit
367
+ npm test # Test if bug exists
368
+ git bisect good # or bad
369
+ # Repeat until bug commit found
370
+ git bisect reset
371
+ ```
372
+
373
+ ## Integration with Other Commands
374
+
375
+ **/debug** → **/test**
376
+ - After fixing bug, add regression test
377
+
378
+ **/debug** → **/review**
379
+ - Review fix for quality and security
380
+
381
+ **/debug** → **/secure**
382
+ - If security bug, run security scan
383
+
384
+ ## Debug Checklist
385
+
386
+ ### Investigation
387
+ - ✅ Read full error message
388
+ - ✅ Analyze stack trace
389
+ - ✅ Reproduce reliably
390
+ - ✅ Check recent changes
391
+ - ✅ Search error online
392
+
393
+ ### Fix
394
+ - ✅ Minimal change (don't refactor while debugging)
395
+ - ✅ Test thoroughly
396
+ - ✅ No new bugs introduced
397
+ - ✅ Edge cases handled
398
+
399
+ ### Prevention
400
+ - ✅ Regression test added
401
+ - ✅ Root cause documented
402
+ - ✅ Similar bugs prevented
403
+ - ✅ Team notified
404
+
405
+ ## Common Debugging Strategies
406
+
407
+ ### Binary Search
408
+ ```typescript
409
+ // Bug somewhere in 1000-line function
410
+ // Add logs to narrow down
411
+ function complexFunction() {
412
+ console.log('Step 1 OK'); // Works
413
+ // ... 500 lines ...
414
+ console.log('Step 2 OK'); // Works
415
+ // ... 500 lines ...
416
+ console.log('Step 3 OK'); // Doesn't print → bug before this
417
+ }
418
+ ```
419
+
420
+ ### Rubber Duck Debugging
421
+ 1. Explain code line-by-line
422
+ 2. Often find bug while explaining
423
+ 3. Write it down or talk to AI
424
+
425
+ ### Divide and Conquer
426
+ 1. Disable half the code
427
+ 2. See if bug still occurs
428
+ 3. Narrow down to problematic section
429
+
430
+ ## Success Criteria
431
+
432
+ Debugging is successful when:
433
+ - ✅ Root cause identified
434
+ - ✅ Bug fixed (not masked)
435
+ - ✅ Fix verified with tests
436
+ - ✅ Regression test prevents recurrence
437
+ - ✅ No new bugs introduced
438
+ - ✅ Documented for future
439
+
440
+ ## Remember
441
+
442
+ **Good debugging:**
443
+ - Understands problem fully before fixing
444
+ - Makes minimal changes
445
+ - Tests thoroughly
446
+ - Prevents recurrence
447
+ - Documents findings
448
+
449
+ **"Hours of debugging can save minutes of planning."**