@complexthings/superpowers-agent 9.2.1 → 10.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/.agents/skills/claude-handoff/SKILL.md +18 -0
  2. package/.agents/skills/code-review/SKILL.md +89 -0
  3. package/.agents/skills/{improve-codebase-architecture → codebase-design}/DEEPENING.md +1 -1
  4. package/.agents/skills/{improve-codebase-architecture/INTERFACE-DESIGN.md → codebase-design/DESIGN-IT-TWICE.md} +3 -3
  5. package/.agents/skills/codebase-design/SKILL.md +114 -0
  6. package/.agents/skills/design-an-interface/SKILL.md +94 -0
  7. package/.agents/skills/{diagnose → diagnosing-bugs}/SKILL.md +29 -12
  8. package/.agents/skills/{grill-with-docs → domain-modeling}/CONTEXT-FORMAT.md +1 -4
  9. package/.agents/skills/domain-modeling/SKILL.md +74 -0
  10. package/.agents/skills/fable-mode/SKILL.md +95 -0
  11. package/.agents/skills/git-guardrails-claude-code/SKILL.md +95 -0
  12. package/.agents/skills/git-guardrails-claude-code/scripts/block-dangerous-git.sh +25 -0
  13. package/.agents/skills/grill-me/SKILL.md +7 -0
  14. package/.agents/skills/grill-with-docs/SKILL.md +3 -86
  15. package/.agents/skills/grilling/SKILL.md +14 -0
  16. package/.agents/skills/handoff/SKILL.md +2 -1
  17. package/.agents/skills/i-have-adhd/SKILL.md +120 -0
  18. package/.agents/skills/implement/SKILL.md +11 -0
  19. package/.agents/skills/improve-codebase-architecture/HTML-REPORT.md +3 -3
  20. package/.agents/skills/improve-codebase-architecture/SKILL.md +13 -28
  21. package/.agents/skills/loop-me/SKILL.md +32 -0
  22. package/.agents/skills/prototype/SKILL.md +1 -1
  23. package/.agents/skills/qa/SKILL.md +130 -0
  24. package/.agents/skills/request-refactor-plan/SKILL.md +68 -0
  25. package/.agents/skills/research/SKILL.md +12 -0
  26. package/.agents/skills/resolving-merge-conflicts/SKILL.md +14 -0
  27. package/.agents/skills/scaffold-exercises/SKILL.md +106 -0
  28. package/.agents/skills/setup-matt-pocock-skills/SKILL.md +11 -9
  29. package/.agents/skills/setup-matt-pocock-skills/domain.md +2 -2
  30. package/.agents/skills/setup-matt-pocock-skills/issue-tracker-github.md +23 -0
  31. package/.agents/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +23 -0
  32. package/.agents/skills/setup-matt-pocock-skills/issue-tracker-local.md +11 -0
  33. package/.agents/skills/skill-creator/LICENSE.txt +202 -0
  34. package/.agents/skills/skill-creator/SKILL.md +485 -0
  35. package/.agents/skills/skill-creator/agents/analyzer.md +274 -0
  36. package/.agents/skills/skill-creator/agents/comparator.md +202 -0
  37. package/.agents/skills/skill-creator/agents/grader.md +223 -0
  38. package/.agents/skills/skill-creator/assets/eval_review.html +146 -0
  39. package/.agents/skills/skill-creator/eval-viewer/generate_review.py +471 -0
  40. package/.agents/skills/skill-creator/eval-viewer/viewer.html +1325 -0
  41. package/.agents/skills/skill-creator/references/schemas.md +430 -0
  42. package/.agents/skills/skill-creator/scripts/__init__.py +0 -0
  43. package/.agents/skills/skill-creator/scripts/__pycache__/__init__.cpython-314.pyc +0 -0
  44. package/.agents/skills/skill-creator/scripts/__pycache__/run_eval.cpython-314.pyc +0 -0
  45. package/.agents/skills/skill-creator/scripts/__pycache__/utils.cpython-314.pyc +0 -0
  46. package/.agents/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
  47. package/.agents/skills/skill-creator/scripts/generate_report.py +326 -0
  48. package/.agents/skills/skill-creator/scripts/improve_description.py +247 -0
  49. package/.agents/skills/skill-creator/scripts/package_skill.py +136 -0
  50. package/.agents/skills/skill-creator/scripts/quick_validate.py +103 -0
  51. package/.agents/skills/skill-creator/scripts/run_eval.py +310 -0
  52. package/.agents/skills/skill-creator/scripts/run_loop.py +328 -0
  53. package/.agents/skills/skill-creator/scripts/utils.py +47 -0
  54. package/.agents/skills/tdd/SKILL.md +17 -90
  55. package/.agents/skills/tdd/tests.md +16 -0
  56. package/.agents/skills/teach/GLOSSARY-FORMAT.md +35 -0
  57. package/.agents/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
  58. package/.agents/skills/teach/MISSION-FORMAT.md +31 -0
  59. package/.agents/skills/teach/RESOURCES-FORMAT.md +32 -0
  60. package/.agents/skills/teach/SKILL.md +140 -0
  61. package/.agents/skills/{to-prd → to-spec}/SKILL.md +11 -12
  62. package/.agents/skills/to-tickets/SKILL.md +114 -0
  63. package/.agents/skills/triage/AGENT-BRIEF.md +40 -1
  64. package/.agents/skills/triage/OUT-OF-SCOPE.md +5 -1
  65. package/.agents/skills/triage/SKILL.md +20 -11
  66. package/.agents/skills/wayfinder/SKILL.md +127 -0
  67. package/.agents/skills/writing-great-skills/GLOSSARY.md +201 -0
  68. package/.agents/skills/writing-great-skills/SKILL.md +83 -0
  69. package/.agents/superpowers-agent +103 -222
  70. package/.agents/superpowers-bootstrap.md +3 -3
  71. package/.agents/templates/AGENTS.md.template +11 -34
  72. package/.agents/templates/SUPERPOWERS.md.template +4 -4
  73. package/.github/copilot-instructions.md +23 -99
  74. package/.github/hooks/rtk-rewrite.json +22 -0
  75. package/AGENTS.md +7 -6
  76. package/README.md +53 -174
  77. package/package.json +2 -2
  78. package/skills/collaboration/brainstorming/SKILL.md +39 -139
  79. package/skills/collaboration/brainstorming/skill.json +2 -2
  80. package/skills/collaboration/leveraging-cli-tools/SKILL.md +70 -71
  81. package/skills/collaboration/leveraging-cli-tools/references/copilot-instructions.md +30 -0
  82. package/skills/collaboration/leveraging-cli-tools/scripts/setup-ponytail.sh +185 -0
  83. package/skills/collaboration/leveraging-cli-tools/scripts/setup-rtk.sh +217 -0
  84. package/skills/collaboration/leveraging-cli-tools/skill.json +1 -1
  85. package/skills/meta/create-skill-json/SKILL.md +4 -4
  86. package/skills/meta/create-skill-json/skill.json +1 -1
  87. package/skills/meta/create-skill-json/test-scenarios.md +1 -1
  88. package/skills/setup-skills/SKILL.md +18 -11
  89. package/skills/setup-skills/skill.json +8 -0
  90. package/.agents/skills/caveman/SKILL.md +0 -49
  91. package/.agents/skills/improve-codebase-architecture/LANGUAGE.md +0 -53
  92. package/.agents/skills/karpathy-guidelines/SKILL.md +0 -75
  93. package/.agents/skills/review/SKILL.md +0 -78
  94. package/.agents/skills/tdd/deep-modules.md +0 -33
  95. package/.agents/skills/tdd/interface-design.md +0 -31
  96. package/.agents/skills/tdd/refactoring.md +0 -10
  97. package/.agents/skills/to-issues/SKILL.md +0 -83
  98. package/.agents/skills/zoom-out/SKILL.md +0 -7
  99. package/skills/architecture/ABOUT.md +0 -20
  100. package/skills/architecture/preserving-productive-tensions/SKILL.md +0 -146
  101. package/skills/architecture/preserving-productive-tensions/skill.json +0 -9
  102. package/skills/collaboration/brainstorming/spec-document-reviewer-prompt.md +0 -50
  103. package/skills/collaboration/brainstorming/visual-companion.md +0 -277
  104. package/skills/collaboration/dispatching-parallel-agents/SKILL.md +0 -174
  105. package/skills/collaboration/dispatching-parallel-agents/skill.json +0 -9
  106. package/skills/collaboration/executing-plans/SKILL.md +0 -130
  107. package/skills/collaboration/executing-plans/skill.json +0 -9
  108. package/skills/collaboration/finishing-a-development-branch/SKILL.md +0 -261
  109. package/skills/collaboration/finishing-a-development-branch/skill.json +0 -9
  110. package/skills/collaboration/leveraging-cli-tools/scripts/slim.py +0 -167
  111. package/skills/collaboration/receiving-code-review/SKILL.md +0 -233
  112. package/skills/collaboration/receiving-code-review/skill.json +0 -9
  113. package/skills/collaboration/requesting-code-review/SKILL.md +0 -110
  114. package/skills/collaboration/requesting-code-review/code-reviewer.md +0 -146
  115. package/skills/collaboration/requesting-code-review/skill.json +0 -12
  116. package/skills/collaboration/subagent-driven-development/SKILL.md +0 -255
  117. package/skills/collaboration/subagent-driven-development/code-quality-reviewer-prompt.md +0 -26
  118. package/skills/collaboration/subagent-driven-development/implementer-prompt.md +0 -113
  119. package/skills/collaboration/subagent-driven-development/skill.json +0 -15
  120. package/skills/collaboration/subagent-driven-development/spec-reviewer-prompt.md +0 -61
  121. package/skills/collaboration/using-git-worktrees/SKILL.md +0 -366
  122. package/skills/collaboration/using-git-worktrees/skill.json +0 -9
  123. package/skills/collaboration/writing-plans/SKILL.md +0 -121
  124. package/skills/collaboration/writing-plans/plan-document-reviewer-prompt.md +0 -52
  125. package/skills/collaboration/writing-plans/skill.json +0 -9
  126. package/skills/debugging/defense-in-depth/SKILL.md +0 -380
  127. package/skills/debugging/defense-in-depth/skill.json +0 -9
  128. package/skills/debugging/root-cause-tracing/SKILL.md +0 -361
  129. package/skills/debugging/root-cause-tracing/find-polluter.sh +0 -63
  130. package/skills/debugging/root-cause-tracing/skill.json +0 -12
  131. package/skills/debugging/systematic-debugging/SKILL.md +0 -299
  132. package/skills/debugging/systematic-debugging/condition-based-waiting-example.ts +0 -158
  133. package/skills/debugging/systematic-debugging/condition-based-waiting.md +0 -115
  134. package/skills/debugging/systematic-debugging/defense-in-depth.md +0 -122
  135. package/skills/debugging/systematic-debugging/find-polluter.sh +0 -63
  136. package/skills/debugging/systematic-debugging/root-cause-tracing.md +0 -169
  137. package/skills/debugging/systematic-debugging/skill.json +0 -9
  138. package/skills/debugging/systematic-debugging/test-academic.md +0 -14
  139. package/skills/debugging/systematic-debugging/test-pressure-1.md +0 -58
  140. package/skills/debugging/systematic-debugging/test-pressure-2.md +0 -68
  141. package/skills/debugging/systematic-debugging/test-pressure-3.md +0 -69
  142. package/skills/debugging/verification-before-completion/SKILL.md +0 -143
  143. package/skills/debugging/verification-before-completion/skill.json +0 -9
  144. package/skills/finding-skills/SKILL.md +0 -101
  145. package/skills/finding-skills/skill.json +0 -8
  146. package/skills/meta/create-agents-md/SKILL.md +0 -182
  147. package/skills/meta/create-agents-md/skill.json +0 -9
  148. package/skills/meta/creating-prompts/SKILL.md +0 -349
  149. package/skills/meta/creating-prompts/examples/do-example.md +0 -65
  150. package/skills/meta/creating-prompts/examples/plan-example.md +0 -75
  151. package/skills/meta/creating-prompts/examples/refine-example.md +0 -65
  152. package/skills/meta/creating-prompts/examples/research-example.md +0 -63
  153. package/skills/meta/creating-prompts/scripts/get-next-number.sh +0 -27
  154. package/skills/meta/creating-prompts/skill.json +0 -20
  155. package/skills/meta/creating-prompts/templates/do-template.md +0 -59
  156. package/skills/meta/creating-prompts/templates/plan-template.md +0 -58
  157. package/skills/meta/creating-prompts/templates/refine-template.md +0 -54
  158. package/skills/meta/creating-prompts/templates/research-template.md +0 -56
  159. package/skills/meta/using-superpowers/SKILL.md +0 -108
  160. package/skills/meta/using-superpowers/skill.json +0 -5
  161. package/skills/meta/writing-prompts/SKILL.md +0 -122
  162. package/skills/meta/writing-prompts/references/platforms.md +0 -114
  163. package/skills/meta/writing-prompts/skill.json +0 -9
  164. package/skills/problem-solving/ABOUT.md +0 -40
  165. package/skills/problem-solving/collision-zone-thinking/SKILL.md +0 -188
  166. package/skills/problem-solving/collision-zone-thinking/references/historical-examples.md +0 -393
  167. package/skills/problem-solving/collision-zone-thinking/skill.json +0 -9
  168. package/skills/problem-solving/inversion-exercise/SKILL.md +0 -174
  169. package/skills/problem-solving/inversion-exercise/skill.json +0 -9
  170. package/skills/problem-solving/meta-pattern-recognition/SKILL.md +0 -116
  171. package/skills/problem-solving/meta-pattern-recognition/skill.json +0 -9
  172. package/skills/problem-solving/scale-game/SKILL.md +0 -222
  173. package/skills/problem-solving/scale-game/skill.json +0 -9
  174. package/skills/problem-solving/simplification-cascades/SKILL.md +0 -113
  175. package/skills/problem-solving/simplification-cascades/skill.json +0 -9
  176. package/skills/problem-solving/when-stuck/SKILL.md +0 -69
  177. package/skills/problem-solving/when-stuck/skill.json +0 -9
  178. package/skills/research/ABOUT.md +0 -20
  179. package/skills/research/tracing-knowledge-lineages/SKILL.md +0 -241
  180. package/skills/research/tracing-knowledge-lineages/skill.json +0 -9
  181. package/skills/testing/condition-based-waiting/SKILL.md +0 -359
  182. package/skills/testing/condition-based-waiting/example.ts +0 -158
  183. package/skills/testing/condition-based-waiting/skill.json +0 -12
  184. package/skills/testing/test-driven-development/SKILL.md +0 -434
  185. package/skills/testing/test-driven-development/skill.json +0 -9
  186. package/skills/testing/testing-anti-patterns/SKILL.md +0 -298
  187. package/skills/testing/testing-anti-patterns/skill.json +0 -9
  188. package/skills/testing/verification-before-completion/SKILL.md +0 -246
  189. package/skills/testing/verification-before-completion/skill.json +0 -10
  190. package/skills/using-a-skill/SKILL.md +0 -101
  191. package/skills/using-a-skill/skill.json +0 -8
  192. /package/.agents/skills/{diagnose → diagnosing-bugs}/scripts/hitl-loop.template.sh +0 -0
  193. /package/.agents/skills/{grill-with-docs → domain-modeling}/ADR-FORMAT.md +0 -0
