@minko-ai/minko 0.1.0 → 0.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.
- package/README.md +577 -2
- package/assets/mascot-preview.png +0 -0
- package/assets/mascot-preview.txt +46 -0
- package/assets/mascot-source.png +0 -0
- package/assets/skills/README.md +21 -0
- package/assets/skills/brainstorming/LICENSE +21 -0
- package/assets/skills/brainstorming/SKILL.md +316 -0
- package/assets/skills/buddhist-method/LICENSE +21 -0
- package/assets/skills/buddhist-method/SKILL.md +137 -0
- package/assets/skills/buddhist-method/references/ariyasacca-debug.md +57 -0
- package/assets/skills/buddhist-method/references/extended-principles.md +100 -0
- package/assets/skills/code-humanizer/LICENSE +21 -0
- package/assets/skills/code-humanizer/SKILL.md +174 -0
- package/assets/skills/code-review/LICENSE +21 -0
- package/assets/skills/code-review/SKILL.md +232 -0
- package/assets/skills/code-review/reference/angular.md +768 -0
- package/assets/skills/code-review/reference/architecture-review-guide.md +472 -0
- package/assets/skills/code-review/reference/c.md +890 -0
- package/assets/skills/code-review/reference/code-quality-universal.md +488 -0
- package/assets/skills/code-review/reference/code-review-best-practices.md +136 -0
- package/assets/skills/code-review/reference/common-bugs-checklist.md +302 -0
- package/assets/skills/code-review/reference/cpp.md +893 -0
- package/assets/skills/code-review/reference/cross-cutting/async-concurrency-patterns.md +515 -0
- package/assets/skills/code-review/reference/cross-cutting/error-handling-principles.md +492 -0
- package/assets/skills/code-review/reference/cross-cutting/n-plus-one-queries.md +309 -0
- package/assets/skills/code-review/reference/cross-cutting/sql-injection-prevention.md +308 -0
- package/assets/skills/code-review/reference/cross-cutting/xss-prevention.md +264 -0
- package/assets/skills/code-review/reference/csharp.md +525 -0
- package/assets/skills/code-review/reference/css-less-sass.md +661 -0
- package/assets/skills/code-review/reference/dart.md +670 -0
- package/assets/skills/code-review/reference/django.md +985 -0
- package/assets/skills/code-review/reference/fastapi.md +580 -0
- package/assets/skills/code-review/reference/go.md +993 -0
- package/assets/skills/code-review/reference/java.md +409 -0
- package/assets/skills/code-review/reference/java8.md +586 -0
- package/assets/skills/code-review/reference/kotlin.md +1018 -0
- package/assets/skills/code-review/reference/nestjs.md +593 -0
- package/assets/skills/code-review/reference/performance-review-guide.md +816 -0
- package/assets/skills/code-review/reference/php.md +684 -0
- package/assets/skills/code-review/reference/python.md +1073 -0
- package/assets/skills/code-review/reference/qt.md +757 -0
- package/assets/skills/code-review/reference/react.md +871 -0
- package/assets/skills/code-review/reference/ruby.md +964 -0
- package/assets/skills/code-review/reference/rust.md +846 -0
- package/assets/skills/code-review/reference/security-review-guide.md +494 -0
- package/assets/skills/code-review/reference/svelte.md +1064 -0
- package/assets/skills/code-review/reference/swift.md +936 -0
- package/assets/skills/code-review/reference/typescript.md +1016 -0
- package/assets/skills/code-review/reference/vue.md +924 -0
- package/assets/skills/code-review/reference/zig.md +440 -0
- package/assets/skills/cyclomatic-complexity/LICENSE +201 -0
- package/assets/skills/cyclomatic-complexity/SKILL.md +69 -0
- package/assets/skills/five-whys/LICENSE +21 -0
- package/assets/skills/five-whys/SKILL.md +247 -0
- package/assets/skills/five-whys/examples/performance-regression.md +161 -0
- package/assets/skills/five-whys/examples/production-incident.md +134 -0
- package/assets/skills/five-whys/references/software-patterns.md +284 -0
- package/assets/skills/five-whys/references/toyota-origins.md +257 -0
- package/assets/skills/systematic-debugging/LICENSE +21 -0
- package/assets/skills/systematic-debugging/SKILL.md +283 -0
- package/assets/skills/test-driven-development/LICENSE +21 -0
- package/assets/skills/test-driven-development/SKILL.md +330 -0
- package/assets/skills/verification-before-completion/LICENSE +21 -0
- package/assets/skills/verification-before-completion/SKILL.md +120 -0
- package/assets/skills/vibe-sec/LICENSE +201 -0
- package/assets/skills/vibe-sec/SKILL.md +758 -0
- package/assets/skills/writing-plans/LICENSE +21 -0
- package/assets/skills/writing-plans/SKILL.md +204 -0
- package/bin/minko.js +2 -2
- package/dist/agent/approvalTokens.js +224 -0
- package/dist/agent/branchLock.js +315 -0
- package/dist/agent/compact.js +182 -0
- package/dist/agent/context.js +183 -0
- package/dist/agent/cron.js +326 -0
- package/dist/agent/hooks.js +211 -0
- package/dist/agent/lanes.js +511 -0
- package/dist/agent/loop.js +337 -0
- package/dist/agent/memory.js +159 -0
- package/dist/agent/permissions.js +71 -0
- package/dist/agent/plan.js +118 -0
- package/dist/agent/prompt.js +120 -0
- package/dist/agent/subagent.js +67 -0
- package/dist/agent/tasks.js +449 -0
- package/dist/agent/transcript.js +62 -0
- package/dist/agent/workerStore.js +172 -0
- package/dist/agent/workerTypes.js +1 -0
- package/dist/agent/workers.js +503 -0
- package/dist/cli/app.js +261 -0
- package/dist/cli/argv.js +206 -0
- package/dist/cli/commandsCommand.js +12 -0
- package/dist/cli/configCommand.js +170 -0
- package/dist/cli/doctorCommand.js +112 -0
- package/dist/cli/exportCommand.js +85 -0
- package/dist/cli/forkCommand.js +24 -0
- package/dist/cli/linkCommand.js +272 -0
- package/dist/cli/loginCommand.js +69 -0
- package/dist/cli/mcpLoginCommand.js +68 -0
- package/dist/cli/pluginCommand.js +113 -0
- package/dist/cli/powerCommand.js +174 -0
- package/dist/cli/promptFooter.js +74 -0
- package/dist/cli/relayCommand.js +38 -0
- package/dist/cli/sandboxCommand.js +31 -0
- package/dist/cli/serveCommand.js +104 -0
- package/dist/cli/statusCommand.js +120 -0
- package/dist/cli/tui.js +1104 -0
- package/dist/commands/registry.js +99 -0
- package/dist/config/paths.js +81 -0
- package/dist/config/store.js +605 -0
- package/dist/index.js +199 -0
- package/dist/link/protocol.js +159 -0
- package/dist/link/relay.js +184 -0
- package/dist/link/server.js +566 -0
- package/dist/link/tunnel.js +90 -0
- package/dist/lsp/client.js +340 -0
- package/dist/lsp/tool.js +177 -0
- package/dist/mcp/client.js +469 -0
- package/dist/mcp/httpClient.js +191 -0
- package/dist/mcp/server.js +206 -0
- package/dist/mcp/tools.js +173 -0
- package/dist/oauth/device.js +111 -0
- package/dist/oauth/store.js +56 -0
- package/dist/plugins/loader.js +291 -0
- package/dist/plugins/market.js +98 -0
- package/dist/providers/anthropic.js +279 -0
- package/dist/providers/factory.js +109 -0
- package/dist/providers/openai.js +182 -0
- package/dist/providers/retry.js +95 -0
- package/dist/providers/sse.js +67 -0
- package/dist/providers/types.js +10 -0
- package/dist/rag/embeddings.js +171 -0
- package/dist/rag/index.js +373 -0
- package/dist/rag/server.js +167 -0
- package/dist/rag/tool.js +148 -0
- package/dist/sandbox/index.js +55 -0
- package/dist/sdk/server.js +150 -0
- package/dist/sdk/session.js +104 -0
- package/dist/session/liveness.js +148 -0
- package/dist/session/recorder.js +49 -0
- package/dist/session/store.js +171 -0
- package/dist/skills/index.js +428 -0
- package/dist/theme.js +30 -0
- package/dist/tools/fs.js +195 -0
- package/dist/tools/notebook.js +109 -0
- package/dist/tools/registry.js +32 -0
- package/dist/tools/search.js +130 -0
- package/dist/tools/shell.js +200 -0
- package/dist/tools/structured.js +83 -0
- package/dist/tools/types.js +1 -0
- package/dist/ui/ansi.js +135 -0
- package/dist/ui/banner.js +103 -0
- package/dist/ui/input.js +49 -0
- package/dist/ui/inputModel.js +113 -0
- package/dist/ui/keyboard.js +142 -0
- package/dist/ui/mascot.js +34 -0
- package/dist/ui/mascotData.js +96 -0
- package/dist/ui/md.js +183 -0
- package/dist/ui/screen.js +49 -0
- package/dist/ui/spinner.js +52 -0
- package/dist/ui/transcript.js +287 -0
- package/dist/util/clipboard.js +53 -0
- package/dist/util/errors.js +50 -0
- package/dist/util/version.js +12 -0
- package/dist/web/fetch.js +168 -0
- package/dist/web/search.js +97 -0
- package/package.json +45 -36
- package/src/agent/loop.ts +0 -159
- package/src/agent/prompt.ts +0 -45
- package/src/cli/app.ts +0 -396
- package/src/cli/argv.ts +0 -139
- package/src/cli/configCommand.ts +0 -175
- package/src/config/paths.ts +0 -20
- package/src/config/store.ts +0 -149
- package/src/index.ts +0 -120
- package/src/providers/anthropic.ts +0 -215
- package/src/providers/openai.ts +0 -158
- package/src/providers/sse.ts +0 -57
- package/src/providers/types.ts +0 -59
- package/src/session/store.ts +0 -125
- package/src/theme.ts +0 -41
- package/src/tools/fs.ts +0 -143
- package/src/tools/registry.ts +0 -19
- package/src/tools/shell.ts +0 -120
- package/src/tools/types.ts +0 -26
- package/src/ui/ansi.ts +0 -110
- package/src/ui/banner.ts +0 -39
- package/src/ui/input.ts +0 -54
- package/src/ui/md.ts +0 -160
- package/src/ui/spinner.ts +0 -58
- package/src/util/errors.ts +0 -48
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: systematic-debugging
|
|
3
|
+
description: Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Systematic Debugging
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
**Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.
|
|
11
|
+
|
|
12
|
+
**Violating the letter of this process is violating the spirit of debugging.**
|
|
13
|
+
|
|
14
|
+
## The Iron Law
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
If you haven't completed Phase 1, you cannot propose fixes.
|
|
21
|
+
|
|
22
|
+
## When to Use
|
|
23
|
+
|
|
24
|
+
Use for ANY technical issue:
|
|
25
|
+
- Test failures
|
|
26
|
+
- Bugs in production
|
|
27
|
+
- Unexpected behavior
|
|
28
|
+
- Performance problems
|
|
29
|
+
- Build failures
|
|
30
|
+
- Integration issues
|
|
31
|
+
|
|
32
|
+
**Use this ESPECIALLY when:**
|
|
33
|
+
- Under time pressure (emergencies make guessing tempting)
|
|
34
|
+
- "Just one quick fix" seems obvious
|
|
35
|
+
- You've already tried multiple fixes
|
|
36
|
+
- Previous fix didn't work
|
|
37
|
+
- You don't fully understand the issue
|
|
38
|
+
|
|
39
|
+
**Don't skip when:**
|
|
40
|
+
- Issue seems simple (simple bugs have root causes too)
|
|
41
|
+
- You're in a hurry (rushing guarantees rework)
|
|
42
|
+
- Manager wants it fixed NOW (systematic is faster than thrashing)
|
|
43
|
+
|
|
44
|
+
## The Four Phases
|
|
45
|
+
|
|
46
|
+
You MUST complete each phase before proceeding to the next.
|
|
47
|
+
|
|
48
|
+
### Phase 1: Root Cause Investigation
|
|
49
|
+
|
|
50
|
+
**BEFORE attempting ANY fix:**
|
|
51
|
+
|
|
52
|
+
1. **Read Error Messages Carefully**
|
|
53
|
+
- Don't skip past errors or warnings
|
|
54
|
+
- They often contain the exact solution
|
|
55
|
+
- Read stack traces completely
|
|
56
|
+
- Note line numbers, file paths, error codes
|
|
57
|
+
|
|
58
|
+
2. **Reproduce Consistently**
|
|
59
|
+
- Can you trigger it reliably?
|
|
60
|
+
- What are the exact steps?
|
|
61
|
+
- Does it happen every time?
|
|
62
|
+
- If not reproducible → gather more data, don't guess
|
|
63
|
+
|
|
64
|
+
3. **Check Recent Changes**
|
|
65
|
+
- What changed that could cause this?
|
|
66
|
+
- Git diff, recent commits
|
|
67
|
+
- New dependencies, config changes
|
|
68
|
+
- Environmental differences
|
|
69
|
+
|
|
70
|
+
4. **Gather Evidence in Multi-Component Systems**
|
|
71
|
+
|
|
72
|
+
**WHEN system has multiple components (CI → build → signing, API → service → database):**
|
|
73
|
+
|
|
74
|
+
**BEFORE proposing fixes, add diagnostic instrumentation:**
|
|
75
|
+
```
|
|
76
|
+
For EACH component boundary:
|
|
77
|
+
- Log what data enters component
|
|
78
|
+
- Log what data exits component
|
|
79
|
+
- Verify environment/config propagation
|
|
80
|
+
- Check state at each layer
|
|
81
|
+
|
|
82
|
+
Run once to gather evidence showing WHERE it breaks
|
|
83
|
+
THEN analyze evidence to identify failing component
|
|
84
|
+
THEN investigate that specific component
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Example (multi-layer system):**
|
|
88
|
+
```bash
|
|
89
|
+
# Layer 1: Workflow
|
|
90
|
+
echo "=== Secrets available in workflow: ==="
|
|
91
|
+
echo "IDENTITY: $([ -n "${IDENTITY:-}" ] && echo SET || echo UNSET)"
|
|
92
|
+
|
|
93
|
+
# Layer 2: Build script
|
|
94
|
+
echo "=== Env vars in build script: ==="
|
|
95
|
+
printenv IDENTITY >/dev/null 2>&1 && echo "IDENTITY in environment" || echo "IDENTITY not in environment"
|
|
96
|
+
|
|
97
|
+
# Layer 3: Signing script
|
|
98
|
+
echo "=== Keychain state: ==="
|
|
99
|
+
security list-keychains
|
|
100
|
+
security find-identity -v
|
|
101
|
+
|
|
102
|
+
# Layer 4: Actual signing
|
|
103
|
+
codesign --sign "$IDENTITY" --verbose=4 "$APP"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**This reveals:** Which layer fails (secrets → workflow ✓, workflow → build ✗)
|
|
107
|
+
|
|
108
|
+
5. **Trace Data Flow**
|
|
109
|
+
|
|
110
|
+
**WHEN error is deep in call stack:**
|
|
111
|
+
|
|
112
|
+
See `root-cause-tracing.md` in this directory for the complete backward tracing technique.
|
|
113
|
+
|
|
114
|
+
**Quick version:**
|
|
115
|
+
- Where does bad value originate?
|
|
116
|
+
- What called this with bad value?
|
|
117
|
+
- Keep tracing up until you find the source
|
|
118
|
+
- Fix at source, not at symptom
|
|
119
|
+
|
|
120
|
+
### Phase 2: Pattern Analysis
|
|
121
|
+
|
|
122
|
+
**Find the pattern before fixing:**
|
|
123
|
+
|
|
124
|
+
1. **Find Working Examples**
|
|
125
|
+
- Locate similar working code in same codebase
|
|
126
|
+
- What works that's similar to what's broken?
|
|
127
|
+
|
|
128
|
+
2. **Compare Against References**
|
|
129
|
+
- If implementing pattern, read reference implementation COMPLETELY
|
|
130
|
+
- Don't skim - read every line
|
|
131
|
+
- Understand the pattern fully before applying
|
|
132
|
+
|
|
133
|
+
3. **Identify Differences**
|
|
134
|
+
- What's different between working and broken?
|
|
135
|
+
- List every difference, however small
|
|
136
|
+
- Don't assume "that can't matter"
|
|
137
|
+
|
|
138
|
+
4. **Understand Dependencies**
|
|
139
|
+
- What other components does this need?
|
|
140
|
+
- What settings, config, environment?
|
|
141
|
+
- What assumptions does it make?
|
|
142
|
+
|
|
143
|
+
### Phase 3: Hypothesis and Testing
|
|
144
|
+
|
|
145
|
+
**Scientific method:**
|
|
146
|
+
|
|
147
|
+
1. **Form Single Hypothesis**
|
|
148
|
+
- State clearly: "I think X is the root cause because Y"
|
|
149
|
+
- Write it down
|
|
150
|
+
- Be specific, not vague
|
|
151
|
+
|
|
152
|
+
2. **Test Minimally**
|
|
153
|
+
- Make the SMALLEST possible change to test hypothesis
|
|
154
|
+
- One variable at a time
|
|
155
|
+
- Don't fix multiple things at once
|
|
156
|
+
|
|
157
|
+
3. **Verify Before Continuing**
|
|
158
|
+
- Did it work? Yes → Phase 4
|
|
159
|
+
- Didn't work? Form NEW hypothesis
|
|
160
|
+
- DON'T add more fixes on top
|
|
161
|
+
|
|
162
|
+
4. **When You Don't Know**
|
|
163
|
+
- Say "I don't understand X"
|
|
164
|
+
- Don't pretend to know
|
|
165
|
+
- Ask for help
|
|
166
|
+
- Research more
|
|
167
|
+
|
|
168
|
+
### Phase 4: Implementation
|
|
169
|
+
|
|
170
|
+
**Fix the root cause, not the symptom:**
|
|
171
|
+
|
|
172
|
+
1. **Create Failing Test Case**
|
|
173
|
+
- Simplest possible reproduction
|
|
174
|
+
- Automated test if possible
|
|
175
|
+
- One-off test script if no framework
|
|
176
|
+
- MUST have before fixing
|
|
177
|
+
- Use the `superpowers:test-driven-development` skill for writing proper failing tests
|
|
178
|
+
|
|
179
|
+
2. **Implement Single Fix**
|
|
180
|
+
- Address the root cause identified
|
|
181
|
+
- ONE change at a time
|
|
182
|
+
- No "while I'm here" improvements
|
|
183
|
+
- No bundled refactoring
|
|
184
|
+
|
|
185
|
+
3. **Verify Fix**
|
|
186
|
+
- Test passes now?
|
|
187
|
+
- No other tests broken?
|
|
188
|
+
- Issue actually resolved?
|
|
189
|
+
- Use the `superpowers:verification-before-completion` skill before claiming success
|
|
190
|
+
|
|
191
|
+
4. **If Fix Doesn't Work**
|
|
192
|
+
- STOP
|
|
193
|
+
- Count: How many fixes have you tried?
|
|
194
|
+
- If < 3: Return to Phase 1, re-analyze with new information
|
|
195
|
+
- **If ≥ 3: STOP and question the architecture (step 5 below)**
|
|
196
|
+
- DON'T attempt Fix #4 without architectural discussion
|
|
197
|
+
|
|
198
|
+
5. **If 3+ Fixes Failed: Question Architecture**
|
|
199
|
+
|
|
200
|
+
**Pattern indicating architectural problem:**
|
|
201
|
+
- Each fix reveals new shared state/coupling/problem in different place
|
|
202
|
+
- Fixes require "massive refactoring" to implement
|
|
203
|
+
- Each fix creates new symptoms elsewhere
|
|
204
|
+
|
|
205
|
+
**STOP and question fundamentals:**
|
|
206
|
+
- Is this pattern fundamentally sound?
|
|
207
|
+
- Are we "sticking with it through sheer inertia"?
|
|
208
|
+
- Should we refactor architecture vs. continue fixing symptoms?
|
|
209
|
+
|
|
210
|
+
**Discuss with your human partner before attempting more fixes**
|
|
211
|
+
|
|
212
|
+
This is NOT a failed hypothesis - this is a wrong architecture.
|
|
213
|
+
|
|
214
|
+
## Red Flags - STOP and Follow Process
|
|
215
|
+
|
|
216
|
+
If you catch yourself thinking:
|
|
217
|
+
- "Quick fix for now, investigate later"
|
|
218
|
+
- "Just try changing X and see if it works"
|
|
219
|
+
- "Add multiple changes, run tests"
|
|
220
|
+
- "Skip the test, I'll manually verify"
|
|
221
|
+
- "It's probably X, let me fix that"
|
|
222
|
+
- "I don't fully understand but this might work"
|
|
223
|
+
- "Pattern says X but I'll adapt it differently"
|
|
224
|
+
- "Here are the main problems: [lists fixes without investigation]"
|
|
225
|
+
- Proposing solutions before tracing data flow
|
|
226
|
+
- **"One more fix attempt" (when already tried 2+)**
|
|
227
|
+
- **Each fix reveals new problem in different place**
|
|
228
|
+
|
|
229
|
+
**ALL of these mean: STOP. Return to Phase 1.**
|
|
230
|
+
|
|
231
|
+
**If 3+ fixes failed:** Question the architecture (see Phase 4.5)
|
|
232
|
+
|
|
233
|
+
## your human partner's Signals You're Doing It Wrong
|
|
234
|
+
|
|
235
|
+
**Watch for these redirections:**
|
|
236
|
+
- "Is that not happening?" - You assumed without verifying
|
|
237
|
+
- "Will it show us...?" - You should have added evidence gathering
|
|
238
|
+
- "Stop guessing" - You're proposing fixes without understanding
|
|
239
|
+
- "Ultra-think this" - Question fundamentals, not just symptoms
|
|
240
|
+
- "We're stuck?" (frustrated) - Your approach isn't working
|
|
241
|
+
|
|
242
|
+
**When you see these:** STOP. Return to Phase 1.
|
|
243
|
+
|
|
244
|
+
## Common Rationalizations
|
|
245
|
+
|
|
246
|
+
| Excuse | Reality |
|
|
247
|
+
|--------|---------|
|
|
248
|
+
| "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. |
|
|
249
|
+
| "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. |
|
|
250
|
+
| "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. |
|
|
251
|
+
| "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. |
|
|
252
|
+
| "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |
|
|
253
|
+
| "Reference too long, I'll adapt the pattern" | Partial understanding guarantees bugs. Read it completely. |
|
|
254
|
+
| "I see the problem, let me fix it" | Seeing symptoms ≠ understanding root cause. |
|
|
255
|
+
| "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again. |
|
|
256
|
+
|
|
257
|
+
## Quick Reference
|
|
258
|
+
|
|
259
|
+
| Phase | Key Activities | Success Criteria |
|
|
260
|
+
|-------|---------------|------------------|
|
|
261
|
+
| **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |
|
|
262
|
+
| **2. Pattern** | Find working examples, compare | Identify differences |
|
|
263
|
+
| **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |
|
|
264
|
+
| **4. Implementation** | Create test, fix, verify | Bug resolved, tests pass |
|
|
265
|
+
|
|
266
|
+
## When Process Reveals "No Root Cause"
|
|
267
|
+
|
|
268
|
+
If systematic investigation reveals issue is truly environmental, timing-dependent, or external:
|
|
269
|
+
|
|
270
|
+
1. You've completed the process
|
|
271
|
+
2. Document what you investigated
|
|
272
|
+
3. Implement appropriate handling (retry, timeout, error message)
|
|
273
|
+
4. Add monitoring/logging for future investigation
|
|
274
|
+
|
|
275
|
+
**But:** 95% of "no root cause" cases are incomplete investigation.
|
|
276
|
+
|
|
277
|
+
## Supporting Techniques
|
|
278
|
+
|
|
279
|
+
These techniques are part of systematic debugging and available in this directory:
|
|
280
|
+
|
|
281
|
+
- **`root-cause-tracing.md`** - Trace bugs backward through call stack to find original trigger
|
|
282
|
+
- **`defense-in-depth.md`** - Add validation at multiple layers after finding root cause
|
|
283
|
+
- **`condition-based-waiting.md`** - Replace arbitrary timeouts with condition polling
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jesse Vincent
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: test-driven-development
|
|
3
|
+
description: Use when implementing any feature or bugfix, before writing implementation code
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Test-Driven Development (TDD)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Write the test first. Watch it fail. Write minimal code to pass.
|
|
11
|
+
|
|
12
|
+
**Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
|
|
13
|
+
|
|
14
|
+
**Violating the letter of the rules is violating the spirit of the rules.**
|
|
15
|
+
|
|
16
|
+
## When to Use
|
|
17
|
+
|
|
18
|
+
**Always:**
|
|
19
|
+
- New features
|
|
20
|
+
- Bug fixes
|
|
21
|
+
- Refactoring
|
|
22
|
+
- Behavior changes
|
|
23
|
+
|
|
24
|
+
**Exceptions (ask your human partner):**
|
|
25
|
+
- Throwaway prototypes
|
|
26
|
+
- Generated code
|
|
27
|
+
- Configuration files
|
|
28
|
+
|
|
29
|
+
Thinking "skip TDD just this once"? Stop. That's rationalization.
|
|
30
|
+
|
|
31
|
+
## The Iron Law
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Write code before the test? Delete it. Start over.
|
|
38
|
+
|
|
39
|
+
**No exceptions:**
|
|
40
|
+
- Don't keep it as "reference"
|
|
41
|
+
- Don't "adapt" it while writing tests
|
|
42
|
+
- Don't look at it
|
|
43
|
+
- Delete means delete
|
|
44
|
+
|
|
45
|
+
Implement fresh from tests. Period.
|
|
46
|
+
|
|
47
|
+
## Red-Green-Refactor
|
|
48
|
+
|
|
49
|
+
```dot
|
|
50
|
+
digraph tdd_cycle {
|
|
51
|
+
rankdir=LR;
|
|
52
|
+
red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
|
|
53
|
+
verify_red [label="Verify fails\ncorrectly", shape=diamond];
|
|
54
|
+
green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
|
|
55
|
+
verify_green [label="Verify passes\nAll green", shape=diamond];
|
|
56
|
+
refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
|
|
57
|
+
next [label="Next", shape=ellipse];
|
|
58
|
+
|
|
59
|
+
red -> verify_red;
|
|
60
|
+
verify_red -> green [label="yes"];
|
|
61
|
+
verify_red -> red [label="wrong\nfailure"];
|
|
62
|
+
green -> verify_green;
|
|
63
|
+
verify_green -> refactor [label="yes"];
|
|
64
|
+
verify_green -> green [label="no"];
|
|
65
|
+
refactor -> verify_green [label="stay\ngreen"];
|
|
66
|
+
verify_green -> next;
|
|
67
|
+
next -> red;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### RED - Write Failing Test
|
|
72
|
+
|
|
73
|
+
Write one minimal test showing what should happen.
|
|
74
|
+
|
|
75
|
+
<Good>
|
|
76
|
+
```typescript
|
|
77
|
+
test('retries failed operations 3 times', async () => {
|
|
78
|
+
let attempts = 0;
|
|
79
|
+
const operation = () => {
|
|
80
|
+
attempts++;
|
|
81
|
+
if (attempts < 3) throw new Error('fail');
|
|
82
|
+
return 'success';
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const result = await retryOperation(operation);
|
|
86
|
+
|
|
87
|
+
expect(result).toBe('success');
|
|
88
|
+
expect(attempts).toBe(3);
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
Clear name, tests real behavior, one thing
|
|
92
|
+
</Good>
|
|
93
|
+
|
|
94
|
+
<Bad>
|
|
95
|
+
```typescript
|
|
96
|
+
test('retry works', async () => {
|
|
97
|
+
const mock = jest.fn()
|
|
98
|
+
.mockRejectedValueOnce(new Error())
|
|
99
|
+
.mockRejectedValueOnce(new Error())
|
|
100
|
+
.mockResolvedValueOnce('success');
|
|
101
|
+
await retryOperation(mock);
|
|
102
|
+
expect(mock).toHaveBeenCalledTimes(3);
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
Vague name, tests mock not code
|
|
106
|
+
</Bad>
|
|
107
|
+
|
|
108
|
+
**Requirements:**
|
|
109
|
+
- One behavior
|
|
110
|
+
- Clear name
|
|
111
|
+
- Real code (no mocks unless unavoidable)
|
|
112
|
+
|
|
113
|
+
### Verify RED - Watch It Fail
|
|
114
|
+
|
|
115
|
+
**MANDATORY. Never skip.**
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm test path/to/test.test.ts
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Confirm:
|
|
122
|
+
- Test fails (not errors)
|
|
123
|
+
- Failure message is expected
|
|
124
|
+
- Fails because feature missing (not typos)
|
|
125
|
+
|
|
126
|
+
**Test passes?** You're testing existing behavior. Fix test.
|
|
127
|
+
|
|
128
|
+
**Test errors?** Fix error, re-run until it fails correctly.
|
|
129
|
+
|
|
130
|
+
### GREEN - Minimal Code
|
|
131
|
+
|
|
132
|
+
Write simplest code to pass the test.
|
|
133
|
+
|
|
134
|
+
<Good>
|
|
135
|
+
```typescript
|
|
136
|
+
async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
|
|
137
|
+
for (let i = 0; i < 3; i++) {
|
|
138
|
+
try {
|
|
139
|
+
return await fn();
|
|
140
|
+
} catch (e) {
|
|
141
|
+
if (i === 2) throw e;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
throw new Error('unreachable');
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
Just enough to pass
|
|
148
|
+
</Good>
|
|
149
|
+
|
|
150
|
+
<Bad>
|
|
151
|
+
```typescript
|
|
152
|
+
async function retryOperation<T>(
|
|
153
|
+
fn: () => Promise<T>,
|
|
154
|
+
options?: {
|
|
155
|
+
maxRetries?: number;
|
|
156
|
+
backoff?: 'linear' | 'exponential';
|
|
157
|
+
onRetry?: (attempt: number) => void;
|
|
158
|
+
}
|
|
159
|
+
): Promise<T> {
|
|
160
|
+
// YAGNI
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
Over-engineered
|
|
164
|
+
</Bad>
|
|
165
|
+
|
|
166
|
+
Don't add features, refactor other code, or "improve" beyond the test.
|
|
167
|
+
|
|
168
|
+
### Verify GREEN - Watch It Pass
|
|
169
|
+
|
|
170
|
+
**MANDATORY.**
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
npm test path/to/test.test.ts
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Confirm:
|
|
177
|
+
- Test passes
|
|
178
|
+
- Other tests still pass
|
|
179
|
+
- Output pristine (no errors, warnings)
|
|
180
|
+
|
|
181
|
+
**Test fails?** Fix code, not test.
|
|
182
|
+
|
|
183
|
+
**Other tests fail?** Fix now.
|
|
184
|
+
|
|
185
|
+
**"Other tests" means the project's suite, not just your file.** A
|
|
186
|
+
green run of the test you wrote is not a green suite. Before you call
|
|
187
|
+
the change done, run the project's test command (bare `pytest`,
|
|
188
|
+
`npm test`, `cargo test` — whatever the repo uses) even when your task
|
|
189
|
+
named only one test file. A scope statement in your task bounds the
|
|
190
|
+
deliverable, not your verification. Any failure that run shows —
|
|
191
|
+
including one you didn't cause — goes in your report by name; a red
|
|
192
|
+
test you watched scroll past and didn't mention is a report falsified
|
|
193
|
+
by omission.
|
|
194
|
+
|
|
195
|
+
### REFACTOR - Clean Up
|
|
196
|
+
|
|
197
|
+
After green only:
|
|
198
|
+
- Remove duplication
|
|
199
|
+
- Improve names
|
|
200
|
+
- Extract helpers
|
|
201
|
+
|
|
202
|
+
Keep tests green. Don't add behavior.
|
|
203
|
+
|
|
204
|
+
### Repeat
|
|
205
|
+
|
|
206
|
+
Next failing test for next feature.
|
|
207
|
+
|
|
208
|
+
## Good Tests
|
|
209
|
+
|
|
210
|
+
| Quality | Good | Bad |
|
|
211
|
+
|---------|------|-----|
|
|
212
|
+
| **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
|
|
213
|
+
| **Clear** | Name describes behavior | `test('test1')` |
|
|
214
|
+
| **Shows intent** | Demonstrates desired API | Obscures what code should do |
|
|
215
|
+
|
|
216
|
+
When writing or changing any test, read [writing-good-tests.md](writing-good-tests.md) for the rules that keep tests honest:
|
|
217
|
+
- Name the production change that would make the test fail — before writing it
|
|
218
|
+
- Assert on real behavior, never on mock behavior
|
|
219
|
+
- Keep test-only code in test utilities, out of production classes
|
|
220
|
+
- Understand a dependency's side effects before mocking it
|
|
221
|
+
|
|
222
|
+
## Common Rationalizations
|
|
223
|
+
|
|
224
|
+
| Excuse | Reality |
|
|
225
|
+
|--------|---------|
|
|
226
|
+
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
|
|
227
|
+
| "I'll test after" | Tests written after pass immediately — which proves nothing. They may test the wrong thing, test the implementation instead of the behavior, or miss the edge case you forgot. You never watched it fail, so you never proved it can catch the bug. Test-first forces that failure. |
|
|
228
|
+
| "Tests after achieve same goals (spirit not ritual)" | Tests-after answer "what does this do?"; tests-first answer "what should this do?" Tests written after are biased by the code you already wrote — you verify the cases you remembered, not the ones you'd have discovered. Coverage without proof the tests work. |
|
|
229
|
+
| "Already manually tested" | Manual testing is ad-hoc: no record of what you covered, no way to re-run it when the code changes, easy to forget cases under pressure. "Worked when I tried it" ≠ comprehensive. Automated tests run the same way every time. |
|
|
230
|
+
| "Deleting X hours is wasteful" | Sunk cost fallacy — that time is already spent either way. The real choice: rewrite with TDD (high confidence) vs. keep it and bolt tests on after (low confidence, likely bugs). Keeping code you can't trust is the waste. |
|
|
231
|
+
| "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
|
|
232
|
+
| "Need to explore first" | Fine. Throw away exploration, start with TDD. |
|
|
233
|
+
| "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
|
|
234
|
+
| "TDD will slow me down" | TDD IS the pragmatic path: catches bugs before commit, prevents regressions, lets you refactor without fear. "Pragmatic" shortcuts mean debugging in production — slower, not faster. |
|
|
235
|
+
| "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
|
|
236
|
+
| "Existing code has no tests" | You're improving it. Add tests for existing code. |
|
|
237
|
+
|
|
238
|
+
## Red Flags - STOP and Start Over
|
|
239
|
+
|
|
240
|
+
- Code before test
|
|
241
|
+
- Test after implementation
|
|
242
|
+
- Test passes immediately
|
|
243
|
+
- Can't explain why test failed
|
|
244
|
+
- Tests added "later"
|
|
245
|
+
- Rationalizing "just this once"
|
|
246
|
+
- "I already manually tested it"
|
|
247
|
+
- "Tests after achieve the same purpose"
|
|
248
|
+
- "It's about spirit not ritual"
|
|
249
|
+
- "Keep as reference" or "adapt existing code"
|
|
250
|
+
- "Already spent X hours, deleting is wasteful"
|
|
251
|
+
- "TDD is dogmatic, I'm being pragmatic"
|
|
252
|
+
- "This is different because..."
|
|
253
|
+
|
|
254
|
+
**All of these mean: Delete code. Start over with TDD.**
|
|
255
|
+
|
|
256
|
+
## Example: Bug Fix
|
|
257
|
+
|
|
258
|
+
**Bug:** Empty email accepted
|
|
259
|
+
|
|
260
|
+
**RED**
|
|
261
|
+
```typescript
|
|
262
|
+
test('rejects empty email', async () => {
|
|
263
|
+
const result = await submitForm({ email: '' });
|
|
264
|
+
expect(result.error).toBe('Email required');
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
**Verify RED**
|
|
269
|
+
```bash
|
|
270
|
+
$ npm test
|
|
271
|
+
FAIL: expected 'Email required', got undefined
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
**GREEN**
|
|
275
|
+
```typescript
|
|
276
|
+
function submitForm(data: FormData) {
|
|
277
|
+
if (!data.email?.trim()) {
|
|
278
|
+
return { error: 'Email required' };
|
|
279
|
+
}
|
|
280
|
+
// ...
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
**Verify GREEN**
|
|
285
|
+
```bash
|
|
286
|
+
$ npm test
|
|
287
|
+
PASS
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
**REFACTOR**
|
|
291
|
+
Extract validation for multiple fields if needed.
|
|
292
|
+
|
|
293
|
+
## Verification Checklist
|
|
294
|
+
|
|
295
|
+
Before marking work complete:
|
|
296
|
+
|
|
297
|
+
- [ ] Every new function/method has a test
|
|
298
|
+
- [ ] Watched each test fail before implementing
|
|
299
|
+
- [ ] Each test failed for expected reason (feature missing, not typo)
|
|
300
|
+
- [ ] Wrote minimal code to pass each test
|
|
301
|
+
- [ ] All tests pass
|
|
302
|
+
- [ ] Output pristine (no errors, warnings)
|
|
303
|
+
- [ ] Tests use real code (mocks only if unavoidable)
|
|
304
|
+
- [ ] Edge cases and errors covered
|
|
305
|
+
|
|
306
|
+
Can't check all boxes? You skipped TDD. Start over.
|
|
307
|
+
|
|
308
|
+
## When Stuck
|
|
309
|
+
|
|
310
|
+
| Problem | Solution |
|
|
311
|
+
|---------|----------|
|
|
312
|
+
| Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
|
|
313
|
+
| Test too complicated | Design too complicated. Simplify interface. |
|
|
314
|
+
| Must mock everything | Code too coupled. Use dependency injection. |
|
|
315
|
+
| Test setup huge | Extract helpers. Still complex? Simplify design. |
|
|
316
|
+
|
|
317
|
+
## Debugging Integration
|
|
318
|
+
|
|
319
|
+
Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
|
|
320
|
+
|
|
321
|
+
Never fix bugs without a test.
|
|
322
|
+
|
|
323
|
+
## Final Rule
|
|
324
|
+
|
|
325
|
+
```
|
|
326
|
+
Production code → test exists and failed first
|
|
327
|
+
Otherwise → not TDD
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
No exceptions without your human partner's permission.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jesse Vincent
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|