start-vibing 2.0.8 → 2.0.10

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 (139) hide show
  1. package/README.md +177 -176
  2. package/dist/cli.js +38 -11
  3. package/package.json +42 -42
  4. package/template/.claude/CLAUDE.md +174 -152
  5. package/template/.claude/agents/01-orchestration/agent-selector.md +130 -123
  6. package/template/.claude/agents/01-orchestration/checkpoint-manager.md +142 -131
  7. package/template/.claude/agents/01-orchestration/context-manager.md +138 -124
  8. package/template/.claude/agents/01-orchestration/error-recovery.md +182 -176
  9. package/template/.claude/agents/01-orchestration/orchestrator.md +114 -107
  10. package/template/.claude/agents/01-orchestration/parallel-coordinator.md +141 -130
  11. package/template/.claude/agents/01-orchestration/task-decomposer.md +121 -118
  12. package/template/.claude/agents/01-orchestration/workflow-router.md +114 -111
  13. package/template/.claude/agents/02-typescript/bun-runtime-expert.md +197 -180
  14. package/template/.claude/agents/02-typescript/esm-resolver.md +193 -187
  15. package/template/.claude/agents/02-typescript/import-alias-enforcer.md +158 -149
  16. package/template/.claude/agents/02-typescript/ts-generics-helper.md +183 -165
  17. package/template/.claude/agents/02-typescript/ts-migration-helper.md +238 -227
  18. package/template/.claude/agents/02-typescript/ts-strict-checker.md +180 -162
  19. package/template/.claude/agents/02-typescript/ts-types-analyzer.md +199 -185
  20. package/template/.claude/agents/02-typescript/type-definition-writer.md +187 -183
  21. package/template/.claude/agents/02-typescript/zod-schema-designer.md +212 -197
  22. package/template/.claude/agents/02-typescript/zod-validator.md +158 -153
  23. package/template/.claude/agents/03-testing/playwright-assertions.md +265 -255
  24. package/template/.claude/agents/03-testing/playwright-e2e.md +247 -245
  25. package/template/.claude/agents/03-testing/playwright-fixtures.md +234 -240
  26. package/template/.claude/agents/03-testing/playwright-multi-viewport.md +256 -261
  27. package/template/.claude/agents/03-testing/playwright-page-objects.md +247 -247
  28. package/template/.claude/agents/03-testing/test-cleanup-manager.md +248 -256
  29. package/template/.claude/agents/03-testing/test-data-generator.md +254 -266
  30. package/template/.claude/agents/03-testing/tester-integration.md +278 -278
  31. package/template/.claude/agents/03-testing/tester-unit.md +207 -204
  32. package/template/.claude/agents/03-testing/vitest-config.md +287 -289
  33. package/template/.claude/agents/04-docker/container-health.md +255 -239
  34. package/template/.claude/agents/04-docker/deployment-validator.md +225 -217
  35. package/template/.claude/agents/04-docker/docker-compose-designer.md +281 -268
  36. package/template/.claude/agents/04-docker/docker-env-manager.md +235 -228
  37. package/template/.claude/agents/04-docker/docker-multi-stage.md +241 -229
  38. package/template/.claude/agents/04-docker/dockerfile-optimizer.md +208 -204
  39. package/template/.claude/agents/05-database/data-migration.md +0 -293
  40. package/template/.claude/agents/05-database/database-seeder.md +273 -270
  41. package/template/.claude/agents/05-database/mongodb-query-optimizer.md +230 -219
  42. package/template/.claude/agents/05-database/mongoose-aggregation.md +306 -280
  43. package/template/.claude/agents/05-database/mongoose-index-optimizer.md +182 -174
  44. package/template/.claude/agents/05-database/mongoose-schema-designer.md +267 -267
  45. package/template/.claude/agents/06-security/auth-session-validator.md +68 -65
  46. package/template/.claude/agents/06-security/input-sanitizer.md +80 -81
  47. package/template/.claude/agents/06-security/owasp-checker.md +97 -87
  48. package/template/.claude/agents/06-security/permission-auditor.md +100 -95
  49. package/template/.claude/agents/06-security/security-auditor.md +84 -82
  50. package/template/.claude/agents/06-security/sensitive-data-scanner.md +83 -85
  51. package/template/.claude/agents/07-documentation/api-documenter.md +136 -131
  52. package/template/.claude/agents/07-documentation/changelog-manager.md +105 -96
  53. package/template/.claude/agents/07-documentation/documenter.md +76 -73
  54. package/template/.claude/agents/07-documentation/domain-updater.md +81 -74
  55. package/template/.claude/agents/07-documentation/jsdoc-generator.md +114 -114
  56. package/template/.claude/agents/07-documentation/readme-generator.md +135 -132
  57. package/template/.claude/agents/08-git/branch-manager.md +58 -58
  58. package/template/.claude/agents/08-git/commit-manager.md +63 -61
  59. package/template/.claude/agents/08-git/pr-creator.md +76 -72
  60. package/template/.claude/agents/09-quality/code-reviewer.md +71 -64
  61. package/template/.claude/agents/09-quality/quality-checker.md +67 -67
  62. package/template/.claude/agents/10-research/best-practices-finder.md +89 -82
  63. package/template/.claude/agents/10-research/competitor-analyzer.md +106 -96
  64. package/template/.claude/agents/10-research/pattern-researcher.md +93 -86
  65. package/template/.claude/agents/10-research/research-cache-manager.md +76 -75
  66. package/template/.claude/agents/10-research/research-web.md +98 -91
  67. package/template/.claude/agents/10-research/tech-evaluator.md +101 -94
  68. package/template/.claude/agents/11-ui-ux/accessibility-auditor.md +136 -128
  69. package/template/.claude/agents/11-ui-ux/design-system-enforcer.md +125 -116
  70. package/template/.claude/agents/11-ui-ux/skeleton-generator.md +118 -120
  71. package/template/.claude/agents/11-ui-ux/ui-desktop.md +132 -126
  72. package/template/.claude/agents/11-ui-ux/ui-mobile.md +98 -94
  73. package/template/.claude/agents/11-ui-ux/ui-tablet.md +110 -111
  74. package/template/.claude/agents/12-performance/api-latency-analyzer.md +156 -149
  75. package/template/.claude/agents/12-performance/bundle-analyzer.md +113 -107
  76. package/template/.claude/agents/12-performance/memory-leak-detector.md +137 -126
  77. package/template/.claude/agents/12-performance/performance-profiler.md +115 -108
  78. package/template/.claude/agents/12-performance/query-optimizer.md +124 -116
  79. package/template/.claude/agents/12-performance/render-optimizer.md +154 -148
  80. package/template/.claude/agents/13-debugging/build-error-fixer.md +207 -188
  81. package/template/.claude/agents/13-debugging/debugger.md +149 -137
  82. package/template/.claude/agents/13-debugging/error-stack-analyzer.md +141 -131
  83. package/template/.claude/agents/13-debugging/network-debugger.md +208 -185
  84. package/template/.claude/agents/13-debugging/runtime-error-fixer.md +181 -173
  85. package/template/.claude/agents/13-debugging/type-error-resolver.md +185 -173
  86. package/template/.claude/agents/14-validation/final-validator.md +93 -83
  87. package/template/.claude/agents/_backup/analyzer.md +134 -125
  88. package/template/.claude/agents/_backup/code-reviewer.md +279 -272
  89. package/template/.claude/agents/_backup/commit-manager.md +219 -212
  90. package/template/.claude/agents/_backup/debugger.md +280 -271
  91. package/template/.claude/agents/_backup/documenter.md +237 -220
  92. package/template/.claude/agents/_backup/domain-updater.md +197 -194
  93. package/template/.claude/agents/_backup/final-validator.md +169 -164
  94. package/template/.claude/agents/_backup/orchestrator.md +149 -138
  95. package/template/.claude/agents/_backup/performance.md +232 -228
  96. package/template/.claude/agents/_backup/quality-checker.md +240 -240
  97. package/template/.claude/agents/_backup/research.md +315 -299
  98. package/template/.claude/agents/_backup/security-auditor.md +192 -186
  99. package/template/.claude/agents/_backup/tester.md +566 -564
  100. package/template/.claude/agents/_backup/ui-ux-reviewer.md +247 -242
  101. package/template/.claude/commands/feature.md +48 -48
  102. package/template/.claude/config/README.md +30 -30
  103. package/template/.claude/config/mcp-config.json +344 -330
  104. package/template/.claude/config/project-config.json +53 -53
  105. package/template/.claude/config/quality-gates.json +46 -46
  106. package/template/.claude/config/security-rules.json +45 -45
  107. package/template/.claude/config/testing-config.json +164 -168
  108. package/template/.claude/hooks/SETUP.md +126 -126
  109. package/template/.claude/hooks/run-hook.ts +176 -172
  110. package/template/.claude/hooks/stop-validator.ts +825 -353
  111. package/template/.claude/hooks/user-prompt-submit.ts +886 -794
  112. package/template/.claude/scripts/mcp-quick-install.ts +151 -151
  113. package/template/.claude/scripts/setup-mcps.ts +651 -628
  114. package/template/.claude/settings.json +275 -276
  115. package/template/.claude/skills/bun-runtime/SKILL.md +430 -430
  116. package/template/.claude/skills/codebase-knowledge/SKILL.md +145 -145
  117. package/template/.claude/skills/codebase-knowledge/domains/claude-system.md +431 -403
  118. package/template/.claude/skills/codebase-knowledge/domains/mcp-integration.md +295 -281
  119. package/template/.claude/skills/debugging-patterns/SKILL.md +485 -484
  120. package/template/.claude/skills/docker-patterns/SKILL.md +555 -547
  121. package/template/.claude/skills/docs-tracker/SKILL.md +239 -239
  122. package/template/.claude/skills/final-check/SKILL.md +284 -284
  123. package/template/.claude/skills/git-workflow/SKILL.md +454 -454
  124. package/template/.claude/skills/mongoose-patterns/SKILL.md +499 -512
  125. package/template/.claude/skills/nextjs-app-router/SKILL.md +327 -337
  126. package/template/.claude/skills/performance-patterns/SKILL.md +547 -549
  127. package/template/.claude/skills/playwright-automation/SKILL.md +438 -438
  128. package/template/.claude/skills/quality-gate/SKILL.md +294 -294
  129. package/template/.claude/skills/react-patterns/SKILL.md +389 -376
  130. package/template/.claude/skills/research-cache/SKILL.md +222 -207
  131. package/template/.claude/skills/security-scan/SKILL.md +222 -222
  132. package/template/.claude/skills/shadcn-ui/SKILL.md +511 -520
  133. package/template/.claude/skills/tailwind-patterns/SKILL.md +465 -467
  134. package/template/.claude/skills/test-coverage/SKILL.md +467 -464
  135. package/template/.claude/skills/trpc-api/SKILL.md +434 -435
  136. package/template/.claude/skills/typescript-strict/SKILL.md +367 -368
  137. package/template/.claude/skills/ui-ux-audit/SKILL.md +254 -254
  138. package/template/.claude/skills/zod-validation/SKILL.md +403 -405
  139. package/template/CLAUDE.md +25 -25
