@el-j/magic-helix-core 4.0.0-beta.1 → 4.0.0-beta.3
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.
- package/dist/index-B88j4AyE.js +13 -0
- package/dist/index-B88j4AyE.js.map +1 -0
- package/dist/index-CY-pQbuu.cjs +2 -0
- package/dist/index-CY-pQbuu.cjs.map +1 -0
- package/dist/index.cjs +75 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.mjs +2234 -51
- package/dist/index.mjs.map +1 -1
- package/dist/pattern-combiner.d.ts +1 -1
- package/dist/plugin-loader.d.ts +7 -1
- package/package.json +4 -4
- package/dist/BasePlugin-6wv0hYJ9.js +0 -98
- package/dist/BasePlugin-6wv0hYJ9.js.map +0 -1
- package/dist/BasePlugin-odQJAKA-.cjs +0 -2
- package/dist/BasePlugin-odQJAKA-.cjs.map +0 -1
- package/dist/builtin-plugins/base/BasePlugin.d.ts +0 -69
- package/dist/builtin-plugins/csharp/index.d.ts +0 -20
- package/dist/builtin-plugins/go/index.d.ts +0 -23
- package/dist/builtin-plugins/index.d.ts +0 -15
- package/dist/builtin-plugins/java/index.d.ts +0 -22
- package/dist/builtin-plugins/nodejs/index.d.ts +0 -44
- package/dist/builtin-plugins/php/index.d.ts +0 -20
- package/dist/builtin-plugins/python/index.d.ts +0 -27
- package/dist/builtin-plugins/ruby/index.d.ts +0 -20
- package/dist/builtin-plugins/rust/index.d.ts +0 -53
- package/dist/builtin-plugins/swift/index.d.ts +0 -22
- package/dist/default_templates/angular/angular-core.md +0 -19
- package/dist/default_templates/architecture/codeowners.md +0 -123
- package/dist/default_templates/architecture/monorepo.md +0 -146
- package/dist/default_templates/architecture/nx.md +0 -122
- package/dist/default_templates/architecture/turborepo.md +0 -114
- package/dist/default_templates/ci/github-actions.md +0 -268
- package/dist/default_templates/ci/gitlab-ci.md +0 -330
- package/dist/default_templates/containers/docker-multistage.md +0 -120
- package/dist/default_templates/containers/kubernetes-deploy.md +0 -210
- package/dist/default_templates/devops/docker-compose.md +0 -111
- package/dist/default_templates/devops/docker-dockerfile.md +0 -94
- package/dist/default_templates/devops/github-actions.md +0 -160
- package/dist/default_templates/devops/gitlab-ci.md +0 -210
- package/dist/default_templates/dotnet/framework-aspnetcore.md +0 -205
- package/dist/default_templates/dotnet/framework-blazor.md +0 -271
- package/dist/default_templates/dotnet/lang-csharp.md +0 -162
- package/dist/default_templates/generic/lang-typescript.md +0 -11
- package/dist/default_templates/generic/state-redux.md +0 -21
- package/dist/default_templates/generic/state-rxjs.md +0 -6
- package/dist/default_templates/generic/style-mui.md +0 -23
- package/dist/default_templates/generic/style-tailwind.md +0 -6
- package/dist/default_templates/generic/test-cypress.md +0 -21
- package/dist/default_templates/generic/test-jest.md +0 -20
- package/dist/default_templates/generic/test-playwright.md +0 -21
- package/dist/default_templates/generic/test-vitest.md +0 -6
- package/dist/default_templates/go/lang-go.md +0 -571
- package/dist/default_templates/java/build-gradle.md +0 -102
- package/dist/default_templates/java/build-maven.md +0 -86
- package/dist/default_templates/java/framework-spring-boot.md +0 -179
- package/dist/default_templates/java/lang-java.md +0 -78
- package/dist/default_templates/java/lang-kotlin.md +0 -88
- package/dist/default_templates/meta/magic-helix-meta.md +0 -213
- package/dist/default_templates/meta/meta-debug.md +0 -459
- package/dist/default_templates/meta/meta-implement.md +0 -450
- package/dist/default_templates/meta/meta-roadmap.md +0 -265
- package/dist/default_templates/nestjs/nestjs-core.md +0 -7
- package/dist/default_templates/patterns/architecture/clean-architecture.md +0 -469
- package/dist/default_templates/patterns/architecture/dependency-injection.md +0 -517
- package/dist/default_templates/patterns/architecture/domain-driven-design.md +0 -621
- package/dist/default_templates/patterns/architecture/layered-architecture.md +0 -382
- package/dist/default_templates/patterns/architecture/repository-pattern.md +0 -408
- package/dist/default_templates/patterns/domain-expertise/nextjs-rules.md +0 -115
- package/dist/default_templates/patterns/domain-expertise/react-patterns.md +0 -181
- package/dist/default_templates/patterns/domain-expertise/server-components.md +0 -212
- package/dist/default_templates/patterns/domain-expertise/shadcn-ui.md +0 -52
- package/dist/default_templates/patterns/domain-expertise/tailwind-patterns.md +0 -52
- package/dist/default_templates/patterns/environment/container-awareness.md +0 -17
- package/dist/default_templates/patterns/environment/ide-features.md +0 -17
- package/dist/default_templates/patterns/environment/os-commands.md +0 -17
- package/dist/default_templates/patterns/organization/heading-hierarchy.md +0 -103
- package/dist/default_templates/patterns/organization/sequential-workflows.md +0 -102
- package/dist/default_templates/patterns/organization/xml-rule-groups.md +0 -64
- package/dist/default_templates/patterns/reasoning/agent-loop.md +0 -151
- package/dist/default_templates/patterns/reasoning/confirmation-gates.md +0 -141
- package/dist/default_templates/patterns/reasoning/dependency-analysis.md +0 -132
- package/dist/default_templates/patterns/reasoning/one-tool-per-iteration.md +0 -152
- package/dist/default_templates/patterns/reasoning/preview-before-action.md +0 -194
- package/dist/default_templates/patterns/reasoning/reflection-checkpoints.md +0 -166
- package/dist/default_templates/patterns/reasoning/result-verification.md +0 -157
- package/dist/default_templates/patterns/reasoning/subtask-breakdown.md +0 -131
- package/dist/default_templates/patterns/reasoning/thinking-tags.md +0 -100
- package/dist/default_templates/patterns/role-definition/capability-declarations.md +0 -72
- package/dist/default_templates/patterns/role-definition/expert-identity.md +0 -45
- package/dist/default_templates/patterns/role-definition/scope-boundaries.md +0 -61
- package/dist/default_templates/patterns/safety/code-safety-rules.md +0 -17
- package/dist/default_templates/patterns/safety/credential-handling.md +0 -17
- package/dist/default_templates/patterns/safety/destructive-warnings.md +0 -17
- package/dist/default_templates/patterns/safety/refusal-messages.md +0 -17
- package/dist/default_templates/patterns/tone/adaptive-tone.md +0 -17
- package/dist/default_templates/patterns/tone/concise-communication.md +0 -17
- package/dist/default_templates/patterns/tone/forbidden-phrases.md +0 -17
- package/dist/default_templates/patterns/tool-guidelines/function-schemas.md +0 -143
- package/dist/default_templates/patterns/tool-guidelines/parameter-examples.md +0 -137
- package/dist/default_templates/patterns/tool-guidelines/usage-policies.md +0 -105
- package/dist/default_templates/php/framework-laravel.md +0 -112
- package/dist/default_templates/php/lang-php.md +0 -94
- package/dist/default_templates/python/lang-python.md +0 -508
- package/dist/default_templates/react/react-core.md +0 -677
- package/dist/default_templates/react/react-zustand.md +0 -7
- package/dist/default_templates/ruby/framework-rails.md +0 -309
- package/dist/default_templates/ruby/framework-sinatra.md +0 -227
- package/dist/default_templates/ruby/lang-ruby.md +0 -216
- package/dist/default_templates/rust/lang-rust.md +0 -89
- package/dist/default_templates/swift/framework-vapor.md +0 -352
- package/dist/default_templates/swift/lang-swift.md +0 -291
- package/dist/default_templates/vue/style-primevue.md +0 -6
- package/dist/default_templates/vue/style-quasar.md +0 -22
- package/dist/default_templates/vue/vue-core.md +0 -28
- package/dist/default_templates/vue/vue-pinia.md +0 -5
- package/dist/index-AkVwRl-r.js +0 -92
- package/dist/index-AkVwRl-r.js.map +0 -1
- package/dist/index-B6BeG1yT.cjs +0 -68
- package/dist/index-B6BeG1yT.cjs.map +0 -1
- package/dist/index-B8pyjKdF.js +0 -94
- package/dist/index-B8pyjKdF.js.map +0 -1
- package/dist/index-B_6W_RnJ.cjs +0 -76
- package/dist/index-B_6W_RnJ.cjs.map +0 -1
- package/dist/index-Bg8DD8ku.js +0 -216
- package/dist/index-Bg8DD8ku.js.map +0 -1
- package/dist/index-BkJhe5Af.js +0 -1748
- package/dist/index-BkJhe5Af.js.map +0 -1
- package/dist/index-Bv4Q1Pr7.cjs +0 -33
- package/dist/index-Bv4Q1Pr7.cjs.map +0 -1
- package/dist/index-CN8J45Nc.cjs +0 -24
- package/dist/index-CN8J45Nc.cjs.map +0 -1
- package/dist/index-CPbv2Od1.js +0 -62
- package/dist/index-CPbv2Od1.js.map +0 -1
- package/dist/index-Cf-MC6Al.js +0 -63
- package/dist/index-Cf-MC6Al.js.map +0 -1
- package/dist/index-DDPXXXDy.cjs +0 -19
- package/dist/index-DDPXXXDy.cjs.map +0 -1
- package/dist/index-DO30AzDe.cjs +0 -19
- package/dist/index-DO30AzDe.cjs.map +0 -1
- package/dist/index-Dm37u5ut.js +0 -2128
- package/dist/index-Dm37u5ut.js.map +0 -1
- package/dist/index-DqHvgoXJ.cjs +0 -19
- package/dist/index-DqHvgoXJ.cjs.map +0 -1
- package/dist/index-J1qAfsnO.cjs +0 -2
- package/dist/index-J1qAfsnO.cjs.map +0 -1
- package/dist/index-Jz0HYZ7B.js +0 -13
- package/dist/index-Jz0HYZ7B.js.map +0 -1
- package/dist/index-K39pdw94.cjs +0 -31
- package/dist/index-K39pdw94.cjs.map +0 -1
- package/dist/index-L3IVvhd1.cjs +0 -89
- package/dist/index-L3IVvhd1.cjs.map +0 -1
- package/dist/index-OT2XAJkc.js +0 -117
- package/dist/index-OT2XAJkc.js.map +0 -1
- package/dist/index-TPAX4XKg.cjs +0 -30
- package/dist/index-TPAX4XKg.cjs.map +0 -1
- package/dist/index-WmVSB57y.js +0 -107
- package/dist/index-WmVSB57y.js.map +0 -1
- package/dist/index-mYXvc3Fs.js +0 -68
- package/dist/index-mYXvc3Fs.js.map +0 -1
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
# 🪄 Magic Helix: Universal AI Agent Optimization
|
|
2
|
-
|
|
3
|
-
This instruction file teaches AI agents to work more efficiently with your codebase.
|
|
4
|
-
|
|
5
|
-
## Core Principles for Effective Agent Work
|
|
6
|
-
|
|
7
|
-
### 1. Task Management & Progress Tracking
|
|
8
|
-
|
|
9
|
-
**Create structured todo lists** for multi-step work:
|
|
10
|
-
- Break complex requests into 3-7 concrete, actionable steps
|
|
11
|
-
- Mark tasks `in-progress` before starting
|
|
12
|
-
- Mark tasks `completed` immediately after finishing
|
|
13
|
-
- Update progress frequently for user visibility
|
|
14
|
-
|
|
15
|
-
**Example workflow:**
|
|
16
|
-
```
|
|
17
|
-
User: "Add authentication to the app"
|
|
18
|
-
|
|
19
|
-
Agent creates:
|
|
20
|
-
1. [ ] Research existing auth patterns in codebase
|
|
21
|
-
2. [ ] Create authentication middleware
|
|
22
|
-
3. [ ] Add login/logout routes
|
|
23
|
-
4. [ ] Update user model with auth fields
|
|
24
|
-
5. [ ] Write tests for auth flows
|
|
25
|
-
6. [ ] Update documentation
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### 2. Efficient Context Gathering
|
|
29
|
-
|
|
30
|
-
**Batch parallel operations** to minimize latency:
|
|
31
|
-
- Read multiple files simultaneously, not sequentially
|
|
32
|
-
- Search multiple patterns in one query using alternation: `(pattern1|pattern2|pattern3)`
|
|
33
|
-
- Deduplicate file paths before reading to avoid redundant operations
|
|
34
|
-
|
|
35
|
-
**Smart search strategies:**
|
|
36
|
-
- Use `semantic_search` for high-level code discovery (finding similar implementations)
|
|
37
|
-
- Use `grep_search` for specific strings/patterns in known areas
|
|
38
|
-
- Use alternation in regex: `function|method|class` instead of multiple searches
|
|
39
|
-
|
|
40
|
-
**Get enough context to act, then proceed** - don't over-research before implementation.
|
|
41
|
-
|
|
42
|
-
### 3. Code Editing Best Practices
|
|
43
|
-
|
|
44
|
-
**Read surrounding context** before editing:
|
|
45
|
-
- Include 3-5 lines before and after the target code
|
|
46
|
-
- Ensure `oldString` is unique enough to match only once
|
|
47
|
-
- Verify the change won't break surrounding logic
|
|
48
|
-
|
|
49
|
-
**Prefer batch edits** for independent changes:
|
|
50
|
-
- Use `multi_replace_string_in_file` for multiple unrelated edits
|
|
51
|
-
- One tool call is faster than sequential calls
|
|
52
|
-
- Only works for truly independent changes (no dependencies between edits)
|
|
53
|
-
|
|
54
|
-
**Verify after editing:**
|
|
55
|
-
- Check for compilation/lint errors immediately
|
|
56
|
-
- Run tests if modifying critical code
|
|
57
|
-
- Read the file back if the change was complex
|
|
58
|
-
|
|
59
|
-
### 4. Communication Style
|
|
60
|
-
|
|
61
|
-
**Be concise and direct:**
|
|
62
|
-
- Match response length to task complexity
|
|
63
|
-
- No unnecessary preamble: avoid "I will now...", "Here's the...", "Let me..."
|
|
64
|
-
- Confirm completions briefly: "Updated 3 files" not explaining each edit
|
|
65
|
-
- Get straight to the point
|
|
66
|
-
|
|
67
|
-
**Use proper formatting:**
|
|
68
|
-
- Wrap code symbols in backticks: `functionName`, `fileName.ts`
|
|
69
|
-
- Use code blocks for multi-line code
|
|
70
|
-
- Use bullet points for lists
|
|
71
|
-
- Bold important terms
|
|
72
|
-
|
|
73
|
-
**Forbidden phrases:**
|
|
74
|
-
- "Great!", "Certainly!", "Sure!", "Of course!"
|
|
75
|
-
- "Let me help you with that"
|
|
76
|
-
- Unnecessary apologies or enthusiasm
|
|
77
|
-
- Redundant confirmations
|
|
78
|
-
|
|
79
|
-
### 5. Tool Usage Guidelines
|
|
80
|
-
|
|
81
|
-
**Check tool availability** before using:
|
|
82
|
-
- Tools may be disabled or unavailable
|
|
83
|
-
- Don't reference tools that aren't currently accessible
|
|
84
|
-
|
|
85
|
-
**Never announce tool names** to users:
|
|
86
|
-
- Say "I'll run the command" not "I'll use run_in_terminal"
|
|
87
|
-
- Say "I'll search the codebase" not "I'll use semantic_search"
|
|
88
|
-
- Focus on what you're doing, not how
|
|
89
|
-
|
|
90
|
-
**Use absolute paths** for file operations:
|
|
91
|
-
- Always resolve to full paths
|
|
92
|
-
- Don't rely on relative paths
|
|
93
|
-
- Handle URI schemes (untitled:, vscode-userdata:) correctly
|
|
94
|
-
|
|
95
|
-
**Parallelize wisely:**
|
|
96
|
-
- ✅ DO parallelize: file reads, searches, analysis
|
|
97
|
-
- ❌ DON'T parallelize: terminal commands, sequential workflows
|
|
98
|
-
|
|
99
|
-
### 6. Project Understanding
|
|
100
|
-
|
|
101
|
-
**Start with high-level discovery:**
|
|
102
|
-
1. Use `semantic_search` to understand codebase architecture
|
|
103
|
-
2. Use `grep_search` for specific strings once you know where to look
|
|
104
|
-
3. List directories to understand structure before making assumptions
|
|
105
|
-
4. Check for errors with `get_errors` after making changes
|
|
106
|
-
|
|
107
|
-
**Understand before implementing:**
|
|
108
|
-
- Search for similar existing implementations
|
|
109
|
-
- Identify patterns and conventions in the codebase
|
|
110
|
-
- Match existing code style and architecture
|
|
111
|
-
- Ask clarifying questions if requirements are ambiguous
|
|
112
|
-
|
|
113
|
-
## Task-Specific Strategies
|
|
114
|
-
|
|
115
|
-
### When Creating Roadmaps or Plans
|
|
116
|
-
|
|
117
|
-
1. **Clarify the request**: Rephrase to confirm understanding
|
|
118
|
-
2. **Research existing architecture**: Find similar features/patterns
|
|
119
|
-
3. **Create phased plan**: Break into logical phases with dependencies
|
|
120
|
-
4. **Define success criteria**: How will we know each phase is done?
|
|
121
|
-
5. **Identify risks**: What could go wrong?
|
|
122
|
-
|
|
123
|
-
### When Implementing Features
|
|
124
|
-
|
|
125
|
-
1. **Search for similar implementations**: Learn from existing code
|
|
126
|
-
2. **Identify all affected files**: Types, logic, tests, docs
|
|
127
|
-
3. **Plan changes in logical order**: Types → interfaces → implementation → tests
|
|
128
|
-
4. **Make incremental changes**: One logical unit at a time
|
|
129
|
-
5. **Verify compilation**: Check after each major change
|
|
130
|
-
6. **Update tests**: Ensure existing tests pass, add new ones
|
|
131
|
-
|
|
132
|
-
### When Debugging Issues
|
|
133
|
-
|
|
134
|
-
1. **Reproduce the error**: Verify it happens consistently
|
|
135
|
-
2. **Read error messages completely**: Don't skim, read fully
|
|
136
|
-
3. **Check recent changes**: Use git diff, check what changed
|
|
137
|
-
4. **Form hypotheses**: List possible causes
|
|
138
|
-
5. **Test incrementally**: Verify each hypothesis systematically
|
|
139
|
-
6. **Fix root cause**: Don't just treat symptoms
|
|
140
|
-
|
|
141
|
-
### When Refactoring Code
|
|
142
|
-
|
|
143
|
-
1. **Understand current behavior**: Read and comprehend existing code
|
|
144
|
-
2. **Ensure test coverage**: Write tests if missing
|
|
145
|
-
3. **Make small changes**: Incremental refactors are safer
|
|
146
|
-
4. **Verify tests pass**: After each refactor step
|
|
147
|
-
5. **Maintain backwards compatibility**: Unless explicitly breaking
|
|
148
|
-
6. **Update documentation**: Keep docs in sync
|
|
149
|
-
|
|
150
|
-
## Error Handling & Recovery
|
|
151
|
-
|
|
152
|
-
**When errors occur:**
|
|
153
|
-
- Read the full error message (don't skip details)
|
|
154
|
-
- Check the file and line number referenced
|
|
155
|
-
- Look for stack traces or additional context
|
|
156
|
-
- Try the obvious fix first
|
|
157
|
-
- If stuck, ask for clarification
|
|
158
|
-
|
|
159
|
-
**Never:**
|
|
160
|
-
- Ignore compiler/lint errors
|
|
161
|
-
- Assume success without verification
|
|
162
|
-
- Continue with broken code
|
|
163
|
-
- Skip error checking
|
|
164
|
-
|
|
165
|
-
## File Operations Safety
|
|
166
|
-
|
|
167
|
-
**Before modifying files:**
|
|
168
|
-
1. Explain what you're about to change
|
|
169
|
-
2. Show preview of changes when significant
|
|
170
|
-
3. Wait for confirmation if potentially destructive
|
|
171
|
-
4. Never assume success—verify the result
|
|
172
|
-
|
|
173
|
-
**Never do without explicit permission:**
|
|
174
|
-
- Delete files outside project directory
|
|
175
|
-
- Modify system files
|
|
176
|
-
- Install packages without showing changes
|
|
177
|
-
- Execute shell commands with `sudo`
|
|
178
|
-
- Include API keys or secrets in code
|
|
179
|
-
|
|
180
|
-
## Performance & Efficiency
|
|
181
|
-
|
|
182
|
-
**Minimize tool calls:**
|
|
183
|
-
- Read once, not multiple times
|
|
184
|
-
- Batch parallel operations
|
|
185
|
-
- Search smart, not exhaustively
|
|
186
|
-
- Cache information you've already retrieved
|
|
187
|
-
|
|
188
|
-
**Respect token budgets:**
|
|
189
|
-
- Be concise in responses
|
|
190
|
-
- Don't repeat information unnecessarily
|
|
191
|
-
- Summarize large outputs
|
|
192
|
-
- Use code references instead of copying full files
|
|
193
|
-
|
|
194
|
-
## Quality Standards
|
|
195
|
-
|
|
196
|
-
**All code changes should:**
|
|
197
|
-
- Follow existing code style
|
|
198
|
-
- Include error handling
|
|
199
|
-
- Be properly typed (if applicable)
|
|
200
|
-
- Have meaningful names
|
|
201
|
-
- Include comments for complex logic
|
|
202
|
-
- Pass linting and formatting checks
|
|
203
|
-
|
|
204
|
-
**All features should:**
|
|
205
|
-
- Have tests
|
|
206
|
-
- Update documentation
|
|
207
|
-
- Handle edge cases
|
|
208
|
-
- Provide good error messages
|
|
209
|
-
- Be backwards compatible (unless breaking intentionally)
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
213
|
-
*This meta-instruction file helps AI agents work more efficiently with your codebase. It's always included to improve agent performance.*
|
|
@@ -1,459 +0,0 @@
|
|
|
1
|
-
# 🐛 Debugging & Problem-Solving Mode
|
|
2
|
-
|
|
3
|
-
*This context-specific meta-instruction activates when you're debugging issues, investigating errors, or troubleshooting problems.*
|
|
4
|
-
|
|
5
|
-
## Debugging Mindset
|
|
6
|
-
|
|
7
|
-
You are in **debugging mode**. Focus on:
|
|
8
|
-
- Systematic problem investigation
|
|
9
|
-
- Root cause analysis
|
|
10
|
-
- Minimal, targeted fixes
|
|
11
|
-
- Preventing regression
|
|
12
|
-
|
|
13
|
-
## Systematic Debugging Process
|
|
14
|
-
|
|
15
|
-
### 1. Reproduce the Problem
|
|
16
|
-
|
|
17
|
-
**First, confirm the issue:**
|
|
18
|
-
- Can you reproduce it consistently?
|
|
19
|
-
- What are the exact steps to trigger it?
|
|
20
|
-
- Does it happen in all environments?
|
|
21
|
-
- Are there specific conditions required?
|
|
22
|
-
|
|
23
|
-
**Document reproduction steps:**
|
|
24
|
-
```
|
|
25
|
-
Steps to reproduce:
|
|
26
|
-
1. Navigate to /users page
|
|
27
|
-
2. Click "Add User" button
|
|
28
|
-
3. Enter email without @ symbol
|
|
29
|
-
4. Click "Submit"
|
|
30
|
-
5. Observe: Error thrown instead of validation message
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### 2. Gather Information
|
|
34
|
-
|
|
35
|
-
**Read error messages completely:**
|
|
36
|
-
- Full error text (don't skim)
|
|
37
|
-
- Stack trace (which files/lines)
|
|
38
|
-
- Error type/code
|
|
39
|
-
- Any additional context
|
|
40
|
-
|
|
41
|
-
**Example error analysis:**
|
|
42
|
-
```
|
|
43
|
-
TypeError: Cannot read property 'email' of undefined
|
|
44
|
-
at validateUser (validation.ts:42:15)
|
|
45
|
-
at processForm (form-handler.ts:89:20)
|
|
46
|
-
at onClick (UserForm.tsx:156:5)
|
|
47
|
-
|
|
48
|
-
Analysis:
|
|
49
|
-
- Error occurs in validation.ts line 42
|
|
50
|
-
- Trying to access 'email' property
|
|
51
|
-
- Value is undefined (should be object)
|
|
52
|
-
- Called from form-handler.ts during form processing
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
**Collect context:**
|
|
56
|
-
- What changed recently? (check git log)
|
|
57
|
-
- What's the expected behavior?
|
|
58
|
-
- What's the actual behavior?
|
|
59
|
-
- Are there related issues/tickets?
|
|
60
|
-
|
|
61
|
-
### 3. Form Hypotheses
|
|
62
|
-
|
|
63
|
-
**List possible causes:**
|
|
64
|
-
|
|
65
|
-
```
|
|
66
|
-
Hypothesis 1: Form data not being passed correctly
|
|
67
|
-
- Check: Form submission code
|
|
68
|
-
- Verify: Data reaching validation function
|
|
69
|
-
|
|
70
|
-
Hypothesis 2: User object structure changed
|
|
71
|
-
- Check: Recent type/interface changes
|
|
72
|
-
- Verify: Object shape at runtime
|
|
73
|
-
|
|
74
|
-
Hypothesis 3: Missing null check
|
|
75
|
-
- Check: Validation function implementation
|
|
76
|
-
- Verify: Handling of undefined/null cases
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
**Prioritize by likelihood:**
|
|
80
|
-
1. Most likely cause first
|
|
81
|
-
2. Easiest to test second
|
|
82
|
-
3. Least likely but possible last
|
|
83
|
-
|
|
84
|
-
### 4. Test Hypotheses Systematically
|
|
85
|
-
|
|
86
|
-
**One hypothesis at a time:**
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
// Hypothesis 1: Data not passed
|
|
90
|
-
console.log('Form data:', formData); // Add logging
|
|
91
|
-
// Result: formData is undefined ✓ Confirmed!
|
|
92
|
-
|
|
93
|
-
// Root cause found: form submission not collecting data
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
**Use debugging techniques:**
|
|
97
|
-
- `console.log()` for quick checks
|
|
98
|
-
- Debugger breakpoints for step-through
|
|
99
|
-
- Unit tests for isolated testing
|
|
100
|
-
- Integration tests for workflow testing
|
|
101
|
-
|
|
102
|
-
### 5. Identify Root Cause
|
|
103
|
-
|
|
104
|
-
**Don't just fix symptoms:**
|
|
105
|
-
|
|
106
|
-
```
|
|
107
|
-
❌ Symptom fix (bad):
|
|
108
|
-
function validateUser(user) {
|
|
109
|
-
if (!user) return { valid: false }; // Band-aid
|
|
110
|
-
// ... rest of validation
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
✓ Root cause fix (good):
|
|
114
|
-
function handleSubmit() {
|
|
115
|
-
const formData = collectFormData(); // Was missing!
|
|
116
|
-
const result = validateUser(formData);
|
|
117
|
-
// ...
|
|
118
|
-
}
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
**Ask "Why?" 5 times:**
|
|
122
|
-
```
|
|
123
|
-
Problem: App crashes on user submit
|
|
124
|
-
Why? → validateUser receives undefined
|
|
125
|
-
Why? → handleSubmit doesn't pass data
|
|
126
|
-
Why? → collectFormData() not called
|
|
127
|
-
Why? → Refactored code removed the call
|
|
128
|
-
Why? → No test coverage caught regression
|
|
129
|
-
|
|
130
|
-
Fix: Add unit test + restore collectFormData() call
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### 6. Implement Minimal Fix
|
|
134
|
-
|
|
135
|
-
**Smallest change that fixes root cause:**
|
|
136
|
-
|
|
137
|
-
```typescript
|
|
138
|
-
// Before (broken)
|
|
139
|
-
function handleSubmit() {
|
|
140
|
-
const result = validateUser(formData); // formData not defined
|
|
141
|
-
processResult(result);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// After (fixed)
|
|
145
|
-
function handleSubmit() {
|
|
146
|
-
const formData = collectFormData(); // Added missing call
|
|
147
|
-
const result = validateUser(formData);
|
|
148
|
-
processResult(result);
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
**Verify fix:**
|
|
153
|
-
- Manual test: Follow reproduction steps
|
|
154
|
-
- Automated test: Add regression test
|
|
155
|
-
- Code review: Ensure no side effects
|
|
156
|
-
|
|
157
|
-
### 7. Prevent Regression
|
|
158
|
-
|
|
159
|
-
**Add test coverage:**
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
describe('handleSubmit', () => {
|
|
163
|
-
it('should collect form data before validation', () => {
|
|
164
|
-
const collectSpy = jest.spyOn(form, 'collectFormData');
|
|
165
|
-
|
|
166
|
-
handleSubmit();
|
|
167
|
-
|
|
168
|
-
expect(collectSpy).toHaveBeenCalled();
|
|
169
|
-
expect(collectSpy).toHaveBeenCalledBefore(validateUser);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('should not crash with empty form', () => {
|
|
173
|
-
expect(() => handleSubmit()).not.toThrow();
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
## Debugging Strategies by Error Type
|
|
179
|
-
|
|
180
|
-
### TypeError / NullReferenceError
|
|
181
|
-
|
|
182
|
-
**Common causes:**
|
|
183
|
-
- Accessing property of null/undefined
|
|
184
|
-
- Calling method on wrong type
|
|
185
|
-
- Incorrect type assumptions
|
|
186
|
-
|
|
187
|
-
**Investigation:**
|
|
188
|
-
```typescript
|
|
189
|
-
// Add defensive checks
|
|
190
|
-
if (!obj) {
|
|
191
|
-
console.error('Object is null/undefined', { obj, context });
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Log type
|
|
196
|
-
console.log('Type:', typeof obj, 'Value:', obj);
|
|
197
|
-
|
|
198
|
-
// Check prototype chain
|
|
199
|
-
console.log('Constructor:', obj?.constructor?.name);
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### Logic Errors
|
|
203
|
-
|
|
204
|
-
**Common causes:**
|
|
205
|
-
- Off-by-one errors
|
|
206
|
-
- Wrong comparison operators
|
|
207
|
-
- Incorrect boolean logic
|
|
208
|
-
- Edge case not handled
|
|
209
|
-
|
|
210
|
-
**Investigation:**
|
|
211
|
-
```typescript
|
|
212
|
-
// Log intermediate values
|
|
213
|
-
const isValid = age >= 18 && age <= 65;
|
|
214
|
-
console.log({ age, isValid,
|
|
215
|
-
check1: age >= 18,
|
|
216
|
-
check2: age <= 65
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
// Test boundary conditions
|
|
220
|
-
expect(isAdult(17)).toBe(false); // Just below
|
|
221
|
-
expect(isAdult(18)).toBe(true); // Exact boundary
|
|
222
|
-
expect(isAdult(19)).toBe(true); // Just above
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### Performance Issues
|
|
226
|
-
|
|
227
|
-
**Common causes:**
|
|
228
|
-
- Unnecessary re-renders
|
|
229
|
-
- N+1 queries
|
|
230
|
-
- Large data processing
|
|
231
|
-
- Memory leaks
|
|
232
|
-
|
|
233
|
-
**Investigation:**
|
|
234
|
-
```typescript
|
|
235
|
-
// Measure execution time
|
|
236
|
-
console.time('expensiveOperation');
|
|
237
|
-
const result = expensiveOperation();
|
|
238
|
-
console.timeEnd('expensiveOperation');
|
|
239
|
-
|
|
240
|
-
// Profile memory usage
|
|
241
|
-
const before = process.memoryUsage();
|
|
242
|
-
doOperation();
|
|
243
|
-
const after = process.memoryUsage();
|
|
244
|
-
console.log('Memory delta:',
|
|
245
|
-
(after.heapUsed - before.heapUsed) / 1024 / 1024, 'MB');
|
|
246
|
-
|
|
247
|
-
// Check call frequency
|
|
248
|
-
let callCount = 0;
|
|
249
|
-
function tracked() {
|
|
250
|
-
console.log('Call #', ++callCount);
|
|
251
|
-
// ...
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
### Integration Issues
|
|
256
|
-
|
|
257
|
-
**Common causes:**
|
|
258
|
-
- API contract mismatch
|
|
259
|
-
- Environment differences
|
|
260
|
-
- Timing/race conditions
|
|
261
|
-
- Dependency version conflicts
|
|
262
|
-
|
|
263
|
-
**Investigation:**
|
|
264
|
-
```typescript
|
|
265
|
-
// Log full request/response
|
|
266
|
-
console.log('Request:', {
|
|
267
|
-
url,
|
|
268
|
-
method,
|
|
269
|
-
headers,
|
|
270
|
-
body: JSON.stringify(body, null, 2)
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
console.log('Response:', {
|
|
274
|
-
status,
|
|
275
|
-
headers,
|
|
276
|
-
body: JSON.stringify(data, null, 2)
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
// Check environment
|
|
280
|
-
console.log('Environment:', {
|
|
281
|
-
NODE_ENV: process.env.NODE_ENV,
|
|
282
|
-
API_URL: process.env.API_URL,
|
|
283
|
-
version: process.version
|
|
284
|
-
});
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
## Debugging Tools & Techniques
|
|
288
|
-
|
|
289
|
-
### Console Debugging
|
|
290
|
-
|
|
291
|
-
```typescript
|
|
292
|
-
// Structured logging
|
|
293
|
-
console.log('User data:', { id, email, role });
|
|
294
|
-
|
|
295
|
-
// Conditional logging
|
|
296
|
-
if (DEBUG) {
|
|
297
|
-
console.log('Debug info:', state);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// Stack trace
|
|
301
|
-
console.trace('How did we get here?');
|
|
302
|
-
|
|
303
|
-
// Timing
|
|
304
|
-
console.time('operation');
|
|
305
|
-
// ... code
|
|
306
|
-
console.timeEnd('operation');
|
|
307
|
-
|
|
308
|
-
// Table format (for arrays)
|
|
309
|
-
console.table(users);
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
### Debugger
|
|
313
|
-
|
|
314
|
-
```typescript
|
|
315
|
-
// Pause execution
|
|
316
|
-
debugger; // Browser/Node will break here
|
|
317
|
-
|
|
318
|
-
// Conditional breakpoint
|
|
319
|
-
if (userId === '123') {
|
|
320
|
-
debugger; // Only break for specific case
|
|
321
|
-
}
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
### Git Bisect
|
|
325
|
-
|
|
326
|
-
```bash
|
|
327
|
-
# Find which commit introduced bug
|
|
328
|
-
git bisect start
|
|
329
|
-
git bisect bad # Current commit is bad
|
|
330
|
-
git bisect good v1.2.0 # v1.2.0 was good
|
|
331
|
-
# Git will checkout commits for testing
|
|
332
|
-
# Mark each as good/bad until found
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
### Binary Search Debugging
|
|
336
|
-
|
|
337
|
-
```typescript
|
|
338
|
-
// Comment out half the code
|
|
339
|
-
// Does error still occur?
|
|
340
|
-
// If yes → bug is in remaining code
|
|
341
|
-
// If no → bug is in commented code
|
|
342
|
-
// Repeat until isolated
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
## Common Debugging Pitfalls
|
|
346
|
-
|
|
347
|
-
❌ **Don't:**
|
|
348
|
-
- Jump to conclusions without evidence
|
|
349
|
-
- Fix symptoms instead of root cause
|
|
350
|
-
- Change multiple things at once
|
|
351
|
-
- Ignore error messages
|
|
352
|
-
- Give up after first attempt
|
|
353
|
-
|
|
354
|
-
✓ **Do:**
|
|
355
|
-
- Follow systematic process
|
|
356
|
-
- Test one hypothesis at a time
|
|
357
|
-
- Read error messages completely
|
|
358
|
-
- Document findings
|
|
359
|
-
- Add tests to prevent regression
|
|
360
|
-
|
|
361
|
-
## Debugging Checklist
|
|
362
|
-
|
|
363
|
-
Before concluding debugging:
|
|
364
|
-
|
|
365
|
-
### Understanding
|
|
366
|
-
- [ ] Can reproduce consistently
|
|
367
|
-
- [ ] Understand exact failure mode
|
|
368
|
-
- [ ] Know expected vs actual behavior
|
|
369
|
-
- [ ] Identified root cause (not symptom)
|
|
370
|
-
|
|
371
|
-
### Fix Validation
|
|
372
|
-
- [ ] Fix works in all test cases
|
|
373
|
-
- [ ] No new errors introduced
|
|
374
|
-
- [ ] Edge cases handled
|
|
375
|
-
- [ ] Code is clean (no debug statements left)
|
|
376
|
-
|
|
377
|
-
### Prevention
|
|
378
|
-
- [ ] Added regression test
|
|
379
|
-
- [ ] Updated documentation if needed
|
|
380
|
-
- [ ] Considered similar issues
|
|
381
|
-
- [ ] Team informed of gotchas
|
|
382
|
-
|
|
383
|
-
## Communication During Debugging
|
|
384
|
-
|
|
385
|
-
**Keep user informed:**
|
|
386
|
-
|
|
387
|
-
```
|
|
388
|
-
Finding: "I've identified the issue - the form data isn't being
|
|
389
|
-
collected before validation."
|
|
390
|
-
|
|
391
|
-
Plan: "I'll add the missing collectFormData() call and add a test
|
|
392
|
-
to prevent this regression."
|
|
393
|
-
|
|
394
|
-
Status: "Fixed and tested. The form now properly validates user input."
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
**Be transparent about uncertainty:**
|
|
398
|
-
|
|
399
|
-
```
|
|
400
|
-
"I've identified two possible causes:
|
|
401
|
-
1. Data not being passed (most likely)
|
|
402
|
-
2. Validation logic changed (less likely)
|
|
403
|
-
|
|
404
|
-
Testing hypothesis 1 first..."
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
## Advanced Debugging Scenarios
|
|
408
|
-
|
|
409
|
-
### Race Conditions
|
|
410
|
-
|
|
411
|
-
```typescript
|
|
412
|
-
// Add sequence logging
|
|
413
|
-
let seq = 0;
|
|
414
|
-
async function operation() {
|
|
415
|
-
const id = ++seq;
|
|
416
|
-
console.log(`[${id}] Start`);
|
|
417
|
-
await asyncWork();
|
|
418
|
-
console.log(`[${id}] End`);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
// Check for: [1] Start, [2] Start, [1] End, [2] End
|
|
422
|
-
// vs expected: [1] Start, [1] End, [2] Start, [2] End
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
### Memory Leaks
|
|
426
|
-
|
|
427
|
-
```typescript
|
|
428
|
-
// Track object creation
|
|
429
|
-
const tracker = new WeakMap();
|
|
430
|
-
function track(obj) {
|
|
431
|
-
tracker.set(obj, new Error().stack);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// Check for growing collections
|
|
435
|
-
setInterval(() => {
|
|
436
|
-
console.log('Active items:', cache.size);
|
|
437
|
-
}, 1000);
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
### Intermittent Issues
|
|
441
|
-
|
|
442
|
-
```typescript
|
|
443
|
-
// Add extensive logging
|
|
444
|
-
function problamaticFunction() {
|
|
445
|
-
logger.debug('Entry', { args: Array.from(arguments) });
|
|
446
|
-
try {
|
|
447
|
-
const result = doWork();
|
|
448
|
-
logger.debug('Success', { result });
|
|
449
|
-
return result;
|
|
450
|
-
} catch (error) {
|
|
451
|
-
logger.error('Failure', { error, state: captureState() });
|
|
452
|
-
throw error;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
---
|
|
458
|
-
|
|
459
|
-
*This meta-instruction helps you debug issues systematically and effectively. It activates automatically when debugging tasks are detected.*
|