@protolabsai/proto 0.14.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.
Files changed (85) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +286 -0
  3. package/dist/bundled/adversarial-verification/SKILL.md +98 -0
  4. package/dist/bundled/brainstorming/SKILL.md +171 -0
  5. package/dist/bundled/coding-agent-standards/SKILL.md +67 -0
  6. package/dist/bundled/dispatching-parallel-agents/SKILL.md +193 -0
  7. package/dist/bundled/executing-plans/SKILL.md +77 -0
  8. package/dist/bundled/finishing-a-development-branch/SKILL.md +213 -0
  9. package/dist/bundled/loop/SKILL.md +61 -0
  10. package/dist/bundled/qc-helper/SKILL.md +151 -0
  11. package/dist/bundled/qc-helper/docs/_meta.ts +30 -0
  12. package/dist/bundled/qc-helper/docs/common-workflow.md +571 -0
  13. package/dist/bundled/qc-helper/docs/configuration/_meta.ts +10 -0
  14. package/dist/bundled/qc-helper/docs/configuration/auth.md +366 -0
  15. package/dist/bundled/qc-helper/docs/configuration/memory.md +0 -0
  16. package/dist/bundled/qc-helper/docs/configuration/model-providers.md +542 -0
  17. package/dist/bundled/qc-helper/docs/configuration/qwen-ignore.md +55 -0
  18. package/dist/bundled/qc-helper/docs/configuration/settings.md +652 -0
  19. package/dist/bundled/qc-helper/docs/configuration/themes.md +160 -0
  20. package/dist/bundled/qc-helper/docs/configuration/trusted-folders.md +61 -0
  21. package/dist/bundled/qc-helper/docs/extension/_meta.ts +9 -0
  22. package/dist/bundled/qc-helper/docs/extension/extension-releasing.md +121 -0
  23. package/dist/bundled/qc-helper/docs/extension/getting-started-extensions.md +299 -0
  24. package/dist/bundled/qc-helper/docs/extension/introduction.md +303 -0
  25. package/dist/bundled/qc-helper/docs/features/_meta.ts +18 -0
  26. package/dist/bundled/qc-helper/docs/features/approval-mode.md +263 -0
  27. package/dist/bundled/qc-helper/docs/features/arena.md +218 -0
  28. package/dist/bundled/qc-helper/docs/features/checkpointing.md +77 -0
  29. package/dist/bundled/qc-helper/docs/features/commands.md +312 -0
  30. package/dist/bundled/qc-helper/docs/features/headless.md +318 -0
  31. package/dist/bundled/qc-helper/docs/features/hooks.md +343 -0
  32. package/dist/bundled/qc-helper/docs/features/language.md +139 -0
  33. package/dist/bundled/qc-helper/docs/features/lsp.md +453 -0
  34. package/dist/bundled/qc-helper/docs/features/mcp.md +281 -0
  35. package/dist/bundled/qc-helper/docs/features/sandbox.md +241 -0
  36. package/dist/bundled/qc-helper/docs/features/scheduled-tasks.md +139 -0
  37. package/dist/bundled/qc-helper/docs/features/skills.md +289 -0
  38. package/dist/bundled/qc-helper/docs/features/sub-agents.md +307 -0
  39. package/dist/bundled/qc-helper/docs/features/token-caching.md +29 -0
  40. package/dist/bundled/qc-helper/docs/ide-integration/_meta.ts +4 -0
  41. package/dist/bundled/qc-helper/docs/ide-integration/ide-companion-spec.md +182 -0
  42. package/dist/bundled/qc-helper/docs/ide-integration/ide-integration.md +144 -0
  43. package/dist/bundled/qc-helper/docs/integration-github-action.md +241 -0
  44. package/dist/bundled/qc-helper/docs/integration-jetbrains.md +81 -0
  45. package/dist/bundled/qc-helper/docs/integration-vscode.md +39 -0
  46. package/dist/bundled/qc-helper/docs/integration-zed.md +72 -0
  47. package/dist/bundled/qc-helper/docs/overview.md +64 -0
  48. package/dist/bundled/qc-helper/docs/quickstart.md +273 -0
  49. package/dist/bundled/qc-helper/docs/reference/_meta.ts +4 -0
  50. package/dist/bundled/qc-helper/docs/reference/keyboard-shortcuts.md +72 -0
  51. package/dist/bundled/qc-helper/docs/reference/sdk-api.md +524 -0
  52. package/dist/bundled/qc-helper/docs/support/Uninstall.md +42 -0
  53. package/dist/bundled/qc-helper/docs/support/_meta.ts +6 -0
  54. package/dist/bundled/qc-helper/docs/support/tos-privacy.md +112 -0
  55. package/dist/bundled/qc-helper/docs/support/troubleshooting.md +123 -0
  56. package/dist/bundled/receiving-code-review/SKILL.md +226 -0
  57. package/dist/bundled/requesting-code-review/SKILL.md +115 -0
  58. package/dist/bundled/review/SKILL.md +123 -0
  59. package/dist/bundled/subagent-driven-development/SKILL.md +292 -0
  60. package/dist/bundled/subagent-driven-development/code-quality-reviewer-prompt.md +27 -0
  61. package/dist/bundled/subagent-driven-development/implementer-prompt.md +113 -0
  62. package/dist/bundled/subagent-driven-development/spec-reviewer-prompt.md +61 -0
  63. package/dist/bundled/systematic-debugging/SKILL.md +305 -0
  64. package/dist/bundled/test-driven-development/SKILL.md +396 -0
  65. package/dist/bundled/using-git-worktrees/SKILL.md +223 -0
  66. package/dist/bundled/using-superpowers/SKILL.md +117 -0
  67. package/dist/bundled/verification-before-completion/SKILL.md +147 -0
  68. package/dist/bundled/writing-plans/SKILL.md +159 -0
  69. package/dist/bundled/writing-skills/SKILL.md +716 -0
  70. package/dist/cli.js +483432 -0
  71. package/dist/sandbox-macos-permissive-closed.sb +32 -0
  72. package/dist/sandbox-macos-permissive-open.sb +27 -0
  73. package/dist/sandbox-macos-permissive-proxied.sb +37 -0
  74. package/dist/sandbox-macos-restrictive-closed.sb +93 -0
  75. package/dist/sandbox-macos-restrictive-open.sb +96 -0
  76. package/dist/sandbox-macos-restrictive-proxied.sb +98 -0
  77. package/dist/vendor/ripgrep/COPYING +3 -0
  78. package/dist/vendor/ripgrep/arm64-darwin/rg +0 -0
  79. package/dist/vendor/ripgrep/arm64-linux/rg +0 -0
  80. package/dist/vendor/ripgrep/x64-darwin/rg +0 -0
  81. package/dist/vendor/ripgrep/x64-linux/rg +0 -0
  82. package/dist/vendor/ripgrep/x64-win32/rg.exe +0 -0
  83. package/dist/vendor/tree-sitter/tree-sitter-bash.wasm +0 -0
  84. package/dist/vendor/tree-sitter/tree-sitter.wasm +0 -0
  85. package/package.json +143 -0
