axiom-coding-agent-setup 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/CONTEXT-MANAGEMENT.md +155 -155
- package/.agents/DEBUGGING.md +124 -124
- package/.agents/ENGINEERING.md +180 -180
- package/.agents/PERFORMANCE.md +164 -164
- package/.agents/SECURITY.md +109 -109
- package/.agents/WORKFLOW.md +143 -143
- package/.agents/skills/agent-browser/SKILL.md +55 -55
- package/.agents/skills/huggingface-deployment/SKILL.md +230 -0
- package/.agents/skills/project-design/SKILL.md +207 -207
- package/.agents/skills/project-design/references/ARCHITECTURE.md +641 -641
- package/.agents/skills/project-design/references/PROJECT_PLAN.md +315 -315
- package/.env.axiom +8 -8
- package/AGENTS.md +104 -104
- package/README.md +146 -145
- package/bin/cli.js +1 -1
- package/opencode.json +64 -64
- package/package.json +1 -1
- package/plugin/oh-my-openagent.json +198 -198
- package/skills-lock.json +57 -57
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
# Context Management
|
|
2
|
-
|
|
3
|
-
## The Context Problem
|
|
4
|
-
|
|
5
|
-
AI agents have limited context windows. Every token counts. Wasted context = degraded reasoning = worse output. Managing context is a core competency of a world-class agent.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Context Budget Principles
|
|
10
|
-
|
|
11
|
-
### The 50% Rule
|
|
12
|
-
When context reaches ~50% of the window, proactively compact. Don't wait until you're forced to.
|
|
13
|
-
|
|
14
|
-
### Every Token Must Earn Its Place
|
|
15
|
-
Before including anything in context, ask:
|
|
16
|
-
- Does this directly help solve the current task?
|
|
17
|
-
- Can I summarize this instead of including it verbatim?
|
|
18
|
-
- Is this already known from the conversation history?
|
|
19
|
-
- Would a file reference suffice instead of the full content?
|
|
20
|
-
|
|
21
|
-
### Read Before Claiming, But Don't Read Everything
|
|
22
|
-
- Read files that are directly relevant to the current task
|
|
23
|
-
- Use search tools (grep, ast-grep) to find specific patterns without reading entire files
|
|
24
|
-
- Batch read multiple files when you know they're all needed
|
|
25
|
-
- Stop reading once you have sufficient understanding
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## Context Compaction Strategy
|
|
30
|
-
|
|
31
|
-
### When to Compact
|
|
32
|
-
- Context exceeds 50% of window
|
|
33
|
-
- Starting a new sub-task within the same session
|
|
34
|
-
- Switching from exploration to implementation
|
|
35
|
-
- Before making a complex, multi-step change
|
|
36
|
-
|
|
37
|
-
### How to Compact
|
|
38
|
-
1. **Summarize conversation history** — Replace long exchanges with key decisions and current state
|
|
39
|
-
2. **Remove completed work** — Move done items to a summary; keep only what's still open
|
|
40
|
-
3. **Replace file contents with references** — "See `src/auth.ts` for implementation" vs. full file content
|
|
41
|
-
4. **Use todo lists** — Track state externally (todo tool) instead of in conversation
|
|
42
|
-
5. **Extract key findings** — Move exploration results into a concise summary
|
|
43
|
-
|
|
44
|
-
### The Compact Format
|
|
45
|
-
```
|
|
46
|
-
## Session Summary
|
|
47
|
-
- Task: [one-line description]
|
|
48
|
-
- Status: [in progress / blocked / completed]
|
|
49
|
-
- Key decisions: [bullet list]
|
|
50
|
-
- Open items: [from todo list]
|
|
51
|
-
- Relevant files: [file paths only, not contents]
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
---
|
|
55
|
-
|
|
56
|
-
## Session Discipline
|
|
57
|
-
|
|
58
|
-
### One Task Per Session
|
|
59
|
-
Switching tasks mid-session degrades quality. Use `/clear` or start a new session when pivoting.
|
|
60
|
-
|
|
61
|
-
### Session Lifecycle
|
|
62
|
-
1. **Setup** — Load relevant skills, read initial files, clarify requirements
|
|
63
|
-
2. **Exploration** — Search codebase, understand patterns, identify files to change
|
|
64
|
-
3. **Implementation** — Make changes, verify, test
|
|
65
|
-
4. **Verification** — Run tests, check for regressions, confirm requirements met
|
|
66
|
-
5. **Handoff** — Summarize what changed, what's still open, what needs follow-up
|
|
67
|
-
|
|
68
|
-
### Handoff Documentation
|
|
69
|
-
When ending a session or passing to another agent:
|
|
70
|
-
- What was completed
|
|
71
|
-
- What is still in progress
|
|
72
|
-
- What decisions were made and why
|
|
73
|
-
- What blockers exist
|
|
74
|
-
- What files were changed
|
|
75
|
-
- What tests were run and their results
|
|
76
|
-
|
|
77
|
-
---
|
|
78
|
-
|
|
79
|
-
## Parallel Execution & Context
|
|
80
|
-
|
|
81
|
-
### When to Parallelize
|
|
82
|
-
- Multiple independent file reads
|
|
83
|
-
- Multiple search queries
|
|
84
|
-
- Multiple test runs
|
|
85
|
-
- Independent implementation tasks
|
|
86
|
-
|
|
87
|
-
### When NOT to Parallelize
|
|
88
|
-
- Tasks that depend on each other's output
|
|
89
|
-
- Tasks that modify the same files
|
|
90
|
-
- Tasks that share mutable state
|
|
91
|
-
|
|
92
|
-
### Context Isolation
|
|
93
|
-
Each parallel agent/worker should receive:
|
|
94
|
-
- The specific task it's responsible for
|
|
95
|
-
- The minimal context needed for that task
|
|
96
|
-
- Clear boundaries on what it should NOT touch
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
## Codebase Navigation Without Context Bloat
|
|
101
|
-
|
|
102
|
-
### Grepping > Reading
|
|
103
|
-
Use grep/ast-grep to find specific patterns without loading entire files into context.
|
|
104
|
-
|
|
105
|
-
### Symbol Search > File Reading
|
|
106
|
-
Use LSP symbol search to find where something is defined, then read only that definition.
|
|
107
|
-
|
|
108
|
-
### References > Full Content
|
|
109
|
-
When you've already read a file once, reference it by path. Don't re-read it unless you need to verify current state.
|
|
110
|
-
|
|
111
|
-
### Tree > List
|
|
112
|
-
Use `tree` with depth limits to understand structure without listing every file.
|
|
113
|
-
|
|
114
|
-
---
|
|
115
|
-
|
|
116
|
-
## Memory Management for Long Sessions
|
|
117
|
-
|
|
118
|
-
### Progressive Disclosure
|
|
119
|
-
1. Start with high-level overview (tree, key files)
|
|
120
|
-
2. Read relevant files as needed
|
|
121
|
-
3. Compact and summarize before diving deeper
|
|
122
|
-
4. Reference, don't repeat
|
|
123
|
-
|
|
124
|
-
### The Rule of Three
|
|
125
|
-
If you find yourself re-reading the same file more than 3 times in a session, something is wrong:
|
|
126
|
-
- You didn't understand it the first time (take notes)
|
|
127
|
-
- You're working on too many things at once (narrow scope)
|
|
128
|
-
- The file is too large and needs refactoring (flag it)
|
|
129
|
-
|
|
130
|
-
### State Persistence
|
|
131
|
-
Use external tools for state:
|
|
132
|
-
- **Todo lists** — Track progress without consuming context
|
|
133
|
-
- **File system** — Write summaries to temp files
|
|
134
|
-
- **Session state** — Use session variables for cross-turn data
|
|
135
|
-
|
|
136
|
-
---
|
|
137
|
-
|
|
138
|
-
## Context Anti-Patterns
|
|
139
|
-
|
|
140
|
-
| Anti-Pattern | Why It Hurts |
|
|
141
|
-
|---|---|
|
|
142
|
-
| **Including entire files** | Eats context budget; most of the file is irrelevant |
|
|
143
|
-
| **Repeating history** | Every turn doesn't need full conversation replay |
|
|
144
|
-
| **Loading unrelated skills** | Only load skills relevant to the current task |
|
|
145
|
-
| **Parallelizing dependent tasks** | Results in conflicts, wasted work, context pollution |
|
|
146
|
-
| **Never compacting** | Context degrades until the agent starts hallucinating or making mistakes |
|
|
147
|
-
| **Over-reading** | Reading 20 files when 3 would suffice |
|
|
148
|
-
|
|
149
|
-
---
|
|
150
|
-
|
|
151
|
-
## The Ultimate Rule
|
|
152
|
-
|
|
153
|
-
**Context is your most precious resource. Spend it wisely.**
|
|
154
|
-
|
|
155
|
-
Every byte of context should directly contribute to producing correct, high-quality output. If it doesn't, remove it.
|
|
1
|
+
# Context Management
|
|
2
|
+
|
|
3
|
+
## The Context Problem
|
|
4
|
+
|
|
5
|
+
AI agents have limited context windows. Every token counts. Wasted context = degraded reasoning = worse output. Managing context is a core competency of a world-class agent.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Context Budget Principles
|
|
10
|
+
|
|
11
|
+
### The 50% Rule
|
|
12
|
+
When context reaches ~50% of the window, proactively compact. Don't wait until you're forced to.
|
|
13
|
+
|
|
14
|
+
### Every Token Must Earn Its Place
|
|
15
|
+
Before including anything in context, ask:
|
|
16
|
+
- Does this directly help solve the current task?
|
|
17
|
+
- Can I summarize this instead of including it verbatim?
|
|
18
|
+
- Is this already known from the conversation history?
|
|
19
|
+
- Would a file reference suffice instead of the full content?
|
|
20
|
+
|
|
21
|
+
### Read Before Claiming, But Don't Read Everything
|
|
22
|
+
- Read files that are directly relevant to the current task
|
|
23
|
+
- Use search tools (grep, ast-grep) to find specific patterns without reading entire files
|
|
24
|
+
- Batch read multiple files when you know they're all needed
|
|
25
|
+
- Stop reading once you have sufficient understanding
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Context Compaction Strategy
|
|
30
|
+
|
|
31
|
+
### When to Compact
|
|
32
|
+
- Context exceeds 50% of window
|
|
33
|
+
- Starting a new sub-task within the same session
|
|
34
|
+
- Switching from exploration to implementation
|
|
35
|
+
- Before making a complex, multi-step change
|
|
36
|
+
|
|
37
|
+
### How to Compact
|
|
38
|
+
1. **Summarize conversation history** — Replace long exchanges with key decisions and current state
|
|
39
|
+
2. **Remove completed work** — Move done items to a summary; keep only what's still open
|
|
40
|
+
3. **Replace file contents with references** — "See `src/auth.ts` for implementation" vs. full file content
|
|
41
|
+
4. **Use todo lists** — Track state externally (todo tool) instead of in conversation
|
|
42
|
+
5. **Extract key findings** — Move exploration results into a concise summary
|
|
43
|
+
|
|
44
|
+
### The Compact Format
|
|
45
|
+
```
|
|
46
|
+
## Session Summary
|
|
47
|
+
- Task: [one-line description]
|
|
48
|
+
- Status: [in progress / blocked / completed]
|
|
49
|
+
- Key decisions: [bullet list]
|
|
50
|
+
- Open items: [from todo list]
|
|
51
|
+
- Relevant files: [file paths only, not contents]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Session Discipline
|
|
57
|
+
|
|
58
|
+
### One Task Per Session
|
|
59
|
+
Switching tasks mid-session degrades quality. Use `/clear` or start a new session when pivoting.
|
|
60
|
+
|
|
61
|
+
### Session Lifecycle
|
|
62
|
+
1. **Setup** — Load relevant skills, read initial files, clarify requirements
|
|
63
|
+
2. **Exploration** — Search codebase, understand patterns, identify files to change
|
|
64
|
+
3. **Implementation** — Make changes, verify, test
|
|
65
|
+
4. **Verification** — Run tests, check for regressions, confirm requirements met
|
|
66
|
+
5. **Handoff** — Summarize what changed, what's still open, what needs follow-up
|
|
67
|
+
|
|
68
|
+
### Handoff Documentation
|
|
69
|
+
When ending a session or passing to another agent:
|
|
70
|
+
- What was completed
|
|
71
|
+
- What is still in progress
|
|
72
|
+
- What decisions were made and why
|
|
73
|
+
- What blockers exist
|
|
74
|
+
- What files were changed
|
|
75
|
+
- What tests were run and their results
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Parallel Execution & Context
|
|
80
|
+
|
|
81
|
+
### When to Parallelize
|
|
82
|
+
- Multiple independent file reads
|
|
83
|
+
- Multiple search queries
|
|
84
|
+
- Multiple test runs
|
|
85
|
+
- Independent implementation tasks
|
|
86
|
+
|
|
87
|
+
### When NOT to Parallelize
|
|
88
|
+
- Tasks that depend on each other's output
|
|
89
|
+
- Tasks that modify the same files
|
|
90
|
+
- Tasks that share mutable state
|
|
91
|
+
|
|
92
|
+
### Context Isolation
|
|
93
|
+
Each parallel agent/worker should receive:
|
|
94
|
+
- The specific task it's responsible for
|
|
95
|
+
- The minimal context needed for that task
|
|
96
|
+
- Clear boundaries on what it should NOT touch
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Codebase Navigation Without Context Bloat
|
|
101
|
+
|
|
102
|
+
### Grepping > Reading
|
|
103
|
+
Use grep/ast-grep to find specific patterns without loading entire files into context.
|
|
104
|
+
|
|
105
|
+
### Symbol Search > File Reading
|
|
106
|
+
Use LSP symbol search to find where something is defined, then read only that definition.
|
|
107
|
+
|
|
108
|
+
### References > Full Content
|
|
109
|
+
When you've already read a file once, reference it by path. Don't re-read it unless you need to verify current state.
|
|
110
|
+
|
|
111
|
+
### Tree > List
|
|
112
|
+
Use `tree` with depth limits to understand structure without listing every file.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Memory Management for Long Sessions
|
|
117
|
+
|
|
118
|
+
### Progressive Disclosure
|
|
119
|
+
1. Start with high-level overview (tree, key files)
|
|
120
|
+
2. Read relevant files as needed
|
|
121
|
+
3. Compact and summarize before diving deeper
|
|
122
|
+
4. Reference, don't repeat
|
|
123
|
+
|
|
124
|
+
### The Rule of Three
|
|
125
|
+
If you find yourself re-reading the same file more than 3 times in a session, something is wrong:
|
|
126
|
+
- You didn't understand it the first time (take notes)
|
|
127
|
+
- You're working on too many things at once (narrow scope)
|
|
128
|
+
- The file is too large and needs refactoring (flag it)
|
|
129
|
+
|
|
130
|
+
### State Persistence
|
|
131
|
+
Use external tools for state:
|
|
132
|
+
- **Todo lists** — Track progress without consuming context
|
|
133
|
+
- **File system** — Write summaries to temp files
|
|
134
|
+
- **Session state** — Use session variables for cross-turn data
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Context Anti-Patterns
|
|
139
|
+
|
|
140
|
+
| Anti-Pattern | Why It Hurts |
|
|
141
|
+
|---|---|
|
|
142
|
+
| **Including entire files** | Eats context budget; most of the file is irrelevant |
|
|
143
|
+
| **Repeating history** | Every turn doesn't need full conversation replay |
|
|
144
|
+
| **Loading unrelated skills** | Only load skills relevant to the current task |
|
|
145
|
+
| **Parallelizing dependent tasks** | Results in conflicts, wasted work, context pollution |
|
|
146
|
+
| **Never compacting** | Context degrades until the agent starts hallucinating or making mistakes |
|
|
147
|
+
| **Over-reading** | Reading 20 files when 3 would suffice |
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## The Ultimate Rule
|
|
152
|
+
|
|
153
|
+
**Context is your most precious resource. Spend it wisely.**
|
|
154
|
+
|
|
155
|
+
Every byte of context should directly contribute to producing correct, high-quality output. If it doesn't, remove it.
|
package/.agents/DEBUGGING.md
CHANGED
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
# Debugging Methodology
|
|
2
|
-
|
|
3
|
-
## The Golden Rule of Debugging
|
|
4
|
-
|
|
5
|
-
**Never guess. Always observe.**
|
|
6
|
-
|
|
7
|
-
Debugging is not about being smart — it's about being systematic. The fastest way to fix a bug is to understand it completely before touching code.
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## The Debugging Protocol
|
|
12
|
-
|
|
13
|
-
### Phase 1: Reproduction
|
|
14
|
-
1. **Can you reproduce it consistently?** If not, find the pattern.
|
|
15
|
-
2. **What are the exact steps?** Document them precisely.
|
|
16
|
-
3. **What is the smallest input that triggers it?** Minimize the reproduction case.
|
|
17
|
-
4. **When did it last work?** Use `git bisect` to find the offending commit.
|
|
18
|
-
|
|
19
|
-
### Phase 2: Observation
|
|
20
|
-
1. **Read the error message carefully** — not just the first line, the full stack trace
|
|
21
|
-
2. **Check the obvious first** — null pointers, off-by-one, typos, recent changes
|
|
22
|
-
3. **Inspect the state** — print/LOG variables at key points; don't assume you know their values
|
|
23
|
-
4. **Trace the data flow** — where does the bad value come from?
|
|
24
|
-
5. **Check boundaries** — empty collections, first/last items, zero, null, max values
|
|
25
|
-
6. **Check the environment** — different OS, different Node version, different database state
|
|
26
|
-
|
|
27
|
-
### Phase 3: Hypothesis
|
|
28
|
-
1. **Form a specific, testable hypothesis** — "The bug is caused by X because Y"
|
|
29
|
-
2. **Design an experiment to prove or disprove it** — a test, a log, a minimal change
|
|
30
|
-
3. **If disproven, discard and form a new hypothesis** — don't cling to wrong theories
|
|
31
|
-
4. **If proven, fix the root cause** — not the symptom
|
|
32
|
-
|
|
33
|
-
### Phase 4: Fix & Verify
|
|
34
|
-
1. **Fix the root cause, not the symptom** — suppressing the error message is not fixing the bug
|
|
35
|
-
2. **Verify the fix** — run the reproduction case; it should pass
|
|
36
|
-
3. **Verify you didn't break anything else** — run the full test suite
|
|
37
|
-
4. **Add a regression test** — ensure this bug never returns
|
|
38
|
-
5. **Document what you learned** — if it was tricky, save the next engineer the trouble
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
## Debugging Techniques
|
|
43
|
-
|
|
44
|
-
### Binary Search (Divide and Conquer)
|
|
45
|
-
When you don't know where the bug is:
|
|
46
|
-
1. Add a check/log at the midpoint of the suspected code path
|
|
47
|
-
2. Determine if the bug is before or after that point
|
|
48
|
-
3. Repeat, halving the search space each time
|
|
49
|
-
|
|
50
|
-
### Rubber Duck Debugging
|
|
51
|
-
Explain the bug out loud (or in writing) to an inanimate object. Forcing yourself to articulate the problem often reveals the solution.
|
|
52
|
-
|
|
53
|
-
### Git Bisect
|
|
54
|
-
When you know it worked before:
|
|
55
|
-
```bash
|
|
56
|
-
git bisect start
|
|
57
|
-
git bisect bad HEAD
|
|
58
|
-
git bisect good <last-known-good-commit>
|
|
59
|
-
# Git will checkout commits; test and mark good/bad until it finds the culprit
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### Backwards from the Error
|
|
63
|
-
Start at the crash/error and trace backwards:
|
|
64
|
-
1. What function threw the error?
|
|
65
|
-
2. What called that function?
|
|
66
|
-
3. What data was passed?
|
|
67
|
-
4. Where did that data come from?
|
|
68
|
-
|
|
69
|
-
### Isolate Variables
|
|
70
|
-
Change one thing at a time:
|
|
71
|
-
- Does it fail on a different machine?
|
|
72
|
-
- Does it fail with a different database?
|
|
73
|
-
- Does it fail with different input?
|
|
74
|
-
- Does it fail with the previous commit?
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
## Common Bug Categories & Patterns
|
|
79
|
-
|
|
80
|
-
| Symptom | Likely Causes |
|
|
81
|
-
|---|---|
|
|
82
|
-
| Works on my machine | Environment differences, missing env vars, different versions |
|
|
83
|
-
| Intermittent failure | Race condition, timing issue, external dependency flakiness |
|
|
84
|
-
| Works after restart | Memory leak, state corruption, resource exhaustion |
|
|
85
|
-
| Only fails with large data | Buffer overflow, timeout, memory limit, algorithmic complexity |
|
|
86
|
-
| Works in tests, fails in prod | Different data, different config, different permissions |
|
|
87
|
-
| Works in prod, fails in tests | Test isolation, mock mismatch, different environment setup |
|
|
88
|
-
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
## Anti-Patterns to Avoid
|
|
92
|
-
|
|
93
|
-
| Anti-Pattern | Why It Fails |
|
|
94
|
-
|---|---|
|
|
95
|
-
| **Shotgun debugging** | Randomly changing things hoping something works. You learn nothing and introduce new bugs. |
|
|
96
|
-
| **Print-driven development** | Adding `console.log` everywhere instead of understanding the flow. Clutters code and output. |
|
|
97
|
-
| **Commenting out code** | "Maybe if I disable this..." You hide the symptom without fixing the cause. |
|
|
98
|
-
| **Blaming the compiler/framework** | It's almost never the compiler. Check your assumptions first. |
|
|
99
|
-
| **Ignoring the stack trace** | The answer is usually in the stack trace. Read it fully. |
|
|
100
|
-
| **Fixing without reproducing** | If you can't reproduce it, you can't verify your fix. |
|
|
101
|
-
| **Not adding a regression test** | The same bug will come back. Guaranteed. |
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
## Debugging Tools
|
|
106
|
-
|
|
107
|
-
- **Stack traces** — Read bottom-up: the error is at the bottom, the call chain above it
|
|
108
|
-
- **Breakpoints** — Pause execution and inspect state (better than print statements)
|
|
109
|
-
- **Diff tools** — Compare working vs broken state (files, configs, database dumps)
|
|
110
|
-
- **Log aggregation** — Centralized logs for tracing requests across services
|
|
111
|
-
- **Request tracing** — Trace IDs to follow a single request through multiple services
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## When to Ask for Help
|
|
116
|
-
|
|
117
|
-
Stop and escalate when:
|
|
118
|
-
- You've spent 30+ minutes without progress
|
|
119
|
-
- The bug involves a third-party library you don't control
|
|
120
|
-
- It requires access to production data or systems you don't have
|
|
121
|
-
- You're tempted to add a hack/workaround instead of a real fix
|
|
122
|
-
- The fix would change security-critical code
|
|
123
|
-
|
|
124
|
-
**Debugging is a skill. The more methodical you are, the faster you solve problems.**
|
|
1
|
+
# Debugging Methodology
|
|
2
|
+
|
|
3
|
+
## The Golden Rule of Debugging
|
|
4
|
+
|
|
5
|
+
**Never guess. Always observe.**
|
|
6
|
+
|
|
7
|
+
Debugging is not about being smart — it's about being systematic. The fastest way to fix a bug is to understand it completely before touching code.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## The Debugging Protocol
|
|
12
|
+
|
|
13
|
+
### Phase 1: Reproduction
|
|
14
|
+
1. **Can you reproduce it consistently?** If not, find the pattern.
|
|
15
|
+
2. **What are the exact steps?** Document them precisely.
|
|
16
|
+
3. **What is the smallest input that triggers it?** Minimize the reproduction case.
|
|
17
|
+
4. **When did it last work?** Use `git bisect` to find the offending commit.
|
|
18
|
+
|
|
19
|
+
### Phase 2: Observation
|
|
20
|
+
1. **Read the error message carefully** — not just the first line, the full stack trace
|
|
21
|
+
2. **Check the obvious first** — null pointers, off-by-one, typos, recent changes
|
|
22
|
+
3. **Inspect the state** — print/LOG variables at key points; don't assume you know their values
|
|
23
|
+
4. **Trace the data flow** — where does the bad value come from?
|
|
24
|
+
5. **Check boundaries** — empty collections, first/last items, zero, null, max values
|
|
25
|
+
6. **Check the environment** — different OS, different Node version, different database state
|
|
26
|
+
|
|
27
|
+
### Phase 3: Hypothesis
|
|
28
|
+
1. **Form a specific, testable hypothesis** — "The bug is caused by X because Y"
|
|
29
|
+
2. **Design an experiment to prove or disprove it** — a test, a log, a minimal change
|
|
30
|
+
3. **If disproven, discard and form a new hypothesis** — don't cling to wrong theories
|
|
31
|
+
4. **If proven, fix the root cause** — not the symptom
|
|
32
|
+
|
|
33
|
+
### Phase 4: Fix & Verify
|
|
34
|
+
1. **Fix the root cause, not the symptom** — suppressing the error message is not fixing the bug
|
|
35
|
+
2. **Verify the fix** — run the reproduction case; it should pass
|
|
36
|
+
3. **Verify you didn't break anything else** — run the full test suite
|
|
37
|
+
4. **Add a regression test** — ensure this bug never returns
|
|
38
|
+
5. **Document what you learned** — if it was tricky, save the next engineer the trouble
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Debugging Techniques
|
|
43
|
+
|
|
44
|
+
### Binary Search (Divide and Conquer)
|
|
45
|
+
When you don't know where the bug is:
|
|
46
|
+
1. Add a check/log at the midpoint of the suspected code path
|
|
47
|
+
2. Determine if the bug is before or after that point
|
|
48
|
+
3. Repeat, halving the search space each time
|
|
49
|
+
|
|
50
|
+
### Rubber Duck Debugging
|
|
51
|
+
Explain the bug out loud (or in writing) to an inanimate object. Forcing yourself to articulate the problem often reveals the solution.
|
|
52
|
+
|
|
53
|
+
### Git Bisect
|
|
54
|
+
When you know it worked before:
|
|
55
|
+
```bash
|
|
56
|
+
git bisect start
|
|
57
|
+
git bisect bad HEAD
|
|
58
|
+
git bisect good <last-known-good-commit>
|
|
59
|
+
# Git will checkout commits; test and mark good/bad until it finds the culprit
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Backwards from the Error
|
|
63
|
+
Start at the crash/error and trace backwards:
|
|
64
|
+
1. What function threw the error?
|
|
65
|
+
2. What called that function?
|
|
66
|
+
3. What data was passed?
|
|
67
|
+
4. Where did that data come from?
|
|
68
|
+
|
|
69
|
+
### Isolate Variables
|
|
70
|
+
Change one thing at a time:
|
|
71
|
+
- Does it fail on a different machine?
|
|
72
|
+
- Does it fail with a different database?
|
|
73
|
+
- Does it fail with different input?
|
|
74
|
+
- Does it fail with the previous commit?
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Common Bug Categories & Patterns
|
|
79
|
+
|
|
80
|
+
| Symptom | Likely Causes |
|
|
81
|
+
|---|---|
|
|
82
|
+
| Works on my machine | Environment differences, missing env vars, different versions |
|
|
83
|
+
| Intermittent failure | Race condition, timing issue, external dependency flakiness |
|
|
84
|
+
| Works after restart | Memory leak, state corruption, resource exhaustion |
|
|
85
|
+
| Only fails with large data | Buffer overflow, timeout, memory limit, algorithmic complexity |
|
|
86
|
+
| Works in tests, fails in prod | Different data, different config, different permissions |
|
|
87
|
+
| Works in prod, fails in tests | Test isolation, mock mismatch, different environment setup |
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Anti-Patterns to Avoid
|
|
92
|
+
|
|
93
|
+
| Anti-Pattern | Why It Fails |
|
|
94
|
+
|---|---|
|
|
95
|
+
| **Shotgun debugging** | Randomly changing things hoping something works. You learn nothing and introduce new bugs. |
|
|
96
|
+
| **Print-driven development** | Adding `console.log` everywhere instead of understanding the flow. Clutters code and output. |
|
|
97
|
+
| **Commenting out code** | "Maybe if I disable this..." You hide the symptom without fixing the cause. |
|
|
98
|
+
| **Blaming the compiler/framework** | It's almost never the compiler. Check your assumptions first. |
|
|
99
|
+
| **Ignoring the stack trace** | The answer is usually in the stack trace. Read it fully. |
|
|
100
|
+
| **Fixing without reproducing** | If you can't reproduce it, you can't verify your fix. |
|
|
101
|
+
| **Not adding a regression test** | The same bug will come back. Guaranteed. |
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Debugging Tools
|
|
106
|
+
|
|
107
|
+
- **Stack traces** — Read bottom-up: the error is at the bottom, the call chain above it
|
|
108
|
+
- **Breakpoints** — Pause execution and inspect state (better than print statements)
|
|
109
|
+
- **Diff tools** — Compare working vs broken state (files, configs, database dumps)
|
|
110
|
+
- **Log aggregation** — Centralized logs for tracing requests across services
|
|
111
|
+
- **Request tracing** — Trace IDs to follow a single request through multiple services
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## When to Ask for Help
|
|
116
|
+
|
|
117
|
+
Stop and escalate when:
|
|
118
|
+
- You've spent 30+ minutes without progress
|
|
119
|
+
- The bug involves a third-party library you don't control
|
|
120
|
+
- It requires access to production data or systems you don't have
|
|
121
|
+
- You're tempted to add a hack/workaround instead of a real fix
|
|
122
|
+
- The fix would change security-critical code
|
|
123
|
+
|
|
124
|
+
**Debugging is a skill. The more methodical you are, the faster you solve problems.**
|