opencode-swarm-plugin 0.43.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.
- package/bin/cass.characterization.test.ts +422 -0
- package/bin/swarm.serve.test.ts +6 -4
- package/bin/swarm.test.ts +68 -0
- package/bin/swarm.ts +81 -8
- package/dist/compaction-prompt-scoring.js +139 -0
- package/dist/contributor-tools.d.ts +42 -0
- package/dist/contributor-tools.d.ts.map +1 -0
- package/dist/eval-capture.js +12811 -0
- package/dist/hive.d.ts.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7728 -62590
- package/dist/plugin.js +23833 -78695
- package/dist/sessions/agent-discovery.d.ts +59 -0
- package/dist/sessions/agent-discovery.d.ts.map +1 -0
- package/dist/sessions/index.d.ts +10 -0
- package/dist/sessions/index.d.ts.map +1 -0
- package/dist/swarm-orchestrate.d.ts.map +1 -1
- package/dist/swarm-prompts.d.ts.map +1 -1
- package/dist/swarm-review.d.ts.map +1 -1
- package/package.json +17 -5
- package/.changeset/swarm-insights-data-layer.md +0 -63
- package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
- package/.hive/analysis/session-data-quality-audit.md +0 -320
- package/.hive/eval-results.json +0 -483
- package/.hive/issues.jsonl +0 -138
- package/.hive/memories.jsonl +0 -729
- package/.opencode/eval-history.jsonl +0 -327
- package/.turbo/turbo-build.log +0 -9
- package/CHANGELOG.md +0 -2255
- package/SCORER-ANALYSIS.md +0 -598
- package/docs/analysis/subagent-coordination-patterns.md +0 -902
- package/docs/analysis-socratic-planner-pattern.md +0 -504
- package/docs/planning/ADR-001-monorepo-structure.md +0 -171
- package/docs/planning/ADR-002-package-extraction.md +0 -393
- package/docs/planning/ADR-003-performance-improvements.md +0 -451
- package/docs/planning/ADR-004-message-queue-features.md +0 -187
- package/docs/planning/ADR-005-devtools-observability.md +0 -202
- package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
- package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
- package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
- package/docs/planning/ROADMAP.md +0 -368
- package/docs/semantic-memory-cli-syntax.md +0 -123
- package/docs/swarm-mail-architecture.md +0 -1147
- package/docs/testing/context-recovery-test.md +0 -470
- package/evals/ARCHITECTURE.md +0 -1189
- package/evals/README.md +0 -768
- package/evals/compaction-prompt.eval.ts +0 -149
- package/evals/compaction-resumption.eval.ts +0 -289
- package/evals/coordinator-behavior.eval.ts +0 -307
- package/evals/coordinator-session.eval.ts +0 -154
- package/evals/evalite.config.ts.bak +0 -15
- package/evals/example.eval.ts +0 -31
- package/evals/fixtures/compaction-cases.ts +0 -350
- package/evals/fixtures/compaction-prompt-cases.ts +0 -311
- package/evals/fixtures/coordinator-sessions.ts +0 -328
- package/evals/fixtures/decomposition-cases.ts +0 -105
- package/evals/lib/compaction-loader.test.ts +0 -248
- package/evals/lib/compaction-loader.ts +0 -320
- package/evals/lib/data-loader.evalite-test.ts +0 -289
- package/evals/lib/data-loader.test.ts +0 -345
- package/evals/lib/data-loader.ts +0 -281
- package/evals/lib/llm.ts +0 -115
- package/evals/scorers/compaction-prompt-scorers.ts +0 -145
- package/evals/scorers/compaction-scorers.ts +0 -305
- package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
- package/evals/scorers/coordinator-discipline.ts +0 -325
- package/evals/scorers/index.test.ts +0 -146
- package/evals/scorers/index.ts +0 -328
- package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
- package/evals/scorers/outcome-scorers.ts +0 -349
- package/evals/swarm-decomposition.eval.ts +0 -121
- package/examples/commands/swarm.md +0 -745
- package/examples/plugin-wrapper-template.ts +0 -2426
- package/examples/skills/hive-workflow/SKILL.md +0 -212
- package/examples/skills/skill-creator/SKILL.md +0 -223
- package/examples/skills/swarm-coordination/SKILL.md +0 -292
- package/global-skills/cli-builder/SKILL.md +0 -344
- package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
- package/global-skills/learning-systems/SKILL.md +0 -644
- package/global-skills/skill-creator/LICENSE.txt +0 -202
- package/global-skills/skill-creator/SKILL.md +0 -352
- package/global-skills/skill-creator/references/output-patterns.md +0 -82
- package/global-skills/skill-creator/references/workflows.md +0 -28
- package/global-skills/swarm-coordination/SKILL.md +0 -995
- package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
- package/global-skills/swarm-coordination/references/strategies.md +0 -138
- package/global-skills/system-design/SKILL.md +0 -213
- package/global-skills/testing-patterns/SKILL.md +0 -430
- package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
- package/opencode-swarm-plugin-0.30.7.tgz +0 -0
- package/opencode-swarm-plugin-0.31.0.tgz +0 -0
- package/scripts/cleanup-test-memories.ts +0 -346
- package/scripts/init-skill.ts +0 -222
- package/scripts/migrate-unknown-sessions.ts +0 -349
- package/scripts/validate-skill.ts +0 -204
- package/src/agent-mail.ts +0 -1724
- package/src/anti-patterns.test.ts +0 -1167
- package/src/anti-patterns.ts +0 -448
- package/src/compaction-capture.integration.test.ts +0 -257
- package/src/compaction-hook.test.ts +0 -838
- package/src/compaction-hook.ts +0 -1204
- package/src/compaction-observability.integration.test.ts +0 -139
- package/src/compaction-observability.test.ts +0 -187
- package/src/compaction-observability.ts +0 -324
- package/src/compaction-prompt-scorers.test.ts +0 -475
- package/src/compaction-prompt-scoring.ts +0 -300
- package/src/dashboard.test.ts +0 -611
- package/src/dashboard.ts +0 -462
- package/src/error-enrichment.test.ts +0 -403
- package/src/error-enrichment.ts +0 -219
- package/src/eval-capture.test.ts +0 -1015
- package/src/eval-capture.ts +0 -929
- package/src/eval-gates.test.ts +0 -306
- package/src/eval-gates.ts +0 -218
- package/src/eval-history.test.ts +0 -508
- package/src/eval-history.ts +0 -214
- package/src/eval-learning.test.ts +0 -378
- package/src/eval-learning.ts +0 -360
- package/src/eval-runner.test.ts +0 -223
- package/src/eval-runner.ts +0 -402
- package/src/export-tools.test.ts +0 -476
- package/src/export-tools.ts +0 -257
- package/src/hive.integration.test.ts +0 -2241
- package/src/hive.ts +0 -1628
- package/src/index.ts +0 -935
- package/src/learning.integration.test.ts +0 -1815
- package/src/learning.ts +0 -1079
- package/src/logger.test.ts +0 -189
- package/src/logger.ts +0 -135
- package/src/mandate-promotion.test.ts +0 -473
- package/src/mandate-promotion.ts +0 -239
- package/src/mandate-storage.integration.test.ts +0 -601
- package/src/mandate-storage.test.ts +0 -578
- package/src/mandate-storage.ts +0 -794
- package/src/mandates.ts +0 -540
- package/src/memory-tools.test.ts +0 -195
- package/src/memory-tools.ts +0 -344
- package/src/memory.integration.test.ts +0 -334
- package/src/memory.test.ts +0 -158
- package/src/memory.ts +0 -527
- package/src/model-selection.test.ts +0 -188
- package/src/model-selection.ts +0 -68
- package/src/observability-tools.test.ts +0 -359
- package/src/observability-tools.ts +0 -871
- package/src/output-guardrails.test.ts +0 -438
- package/src/output-guardrails.ts +0 -381
- package/src/pattern-maturity.test.ts +0 -1160
- package/src/pattern-maturity.ts +0 -525
- package/src/planning-guardrails.test.ts +0 -491
- package/src/planning-guardrails.ts +0 -438
- package/src/plugin.ts +0 -23
- package/src/post-compaction-tracker.test.ts +0 -251
- package/src/post-compaction-tracker.ts +0 -237
- package/src/query-tools.test.ts +0 -636
- package/src/query-tools.ts +0 -324
- package/src/rate-limiter.integration.test.ts +0 -466
- package/src/rate-limiter.ts +0 -774
- package/src/replay-tools.test.ts +0 -496
- package/src/replay-tools.ts +0 -240
- package/src/repo-crawl.integration.test.ts +0 -441
- package/src/repo-crawl.ts +0 -610
- package/src/schemas/cell-events.test.ts +0 -347
- package/src/schemas/cell-events.ts +0 -807
- package/src/schemas/cell.ts +0 -257
- package/src/schemas/evaluation.ts +0 -166
- package/src/schemas/index.test.ts +0 -199
- package/src/schemas/index.ts +0 -286
- package/src/schemas/mandate.ts +0 -232
- package/src/schemas/swarm-context.ts +0 -115
- package/src/schemas/task.ts +0 -161
- package/src/schemas/worker-handoff.test.ts +0 -302
- package/src/schemas/worker-handoff.ts +0 -131
- package/src/skills.integration.test.ts +0 -1192
- package/src/skills.test.ts +0 -643
- package/src/skills.ts +0 -1549
- package/src/storage.integration.test.ts +0 -341
- package/src/storage.ts +0 -884
- package/src/structured.integration.test.ts +0 -817
- package/src/structured.test.ts +0 -1046
- package/src/structured.ts +0 -762
- package/src/swarm-decompose.test.ts +0 -188
- package/src/swarm-decompose.ts +0 -1302
- package/src/swarm-deferred.integration.test.ts +0 -157
- package/src/swarm-deferred.test.ts +0 -38
- package/src/swarm-insights.test.ts +0 -214
- package/src/swarm-insights.ts +0 -459
- package/src/swarm-mail.integration.test.ts +0 -970
- package/src/swarm-mail.ts +0 -739
- package/src/swarm-orchestrate.integration.test.ts +0 -282
- package/src/swarm-orchestrate.test.ts +0 -548
- package/src/swarm-orchestrate.ts +0 -3084
- package/src/swarm-prompts.test.ts +0 -1270
- package/src/swarm-prompts.ts +0 -2077
- package/src/swarm-research.integration.test.ts +0 -701
- package/src/swarm-research.test.ts +0 -698
- package/src/swarm-research.ts +0 -472
- package/src/swarm-review.integration.test.ts +0 -285
- package/src/swarm-review.test.ts +0 -879
- package/src/swarm-review.ts +0 -709
- package/src/swarm-strategies.ts +0 -407
- package/src/swarm-worktree.test.ts +0 -501
- package/src/swarm-worktree.ts +0 -575
- package/src/swarm.integration.test.ts +0 -2377
- package/src/swarm.ts +0 -38
- package/src/tool-adapter.integration.test.ts +0 -1221
- package/src/tool-availability.ts +0 -461
- package/tsconfig.json +0 -28
|
@@ -1,701 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration tests for research phase
|
|
3
|
-
*
|
|
4
|
-
* Tests the full research workflow:
|
|
5
|
-
* - Tool discovery (discoverDocTools)
|
|
6
|
-
* - Lockfile parsing (getInstalledVersions)
|
|
7
|
-
* - Researcher prompt generation (formatResearcherPrompt, swarm_spawn_researcher)
|
|
8
|
-
* - Research orchestration (runResearchPhase, extractTechStack)
|
|
9
|
-
*
|
|
10
|
-
* Uses this repo as a real-world test fixture.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
14
|
-
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
15
|
-
import { tmpdir } from "node:os";
|
|
16
|
-
import { join } from "node:path";
|
|
17
|
-
import type { SwarmMailAdapter } from "swarm-mail";
|
|
18
|
-
import {
|
|
19
|
-
clearAdapterCache,
|
|
20
|
-
createInMemorySwarmMailLibSQL,
|
|
21
|
-
} from "swarm-mail";
|
|
22
|
-
import { extractTechStack, runResearchPhase } from "./swarm-orchestrate";
|
|
23
|
-
import {
|
|
24
|
-
formatResearcherPrompt,
|
|
25
|
-
swarm_spawn_researcher,
|
|
26
|
-
} from "./swarm-prompts";
|
|
27
|
-
import {
|
|
28
|
-
discoverDocTools,
|
|
29
|
-
getInstalledVersions,
|
|
30
|
-
swarm_discover_tools,
|
|
31
|
-
swarm_get_versions,
|
|
32
|
-
} from "./swarm-research";
|
|
33
|
-
|
|
34
|
-
describe("Tool discovery integration", () => {
|
|
35
|
-
test("discoverDocTools returns available tools", async () => {
|
|
36
|
-
const tools = await discoverDocTools();
|
|
37
|
-
|
|
38
|
-
// Should return a non-empty array
|
|
39
|
-
expect(tools.length).toBeGreaterThan(0);
|
|
40
|
-
|
|
41
|
-
// Check structure of returned tools
|
|
42
|
-
for (const tool of tools) {
|
|
43
|
-
expect(tool.name).toBeDefined();
|
|
44
|
-
expect(tool.type).toMatch(/^(skill|mcp|cli)$/);
|
|
45
|
-
expect(Array.isArray(tool.capabilities)).toBe(true);
|
|
46
|
-
expect(typeof tool.available).toBe("boolean");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Should include known tools
|
|
50
|
-
const toolNames = tools.map((t) => t.name);
|
|
51
|
-
expect(toolNames).toContain("next-devtools");
|
|
52
|
-
expect(toolNames).toContain("context7");
|
|
53
|
-
expect(toolNames).toContain("fetch");
|
|
54
|
-
expect(toolNames).toContain("pdf-brain");
|
|
55
|
-
expect(toolNames).toContain("semantic-memory");
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("swarm_discover_tools plugin tool returns JSON summary", async () => {
|
|
59
|
-
const result = await swarm_discover_tools.execute({});
|
|
60
|
-
const parsed = JSON.parse(result);
|
|
61
|
-
|
|
62
|
-
// Check summary structure
|
|
63
|
-
expect(parsed.tools).toBeDefined();
|
|
64
|
-
expect(parsed.summary).toBeDefined();
|
|
65
|
-
expect(parsed.summary.total).toBeGreaterThan(0);
|
|
66
|
-
expect(parsed.summary.available).toBeGreaterThanOrEqual(0);
|
|
67
|
-
expect(parsed.summary.by_type).toBeDefined();
|
|
68
|
-
|
|
69
|
-
// Check usage hint
|
|
70
|
-
expect(parsed.usage_hint).toBeDefined();
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe("Lockfile parsing integration", () => {
|
|
75
|
-
let testProjectPath: string;
|
|
76
|
-
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
// Create temp directory for test fixtures
|
|
79
|
-
testProjectPath = join(tmpdir(), `lockfile-test-${Date.now()}`);
|
|
80
|
-
mkdirSync(testProjectPath, { recursive: true });
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
afterEach(() => {
|
|
84
|
-
// Clean up
|
|
85
|
-
rmSync(testProjectPath, { recursive: true, force: true });
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test("getInstalledVersions reads from bun.lock fallback to package.json", async () => {
|
|
89
|
-
// Create a package.json (bun.lock is binary, can't easily mock)
|
|
90
|
-
const packageJson = {
|
|
91
|
-
dependencies: {
|
|
92
|
-
zod: "^3.22.4",
|
|
93
|
-
typescript: "^5.3.3",
|
|
94
|
-
},
|
|
95
|
-
devDependencies: {
|
|
96
|
-
"@types/node": "^20.0.0",
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
writeFileSync(
|
|
101
|
-
join(testProjectPath, "package.json"),
|
|
102
|
-
JSON.stringify(packageJson, null, 2),
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
// Query for specific packages
|
|
106
|
-
const versions = await getInstalledVersions(testProjectPath, [
|
|
107
|
-
"zod",
|
|
108
|
-
"typescript",
|
|
109
|
-
"@types/node",
|
|
110
|
-
]);
|
|
111
|
-
|
|
112
|
-
// Should return versions from package.json (since no npm/pnpm/yarn lockfile)
|
|
113
|
-
expect(versions.length).toBeGreaterThan(0);
|
|
114
|
-
|
|
115
|
-
// Check zod
|
|
116
|
-
const zodVersion = versions.find((v) => v.name === "zod");
|
|
117
|
-
expect(zodVersion).toBeDefined();
|
|
118
|
-
expect(zodVersion?.version).toBe("3.22.4");
|
|
119
|
-
expect(zodVersion?.source).toBe("package.json");
|
|
120
|
-
expect(zodVersion?.constraint).toBe("^3.22.4");
|
|
121
|
-
|
|
122
|
-
// Check typescript
|
|
123
|
-
const tsVersion = versions.find((v) => v.name === "typescript");
|
|
124
|
-
expect(tsVersion).toBeDefined();
|
|
125
|
-
expect(tsVersion?.version).toBe("5.3.3");
|
|
126
|
-
expect(tsVersion?.source).toBe("package.json");
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test("getInstalledVersions handles missing packages gracefully", async () => {
|
|
130
|
-
// Create minimal package.json
|
|
131
|
-
const packageJson = {
|
|
132
|
-
dependencies: {
|
|
133
|
-
zod: "^3.22.4",
|
|
134
|
-
},
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
writeFileSync(
|
|
138
|
-
join(testProjectPath, "package.json"),
|
|
139
|
-
JSON.stringify(packageJson, null, 2),
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
// Query for packages that don't exist
|
|
143
|
-
const versions = await getInstalledVersions(testProjectPath, [
|
|
144
|
-
"zod",
|
|
145
|
-
"nonexistent-package",
|
|
146
|
-
"another-missing",
|
|
147
|
-
]);
|
|
148
|
-
|
|
149
|
-
// Should only return zod
|
|
150
|
-
expect(versions.length).toBe(1);
|
|
151
|
-
expect(versions[0].name).toBe("zod");
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("getInstalledVersions returns empty array for no lockfile or package.json", async () => {
|
|
155
|
-
// Don't create any files - project has no dependencies
|
|
156
|
-
const versions = await getInstalledVersions(testProjectPath, [
|
|
157
|
-
"zod",
|
|
158
|
-
"typescript",
|
|
159
|
-
]);
|
|
160
|
-
|
|
161
|
-
// Should return empty array
|
|
162
|
-
expect(versions).toEqual([]);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test("swarm_get_versions plugin tool returns JSON summary", async () => {
|
|
166
|
-
// Create a package.json
|
|
167
|
-
const packageJson = {
|
|
168
|
-
dependencies: {
|
|
169
|
-
zod: "^3.22.4",
|
|
170
|
-
typescript: "^5.3.3",
|
|
171
|
-
},
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
writeFileSync(
|
|
175
|
-
join(testProjectPath, "package.json"),
|
|
176
|
-
JSON.stringify(packageJson, null, 2),
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
// Call plugin tool
|
|
180
|
-
const result = await swarm_get_versions.execute({
|
|
181
|
-
projectPath: testProjectPath,
|
|
182
|
-
packages: ["zod", "typescript", "missing-pkg"],
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
const parsed = JSON.parse(result);
|
|
186
|
-
|
|
187
|
-
// Check summary
|
|
188
|
-
expect(parsed.versions).toBeDefined();
|
|
189
|
-
expect(parsed.summary).toBeDefined();
|
|
190
|
-
expect(parsed.summary.found).toBe(2);
|
|
191
|
-
expect(parsed.summary.requested).toBe(3);
|
|
192
|
-
expect(parsed.summary.missing).toEqual(["missing-pkg"]);
|
|
193
|
-
expect(parsed.summary.sources.package_json).toBe(2);
|
|
194
|
-
|
|
195
|
-
// Check usage hint
|
|
196
|
-
expect(parsed.usage_hint).toBeDefined();
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
test("reads from real bun.lock in this repo", async () => {
|
|
200
|
-
// Use the plugin package directory which has the dependencies
|
|
201
|
-
const pluginDir = join(process.cwd(), "packages/opencode-swarm-plugin");
|
|
202
|
-
|
|
203
|
-
// Query for packages we know exist in the plugin
|
|
204
|
-
const versions = await getInstalledVersions(pluginDir, [
|
|
205
|
-
"zod",
|
|
206
|
-
"effect",
|
|
207
|
-
"@opencode-ai/plugin",
|
|
208
|
-
]);
|
|
209
|
-
|
|
210
|
-
// Should find at least some versions from package.json
|
|
211
|
-
expect(versions.length).toBeGreaterThan(0);
|
|
212
|
-
|
|
213
|
-
// Check zod (we know it's in dependencies)
|
|
214
|
-
const zodVersion = versions.find((v) => v.name === "zod");
|
|
215
|
-
expect(zodVersion).toBeDefined();
|
|
216
|
-
expect(zodVersion?.version).toMatch(/^\d+\.\d+\.\d+/); // Semver format
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
describe("Researcher prompt generation", () => {
|
|
221
|
-
test("formatResearcherPrompt generates valid prompt with tech stack", () => {
|
|
222
|
-
const prompt = formatResearcherPrompt({
|
|
223
|
-
research_id: "test-research-123",
|
|
224
|
-
epic_id: "epic-456",
|
|
225
|
-
tech_stack: ["zod", "typescript", "next.js"],
|
|
226
|
-
project_path: "/test/project",
|
|
227
|
-
check_upgrades: false,
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
// Should contain all parameters
|
|
231
|
-
expect(prompt).toContain("test-research-123");
|
|
232
|
-
expect(prompt).toContain("epic-456");
|
|
233
|
-
expect(prompt).toContain("zod");
|
|
234
|
-
expect(prompt).toContain("typescript");
|
|
235
|
-
expect(prompt).toContain("next.js");
|
|
236
|
-
expect(prompt).toContain("/test/project");
|
|
237
|
-
|
|
238
|
-
// Should be in DEFAULT MODE (not UPGRADE COMPARISON MODE)
|
|
239
|
-
expect(prompt).toContain("DEFAULT MODE");
|
|
240
|
-
expect(prompt).not.toContain("UPGRADE COMPARISON MODE");
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
test("formatResearcherPrompt includes upgrade mode when check_upgrades=true", () => {
|
|
244
|
-
const prompt = formatResearcherPrompt({
|
|
245
|
-
research_id: "test-research-123",
|
|
246
|
-
epic_id: "epic-456",
|
|
247
|
-
tech_stack: ["zod"],
|
|
248
|
-
project_path: "/test/project",
|
|
249
|
-
check_upgrades: true,
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
// Should be in UPGRADE COMPARISON MODE
|
|
253
|
-
expect(prompt).toContain("UPGRADE COMPARISON MODE");
|
|
254
|
-
expect(prompt).toContain("BOTH installed AND latest versions");
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
test("swarm_spawn_researcher returns JSON with prompt and metadata", async () => {
|
|
258
|
-
const result = await swarm_spawn_researcher.execute({
|
|
259
|
-
research_id: "research-789",
|
|
260
|
-
epic_id: "epic-101",
|
|
261
|
-
tech_stack: ["zod", "typescript"],
|
|
262
|
-
project_path: "/test/project",
|
|
263
|
-
check_upgrades: false,
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
const parsed = JSON.parse(result);
|
|
267
|
-
|
|
268
|
-
// Check structure
|
|
269
|
-
expect(parsed.prompt).toBeDefined();
|
|
270
|
-
expect(parsed.research_id).toBe("research-789");
|
|
271
|
-
expect(parsed.epic_id).toBe("epic-101");
|
|
272
|
-
expect(parsed.tech_stack).toEqual(["zod", "typescript"]);
|
|
273
|
-
expect(parsed.project_path).toBe("/test/project");
|
|
274
|
-
expect(parsed.check_upgrades).toBe(false);
|
|
275
|
-
expect(parsed.subagent_type).toBe("swarm/researcher");
|
|
276
|
-
|
|
277
|
-
// Check expected output schema
|
|
278
|
-
expect(parsed.expected_output).toBeDefined();
|
|
279
|
-
expect(parsed.expected_output.technologies).toBeDefined();
|
|
280
|
-
expect(parsed.expected_output.summary).toBeDefined();
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
describe("Research orchestration integration", () => {
|
|
285
|
-
let testProjectPath: string;
|
|
286
|
-
let swarmMail: SwarmMailAdapter;
|
|
287
|
-
|
|
288
|
-
beforeEach(async () => {
|
|
289
|
-
// Create temp project directory
|
|
290
|
-
testProjectPath = join(tmpdir(), `research-test-${Date.now()}`);
|
|
291
|
-
mkdirSync(testProjectPath, { recursive: true });
|
|
292
|
-
|
|
293
|
-
// Initialize swarm-mail for this project
|
|
294
|
-
swarmMail = await createInMemorySwarmMailLibSQL(testProjectPath);
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
afterEach(async () => {
|
|
298
|
-
// Clean up
|
|
299
|
-
await swarmMail.close();
|
|
300
|
-
clearAdapterCache();
|
|
301
|
-
rmSync(testProjectPath, { recursive: true, force: true });
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
test("extractTechStack identifies technologies from task description", () => {
|
|
305
|
-
const task =
|
|
306
|
-
"Add Zod validation to Next.js API routes with TypeScript types";
|
|
307
|
-
const techStack = extractTechStack(task);
|
|
308
|
-
|
|
309
|
-
// Should extract known technologies
|
|
310
|
-
expect(techStack).toContain("zod");
|
|
311
|
-
expect(techStack).toContain("next"); // Pattern matches "next" (not "next.js")
|
|
312
|
-
expect(techStack).toContain("typescript");
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
test("extractTechStack handles case-insensitive matches", () => {
|
|
316
|
-
const task = "Use REACT and NextJS with TYPESCRIPT";
|
|
317
|
-
const techStack = extractTechStack(task);
|
|
318
|
-
|
|
319
|
-
// Should normalize to lowercase
|
|
320
|
-
expect(techStack).toContain("react");
|
|
321
|
-
expect(techStack).toContain("next"); // Pattern matches "next"
|
|
322
|
-
expect(techStack).toContain("typescript");
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
test("extractTechStack returns empty array for unknown technologies", () => {
|
|
326
|
-
const task = "Implement something with FooBarBaz library";
|
|
327
|
-
const techStack = extractTechStack(task);
|
|
328
|
-
|
|
329
|
-
// Should return empty array (no known tech)
|
|
330
|
-
expect(techStack).toEqual([]);
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
test("runResearchPhase returns tech stack and research summaries", async () => {
|
|
334
|
-
// Create a package.json with dependencies
|
|
335
|
-
const packageJson = {
|
|
336
|
-
dependencies: {
|
|
337
|
-
zod: "^3.22.4",
|
|
338
|
-
typescript: "^5.3.3",
|
|
339
|
-
},
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
writeFileSync(
|
|
343
|
-
join(testProjectPath, "package.json"),
|
|
344
|
-
JSON.stringify(packageJson, null, 2),
|
|
345
|
-
);
|
|
346
|
-
|
|
347
|
-
// Run research phase
|
|
348
|
-
const result = await runResearchPhase(
|
|
349
|
-
"Add Zod validation to TypeScript API",
|
|
350
|
-
testProjectPath,
|
|
351
|
-
);
|
|
352
|
-
|
|
353
|
-
// Should extract tech stack
|
|
354
|
-
expect(result.tech_stack).toBeDefined();
|
|
355
|
-
expect(result.tech_stack.length).toBeGreaterThan(0);
|
|
356
|
-
expect(result.tech_stack).toContain("zod");
|
|
357
|
-
expect(result.tech_stack).toContain("typescript");
|
|
358
|
-
|
|
359
|
-
// Should have summaries object (even if empty for now)
|
|
360
|
-
expect(result.summaries).toBeDefined();
|
|
361
|
-
expect(typeof result.summaries).toBe("object");
|
|
362
|
-
|
|
363
|
-
// Should have memory_ids array (even if empty for now)
|
|
364
|
-
expect(result.memory_ids).toBeDefined();
|
|
365
|
-
expect(Array.isArray(result.memory_ids)).toBe(true);
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
test("runResearchPhase handles no package.json gracefully", async () => {
|
|
369
|
-
// Don't create package.json - project has no dependencies
|
|
370
|
-
|
|
371
|
-
const result = await runResearchPhase(
|
|
372
|
-
"Add Zod validation",
|
|
373
|
-
testProjectPath,
|
|
374
|
-
);
|
|
375
|
-
|
|
376
|
-
// Should still extract tech stack from description
|
|
377
|
-
expect(result.tech_stack).toBeDefined();
|
|
378
|
-
expect(result.tech_stack).toContain("zod");
|
|
379
|
-
|
|
380
|
-
// Should have empty summaries (no research yet)
|
|
381
|
-
expect(result.summaries).toEqual({});
|
|
382
|
-
expect(result.memory_ids).toEqual([]);
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
describe("End-to-end research workflow", () => {
|
|
387
|
-
let testProjectPath: string;
|
|
388
|
-
let swarmMail: SwarmMailAdapter;
|
|
389
|
-
|
|
390
|
-
beforeEach(async () => {
|
|
391
|
-
// Create temp project directory
|
|
392
|
-
testProjectPath = join(tmpdir(), `e2e-research-${Date.now()}`);
|
|
393
|
-
mkdirSync(testProjectPath, { recursive: true });
|
|
394
|
-
|
|
395
|
-
// Create a realistic package.json
|
|
396
|
-
const packageJson = {
|
|
397
|
-
name: "test-project",
|
|
398
|
-
version: "1.0.0",
|
|
399
|
-
dependencies: {
|
|
400
|
-
zod: "^3.22.4",
|
|
401
|
-
"@opencode-ai/plugin": "^0.1.0",
|
|
402
|
-
},
|
|
403
|
-
devDependencies: {
|
|
404
|
-
typescript: "^5.3.3",
|
|
405
|
-
"@types/node": "^20.0.0",
|
|
406
|
-
},
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
writeFileSync(
|
|
410
|
-
join(testProjectPath, "package.json"),
|
|
411
|
-
JSON.stringify(packageJson, null, 2),
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
// Initialize swarm-mail
|
|
415
|
-
swarmMail = await createInMemorySwarmMailLibSQL(testProjectPath);
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
afterEach(async () => {
|
|
419
|
-
await swarmMail.close();
|
|
420
|
-
clearAdapterCache();
|
|
421
|
-
rmSync(testProjectPath, { recursive: true, force: true });
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
test("full research phase workflow", async () => {
|
|
425
|
-
// Step 1: Extract tech stack from task
|
|
426
|
-
const task =
|
|
427
|
-
"Add Zod validation to OpenCode plugin with TypeScript types";
|
|
428
|
-
const techStack = extractTechStack(task);
|
|
429
|
-
|
|
430
|
-
expect(techStack).toContain("zod");
|
|
431
|
-
expect(techStack).toContain("typescript");
|
|
432
|
-
|
|
433
|
-
// Step 2: Discover available doc tools
|
|
434
|
-
const tools = await discoverDocTools();
|
|
435
|
-
expect(tools.length).toBeGreaterThan(0);
|
|
436
|
-
|
|
437
|
-
// Step 3: Get installed versions
|
|
438
|
-
const versions = await getInstalledVersions(testProjectPath, techStack);
|
|
439
|
-
expect(versions.length).toBeGreaterThan(0);
|
|
440
|
-
|
|
441
|
-
const zodVersion = versions.find((v) => v.name === "zod");
|
|
442
|
-
expect(zodVersion?.version).toBe("3.22.4");
|
|
443
|
-
expect(zodVersion?.source).toBe("package.json");
|
|
444
|
-
|
|
445
|
-
// Step 4: Generate researcher prompt
|
|
446
|
-
const prompt = formatResearcherPrompt({
|
|
447
|
-
research_id: "e2e-research",
|
|
448
|
-
epic_id: "epic-test",
|
|
449
|
-
tech_stack: techStack,
|
|
450
|
-
project_path: testProjectPath,
|
|
451
|
-
check_upgrades: false,
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
// Prompt should contain all context
|
|
455
|
-
expect(prompt).toContain("e2e-research");
|
|
456
|
-
expect(prompt).toContain("zod");
|
|
457
|
-
expect(prompt).toContain("typescript");
|
|
458
|
-
expect(prompt).toContain(testProjectPath);
|
|
459
|
-
|
|
460
|
-
// Step 5: Spawn researcher (get JSON for Task tool)
|
|
461
|
-
const spawnResult = await swarm_spawn_researcher.execute({
|
|
462
|
-
research_id: "e2e-research",
|
|
463
|
-
epic_id: "epic-test",
|
|
464
|
-
tech_stack: techStack,
|
|
465
|
-
project_path: testProjectPath,
|
|
466
|
-
check_upgrades: false,
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
const spawnData = JSON.parse(spawnResult);
|
|
470
|
-
expect(spawnData.prompt).toBeDefined();
|
|
471
|
-
expect(spawnData.subagent_type).toBe("swarm/researcher");
|
|
472
|
-
expect(spawnData.tech_stack).toEqual(techStack);
|
|
473
|
-
|
|
474
|
-
// The spawned prompt should be ready for Task tool
|
|
475
|
-
expect(spawnData.prompt).toContain("swarmmail_init");
|
|
476
|
-
expect(spawnData.prompt).toContain("semantic-memory_store");
|
|
477
|
-
expect(spawnData.prompt).toContain(testProjectPath);
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
test("research phase orchestration with runResearchPhase", async () => {
|
|
481
|
-
const task = "Build Next.js app with Zod validation and TypeScript";
|
|
482
|
-
|
|
483
|
-
// Run full research phase
|
|
484
|
-
const result = await runResearchPhase(task, testProjectPath);
|
|
485
|
-
|
|
486
|
-
// Should extract tech stack (normalized names)
|
|
487
|
-
expect(result.tech_stack).toContain("zod");
|
|
488
|
-
expect(result.tech_stack).toContain("typescript");
|
|
489
|
-
expect(result.tech_stack).toContain("next"); // Normalized from "Next.js"
|
|
490
|
-
|
|
491
|
-
// Should have research result structure (GREEN phase - empty for now)
|
|
492
|
-
expect(result.summaries).toBeDefined();
|
|
493
|
-
expect(result.memory_ids).toBeDefined();
|
|
494
|
-
expect(Array.isArray(result.memory_ids)).toBe(true);
|
|
495
|
-
});
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
describe("Research spawn instructions (NEW)", () => {
|
|
499
|
-
let testProjectPath: string;
|
|
500
|
-
|
|
501
|
-
beforeEach(() => {
|
|
502
|
-
testProjectPath = join(tmpdir(), `spawn-test-${Date.now()}`);
|
|
503
|
-
mkdirSync(testProjectPath, { recursive: true });
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
afterEach(() => {
|
|
507
|
-
rmSync(testProjectPath, { recursive: true, force: true });
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
test("runResearchPhase generates spawn instructions for each technology", async () => {
|
|
511
|
-
// Create package.json with dependencies
|
|
512
|
-
const packageJson = {
|
|
513
|
-
dependencies: {
|
|
514
|
-
zod: "^3.22.4",
|
|
515
|
-
typescript: "^5.3.3",
|
|
516
|
-
},
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
writeFileSync(
|
|
520
|
-
join(testProjectPath, "package.json"),
|
|
521
|
-
JSON.stringify(packageJson, null, 2),
|
|
522
|
-
);
|
|
523
|
-
|
|
524
|
-
// Run research phase
|
|
525
|
-
const result = await runResearchPhase(
|
|
526
|
-
"Add Zod validation to TypeScript API",
|
|
527
|
-
testProjectPath,
|
|
528
|
-
);
|
|
529
|
-
|
|
530
|
-
// Should have spawn_instructions array
|
|
531
|
-
expect(result.spawn_instructions).toBeDefined();
|
|
532
|
-
expect(Array.isArray(result.spawn_instructions)).toBe(true);
|
|
533
|
-
|
|
534
|
-
// Should have one instruction per technology
|
|
535
|
-
expect(result.spawn_instructions.length).toBe(result.tech_stack.length);
|
|
536
|
-
|
|
537
|
-
// Each instruction should have required fields
|
|
538
|
-
for (const instruction of result.spawn_instructions) {
|
|
539
|
-
expect(instruction.research_id).toBeDefined();
|
|
540
|
-
expect(instruction.research_id).toMatch(/^research-/); // Should start with "research-"
|
|
541
|
-
expect(instruction.tech).toBeDefined();
|
|
542
|
-
expect(result.tech_stack).toContain(instruction.tech); // Tech should be from tech_stack
|
|
543
|
-
expect(instruction.prompt).toBeDefined();
|
|
544
|
-
expect(typeof instruction.prompt).toBe("string");
|
|
545
|
-
expect(instruction.prompt.length).toBeGreaterThan(0);
|
|
546
|
-
expect(instruction.subagent_type).toBe("swarm/researcher");
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
test("runResearchPhase prompts contain correct technology", async () => {
|
|
551
|
-
const packageJson = {
|
|
552
|
-
dependencies: {
|
|
553
|
-
zod: "^3.22.4",
|
|
554
|
-
},
|
|
555
|
-
};
|
|
556
|
-
|
|
557
|
-
writeFileSync(
|
|
558
|
-
join(testProjectPath, "package.json"),
|
|
559
|
-
JSON.stringify(packageJson, null, 2),
|
|
560
|
-
);
|
|
561
|
-
|
|
562
|
-
const result = await runResearchPhase("Use Zod", testProjectPath);
|
|
563
|
-
|
|
564
|
-
// Should have exactly one spawn instruction (one tech)
|
|
565
|
-
expect(result.spawn_instructions.length).toBe(1);
|
|
566
|
-
|
|
567
|
-
const instruction = result.spawn_instructions[0];
|
|
568
|
-
expect(instruction.tech).toBe("zod");
|
|
569
|
-
expect(instruction.prompt).toContain("zod");
|
|
570
|
-
expect(instruction.prompt).toContain(testProjectPath);
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
test("runResearchPhase with multiple technologies generates multiple instructions", async () => {
|
|
574
|
-
const packageJson = {
|
|
575
|
-
dependencies: {
|
|
576
|
-
zod: "^3.22.4",
|
|
577
|
-
typescript: "^5.3.3",
|
|
578
|
-
react: "^18.2.0",
|
|
579
|
-
},
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
writeFileSync(
|
|
583
|
-
join(testProjectPath, "package.json"),
|
|
584
|
-
JSON.stringify(packageJson, null, 2),
|
|
585
|
-
);
|
|
586
|
-
|
|
587
|
-
const result = await runResearchPhase(
|
|
588
|
-
"Build React app with Zod and TypeScript",
|
|
589
|
-
testProjectPath,
|
|
590
|
-
);
|
|
591
|
-
|
|
592
|
-
// Should extract 3 technologies
|
|
593
|
-
expect(result.tech_stack.length).toBe(3);
|
|
594
|
-
|
|
595
|
-
// Should have 3 spawn instructions
|
|
596
|
-
expect(result.spawn_instructions.length).toBe(3);
|
|
597
|
-
|
|
598
|
-
// Each tech should have one instruction
|
|
599
|
-
const techs = result.spawn_instructions.map((i) => i.tech);
|
|
600
|
-
expect(techs).toContain("zod");
|
|
601
|
-
expect(techs).toContain("typescript");
|
|
602
|
-
expect(techs).toContain("react");
|
|
603
|
-
|
|
604
|
-
// Research IDs should be unique
|
|
605
|
-
const researchIds = result.spawn_instructions.map((i) => i.research_id);
|
|
606
|
-
const uniqueIds = new Set(researchIds);
|
|
607
|
-
expect(uniqueIds.size).toBe(researchIds.length);
|
|
608
|
-
});
|
|
609
|
-
|
|
610
|
-
test("runResearchPhase with empty tech_stack returns empty spawn_instructions", async () => {
|
|
611
|
-
// Don't create package.json - no dependencies
|
|
612
|
-
|
|
613
|
-
const result = await runResearchPhase(
|
|
614
|
-
"Implement something with FooBarBaz",
|
|
615
|
-
testProjectPath,
|
|
616
|
-
);
|
|
617
|
-
|
|
618
|
-
// Should have empty tech_stack (no known technologies)
|
|
619
|
-
expect(result.tech_stack).toEqual([]);
|
|
620
|
-
|
|
621
|
-
// Should have empty spawn_instructions
|
|
622
|
-
expect(result.spawn_instructions).toEqual([]);
|
|
623
|
-
|
|
624
|
-
// Other fields should be empty
|
|
625
|
-
expect(result.summaries).toEqual({});
|
|
626
|
-
expect(result.memory_ids).toEqual([]);
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
test("spawn instruction prompts include swarmmail_init", async () => {
|
|
630
|
-
const packageJson = {
|
|
631
|
-
dependencies: {
|
|
632
|
-
zod: "^3.22.4",
|
|
633
|
-
},
|
|
634
|
-
};
|
|
635
|
-
|
|
636
|
-
writeFileSync(
|
|
637
|
-
join(testProjectPath, "package.json"),
|
|
638
|
-
JSON.stringify(packageJson, null, 2),
|
|
639
|
-
);
|
|
640
|
-
|
|
641
|
-
const result = await runResearchPhase("Use Zod", testProjectPath);
|
|
642
|
-
|
|
643
|
-
// Prompt should include swarmmail_init (researcher workers need this)
|
|
644
|
-
const instruction = result.spawn_instructions[0];
|
|
645
|
-
expect(instruction.prompt).toContain("swarmmail_init");
|
|
646
|
-
expect(instruction.prompt).toContain("semantic-memory_store");
|
|
647
|
-
});
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
describe("Real-world fixture: this repo", () => {
|
|
651
|
-
test("discovers tools and versions from actual repo", async () => {
|
|
652
|
-
// Use the plugin package directory, not monorepo root
|
|
653
|
-
const pluginDir = join(process.cwd(), "packages/opencode-swarm-plugin");
|
|
654
|
-
|
|
655
|
-
// Step 1: Tool discovery
|
|
656
|
-
const tools = await discoverDocTools();
|
|
657
|
-
expect(tools.length).toBeGreaterThan(0);
|
|
658
|
-
|
|
659
|
-
// Step 2: Version detection for packages we know exist in the plugin
|
|
660
|
-
const versions = await getInstalledVersions(pluginDir, [
|
|
661
|
-
"zod",
|
|
662
|
-
"@opencode-ai/plugin",
|
|
663
|
-
"effect",
|
|
664
|
-
]);
|
|
665
|
-
|
|
666
|
-
// Should find at least some packages (from plugin's package.json)
|
|
667
|
-
expect(versions.length).toBeGreaterThan(0);
|
|
668
|
-
|
|
669
|
-
// Zod should be found (it's in dependencies)
|
|
670
|
-
const zodVersion = versions.find((v) => v.name === "zod");
|
|
671
|
-
expect(zodVersion).toBeDefined();
|
|
672
|
-
|
|
673
|
-
// Effect should be found (it's in dependencies)
|
|
674
|
-
const effectVersion = versions.find((v) => v.name === "effect");
|
|
675
|
-
expect(effectVersion).toBeDefined();
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
test("research phase with real task on this repo", async () => {
|
|
679
|
-
// Use the plugin package directory, not monorepo root
|
|
680
|
-
const pluginDir = join(process.cwd(), "packages/opencode-swarm-plugin");
|
|
681
|
-
const task =
|
|
682
|
-
"Add Zod validation to swarm coordination with TypeScript types";
|
|
683
|
-
|
|
684
|
-
// Run research phase on actual repo
|
|
685
|
-
const result = await runResearchPhase(task, pluginDir);
|
|
686
|
-
|
|
687
|
-
// Should extract tech stack
|
|
688
|
-
expect(result.tech_stack).toContain("zod");
|
|
689
|
-
expect(result.tech_stack).toContain("typescript");
|
|
690
|
-
|
|
691
|
-
// Should have research result structure
|
|
692
|
-
expect(result.summaries).toBeDefined();
|
|
693
|
-
expect(result.memory_ids).toBeDefined();
|
|
694
|
-
expect(Array.isArray(result.memory_ids)).toBe(true);
|
|
695
|
-
|
|
696
|
-
// NEW: Should have spawn_instructions
|
|
697
|
-
expect(result.spawn_instructions).toBeDefined();
|
|
698
|
-
expect(Array.isArray(result.spawn_instructions)).toBe(true);
|
|
699
|
-
expect(result.spawn_instructions.length).toBeGreaterThan(0);
|
|
700
|
-
});
|
|
701
|
-
});
|