@@ -0,0 +1,305 @@
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
+ Random fixes waste time and create new bugs. Quick patches mask underlying issues.
11
+
12
+ **Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.
13
+
14
+ **Violating the letter of this process is violating the spirit of debugging.**
15
+
16
+ ## The Iron Law
17
+
18
+ ```
19
+ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
20
+ ```
21
+
22
+ If you haven't completed Phase 1, you cannot propose fixes.
23
+
24
+ ## When to Use
25
+
26
+ Use for ANY technical issue:
27
+
28
+ - Test failures
29
+ - Bugs in production
30
+ - Unexpected behavior
31
+ - Performance problems
32
+ - Build failures
33
+ - Integration issues
34
+
35
+ **Use this ESPECIALLY when:**
36
+
37
+ - Under time pressure (emergencies make guessing tempting)
38
+ - "Just one quick fix" seems obvious
39
+ - You've already tried multiple fixes
40
+ - Previous fix didn't work
41
+ - You don't fully understand the issue
42
+
43
+ **Don't skip when:**
44
+
45
+ - Issue seems simple (simple bugs have root causes too)
46
+ - You're in a hurry (rushing guarantees rework)
47
+ - Manager wants it fixed NOW (systematic is faster than thrashing)
48
+
49
+ ## The Four Phases
50
+
51
+ You MUST complete each phase before proceeding to the next.
52
+
53
+ ### Phase 1: Root Cause Investigation
54
+
55
+ **BEFORE attempting ANY fix:**
56
+
57
+ 1. **Read Error Messages Carefully**
58
+ - Don't skip past errors or warnings
59
+ - They often contain the exact solution
60
+ - Read stack traces completely
61
+ - Note line numbers, file paths, error codes
62
+
63
+ 2. **Reproduce Consistently**
64
+ - Can you trigger it reliably?
65
+ - What are the exact steps?
66
+ - Does it happen every time?
67
+ - If not reproducible → gather more data, don't guess
68
+
69
+ 3. **Check Recent Changes**
70
+ - What changed that could cause this?
71
+ - Git diff, recent commits
72
+ - New dependencies, config changes
73
+ - Environmental differences
74
+
75
+ 4. **Gather Evidence in Multi-Component Systems**
76
+
77
+ **WHEN system has multiple components (CI → build → signing, API → service → database):**
78
+
79
+ **BEFORE proposing fixes, add diagnostic instrumentation:**
80
+
81
+ ```
82
+ For EACH component boundary:
83
+ - Log what data enters component
84
+ - Log what data exits component
85
+ - Verify environment/config propagation
86
+ - Check state at each layer
87
+
88
+ Run once to gather evidence showing WHERE it breaks
89
+ THEN analyze evidence to identify failing component
90
+ THEN investigate that specific component
91
+ ```
92
+
93
+ **Example (multi-layer system):**
94
+
95
+ ```bash
96
+ # Layer 1: Workflow
97
+ echo "=== Secrets available in workflow: ==="
98
+ echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
99
+
100
+ # Layer 2: Build script
101
+ echo "=== Env vars in build script: ==="
102
+ env | grep IDENTITY || echo "IDENTITY not in environment"
103
+
104
+ # Layer 3: Signing script
105
+ echo "=== Keychain state: ==="
106
+ security list-keychains
107
+ security find-identity -v
108
+
109
+ # Layer 4: Actual signing
110
+ codesign --sign "$IDENTITY" --verbose=4 "$APP"
111
+ ```
112
+
113
+ **This reveals:** Which layer fails (secrets → workflow ✓, workflow → build ✗)
114
+
115
+ 5. **Trace Data Flow**
116
+
117
+ **WHEN error is deep in call stack:**
118
+
119
+ See `root-cause-tracing.md` in this directory for the complete backward tracing technique.
120
+
121
+ **Quick version:**
122
+ - Where does bad value originate?
123
+ - What called this with bad value?
124
+ - Keep tracing up until you find the source
125
+ - Fix at source, not at symptom
126
+
127
+ ### Phase 2: Pattern Analysis
128
+
129
+ **Find the pattern before fixing:**
130
+
131
+ 1. **Find Working Examples**
132
+ - Locate similar working code in same codebase
133
+ - What works that's similar to what's broken?
134
+
135
+ 2. **Compare Against References**
136
+ - If implementing pattern, read reference implementation COMPLETELY
137
+ - Don't skim - read every line
138
+ - Understand the pattern fully before applying
139
+
140
+ 3. **Identify Differences**
141
+ - What's different between working and broken?
142
+ - List every difference, however small
143
+ - Don't assume "that can't matter"
144
+
145
+ 4. **Understand Dependencies**
146
+ - What other components does this need?
147
+ - What settings, config, environment?
148
+ - What assumptions does it make?
149
+
150
+ ### Phase 3: Hypothesis and Testing
151
+
152
+ **Scientific method:**
153
+
154
+ 1. **Form Single Hypothesis**
155
+ - State clearly: "I think X is the root cause because Y"
156
+ - Write it down
157
+ - Be specific, not vague
158
+
159
+ 2. **Test Minimally**
160
+ - Make the SMALLEST possible change to test hypothesis
161
+ - One variable at a time
162
+ - Don't fix multiple things at once
163
+
164
+ 3. **Verify Before Continuing**
165
+ - Did it work? Yes → Phase 4
166
+ - Didn't work? Form NEW hypothesis
167
+ - DON'T add more fixes on top
168
+
169
+ 4. **When You Don't Know**
170
+ - Say "I don't understand X"
171
+ - Don't pretend to know
172
+ - Ask for help
173
+ - Research more
174
+
175
+ ### Phase 4: Implementation
176
+
177
+ **Fix the root cause, not the symptom:**
178
+
179
+ 1. **Create Failing Test Case**
180
+ - Simplest possible reproduction
181
+ - Automated test if possible
182
+ - One-off test script if no framework
183
+ - MUST have before fixing
184
+ - Use the `superpowers:test-driven-development` skill for writing proper failing tests
185
+
186
+ 2. **Implement Single Fix**
187
+ - Address the root cause identified
188
+ - ONE change at a time
189
+ - No "while I'm here" improvements
190
+ - No bundled refactoring
191
+
192
+ 3. **Verify Fix**
193
+ - Test passes now?
194
+ - No other tests broken?
195
+ - Issue actually resolved?
196
+
197
+ 4. **If Fix Doesn't Work**
198
+ - STOP
199
+ - Count: How many fixes have you tried?
200
+ - If < 3: Return to Phase 1, re-analyze with new information
201
+ - **If ≥ 3: STOP and question the architecture (step 5 below)**
202
+ - DON'T attempt Fix #4 without architectural discussion
203
+
204
+ 5. **If 3+ Fixes Failed: Question Architecture**
205
+
206
+ **Pattern indicating architectural problem:**
207
+ - Each fix reveals new shared state/coupling/problem in different place
208
+ - Fixes require "massive refactoring" to implement
209
+ - Each fix creates new symptoms elsewhere
210
+
211
+ **STOP and question fundamentals:**
212
+ - Is this pattern fundamentally sound?
213
+ - Are we "sticking with it through sheer inertia"?
214
+ - Should we refactor architecture vs. continue fixing symptoms?
215
+
216
+ **Discuss with your human partner before attempting more fixes**
217
+
218
+ This is NOT a failed hypothesis - this is a wrong architecture.
219
+
220
+ ## Red Flags - STOP and Follow Process
221
+
222
+ If you catch yourself thinking:
223
+
224
+ - "Quick fix for now, investigate later"
225
+ - "Just try changing X and see if it works"
226
+ - "Add multiple changes, run tests"
227
+ - "Skip the test, I'll manually verify"
228
+ - "It's probably X, let me fix that"
229
+ - "I don't fully understand but this might work"
230
+ - "Pattern says X but I'll adapt it differently"
231
+ - "Here are the main problems: [lists fixes without investigation]"
232
+ - Proposing solutions before tracing data flow
233
+ - **"One more fix attempt" (when already tried 2+)**
234
+ - **Each fix reveals new problem in different place**
235
+
236
+ **ALL of these mean: STOP. Return to Phase 1.**
237
+
238
+ **If 3+ fixes failed:** Question the architecture (see Phase 4.5)
239
+
240
+ ## your human partner's Signals You're Doing It Wrong
241
+
242
+ **Watch for these redirections:**
243
+
244
+ - "Is that not happening?" - You assumed without verifying
245
+ - "Will it show us...?" - You should have added evidence gathering
246
+ - "Stop guessing" - You're proposing fixes without understanding
247
+ - "Ultrathink this" - Question fundamentals, not just symptoms
248
+ - "We're stuck?" (frustrated) - Your approach isn't working
249
+
250
+ **When you see these:** STOP. Return to Phase 1.
251
+
252
+ ## Common Rationalizations
253
+
254
+ | Excuse | Reality |
255
+ | -------------------------------------------- | ----------------------------------------------------------------------- |
256
+ | "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. |
257
+ | "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. |
258
+ | "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. |
259
+ | "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. |
260
+ | "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |
261
+ | "Reference too long, I'll adapt the pattern" | Partial understanding guarantees bugs. Read it completely. |
262
+ | "I see the problem, let me fix it" | Seeing symptoms ≠ understanding root cause. |
263
+ | "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again. |
264
+
265
+ ## Quick Reference
266
+
267
+ | Phase | Key Activities | Success Criteria |
268
+ | --------------------- | ------------------------------------------------------ | --------------------------- |
269
+ | **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |
270
+ | **2. Pattern** | Find working examples, compare | Identify differences |
271
+ | **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |
272
+ | **4. Implementation** | Create test, fix, verify | Bug resolved, tests pass |
273
+
274
+ ## When Process Reveals "No Root Cause"
275
+
276
+ If systematic investigation reveals issue is truly environmental, timing-dependent, or external:
277
+
278
+ 1. You've completed the process
279
+ 2. Document what you investigated
280
+ 3. Implement appropriate handling (retry, timeout, error message)
281
+ 4. Add monitoring/logging for future investigation
282
+
283
+ **But:** 95% of "no root cause" cases are incomplete investigation.
284
+
285
+ ## Supporting Techniques
286
+
287
+ These techniques are part of systematic debugging and available in this directory:
288
+
289
+ - **`root-cause-tracing.md`** - Trace bugs backward through call stack to find original trigger
290
+ - **`defense-in-depth.md`** - Add validation at multiple layers after finding root cause
291
+ - **`condition-based-waiting.md`** - Replace arbitrary timeouts with condition polling
292
+
293
+ **Related skills:**
294
+
295
+ - **superpowers:test-driven-development** - For creating failing test case (Phase 4, Step 1)
296
+ - **superpowers:verification-before-completion** - Verify fix worked before claiming success
297
+
298
+ ## Real-World Impact
299
+
300
+ From debugging sessions:
301
+
302
+ - Systematic approach: 15-30 minutes to fix
303
+ - Random fixes approach: 2-3 hours of thrashing
304
+ - First-time fix rate: 95% vs 40%
305
+ - New bugs introduced: Near zero vs common
@@ -0,0 +1,396 @@
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
+
20
+ - New features
21
+ - Bug fixes
22
+ - Refactoring
23
+ - Behavior changes
24
+
25
+ **Exceptions (ask your human partner):**
26
+
27
+ - Throwaway prototypes
28
+ - Generated code
29
+ - Configuration files
30
+
31
+ Thinking "skip TDD just this once"? Stop. That's rationalization.
32
+
33
+ ## The Iron Law
34
+
35
+ ```
36
+ NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
37
+ ```
38
+
39
+ Write code before the test? Delete it. Start over.
40
+
41
+ **No exceptions:**
42
+
43
+ - Don't keep it as "reference"
44
+ - Don't "adapt" it while writing tests
45
+ - Don't look at it
46
+ - Delete means delete
47
+
48
+ Implement fresh from tests. Period.
49
+
50
+ ## Red-Green-Refactor
51
+
52
+ ```dot
53
+ digraph tdd_cycle {
54
+ rankdir=LR;
55
+ red [label="RED
56
+ Write failing test", shape=box, style=filled, fillcolor="#ffcccc"];
57
+ verify_red [label="Verify fails
58
+ correctly", shape=diamond];
59
+ green [label="GREEN
60
+ Minimal code", shape=box, style=filled, fillcolor="#ccffcc"];
61
+ verify_green [label="Verify passes
62
+ All green", shape=diamond];
63
+ refactor [label="REFACTOR
64
+ Clean up", shape=box, style=filled, fillcolor="#ccccff"];
65
+ next [label="Next", shape=ellipse];
66
+
67
+ red -> verify_red;
68
+ verify_red -> green [label="yes"];
69
+ verify_red -> red [label="wrong
70
+ failure"];
71
+ green -> verify_green;
72
+ verify_green -> refactor [label="yes"];
73
+ verify_green -> green [label="no"];
74
+ refactor -> verify_green [label="stay
75
+ green"];
76
+ verify_green -> next;
77
+ next -> red;
78
+ }
79
+ ```
80
+
81
+ ### RED - Write Failing Test
82
+
83
+ Write one minimal test showing what should happen.
84
+
85
+ <Good>
86
+ ```typescript
87
+ test('retries failed operations 3 times', async () => {
88
+ let attempts = 0;
89
+ const operation = () => {
90
+ attempts++;
91
+ if (attempts < 3) throw new Error('fail');
92
+ return 'success';
93
+ };
94
+
95
+ const result = await retryOperation(operation);
96
+
97
+ expect(result).toBe('success');
98
+ expect(attempts).toBe(3);
99
+ });
100
+
101
+ ````
102
+ Clear name, tests real behavior, one thing
103
+ </Good>
104
+
105
+ <Bad>
106
+ ```typescript
107
+ test('retry works', async () => {
108
+ const mock = jest.fn()
109
+ .mockRejectedValueOnce(new Error())
110
+ .mockRejectedValueOnce(new Error())
111
+ .mockResolvedValueOnce('success');
112
+ await retryOperation(mock);
113
+ expect(mock).toHaveBeenCalledTimes(3);
114
+ });
115
+ ````
116
+
117
+ Vague name, tests mock not code
118
+ </Bad>
119
+
120
+ **Requirements:**
121
+
122
+ - One behavior
123
+ - Clear name
124
+ - Real code (no mocks unless unavoidable)
125
+
126
+ ### Verify RED - Watch It Fail
127
+
128
+ **MANDATORY. Never skip.**
129
+
130
+ ```bash
131
+ npm test path/to/test.test.ts
132
+ ```
133
+
134
+ Confirm:
135
+
136
+ - Test fails (not errors)
137
+ - Failure message is expected
138
+ - Fails because feature missing (not typos)
139
+
140
+ **Test passes?** You're testing existing behavior. Fix test.
141
+
142
+ **Test errors?** Fix error, re-run until it fails correctly.
143
+
144
+ ### GREEN - Minimal Code
145
+
146
+ Write simplest code to pass the test.
147
+
148
+ <Good>
149
+ ```typescript
150
+ async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
151
+ for (let i = 0; i < 3; i++) {
152
+ try {
153
+ return await fn();
154
+ } catch (e) {
155
+ if (i === 2) throw e;
156
+ }
157
+ }
158
+ throw new Error('unreachable');
159
+ }
160
+ ```
161
+ Just enough to pass
162
+ </Good>
163
+
164
+ <Bad>
165
+ ```typescript
166
+ async function retryOperation<T>(
167
+ fn: () => Promise<T>,
168
+ options?: {
169
+ maxRetries?: number;
170
+ backoff?: 'linear' | 'exponential';
171
+ onRetry?: (attempt: number) => void;
172
+ }
173
+ ): Promise<T> {
174
+ // YAGNI
175
+ }
176
+ ```
177
+ Over-engineered
178
+ </Bad>
179
+
180
+ Don't add features, refactor other code, or "improve" beyond the test.
181
+
182
+ ### Verify GREEN - Watch It Pass
183
+
184
+ **MANDATORY.**
185
+
186
+ ```bash
187
+ npm test path/to/test.test.ts
188
+ ```
189
+
190
+ Confirm:
191
+
192
+ - Test passes
193
+ - Other tests still pass
194
+ - Output pristine (no errors, warnings)
195
+
196
+ **Test fails?** Fix code, not test.
197
+
198
+ **Other tests fail?** Fix now.
199
+
200
+ ### REFACTOR - Clean Up
201
+
202
+ After green only:
203
+
204
+ - Remove duplication
205
+ - Improve names
206
+ - Extract helpers
207
+
208
+ Keep tests green. Don't add behavior.
209
+
210
+ ### Repeat
211
+
212
+ Next failing test for next feature.
213
+
214
+ ## Good Tests
215
+
216
+ | Quality | Good | Bad |
217
+ | ---------------- | ----------------------------------- | --------------------------------------------------- |
218
+ | **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
219
+ | **Clear** | Name describes behavior | `test('test1')` |
220
+ | **Shows intent** | Demonstrates desired API | Obscures what code should do |
221
+
222
+ ## Why Order Matters
223
+
224
+ **"I'll write tests after to verify it works"**
225
+
226
+ Tests written after code pass immediately. Passing immediately proves nothing:
227
+
228
+ - Might test wrong thing
229
+ - Might test implementation, not behavior
230
+ - Might miss edge cases you forgot
231
+ - You never saw it catch the bug
232
+
233
+ Test-first forces you to see the test fail, proving it actually tests something.
234
+
235
+ **"I already manually tested all the edge cases"**
236
+
237
+ Manual testing is ad-hoc. You think you tested everything but:
238
+
239
+ - No record of what you tested
240
+ - Can't re-run when code changes
241
+ - Easy to forget cases under pressure
242
+ - "It worked when I tried it" ≠ comprehensive
243
+
244
+ Automated tests are systematic. They run the same way every time.
245
+
246
+ **"Deleting X hours of work is wasteful"**
247
+
248
+ Sunk cost fallacy. The time is already gone. Your choice now:
249
+
250
+ - Delete and rewrite with TDD (X more hours, high confidence)
251
+ - Keep it and add tests after (30 min, low confidence, likely bugs)
252
+
253
+ The "waste" is keeping code you can't trust. Working code without real tests is technical debt.
254
+
255
+ **"TDD is dogmatic, being pragmatic means adapting"**
256
+
257
+ TDD IS pragmatic:
258
+
259
+ - Finds bugs before commit (faster than debugging after)
260
+ - Prevents regressions (tests catch breaks immediately)
261
+ - Documents behavior (tests show how to use code)
262
+ - Enables refactoring (change freely, tests catch breaks)
263
+
264
+ "Pragmatic" shortcuts = debugging in production = slower.
265
+
266
+ **"Tests after achieve the same goals - it's spirit not ritual"**
267
+
268
+ No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
269
+
270
+ Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones.
271
+
272
+ Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't).
273
+
274
+ 30 minutes of tests after ≠ TDD. You get coverage, lose proof tests work.
275
+
276
+ ## Common Rationalizations
277
+
278
+ | Excuse | Reality |
279
+ | -------------------------------------- | ----------------------------------------------------------------------- |
280
+ | "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
281
+ | "I'll test after" | Tests passing immediately prove nothing. |
282
+ | "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
283
+ | "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
284
+ | "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
285
+ | "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
286
+ | "Need to explore first" | Fine. Throw away exploration, start with TDD. |
287
+ | "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
288
+ | "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
289
+ | "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
290
+ | "Existing code has no tests" | You're improving it. Add tests for existing code. |
291
+
292
+ ## Red Flags - STOP and Start Over
293
+
294
+ - Code before test
295
+ - Test after implementation
296
+ - Test passes immediately
297
+ - Can't explain why test failed
298
+ - Tests added "later"
299
+ - Rationalizing "just this once"
300
+ - "I already manually tested it"
301
+ - "Tests after achieve the same purpose"
302
+ - "It's about spirit not ritual"
303
+ - "Keep as reference" or "adapt existing code"
304
+ - "Already spent X hours, deleting is wasteful"
305
+ - "TDD is dogmatic, I'm being pragmatic"
306
+ - "This is different because..."
307
+
308
+ **All of these mean: Delete code. Start over with TDD.**
309
+
310
+ ## Example: Bug Fix
311
+
312
+ **Bug:** Empty email accepted
313
+
314
+ **RED**
315
+
316
+ ```typescript
317
+ test('rejects empty email', async () => {
318
+ const result = await submitForm({ email: '' });
319
+ expect(result.error).toBe('Email required');
320
+ });
321
+ ```
322
+
323
+ **Verify RED**
324
+
325
+ ```bash
326
+ $ npm test
327
+ FAIL: expected 'Email required', got undefined
328
+ ```
329
+
330
+ **GREEN**
331
+
332
+ ```typescript
333
+ function submitForm(data: FormData) {
334
+ if (!data.email?.trim()) {
335
+ return { error: 'Email required' };
336
+ }
337
+ // ...
338
+ }
339
+ ```
340
+
341
+ **Verify GREEN**
342
+
343
+ ```bash
344
+ $ npm test
345
+ PASS
346
+ ```
347
+
348
+ **REFACTOR**
349
+ Extract validation for multiple fields if needed.
350
+
351
+ ## Verification Checklist
352
+
353
+ Before marking work complete:
354
+
355
+ - [ ] Every new function/method has a test
356
+ - [ ] Watched each test fail before implementing
357
+ - [ ] Each test failed for expected reason (feature missing, not typo)
358
+ - [ ] Wrote minimal code to pass each test
359
+ - [ ] All tests pass
360
+ - [ ] Output pristine (no errors, warnings)
361
+ - [ ] Tests use real code (mocks only if unavoidable)
362
+ - [ ] Edge cases and errors covered
363
+
364
+ Can't check all boxes? You skipped TDD. Start over.
365
+
366
+ ## When Stuck
367
+
368
+ | Problem | Solution |
369
+ | ---------------------- | -------------------------------------------------------------------- |
370
+ | Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
371
+ | Test too complicated | Design too complicated. Simplify interface. |
372
+ | Must mock everything | Code too coupled. Use dependency injection. |
373
+ | Test setup huge | Extract helpers. Still complex? Simplify design. |
374
+
375
+ ## Debugging Integration
376
+
377
+ Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
378
+
379
+ Never fix bugs without a test.
380
+
381
+ ## Testing Anti-Patterns
382
+
383
+ When adding mocks or test utilities, read @testing-anti-patterns.md to avoid common pitfalls:
384
+
385
+ - Testing mock behavior instead of real behavior
386
+ - Adding test-only methods to production classes
387
+ - Mocking without understanding dependencies
388
+
389
+ ## Final Rule
390
+
391
+ ```
392
+ Production code → test exists and failed first
393
+ Otherwise → not TDD
394
+ ```
395
+
396
+ No exceptions without your human partner's permission.