opencode-swarm-plugin 0.44.0 → 0.44.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 (205) hide show
  1. package/bin/swarm.serve.test.ts +6 -4
  2. package/bin/swarm.ts +16 -10
  3. package/dist/compaction-prompt-scoring.js +139 -0
  4. package/dist/eval-capture.js +12811 -0
  5. package/dist/hive.d.ts.map +1 -1
  6. package/dist/index.js +7644 -62599
  7. package/dist/plugin.js +23766 -78721
  8. package/dist/swarm-orchestrate.d.ts.map +1 -1
  9. package/dist/swarm-prompts.d.ts.map +1 -1
  10. package/dist/swarm-review.d.ts.map +1 -1
  11. package/package.json +17 -5
  12. package/.changeset/swarm-insights-data-layer.md +0 -63
  13. package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
  14. package/.hive/analysis/session-data-quality-audit.md +0 -320
  15. package/.hive/eval-results.json +0 -483
  16. package/.hive/issues.jsonl +0 -138
  17. package/.hive/memories.jsonl +0 -729
  18. package/.opencode/eval-history.jsonl +0 -327
  19. package/.turbo/turbo-build.log +0 -9
  20. package/CHANGELOG.md +0 -2286
  21. package/SCORER-ANALYSIS.md +0 -598
  22. package/docs/analysis/subagent-coordination-patterns.md +0 -902
  23. package/docs/analysis-socratic-planner-pattern.md +0 -504
  24. package/docs/planning/ADR-001-monorepo-structure.md +0 -171
  25. package/docs/planning/ADR-002-package-extraction.md +0 -393
  26. package/docs/planning/ADR-003-performance-improvements.md +0 -451
  27. package/docs/planning/ADR-004-message-queue-features.md +0 -187
  28. package/docs/planning/ADR-005-devtools-observability.md +0 -202
  29. package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
  30. package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
  31. package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
  32. package/docs/planning/ADR-010-cass-inhousing.md +0 -1215
  33. package/docs/planning/ROADMAP.md +0 -368
  34. package/docs/semantic-memory-cli-syntax.md +0 -123
  35. package/docs/swarm-mail-architecture.md +0 -1147
  36. package/docs/testing/context-recovery-test.md +0 -470
  37. package/evals/ARCHITECTURE.md +0 -1189
  38. package/evals/README.md +0 -768
  39. package/evals/compaction-prompt.eval.ts +0 -149
  40. package/evals/compaction-resumption.eval.ts +0 -289
  41. package/evals/coordinator-behavior.eval.ts +0 -307
  42. package/evals/coordinator-session.eval.ts +0 -154
  43. package/evals/evalite.config.ts.bak +0 -15
  44. package/evals/example.eval.ts +0 -31
  45. package/evals/fixtures/cass-baseline.ts +0 -217
  46. package/evals/fixtures/compaction-cases.ts +0 -350
  47. package/evals/fixtures/compaction-prompt-cases.ts +0 -311
  48. package/evals/fixtures/coordinator-sessions.ts +0 -328
  49. package/evals/fixtures/decomposition-cases.ts +0 -105
  50. package/evals/lib/compaction-loader.test.ts +0 -248
  51. package/evals/lib/compaction-loader.ts +0 -320
  52. package/evals/lib/data-loader.evalite-test.ts +0 -289
  53. package/evals/lib/data-loader.test.ts +0 -345
  54. package/evals/lib/data-loader.ts +0 -281
  55. package/evals/lib/llm.ts +0 -115
  56. package/evals/scorers/compaction-prompt-scorers.ts +0 -145
  57. package/evals/scorers/compaction-scorers.ts +0 -305
  58. package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
  59. package/evals/scorers/coordinator-discipline.ts +0 -325
  60. package/evals/scorers/index.test.ts +0 -146
  61. package/evals/scorers/index.ts +0 -328
  62. package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
  63. package/evals/scorers/outcome-scorers.ts +0 -349
  64. package/evals/swarm-decomposition.eval.ts +0 -121
  65. package/examples/commands/swarm.md +0 -745
  66. package/examples/plugin-wrapper-template.ts +0 -2515
  67. package/examples/skills/hive-workflow/SKILL.md +0 -212
  68. package/examples/skills/skill-creator/SKILL.md +0 -223
  69. package/examples/skills/swarm-coordination/SKILL.md +0 -292
  70. package/global-skills/cli-builder/SKILL.md +0 -344
  71. package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
  72. package/global-skills/learning-systems/SKILL.md +0 -644
  73. package/global-skills/skill-creator/LICENSE.txt +0 -202
  74. package/global-skills/skill-creator/SKILL.md +0 -352
  75. package/global-skills/skill-creator/references/output-patterns.md +0 -82
  76. package/global-skills/skill-creator/references/workflows.md +0 -28
  77. package/global-skills/swarm-coordination/SKILL.md +0 -995
  78. package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
  79. package/global-skills/swarm-coordination/references/strategies.md +0 -138
  80. package/global-skills/system-design/SKILL.md +0 -213
  81. package/global-skills/testing-patterns/SKILL.md +0 -430
  82. package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
  83. package/opencode-swarm-plugin-0.30.7.tgz +0 -0
  84. package/opencode-swarm-plugin-0.31.0.tgz +0 -0
  85. package/scripts/cleanup-test-memories.ts +0 -346
  86. package/scripts/init-skill.ts +0 -222
  87. package/scripts/migrate-unknown-sessions.ts +0 -349
  88. package/scripts/validate-skill.ts +0 -204
  89. package/src/agent-mail.ts +0 -1724
  90. package/src/anti-patterns.test.ts +0 -1167
  91. package/src/anti-patterns.ts +0 -448
  92. package/src/compaction-capture.integration.test.ts +0 -257
  93. package/src/compaction-hook.test.ts +0 -838
  94. package/src/compaction-hook.ts +0 -1204
  95. package/src/compaction-observability.integration.test.ts +0 -139
  96. package/src/compaction-observability.test.ts +0 -187
  97. package/src/compaction-observability.ts +0 -324
  98. package/src/compaction-prompt-scorers.test.ts +0 -475
  99. package/src/compaction-prompt-scoring.ts +0 -300
  100. package/src/contributor-tools.test.ts +0 -133
  101. package/src/contributor-tools.ts +0 -201
  102. package/src/dashboard.test.ts +0 -611
  103. package/src/dashboard.ts +0 -462
  104. package/src/error-enrichment.test.ts +0 -403
  105. package/src/error-enrichment.ts +0 -219
  106. package/src/eval-capture.test.ts +0 -1015
  107. package/src/eval-capture.ts +0 -929
  108. package/src/eval-gates.test.ts +0 -306
  109. package/src/eval-gates.ts +0 -218
  110. package/src/eval-history.test.ts +0 -508
  111. package/src/eval-history.ts +0 -214
  112. package/src/eval-learning.test.ts +0 -378
  113. package/src/eval-learning.ts +0 -360
  114. package/src/eval-runner.test.ts +0 -223
  115. package/src/eval-runner.ts +0 -402
  116. package/src/export-tools.test.ts +0 -476
  117. package/src/export-tools.ts +0 -257
  118. package/src/hive.integration.test.ts +0 -2241
  119. package/src/hive.ts +0 -1628
  120. package/src/index.ts +0 -940
  121. package/src/learning.integration.test.ts +0 -1815
  122. package/src/learning.ts +0 -1079
  123. package/src/logger.test.ts +0 -189
  124. package/src/logger.ts +0 -135
  125. package/src/mandate-promotion.test.ts +0 -473
  126. package/src/mandate-promotion.ts +0 -239
  127. package/src/mandate-storage.integration.test.ts +0 -601
  128. package/src/mandate-storage.test.ts +0 -578
  129. package/src/mandate-storage.ts +0 -794
  130. package/src/mandates.ts +0 -540
  131. package/src/memory-tools.test.ts +0 -195
  132. package/src/memory-tools.ts +0 -344
  133. package/src/memory.integration.test.ts +0 -334
  134. package/src/memory.test.ts +0 -158
  135. package/src/memory.ts +0 -527
  136. package/src/model-selection.test.ts +0 -188
  137. package/src/model-selection.ts +0 -68
  138. package/src/observability-tools.test.ts +0 -359
  139. package/src/observability-tools.ts +0 -871
  140. package/src/output-guardrails.test.ts +0 -438
  141. package/src/output-guardrails.ts +0 -381
  142. package/src/pattern-maturity.test.ts +0 -1160
  143. package/src/pattern-maturity.ts +0 -525
  144. package/src/planning-guardrails.test.ts +0 -491
  145. package/src/planning-guardrails.ts +0 -438
  146. package/src/plugin.ts +0 -23
  147. package/src/post-compaction-tracker.test.ts +0 -251
  148. package/src/post-compaction-tracker.ts +0 -237
  149. package/src/query-tools.test.ts +0 -636
  150. package/src/query-tools.ts +0 -324
  151. package/src/rate-limiter.integration.test.ts +0 -466
  152. package/src/rate-limiter.ts +0 -774
  153. package/src/replay-tools.test.ts +0 -496
  154. package/src/replay-tools.ts +0 -240
  155. package/src/repo-crawl.integration.test.ts +0 -441
  156. package/src/repo-crawl.ts +0 -610
  157. package/src/schemas/cell-events.test.ts +0 -347
  158. package/src/schemas/cell-events.ts +0 -807
  159. package/src/schemas/cell.ts +0 -257
  160. package/src/schemas/evaluation.ts +0 -166
  161. package/src/schemas/index.test.ts +0 -199
  162. package/src/schemas/index.ts +0 -286
  163. package/src/schemas/mandate.ts +0 -232
  164. package/src/schemas/swarm-context.ts +0 -115
  165. package/src/schemas/task.ts +0 -161
  166. package/src/schemas/worker-handoff.test.ts +0 -302
  167. package/src/schemas/worker-handoff.ts +0 -131
  168. package/src/sessions/agent-discovery.test.ts +0 -137
  169. package/src/sessions/agent-discovery.ts +0 -112
  170. package/src/sessions/index.ts +0 -15
  171. package/src/skills.integration.test.ts +0 -1192
  172. package/src/skills.test.ts +0 -643
  173. package/src/skills.ts +0 -1549
  174. package/src/storage.integration.test.ts +0 -341
  175. package/src/storage.ts +0 -884
  176. package/src/structured.integration.test.ts +0 -817
  177. package/src/structured.test.ts +0 -1046
  178. package/src/structured.ts +0 -762
  179. package/src/swarm-decompose.test.ts +0 -188
  180. package/src/swarm-decompose.ts +0 -1302
  181. package/src/swarm-deferred.integration.test.ts +0 -157
  182. package/src/swarm-deferred.test.ts +0 -38
  183. package/src/swarm-insights.test.ts +0 -214
  184. package/src/swarm-insights.ts +0 -459
  185. package/src/swarm-mail.integration.test.ts +0 -970
  186. package/src/swarm-mail.ts +0 -739
  187. package/src/swarm-orchestrate.integration.test.ts +0 -282
  188. package/src/swarm-orchestrate.test.ts +0 -548
  189. package/src/swarm-orchestrate.ts +0 -3084
  190. package/src/swarm-prompts.test.ts +0 -1270
  191. package/src/swarm-prompts.ts +0 -2077
  192. package/src/swarm-research.integration.test.ts +0 -701
  193. package/src/swarm-research.test.ts +0 -698
  194. package/src/swarm-research.ts +0 -472
  195. package/src/swarm-review.integration.test.ts +0 -285
  196. package/src/swarm-review.test.ts +0 -879
  197. package/src/swarm-review.ts +0 -709
  198. package/src/swarm-strategies.ts +0 -407
  199. package/src/swarm-worktree.test.ts +0 -501
  200. package/src/swarm-worktree.ts +0 -575
  201. package/src/swarm.integration.test.ts +0 -2377
  202. package/src/swarm.ts +0 -38
  203. package/src/tool-adapter.integration.test.ts +0 -1221
  204. package/src/tool-availability.ts +0 -461
  205. package/tsconfig.json +0 -28
