opencode-swarm-plugin 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.beads/issues.jsonl +321 -3
- package/README.md +160 -11
- package/dist/index.js +804 -23
- package/dist/plugin.js +443 -23
- package/package.json +7 -3
- package/src/agent-mail.ts +46 -3
- package/src/index.ts +60 -0
- package/src/learning.integration.test.ts +326 -1
- package/src/storage.integration.test.ts +341 -0
- package/src/storage.ts +679 -0
- package/src/swarm.integration.test.ts +194 -3
- package/src/swarm.ts +185 -32
- package/src/tool-availability.ts +390 -0
- package/Dockerfile +0 -30
- package/docker/agent-mail/Dockerfile +0 -23
- package/docker/agent-mail/__pycache__/server.cpython-314.pyc +0 -0
- package/docker/agent-mail/requirements.txt +0 -3
- package/docker/agent-mail/server.py +0 -879
- package/docker-compose.yml +0 -45
- package/scripts/docker-entrypoint.sh +0 -54
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Availability Module
|
|
3
|
+
*
|
|
4
|
+
* Checks for external tool availability and provides graceful degradation.
|
|
5
|
+
* Tools are checked once and cached for the session.
|
|
6
|
+
*
|
|
7
|
+
* Supported tools:
|
|
8
|
+
* - semantic-memory: Learning persistence with semantic search
|
|
9
|
+
* - cass: Cross-agent session search for historical context
|
|
10
|
+
* - ubs: Universal bug scanner for pre-commit checks
|
|
11
|
+
* - beads (bd): Git-backed issue tracking
|
|
12
|
+
* - agent-mail: Multi-agent coordination server
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export type ToolName =
|
|
16
|
+
| "semantic-memory"
|
|
17
|
+
| "cass"
|
|
18
|
+
| "ubs"
|
|
19
|
+
| "beads"
|
|
20
|
+
| "agent-mail";
|
|
21
|
+
|
|
22
|
+
export interface ToolStatus {
|
|
23
|
+
available: boolean;
|
|
24
|
+
checkedAt: string;
|
|
25
|
+
error?: string;
|
|
26
|
+
version?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ToolAvailability {
|
|
30
|
+
tool: ToolName;
|
|
31
|
+
status: ToolStatus;
|
|
32
|
+
fallbackBehavior: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Cached tool status
|
|
36
|
+
const toolCache = new Map<ToolName, ToolStatus>();
|
|
37
|
+
|
|
38
|
+
// Warnings already logged (to avoid spam)
|
|
39
|
+
const warningsLogged = new Set<ToolName>();
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if a command exists and is executable
|
|
43
|
+
*/
|
|
44
|
+
async function commandExists(cmd: string): Promise<boolean> {
|
|
45
|
+
try {
|
|
46
|
+
const result = await Bun.$`which ${cmd}`.quiet().nothrow();
|
|
47
|
+
return result.exitCode === 0;
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check if a URL is reachable
|
|
55
|
+
*/
|
|
56
|
+
async function urlReachable(
|
|
57
|
+
url: string,
|
|
58
|
+
timeoutMs: number = 2000,
|
|
59
|
+
): Promise<boolean> {
|
|
60
|
+
try {
|
|
61
|
+
const controller = new AbortController();
|
|
62
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
63
|
+
|
|
64
|
+
// Use GET instead of HEAD - some servers don't support HEAD
|
|
65
|
+
const response = await fetch(url, {
|
|
66
|
+
method: "GET",
|
|
67
|
+
signal: controller.signal,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
clearTimeout(timeout);
|
|
71
|
+
return response.ok;
|
|
72
|
+
} catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Tool-specific availability checks
|
|
79
|
+
*/
|
|
80
|
+
const toolCheckers: Record<ToolName, () => Promise<ToolStatus>> = {
|
|
81
|
+
"semantic-memory": async () => {
|
|
82
|
+
// Check native first, then bunx
|
|
83
|
+
const nativeExists = await commandExists("semantic-memory");
|
|
84
|
+
if (nativeExists) {
|
|
85
|
+
try {
|
|
86
|
+
const result = await Bun.$`semantic-memory stats`.quiet().nothrow();
|
|
87
|
+
return {
|
|
88
|
+
available: result.exitCode === 0,
|
|
89
|
+
checkedAt: new Date().toISOString(),
|
|
90
|
+
version: "native",
|
|
91
|
+
};
|
|
92
|
+
} catch (e) {
|
|
93
|
+
return {
|
|
94
|
+
available: false,
|
|
95
|
+
checkedAt: new Date().toISOString(),
|
|
96
|
+
error: String(e),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Try bunx with manual timeout
|
|
102
|
+
try {
|
|
103
|
+
const proc = Bun.spawn(["bunx", "semantic-memory", "stats"], {
|
|
104
|
+
stdout: "pipe",
|
|
105
|
+
stderr: "pipe",
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const timeout = setTimeout(() => proc.kill(), 10000);
|
|
109
|
+
const exitCode = await proc.exited;
|
|
110
|
+
clearTimeout(timeout);
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
available: exitCode === 0,
|
|
114
|
+
checkedAt: new Date().toISOString(),
|
|
115
|
+
version: "bunx",
|
|
116
|
+
};
|
|
117
|
+
} catch (e) {
|
|
118
|
+
return {
|
|
119
|
+
available: false,
|
|
120
|
+
checkedAt: new Date().toISOString(),
|
|
121
|
+
error: String(e),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
cass: async () => {
|
|
127
|
+
const exists = await commandExists("cass");
|
|
128
|
+
if (!exists) {
|
|
129
|
+
return {
|
|
130
|
+
available: false,
|
|
131
|
+
checkedAt: new Date().toISOString(),
|
|
132
|
+
error: "cass command not found",
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
const result = await Bun.$`cass health`.quiet().nothrow();
|
|
138
|
+
return {
|
|
139
|
+
available: result.exitCode === 0,
|
|
140
|
+
checkedAt: new Date().toISOString(),
|
|
141
|
+
};
|
|
142
|
+
} catch (e) {
|
|
143
|
+
return {
|
|
144
|
+
available: false,
|
|
145
|
+
checkedAt: new Date().toISOString(),
|
|
146
|
+
error: String(e),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
ubs: async () => {
|
|
152
|
+
const exists = await commandExists("ubs");
|
|
153
|
+
if (!exists) {
|
|
154
|
+
return {
|
|
155
|
+
available: false,
|
|
156
|
+
checkedAt: new Date().toISOString(),
|
|
157
|
+
error: "ubs command not found",
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
const result = await Bun.$`ubs doctor`.quiet().nothrow();
|
|
163
|
+
return {
|
|
164
|
+
available: result.exitCode === 0,
|
|
165
|
+
checkedAt: new Date().toISOString(),
|
|
166
|
+
};
|
|
167
|
+
} catch (e) {
|
|
168
|
+
return {
|
|
169
|
+
available: false,
|
|
170
|
+
checkedAt: new Date().toISOString(),
|
|
171
|
+
error: String(e),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
beads: async () => {
|
|
177
|
+
const exists = await commandExists("bd");
|
|
178
|
+
if (!exists) {
|
|
179
|
+
return {
|
|
180
|
+
available: false,
|
|
181
|
+
checkedAt: new Date().toISOString(),
|
|
182
|
+
error: "bd command not found",
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
try {
|
|
187
|
+
// Just check if bd can run - don't require a repo
|
|
188
|
+
const result = await Bun.$`bd --version`.quiet().nothrow();
|
|
189
|
+
return {
|
|
190
|
+
available: result.exitCode === 0,
|
|
191
|
+
checkedAt: new Date().toISOString(),
|
|
192
|
+
};
|
|
193
|
+
} catch (e) {
|
|
194
|
+
return {
|
|
195
|
+
available: false,
|
|
196
|
+
checkedAt: new Date().toISOString(),
|
|
197
|
+
error: String(e),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
"agent-mail": async () => {
|
|
203
|
+
const reachable = await urlReachable(
|
|
204
|
+
"http://127.0.0.1:8765/health/liveness",
|
|
205
|
+
);
|
|
206
|
+
return {
|
|
207
|
+
available: reachable,
|
|
208
|
+
checkedAt: new Date().toISOString(),
|
|
209
|
+
error: reachable ? undefined : "Agent Mail server not reachable at :8765",
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Fallback behavior descriptions for each tool
|
|
216
|
+
*/
|
|
217
|
+
const fallbackBehaviors: Record<ToolName, string> = {
|
|
218
|
+
"semantic-memory":
|
|
219
|
+
"Learning data stored in-memory only (lost on session end)",
|
|
220
|
+
cass: "Decomposition proceeds without historical context from past sessions",
|
|
221
|
+
ubs: "Subtask completion skips bug scanning - manual review recommended",
|
|
222
|
+
beads: "Swarm cannot track issues - task coordination will be less reliable",
|
|
223
|
+
"agent-mail":
|
|
224
|
+
"Multi-agent coordination disabled - file conflicts possible if multiple agents active",
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Check if a tool is available (cached)
|
|
229
|
+
*
|
|
230
|
+
* @param tool - Tool name to check
|
|
231
|
+
* @returns Tool status
|
|
232
|
+
*/
|
|
233
|
+
export async function checkTool(tool: ToolName): Promise<ToolStatus> {
|
|
234
|
+
const cached = toolCache.get(tool);
|
|
235
|
+
if (cached) {
|
|
236
|
+
return cached;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const checker = toolCheckers[tool];
|
|
240
|
+
const status = await checker();
|
|
241
|
+
toolCache.set(tool, status);
|
|
242
|
+
|
|
243
|
+
return status;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Check if a tool is available (simple boolean, cached)
|
|
248
|
+
*/
|
|
249
|
+
export async function isToolAvailable(tool: ToolName): Promise<boolean> {
|
|
250
|
+
const status = await checkTool(tool);
|
|
251
|
+
return status.available;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Get full availability info including fallback behavior
|
|
256
|
+
*/
|
|
257
|
+
export async function getToolAvailability(
|
|
258
|
+
tool: ToolName,
|
|
259
|
+
): Promise<ToolAvailability> {
|
|
260
|
+
const status = await checkTool(tool);
|
|
261
|
+
return {
|
|
262
|
+
tool,
|
|
263
|
+
status,
|
|
264
|
+
fallbackBehavior: fallbackBehaviors[tool],
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Check all tools and return availability map
|
|
270
|
+
*/
|
|
271
|
+
export async function checkAllTools(): Promise<
|
|
272
|
+
Map<ToolName, ToolAvailability>
|
|
273
|
+
> {
|
|
274
|
+
const tools: ToolName[] = [
|
|
275
|
+
"semantic-memory",
|
|
276
|
+
"cass",
|
|
277
|
+
"ubs",
|
|
278
|
+
"beads",
|
|
279
|
+
"agent-mail",
|
|
280
|
+
];
|
|
281
|
+
|
|
282
|
+
const results = new Map<ToolName, ToolAvailability>();
|
|
283
|
+
|
|
284
|
+
// Check all in parallel
|
|
285
|
+
const checks = await Promise.all(
|
|
286
|
+
tools.map(async (tool) => ({
|
|
287
|
+
tool,
|
|
288
|
+
availability: await getToolAvailability(tool),
|
|
289
|
+
})),
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
for (const { tool, availability } of checks) {
|
|
293
|
+
results.set(tool, availability);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return results;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Log a warning about a missing tool (once per tool per session)
|
|
301
|
+
*/
|
|
302
|
+
export function warnMissingTool(tool: ToolName): void {
|
|
303
|
+
if (warningsLogged.has(tool)) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
warningsLogged.add(tool);
|
|
308
|
+
const fallback = fallbackBehaviors[tool];
|
|
309
|
+
console.warn(`[swarm] ${tool} not available: ${fallback}`);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Require a tool - throws if not available
|
|
314
|
+
*
|
|
315
|
+
* Use this for tools that are mandatory for a feature.
|
|
316
|
+
*/
|
|
317
|
+
export async function requireTool(tool: ToolName): Promise<void> {
|
|
318
|
+
const status = await checkTool(tool);
|
|
319
|
+
if (!status.available) {
|
|
320
|
+
throw new Error(
|
|
321
|
+
`Required tool '${tool}' is not available: ${status.error || "unknown error"}`,
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Execute with fallback - runs the action if tool available, otherwise runs fallback
|
|
328
|
+
*
|
|
329
|
+
* @param tool - Tool to check
|
|
330
|
+
* @param action - Action to run if tool available
|
|
331
|
+
* @param fallback - Fallback to run if tool not available
|
|
332
|
+
* @returns Result from action or fallback
|
|
333
|
+
*/
|
|
334
|
+
export async function withToolFallback<T>(
|
|
335
|
+
tool: ToolName,
|
|
336
|
+
action: () => Promise<T>,
|
|
337
|
+
fallback: () => T | Promise<T>,
|
|
338
|
+
): Promise<T> {
|
|
339
|
+
const available = await isToolAvailable(tool);
|
|
340
|
+
|
|
341
|
+
if (available) {
|
|
342
|
+
return action();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
warnMissingTool(tool);
|
|
346
|
+
return fallback();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Execute if tool available, otherwise return undefined
|
|
351
|
+
*/
|
|
352
|
+
export async function ifToolAvailable<T>(
|
|
353
|
+
tool: ToolName,
|
|
354
|
+
action: () => Promise<T>,
|
|
355
|
+
): Promise<T | undefined> {
|
|
356
|
+
const available = await isToolAvailable(tool);
|
|
357
|
+
|
|
358
|
+
if (available) {
|
|
359
|
+
return action();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
warnMissingTool(tool);
|
|
363
|
+
return undefined;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Reset tool cache (for testing)
|
|
368
|
+
*/
|
|
369
|
+
export function resetToolCache(): void {
|
|
370
|
+
toolCache.clear();
|
|
371
|
+
warningsLogged.clear();
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Format tool availability for display
|
|
376
|
+
*/
|
|
377
|
+
export function formatToolAvailability(
|
|
378
|
+
availability: Map<ToolName, ToolAvailability>,
|
|
379
|
+
): string {
|
|
380
|
+
const lines: string[] = ["Tool Availability:"];
|
|
381
|
+
|
|
382
|
+
for (const [tool, info] of availability) {
|
|
383
|
+
const status = info.status.available ? "✓" : "✗";
|
|
384
|
+
const version = info.status.version ? ` (${info.status.version})` : "";
|
|
385
|
+
const fallback = info.status.available ? "" : ` → ${info.fallbackBehavior}`;
|
|
386
|
+
lines.push(` ${status} ${tool}${version}${fallback}`);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return lines.join("\n");
|
|
390
|
+
}
|
package/Dockerfile
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Test runner container for opencode-swarm-plugin integration tests
|
|
2
|
-
FROM oven/bun:latest
|
|
3
|
-
|
|
4
|
-
# Install git (required for beads) and curl (for healthchecks)
|
|
5
|
-
RUN apt-get update && apt-get install -y \
|
|
6
|
-
git \
|
|
7
|
-
curl \
|
|
8
|
-
&& rm -rf /var/lib/apt/lists/*
|
|
9
|
-
|
|
10
|
-
# Download bd CLI (beads issue tracker) for linux/amd64
|
|
11
|
-
ARG BD_VERSION=0.2.8
|
|
12
|
-
RUN curl -fsSL "https://github.com/beads-ai/beads/releases/download/v${BD_VERSION}/bd-linux-amd64" \
|
|
13
|
-
-o /usr/local/bin/bd \
|
|
14
|
-
&& chmod +x /usr/local/bin/bd
|
|
15
|
-
|
|
16
|
-
WORKDIR /app
|
|
17
|
-
|
|
18
|
-
# Copy package files and install dependencies
|
|
19
|
-
COPY package.json bun.lock* ./
|
|
20
|
-
RUN bun install --frozen-lockfile
|
|
21
|
-
|
|
22
|
-
# Copy source code
|
|
23
|
-
COPY . .
|
|
24
|
-
|
|
25
|
-
# Copy entrypoint script
|
|
26
|
-
COPY scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
|
27
|
-
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
|
28
|
-
|
|
29
|
-
ENTRYPOINT ["docker-entrypoint.sh"]
|
|
30
|
-
CMD ["bun", "run", "test:integration"]
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
FROM python:3.11-slim
|
|
2
|
-
|
|
3
|
-
WORKDIR /app
|
|
4
|
-
|
|
5
|
-
# Install dependencies
|
|
6
|
-
COPY requirements.txt .
|
|
7
|
-
RUN pip install --no-cache-dir -r requirements.txt
|
|
8
|
-
|
|
9
|
-
# Copy server code
|
|
10
|
-
COPY server.py .
|
|
11
|
-
|
|
12
|
-
# Create data directory for SQLite
|
|
13
|
-
RUN mkdir -p /data
|
|
14
|
-
|
|
15
|
-
# Expose port
|
|
16
|
-
EXPOSE 8765
|
|
17
|
-
|
|
18
|
-
# Health check
|
|
19
|
-
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
|
|
20
|
-
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8765/health/liveness')" || exit 1
|
|
21
|
-
|
|
22
|
-
# Run server
|
|
23
|
-
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8765"]
|
|
Binary file
|