liteagents 3.0.0 → 3.6.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 (159) hide show
  1. package/CHANGELOG.md +158 -1
  2. package/README.md +113 -169
  3. package/installer/cli.js +4 -2
  4. package/installer/package-manager.js +3 -1
  5. package/package.json +4 -3
  6. package/packages/ampcode/AGENT.md +10 -18
  7. package/packages/ampcode/agents/code-developer.md +11 -17
  8. package/packages/ampcode/agents/orchestrator.md +1 -1
  9. package/packages/ampcode/agents/quality-assurance.md +3 -1
  10. package/packages/ampcode/{commands/brainstorming.md → skills/brainstorming/SKILL.md} +2 -3
  11. package/packages/ampcode/{commands/branch-review.md → skills/branch-review/SKILL.md} +27 -13
  12. package/packages/{claude/commands/docs-builder.md → ampcode/skills/docs-builder/SKILL.md} +1 -1
  13. package/packages/ampcode/{commands/live-canvas.md → skills/live-canvas/SKILL.md} +8 -4
  14. package/packages/ampcode/{commands/refactor.md → skills/refactor/SKILL.md} +49 -7
  15. package/packages/ampcode/{commands/release.md → skills/release/SKILL.md} +4 -4
  16. package/packages/{claude/commands → ampcode/skills}/remember/AGENT_RULES.md +44 -84
  17. package/packages/ampcode/{commands/remember.md → skills/remember/SKILL.md} +11 -6
  18. package/packages/ampcode/{commands → skills}/remember/friction.cjs +0 -0
  19. package/packages/ampcode/{commands → skills}/remember/stub-check.cjs +28 -19
  20. package/packages/ampcode/{commands → skills}/remember/sync-rules.cjs +28 -19
  21. package/packages/{claude/commands → ampcode/skills}/remember/version-check.cjs +1 -1
  22. package/packages/ampcode/skills/root-cause/SKILL.md +220 -0
  23. package/packages/ampcode/{commands/trace-back → skills/root-cause}/find-polluter.sh +0 -0
  24. package/packages/{claude/commands/security.md → ampcode/skills/security/SKILL.md} +1 -1
  25. package/packages/{claude/commands/ship.md → ampcode/skills/ship/SKILL.md} +1 -1
  26. package/packages/ampcode/skills/skill-creator/LICENSE.txt +202 -0
  27. package/packages/ampcode/{commands/skill-creator.md → skills/skill-creator/SKILL.md} +1 -2
  28. package/packages/ampcode/{commands → skills}/skill-creator/scripts/init_skill.py +0 -0
  29. package/packages/ampcode/{commands → skills}/skill-creator/scripts/package_skill.py +0 -0
  30. package/packages/ampcode/{commands → skills}/skill-creator/scripts/quick_validate.py +0 -0
  31. package/packages/ampcode/{commands/stash.md → skills/stash/SKILL.md} +2 -1
  32. package/packages/{claude/commands/test-generate.md → ampcode/skills/test-generate/SKILL.md} +2 -2
  33. package/packages/ampcode/variants.json +2 -2
  34. package/packages/claude/CLAUDE.md +10 -17
  35. package/packages/claude/agents/code-developer.md +11 -17
  36. package/packages/claude/agents/orchestrator.md +2 -3
  37. package/packages/claude/agents/quality-assurance.md +3 -1
  38. package/packages/claude/skills/brainstorming/SKILL.md +1 -2
  39. package/packages/claude/{commands/branch-review.md → skills/branch-review/SKILL.md} +15 -1
  40. package/packages/{ampcode/commands/docs-builder.md → claude/skills/docs-builder/SKILL.md} +7 -7
  41. package/packages/claude/skills/live-canvas/SKILL.md +5 -1
  42. package/packages/claude/{commands/refactor.md → skills/refactor/SKILL.md} +45 -3
  43. package/packages/claude/{commands/release.md → skills/release/SKILL.md} +1 -1
  44. package/packages/{ampcode/commands → claude/skills}/remember/AGENT_RULES.md +38 -78
  45. package/packages/claude/{commands/remember.md → skills/remember/SKILL.md} +11 -6
  46. package/packages/claude/{commands → skills}/remember/friction.cjs +0 -0
  47. package/packages/claude/{commands → skills}/remember/stub-check.cjs +28 -19
  48. package/packages/claude/{commands → skills}/remember/sync-rules.cjs +28 -19
  49. package/packages/{ampcode/commands → claude/skills}/remember/version-check.cjs +3 -3
  50. package/packages/claude/skills/root-cause/SKILL.md +220 -0
  51. package/packages/{ampcode/commands/security.md → claude/skills/security/SKILL.md} +2 -2
  52. package/packages/{ampcode/commands/ship.md → claude/skills/ship/SKILL.md} +2 -2
  53. package/packages/claude/skills/skill-creator/SKILL.md +1 -2
  54. package/packages/claude/{commands/stash.md → skills/stash/SKILL.md} +2 -1
  55. package/packages/{ampcode/commands/test-generate.md → claude/skills/test-generate/SKILL.md} +3 -3
  56. package/packages/claude/variants.json +1 -2
  57. package/packages/droid/AGENTS.md +10 -15
  58. package/packages/droid/commands/brainstorming.md +1 -4
  59. package/packages/droid/commands/branch-review.md +25 -14
  60. package/packages/droid/commands/docs-builder.md +0 -3
  61. package/packages/droid/commands/live-canvas.md +7 -5
  62. package/packages/droid/commands/refactor.md +47 -8
  63. package/packages/droid/commands/release.md +2 -5
  64. package/packages/droid/commands/remember/AGENT_RULES.md +38 -78
  65. package/packages/droid/commands/remember/stub-check.cjs +28 -19
  66. package/packages/droid/commands/remember/sync-rules.cjs +28 -19
  67. package/packages/droid/commands/remember/version-check.cjs +1 -1
  68. package/packages/droid/commands/remember.md +6 -4
  69. package/packages/droid/commands/root-cause.md +218 -0
  70. package/packages/droid/commands/security.md +0 -3
  71. package/packages/droid/commands/ship.md +0 -3
  72. package/packages/droid/commands/skill-creator/LICENSE.txt +202 -0
  73. package/packages/droid/commands/skill-creator.md +0 -4
  74. package/packages/droid/commands/stash.md +0 -2
  75. package/packages/droid/commands/test-generate.md +1 -4
  76. package/packages/droid/droids/1-create-prd.md +6 -2
  77. package/packages/droid/droids/2-generate-tasks.md +1 -2
  78. package/packages/droid/droids/3-process-task-list.md +1 -2
  79. package/packages/droid/droids/code-developer.md +12 -19
  80. package/packages/droid/droids/feature-planner.md +1 -2
  81. package/packages/droid/droids/market-researcher.md +1 -2
  82. package/packages/droid/droids/orchestrator.md +1 -2
  83. package/packages/droid/droids/quality-assurance.md +4 -3
  84. package/packages/droid/droids/system-architect.md +1 -2
  85. package/packages/droid/droids/ui-designer.md +1 -2
  86. package/packages/opencode/AGENTS.md +10 -15
  87. package/packages/opencode/agent/code-developer.md +11 -17
  88. package/packages/opencode/agent/quality-assurance.md +3 -1
  89. package/packages/opencode/command/brainstorming.md +1 -4
  90. package/packages/opencode/command/branch-review.md +25 -15
  91. package/packages/opencode/command/docs-builder.md +0 -4
  92. package/packages/opencode/command/live-canvas.md +7 -5
  93. package/packages/opencode/command/refactor.md +47 -9
  94. package/packages/opencode/command/release.md +2 -5
  95. package/packages/opencode/command/remember/AGENT_RULES.md +38 -78
  96. package/packages/opencode/command/remember/stub-check.cjs +28 -19
  97. package/packages/opencode/command/remember/sync-rules.cjs +28 -19
  98. package/packages/opencode/command/remember/version-check.cjs +1 -1
  99. package/packages/opencode/command/remember.md +6 -4
  100. package/packages/opencode/command/root-cause.md +218 -0
  101. package/packages/opencode/command/security.md +0 -4
  102. package/packages/opencode/command/ship.md +0 -3
  103. package/packages/opencode/command/skill-creator/LICENSE.txt +202 -0
  104. package/packages/opencode/command/skill-creator.md +0 -4
  105. package/packages/opencode/command/stash.md +0 -3
  106. package/packages/opencode/command/test-generate.md +1 -5
  107. package/packages/opencode/opencode.jsonc +4 -24
  108. package/packages/subagentic-manual.md +147 -314
  109. package/tools/ampcode/manifest-template.json +0 -1
  110. package/tools/claude/manifest-template.json +0 -1
  111. package/tools/droid/manifest-template.json +0 -1
  112. package/tools/opencode/manifest-template.json +0 -1
  113. package/packages/ampcode/commands/debug-method.md +0 -297
  114. package/packages/ampcode/commands/live-canvas/README.md +0 -264
  115. package/packages/ampcode/commands/optimize.md +0 -61
  116. package/packages/ampcode/commands/tdd-flow.md +0 -390
  117. package/packages/ampcode/commands/test-traps/example.ts +0 -158
  118. package/packages/ampcode/commands/test-traps.md +0 -378
  119. package/packages/ampcode/commands/trace-back.md +0 -176
  120. package/packages/ampcode/commands/verify-done.md +0 -152
  121. package/packages/claude/commands/optimize.md +0 -61
  122. package/packages/claude/plugins/live-canvas-marketplace/plugins/live-canvas-channel/README.md +0 -89
  123. package/packages/claude/skills/debug-method/CREATION-LOG.md +0 -119
  124. package/packages/claude/skills/debug-method/SKILL.md +0 -296
  125. package/packages/claude/skills/debug-method/test-academic.md +0 -14
  126. package/packages/claude/skills/debug-method/test-pressure-1.md +0 -58
  127. package/packages/claude/skills/debug-method/test-pressure-2.md +0 -68
  128. package/packages/claude/skills/debug-method/test-pressure-3.md +0 -69
  129. package/packages/claude/skills/live-canvas/README.md +0 -269
  130. package/packages/claude/skills/tdd-flow/SKILL.md +0 -392
  131. package/packages/claude/skills/test-traps/SKILL.md +0 -378
  132. package/packages/claude/skills/test-traps/example.ts +0 -158
  133. package/packages/claude/skills/trace-back/SKILL.md +0 -176
  134. package/packages/claude/skills/verify-done/SKILL.md +0 -152
  135. package/packages/droid/commands/debug-method.md +0 -297
  136. package/packages/droid/commands/live-canvas/README.md +0 -264
  137. package/packages/droid/commands/optimize.md +0 -61
  138. package/packages/droid/commands/tdd-flow.md +0 -390
  139. package/packages/droid/commands/test-traps/example.ts +0 -158
  140. package/packages/droid/commands/test-traps.md +0 -378
  141. package/packages/droid/commands/trace-back.md +0 -176
  142. package/packages/droid/commands/verify-done.md +0 -152
  143. package/packages/opencode/command/debug-method.md +0 -297
  144. package/packages/opencode/command/live-canvas/README.md +0 -264
  145. package/packages/opencode/command/optimize.md +0 -61
  146. package/packages/opencode/command/tdd-flow.md +0 -390
  147. package/packages/opencode/command/test-traps/example.ts +0 -158
  148. package/packages/opencode/command/test-traps.md +0 -378
  149. package/packages/opencode/command/trace-back.md +0 -176
  150. package/packages/opencode/command/verify-done.md +0 -152
  151. /package/packages/ampcode/{commands → skills}/docs-builder/docs-builder.cjs +0 -0
  152. /package/packages/ampcode/{commands → skills}/live-canvas/DESIGN_PRINCIPLES.md +0 -0
  153. /package/packages/ampcode/{commands → skills}/live-canvas/dev/post-variants.html +0 -0
  154. /package/packages/ampcode/{commands → skills}/live-canvas/templates/lab-banner.html +0 -0
  155. /package/packages/ampcode/{commands → skills}/live-canvas/templates/overlay-vanilla.js +0 -0
  156. /package/packages/claude/{commands → skills}/docs-builder/docs-builder.cjs +0 -0
  157. /package/packages/claude/skills/{trace-back → root-cause}/find-polluter.sh +0 -0
  158. /package/packages/droid/commands/{trace-back → root-cause}/find-polluter.sh +0 -0
  159. /package/packages/opencode/command/{trace-back → root-cause}/find-polluter.sh +0 -0
