@zimezone/z-command 1.1.0 → 1.1.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 (182) hide show
  1. package/package.json +4 -1
  2. package/templates/agents/api-documenter.agent.md +161 -0
  3. package/templates/agents/architect-review.agent.md +146 -0
  4. package/templates/agents/arm-cortex-expert.agent.md +288 -0
  5. package/templates/agents/backend-architect.agent.md +309 -0
  6. package/templates/agents/backend-security-coder.agent.md +152 -0
  7. package/templates/agents/bash-pro.agent.md +285 -0
  8. package/templates/agents/c-pro.agent.md +35 -0
  9. package/templates/agents/c4-code.agent.md +320 -0
  10. package/templates/agents/c4-component.agent.md +227 -0
  11. package/templates/agents/c4-container.agent.md +248 -0
  12. package/templates/agents/c4-context.agent.md +235 -0
  13. package/templates/agents/conductor-validator.agent.md +245 -0
  14. package/templates/agents/csharp-pro.agent.md +38 -0
  15. package/templates/agents/customer-support.agent.md +148 -0
  16. package/templates/agents/database-admin.agent.md +142 -0
  17. package/templates/agents/database-architect.agent.md +238 -0
  18. package/templates/agents/database-optimizer.agent.md +144 -0
  19. package/templates/agents/debugger.agent.md +30 -0
  20. package/templates/agents/deployment-engineer.agent.md +0 -0
  21. package/templates/agents/devops-troubleshooter.agent.md +138 -0
  22. package/templates/agents/django-pro.agent.md +159 -0
  23. package/templates/agents/docs-architect.agent.md +77 -0
  24. package/templates/agents/dotnet-architect.agent.md +175 -0
  25. package/templates/agents/dx-optimizer.agent.md +63 -0
  26. package/templates/agents/elixir-pro.agent.md +38 -0
  27. package/templates/agents/error-detective.agent.md +32 -0
  28. package/templates/agents/event-sourcing-architect.agent.md +42 -0
  29. package/templates/agents/fastapi-pro.agent.md +171 -0
  30. package/templates/agents/firmware-analyst.agent.md +330 -0
  31. package/templates/agents/frontend-security-coder.agent.md +149 -0
  32. package/templates/agents/haskell-pro.agent.md +37 -0
  33. package/templates/agents/hr-pro.agent.md +105 -0
  34. package/templates/agents/incident-responder.agent.md +190 -0
  35. package/templates/agents/ios-developer.agent.md +198 -0
  36. package/templates/agents/java-pro.agent.md +156 -0
  37. package/templates/agents/javascript-pro.agent.md +35 -0
  38. package/templates/agents/julia-pro.agent.md +187 -0
  39. package/templates/agents/legal-advisor.agent.md +49 -0
  40. package/templates/agents/malware-analyst.agent.md +272 -0
  41. package/templates/agents/mermaid-expert.agent.md +39 -0
  42. package/templates/agents/minecraft-bukkit-pro.agent.md +104 -0
  43. package/templates/agents/mobile-security-coder.agent.md +163 -0
  44. package/templates/agents/monorepo-architect.agent.md +44 -0
  45. package/templates/agents/observability-engineer.agent.md +228 -0
  46. package/templates/agents/performance-engineer.agent.md +167 -0
  47. package/templates/agents/php-pro.agent.md +43 -0
  48. package/templates/agents/posix-shell-pro.agent.md +284 -0
  49. package/templates/agents/quant-analyst.agent.md +32 -0
  50. package/templates/agents/reference-builder.agent.md +167 -0
  51. package/templates/agents/reverse-engineer.agent.md +202 -0
  52. package/templates/agents/risk-manager.agent.md +41 -0
  53. package/templates/agents/ruby-pro.agent.md +35 -0
  54. package/templates/agents/rust-pro.agent.md +156 -0
  55. package/templates/agents/sales-automator.agent.md +35 -0
  56. package/templates/agents/scala-pro.agent.md +60 -0
  57. package/templates/agents/search-specialist.agent.md +59 -0
  58. package/templates/agents/security-auditor.agent.md +138 -0
  59. package/templates/agents/seo-authority-builder.agent.md +116 -0
  60. package/templates/agents/seo-cannibalization-detector.agent.md +103 -0
  61. package/templates/agents/seo-content-auditor.agent.md +63 -0
  62. package/templates/agents/seo-content-planner.agent.md +88 -0
  63. package/templates/agents/seo-content-refresher.agent.md +98 -0
  64. package/templates/agents/seo-content-writer.agent.md +76 -0
  65. package/templates/agents/seo-keyword-strategist.agent.md +75 -0
  66. package/templates/agents/seo-meta-optimizer.agent.md +72 -0
  67. package/templates/agents/seo-snippet-hunter.agent.md +94 -0
  68. package/templates/agents/seo-structure-architect.agent.md +88 -0
  69. package/templates/agents/service-mesh-expert.agent.md +41 -0
  70. package/templates/agents/sql-pro.agent.md +146 -0
  71. package/templates/agents/tdd-orchestrator.agent.md +183 -0
  72. package/templates/agents/temporal-python-pro.agent.md +349 -0
  73. package/templates/agents/terraform-specialist.agent.md +137 -0
  74. package/templates/agents/test-automator.agent.md +203 -0
  75. package/templates/agents/threat-modeling-expert.agent.md +44 -0
  76. package/templates/agents/tutorial-engineer.agent.md +118 -0
  77. package/templates/agents/ui-ux-designer.agent.md +188 -0
  78. package/templates/agents/ui-visual-validator.agent.md +192 -0
  79. package/templates/agents/vector-database-engineer.agent.md +43 -0
  80. package/templates/skills/angular-migration/SKILL.md +410 -0
  81. package/templates/skills/api-design-principles/SKILL.md +528 -0
  82. package/templates/skills/api-design-principles/assets/api-design-checklist.md +155 -0
  83. package/templates/skills/api-design-principles/assets/rest-api-template.py +182 -0
  84. package/templates/skills/api-design-principles/references/graphql-schema-design.md +583 -0
  85. package/templates/skills/api-design-principles/references/rest-best-practices.md +408 -0
  86. package/templates/skills/architecture-decision-records/SKILL.md +428 -0
  87. package/templates/skills/architecture-patterns/SKILL.md +494 -0
  88. package/templates/skills/async-python-patterns/SKILL.md +694 -0
  89. package/templates/skills/auth-implementation-patterns/SKILL.md +634 -0
  90. package/templates/skills/changelog-automation/SKILL.md +552 -0
  91. package/templates/skills/code-review-excellence/SKILL.md +520 -0
  92. package/templates/skills/competitive-landscape/SKILL.md +479 -0
  93. package/templates/skills/context-driven-development/SKILL.md +385 -0
  94. package/templates/skills/cost-optimization/SKILL.md +274 -0
  95. package/templates/skills/cqrs-implementation/SKILL.md +554 -0
  96. package/templates/skills/data-quality-frameworks/SKILL.md +587 -0
  97. package/templates/skills/data-storytelling/SKILL.md +453 -0
  98. package/templates/skills/database-migration/SKILL.md +424 -0
  99. package/templates/skills/dbt-transformation-patterns/SKILL.md +561 -0
  100. package/templates/skills/debugging-strategies/SKILL.md +527 -0
  101. package/templates/skills/defi-protocol-templates/SKILL.md +454 -0
  102. package/templates/skills/dependency-upgrade/SKILL.md +409 -0
  103. package/templates/skills/deployment-pipeline-design/SKILL.md +359 -0
  104. package/templates/skills/distributed-tracing/SKILL.md +438 -0
  105. package/templates/skills/dotnet-backend-patterns/SKILL.md +815 -0
  106. package/templates/skills/dotnet-backend-patterns/assets/repository-template.cs +523 -0
  107. package/templates/skills/dotnet-backend-patterns/assets/service-template.cs +336 -0
  108. package/templates/skills/dotnet-backend-patterns/references/dapper-patterns.md +544 -0
  109. package/templates/skills/dotnet-backend-patterns/references/ef-core-best-practices.md +355 -0
  110. package/templates/skills/e2e-testing-patterns/SKILL.md +547 -0
  111. package/templates/skills/employment-contract-templates/SKILL.md +507 -0
  112. package/templates/skills/error-handling-patterns/SKILL.md +636 -0
  113. package/templates/skills/event-store-design/SKILL.md +437 -0
  114. package/templates/skills/fastapi-templates/SKILL.md +567 -0
  115. package/templates/skills/git-advanced-workflows/SKILL.md +400 -0
  116. package/templates/skills/github-actions-templates/SKILL.md +333 -0
  117. package/templates/skills/go-concurrency-patterns/SKILL.md +655 -0
  118. package/templates/skills/grafana-dashboards/SKILL.md +369 -0
  119. package/templates/skills/helm-chart-scaffolding/SKILL.md +544 -0
  120. package/templates/skills/helm-chart-scaffolding/assets/Chart.yaml.template +42 -0
  121. package/templates/skills/helm-chart-scaffolding/assets/values.yaml.template +185 -0
  122. package/templates/skills/helm-chart-scaffolding/references/chart-structure.md +500 -0
  123. package/templates/skills/helm-chart-scaffolding/scripts/validate-chart.sh +244 -0
  124. package/templates/skills/javascript-testing-patterns/SKILL.md +1025 -0
  125. package/templates/skills/langchain-architecture/SKILL.md +338 -0
  126. package/templates/skills/llm-evaluation/SKILL.md +471 -0
  127. package/templates/skills/microservices-patterns/SKILL.md +595 -0
  128. package/templates/skills/modern-javascript-patterns/SKILL.md +911 -0
  129. package/templates/skills/monorepo-management/SKILL.md +622 -0
  130. package/templates/skills/nextjs-app-router-patterns/SKILL.md +544 -0
  131. package/templates/skills/nodejs-backend-patterns/SKILL.md +1020 -0
  132. package/templates/skills/nx-workspace-patterns/SKILL.md +452 -0
  133. package/templates/skills/openapi-spec-generation/SKILL.md +1028 -0
  134. package/templates/skills/paypal-integration/SKILL.md +467 -0
  135. package/templates/skills/pci-compliance/SKILL.md +466 -0
  136. package/templates/skills/postgresql/SKILL.md +204 -0
  137. package/templates/skills/projection-patterns/SKILL.md +490 -0
  138. package/templates/skills/prometheus-configuration/SKILL.md +392 -0
  139. package/templates/skills/prompt-engineering-patterns/SKILL.md +201 -0
  140. package/templates/skills/prompt-engineering-patterns/assets/few-shot-examples.json +106 -0
  141. package/templates/skills/prompt-engineering-patterns/assets/prompt-template-library.md +246 -0
  142. package/templates/skills/prompt-engineering-patterns/references/chain-of-thought.md +399 -0
  143. package/templates/skills/prompt-engineering-patterns/references/few-shot-learning.md +369 -0
  144. package/templates/skills/prompt-engineering-patterns/references/prompt-optimization.md +414 -0
  145. package/templates/skills/prompt-engineering-patterns/references/prompt-templates.md +470 -0
  146. package/templates/skills/prompt-engineering-patterns/references/system-prompts.md +189 -0
  147. package/templates/skills/prompt-engineering-patterns/scripts/optimize-prompt.py +279 -0
  148. package/templates/skills/python-packaging/SKILL.md +870 -0
  149. package/templates/skills/python-performance-optimization/SKILL.md +869 -0
  150. package/templates/skills/python-testing-patterns/SKILL.md +907 -0
  151. package/templates/skills/rag-implementation/SKILL.md +403 -0
  152. package/templates/skills/react-modernization/SKILL.md +513 -0
  153. package/templates/skills/react-native-architecture/SKILL.md +671 -0
  154. package/templates/skills/react-state-management/SKILL.md +429 -0
  155. package/templates/skills/risk-metrics-calculation/SKILL.md +555 -0
  156. package/templates/skills/rust-async-patterns/SKILL.md +517 -0
  157. package/templates/skills/secrets-management/SKILL.md +346 -0
  158. package/templates/skills/security-requirement-extraction/SKILL.md +677 -0
  159. package/templates/skills/shellcheck-configuration/SKILL.md +454 -0
  160. package/templates/skills/similarity-search-patterns/SKILL.md +558 -0
  161. package/templates/skills/slo-implementation/SKILL.md +329 -0
  162. package/templates/skills/sql-optimization-patterns/SKILL.md +493 -0
  163. package/templates/skills/stripe-integration/SKILL.md +442 -0
  164. package/templates/skills/tailwind-design-system/SKILL.md +666 -0
  165. package/templates/skills/temporal-python-testing/SKILL.md +158 -0
  166. package/templates/skills/temporal-python-testing/resources/integration-testing.md +455 -0
  167. package/templates/skills/temporal-python-testing/resources/local-setup.md +553 -0
  168. package/templates/skills/temporal-python-testing/resources/replay-testing.md +462 -0
  169. package/templates/skills/temporal-python-testing/resources/unit-testing.md +328 -0
  170. package/templates/skills/terraform-module-library/SKILL.md +249 -0
  171. package/templates/skills/terraform-module-library/references/aws-modules.md +63 -0
  172. package/templates/skills/threat-mitigation-mapping/SKILL.md +745 -0
  173. package/templates/skills/track-management/SKILL.md +593 -0
  174. package/templates/skills/typescript-advanced-types/SKILL.md +717 -0
  175. package/templates/skills/uv-package-manager/SKILL.md +831 -0
  176. package/templates/skills/vector-index-tuning/SKILL.md +521 -0
  177. package/templates/skills/wcag-audit-patterns/SKILL.md +555 -0
  178. package/templates/skills/workflow-orchestration-patterns/SKILL.md +316 -0
  179. package/templates/skills/workflow-patterns/SKILL.md +623 -0
  180. package/templates/agents/game-developer.agent.md +0 -57
  181. package/templates/agents/kubernetes-specialist.agent.md +0 -56
  182. package/templates/agents/market-researcher.agent.md +0 -47