@@ -1,484 +1,485 @@
1
- ---
2
- name: debugging-patterns
3
- description: Debugging strategies and error resolution patterns. Stack trace analysis, runtime errors, build errors, network issues. Use when debugging any type of error.
4
- allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
- ---
6
-
7
- # Debugging Patterns - Error Resolution Best Practices
8
-
9
- ## Purpose
10
-
11
- Expert guidance for debugging:
12
-
13
- - **Error Analysis** - Stack traces, error messages
14
- - **Runtime Issues** - Type errors, null references
15
- - **Build Errors** - Compilation, bundling
16
- - **Network Issues** - API, CORS, HTTP errors
17
- - **Performance Bugs** - Slow operations, memory leaks
18
-
19
- ---
20
-
21
- ## Debug Process
22
-
23
- ```
24
- 1. UNDERSTAND - What should happen vs what happens
25
-
26
- 2. REPRODUCE - Consistent steps to trigger bug
27
-
28
- 3. ISOLATE - Narrow down to specific code
29
-
30
- 4. IDENTIFY - Find root cause
31
-
32
- 5. FIX - Implement solution
33
-
34
- 6. VERIFY - Confirm fix works + no regressions
35
- ```
36
-
37
- ---
38
-
39
- ## Stack Trace Analysis
40
-
41
- ### Reading Error Stack
42
-
43
- ```
44
- TypeError: Cannot read properties of undefined (reading 'name')
45
- at getUserName (src/utils/user.ts:45:23)
46
- at ProfileCard (src/components/ProfileCard.tsx:12:18)
47
- at renderWithHooks (node_modules/react-dom/...)
48
- ```
49
-
50
- **Key Information:**
51
- - **Error Type**: `TypeError`
52
- - **Message**: `Cannot read properties of undefined`
53
- - **Property**: `name`
54
- - **Location**: `src/utils/user.ts:45:23` (file:line:column)
55
- - **Call Stack**: Shows how we got here
56
-
57
- ### Fix Pattern
58
-
59
- ```typescript
60
- // Error at line 45
61
- function getUserName(user: User) {
62
- return user.name; // ERROR: user is undefined
63
- }
64
-
65
- // Fix: Add null check
66
- function getUserName(user: User | undefined): string {
67
- return user?.name ?? 'Unknown';
68
- }
69
-
70
- // Or use assertion with clear error
71
- function getUserName(user: User | undefined): string {
72
- if (!user) {
73
- throw new Error('User is required for getUserName');
74
- }
75
- return user.name;
76
- }
77
- ```
78
-
79
- ---
80
-
81
- ## Common Error Patterns
82
-
83
- ### TypeError: Cannot read properties of undefined
84
-
85
- ```typescript
86
- // Pattern: Accessing property on undefined
87
- const name = user.profile.name;
88
-
89
- // Fix 1: Optional chaining
90
- const name = user?.profile?.name ?? 'Unknown';
91
-
92
- // Fix 2: Early return
93
- if (!user?.profile) return null;
94
- const name = user.profile.name;
95
-
96
- // Fix 3: Default value
97
- const profile = user?.profile ?? { name: 'Unknown' };
98
- ```
99
-
100
- ### TypeError: X is not a function
101
-
102
- ```typescript
103
- // Pattern: Calling non-function
104
- onClick(); // onClick is undefined
105
-
106
- // Fix 1: Check before calling
107
- onClick?.();
108
-
109
- // Fix 2: Provide default
110
- const handleClick = onClick ?? (() => {});
111
- handleClick();
112
- ```
113
-
114
- ### ReferenceError: X is not defined
115
-
116
- ```typescript
117
- // Pattern: Using undefined variable
118
- console.log(userData); // userData not imported/declared
119
-
120
- // Fix: Import or declare
121
- import { userData } from './data';
122
- // or
123
- const userData = await fetchUserData();
124
- ```
125
-
126
- ### SyntaxError: Unexpected token
127
-
128
- ```typescript
129
- // Pattern: Invalid JSON
130
- const data = JSON.parse(response);
131
- // SyntaxError: Unexpected token '<'
132
-
133
- // Fix: Check response before parsing
134
- if (!response.ok) {
135
- throw new Error(`HTTP ${response.status}`);
136
- }
137
- const text = await response.text();
138
- try {
139
- return JSON.parse(text);
140
- } catch {
141
- throw new Error(`Invalid JSON: ${text.slice(0, 100)}`);
142
- }
143
- ```
144
-
145
- ---
146
-
147
- ## TypeScript Errors
148
-
149
- ### TS2339: Property does not exist
150
-
151
- ```typescript
152
- // Error
153
- const env = process.env.NODE_ENV;
154
- // Property 'NODE_ENV' does not exist on type 'ProcessEnv'
155
-
156
- // Fix: Use bracket notation
157
- const env = process.env['NODE_ENV'];
158
- ```
159
-
160
- ### TS2532: Object is possibly undefined
161
-
162
- ```typescript
163
- // Error
164
- const items = array.map(x => x.value);
165
- // Object is possibly 'undefined'
166
-
167
- // Fix 1: Non-null assertion (if certain)
168
- const items = array!.map(x => x.value);
169
-
170
- // Fix 2: Default value
171
- const items = (array ?? []).map(x => x.value);
172
-
173
- // Fix 3: Conditional
174
- const items = array ? array.map(x => x.value) : [];
175
- ```
176
-
177
- ### TS2345: Argument type mismatch
178
-
179
- ```typescript
180
- // Error
181
- function greet(name: string) { }
182
- greet(user.name); // Argument of type 'string | undefined'
183
-
184
- // Fix 1: Provide default
185
- greet(user.name ?? 'Guest');
186
-
187
- // Fix 2: Assert
188
- greet(user.name!);
189
-
190
- // Fix 3: Guard
191
- if (user.name) greet(user.name);
192
- ```
193
-
194
- ### TS7053: Index signature
195
-
196
- ```typescript
197
- // Error
198
- const value = obj[key];
199
- // Element implicitly has 'any' type
200
-
201
- // Fix: Type the index
202
- const value = (obj as Record<string, unknown>)[key];
203
-
204
- // Or define proper type
205
- interface MyObj {
206
- [key: string]: string | undefined;
207
- }
208
- ```
209
-
210
- ---
211
-
212
- ## Build Errors
213
-
214
- ### Module Not Found
215
-
216
- ```bash
217
- # Error
218
- Cannot find module './utils' or its corresponding type declarations
219
-
220
- # Check 1: File exists?
221
- ls src/utils.ts
222
-
223
- # Check 2: Extension needed?
224
- import { helper } from './utils.js'; # ESM requires extension
225
-
226
- # Check 3: Path alias configured?
227
- # Check tsconfig.json paths
228
- ```
229
-
230
- ### Duplicate Identifier
231
-
232
- ```bash
233
- # Error
234
- Duplicate identifier 'User'
235
-
236
- # Fix: Check imports for conflicts
237
- # May have both named and default import
238
- import User from './User';
239
- import { User } from './types'; # Conflict!
240
-
241
- # Solution: Rename one
242
- import { User as UserType } from './types';
243
- ```
244
-
245
- ### ESM/CJS Compatibility
246
-
247
- ```typescript
248
- // Error: require is not defined in ES module
249
- const fs = require('fs');
250
-
251
- // Fix: Use ESM import
252
- import fs from 'fs';
253
- import { readFileSync } from 'fs';
254
-
255
- // If must use require in ESM
256
- import { createRequire } from 'module';
257
- const require = createRequire(import.meta.url);
258
- ```
259
-
260
- ---
261
-
262
- ## Network & API Errors
263
-
264
- ### CORS Errors
265
-
266
- ```
267
- Access to fetch at 'https://api.example.com' has been blocked by CORS policy
268
- ```
269
-
270
- ```typescript
271
- // Server-side fix (add headers)
272
- res.setHeader('Access-Control-Allow-Origin', 'https://yoursite.com');
273
- res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
274
- res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
275
-
276
- // Client-side workaround (proxy in dev)
277
- // vite.config.ts
278
- export default {
279
- server: {
280
- proxy: {
281
- '/api': {
282
- target: 'https://api.example.com',
283
- changeOrigin: true,
284
- },
285
- },
286
- },
287
- };
288
- ```
289
-
290
- ### HTTP Error Handling
291
-
292
- ```typescript
293
- async function fetchWithErrorHandling<T>(url: string): Promise<T> {
294
- const response = await fetch(url);
295
-
296
- if (!response.ok) {
297
- // Get error details
298
- let message: string;
299
- try {
300
- const error = await response.json();
301
- message = error.message || response.statusText;
302
- } catch {
303
- message = response.statusText;
304
- }
305
-
306
- throw new Error(`${response.status} ${message}`);
307
- }
308
-
309
- return response.json();
310
- }
311
- ```
312
-
313
- ### Network Timeout
314
-
315
- ```typescript
316
- async function fetchWithTimeout(url: string, timeout = 5000) {
317
- const controller = new AbortController();
318
- const id = setTimeout(() => controller.abort(), timeout);
319
-
320
- try {
321
- const response = await fetch(url, { signal: controller.signal });
322
- clearTimeout(id);
323
- return response;
324
- } catch (error) {
325
- clearTimeout(id);
326
- if (error instanceof Error && error.name === 'AbortError') {
327
- throw new Error(`Request timeout after ${timeout}ms`);
328
- }
329
- throw error;
330
- }
331
- }
332
- ```
333
-
334
- ---
335
-
336
- ## React Debugging
337
-
338
- ### "Cannot update a component while rendering"
339
-
340
- ```typescript
341
- // Error: State update during render
342
- function Component({ value }) {
343
- const [state, setState] = useState(0);
344
- setState(value); // ERROR!
345
-
346
- // Fix: Use useEffect
347
- useEffect(() => {
348
- setState(value);
349
- }, [value]);
350
- }
351
- ```
352
-
353
- ### "Too many re-renders"
354
-
355
- ```typescript
356
- // Error: Infinite loop
357
- function Component() {
358
- const [count, setCount] = useState(0);
359
- setCount(count + 1); // Causes re-render, which sets count...
360
-
361
- // Fix: Add condition or use effect
362
- useEffect(() => {
363
- if (count < 10) {
364
- setCount(c => c + 1);
365
- }
366
- }, [count]);
367
- }
368
- ```
369
-
370
- ### "Invalid hook call"
371
-
372
- ```typescript
373
- // Error: Hook outside component or conditional
374
- function Component() {
375
- if (condition) {
376
- const [state] = useState(0); // ERROR!
377
- }
378
- }
379
-
380
- // Fix: Hooks must be at top level
381
- function Component() {
382
- const [state] = useState(0); // OK
383
- if (condition) {
384
- // use state here
385
- }
386
- }
387
- ```
388
-
389
- ---
390
-
391
- ## Debug Commands
392
-
393
- ### Git - Find Breaking Commit
394
-
395
- ```bash
396
- # Start bisect
397
- git bisect start
398
- git bisect bad HEAD
399
- git bisect good abc123 # Last known good commit
400
-
401
- # Test and mark each commit
402
- git bisect good # or bad
403
-
404
- # End bisect
405
- git bisect reset
406
- ```
407
-
408
- ### Find Error in Code
409
-
410
- ```bash
411
- # Search for error message
412
- grep -rn "specific error text" src/
413
-
414
- # Search for pattern
415
- grep -rn "throw new Error" src/ --include="*.ts"
416
-
417
- # Find file with symbol
418
- grep -rn "functionName" src/ --include="*.ts" -l
419
- ```
420
-
421
- ### Bun Debugging
422
-
423
- ```bash
424
- # Debug mode
425
- bun --inspect src/index.ts
426
-
427
- # With breakpoint on start
428
- bun --inspect-brk src/index.ts
429
-
430
- # Low memory mode (for memory issues)
431
- bun --smol src/index.ts
432
- ```
433
-
434
- ---
435
-
436
- ## Debugging Checklist
437
-
438
- ### Before You Start
439
-
440
- - [ ] Can you reproduce the bug?
441
- - [ ] Do you have the exact error message?
442
- - [ ] What changed recently? (`git log`, `git diff`)
443
-
444
- ### Investigation
445
-
446
- - [ ] Read the full error message and stack trace
447
- - [ ] Check the line number mentioned in error
448
- - [ ] Add console.log at key points
449
- - [ ] Check network tab for API errors
450
-
451
- ### After Fix
452
-
453
- - [ ] Does the fix work for all cases?
454
- - [ ] Did you add tests to prevent regression?
455
- - [ ] Did you handle edge cases?
456
-
457
- ---
458
-
459
- ## Agent Integration
460
-
461
- This skill is used by:
462
-
463
- - **debugger** agent
464
- - **error-stack-analyzer** agent
465
- - **type-error-resolver** agent
466
- - **runtime-error-fixer** agent
467
- - **network-debugger** agent
468
- - **build-error-fixer** agent
469
-
470
- ---
471
-
472
- ## FORBIDDEN
473
-
474
- 1. **Swallowing errors silently** - Always log or handle
475
- 2. **Using `any` to hide errors** - Fix the actual type issue
476
- 3. **`@ts-ignore` without comment** - Use `@ts-expect-error` with explanation
477
- 4. **Empty catch blocks** - At minimum, log the error
478
- 5. **Fixing symptoms not causes** - Find and fix root cause
479
-
480
- ---
481
-
482
- ## Version
483
-
484
- - **v1.0.0** - Initial implementation based on 2024-2025 debugging patterns
1
+ ---
2
+ name: debugging-patterns
3
+ description: Debugging strategies and error resolution patterns. Stack trace analysis, runtime errors, build errors, network issues. Use when debugging any type of error.
4
+ allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ ---
6
+
7
+ # Debugging Patterns - Error Resolution Best Practices
8
+
9
+ ## Purpose
10
+
11
+ Expert guidance for debugging:
12
+
13
+ - **Error Analysis** - Stack traces, error messages
14
+ - **Runtime Issues** - Type errors, null references
15
+ - **Build Errors** - Compilation, bundling
16
+ - **Network Issues** - API, CORS, HTTP errors
17
+ - **Performance Bugs** - Slow operations, memory leaks
18
+
19
+ ---
20
+
21
+ ## Debug Process
22
+
23
+ ```
24
+ 1. UNDERSTAND - What should happen vs what happens
25
+
26
+ 2. REPRODUCE - Consistent steps to trigger bug
27
+
28
+ 3. ISOLATE - Narrow down to specific code
29
+
30
+ 4. IDENTIFY - Find root cause
31
+
32
+ 5. FIX - Implement solution
33
+
34
+ 6. VERIFY - Confirm fix works + no regressions
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Stack Trace Analysis
40
+
41
+ ### Reading Error Stack
42
+
43
+ ```
44
+ TypeError: Cannot read properties of undefined (reading 'name')
45
+ at getUserName (src/utils/user.ts:45:23)
46
+ at ProfileCard (src/components/ProfileCard.tsx:12:18)
47
+ at renderWithHooks (node_modules/react-dom/...)
48
+ ```
49
+
50
+ **Key Information:**
51
+
52
+ - **Error Type**: `TypeError`
53
+ - **Message**: `Cannot read properties of undefined`
54
+ - **Property**: `name`
55
+ - **Location**: `src/utils/user.ts:45:23` (file:line:column)
56
+ - **Call Stack**: Shows how we got here
57
+
58
+ ### Fix Pattern
59
+
60
+ ```typescript
61
+ // Error at line 45
62
+ function getUserName(user: User) {
63
+ return user.name; // ERROR: user is undefined
64
+ }
65
+
66
+ // Fix: Add null check
67
+ function getUserName(user: User | undefined): string {
68
+ return user?.name ?? 'Unknown';
69
+ }
70
+
71
+ // Or use assertion with clear error
72
+ function getUserName(user: User | undefined): string {
73
+ if (!user) {
74
+ throw new Error('User is required for getUserName');
75
+ }
76
+ return user.name;
77
+ }
78
+ ```
79
+
80
+ ---
81
+
82
+ ## Common Error Patterns
83
+
84
+ ### TypeError: Cannot read properties of undefined
85
+
86
+ ```typescript
87
+ // Pattern: Accessing property on undefined
88
+ const name = user.profile.name;
89
+
90
+ // Fix 1: Optional chaining
91
+ const name = user?.profile?.name ?? 'Unknown';
92
+
93
+ // Fix 2: Early return
94
+ if (!user?.profile) return null;
95
+ const name = user.profile.name;
96
+
97
+ // Fix 3: Default value
98
+ const profile = user?.profile ?? { name: 'Unknown' };
99
+ ```
100
+
101
+ ### TypeError: X is not a function
102
+
103
+ ```typescript
104
+ // Pattern: Calling non-function
105
+ onClick(); // onClick is undefined
106
+
107
+ // Fix 1: Check before calling
108
+ onClick?.();
109
+
110
+ // Fix 2: Provide default
111
+ const handleClick = onClick ?? (() => {});
112
+ handleClick();
113
+ ```
114
+
115
+ ### ReferenceError: X is not defined
116
+
117
+ ```typescript
118
+ // Pattern: Using undefined variable
119
+ console.log(userData); // userData not imported/declared
120
+
121
+ // Fix: Import or declare
122
+ import { userData } from './data';
123
+ // or
124
+ const userData = await fetchUserData();
125
+ ```
126
+
127
+ ### SyntaxError: Unexpected token
128
+
129
+ ```typescript
130
+ // Pattern: Invalid JSON
131
+ const data = JSON.parse(response);
132
+ // SyntaxError: Unexpected token '<'
133
+
134
+ // Fix: Check response before parsing
135
+ if (!response.ok) {
136
+ throw new Error(`HTTP ${response.status}`);
137
+ }
138
+ const text = await response.text();
139
+ try {
140
+ return JSON.parse(text);
141
+ } catch {
142
+ throw new Error(`Invalid JSON: ${text.slice(0, 100)}`);
143
+ }
144
+ ```
145
+
146
+ ---
147
+
148
+ ## TypeScript Errors
149
+
150
+ ### TS2339: Property does not exist
151
+
152
+ ```typescript
153
+ // Error
154
+ const env = process.env.NODE_ENV;
155
+ // Property 'NODE_ENV' does not exist on type 'ProcessEnv'
156
+
157
+ // Fix: Use bracket notation
158
+ const env = process.env['NODE_ENV'];
159
+ ```
160
+
161
+ ### TS2532: Object is possibly undefined
162
+
163
+ ```typescript
164
+ // Error
165
+ const items = array.map((x) => x.value);
166
+ // Object is possibly 'undefined'
167
+
168
+ // Fix 1: Non-null assertion (if certain)
169
+ const items = array!.map((x) => x.value);
170
+
171
+ // Fix 2: Default value
172
+ const items = (array ?? []).map((x) => x.value);
173
+
174
+ // Fix 3: Conditional
175
+ const items = array ? array.map((x) => x.value) : [];
176
+ ```
177
+
178
+ ### TS2345: Argument type mismatch
179
+
180
+ ```typescript
181
+ // Error
182
+ function greet(name: string) {}
183
+ greet(user.name); // Argument of type 'string | undefined'
184
+
185
+ // Fix 1: Provide default
186
+ greet(user.name ?? 'Guest');
187
+
188
+ // Fix 2: Assert
189
+ greet(user.name!);
190
+
191
+ // Fix 3: Guard
192
+ if (user.name) greet(user.name);
193
+ ```
194
+
195
+ ### TS7053: Index signature
196
+
197
+ ```typescript
198
+ // Error
199
+ const value = obj[key];
200
+ // Element implicitly has 'any' type
201
+
202
+ // Fix: Type the index
203
+ const value = (obj as Record<string, unknown>)[key];
204
+
205
+ // Or define proper type
206
+ interface MyObj {
207
+ [key: string]: string | undefined;
208
+ }
209
+ ```
210
+
211
+ ---
212
+
213
+ ## Build Errors
214
+
215
+ ### Module Not Found
216
+
217
+ ```bash
218
+ # Error
219
+ Cannot find module './utils' or its corresponding type declarations
220
+
221
+ # Check 1: File exists?
222
+ ls src/utils.ts
223
+
224
+ # Check 2: Extension needed?
225
+ import { helper } from './utils.js'; # ESM requires extension
226
+
227
+ # Check 3: Path alias configured?
228
+ # Check tsconfig.json paths
229
+ ```
230
+
231
+ ### Duplicate Identifier
232
+
233
+ ```bash
234
+ # Error
235
+ Duplicate identifier 'User'
236
+
237
+ # Fix: Check imports for conflicts
238
+ # May have both named and default import
239
+ import User from './User';
240
+ import { User } from './types'; # Conflict!
241
+
242
+ # Solution: Rename one
243
+ import { User as UserType } from './types';
244
+ ```
245
+
246
+ ### ESM/CJS Compatibility
247
+
248
+ ```typescript
249
+ // Error: require is not defined in ES module
250
+ const fs = require('fs');
251
+
252
+ // Fix: Use ESM import
253
+ import fs from 'fs';
254
+ import { readFileSync } from 'fs';
255
+
256
+ // If must use require in ESM
257
+ import { createRequire } from 'module';
258
+ const require = createRequire(import.meta.url);
259
+ ```
260
+
261
+ ---
262
+
263
+ ## Network & API Errors
264
+
265
+ ### CORS Errors
266
+
267
+ ```
268
+ Access to fetch at 'https://api.example.com' has been blocked by CORS policy
269
+ ```
270
+
271
+ ```typescript
272
+ // Server-side fix (add headers)
273
+ res.setHeader('Access-Control-Allow-Origin', 'https://yoursite.com');
274
+ res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
275
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
276
+
277
+ // Client-side workaround (proxy in dev)
278
+ // vite.config.ts
279
+ export default {
280
+ server: {
281
+ proxy: {
282
+ '/api': {
283
+ target: 'https://api.example.com',
284
+ changeOrigin: true,
285
+ },
286
+ },
287
+ },
288
+ };
289
+ ```
290
+
291
+ ### HTTP Error Handling
292
+
293
+ ```typescript
294
+ async function fetchWithErrorHandling<T>(url: string): Promise<T> {
295
+ const response = await fetch(url);
296
+
297
+ if (!response.ok) {
298
+ // Get error details
299
+ let message: string;
300
+ try {
301
+ const error = await response.json();
302
+ message = error.message || response.statusText;
303
+ } catch {
304
+ message = response.statusText;
305
+ }
306
+
307
+ throw new Error(`${response.status} ${message}`);
308
+ }
309
+
310
+ return response.json();
311
+ }
312
+ ```
313
+
314
+ ### Network Timeout
315
+
316
+ ```typescript
317
+ async function fetchWithTimeout(url: string, timeout = 5000) {
318
+ const controller = new AbortController();
319
+ const id = setTimeout(() => controller.abort(), timeout);
320
+
321
+ try {
322
+ const response = await fetch(url, { signal: controller.signal });
323
+ clearTimeout(id);
324
+ return response;
325
+ } catch (error) {
326
+ clearTimeout(id);
327
+ if (error instanceof Error && error.name === 'AbortError') {
328
+ throw new Error(`Request timeout after ${timeout}ms`);
329
+ }
330
+ throw error;
331
+ }
332
+ }
333
+ ```
334
+
335
+ ---
336
+
337
+ ## React Debugging
338
+
339
+ ### "Cannot update a component while rendering"
340
+
341
+ ```typescript
342
+ // Error: State update during render
343
+ function Component({ value }) {
344
+ const [state, setState] = useState(0);
345
+ setState(value); // ERROR!
346
+
347
+ // Fix: Use useEffect
348
+ useEffect(() => {
349
+ setState(value);
350
+ }, [value]);
351
+ }
352
+ ```
353
+
354
+ ### "Too many re-renders"
355
+
356
+ ```typescript
357
+ // Error: Infinite loop
358
+ function Component() {
359
+ const [count, setCount] = useState(0);
360
+ setCount(count + 1); // Causes re-render, which sets count...
361
+
362
+ // Fix: Add condition or use effect
363
+ useEffect(() => {
364
+ if (count < 10) {
365
+ setCount((c) => c + 1);
366
+ }
367
+ }, [count]);
368
+ }
369
+ ```
370
+
371
+ ### "Invalid hook call"
372
+
373
+ ```typescript
374
+ // Error: Hook outside component or conditional
375
+ function Component() {
376
+ if (condition) {
377
+ const [state] = useState(0); // ERROR!
378
+ }
379
+ }
380
+
381
+ // Fix: Hooks must be at top level
382
+ function Component() {
383
+ const [state] = useState(0); // OK
384
+ if (condition) {
385
+ // use state here
386
+ }
387
+ }
388
+ ```
389
+
390
+ ---
391
+
392
+ ## Debug Commands
393
+
394
+ ### Git - Find Breaking Commit
395
+
396
+ ```bash
397
+ # Start bisect
398
+ git bisect start
399
+ git bisect bad HEAD
400
+ git bisect good abc123 # Last known good commit
401
+
402
+ # Test and mark each commit
403
+ git bisect good # or bad
404
+
405
+ # End bisect
406
+ git bisect reset
407
+ ```
408
+
409
+ ### Find Error in Code
410
+
411
+ ```bash
412
+ # Search for error message
413
+ grep -rn "specific error text" src/
414
+
415
+ # Search for pattern
416
+ grep -rn "throw new Error" src/ --include="*.ts"
417
+
418
+ # Find file with symbol
419
+ grep -rn "functionName" src/ --include="*.ts" -l
420
+ ```
421
+
422
+ ### Bun Debugging
423
+
424
+ ```bash
425
+ # Debug mode
426
+ bun --inspect src/index.ts
427
+
428
+ # With breakpoint on start
429
+ bun --inspect-brk src/index.ts
430
+
431
+ # Low memory mode (for memory issues)
432
+ bun --smol src/index.ts
433
+ ```
434
+
435
+ ---
436
+
437
+ ## Debugging Checklist
438
+
439
+ ### Before You Start
440
+
441
+ - [ ] Can you reproduce the bug?
442
+ - [ ] Do you have the exact error message?
443
+ - [ ] What changed recently? (`git log`, `git diff`)
444
+
445
+ ### Investigation
446
+
447
+ - [ ] Read the full error message and stack trace
448
+ - [ ] Check the line number mentioned in error
449
+ - [ ] Add console.log at key points
450
+ - [ ] Check network tab for API errors
451
+
452
+ ### After Fix
453
+
454
+ - [ ] Does the fix work for all cases?
455
+ - [ ] Did you add tests to prevent regression?
456
+ - [ ] Did you handle edge cases?
457
+
458
+ ---
459
+
460
+ ## Agent Integration
461
+
462
+ This skill is used by:
463
+
464
+ - **debugger** agent
465
+ - **error-stack-analyzer** agent
466
+ - **type-error-resolver** agent
467
+ - **runtime-error-fixer** agent
468
+ - **network-debugger** agent
469
+ - **build-error-fixer** agent
470
+
471
+ ---
472
+
473
+ ## FORBIDDEN
474
+
475
+ 1. **Swallowing errors silently** - Always log or handle
476
+ 2. **Using `any` to hide errors** - Fix the actual type issue
477
+ 3. **`@ts-ignore` without comment** - Use `@ts-expect-error` with explanation
478
+ 4. **Empty catch blocks** - At minimum, log the error
479
+ 5. **Fixing symptoms not causes** - Find and fix root cause
480
+
481
+ ---
482
+
483
+ ## Version
484
+
485
+ - **v1.0.0** - Initial implementation based on 2024-2025 debugging patterns