@@ -1,879 +0,0 @@
1
- /**
2
- * Swarm Structured Review Tests
3
- *
4
- * Tests for the coordinator-driven review of worker output.
5
- * The review is epic-aware - it checks if work serves the overall goal
6
- * and enables downstream tasks.
7
- *
8
- * Credit: Review patterns inspired by https://github.com/nexxeln/opencode-config
9
- */
10
- import { describe, it, expect, beforeEach, vi } from "vitest";
11
- import {
12
- generateReviewPrompt,
13
- ReviewResultSchema,
14
- markReviewApproved,
15
- isReviewApproved,
16
- getReviewStatus,
17
- clearReviewStatus,
18
- swarm_review,
19
- swarm_review_feedback,
20
- type ReviewPromptContext,
21
- type ReviewResult,
22
- type ReviewIssue,
23
- } from "./swarm-review";
24
-
25
- // Mock swarm-mail
26
- vi.mock("swarm-mail", () => ({
27
- sendSwarmMessage: vi.fn().mockResolvedValue({ success: true }),
28
- }));
29
-
30
- const mockContext = {
31
- sessionID: `test-review-${Date.now()}`,
32
- messageID: `test-message-${Date.now()}`,
33
- agent: "test-agent",
34
- abort: new AbortController().signal,
35
- };
36
-
37
- // ============================================================================
38
- // Review Prompt Generation
39
- // ============================================================================
40
-
41
- describe("generateReviewPrompt", () => {
42
- const baseContext: ReviewPromptContext = {
43
- epic_id: "bd-test-123",
44
- epic_title: "Add user authentication",
45
- epic_description: "Implement OAuth2 with JWT tokens",
46
- task_id: "bd-test-123.1",
47
- task_title: "Create auth utilities",
48
- task_description: "JWT sign/verify functions",
49
- files_touched: ["src/lib/auth.ts"],
50
- diff: "+export function signToken() {}",
51
- };
52
-
53
- it("includes epic goal for big-picture context", () => {
54
- const prompt = generateReviewPrompt(baseContext);
55
- expect(prompt).toContain("Add user authentication");
56
- expect(prompt).toContain("OAuth2 with JWT tokens");
57
- expect(prompt).toContain("## Epic Goal");
58
- });
59
-
60
- it("includes task requirements", () => {
61
- const prompt = generateReviewPrompt(baseContext);
62
- expect(prompt).toContain("Create auth utilities");
63
- expect(prompt).toContain("JWT sign/verify functions");
64
- expect(prompt).toContain("## Task Requirements");
65
- });
66
-
67
- it("includes dependency context (what this builds on)", () => {
68
- const contextWithDeps: ReviewPromptContext = {
69
- ...baseContext,
70
- task_id: "bd-test-123.2",
71
- task_title: "Create auth middleware",
72
- completed_dependencies: [
73
- {
74
- id: "bd-test-123.1",
75
- title: "Create auth utilities",
76
- summary: "JWT sign/verify done",
77
- },
78
- ],
79
- };
80
- const prompt = generateReviewPrompt(contextWithDeps);
81
- expect(prompt).toContain("This Task Builds On");
82
- expect(prompt).toContain("Create auth utilities");
83
- expect(prompt).toContain("JWT sign/verify done");
84
- });
85
-
86
- it("includes downstream context (what depends on this)", () => {
87
- const contextWithDownstream: ReviewPromptContext = {
88
- ...baseContext,
89
- downstream_tasks: [
90
- { id: "bd-test-123.2", title: "Create auth middleware" },
91
- { id: "bd-test-123.3", title: "Add protected routes" },
92
- ],
93
- };
94
- const prompt = generateReviewPrompt(contextWithDownstream);
95
- expect(prompt).toContain("Downstream Tasks");
96
- expect(prompt).toContain("Create auth middleware");
97
- expect(prompt).toContain("Add protected routes");
98
- });
99
-
100
- it("includes the actual code diff", () => {
101
- const diff = `+export function signToken(payload: TokenPayload): string {
102
- + return jwt.sign(payload, SECRET, { expiresIn: '1h' });
103
- +}`;
104
- const contextWithDiff: ReviewPromptContext = {
105
- ...baseContext,
106
- diff,
107
- };
108
- const prompt = generateReviewPrompt(contextWithDiff);
109
- expect(prompt).toContain("signToken");
110
- expect(prompt).toContain("TokenPayload");
111
- expect(prompt).toContain("```diff");
112
- });
113
-
114
- it("includes review criteria checklist", () => {
115
- const prompt = generateReviewPrompt(baseContext);
116
- expect(prompt).toContain("Fulfills Requirements");
117
- expect(prompt).toContain("Serves Epic Goal");
118
- expect(prompt).toContain("Enables Downstream");
119
- expect(prompt).toContain("Type Safety");
120
- expect(prompt).toContain("No Critical Bugs");
121
- expect(prompt).toContain("Test Coverage");
122
- });
123
-
124
- it("includes files modified section", () => {
125
- const prompt = generateReviewPrompt(baseContext);
126
- expect(prompt).toContain("## Files Modified");
127
- expect(prompt).toContain("`src/lib/auth.ts`");
128
- });
129
-
130
- it("includes response format instructions", () => {
131
- const prompt = generateReviewPrompt(baseContext);
132
- expect(prompt).toContain("## Response Format");
133
- expect(prompt).toContain('"status"');
134
- expect(prompt).toContain('"approved"');
135
- expect(prompt).toContain('"needs_changes"');
136
- });
137
- });
138
-
139
- // ============================================================================
140
- // Review Result Schema
141
- // ============================================================================
142
-
143
- describe("ReviewResultSchema", () => {
144
- it("accepts approved status with summary", () => {
145
- const result: ReviewResult = {
146
- status: "approved",
147
- summary: "Clean implementation, exports are clear for downstream tasks",
148
- };
149
- expect(ReviewResultSchema.safeParse(result).success).toBe(true);
150
- });
151
-
152
- it("accepts needs_changes status with issues array", () => {
153
- const result: ReviewResult = {
154
- status: "needs_changes",
155
- issues: [
156
- {
157
- file: "src/lib/auth.ts",
158
- line: 42,
159
- issue: "Missing error handling for expired tokens",
160
- suggestion:
161
- "Return { valid: false, error: 'expired' } instead of throwing",
162
- },
163
- ],
164
- remaining_attempts: 2,
165
- };
166
- expect(ReviewResultSchema.safeParse(result).success).toBe(true);
167
- });
168
-
169
- it("requires issues array when status is needs_changes", () => {
170
- const result = {
171
- status: "needs_changes",
172
- // missing issues array
173
- };
174
- const parsed = ReviewResultSchema.safeParse(result);
175
- expect(parsed.success).toBe(false);
176
- });
177
-
178
- it("rejects needs_changes with empty issues array", () => {
179
- const result = {
180
- status: "needs_changes",
181
- issues: [],
182
- };
183
- const parsed = ReviewResultSchema.safeParse(result);
184
- expect(parsed.success).toBe(false);
185
- });
186
-
187
- it("tracks remaining review attempts", () => {
188
- const result: ReviewResult = {
189
- status: "needs_changes",
190
- issues: [{ file: "x.ts", issue: "bug" }],
191
- remaining_attempts: 1,
192
- };
193
- const parsed = ReviewResultSchema.safeParse(result);
194
- expect(parsed.success).toBe(true);
195
- if (parsed.success) {
196
- expect(parsed.data.remaining_attempts).toBe(1);
197
- }
198
- });
199
-
200
- it("accepts approved without summary", () => {
201
- const result: ReviewResult = {
202
- status: "approved",
203
- };
204
- expect(ReviewResultSchema.safeParse(result).success).toBe(true);
205
- });
206
-
207
- it("accepts issue without line number", () => {
208
- const result: ReviewResult = {
209
- status: "needs_changes",
210
- issues: [{ file: "x.ts", issue: "general problem" }],
211
- };
212
- expect(ReviewResultSchema.safeParse(result).success).toBe(true);
213
- });
214
-
215
- it("accepts issue without suggestion", () => {
216
- const result: ReviewResult = {
217
- status: "needs_changes",
218
- issues: [{ file: "x.ts", line: 10, issue: "problem here" }],
219
- };
220
- expect(ReviewResultSchema.safeParse(result).success).toBe(true);
221
- });
222
- });
223
-
224
- // ============================================================================
225
- // Review Status Tracking
226
- // ============================================================================
227
-
228
- describe("Review status tracking", () => {
229
- beforeEach(() => {
230
- clearReviewStatus("test-task-1");
231
- clearReviewStatus("test-task-2");
232
- });
233
-
234
- it("starts with no review status", () => {
235
- const status = getReviewStatus("test-task-1");
236
- expect(status.reviewed).toBe(false);
237
- expect(status.approved).toBe(false);
238
- expect(status.attempt_count).toBe(0);
239
- expect(status.remaining_attempts).toBe(3);
240
- });
241
-
242
- it("marks task as approved", () => {
243
- markReviewApproved("test-task-1");
244
- expect(isReviewApproved("test-task-1")).toBe(true);
245
- const status = getReviewStatus("test-task-1");
246
- expect(status.reviewed).toBe(true);
247
- expect(status.approved).toBe(true);
248
- });
249
-
250
- it("tracks separate status per task", () => {
251
- markReviewApproved("test-task-1");
252
- expect(isReviewApproved("test-task-1")).toBe(true);
253
- expect(isReviewApproved("test-task-2")).toBe(false);
254
- });
255
-
256
- it("clears review status", () => {
257
- markReviewApproved("test-task-1");
258
- expect(isReviewApproved("test-task-1")).toBe(true);
259
- clearReviewStatus("test-task-1");
260
- expect(isReviewApproved("test-task-1")).toBe(false);
261
- });
262
- });
263
-
264
- // ============================================================================
265
- // swarm_review tool
266
- // ============================================================================
267
-
268
- describe("swarm_review", () => {
269
- it("has correct tool metadata", () => {
270
- expect(swarm_review.description).toContain("review prompt");
271
- expect(swarm_review.description).toContain("epic context");
272
- });
273
-
274
- it("returns JSON with review_prompt field", async () => {
275
- // This test exercises the tool structure without needing real git/beads
276
- // The tool will fail to get real data but should still return valid JSON
277
- // Use /tmp which exists on all systems
278
- const result = await swarm_review.execute(
279
- {
280
- project_key: "/tmp",
281
- epic_id: "bd-test-123",
282
- task_id: "bd-test-123.1",
283
- files_touched: ["src/test.ts"],
284
- },
285
- mockContext
286
- );
287
-
288
- const parsed = JSON.parse(result);
289
- expect(parsed).toHaveProperty("review_prompt");
290
- expect(parsed).toHaveProperty("context");
291
- expect(parsed.context.epic_id).toBe("bd-test-123");
292
- expect(parsed.context.task_id).toBe("bd-test-123.1");
293
- });
294
-
295
- it("includes remaining attempts in context", async () => {
296
- clearReviewStatus("bd-test-123.1");
297
- const result = await swarm_review.execute(
298
- {
299
- project_key: "/tmp",
300
- epic_id: "bd-test-123",
301
- task_id: "bd-test-123.1",
302
- },
303
- mockContext
304
- );
305
-
306
- const parsed = JSON.parse(result);
307
- expect(parsed.context.remaining_attempts).toBe(3);
308
- });
309
- });
310
-
311
- // ============================================================================
312
- // swarm_review_feedback tool
313
- // ============================================================================
314
-
315
- describe("swarm_review_feedback", () => {
316
- beforeEach(() => {
317
- clearReviewStatus("bd-feedback-test");
318
- vi.clearAllMocks();
319
- });
320
-
321
- it("has correct tool metadata", () => {
322
- expect(swarm_review_feedback.description).toContain("feedback");
323
- expect(swarm_review_feedback.description).toContain("max 3");
324
- });
325
-
326
- it("sends approved feedback successfully", async () => {
327
- const result = await swarm_review_feedback.execute(
328
- {
329
- project_key: "/tmp/test-project",
330
- task_id: "bd-feedback-test",
331
- worker_id: "worker-test",
332
- status: "approved",
333
- summary: "Looks good, clean implementation",
334
- },
335
- mockContext
336
- );
337
-
338
- const parsed = JSON.parse(result);
339
- expect(parsed.success).toBe(true);
340
- expect(parsed.status).toBe("approved");
341
- });
342
-
343
- it("sends needs_changes feedback with structured issues", async () => {
344
- const issues: ReviewIssue[] = [
345
- {
346
- file: "src/auth.ts",
347
- line: 42,
348
- issue: "Missing null check",
349
- suggestion: "Add if (!token) return null",
350
- },
351
- ];
352
-
353
- const result = await swarm_review_feedback.execute(
354
- {
355
- project_key: "/tmp/test-project",
356
- task_id: "bd-feedback-test",
357
- worker_id: "worker-test",
358
- status: "needs_changes",
359
- issues: JSON.stringify(issues),
360
- },
361
- mockContext
362
- );
363
-
364
- const parsed = JSON.parse(result);
365
- expect(parsed.success).toBe(true);
366
- expect(parsed.status).toBe("needs_changes");
367
- expect(parsed.remaining_attempts).toBe(2);
368
- });
369
-
370
- it("requires issues for needs_changes status", async () => {
371
- const result = await swarm_review_feedback.execute(
372
- {
373
- project_key: "/tmp/test-project",
374
- task_id: "bd-feedback-test",
375
- worker_id: "worker-test",
376
- status: "needs_changes",
377
- // no issues provided
378
- },
379
- mockContext
380
- );
381
-
382
- const parsed = JSON.parse(result);
383
- expect(parsed.success).toBe(false);
384
- expect(parsed.error).toContain("requires at least one issue");
385
- });
386
-
387
- it("tracks review attempts (max 3)", async () => {
388
- const issues = JSON.stringify([{ file: "x.ts", issue: "bug" }]);
389
-
390
- // First attempt
391
- let result = await swarm_review_feedback.execute(
392
- {
393
- project_key: "/tmp/test-project",
394
- task_id: "bd-feedback-test",
395
- worker_id: "worker-test",
396
- status: "needs_changes",
397
- issues,
398
- },
399
- mockContext
400
- );
401
- let parsed = JSON.parse(result);
402
- expect(parsed.attempt).toBe(1);
403
- expect(parsed.remaining_attempts).toBe(2);
404
-
405
- // Second attempt
406
- result = await swarm_review_feedback.execute(
407
- {
408
- project_key: "/tmp/test-project",
409
- task_id: "bd-feedback-test",
410
- worker_id: "worker-test",
411
- status: "needs_changes",
412
- issues,
413
- },
414
- mockContext
415
- );
416
- parsed = JSON.parse(result);
417
- expect(parsed.attempt).toBe(2);
418
- expect(parsed.remaining_attempts).toBe(1);
419
- });
420
-
421
- it("fails task after 3 rejected reviews", async () => {
422
- const issues = JSON.stringify([{ file: "x.ts", issue: "still broken" }]);
423
-
424
- // Exhaust all attempts
425
- for (let i = 0; i < 3; i++) {
426
- await swarm_review_feedback.execute(
427
- {
428
- project_key: "/tmp/test-project",
429
- task_id: "bd-feedback-test",
430
- worker_id: "worker-test",
431
- status: "needs_changes",
432
- issues,
433
- },
434
- mockContext
435
- );
436
- }
437
-
438
- // Check final state
439
- const status = getReviewStatus("bd-feedback-test");
440
- expect(status.remaining_attempts).toBe(0);
441
- });
442
-
443
- it("clears attempts on approval", async () => {
444
- const issues = JSON.stringify([{ file: "x.ts", issue: "bug" }]);
445
-
446
- // Add some attempts
447
- await swarm_review_feedback.execute(
448
- {
449
- project_key: "/tmp/test-project",
450
- task_id: "bd-feedback-test",
451
- worker_id: "worker-test",
452
- status: "needs_changes",
453
- issues,
454
- },
455
- mockContext
456
- );
457
-
458
- // Now approve
459
- await swarm_review_feedback.execute(
460
- {
461
- project_key: "/tmp/test-project",
462
- task_id: "bd-feedback-test",
463
- worker_id: "worker-test",
464
- status: "approved",
465
- summary: "Fixed!",
466
- },
467
- mockContext
468
- );
469
-
470
- // Attempts should be cleared
471
- const status = getReviewStatus("bd-feedback-test");
472
- expect(status.attempt_count).toBe(0);
473
- expect(status.remaining_attempts).toBe(3);
474
- });
475
-
476
- it("handles invalid issues JSON", async () => {
477
- const result = await swarm_review_feedback.execute(
478
- {
479
- project_key: "/tmp/test-project",
480
- task_id: "bd-feedback-test",
481
- worker_id: "worker-test",
482
- status: "needs_changes",
483
- issues: "not valid json",
484
- },
485
- mockContext
486
- );
487
-
488
- const parsed = JSON.parse(result);
489
- expect(parsed.success).toBe(false);
490
- expect(parsed.error).toContain("parse");
491
- });
492
-
493
- it("extracts epic ID from task ID for thread", async () => {
494
- // Task ID format: bd-epic.subtask
495
- const result = await swarm_review_feedback.execute(
496
- {
497
- project_key: "/tmp/test-project",
498
- task_id: "bd-epic-123.4",
499
- worker_id: "worker-test",
500
- status: "approved",
501
- },
502
- mockContext
503
- );
504
-
505
- const parsed = JSON.parse(result);
506
- expect(parsed.success).toBe(true);
507
- // The sendSwarmMessage mock was called with threadId = "bd-epic-123"
508
- });
509
- });
510
-
511
- // ============================================================================
512
- // Integration: swarm_complete with review gate
513
- // ============================================================================
514
-
515
- describe("swarm_complete with review gate", () => {
516
- // These tests verify the review gate behavior that was added to swarm_complete
517
- // The actual swarm_complete tests are in swarm.integration.test.ts
518
- // Here we test the review status functions that gate completion
519
-
520
- beforeEach(() => {
521
- clearReviewStatus("bd-gate-test");
522
- });
523
-
524
- it("isReviewApproved returns false for unreviewed task", () => {
525
- expect(isReviewApproved("bd-gate-test")).toBe(false);
526
- });
527
-
528
- it("isReviewApproved returns true after markReviewApproved", () => {
529
- markReviewApproved("bd-gate-test");
530
- expect(isReviewApproved("bd-gate-test")).toBe(true);
531
- });
532
-
533
- it("getReviewStatus provides complete status info", () => {
534
- const status = getReviewStatus("bd-gate-test");
535
- expect(status).toEqual({
536
- reviewed: false,
537
- approved: false,
538
- attempt_count: 0,
539
- remaining_attempts: 3,
540
- });
541
- });
542
-
543
- it("approval clears attempt count", async () => {
544
- // Simulate some failed attempts
545
- const issues = JSON.stringify([{ file: "x.ts", issue: "bug" }]);
546
- await swarm_review_feedback.execute(
547
- {
548
- project_key: "/tmp/test",
549
- task_id: "bd-gate-test",
550
- worker_id: "worker",
551
- status: "needs_changes",
552
- issues,
553
- },
554
- mockContext
555
- );
556
-
557
- let status = getReviewStatus("bd-gate-test");
558
- expect(status.attempt_count).toBe(1);
559
-
560
- // Approve
561
- await swarm_review_feedback.execute(
562
- {
563
- project_key: "/tmp/test",
564
- task_id: "bd-gate-test",
565
- worker_id: "worker",
566
- status: "approved",
567
- },
568
- mockContext
569
- );
570
-
571
- status = getReviewStatus("bd-gate-test");
572
- expect(status.attempt_count).toBe(0);
573
- expect(status.approved).toBe(true);
574
- });
575
- });
576
-
577
- // ============================================================================
578
- // Worker prompt updates for review flow
579
- // ============================================================================
580
-
581
- describe("worker prompt with review instructions", () => {
582
- // These tests verify that the review prompt includes proper instructions
583
- // The actual worker prompt generation is in swarm-prompts.ts
584
-
585
- it("review prompt includes response format for workers", () => {
586
- const prompt = generateReviewPrompt({
587
- epic_id: "bd-test",
588
- epic_title: "Test Epic",
589
- task_id: "bd-test.1",
590
- task_title: "Test Task",
591
- files_touched: [],
592
- diff: "",
593
- });
594
-
595
- // Workers need to know how to respond
596
- expect(prompt).toContain("Response Format");
597
- expect(prompt).toContain("approved");
598
- expect(prompt).toContain("needs_changes");
599
- });
600
-
601
- it("review prompt explains issue structure", () => {
602
- const prompt = generateReviewPrompt({
603
- epic_id: "bd-test",
604
- epic_title: "Test Epic",
605
- task_id: "bd-test.1",
606
- task_title: "Test Task",
607
- files_touched: [],
608
- diff: "",
609
- });
610
-
611
- expect(prompt).toContain("file");
612
- expect(prompt).toContain("line");
613
- expect(prompt).toContain("issue");
614
- expect(prompt).toContain("suggestion");
615
- });
616
- });
617
-
618
- // ============================================================================
619
- // TDD ENFORCEMENT IN SWARM
620
- // ============================================================================
621
-
622
- describe("TDD enforcement in review criteria", () => {
623
- it("review criteria includes test coverage check", () => {
624
- const prompt = generateReviewPrompt({
625
- epic_id: "bd-test",
626
- epic_title: "Test Epic",
627
- task_id: "bd-test.1",
628
- task_title: "Test Task",
629
- files_touched: ["src/foo.ts"],
630
- diff: "+function foo() {}",
631
- });
632
-
633
- expect(prompt).toContain("Test Coverage");
634
- });
635
- });
636
-
637
- // ============================================================================
638
- // Edge Cases
639
- // ============================================================================
640
-
641
- describe("edge cases", () => {
642
- it("handles empty files_touched", () => {
643
- const prompt = generateReviewPrompt({
644
- epic_id: "bd-test",
645
- epic_title: "Test Epic",
646
- task_id: "bd-test.1",
647
- task_title: "Test Task",
648
- files_touched: [],
649
- diff: "",
650
- });
651
-
652
- expect(prompt).toContain("## Files Modified");
653
- // Should not crash, just have empty list
654
- });
655
-
656
- it("handles missing optional fields", () => {
657
- const prompt = generateReviewPrompt({
658
- epic_id: "bd-test",
659
- epic_title: "Test Epic",
660
- task_id: "bd-test.1",
661
- task_title: "Test Task",
662
- files_touched: [],
663
- diff: "",
664
- // No epic_description, task_description, dependencies, downstream
665
- });
666
-
667
- expect(prompt).toContain("Test Epic");
668
- expect(prompt).toContain("Test Task");
669
- // Should not include dependency sections
670
- expect(prompt).not.toContain("This Task Builds On");
671
- expect(prompt).not.toContain("Downstream Tasks");
672
- });
673
-
674
- it("handles special characters in diff", () => {
675
- const prompt = generateReviewPrompt({
676
- epic_id: "bd-test",
677
- epic_title: "Test Epic",
678
- task_id: "bd-test.1",
679
- task_title: "Test Task",
680
- files_touched: ["src/test.ts"],
681
- diff: '+const regex = /[a-z]+/g;\n+const template = `Hello ${name}`;',
682
- });
683
-
684
- expect(prompt).toContain("regex");
685
- expect(prompt).toContain("template");
686
- });
687
-
688
- it("handles very long diffs", () => {
689
- const longDiff = "+line\n".repeat(1000);
690
- const prompt = generateReviewPrompt({
691
- epic_id: "bd-test",
692
- epic_title: "Test Epic",
693
- task_id: "bd-test.1",
694
- task_title: "Test Task",
695
- files_touched: ["src/big.ts"],
696
- diff: longDiff,
697
- });
698
-
699
- // Should include the diff without truncation (truncation is caller's responsibility)
700
- expect(prompt).toContain(longDiff);
701
- });
702
- });
703
-
704
- // ============================================================================
705
- // Coordinator-Driven Retry: swarm_review_feedback returns retry_context
706
- // ============================================================================
707
-
708
- describe("swarm_review_feedback retry_context", () => {
709
- beforeEach(() => {
710
- clearReviewStatus("bd-retry-test");
711
- vi.clearAllMocks();
712
- });
713
-
714
- it("returns retry_context when status is needs_changes", async () => {
715
- const issues = JSON.stringify([
716
- { file: "src/auth.ts", line: 42, issue: "Missing null check", suggestion: "Add null check" }
717
- ]);
718
-
719
- const result = await swarm_review_feedback.execute(
720
- {
721
- project_key: "/tmp/test-project",
722
- task_id: "bd-retry-test",
723
- worker_id: "worker-test",
724
- status: "needs_changes",
725
- issues,
726
- },
727
- mockContext
728
- );
729
-
730
- const parsed = JSON.parse(result);
731
- expect(parsed.success).toBe(true);
732
- expect(parsed.status).toBe("needs_changes");
733
- // NEW: Should include retry_context for coordinator
734
- expect(parsed).toHaveProperty("retry_context");
735
- expect(parsed.retry_context).toHaveProperty("task_id", "bd-retry-test");
736
- expect(parsed.retry_context).toHaveProperty("attempt", 1);
737
- expect(parsed.retry_context).toHaveProperty("issues");
738
- expect(parsed.retry_context.issues).toHaveLength(1);
739
- });
740
-
741
- it("retry_context includes issues in structured format", async () => {
742
- const issues = [
743
- { file: "src/a.ts", line: 10, issue: "Bug A", suggestion: "Fix A" },
744
- { file: "src/b.ts", line: 20, issue: "Bug B", suggestion: "Fix B" },
745
- ];
746
-
747
- const result = await swarm_review_feedback.execute(
748
- {
749
- project_key: "/tmp/test-project",
750
- task_id: "bd-retry-test",
751
- worker_id: "worker-test",
752
- status: "needs_changes",
753
- issues: JSON.stringify(issues),
754
- },
755
- mockContext
756
- );
757
-
758
- const parsed = JSON.parse(result);
759
- expect(parsed.retry_context.issues).toEqual(issues);
760
- });
761
-
762
- it("retry_context includes next_action hint for coordinator", async () => {
763
- const issues = JSON.stringify([{ file: "x.ts", issue: "bug" }]);
764
-
765
- const result = await swarm_review_feedback.execute(
766
- {
767
- project_key: "/tmp/test-project",
768
- task_id: "bd-retry-test",
769
- worker_id: "worker-test",
770
- status: "needs_changes",
771
- issues,
772
- },
773
- mockContext
774
- );
775
-
776
- const parsed = JSON.parse(result);
777
- // Should tell coordinator what to do next
778
- expect(parsed.retry_context).toHaveProperty("next_action");
779
- expect(parsed.retry_context.next_action).toContain("swarm_spawn_retry");
780
- });
781
-
782
- it("does NOT include retry_context when approved", async () => {
783
- const result = await swarm_review_feedback.execute(
784
- {
785
- project_key: "/tmp/test-project",
786
- task_id: "bd-retry-test",
787
- worker_id: "worker-test",
788
- status: "approved",
789
- summary: "Looks good!",
790
- },
791
- mockContext
792
- );
793
-
794
- const parsed = JSON.parse(result);
795
- expect(parsed.success).toBe(true);
796
- expect(parsed.status).toBe("approved");
797
- expect(parsed).not.toHaveProperty("retry_context");
798
- });
799
-
800
- it("does NOT include retry_context when task fails (3 attempts)", async () => {
801
- const issues = JSON.stringify([{ file: "x.ts", issue: "still broken" }]);
802
-
803
- // Exhaust all attempts
804
- let result: string = "";
805
- for (let i = 0; i < 3; i++) {
806
- result = await swarm_review_feedback.execute(
807
- {
808
- project_key: "/tmp/test-project",
809
- task_id: "bd-retry-test",
810
- worker_id: "worker-test",
811
- status: "needs_changes",
812
- issues,
813
- },
814
- mockContext
815
- );
816
- }
817
-
818
- const parsed = JSON.parse(result);
819
- expect(parsed.task_failed).toBe(true);
820
- // No retry_context when task is failed - nothing more to retry
821
- expect(parsed).not.toHaveProperty("retry_context");
822
- });
823
-
824
- it("retry_context includes max_attempts for coordinator awareness", async () => {
825
- const issues = JSON.stringify([{ file: "x.ts", issue: "bug" }]);
826
-
827
- const result = await swarm_review_feedback.execute(
828
- {
829
- project_key: "/tmp/test-project",
830
- task_id: "bd-retry-test",
831
- worker_id: "worker-test",
832
- status: "needs_changes",
833
- issues,
834
- },
835
- mockContext
836
- );
837
-
838
- const parsed = JSON.parse(result);
839
- expect(parsed.retry_context).toHaveProperty("max_attempts", 3);
840
- });
841
-
842
- it("does NOT send message to dead worker for needs_changes", async () => {
843
- const { sendSwarmMessage } = await import("swarm-mail");
844
- const issues = JSON.stringify([{ file: "x.ts", issue: "bug" }]);
845
-
846
- await swarm_review_feedback.execute(
847
- {
848
- project_key: "/tmp/test-project",
849
- task_id: "bd-retry-test",
850
- worker_id: "worker-test",
851
- status: "needs_changes",
852
- issues,
853
- },
854
- mockContext
855
- );
856
-
857
- // Should NOT call sendSwarmMessage for needs_changes
858
- // Workers are dead - they can't read messages
859
- expect(sendSwarmMessage).not.toHaveBeenCalled();
860
- });
861
-
862
- it("DOES send message for approved status (audit trail)", async () => {
863
- const { sendSwarmMessage } = await import("swarm-mail");
864
-
865
- await swarm_review_feedback.execute(
866
- {
867
- project_key: "/tmp/test-project",
868
- task_id: "bd-retry-test",
869
- worker_id: "worker-test",
870
- status: "approved",
871
- summary: "Good work!",
872
- },
873
- mockContext
874
- );
875
-
876
- // Approved messages are still sent for audit trail
877
- expect(sendSwarmMessage).toHaveBeenCalled();
878
- });
879
- });