opencode-swarm-plugin 0.44.0 → 0.44.2

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 (215) hide show
  1. package/bin/swarm.serve.test.ts +6 -4
  2. package/bin/swarm.ts +18 -12
  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/hive.js +14834 -0
  7. package/dist/index.d.ts +18 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +7743 -62593
  10. package/dist/plugin.js +24052 -78907
  11. package/dist/swarm-orchestrate.d.ts.map +1 -1
  12. package/dist/swarm-prompts.d.ts.map +1 -1
  13. package/dist/swarm-prompts.js +39407 -0
  14. package/dist/swarm-review.d.ts.map +1 -1
  15. package/dist/swarm-validation.d.ts +127 -0
  16. package/dist/swarm-validation.d.ts.map +1 -0
  17. package/dist/validators/index.d.ts +7 -0
  18. package/dist/validators/index.d.ts.map +1 -0
  19. package/dist/validators/schema-validator.d.ts +58 -0
  20. package/dist/validators/schema-validator.d.ts.map +1 -0
  21. package/package.json +17 -5
  22. package/.changeset/swarm-insights-data-layer.md +0 -63
  23. package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
  24. package/.hive/analysis/session-data-quality-audit.md +0 -320
  25. package/.hive/eval-results.json +0 -483
  26. package/.hive/issues.jsonl +0 -138
  27. package/.hive/memories.jsonl +0 -729
  28. package/.opencode/eval-history.jsonl +0 -327
  29. package/.turbo/turbo-build.log +0 -9
  30. package/CHANGELOG.md +0 -2286
  31. package/SCORER-ANALYSIS.md +0 -598
  32. package/docs/analysis/subagent-coordination-patterns.md +0 -902
  33. package/docs/analysis-socratic-planner-pattern.md +0 -504
  34. package/docs/planning/ADR-001-monorepo-structure.md +0 -171
  35. package/docs/planning/ADR-002-package-extraction.md +0 -393
  36. package/docs/planning/ADR-003-performance-improvements.md +0 -451
  37. package/docs/planning/ADR-004-message-queue-features.md +0 -187
  38. package/docs/planning/ADR-005-devtools-observability.md +0 -202
  39. package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
  40. package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
  41. package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
  42. package/docs/planning/ADR-010-cass-inhousing.md +0 -1215
  43. package/docs/planning/ROADMAP.md +0 -368
  44. package/docs/semantic-memory-cli-syntax.md +0 -123
  45. package/docs/swarm-mail-architecture.md +0 -1147
  46. package/docs/testing/context-recovery-test.md +0 -470
  47. package/evals/ARCHITECTURE.md +0 -1189
  48. package/evals/README.md +0 -768
  49. package/evals/compaction-prompt.eval.ts +0 -149
  50. package/evals/compaction-resumption.eval.ts +0 -289
  51. package/evals/coordinator-behavior.eval.ts +0 -307
  52. package/evals/coordinator-session.eval.ts +0 -154
  53. package/evals/evalite.config.ts.bak +0 -15
  54. package/evals/example.eval.ts +0 -31
  55. package/evals/fixtures/cass-baseline.ts +0 -217
  56. package/evals/fixtures/compaction-cases.ts +0 -350
  57. package/evals/fixtures/compaction-prompt-cases.ts +0 -311
  58. package/evals/fixtures/coordinator-sessions.ts +0 -328
  59. package/evals/fixtures/decomposition-cases.ts +0 -105
  60. package/evals/lib/compaction-loader.test.ts +0 -248
  61. package/evals/lib/compaction-loader.ts +0 -320
  62. package/evals/lib/data-loader.evalite-test.ts +0 -289
  63. package/evals/lib/data-loader.test.ts +0 -345
  64. package/evals/lib/data-loader.ts +0 -281
  65. package/evals/lib/llm.ts +0 -115
  66. package/evals/scorers/compaction-prompt-scorers.ts +0 -145
  67. package/evals/scorers/compaction-scorers.ts +0 -305
  68. package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
  69. package/evals/scorers/coordinator-discipline.ts +0 -325
  70. package/evals/scorers/index.test.ts +0 -146
  71. package/evals/scorers/index.ts +0 -328
  72. package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
  73. package/evals/scorers/outcome-scorers.ts +0 -349
  74. package/evals/swarm-decomposition.eval.ts +0 -121
  75. package/examples/commands/swarm.md +0 -745
  76. package/examples/plugin-wrapper-template.ts +0 -2515
  77. package/examples/skills/hive-workflow/SKILL.md +0 -212
  78. package/examples/skills/skill-creator/SKILL.md +0 -223
  79. package/examples/skills/swarm-coordination/SKILL.md +0 -292
  80. package/global-skills/cli-builder/SKILL.md +0 -344
  81. package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
  82. package/global-skills/learning-systems/SKILL.md +0 -644
  83. package/global-skills/skill-creator/LICENSE.txt +0 -202
  84. package/global-skills/skill-creator/SKILL.md +0 -352
  85. package/global-skills/skill-creator/references/output-patterns.md +0 -82
  86. package/global-skills/skill-creator/references/workflows.md +0 -28
  87. package/global-skills/swarm-coordination/SKILL.md +0 -995
  88. package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
  89. package/global-skills/swarm-coordination/references/strategies.md +0 -138
  90. package/global-skills/system-design/SKILL.md +0 -213
  91. package/global-skills/testing-patterns/SKILL.md +0 -430
  92. package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
  93. package/opencode-swarm-plugin-0.30.7.tgz +0 -0
  94. package/opencode-swarm-plugin-0.31.0.tgz +0 -0
  95. package/scripts/cleanup-test-memories.ts +0 -346
  96. package/scripts/init-skill.ts +0 -222
  97. package/scripts/migrate-unknown-sessions.ts +0 -349
  98. package/scripts/validate-skill.ts +0 -204
  99. package/src/agent-mail.ts +0 -1724
  100. package/src/anti-patterns.test.ts +0 -1167
  101. package/src/anti-patterns.ts +0 -448
  102. package/src/compaction-capture.integration.test.ts +0 -257
  103. package/src/compaction-hook.test.ts +0 -838
  104. package/src/compaction-hook.ts +0 -1204
  105. package/src/compaction-observability.integration.test.ts +0 -139
  106. package/src/compaction-observability.test.ts +0 -187
  107. package/src/compaction-observability.ts +0 -324
  108. package/src/compaction-prompt-scorers.test.ts +0 -475
  109. package/src/compaction-prompt-scoring.ts +0 -300
  110. package/src/contributor-tools.test.ts +0 -133
  111. package/src/contributor-tools.ts +0 -201
  112. package/src/dashboard.test.ts +0 -611
  113. package/src/dashboard.ts +0 -462
  114. package/src/error-enrichment.test.ts +0 -403
  115. package/src/error-enrichment.ts +0 -219
  116. package/src/eval-capture.test.ts +0 -1015
  117. package/src/eval-capture.ts +0 -929
  118. package/src/eval-gates.test.ts +0 -306
  119. package/src/eval-gates.ts +0 -218
  120. package/src/eval-history.test.ts +0 -508
  121. package/src/eval-history.ts +0 -214
  122. package/src/eval-learning.test.ts +0 -378
  123. package/src/eval-learning.ts +0 -360
  124. package/src/eval-runner.test.ts +0 -223
  125. package/src/eval-runner.ts +0 -402
  126. package/src/export-tools.test.ts +0 -476
  127. package/src/export-tools.ts +0 -257
  128. package/src/hive.integration.test.ts +0 -2241
  129. package/src/hive.ts +0 -1628
  130. package/src/index.ts +0 -940
  131. package/src/learning.integration.test.ts +0 -1815
  132. package/src/learning.ts +0 -1079
  133. package/src/logger.test.ts +0 -189
  134. package/src/logger.ts +0 -135
  135. package/src/mandate-promotion.test.ts +0 -473
  136. package/src/mandate-promotion.ts +0 -239
  137. package/src/mandate-storage.integration.test.ts +0 -601
  138. package/src/mandate-storage.test.ts +0 -578
  139. package/src/mandate-storage.ts +0 -794
  140. package/src/mandates.ts +0 -540
  141. package/src/memory-tools.test.ts +0 -195
  142. package/src/memory-tools.ts +0 -344
  143. package/src/memory.integration.test.ts +0 -334
  144. package/src/memory.test.ts +0 -158
  145. package/src/memory.ts +0 -527
  146. package/src/model-selection.test.ts +0 -188
  147. package/src/model-selection.ts +0 -68
  148. package/src/observability-tools.test.ts +0 -359
  149. package/src/observability-tools.ts +0 -871
  150. package/src/output-guardrails.test.ts +0 -438
  151. package/src/output-guardrails.ts +0 -381
  152. package/src/pattern-maturity.test.ts +0 -1160
  153. package/src/pattern-maturity.ts +0 -525
  154. package/src/planning-guardrails.test.ts +0 -491
  155. package/src/planning-guardrails.ts +0 -438
  156. package/src/plugin.ts +0 -23
  157. package/src/post-compaction-tracker.test.ts +0 -251
  158. package/src/post-compaction-tracker.ts +0 -237
  159. package/src/query-tools.test.ts +0 -636
  160. package/src/query-tools.ts +0 -324
  161. package/src/rate-limiter.integration.test.ts +0 -466
  162. package/src/rate-limiter.ts +0 -774
  163. package/src/replay-tools.test.ts +0 -496
  164. package/src/replay-tools.ts +0 -240
  165. package/src/repo-crawl.integration.test.ts +0 -441
  166. package/src/repo-crawl.ts +0 -610
  167. package/src/schemas/cell-events.test.ts +0 -347
  168. package/src/schemas/cell-events.ts +0 -807
  169. package/src/schemas/cell.ts +0 -257
  170. package/src/schemas/evaluation.ts +0 -166
  171. package/src/schemas/index.test.ts +0 -199
  172. package/src/schemas/index.ts +0 -286
  173. package/src/schemas/mandate.ts +0 -232
  174. package/src/schemas/swarm-context.ts +0 -115
  175. package/src/schemas/task.ts +0 -161
  176. package/src/schemas/worker-handoff.test.ts +0 -302
  177. package/src/schemas/worker-handoff.ts +0 -131
  178. package/src/sessions/agent-discovery.test.ts +0 -137
  179. package/src/sessions/agent-discovery.ts +0 -112
  180. package/src/sessions/index.ts +0 -15
  181. package/src/skills.integration.test.ts +0 -1192
  182. package/src/skills.test.ts +0 -643
  183. package/src/skills.ts +0 -1549
  184. package/src/storage.integration.test.ts +0 -341
  185. package/src/storage.ts +0 -884
  186. package/src/structured.integration.test.ts +0 -817
  187. package/src/structured.test.ts +0 -1046
  188. package/src/structured.ts +0 -762
  189. package/src/swarm-decompose.test.ts +0 -188
  190. package/src/swarm-decompose.ts +0 -1302
  191. package/src/swarm-deferred.integration.test.ts +0 -157
  192. package/src/swarm-deferred.test.ts +0 -38
  193. package/src/swarm-insights.test.ts +0 -214
  194. package/src/swarm-insights.ts +0 -459
  195. package/src/swarm-mail.integration.test.ts +0 -970
  196. package/src/swarm-mail.ts +0 -739
  197. package/src/swarm-orchestrate.integration.test.ts +0 -282
  198. package/src/swarm-orchestrate.test.ts +0 -548
  199. package/src/swarm-orchestrate.ts +0 -3084
  200. package/src/swarm-prompts.test.ts +0 -1270
  201. package/src/swarm-prompts.ts +0 -2077
  202. package/src/swarm-research.integration.test.ts +0 -701
  203. package/src/swarm-research.test.ts +0 -698
  204. package/src/swarm-research.ts +0 -472
  205. package/src/swarm-review.integration.test.ts +0 -285
  206. package/src/swarm-review.test.ts +0 -879
  207. package/src/swarm-review.ts +0 -709
  208. package/src/swarm-strategies.ts +0 -407
  209. package/src/swarm-worktree.test.ts +0 -501
  210. package/src/swarm-worktree.ts +0 -575
  211. package/src/swarm.integration.test.ts +0 -2377
  212. package/src/swarm.ts +0 -38
  213. package/src/tool-adapter.integration.test.ts +0 -1221
  214. package/src/tool-availability.ts +0 -461
  215. package/tsconfig.json +0 -28
