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.
- package/bin/swarm.serve.test.ts +6 -4
- package/bin/swarm.ts +18 -12
- package/dist/compaction-prompt-scoring.js +139 -0
- package/dist/eval-capture.js +12811 -0
- package/dist/hive.d.ts.map +1 -1
- package/dist/hive.js +14834 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7743 -62593
- package/dist/plugin.js +24052 -78907
- package/dist/swarm-orchestrate.d.ts.map +1 -1
- package/dist/swarm-prompts.d.ts.map +1 -1
- package/dist/swarm-prompts.js +39407 -0
- package/dist/swarm-review.d.ts.map +1 -1
- package/dist/swarm-validation.d.ts +127 -0
- package/dist/swarm-validation.d.ts.map +1 -0
- package/dist/validators/index.d.ts +7 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/schema-validator.d.ts +58 -0
- package/dist/validators/schema-validator.d.ts.map +1 -0
- 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 -2286
- 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/ADR-010-cass-inhousing.md +0 -1215
- 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/cass-baseline.ts +0 -217
- 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 -2515
- 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/contributor-tools.test.ts +0 -133
- package/src/contributor-tools.ts +0 -201
- 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 -940
- 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/sessions/agent-discovery.test.ts +0 -137
- package/src/sessions/agent-discovery.ts +0 -112
- package/src/sessions/index.ts +0 -15
- 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
package/src/swarm-research.ts
DELETED
|
@@ -1,472 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Swarm Research Module - Tool discovery for documentation researchers
|
|
3
|
-
*
|
|
4
|
-
* Provides runtime detection of available documentation tools:
|
|
5
|
-
* - Skills (via skills_list)
|
|
6
|
-
* - MCP servers (next-devtools, context7, fetch, pdf-brain)
|
|
7
|
-
* - CLI tools (semantic-memory via ollama)
|
|
8
|
-
*
|
|
9
|
-
* Researchers use this to discover HOW to fetch docs.
|
|
10
|
-
* Coordinators provide WHAT to research (tech stack).
|
|
11
|
-
*
|
|
12
|
-
* @module swarm-research
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { tool } from "@opencode-ai/plugin";
|
|
16
|
-
import type { ToolName } from "./tool-availability";
|
|
17
|
-
import { isToolAvailable } from "./tool-availability";
|
|
18
|
-
import { existsSync } from "node:fs";
|
|
19
|
-
import { readFile } from "node:fs/promises";
|
|
20
|
-
import { join } from "node:path";
|
|
21
|
-
import { parse as parseYaml } from "yaml";
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Version information for an installed package
|
|
25
|
-
*/
|
|
26
|
-
export interface VersionInfo {
|
|
27
|
-
/** Package name */
|
|
28
|
-
name: string;
|
|
29
|
-
/** Installed version (semver) */
|
|
30
|
-
version: string;
|
|
31
|
-
/** Where version was discovered */
|
|
32
|
-
source: "lockfile" | "package.json";
|
|
33
|
-
/** Original constraint from package.json (e.g., "^1.2.3") */
|
|
34
|
-
constraint?: string;
|
|
35
|
-
/** Latest version from npm registry (only if checkUpgrades=true) */
|
|
36
|
-
latest?: string;
|
|
37
|
-
/** Whether an update is available (version !== latest) */
|
|
38
|
-
updateAvailable?: boolean;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Discovered tool with capabilities
|
|
43
|
-
*/
|
|
44
|
-
export interface DiscoveredTool {
|
|
45
|
-
/** Tool name */
|
|
46
|
-
name: string;
|
|
47
|
-
/** Tool type: skill, MCP server, or CLI */
|
|
48
|
-
type: "skill" | "mcp" | "cli";
|
|
49
|
-
/** What this tool can do */
|
|
50
|
-
capabilities: string[];
|
|
51
|
-
/** Whether tool is available in this environment */
|
|
52
|
-
available: boolean;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Tool definitions with their capabilities
|
|
57
|
-
*/
|
|
58
|
-
const TOOL_DEFINITIONS: Omit<DiscoveredTool, "available">[] = [
|
|
59
|
-
{
|
|
60
|
-
name: "next-devtools",
|
|
61
|
-
type: "mcp",
|
|
62
|
-
capabilities: ["nextjs-docs", "version-lookup", "api-reference"],
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
name: "context7",
|
|
66
|
-
type: "mcp",
|
|
67
|
-
capabilities: ["library-docs", "api-reference", "search"],
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
name: "fetch",
|
|
71
|
-
type: "mcp",
|
|
72
|
-
capabilities: ["http-fetch", "markdown-conversion"],
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
name: "pdf-brain",
|
|
76
|
-
type: "mcp",
|
|
77
|
-
capabilities: ["knowledge-base-search", "internal-docs"],
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
name: "semantic-memory",
|
|
81
|
-
type: "cli",
|
|
82
|
-
capabilities: ["storage", "semantic-search", "persistence"],
|
|
83
|
-
},
|
|
84
|
-
];
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Strip semver constraint from version string
|
|
88
|
-
* Examples: "^3.22.4" → "3.22.4", "~1.2.3" → "1.2.3"
|
|
89
|
-
*/
|
|
90
|
-
function stripSemverConstraint(versionStr: string): string | undefined {
|
|
91
|
-
// Match semver version pattern (X.Y.Z with optional pre-release/build)
|
|
92
|
-
const match = versionStr.match(/(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?(?:\+[a-zA-Z0-9.-]+)?)/);
|
|
93
|
-
return match?.[1];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Fetch latest version of a package from npm registry
|
|
98
|
-
*
|
|
99
|
-
* Uses npm registry API: https://registry.npmjs.org/{package}/latest
|
|
100
|
-
*
|
|
101
|
-
* @param packageName - Package name (supports scoped packages like @types/node)
|
|
102
|
-
* @returns Latest version string, or undefined if fetch fails
|
|
103
|
-
*/
|
|
104
|
-
export async function getLatestVersion(
|
|
105
|
-
packageName: string,
|
|
106
|
-
): Promise<string | undefined> {
|
|
107
|
-
try {
|
|
108
|
-
const url = `https://registry.npmjs.org/${packageName}/latest`;
|
|
109
|
-
const response = await fetch(url);
|
|
110
|
-
|
|
111
|
-
if (!response.ok) {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const data = await response.json() as { version?: string };
|
|
116
|
-
return data.version;
|
|
117
|
-
} catch {
|
|
118
|
-
// Network error, invalid package name, etc.
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Parse npm package-lock.json
|
|
125
|
-
*/
|
|
126
|
-
async function parseNpmLockfile(
|
|
127
|
-
lockfilePath: string,
|
|
128
|
-
packages: string[],
|
|
129
|
-
): Promise<VersionInfo[]> {
|
|
130
|
-
try {
|
|
131
|
-
const content = await readFile(lockfilePath, "utf-8");
|
|
132
|
-
const lockfile = JSON.parse(content);
|
|
133
|
-
const versions: VersionInfo[] = [];
|
|
134
|
-
|
|
135
|
-
for (const pkg of packages) {
|
|
136
|
-
// npm v2/v3 format: packages."node_modules/<name>"
|
|
137
|
-
const nodeModulesKey = `node_modules/${pkg}`;
|
|
138
|
-
const pkgData = lockfile.packages?.[nodeModulesKey];
|
|
139
|
-
|
|
140
|
-
if (pkgData?.version) {
|
|
141
|
-
versions.push({
|
|
142
|
-
name: pkg,
|
|
143
|
-
version: pkgData.version,
|
|
144
|
-
source: "lockfile",
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return versions;
|
|
150
|
-
} catch {
|
|
151
|
-
return [];
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Parse pnpm pnpm-lock.yaml
|
|
157
|
-
*/
|
|
158
|
-
async function parsePnpmLockfile(
|
|
159
|
-
lockfilePath: string,
|
|
160
|
-
packages: string[],
|
|
161
|
-
): Promise<VersionInfo[]> {
|
|
162
|
-
try {
|
|
163
|
-
const content = await readFile(lockfilePath, "utf-8");
|
|
164
|
-
const lockfile = parseYaml(content);
|
|
165
|
-
const versions: VersionInfo[] = [];
|
|
166
|
-
|
|
167
|
-
for (const pkg of packages) {
|
|
168
|
-
// pnpm format: dependencies.pkg.version
|
|
169
|
-
const version = lockfile.dependencies?.[pkg]?.version;
|
|
170
|
-
|
|
171
|
-
if (version) {
|
|
172
|
-
versions.push({
|
|
173
|
-
name: pkg,
|
|
174
|
-
version,
|
|
175
|
-
source: "lockfile",
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return versions;
|
|
181
|
-
} catch {
|
|
182
|
-
return [];
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Parse yarn yarn.lock
|
|
188
|
-
*/
|
|
189
|
-
async function parseYarnLockfile(
|
|
190
|
-
lockfilePath: string,
|
|
191
|
-
packages: string[],
|
|
192
|
-
): Promise<VersionInfo[]> {
|
|
193
|
-
try {
|
|
194
|
-
const content = await readFile(lockfilePath, "utf-8");
|
|
195
|
-
const versions: VersionInfo[] = [];
|
|
196
|
-
|
|
197
|
-
for (const pkg of packages) {
|
|
198
|
-
// yarn format: "pkg@^version:\n version "X.Y.Z""
|
|
199
|
-
const pattern = new RegExp(`${pkg}@[^:]+:\\s+version "([^"]+)"`, "m");
|
|
200
|
-
const match = content.match(pattern);
|
|
201
|
-
|
|
202
|
-
if (match?.[1]) {
|
|
203
|
-
versions.push({
|
|
204
|
-
name: pkg,
|
|
205
|
-
version: match[1],
|
|
206
|
-
source: "lockfile",
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return versions;
|
|
212
|
-
} catch {
|
|
213
|
-
return [];
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Parse package.json as fallback
|
|
219
|
-
*/
|
|
220
|
-
async function parsePackageJson(
|
|
221
|
-
packageJsonPath: string,
|
|
222
|
-
packages: string[],
|
|
223
|
-
): Promise<VersionInfo[]> {
|
|
224
|
-
try {
|
|
225
|
-
const content = await readFile(packageJsonPath, "utf-8");
|
|
226
|
-
const packageJson = JSON.parse(content);
|
|
227
|
-
const versions: VersionInfo[] = [];
|
|
228
|
-
|
|
229
|
-
const allDeps = {
|
|
230
|
-
...packageJson.dependencies,
|
|
231
|
-
...packageJson.devDependencies,
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
for (const pkg of packages) {
|
|
235
|
-
const constraint = allDeps[pkg];
|
|
236
|
-
if (!constraint) continue;
|
|
237
|
-
|
|
238
|
-
// Strip semver constraint to get base version
|
|
239
|
-
const version = stripSemverConstraint(constraint);
|
|
240
|
-
if (!version) continue; // Skip if can't parse (e.g., "latest", URLs)
|
|
241
|
-
|
|
242
|
-
versions.push({
|
|
243
|
-
name: pkg,
|
|
244
|
-
version,
|
|
245
|
-
source: "package.json",
|
|
246
|
-
constraint,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return versions;
|
|
251
|
-
} catch {
|
|
252
|
-
return [];
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Get installed versions of packages from lockfile (preferred) or package.json
|
|
258
|
-
*
|
|
259
|
-
* Detection order:
|
|
260
|
-
* 1. package-lock.json (npm)
|
|
261
|
-
* 2. pnpm-lock.yaml (pnpm)
|
|
262
|
-
* 3. yarn.lock (yarn)
|
|
263
|
-
* 4. bun.lock → fallback to package.json (bun lockfile is binary)
|
|
264
|
-
* 5. package.json (fallback)
|
|
265
|
-
*
|
|
266
|
-
* @param projectPath - Absolute path to project root
|
|
267
|
-
* @param packages - Package names to look up
|
|
268
|
-
* @param checkUpgrades - If true, fetch latest versions from npm registry and compare
|
|
269
|
-
* @returns Array of version info for found packages
|
|
270
|
-
*/
|
|
271
|
-
export async function getInstalledVersions(
|
|
272
|
-
projectPath: string,
|
|
273
|
-
packages: string[],
|
|
274
|
-
checkUpgrades = false,
|
|
275
|
-
): Promise<VersionInfo[]> {
|
|
276
|
-
// Try lockfiles in order
|
|
277
|
-
const npmLock = join(projectPath, "package-lock.json");
|
|
278
|
-
let versions: VersionInfo[] = [];
|
|
279
|
-
|
|
280
|
-
if (existsSync(npmLock)) {
|
|
281
|
-
versions = await parseNpmLockfile(npmLock, packages);
|
|
282
|
-
} else {
|
|
283
|
-
const pnpmLock = join(projectPath, "pnpm-lock.yaml");
|
|
284
|
-
if (existsSync(pnpmLock)) {
|
|
285
|
-
versions = await parsePnpmLockfile(pnpmLock, packages);
|
|
286
|
-
} else {
|
|
287
|
-
const yarnLock = join(projectPath, "yarn.lock");
|
|
288
|
-
if (existsSync(yarnLock)) {
|
|
289
|
-
versions = await parseYarnLockfile(yarnLock, packages);
|
|
290
|
-
} else {
|
|
291
|
-
// bun.lock is binary, fallback to package.json
|
|
292
|
-
// (same fallback for no lockfile at all)
|
|
293
|
-
const packageJson = join(projectPath, "package.json");
|
|
294
|
-
if (existsSync(packageJson)) {
|
|
295
|
-
versions = await parsePackageJson(packageJson, packages);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// Optionally check for upgrades
|
|
302
|
-
if (checkUpgrades && versions.length > 0) {
|
|
303
|
-
await Promise.all(
|
|
304
|
-
versions.map(async (versionInfo) => {
|
|
305
|
-
const latest = await getLatestVersion(versionInfo.name);
|
|
306
|
-
if (latest) {
|
|
307
|
-
versionInfo.latest = latest;
|
|
308
|
-
versionInfo.updateAvailable = versionInfo.version !== latest;
|
|
309
|
-
}
|
|
310
|
-
}),
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return versions;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Check if an MCP server tool is available
|
|
319
|
-
*
|
|
320
|
-
* MCP tools don't have runtime detection in OpenCode yet,
|
|
321
|
-
* so we return true for known MCP servers (they're checked at runtime).
|
|
322
|
-
*/
|
|
323
|
-
function isMcpToolAvailable(_toolName: string): boolean {
|
|
324
|
-
// TODO: Once OpenCode exposes MCP server list, check actual availability
|
|
325
|
-
// For now, assume MCP tools are available (fail gracefully at runtime)
|
|
326
|
-
return true;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Discover available documentation tools
|
|
331
|
-
*
|
|
332
|
-
* Checks for:
|
|
333
|
-
* - Skills (via skills discovery)
|
|
334
|
-
* - MCP servers (next-devtools, context7, fetch, pdf-brain)
|
|
335
|
-
* - CLI tools (semantic-memory)
|
|
336
|
-
*
|
|
337
|
-
* @returns List of discovered tools with availability status
|
|
338
|
-
*/
|
|
339
|
-
export async function discoverDocTools(): Promise<DiscoveredTool[]> {
|
|
340
|
-
const tools: DiscoveredTool[] = [];
|
|
341
|
-
|
|
342
|
-
// Check each tool definition
|
|
343
|
-
for (const def of TOOL_DEFINITIONS) {
|
|
344
|
-
let available = false;
|
|
345
|
-
|
|
346
|
-
if (def.type === "cli") {
|
|
347
|
-
// Check CLI tool availability
|
|
348
|
-
available = await isToolAvailable(def.name as ToolName);
|
|
349
|
-
} else if (def.type === "mcp") {
|
|
350
|
-
// Check MCP server availability
|
|
351
|
-
available = isMcpToolAvailable(def.name);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
tools.push({
|
|
355
|
-
...def,
|
|
356
|
-
available,
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
return tools;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Plugin tool for discovering available documentation tools
|
|
365
|
-
*/
|
|
366
|
-
export const swarm_discover_tools = tool({
|
|
367
|
-
description:
|
|
368
|
-
"Discover available documentation tools for researchers. Returns list of tools (skills, MCP servers, CLI) with capabilities and availability status.",
|
|
369
|
-
args: {},
|
|
370
|
-
async execute() {
|
|
371
|
-
const tools = await discoverDocTools();
|
|
372
|
-
|
|
373
|
-
return JSON.stringify(
|
|
374
|
-
{
|
|
375
|
-
tools,
|
|
376
|
-
summary: {
|
|
377
|
-
total: tools.length,
|
|
378
|
-
available: tools.filter((t) => t.available).length,
|
|
379
|
-
unavailable: tools.filter((t) => !t.available).length,
|
|
380
|
-
by_type: {
|
|
381
|
-
skill: tools.filter((t) => t.type === "skill").length,
|
|
382
|
-
mcp: tools.filter((t) => t.type === "mcp").length,
|
|
383
|
-
cli: tools.filter((t) => t.type === "cli").length,
|
|
384
|
-
},
|
|
385
|
-
},
|
|
386
|
-
usage_hint:
|
|
387
|
-
"Use 'available' tools first. If unavailable, either skip or provide alternative instructions.",
|
|
388
|
-
},
|
|
389
|
-
null,
|
|
390
|
-
2,
|
|
391
|
-
);
|
|
392
|
-
},
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Plugin tool for getting installed package versions
|
|
397
|
-
*/
|
|
398
|
-
export const swarm_get_versions = tool({
|
|
399
|
-
description:
|
|
400
|
-
"Get installed versions of packages from lockfile (preferred) or package.json. Used by researchers to fetch docs for the correct version (not latest). Detects npm (package-lock.json), pnpm (pnpm-lock.yaml), yarn (yarn.lock), or falls back to package.json. Optionally compares to latest versions from npm registry.",
|
|
401
|
-
args: {
|
|
402
|
-
projectPath: tool.schema
|
|
403
|
-
.string()
|
|
404
|
-
.describe("Absolute path to project root directory"),
|
|
405
|
-
packages: tool.schema
|
|
406
|
-
.array(tool.schema.string())
|
|
407
|
-
.describe("Package names to look up (e.g., ['zod', 'typescript'])"),
|
|
408
|
-
checkUpgrades: tool.schema
|
|
409
|
-
.boolean()
|
|
410
|
-
.optional()
|
|
411
|
-
.describe("If true, fetch latest versions from npm registry and compare to installed. Default: false"),
|
|
412
|
-
},
|
|
413
|
-
async execute(args: { projectPath: string; packages: string[]; checkUpgrades?: boolean }) {
|
|
414
|
-
const versions = await getInstalledVersions(
|
|
415
|
-
args.projectPath,
|
|
416
|
-
args.packages,
|
|
417
|
-
args.checkUpgrades ?? false,
|
|
418
|
-
);
|
|
419
|
-
|
|
420
|
-
const summary: {
|
|
421
|
-
found: number;
|
|
422
|
-
requested: number;
|
|
423
|
-
missing: string[];
|
|
424
|
-
sources: {
|
|
425
|
-
lockfile: number;
|
|
426
|
-
package_json: number;
|
|
427
|
-
};
|
|
428
|
-
upgrades?: {
|
|
429
|
-
available: number;
|
|
430
|
-
upToDate: number;
|
|
431
|
-
};
|
|
432
|
-
} = {
|
|
433
|
-
found: versions.length,
|
|
434
|
-
requested: args.packages.length,
|
|
435
|
-
missing: args.packages.filter(
|
|
436
|
-
(pkg) => !versions.find((v) => v.name === pkg),
|
|
437
|
-
),
|
|
438
|
-
sources: {
|
|
439
|
-
lockfile: versions.filter((v) => v.source === "lockfile").length,
|
|
440
|
-
package_json: versions.filter((v) => v.source === "package.json")
|
|
441
|
-
.length,
|
|
442
|
-
},
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
if (args.checkUpgrades) {
|
|
446
|
-
summary.upgrades = {
|
|
447
|
-
available: versions.filter((v) => v.updateAvailable === true).length,
|
|
448
|
-
upToDate: versions.filter((v) => v.updateAvailable === false).length,
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
return JSON.stringify(
|
|
453
|
-
{
|
|
454
|
-
versions,
|
|
455
|
-
summary,
|
|
456
|
-
usage_hint:
|
|
457
|
-
"Use 'version' field for doc lookups. If source is 'package.json', consider warning user that lockfile is missing (versions may be outdated)." +
|
|
458
|
-
(args.checkUpgrades ? " When checkUpgrades=true, 'latest' and 'updateAvailable' fields show upgrade status." : ""),
|
|
459
|
-
},
|
|
460
|
-
null,
|
|
461
|
-
2,
|
|
462
|
-
);
|
|
463
|
-
},
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Research tools for plugin registration
|
|
468
|
-
*/
|
|
469
|
-
export const researchTools = {
|
|
470
|
-
swarm_discover_tools,
|
|
471
|
-
swarm_get_versions,
|
|
472
|
-
};
|