@@ -1,158 +0,0 @@
1
- // Complete implementation of condition-based waiting utilities
2
- // From: Lace test infrastructure improvements (2025-10-03)
3
- // Context: Fixed 15 flaky tests by replacing arbitrary timeouts
4
-
5
- import type { ThreadManager } from '~/threads/thread-manager';
6
- import type { LaceEvent, LaceEventType } from '~/threads/types';
7
-
8
- /**
9
- * Wait for a specific event type to appear in thread
10
- *
11
- * @param threadManager - The thread manager to query
12
- * @param threadId - Thread to check for events
13
- * @param eventType - Type of event to wait for
14
- * @param timeoutMs - Maximum time to wait (default 5000ms)
15
- * @returns Promise resolving to the first matching event
16
- *
17
- * Example:
18
- * await waitForEvent(threadManager, agentThreadId, 'TOOL_RESULT');
19
- */
20
- export function waitForEvent(
21
- threadManager: ThreadManager,
22
- threadId: string,
23
- eventType: LaceEventType,
24
- timeoutMs = 5000
25
- ): Promise<LaceEvent> {
26
- return new Promise((resolve, reject) => {
27
- const startTime = Date.now();
28
-
29
- const check = () => {
30
- const events = threadManager.getEvents(threadId);
31
- const event = events.find((e) => e.type === eventType);
32
-
33
- if (event) {
34
- resolve(event);
35
- } else if (Date.now() - startTime > timeoutMs) {
36
- reject(new Error(`Timeout waiting for ${eventType} event after ${timeoutMs}ms`));
37
- } else {
38
- setTimeout(check, 50); // Poll every 50ms — efficient without hammering CPU
39
- }
40
- };
41
-
42
- check();
43
- });
44
- }
45
-
46
- /**
47
- * Wait for a specific number of events of a given type
48
- *
49
- * @param threadManager - The thread manager to query
50
- * @param threadId - Thread to check for events
51
- * @param eventType - Type of event to wait for
52
- * @param count - Number of events to wait for
53
- * @param timeoutMs - Maximum time to wait (default 5000ms)
54
- * @returns Promise resolving to all matching events once count is reached
55
- *
56
- * Example:
57
- * // Wait for 2 AGENT_MESSAGE events (initial response + continuation)
58
- * await waitForEventCount(threadManager, agentThreadId, 'AGENT_MESSAGE', 2);
59
- */
60
- export function waitForEventCount(
61
- threadManager: ThreadManager,
62
- threadId: string,
63
- eventType: LaceEventType,
64
- count: number,
65
- timeoutMs = 5000
66
- ): Promise<LaceEvent[]> {
67
- return new Promise((resolve, reject) => {
68
- const startTime = Date.now();
69
-
70
- const check = () => {
71
- const events = threadManager.getEvents(threadId);
72
- const matchingEvents = events.filter((e) => e.type === eventType);
73
-
74
- if (matchingEvents.length >= count) {
75
- resolve(matchingEvents);
76
- } else if (Date.now() - startTime > timeoutMs) {
77
- reject(
78
- new Error(
79
- `Timeout waiting for ${count} ${eventType} events after ${timeoutMs}ms (got ${matchingEvents.length})`
80
- )
81
- );
82
- } else {
83
- setTimeout(check, 50);
84
- }
85
- };
86
-
87
- check();
88
- });
89
- }
90
-
91
- /**
92
- * Wait for an event matching a custom predicate
93
- * Useful when you need to check event data, not just type
94
- *
95
- * @param threadManager - The thread manager to query
96
- * @param threadId - Thread to check for events
97
- * @param predicate - Function that returns true when event matches
98
- * @param description - Human-readable description for error messages
99
- * @param timeoutMs - Maximum time to wait (default 5000ms)
100
- * @returns Promise resolving to the first matching event
101
- *
102
- * Example:
103
- * // Wait for TOOL_RESULT with specific ID
104
- * await waitForEventMatch(
105
- * threadManager,
106
- * agentThreadId,
107
- * (e) => e.type === 'TOOL_RESULT' && e.data.id === 'call_123',
108
- * 'TOOL_RESULT with id=call_123'
109
- * );
110
- */
111
- export function waitForEventMatch(
112
- threadManager: ThreadManager,
113
- threadId: string,
114
- predicate: (event: LaceEvent) => boolean,
115
- description: string,
116
- timeoutMs = 5000
117
- ): Promise<LaceEvent> {
118
- return new Promise((resolve, reject) => {
119
- const startTime = Date.now();
120
-
121
- const check = () => {
122
- const events = threadManager.getEvents(threadId);
123
- const event = events.find(predicate);
124
-
125
- if (event) {
126
- resolve(event);
127
- } else if (Date.now() - startTime > timeoutMs) {
128
- reject(new Error(`Timeout waiting for ${description} after ${timeoutMs}ms`));
129
- } else {
130
- setTimeout(check, 50);
131
- }
132
- };
133
-
134
- check();
135
- });
136
- }
137
-
138
- // Usage example from actual debugging session:
139
- //
140
- // BEFORE (flaky):
141
- // ---------------
142
- // const messagePromise = agent.sendMessage('Execute tools');
143
- // await new Promise(r => setTimeout(r, 300)); // Hope tools start in 300ms
144
- // agent.abort();
145
- // await messagePromise;
146
- // await new Promise(r => setTimeout(r, 50)); // Hope results arrive in 50ms
147
- // expect(toolResults.length).toBe(2); // Fails randomly
148
- //
149
- // AFTER (reliable):
150
- // ----------------
151
- // const messagePromise = agent.sendMessage('Execute tools');
152
- // await waitForEventCount(threadManager, threadId, 'TOOL_CALL', 2); // Wait for tools to start
153
- // agent.abort();
154
- // await messagePromise;
155
- // await waitForEventCount(threadManager, threadId, 'TOOL_RESULT', 2); // Wait for results
156
- // expect(toolResults.length).toBe(2); // Always succeeds
157
- //
158
- // Result: 60% pass rate → 100%, 40% faster execution
@@ -1,12 +0,0 @@
1
- {
2
- "version": "2.1.0",
3
- "name": "superpowers:testing/condition-based-waiting",
4
- "title": "Condition-Based Waiting",
5
- "helpers": [
6
- "example.ts"
7
- ],
8
- "aliases": [
9
- "condition-based-waiting",
10
- "testing/condition-based-waiting"
11
- ]
12
- }
@@ -1,434 +0,0 @@
1
- ---
2
- name: test-driven-development
3
- description: Write the test first, watch it fail, write minimal code to pass. Use when implementing any feature or bugfix, before writing implementation code. Also use when fixing bugs, refactoring, or doing behavior changes — any time you're about to write production code, TDD applies. Essential for AI-assisted coding sessions to ensure generated code is verified.
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 (delete before merging)
26
- - Scaffolded/boilerplate code with no logic
27
- - Pure 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
- ## The Full Cycle
48
-
49
- Before writing your first test, write a **test list**: a short list of scenarios you need to cover. Don't turn them all into tests immediately — just capture them so you don't lose track of edge cases while you're heads-down implementing.
50
-
51
- Then for each item, follow Red-Green-Refactor:
52
-
53
- ```mermaid
54
- flowchart LR
55
- LIST[Test List] --> RED
56
- RED[RED: Write failing test] --> VR{Verify fails correctly}
57
- VR -->|yes| GREEN[GREEN: Minimal code]
58
- VR -->|wrong failure| RED
59
- GREEN --> VG{Verify passes, all green}
60
- VG -->|yes| REFACTOR[REFACTOR: Clean up]
61
- VG -->|no| GREEN
62
- REFACTOR --> VG2{Stay green?}
63
- VG2 -->|yes| NEXT((Next item))
64
- NEXT --> RED
65
- ```
66
-
67
- ### Step 0 — Write the Test List
68
-
69
- Before writing any code or test, write down the scenarios you'll need to handle:
70
-
71
- ```
72
- User login:
73
- - valid credentials → success
74
- - wrong password → error message
75
- - empty email → validation error
76
- - locked account → specific error
77
- - remember me → session persists
78
- ```
79
-
80
- Pick the simplest item first. Sequence matters — easier tests illuminate the design for harder ones.
81
-
82
- ### RED — Write Failing Test
83
-
84
- Write one minimal test showing what should happen.
85
-
86
- <Good>
87
- ```typescript
88
- test('retries failed operations 3 times', async () => {
89
- let attempts = 0;
90
- const operation = () => {
91
- attempts++;
92
- if (attempts < 3) throw new Error('fail');
93
- return 'success';
94
- };
95
-
96
- const result = await retryOperation(operation);
97
-
98
- expect(result).toBe('success');
99
- expect(attempts).toBe(3);
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
- Vague name, tests mock not code
117
- </Bad>
118
-
119
- **Requirements:**
120
- - One behavior
121
- - Clear name
122
- - Real code (no mocks unless unavoidable)
123
-
124
- ### Verify RED — Watch It Fail
125
-
126
- **MANDATORY. Never skip.**
127
-
128
- ```bash
129
- npm test path/to/test.test.ts
130
- ```
131
-
132
- Confirm:
133
- - Test fails (not errors)
134
- - Failure message is expected
135
- - Fails because feature missing (not typos)
136
-
137
- **Test passes?** You're testing existing behavior. Fix test.
138
-
139
- **Test errors?** Fix error, re-run until it fails correctly.
140
-
141
- ### GREEN — Minimal Code
142
-
143
- Write simplest code to pass the test.
144
-
145
- <Good>
146
- ```typescript
147
- async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
148
- for (let i = 0; i < 3; i++) {
149
- try {
150
- return await fn();
151
- } catch (e) {
152
- if (i === 2) throw e;
153
- }
154
- }
155
- throw new Error('unreachable');
156
- }
157
- ```
158
- Just enough to pass
159
- </Good>
160
-
161
- <Bad>
162
- ```typescript
163
- async function retryOperation<T>(
164
- fn: () => Promise<T>,
165
- options?: {
166
- maxRetries?: number;
167
- backoff?: 'linear' | 'exponential';
168
- onRetry?: (attempt: number) => void;
169
- }
170
- ): Promise<T> {
171
- // YAGNI
172
- }
173
- ```
174
- Over-engineered
175
- </Bad>
176
-
177
- Don't add features, refactor other code, or "improve" beyond the test.
178
-
179
- ### Verify GREEN — Watch It Pass
180
-
181
- **MANDATORY.**
182
-
183
- ```bash
184
- npm test path/to/test.test.ts
185
- ```
186
-
187
- Confirm:
188
- - Test passes
189
- - Other tests still pass
190
- - Output pristine (no errors, warnings)
191
-
192
- **Test fails?** Fix code, not test.
193
-
194
- **Other tests fail?** Fix now.
195
-
196
- ### REFACTOR — Clean Up
197
-
198
- After green only:
199
- - Remove duplication
200
- - Improve names
201
- - Extract helpers
202
-
203
- Keep tests green. Don't add behavior.
204
-
205
- ### Repeat
206
-
207
- Pick the next item from your test list. Write the next failing test.
208
-
209
- ## Using TDD with AI-Generated Code
210
-
211
- When an AI assistant generates implementation code, TDD discipline is *more* important, not less — AI code looks plausible but may be subtly wrong.
212
-
213
- **The rule is the same:** tests first, then generation.
214
-
215
- **Practical pattern:**
216
- 1. Write your test list as you normally would
217
- 2. Write the failing test
218
- 3. Run it — confirm it fails for the right reason
219
- 4. Ask the AI to implement the minimal code to pass the test (paste the test as context)
220
- 5. Run the test — confirm it passes
221
- 6. Review the AI code before accepting: does it actually do what you intended, or did it fake out the test?
222
-
223
- **Watch for faking:** AI assistants sometimes generate code that passes the specific test without implementing the real behavior. For example, hardcoding a return value that matches your test fixture. Your test list (step 0) and multiple test cases prevent this.
224
-
225
- **Exploration is fine — then delete it:**
226
- ```
227
- ✅ "Generate a spike to explore the API"
228
- ✅ Review the spike for understanding
229
- ✅ Delete the spike completely
230
- ✅ Write tests, then re-implement from scratch
231
- ```
232
-
233
- Never ask an AI to "add tests to the code I just wrote." The tests will be biased toward the existing implementation.
234
-
235
- ## Good Tests
236
-
237
- | Quality | Good | Bad |
238
- |---------|------|-----|
239
- | **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
240
- | **Clear** | Name describes behavior | `test('test1')` |
241
- | **Shows intent** | Demonstrates desired API | Obscures what code should do |
242
-
243
- ## Test Doubles — Use Sparingly
244
-
245
- A **test double** replaces a real dependency during testing. The goal is isolation from slow or external systems — not avoiding real code.
246
-
247
- | Type | What it does | When to use |
248
- |------|-------------|-------------|
249
- | **Fake** | Working implementation, shortcuts (e.g., in-memory DB) | Best choice when available |
250
- | **Stub** | Returns canned values | Isolate from external data sources |
251
- | **Spy** | Records calls for later assertion | Verify side-effect behavior |
252
- | **Mock** | Pre-programmed expectations, fails if wrong calls | Rarely — fragile on refactoring |
253
- | **Dummy** | Passed but never used | Fill required parameters |
254
-
255
- **Prefer fakes and stubs over mocks.** Mocks couple tests to implementation details, breaking on refactoring even when behavior is correct.
256
-
257
- **The real-code default:** Write your test without any doubles first. Add doubles only when the test is genuinely slow, non-deterministic, or has destructive side effects.
258
-
259
- Read `@testing-anti-patterns` before adding any mocks or test utilities.
260
-
261
- ## Why Order Matters
262
-
263
- **"I'll write tests after to verify it works"**
264
-
265
- Tests written after code pass immediately. Passing immediately proves nothing:
266
- - Might test wrong thing
267
- - Might test implementation, not behavior
268
- - Might miss edge cases you forgot
269
- - You never saw it catch the bug
270
-
271
- Test-first forces you to see the test fail, proving it actually tests something.
272
-
273
- **"I already manually tested all the edge cases"**
274
-
275
- Manual testing is ad-hoc. You think you tested everything but:
276
- - No record of what you tested
277
- - Can't re-run when code changes
278
- - Easy to forget cases under pressure
279
- - "It worked when I tried it" ≠ comprehensive
280
-
281
- Automated tests are systematic. They run the same way every time.
282
-
283
- **"Deleting X hours of work is wasteful"**
284
-
285
- Sunk cost fallacy. The time is already gone. Your choice now:
286
- - Delete and rewrite with TDD (X more hours, high confidence)
287
- - Keep it and add tests after (30 min, low confidence, likely bugs)
288
-
289
- The "waste" is keeping code you can't trust. Working code without real tests is technical debt.
290
-
291
- **"TDD is dogmatic, being pragmatic means adapting"**
292
-
293
- TDD IS pragmatic:
294
- - Finds bugs before commit (faster than debugging after)
295
- - Prevents regressions (tests catch breaks immediately)
296
- - Documents behavior (tests show how to use code)
297
- - Enables refactoring (change freely, tests catch breaks)
298
-
299
- "Pragmatic" shortcuts = debugging in production = slower.
300
-
301
- **"Tests after achieve the same goals - it's spirit not ritual"**
302
-
303
- No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
304
-
305
- Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones.
306
-
307
- Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't).
308
-
309
- 30 minutes of tests after ≠ TDD. You get coverage, lose proof tests work.
310
-
311
- ## Common Rationalizations
312
-
313
- | Excuse | Reality |
314
- |--------|---------|
315
- | "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
316
- | "I'll test after" | Tests passing immediately prove nothing. |
317
- | "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
318
- | "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
319
- | "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
320
- | "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
321
- | "Need to explore first" | Fine. Throw away exploration, start with TDD. |
322
- | "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
323
- | "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
324
- | "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
325
- | "Existing code has no tests" | You're improving it. Add tests for existing code. |
326
- | "AI generated the code, tests would be redundant" | AI code looks correct but often isn't. TDD applies especially here. |
327
-
328
- ## Red Flags — STOP and Start Over
329
-
330
- - Code before test
331
- - Test after implementation
332
- - Test passes immediately (without implementation)
333
- - Can't explain why test failed
334
- - Tests added "later"
335
- - Rationalizing "just this once"
336
- - "I already manually tested it"
337
- - "Tests after achieve the same purpose"
338
- - "It's about spirit not ritual"
339
- - "Keep as reference" or "adapt existing code"
340
- - "Already spent X hours, deleting is wasteful"
341
- - "TDD is dogmatic, I'm being pragmatic"
342
- - "This is different because..."
343
-
344
- **All of these mean: Delete code. Start over with TDD.**
345
-
346
- ## Example: Bug Fix
347
-
348
- **Bug:** Empty email accepted
349
-
350
- **Test List:**
351
- - empty email → validation error
352
- - whitespace-only email → validation error
353
- - valid email → passes through
354
-
355
- **RED**
356
- ```typescript
357
- test('rejects empty email', async () => {
358
- const result = await submitForm({ email: '' });
359
- expect(result.error).toBe('Email required');
360
- });
361
- ```
362
-
363
- **Verify RED**
364
- ```bash
365
- $ npm test
366
- FAIL: expected 'Email required', got undefined
367
- ```
368
-
369
- **GREEN**
370
- ```typescript
371
- function submitForm(data: FormData) {
372
- if (!data.email?.trim()) {
373
- return { error: 'Email required' };
374
- }
375
- // ...
376
- }
377
- ```
378
-
379
- **Verify GREEN**
380
- ```bash
381
- $ npm test
382
- PASS
383
- ```
384
-
385
- **REFACTOR**
386
- Extract validation for multiple fields if needed.
387
-
388
- ## Verification Checklist
389
-
390
- Before marking work complete:
391
-
392
- - [ ] Wrote a test list before writing any test
393
- - [ ] Every new function/method has a test
394
- - [ ] Watched each test fail before implementing
395
- - [ ] Each test failed for expected reason (feature missing, not typo)
396
- - [ ] Wrote minimal code to pass each test
397
- - [ ] All tests pass
398
- - [ ] Output pristine (no errors, warnings)
399
- - [ ] Tests use real code (mocks only if unavoidable)
400
- - [ ] Edge cases and errors covered
401
-
402
- Can't check all boxes? You skipped TDD. Start over.
403
-
404
- ## When Stuck
405
-
406
- | Problem | Solution |
407
- |---------|----------|
408
- | Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
409
- | Test too complicated | Design too complicated. Simplify interface. |
410
- | Must mock everything | Code too coupled. Use dependency injection. |
411
- | Test setup huge | Extract helpers. Still complex? Simplify design. |
412
- | AI generated code first | Delete it. Write test. Ask AI to implement from test. |
413
-
414
- ## Debugging Integration
415
-
416
- Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
417
-
418
- Never fix bugs without a test.
419
-
420
- ## Testing Anti-Patterns
421
-
422
- When adding mocks or test utilities, read @testing-anti-patterns to avoid common pitfalls:
423
- - Testing mock behavior instead of real behavior
424
- - Adding test-only methods to production classes
425
- - Mocking without understanding dependencies
426
-
427
- ## Final Rule
428
-
429
- ```
430
- Production code → test exists and failed first
431
- Otherwise → not TDD
432
- ```
433
-
434
- No exceptions without your human partner's permission.
@@ -1,9 +0,0 @@
1
- {
2
- "version": "3.1.0",
3
- "name": "superpowers:testing/test-driven-development",
4
- "title": "Test-Driven Development (TDD)",
5
- "aliases": [
6
- "test-driven-development",
7
- "testing/test-driven-development"
8
- ]
9
- }