@@ -1,817 +0,0 @@
1
- /**
2
- * Integration tests for structured_* tools
3
- *
4
- * Tests the complete tool execution flow:
5
- * - Tool argument parsing and validation
6
- * - JSON extraction from various formats
7
- * - Schema validation with structured output
8
- * - Error handling and feedback formatting
9
- *
10
- * ## Test Pattern
11
- * - Call tool.execute() directly (simulates plugin invocation)
12
- * - Use mock ToolContext
13
- * - Test happy paths with real-world scenarios
14
- * - No external dependencies (pure JSON parsing)
15
- */
16
-
17
- import type { ToolContext } from "@opencode-ai/plugin";
18
- import { describe, expect, it } from "bun:test";
19
- import {
20
- structured_extract_json,
21
- structured_parse_cell_tree,
22
- structured_parse_decomposition,
23
- structured_parse_evaluation,
24
- structured_validate,
25
- } from "./structured";
26
-
27
- // Mock ToolContext for tool execution
28
- const mockCtx = {} as ToolContext;
29
-
30
- // ============================================================================
31
- // structured_extract_json - JSON Extraction
32
- // ============================================================================
33
-
34
- describe("structured_extract_json integration", () => {
35
- it("extracts clean JSON and returns success", async () => {
36
- const result = await structured_extract_json.execute(
37
- { text: '{"name": "Joel", "role": "developer"}' },
38
- mockCtx,
39
- );
40
-
41
- const parsed = JSON.parse(result);
42
- expect(parsed.success).toBe(true);
43
- expect(parsed.data).toEqual({ name: "Joel", role: "developer" });
44
- expect(parsed.extraction_method).toBe("direct_parse");
45
- });
46
-
47
- it("extracts JSON from markdown code block", async () => {
48
- const markdown = `Here is the response:\n\`\`\`json\n{"status": "complete"}\n\`\`\``;
49
-
50
- const result = await structured_extract_json.execute(
51
- { text: markdown },
52
- mockCtx,
53
- );
54
-
55
- const parsed = JSON.parse(result);
56
- expect(parsed.success).toBe(true);
57
- expect(parsed.data).toEqual({ status: "complete" });
58
- expect(parsed.extraction_method).toBe("json_code_block");
59
- });
60
-
61
- it("extracts JSON from mixed content with multiple code blocks", async () => {
62
- const mixed = `
63
- Some text here.
64
-
65
- \`\`\`typescript
66
- const code = "not json";
67
- \`\`\`
68
-
69
- Result:
70
-
71
- \`\`\`json
72
- {"result": "success"}
73
- \`\`\`
74
- `;
75
-
76
- const result = await structured_extract_json.execute(
77
- { text: mixed },
78
- mockCtx,
79
- );
80
-
81
- const parsed = JSON.parse(result);
82
- expect(parsed.success).toBe(true);
83
- expect(parsed.data).toEqual({ result: "success" });
84
- expect(parsed.extraction_method).toBe("json_code_block");
85
- });
86
-
87
- it("handles complex nested structures", async () => {
88
- const complex = JSON.stringify({
89
- epic: {
90
- title: "Add authentication",
91
- description: "OAuth + session management",
92
- },
93
- subtasks: [
94
- {
95
- title: "OAuth integration",
96
- files: ["src/auth/oauth.ts"],
97
- estimated_complexity: 3,
98
- },
99
- {
100
- title: "Session store",
101
- files: ["src/auth/sessions.ts"],
102
- estimated_complexity: 2,
103
- },
104
- ],
105
- });
106
-
107
- const result = await structured_extract_json.execute(
108
- { text: complex },
109
- mockCtx,
110
- );
111
-
112
- const parsed = JSON.parse(result);
113
- expect(parsed.success).toBe(true);
114
- expect(parsed.data.epic.title).toBe("Add authentication");
115
- expect(parsed.data.subtasks).toHaveLength(2);
116
- });
117
-
118
- it("returns error for non-JSON input", async () => {
119
- const result = await structured_extract_json.execute(
120
- { text: "This is not JSON at all" },
121
- mockCtx,
122
- );
123
-
124
- const parsed = JSON.parse(result);
125
- expect(parsed.success).toBe(false);
126
- expect(parsed.error).toContain("Could not extract");
127
- expect(Array.isArray(parsed.attempted_strategies)).toBe(true);
128
- expect(parsed.attempted_strategies.length).toBeGreaterThan(0);
129
- });
130
-
131
- it("includes input preview in error for long text", async () => {
132
- const longText = "x".repeat(300);
133
-
134
- const result = await structured_extract_json.execute(
135
- { text: longText },
136
- mockCtx,
137
- );
138
-
139
- const parsed = JSON.parse(result);
140
- expect(parsed.success).toBe(false);
141
- expect(parsed.raw_input_preview).toBeDefined();
142
- expect(parsed.raw_input_preview.length).toBeLessThanOrEqual(200);
143
- });
144
- });
145
-
146
- // ============================================================================
147
- // structured_validate - Schema Validation
148
- // ============================================================================
149
-
150
- describe("structured_validate integration", () => {
151
- describe("evaluation schema", () => {
152
- it("validates correct evaluation structure", async () => {
153
- const evalObj = {
154
- passed: true,
155
- criteria: {
156
- type_safety: { passed: true, feedback: "All types validated" },
157
- no_bugs: { passed: true, feedback: "No issues found" },
158
- },
159
- overall_feedback: "Excellent work",
160
- retry_suggestion: null,
161
- };
162
-
163
- const result = await structured_validate.execute(
164
- {
165
- response: JSON.stringify(evalObj),
166
- schema_name: "evaluation",
167
- },
168
- mockCtx,
169
- );
170
-
171
- const parsed = JSON.parse(result);
172
- expect(parsed.success).toBe(true);
173
- expect(parsed.data.passed).toBe(true);
174
- expect(Object.keys(parsed.data.criteria)).toHaveLength(2);
175
- });
176
-
177
- it("extracts JSON from markdown before validating", async () => {
178
- const evalObj = {
179
- passed: false,
180
- criteria: {
181
- test: { passed: false, feedback: "Test failed" },
182
- },
183
- overall_feedback: "Needs fixes",
184
- retry_suggestion: "Add tests",
185
- };
186
-
187
- const markdown = `Analysis complete:\n\`\`\`json\n${JSON.stringify(evalObj)}\n\`\`\``;
188
-
189
- const result = await structured_validate.execute(
190
- {
191
- response: markdown,
192
- schema_name: "evaluation",
193
- },
194
- mockCtx,
195
- );
196
-
197
- const parsed = JSON.parse(result);
198
- expect(parsed.success).toBe(true);
199
- expect(parsed.extractionMethod).toBe("json_code_block");
200
- });
201
-
202
- it("returns structured errors for invalid evaluation", async () => {
203
- const result = await structured_validate.execute(
204
- {
205
- response: '{"invalid": true}',
206
- schema_name: "evaluation",
207
- },
208
- mockCtx,
209
- );
210
-
211
- const parsed = JSON.parse(result);
212
- expect(parsed.success).toBe(false);
213
- expect(Array.isArray(parsed.errors)).toBe(true);
214
- expect(parsed.errors.length).toBeGreaterThan(0);
215
- });
216
-
217
- it("handles empty response gracefully", async () => {
218
- const result = await structured_validate.execute(
219
- {
220
- response: "",
221
- schema_name: "evaluation",
222
- },
223
- mockCtx,
224
- );
225
-
226
- const parsed = JSON.parse(result);
227
- expect(parsed.valid).toBe(false);
228
- expect(parsed.error).toContain("empty");
229
- });
230
- });
231
-
232
- describe("task_decomposition schema", () => {
233
- it("validates correct decomposition structure", async () => {
234
- const decompObj = {
235
- task: "Implement authentication",
236
- reasoning: "Split by feature layer",
237
- subtasks: [
238
- {
239
- title: "Auth service",
240
- description: "Core logic",
241
- files: ["src/auth.ts"],
242
- estimated_effort: "medium",
243
- },
244
- {
245
- title: "Auth UI",
246
- description: "Login form",
247
- files: ["src/components/Login.tsx"],
248
- estimated_effort: "small",
249
- },
250
- ],
251
- };
252
-
253
- const result = await structured_validate.execute(
254
- {
255
- response: JSON.stringify(decompObj),
256
- schema_name: "task_decomposition",
257
- },
258
- mockCtx,
259
- );
260
-
261
- const parsed = JSON.parse(result);
262
- expect(parsed.success).toBe(true);
263
- expect(parsed.data.task).toBe("Implement authentication");
264
- expect(parsed.data.subtasks).toHaveLength(2);
265
- });
266
- });
267
-
268
- describe("cell_tree schema", () => {
269
- it("validates correct cell tree structure", async () => {
270
- const treeObj = {
271
- epic: {
272
- title: "Add authentication",
273
- description: "OAuth + sessions",
274
- },
275
- subtasks: [
276
- {
277
- title: "OAuth integration",
278
- description: "Connect to provider",
279
- files: ["src/auth/oauth.ts"],
280
- dependencies: [],
281
- estimated_complexity: 3,
282
- },
283
- {
284
- title: "Session store",
285
- files: ["src/auth/sessions.ts"],
286
- dependencies: [0],
287
- estimated_complexity: 2,
288
- },
289
- ],
290
- };
291
-
292
- const result = await structured_validate.execute(
293
- {
294
- response: JSON.stringify(treeObj),
295
- schema_name: "cell_tree",
296
- },
297
- mockCtx,
298
- );
299
-
300
- const parsed = JSON.parse(result);
301
- expect(parsed.success).toBe(true);
302
- expect(parsed.data.epic.title).toBe("Add authentication");
303
- expect(parsed.data.subtasks).toHaveLength(2);
304
- });
305
- });
306
-
307
- it("includes retry hint when max_retries provided", async () => {
308
- const result = await structured_validate.execute(
309
- {
310
- response: '{"invalid": true}',
311
- schema_name: "evaluation",
312
- max_retries: 3,
313
- },
314
- mockCtx,
315
- );
316
-
317
- const parsed = JSON.parse(result);
318
- expect(parsed.success).toBe(false);
319
- const hasRetryHint = parsed.errors.some((e: string) =>
320
- e.includes("try again"),
321
- );
322
- expect(hasRetryHint).toBe(true);
323
- });
324
- });
325
-
326
- // ============================================================================
327
- // structured_parse_evaluation - Typed Evaluation Parsing
328
- // ============================================================================
329
-
330
- describe("structured_parse_evaluation integration", () => {
331
- it("parses valid evaluation with summary", async () => {
332
- const evalObj = {
333
- passed: true,
334
- criteria: {
335
- type_safe: { passed: true, feedback: "All types validated" },
336
- no_bugs: { passed: true, feedback: "No issues found" },
337
- patterns: { passed: true, feedback: "Follows best practices" },
338
- },
339
- overall_feedback: "Excellent implementation",
340
- retry_suggestion: null,
341
- };
342
-
343
- const result = await structured_parse_evaluation.execute(
344
- { response: JSON.stringify(evalObj) },
345
- mockCtx,
346
- );
347
-
348
- const parsed = JSON.parse(result);
349
- expect(parsed.success).toBe(true);
350
- expect(parsed.data.passed).toBe(true);
351
- expect(parsed.summary.passed).toBe(true);
352
- expect(parsed.summary.criteria_count).toBe(3);
353
- expect(parsed.summary.failed_criteria).toEqual([]);
354
- });
355
-
356
- it("identifies failed criteria in summary", async () => {
357
- const evalObj = {
358
- passed: false,
359
- criteria: {
360
- type_safe: { passed: true, feedback: "OK" },
361
- no_bugs: { passed: false, feedback: "Found null pointer" },
362
- patterns: { passed: false, feedback: "Missing error handling" },
363
- },
364
- overall_feedback: "Needs fixes",
365
- retry_suggestion: "Add null checks and error handling",
366
- };
367
-
368
- const result = await structured_parse_evaluation.execute(
369
- { response: JSON.stringify(evalObj) },
370
- mockCtx,
371
- );
372
-
373
- const parsed = JSON.parse(result);
374
- expect(parsed.success).toBe(true);
375
- expect(parsed.summary.passed).toBe(false);
376
- expect(parsed.summary.failed_criteria).toContain("no_bugs");
377
- expect(parsed.summary.failed_criteria).toContain("patterns");
378
- expect(parsed.summary.failed_criteria).not.toContain("type_safe");
379
- });
380
-
381
- it("returns structured error for malformed JSON", async () => {
382
- const result = await structured_parse_evaluation.execute(
383
- { response: "not json" },
384
- mockCtx,
385
- );
386
-
387
- const parsed = JSON.parse(result);
388
- expect(parsed.success).toBe(false);
389
- expect(parsed.error).toContain("extract JSON");
390
- expect(parsed.feedback).toBeDefined();
391
- expect(Array.isArray(parsed.attempted_strategies)).toBe(true);
392
- });
393
-
394
- it("returns structured error for invalid schema", async () => {
395
- const invalidEval = {
396
- passed: "not a boolean",
397
- criteria: {},
398
- overall_feedback: "test",
399
- retry_suggestion: null,
400
- };
401
-
402
- const result = await structured_parse_evaluation.execute(
403
- { response: JSON.stringify(invalidEval) },
404
- mockCtx,
405
- );
406
-
407
- const parsed = JSON.parse(result);
408
- expect(parsed.success).toBe(false);
409
- expect(parsed.error).toContain("does not match schema");
410
- expect(Array.isArray(parsed.validation_errors)).toBe(true);
411
- expect(parsed.expected_shape).toBeDefined();
412
- });
413
- });
414
-
415
- // ============================================================================
416
- // structured_parse_decomposition - Typed Decomposition Parsing
417
- // ============================================================================
418
-
419
- describe("structured_parse_decomposition integration", () => {
420
- it("parses valid decomposition with summary", async () => {
421
- const decompObj = {
422
- task: "Implement authentication",
423
- reasoning: "Split by feature layer for parallel development",
424
- subtasks: [
425
- {
426
- title: "Auth service",
427
- description: "Core authentication logic",
428
- files: ["src/auth/service.ts", "src/auth/types.ts"],
429
- estimated_effort: "medium",
430
- },
431
- {
432
- title: "Auth UI",
433
- description: "Login and signup forms",
434
- files: ["src/components/Login.tsx", "src/components/Signup.tsx"],
435
- estimated_effort: "small",
436
- },
437
- {
438
- title: "Auth API",
439
- description: "REST endpoints",
440
- files: ["src/api/auth.ts"],
441
- estimated_effort: "small",
442
- },
443
- ],
444
- };
445
-
446
- const result = await structured_parse_decomposition.execute(
447
- { response: JSON.stringify(decompObj) },
448
- mockCtx,
449
- );
450
-
451
- const parsed = JSON.parse(result);
452
- expect(parsed.success).toBe(true);
453
- expect(parsed.data.task).toBe("Implement authentication");
454
- expect(parsed.summary.subtask_count).toBe(3);
455
- expect(parsed.summary.total_files).toBe(5);
456
- expect(parsed.summary.files).toContain("src/auth/service.ts");
457
- });
458
-
459
- it("includes effort breakdown in summary", async () => {
460
- const decompObj = {
461
- task: "Test task",
462
- subtasks: [
463
- {
464
- title: "T1",
465
- description: "D1",
466
- files: ["a.ts"],
467
- estimated_effort: "small",
468
- },
469
- {
470
- title: "T2",
471
- description: "D2",
472
- files: ["b.ts"],
473
- estimated_effort: "small",
474
- },
475
- {
476
- title: "T3",
477
- description: "D3",
478
- files: ["c.ts"],
479
- estimated_effort: "medium",
480
- },
481
- {
482
- title: "T4",
483
- description: "D4",
484
- files: ["d.ts"],
485
- estimated_effort: "large",
486
- },
487
- ],
488
- };
489
-
490
- const result = await structured_parse_decomposition.execute(
491
- { response: JSON.stringify(decompObj) },
492
- mockCtx,
493
- );
494
-
495
- const parsed = JSON.parse(result);
496
- expect(parsed.success).toBe(true);
497
- expect(parsed.summary.effort_breakdown.small).toBe(2);
498
- expect(parsed.summary.effort_breakdown.medium).toBe(1);
499
- expect(parsed.summary.effort_breakdown.large).toBe(1);
500
- });
501
-
502
- it("deduplicates files in summary", async () => {
503
- const decompObj = {
504
- task: "Test task",
505
- subtasks: [
506
- {
507
- title: "T1",
508
- description: "D1",
509
- files: ["shared.ts", "a.ts"],
510
- estimated_effort: "small",
511
- },
512
- {
513
- title: "T2",
514
- description: "D2",
515
- files: ["shared.ts", "b.ts"],
516
- estimated_effort: "small",
517
- },
518
- ],
519
- };
520
-
521
- const result = await structured_parse_decomposition.execute(
522
- { response: JSON.stringify(decompObj) },
523
- mockCtx,
524
- );
525
-
526
- const parsed = JSON.parse(result);
527
- expect(parsed.success).toBe(true);
528
- expect(parsed.summary.total_files).toBe(3);
529
- expect(parsed.summary.files).toEqual(["shared.ts", "a.ts", "b.ts"]);
530
- });
531
-
532
- it("handles dependencies in summary", async () => {
533
- const decompObj = {
534
- task: "Test task",
535
- subtasks: [
536
- {
537
- title: "T1",
538
- description: "D1",
539
- files: ["a.ts"],
540
- estimated_effort: "small",
541
- },
542
- {
543
- title: "T2",
544
- description: "D2",
545
- files: ["b.ts"],
546
- estimated_effort: "small",
547
- },
548
- ],
549
- dependencies: [
550
- { from: 0, to: 1, type: "blocks" },
551
- { from: 1, to: 0, type: "requires" },
552
- ],
553
- };
554
-
555
- const result = await structured_parse_decomposition.execute(
556
- { response: JSON.stringify(decompObj) },
557
- mockCtx,
558
- );
559
-
560
- const parsed = JSON.parse(result);
561
- expect(parsed.success).toBe(true);
562
- expect(parsed.summary.dependency_count).toBe(2);
563
- });
564
-
565
- it("returns error for invalid decomposition", async () => {
566
- const result = await structured_parse_decomposition.execute(
567
- { response: '{"task": "Test"}' }, // Missing required subtasks
568
- mockCtx,
569
- );
570
-
571
- const parsed = JSON.parse(result);
572
- expect(parsed.success).toBe(false);
573
- expect(parsed.error).toContain("does not match schema");
574
- expect(parsed.expected_shape).toBeDefined();
575
- });
576
- });
577
-
578
- // ============================================================================
579
- // structured_parse_cell_tree - Typed Cell Tree Parsing
580
- // ============================================================================
581
-
582
- describe("structured_parse_cell_tree integration", () => {
583
- it("parses valid cell tree with summary", async () => {
584
- const treeObj = {
585
- epic: {
586
- title: "Add authentication system",
587
- description: "OAuth + session management + permissions",
588
- },
589
- subtasks: [
590
- {
591
- title: "OAuth integration",
592
- description: "Connect to OAuth provider",
593
- files: ["src/auth/oauth.ts", "src/auth/config.ts"],
594
- dependencies: [],
595
- estimated_complexity: 4,
596
- },
597
- {
598
- title: "Session store",
599
- description: "Redis-backed session management",
600
- files: ["src/auth/sessions.ts"],
601
- dependencies: [0],
602
- estimated_complexity: 3,
603
- },
604
- {
605
- title: "Permissions system",
606
- description: "Role-based access control",
607
- files: ["src/auth/permissions.ts", "src/auth/roles.ts"],
608
- dependencies: [0, 1],
609
- estimated_complexity: 5,
610
- },
611
- ],
612
- };
613
-
614
- const result = await structured_parse_cell_tree.execute(
615
- { response: JSON.stringify(treeObj) },
616
- mockCtx,
617
- );
618
-
619
- const parsed = JSON.parse(result);
620
- expect(parsed.success).toBe(true);
621
- expect(parsed.data.epic.title).toBe("Add authentication system");
622
- expect(parsed.summary.subtask_count).toBe(3);
623
- expect(parsed.summary.total_files).toBe(5);
624
- expect(parsed.summary.complexity_total).toBe(12);
625
- });
626
-
627
- it("lists unique files in summary", async () => {
628
- const treeObj = {
629
- epic: { title: "Test epic" },
630
- subtasks: [
631
- {
632
- title: "T1",
633
- files: ["shared.ts", "a.ts"],
634
- dependencies: [],
635
- estimated_complexity: 2,
636
- },
637
- {
638
- title: "T2",
639
- files: ["shared.ts", "b.ts"],
640
- dependencies: [],
641
- estimated_complexity: 2,
642
- },
643
- ],
644
- };
645
-
646
- const result = await structured_parse_cell_tree.execute(
647
- { response: JSON.stringify(treeObj) },
648
- mockCtx,
649
- );
650
-
651
- const parsed = JSON.parse(result);
652
- expect(parsed.success).toBe(true);
653
- expect(parsed.summary.total_files).toBe(3);
654
- expect(parsed.summary.files).toEqual(["shared.ts", "a.ts", "b.ts"]);
655
- });
656
-
657
- it("calculates complexity total correctly", async () => {
658
- const treeObj = {
659
- epic: { title: "Test epic" },
660
- subtasks: [
661
- {
662
- title: "T1",
663
- files: ["a.ts"],
664
- dependencies: [],
665
- estimated_complexity: 2,
666
- },
667
- {
668
- title: "T2",
669
- files: ["b.ts"],
670
- dependencies: [],
671
- estimated_complexity: 3,
672
- },
673
- {
674
- title: "T3",
675
- files: ["c.ts"],
676
- dependencies: [],
677
- estimated_complexity: 1,
678
- },
679
- ],
680
- };
681
-
682
- const result = await structured_parse_cell_tree.execute(
683
- { response: JSON.stringify(treeObj) },
684
- mockCtx,
685
- );
686
-
687
- const parsed = JSON.parse(result);
688
- expect(parsed.success).toBe(true);
689
- expect(parsed.summary.complexity_total).toBe(6);
690
- });
691
-
692
- it("returns error for invalid cell tree", async () => {
693
- const result = await structured_parse_cell_tree.execute(
694
- { response: '{"epic": {}}' }, // Missing required fields
695
- mockCtx,
696
- );
697
-
698
- const parsed = JSON.parse(result);
699
- expect(parsed.success).toBe(false);
700
- expect(parsed.error).toContain("does not match schema");
701
- expect(parsed.expected_shape).toBeDefined();
702
- });
703
-
704
- it("includes expected shape in error feedback", async () => {
705
- const result = await structured_parse_cell_tree.execute(
706
- { response: '{"wrong": "structure"}' },
707
- mockCtx,
708
- );
709
-
710
- const parsed = JSON.parse(result);
711
- expect(parsed.success).toBe(false);
712
- expect(parsed.expected_shape.epic).toBeDefined();
713
- expect(parsed.expected_shape.subtasks).toBeDefined();
714
- });
715
- });
716
-
717
- // ============================================================================
718
- // Edge Cases and Real-World Scenarios
719
- // ============================================================================
720
-
721
- describe("Real-world integration scenarios", () => {
722
- it("handles evaluation with unicode and special characters", async () => {
723
- const evalObj = {
724
- passed: true,
725
- criteria: {
726
- emoji_support: {
727
- passed: true,
728
- feedback: "Handles 🎉 and 你好 correctly",
729
- },
730
- },
731
- overall_feedback: "All special chars work ✅",
732
- retry_suggestion: null,
733
- };
734
-
735
- const result = await structured_parse_evaluation.execute(
736
- { response: JSON.stringify(evalObj) },
737
- mockCtx,
738
- );
739
-
740
- const parsed = JSON.parse(result);
741
- expect(parsed.success).toBe(true);
742
- expect(parsed.data.criteria.emoji_support.feedback).toContain("🎉");
743
- });
744
-
745
- it("handles decomposition with deeply nested file paths", async () => {
746
- const decompObj = {
747
- task: "Reorganize project structure",
748
- subtasks: [
749
- {
750
- title: "Move auth files",
751
- description: "Restructure auth module",
752
- files: [
753
- "src/features/auth/services/oauth/providers/google.ts",
754
- "src/features/auth/services/oauth/providers/github.ts",
755
- ],
756
- estimated_effort: "small",
757
- },
758
- ],
759
- };
760
-
761
- const result = await structured_parse_decomposition.execute(
762
- { response: JSON.stringify(decompObj) },
763
- mockCtx,
764
- );
765
-
766
- const parsed = JSON.parse(result);
767
- expect(parsed.success).toBe(true);
768
- expect(parsed.summary.total_files).toBe(2);
769
- });
770
-
771
- it("handles cell tree with maximum complexity values", async () => {
772
- const treeObj = {
773
- epic: { title: "Complex refactor" },
774
- subtasks: [
775
- {
776
- title: "High complexity task",
777
- files: ["complex.ts"],
778
- dependencies: [],
779
- estimated_complexity: 5,
780
- },
781
- ],
782
- };
783
-
784
- const result = await structured_parse_cell_tree.execute(
785
- { response: JSON.stringify(treeObj) },
786
- mockCtx,
787
- );
788
-
789
- const parsed = JSON.parse(result);
790
- expect(parsed.success).toBe(true);
791
- expect(parsed.summary.complexity_total).toBe(5);
792
- });
793
-
794
- it("handles JSON with escaped characters in paths", async () => {
795
- const decompObj = {
796
- task: "Windows compatibility",
797
- subtasks: [
798
- {
799
- title: "Fix paths",
800
- description: "Handle backslashes",
801
- files: ["C:\\Users\\file.ts", "path\\to\\file.ts"],
802
- estimated_effort: "small",
803
- },
804
- ],
805
- };
806
-
807
- const result = await structured_parse_decomposition.execute(
808
- { response: JSON.stringify(decompObj) },
809
- mockCtx,
810
- );
811
-
812
- const parsed = JSON.parse(result);
813
- expect(parsed.success).toBe(true);
814
- // JSON.stringify escapes backslashes, so they become double-escaped
815
- expect(parsed.data.subtasks[0].files).toContain("C:\\Users\\file.ts");
816
- });
817
- });