@@ -1,390 +0,0 @@
1
- ---
2
- name: tdd-flow
3
- description: Use when implementing any feature or bugfix, before writing implementation code - write the test first, watch it fail, write minimal code to pass; ensures tests actually verify behavior by requiring failure first
4
- ---
5
-
6
- # TDD Flow
7
-
8
- ## Auto-Trigger
9
-
10
- **APPLIES WHEN:**
11
- - About to write new production code (function, method, class)
12
- - Implementing any feature or bug fix
13
- - Modifying behavior of existing code
14
- - Task metadata includes `tdd: yes`
15
- - User requests feature implementation
16
-
17
- **APPLIES TO:**
18
- - All production code changes
19
- - Feature implementations
20
- - Bug fixes
21
- - Refactoring that changes behavior
22
- - API endpoint creation
23
- - Model/class creation
24
-
25
- **DOES NOT APPLY TO:**
26
- - Documentation files
27
- - Configuration files (unless logic-bearing)
28
- - Throwaway prototypes (with explicit user permission)
29
- - Generated code (with explicit user permission)
30
-
31
- **ENFORCEMENT:**
32
- If you find yourself writing implementation code before tests, STOP immediately. Delete the implementation and start over with TDD.
33
-
34
- ## Overview
35
-
36
- Write the test first. Watch it fail. Write minimal code to pass.
37
-
38
- **Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
39
-
40
- **Violating the letter of the rules is violating the spirit of the rules.**
41
-
42
- ## When to Use
43
-
44
- **Always:**
45
- - New features
46
- - Bug fixes
47
- - Refactoring
48
- - Behavior changes
49
-
50
- **Exceptions (ask your human partner):**
51
- - Throwaway prototypes
52
- - Generated code
53
- - Configuration files
54
-
55
- Thinking "skip TDD just this once"? Stop. That's rationalization.
56
-
57
- ## The Iron Law
58
-
59
- ```
60
- NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
61
- ```
62
-
63
- Write code before the test? Delete it. Start over.
64
-
65
- **No exceptions:**
66
- - Don't keep it as "reference"
67
- - Don't "adapt" it while writing tests
68
- - Don't look at it
69
- - Delete means delete
70
-
71
- Implement fresh from tests. Period.
72
-
73
- ## Red-Green-Refactor
74
-
75
- ```dot
76
- digraph tdd_cycle {
77
- rankdir=LR;
78
- red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
79
- verify_red [label="Verify fails\ncorrectly", shape=diamond];
80
- green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
81
- verify_green [label="Verify passes\nAll green", shape=diamond];
82
- refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
83
- next [label="Next", shape=ellipse];
84
-
85
- red -> verify_red;
86
- verify_red -> green [label="yes"];
87
- verify_red -> red [label="wrong\nfailure"];
88
- green -> verify_green;
89
- verify_green -> refactor [label="yes"];
90
- verify_green -> green [label="no"];
91
- refactor -> verify_green [label="stay\ngreen"];
92
- verify_green -> next;
93
- next -> red;
94
- }
95
- ```
96
-
97
- ### RED - Write Failing Test
98
-
99
- Write one minimal test showing what should happen.
100
-
101
- <Good>
102
- ```typescript
103
- test('retries failed operations 3 times', async () => {
104
- let attempts = 0;
105
- const operation = () => {
106
- attempts++;
107
- if (attempts < 3) throw new Error('fail');
108
- return 'success';
109
- };
110
-
111
- const result = await retryOperation(operation);
112
-
113
- expect(result).toBe('success');
114
- expect(attempts).toBe(3);
115
- });
116
- ```
117
- Clear name, tests real behavior, one thing
118
- </Good>
119
-
120
- <Bad>
121
- ```typescript
122
- test('retry works', async () => {
123
- const mock = jest.fn()
124
- .mockRejectedValueOnce(new Error())
125
- .mockRejectedValueOnce(new Error())
126
- .mockResolvedValueOnce('success');
127
- await retryOperation(mock);
128
- expect(mock).toHaveBeenCalledTimes(3);
129
- });
130
- ```
131
- Vague name, tests mock not code
132
- </Bad>
133
-
134
- **Requirements:**
135
- - One behavior
136
- - Clear name
137
- - Real code (no mocks unless unavoidable)
138
-
139
- ### Verify RED - Watch It Fail
140
-
141
- **MANDATORY. Never skip.**
142
-
143
- ```bash
144
- npm test path/to/test.test.ts
145
- ```
146
-
147
- Confirm:
148
- - Test fails (not errors)
149
- - Failure message is expected
150
- - Fails because feature missing (not typos)
151
-
152
- **Test passes?** You're testing existing behavior. Fix test.
153
-
154
- **Test errors?** Fix error, re-run until it fails correctly.
155
-
156
- ### GREEN - Minimal Code
157
-
158
- Write simplest code to pass the test.
159
-
160
- <Good>
161
- ```typescript
162
- async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
163
- for (let i = 0; i < 3; i++) {
164
- try {
165
- return await fn();
166
- } catch (e) {
167
- if (i === 2) throw e;
168
- }
169
- }
170
- throw new Error('unreachable');
171
- }
172
- ```
173
- Just enough to pass
174
- </Good>
175
-
176
- <Bad>
177
- ```typescript
178
- async function retryOperation<T>(
179
- fn: () => Promise<T>,
180
- options?: {
181
- maxRetries?: number;
182
- backoff?: 'linear' | 'exponential';
183
- onRetry?: (attempt: number) => void;
184
- }
185
- ): Promise<T> {
186
- // YAGNI
187
- }
188
- ```
189
- Over-engineered
190
- </Bad>
191
-
192
- Don't add features, refactor other code, or "improve" beyond the test.
193
-
194
- ### Verify GREEN - Watch It Pass
195
-
196
- **MANDATORY.**
197
-
198
- ```bash
199
- npm test path/to/test.test.ts
200
- ```
201
-
202
- Confirm:
203
- - Test passes
204
- - Other tests still pass
205
- - Output pristine (no errors, warnings)
206
-
207
- **Test fails?** Fix code, not test.
208
-
209
- **Other tests fail?** Fix now.
210
-
211
- ### REFACTOR - Clean Up
212
-
213
- After green only:
214
- - Remove duplication
215
- - Improve names
216
- - Extract helpers
217
-
218
- Keep tests green. Don't add behavior.
219
-
220
- ### Repeat
221
-
222
- Next failing test for next feature.
223
-
224
- ## Good Tests
225
-
226
- | Quality | Good | Bad |
227
- |---------|------|-----|
228
- | **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
229
- | **Clear** | Name describes behavior | `test('test1')` |
230
- | **Shows intent** | Demonstrates desired API | Obscures what code should do |
231
-
232
- ## Why Order Matters
233
-
234
- **"I'll write tests after to verify it works"**
235
-
236
- Tests written after code pass immediately. Passing immediately proves nothing:
237
- - Might test wrong thing
238
- - Might test implementation, not behavior
239
- - Might miss edge cases you forgot
240
- - You never saw it catch the bug
241
-
242
- Test-first forces you to see the test fail, proving it actually tests something.
243
-
244
- **"I already manually tested all the edge cases"**
245
-
246
- Manual testing is ad-hoc. You think you tested everything but:
247
- - No record of what you tested
248
- - Can't re-run when code changes
249
- - Easy to forget cases under pressure
250
- - "It worked when I tried it" ≠ comprehensive
251
-
252
- Automated tests are systematic. They run the same way every time.
253
-
254
- **"Deleting X hours of work is wasteful"**
255
-
256
- Sunk cost fallacy. The time is already gone. Your choice now:
257
- - Delete and rewrite with TDD (X more hours, high confidence)
258
- - Keep it and add tests after (30 min, low confidence, likely bugs)
259
-
260
- The "waste" is keeping code you can't trust. Working code without real tests is technical debt.
261
-
262
- **"TDD is dogmatic, being pragmatic means adapting"**
263
-
264
- TDD IS pragmatic:
265
- - Finds bugs before commit (faster than debugging after)
266
- - Prevents regressions (tests catch breaks immediately)
267
- - Documents behavior (tests show how to use code)
268
- - Enables refactoring (change freely, tests catch breaks)
269
-
270
- "Pragmatic" shortcuts = debugging in production = slower.
271
-
272
- **"Tests after achieve the same goals - it's spirit not ritual"**
273
-
274
- No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
275
-
276
- Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones.
277
-
278
- Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't).
279
-
280
- 30 minutes of tests after ≠ TDD. You get coverage, lose proof tests work.
281
-
282
- ## Common Rationalizations
283
-
284
- | Excuse | Reality |
285
- |--------|---------|
286
- | "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
287
- | "I'll test after" | Tests passing immediately prove nothing. |
288
- | "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
289
- | "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
290
- | "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
291
- | "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
292
- | "Need to explore first" | Fine. Throw away exploration, start with TDD. |
293
- | "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
294
- | "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
295
- | "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
296
- | "Existing code has no tests" | You're improving it. Add tests for existing code. |
297
-
298
- ## Red Flags - STOP and Start Over
299
-
300
- - Code before test
301
- - Test after implementation
302
- - Test passes immediately
303
- - Can't explain why test failed
304
- - Tests added "later"
305
- - Rationalizing "just this once"
306
- - "I already manually tested it"
307
- - "Tests after achieve the same purpose"
308
- - "It's about spirit not ritual"
309
- - "Keep as reference" or "adapt existing code"
310
- - "Already spent X hours, deleting is wasteful"
311
- - "TDD is dogmatic, I'm being pragmatic"
312
- - "This is different because..."
313
-
314
- **All of these mean: Delete code. Start over with TDD.**
315
-
316
- ## Example: Bug Fix
317
-
318
- **Bug:** Empty email accepted
319
-
320
- **RED**
321
- ```typescript
322
- test('rejects empty email', async () => {
323
- const result = await submitForm({ email: '' });
324
- expect(result.error).toBe('Email required');
325
- });
326
- ```
327
-
328
- **Verify RED**
329
- ```bash
330
- $ npm test
331
- FAIL: expected 'Email required', got undefined
332
- ```
333
-
334
- **GREEN**
335
- ```typescript
336
- function submitForm(data: FormData) {
337
- if (!data.email?.trim()) {
338
- return { error: 'Email required' };
339
- }
340
- // ...
341
- }
342
- ```
343
-
344
- **Verify GREEN**
345
- ```bash
346
- $ npm test
347
- PASS
348
- ```
349
-
350
- **REFACTOR**
351
- Extract validation for multiple fields if needed.
352
-
353
- ## Verification Checklist
354
-
355
- Before marking work complete:
356
-
357
- - [ ] Every new function/method has a test
358
- - [ ] Watched each test fail before implementing
359
- - [ ] Each test failed for expected reason (feature missing, not typo)
360
- - [ ] Wrote minimal code to pass each test
361
- - [ ] All tests pass
362
- - [ ] Output pristine (no errors, warnings)
363
- - [ ] Tests use real code (mocks only if unavoidable)
364
- - [ ] Edge cases and errors covered
365
-
366
- Can't check all boxes? You skipped TDD. Start over.
367
-
368
- ## When Stuck
369
-
370
- | Problem | Solution |
371
- |---------|----------|
372
- | Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
373
- | Test too complicated | Design too complicated. Simplify interface. |
374
- | Must mock everything | Code too coupled. Use dependency injection. |
375
- | Test setup huge | Extract helpers. Still complex? Simplify design. |
376
-
377
- ## Debugging Integration
378
-
379
- Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
380
-
381
- Never fix bugs without a test.
382
-
383
- ## Final Rule
384
-
385
- ```
386
- Production code → test exists and failed first
387
- Otherwise → not TDD
388
- ```
389
-
390
- No exceptions without your human partner's permission.
@@ -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, 10); // Poll every 10ms for efficiency
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, 10);
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, 10);
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