@@ -0,0 +1,527 @@
1
+ ---
2
+ name: debugging-strategies
3
+ description: Master systematic debugging techniques, profiling tools, and root cause analysis to efficiently track down bugs across any codebase or technology stack. Use when investigating bugs, performance issues, or unexpected behavior.
4
+ ---
5
+
6
+ # Debugging Strategies
7
+
8
+ Transform debugging from frustrating guesswork into systematic problem-solving with proven strategies, powerful tools, and methodical approaches.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - Tracking down elusive bugs
13
+ - Investigating performance issues
14
+ - Understanding unfamiliar codebases
15
+ - Debugging production issues
16
+ - Analyzing crash dumps and stack traces
17
+ - Profiling application performance
18
+ - Investigating memory leaks
19
+ - Debugging distributed systems
20
+
21
+ ## Core Principles
22
+
23
+ ### 1. The Scientific Method
24
+
25
+ **1. Observe**: What's the actual behavior?
26
+ **2. Hypothesize**: What could be causing it?
27
+ **3. Experiment**: Test your hypothesis
28
+ **4. Analyze**: Did it prove/disprove your theory?
29
+ **5. Repeat**: Until you find the root cause
30
+
31
+ ### 2. Debugging Mindset
32
+
33
+ **Don't Assume:**
34
+ - "It can't be X" - Yes it can
35
+ - "I didn't change Y" - Check anyway
36
+ - "It works on my machine" - Find out why
37
+
38
+ **Do:**
39
+ - Reproduce consistently
40
+ - Isolate the problem
41
+ - Keep detailed notes
42
+ - Question everything
43
+ - Take breaks when stuck
44
+
45
+ ### 3. Rubber Duck Debugging
46
+
47
+ Explain your code and problem out loud (to a rubber duck, colleague, or yourself). Often reveals the issue.
48
+
49
+ ## Systematic Debugging Process
50
+
51
+ ### Phase 1: Reproduce
52
+
53
+ ```markdown
54
+ ## Reproduction Checklist
55
+
56
+ 1. **Can you reproduce it?**
57
+ - Always? Sometimes? Randomly?
58
+ - Specific conditions needed?
59
+ - Can others reproduce it?
60
+
61
+ 2. **Create minimal reproduction**
62
+ - Simplify to smallest example
63
+ - Remove unrelated code
64
+ - Isolate the problem
65
+
66
+ 3. **Document steps**
67
+ - Write down exact steps
68
+ - Note environment details
69
+ - Capture error messages
70
+ ```
71
+
72
+ ### Phase 2: Gather Information
73
+
74
+ ```markdown
75
+ ## Information Collection
76
+
77
+ 1. **Error Messages**
78
+ - Full stack trace
79
+ - Error codes
80
+ - Console/log output
81
+
82
+ 2. **Environment**
83
+ - OS version
84
+ - Language/runtime version
85
+ - Dependencies versions
86
+ - Environment variables
87
+
88
+ 3. **Recent Changes**
89
+ - Git history
90
+ - Deployment timeline
91
+ - Configuration changes
92
+
93
+ 4. **Scope**
94
+ - Affects all users or specific ones?
95
+ - All browsers or specific ones?
96
+ - Production only or also dev?
97
+ ```
98
+
99
+ ### Phase 3: Form Hypothesis
100
+
101
+ ```markdown
102
+ ## Hypothesis Formation
103
+
104
+ Based on gathered info, ask:
105
+
106
+ 1. **What changed?**
107
+ - Recent code changes
108
+ - Dependency updates
109
+ - Infrastructure changes
110
+
111
+ 2. **What's different?**
112
+ - Working vs broken environment
113
+ - Working vs broken user
114
+ - Before vs after
115
+
116
+ 3. **Where could this fail?**
117
+ - Input validation
118
+ - Business logic
119
+ - Data layer
120
+ - External services
121
+ ```
122
+
123
+ ### Phase 4: Test & Verify
124
+
125
+ ```markdown
126
+ ## Testing Strategies
127
+
128
+ 1. **Binary Search**
129
+ - Comment out half the code
130
+ - Narrow down problematic section
131
+ - Repeat until found
132
+
133
+ 2. **Add Logging**
134
+ - Strategic console.log/print
135
+ - Track variable values
136
+ - Trace execution flow
137
+
138
+ 3. **Isolate Components**
139
+ - Test each piece separately
140
+ - Mock dependencies
141
+ - Remove complexity
142
+
143
+ 4. **Compare Working vs Broken**
144
+ - Diff configurations
145
+ - Diff environments
146
+ - Diff data
147
+ ```
148
+
149
+ ## Debugging Tools
150
+
151
+ ### JavaScript/TypeScript Debugging
152
+
153
+ ```typescript
154
+ // Chrome DevTools Debugger
155
+ function processOrder(order: Order) {
156
+ debugger; // Execution pauses here
157
+
158
+ const total = calculateTotal(order);
159
+ console.log('Total:', total);
160
+
161
+ // Conditional breakpoint
162
+ if (order.items.length > 10) {
163
+ debugger; // Only breaks if condition true
164
+ }
165
+
166
+ return total;
167
+ }
168
+
169
+ // Console debugging techniques
170
+ console.log('Value:', value); // Basic
171
+ console.table(arrayOfObjects); // Table format
172
+ console.time('operation'); /* code */ console.timeEnd('operation'); // Timing
173
+ console.trace(); // Stack trace
174
+ console.assert(value > 0, 'Value must be positive'); // Assertion
175
+
176
+ // Performance profiling
177
+ performance.mark('start-operation');
178
+ // ... operation code
179
+ performance.mark('end-operation');
180
+ performance.measure('operation', 'start-operation', 'end-operation');
181
+ console.log(performance.getEntriesByType('measure'));
182
+ ```
183
+
184
+ **VS Code Debugger Configuration:**
185
+ ```json
186
+ // .vscode/launch.json
187
+ {
188
+ "version": "0.2.0",
189
+ "configurations": [
190
+ {
191
+ "type": "node",
192
+ "request": "launch",
193
+ "name": "Debug Program",
194
+ "program": "${workspaceFolder}/src/index.ts",
195
+ "preLaunchTask": "tsc: build - tsconfig.json",
196
+ "outFiles": ["${workspaceFolder}/dist/**/*.js"],
197
+ "skipFiles": ["<node_internals>/**"]
198
+ },
199
+ {
200
+ "type": "node",
201
+ "request": "launch",
202
+ "name": "Debug Tests",
203
+ "program": "${workspaceFolder}/node_modules/jest/bin/jest",
204
+ "args": ["--runInBand", "--no-cache"],
205
+ "console": "integratedTerminal"
206
+ }
207
+ ]
208
+ }
209
+ ```
210
+
211
+ ### Python Debugging
212
+
213
+ ```python
214
+ # Built-in debugger (pdb)
215
+ import pdb
216
+
217
+ def calculate_total(items):
218
+ total = 0
219
+ pdb.set_trace() # Debugger starts here
220
+
221
+ for item in items:
222
+ total += item.price * item.quantity
223
+
224
+ return total
225
+
226
+ # Breakpoint (Python 3.7+)
227
+ def process_order(order):
228
+ breakpoint() # More convenient than pdb.set_trace()
229
+ # ... code
230
+
231
+ # Post-mortem debugging
232
+ try:
233
+ risky_operation()
234
+ except Exception:
235
+ import pdb
236
+ pdb.post_mortem() # Debug at exception point
237
+
238
+ # IPython debugging (ipdb)
239
+ from ipdb import set_trace
240
+ set_trace() # Better interface than pdb
241
+
242
+ # Logging for debugging
243
+ import logging
244
+ logging.basicConfig(level=logging.DEBUG)
245
+ logger = logging.getLogger(__name__)
246
+
247
+ def fetch_user(user_id):
248
+ logger.debug(f'Fetching user: {user_id}')
249
+ user = db.query(User).get(user_id)
250
+ logger.debug(f'Found user: {user}')
251
+ return user
252
+
253
+ # Profile performance
254
+ import cProfile
255
+ import pstats
256
+
257
+ cProfile.run('slow_function()', 'profile_stats')
258
+ stats = pstats.Stats('profile_stats')
259
+ stats.sort_stats('cumulative')
260
+ stats.print_stats(10) # Top 10 slowest
261
+ ```
262
+
263
+ ### Go Debugging
264
+
265
+ ```go
266
+ // Delve debugger
267
+ // Install: go install github.com/go-delve/delve/cmd/dlv@latest
268
+ // Run: dlv debug main.go
269
+
270
+ import (
271
+ "fmt"
272
+ "runtime"
273
+ "runtime/debug"
274
+ )
275
+
276
+ // Print stack trace
277
+ func debugStack() {
278
+ debug.PrintStack()
279
+ }
280
+
281
+ // Panic recovery with debugging
282
+ func processRequest() {
283
+ defer func() {
284
+ if r := recover(); r != nil {
285
+ fmt.Println("Panic:", r)
286
+ debug.PrintStack()
287
+ }
288
+ }()
289
+
290
+ // ... code that might panic
291
+ }
292
+
293
+ // Memory profiling
294
+ import _ "net/http/pprof"
295
+ // Visit http://localhost:6060/debug/pprof/
296
+
297
+ // CPU profiling
298
+ import (
299
+ "os"
300
+ "runtime/pprof"
301
+ )
302
+
303
+ f, _ := os.Create("cpu.prof")
304
+ pprof.StartCPUProfile(f)
305
+ defer pprof.StopCPUProfile()
306
+ // ... code to profile
307
+ ```
308
+
309
+ ## Advanced Debugging Techniques
310
+
311
+ ### Technique 1: Binary Search Debugging
312
+
313
+ ```bash
314
+ # Git bisect for finding regression
315
+ git bisect start
316
+ git bisect bad # Current commit is bad
317
+ git bisect good v1.0.0 # v1.0.0 was good
318
+
319
+ # Git checks out middle commit
320
+ # Test it, then:
321
+ git bisect good # if it works
322
+ git bisect bad # if it's broken
323
+
324
+ # Continue until bug found
325
+ git bisect reset # when done
326
+ ```
327
+
328
+ ### Technique 2: Differential Debugging
329
+
330
+ Compare working vs broken:
331
+
332
+ ```markdown
333
+ ## What's Different?
334
+
335
+ | Aspect | Working | Broken |
336
+ |--------------|-----------------|-----------------|
337
+ | Environment | Development | Production |
338
+ | Node version | 18.16.0 | 18.15.0 |
339
+ | Data | Empty DB | 1M records |
340
+ | User | Admin | Regular user |
341
+ | Browser | Chrome | Safari |
342
+ | Time | During day | After midnight |
343
+
344
+ Hypothesis: Time-based issue? Check timezone handling.
345
+ ```
346
+
347
+ ### Technique 3: Trace Debugging
348
+
349
+ ```typescript
350
+ // Function call tracing
351
+ function trace(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
352
+ const originalMethod = descriptor.value;
353
+
354
+ descriptor.value = function(...args: any[]) {
355
+ console.log(`Calling ${propertyKey} with args:`, args);
356
+ const result = originalMethod.apply(this, args);
357
+ console.log(`${propertyKey} returned:`, result);
358
+ return result;
359
+ };
360
+
361
+ return descriptor;
362
+ }
363
+
364
+ class OrderService {
365
+ @trace
366
+ calculateTotal(items: Item[]): number {
367
+ return items.reduce((sum, item) => sum + item.price, 0);
368
+ }
369
+ }
370
+ ```
371
+
372
+ ### Technique 4: Memory Leak Detection
373
+
374
+ ```typescript
375
+ // Chrome DevTools Memory Profiler
376
+ // 1. Take heap snapshot
377
+ // 2. Perform action
378
+ // 3. Take another snapshot
379
+ // 4. Compare snapshots
380
+
381
+ // Node.js memory debugging
382
+ if (process.memoryUsage().heapUsed > 500 * 1024 * 1024) {
383
+ console.warn('High memory usage:', process.memoryUsage());
384
+
385
+ // Generate heap dump
386
+ require('v8').writeHeapSnapshot();
387
+ }
388
+
389
+ // Find memory leaks in tests
390
+ let beforeMemory: number;
391
+
392
+ beforeEach(() => {
393
+ beforeMemory = process.memoryUsage().heapUsed;
394
+ });
395
+
396
+ afterEach(() => {
397
+ const afterMemory = process.memoryUsage().heapUsed;
398
+ const diff = afterMemory - beforeMemory;
399
+
400
+ if (diff > 10 * 1024 * 1024) { // 10MB threshold
401
+ console.warn(`Possible memory leak: ${diff / 1024 / 1024}MB`);
402
+ }
403
+ });
404
+ ```
405
+
406
+ ## Debugging Patterns by Issue Type
407
+
408
+ ### Pattern 1: Intermittent Bugs
409
+
410
+ ```markdown
411
+ ## Strategies for Flaky Bugs
412
+
413
+ 1. **Add extensive logging**
414
+ - Log timing information
415
+ - Log all state transitions
416
+ - Log external interactions
417
+
418
+ 2. **Look for race conditions**
419
+ - Concurrent access to shared state
420
+ - Async operations completing out of order
421
+ - Missing synchronization
422
+
423
+ 3. **Check timing dependencies**
424
+ - setTimeout/setInterval
425
+ - Promise resolution order
426
+ - Animation frame timing
427
+
428
+ 4. **Stress test**
429
+ - Run many times
430
+ - Vary timing
431
+ - Simulate load
432
+ ```
433
+
434
+ ### Pattern 2: Performance Issues
435
+
436
+ ```markdown
437
+ ## Performance Debugging
438
+
439
+ 1. **Profile first**
440
+ - Don't optimize blindly
441
+ - Measure before and after
442
+ - Find bottlenecks
443
+
444
+ 2. **Common culprits**
445
+ - N+1 queries
446
+ - Unnecessary re-renders
447
+ - Large data processing
448
+ - Synchronous I/O
449
+
450
+ 3. **Tools**
451
+ - Browser DevTools Performance tab
452
+ - Lighthouse
453
+ - Python: cProfile, line_profiler
454
+ - Node: clinic.js, 0x
455
+ ```
456
+
457
+ ### Pattern 3: Production Bugs
458
+
459
+ ```markdown
460
+ ## Production Debugging
461
+
462
+ 1. **Gather evidence**
463
+ - Error tracking (Sentry, Bugsnag)
464
+ - Application logs
465
+ - User reports
466
+ - Metrics/monitoring
467
+
468
+ 2. **Reproduce locally**
469
+ - Use production data (anonymized)
470
+ - Match environment
471
+ - Follow exact steps
472
+
473
+ 3. **Safe investigation**
474
+ - Don't change production
475
+ - Use feature flags
476
+ - Add monitoring/logging
477
+ - Test fixes in staging
478
+ ```
479
+
480
+ ## Best Practices
481
+
482
+ 1. **Reproduce First**: Can't fix what you can't reproduce
483
+ 2. **Isolate the Problem**: Remove complexity until minimal case
484
+ 3. **Read Error Messages**: They're usually helpful
485
+ 4. **Check Recent Changes**: Most bugs are recent
486
+ 5. **Use Version Control**: Git bisect, blame, history
487
+ 6. **Take Breaks**: Fresh eyes see better
488
+ 7. **Document Findings**: Help future you
489
+ 8. **Fix Root Cause**: Not just symptoms
490
+
491
+ ## Common Debugging Mistakes
492
+
493
+ - **Making Multiple Changes**: Change one thing at a time
494
+ - **Not Reading Error Messages**: Read the full stack trace
495
+ - **Assuming It's Complex**: Often it's simple
496
+ - **Debug Logging in Prod**: Remove before shipping
497
+ - **Not Using Debugger**: console.log isn't always best
498
+ - **Giving Up Too Soon**: Persistence pays off
499
+ - **Not Testing the Fix**: Verify it actually works
500
+
501
+ ## Quick Debugging Checklist
502
+
503
+ ```markdown
504
+ ## When Stuck, Check:
505
+
506
+ - [ ] Spelling errors (typos in variable names)
507
+ - [ ] Case sensitivity (fileName vs filename)
508
+ - [ ] Null/undefined values
509
+ - [ ] Array index off-by-one
510
+ - [ ] Async timing (race conditions)
511
+ - [ ] Scope issues (closure, hoisting)
512
+ - [ ] Type mismatches
513
+ - [ ] Missing dependencies
514
+ - [ ] Environment variables
515
+ - [ ] File paths (absolute vs relative)
516
+ - [ ] Cache issues (clear cache)
517
+ - [ ] Stale data (refresh database)
518
+ ```
519
+
520
+ ## Resources
521
+
522
+ - **references/debugging-tools-guide.md**: Comprehensive tool documentation
523
+ - **references/performance-profiling.md**: Performance debugging guide
524
+ - **references/production-debugging.md**: Debugging live systems
525
+ - **assets/debugging-checklist.md**: Quick reference checklist
526
+ - **assets/common-bugs.md**: Common bug patterns
527
+ - **scripts/debug-helper.ts**: Debugging utility functions