opencode-swarm-plugin 0.31.6 → 0.32.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.
Files changed (48) hide show
  1. package/.turbo/turbo-build.log +10 -9
  2. package/.turbo/turbo-test.log +319 -317
  3. package/CHANGELOG.md +158 -0
  4. package/README.md +7 -4
  5. package/bin/swarm.ts +388 -87
  6. package/dist/compaction-hook.d.ts +1 -1
  7. package/dist/compaction-hook.d.ts.map +1 -1
  8. package/dist/hive.d.ts.map +1 -1
  9. package/dist/index.d.ts +0 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +123 -134
  12. package/dist/memory-tools.d.ts.map +1 -1
  13. package/dist/memory.d.ts +5 -4
  14. package/dist/memory.d.ts.map +1 -1
  15. package/dist/plugin.js +118 -131
  16. package/dist/swarm-orchestrate.d.ts +29 -5
  17. package/dist/swarm-orchestrate.d.ts.map +1 -1
  18. package/dist/swarm-prompts.d.ts +7 -0
  19. package/dist/swarm-prompts.d.ts.map +1 -1
  20. package/dist/swarm.d.ts +0 -2
  21. package/dist/swarm.d.ts.map +1 -1
  22. package/evals/lib/{data-loader.test.ts → data-loader.evalite-test.ts} +7 -6
  23. package/evals/lib/data-loader.ts +1 -1
  24. package/evals/scorers/{outcome-scorers.test.ts → outcome-scorers.evalite-test.ts} +1 -1
  25. package/examples/plugin-wrapper-template.ts +19 -4
  26. package/global-skills/swarm-coordination/SKILL.md +118 -8
  27. package/package.json +2 -2
  28. package/src/compaction-hook.ts +5 -3
  29. package/src/hive.integration.test.ts +83 -1
  30. package/src/hive.ts +37 -12
  31. package/src/mandate-storage.integration.test.ts +601 -0
  32. package/src/memory-tools.ts +6 -4
  33. package/src/memory.integration.test.ts +117 -49
  34. package/src/memory.test.ts +41 -217
  35. package/src/memory.ts +12 -8
  36. package/src/repo-crawl.integration.test.ts +441 -0
  37. package/src/skills.integration.test.ts +1056 -0
  38. package/src/structured.integration.test.ts +817 -0
  39. package/src/swarm-deferred.integration.test.ts +157 -0
  40. package/src/swarm-deferred.test.ts +38 -0
  41. package/src/swarm-mail.integration.test.ts +15 -19
  42. package/src/swarm-orchestrate.integration.test.ts +282 -0
  43. package/src/swarm-orchestrate.ts +96 -201
  44. package/src/swarm-prompts.test.ts +92 -0
  45. package/src/swarm-prompts.ts +69 -0
  46. package/src/swarm-review.integration.test.ts +290 -0
  47. package/src/swarm.integration.test.ts +23 -20
  48. package/src/tool-adapter.integration.test.ts +1221 -0
@@ -0,0 +1,441 @@
1
+ /**
2
+ * Repo Crawl Integration Tests
3
+ *
4
+ * Tests GitHub API wrapper tools against a real public repository.
5
+ * Uses "vercel/next.js" as test target (well-known, stable, public).
6
+ *
7
+ * ## Test Strategy
8
+ * - Happy-path only (error cases covered by unit tests)
9
+ * - Real GitHub API calls (may hit rate limits)
10
+ * - Graceful handling of rate limiting (skip tests if hit)
11
+ * - Fast: minimal API calls, shared test state where safe
12
+ *
13
+ * ## Rate Limit Handling
14
+ * - Unauthenticated: 60 requests/hour
15
+ * - Authenticated: 5000 requests/hour (set GITHUB_TOKEN env var)
16
+ * - Tests check for rate limit errors and skip gracefully
17
+ *
18
+ * ## TDD Note
19
+ * These tests were written FIRST (failing), then tools were verified to pass.
20
+ */
21
+
22
+ import { describe, expect, test } from "bun:test";
23
+ import {
24
+ RepoCrawlError,
25
+ repo_file,
26
+ repo_readme,
27
+ repo_search,
28
+ repo_structure,
29
+ repo_tree,
30
+ } from "./repo-crawl";
31
+
32
+ // Test repository (well-known, stable, public)
33
+ const TEST_REPO = "vercel/next.js";
34
+
35
+ /**
36
+ * Helper to parse JSON response from tool
37
+ */
38
+ function parseResponse<T>(response: string): T {
39
+ return JSON.parse(response);
40
+ }
41
+
42
+
43
+
44
+ describe("repo_readme", () => {
45
+ test("fetches README.md from public repo", async () => {
46
+ const response = await repo_readme.execute(
47
+ { repo: TEST_REPO },
48
+ {} as never,
49
+ );
50
+
51
+ const result = parseResponse<{
52
+ repo: string;
53
+ path: string;
54
+ content: string;
55
+ size: number;
56
+ truncated: boolean;
57
+ error?: string;
58
+ }>(response);
59
+
60
+ // Skip if rate limited
61
+ if (result.error?.includes("rate limit")) {
62
+ console.warn("⚠️ Skipping test: GitHub API rate limit hit");
63
+ return;
64
+ }
65
+
66
+ expect(result.repo).toBe(TEST_REPO);
67
+ expect(result.path).toMatch(/README\.md/i);
68
+ expect(result.content).toContain("Next.js"); // Repo name in README
69
+ expect(result.size).toBeGreaterThan(0);
70
+ expect(typeof result.truncated).toBe("boolean");
71
+ });
72
+
73
+ test("accepts GitHub URLs", async () => {
74
+ const response = await repo_readme.execute(
75
+ { repo: `https://github.com/${TEST_REPO}` },
76
+ {} as never,
77
+ );
78
+
79
+ const result = parseResponse<{ repo: string; error?: string }>(response);
80
+
81
+ if (result.error?.includes("rate limit")) {
82
+ console.warn("⚠️ Skipping test: GitHub API rate limit hit");
83
+ return;
84
+ }
85
+
86
+ expect(result.repo).toBe(TEST_REPO);
87
+ });
88
+
89
+ test("truncates content when maxLength specified", async () => {
90
+ const response = await repo_readme.execute(
91
+ { repo: TEST_REPO, maxLength: 100 },
92
+ {} as never,
93
+ );
94
+
95
+ const result = parseResponse<{
96
+ content: string;
97
+ truncated: boolean;
98
+ error?: string;
99
+ }>(response);
100
+
101
+ if (result.error?.includes("rate limit")) {
102
+ console.warn("⚠️ Skipping test: GitHub API rate limit hit");
103
+ return;
104
+ }
105
+
106
+ expect(result.content.length).toBeLessThanOrEqual(125); // Allow for truncation marker + newlines
107
+ expect(result.truncated).toBe(true);
108
+ expect(result.content).toContain("truncated");
109
+ });
110
+
111
+ test("handles invalid repo gracefully", async () => {
112
+ const response = await repo_readme.execute(
113
+ { repo: "nonexistent-org/nonexistent-repo-12345" },
114
+ {} as never,
115
+ );
116
+
117
+ const result = parseResponse<{ error?: string }>(response);
118
+
119
+ expect(result.error).toBeDefined();
120
+ // Could be rate limit or not found - both are valid error handling
121
+ expect(
122
+ result.error.includes("not found") ||
123
+ result.error.includes("rate limit"),
124
+ ).toBe(true);
125
+ });
126
+ });
127
+
128
+ describe("repo_structure", () => {
129
+ test("fetches repo structure with metadata", async () => {
130
+ const response = await repo_structure.execute(
131
+ { repo: TEST_REPO },
132
+ {} as never,
133
+ );
134
+
135
+ const result = parseResponse<{
136
+ repo: string;
137
+ description: string | null;
138
+ language: string | null;
139
+ stars: number;
140
+ topics: string[];
141
+ techStack: string[];
142
+ directories: string[];
143
+ files: string[];
144
+ truncated: boolean;
145
+ error?: string;
146
+ }>(response);
147
+
148
+ if (result.error?.includes("rate limit")) {
149
+ console.warn("⚠️ Skipping test: GitHub API rate limit hit");
150
+ return;
151
+ }
152
+
153
+ expect(result.repo).toBe(TEST_REPO);
154
+ expect(result.description).toBeDefined();
155
+ expect(result.stars).toBeGreaterThan(0);
156
+ expect(Array.isArray(result.techStack)).toBe(true);
157
+ expect(result.techStack).toContain("TypeScript"); // Next.js uses TypeScript
158
+ expect(Array.isArray(result.directories)).toBe(true);
159
+ expect(Array.isArray(result.files)).toBe(true);
160
+ expect(typeof result.truncated).toBe("boolean");
161
+ });
162
+
163
+ test("respects depth parameter", async () => {
164
+ const response = await repo_structure.execute(
165
+ { repo: TEST_REPO, depth: 1 },
166
+ {} as never,
167
+ );
168
+
169
+ const result = parseResponse<{
170
+ directories: string[];
171
+ files: string[];
172
+ error?: string;
173
+ }>(response);
174
+
175
+ if (result.error?.includes("rate limit")) {
176
+ console.warn("⚠️ Skipping test: GitHub API rate limit hit");
177
+ return;
178
+ }
179
+
180
+ // Depth 1 means no nested paths (no slashes in paths)
181
+ const allPaths = [...result.directories, ...result.files];
182
+ const nestedPaths = allPaths.filter((path) => path.includes("/"));
183
+ expect(nestedPaths.length).toBe(0);
184
+ });
185
+ });
186
+
187
+ describe("repo_tree", () => {
188
+ test("fetches root directory tree", async () => {
189
+ const response = await repo_tree.execute(
190
+ { repo: TEST_REPO },
191
+ {} as never,
192
+ );
193
+
194
+ const result = parseResponse<{
195
+ repo: string;
196
+ path: string;
197
+ items: Array<{ path: string; type: string; size?: number }>;
198
+ error?: string;
199
+ }>(response);
200
+
201
+ if (result.error?.includes("rate limit")) {
202
+ console.warn("⚠️ Skipping test: GitHub API rate limit hit");
203
+ return;
204
+ }
205
+
206
+ expect(result.repo).toBe(TEST_REPO);
207
+ expect(result.path).toBe("(root)");
208
+ expect(Array.isArray(result.items)).toBe(true);
209
+ expect(result.items.length).toBeGreaterThan(0);
210
+
211
+ // Should have both files and directories
212
+ const types = new Set(result.items.map((item) => item.type));
213
+ expect(types.has("file") || types.has("dir")).toBe(true);
214
+ });
215
+
216
+ test("fetches specific directory tree", async () => {
217
+ const response = await repo_tree.execute(
218
+ { repo: TEST_REPO, path: "packages" },
219
+ {} as never,
220
+ );
221
+
222
+ const result = parseResponse<{
223
+ path: string;
224
+ items: Array<{ path: string; type: string }>;
225
+ error?: string;
226
+ }>(response);
227
+
228
+ if (result.error?.includes("rate limit")) {
229
+ console.warn("⚠️ Skipping test: GitHub API rate limit hit");
230
+ return;
231
+ }
232
+
233
+ expect(result.path).toBe("packages");
234
+ expect(Array.isArray(result.items)).toBe(true);
235
+
236
+ // All items should be under packages/ path
237
+ for (const item of result.items) {
238
+ expect(item.path).toMatch(/^packages\//);
239
+ }
240
+ });
241
+
242
+ test("handles file path gracefully", async () => {
243
+ const response = await repo_tree.execute(
244
+ { repo: TEST_REPO, path: "package.json" },
245
+ {} as never,
246
+ );
247
+
248
+ const result = parseResponse<{ error?: string }>(response);
249
+
250
+ expect(result.error).toBeDefined();
251
+ // Could be rate limit or "not a directory" - both are valid error handling
252
+ expect(
253
+ result.error.includes("not a directory") ||
254
+ result.error.includes("rate limit"),
255
+ ).toBe(true);
256
+ });
257
+ });
258
+
259
+ describe("repo_file", () => {
260
+ test("fetches file content", async () => {
261
+ const response = await repo_file.execute(
262
+ { repo: TEST_REPO, path: "package.json" },
263
+ {} as never,
264
+ );
265
+
266
+ const result = parseResponse<{
267
+ repo: string;
268
+ path: string;
269
+ content: string;
270
+ size: number;
271
+ truncated: boolean;
272
+ error?: string;
273
+ }>(response);
274
+
275
+ if (result.error?.includes("rate limit")) {
276
+ console.warn("⚠️ Skipping test: GitHub API rate limit hit");
277
+ return;
278
+ }
279
+
280
+ expect(result.repo).toBe(TEST_REPO);
281
+ expect(result.path).toBe("package.json");
282
+ expect(result.content).toContain('"name"'); // Valid package.json
283
+ expect(result.size).toBeGreaterThan(0);
284
+ expect(typeof result.truncated).toBe("boolean");
285
+ });
286
+
287
+ test("truncates large files when maxLength specified", async () => {
288
+ const response = await repo_file.execute(
289
+ { repo: TEST_REPO, path: "package.json", maxLength: 50 },
290
+ {} as never,
291
+ );
292
+
293
+ const result = parseResponse<{
294
+ content: string;
295
+ truncated: boolean;
296
+ error?: string;
297
+ }>(response);
298
+
299
+ if (result.error?.includes("rate limit")) {
300
+ console.warn("⚠️ Skipping test: GitHub API rate limit hit");
301
+ return;
302
+ }
303
+
304
+ expect(result.content.length).toBeLessThanOrEqual(75); // Allow for truncation marker + newlines
305
+ expect(result.truncated).toBe(true);
306
+ });
307
+
308
+ test("handles directory path gracefully", async () => {
309
+ const response = await repo_file.execute(
310
+ { repo: TEST_REPO, path: "packages" },
311
+ {} as never,
312
+ );
313
+
314
+ const result = parseResponse<{ error?: string }>(response);
315
+
316
+ expect(result.error).toBeDefined();
317
+ // Could be rate limit or "not a file" - both are valid error handling
318
+ expect(
319
+ result.error.includes("not a file") ||
320
+ result.error.includes("rate limit"),
321
+ ).toBe(true);
322
+ });
323
+
324
+ test("handles nonexistent file gracefully", async () => {
325
+ const response = await repo_file.execute(
326
+ { repo: TEST_REPO, path: "nonexistent-file-12345.txt" },
327
+ {} as never,
328
+ );
329
+
330
+ const result = parseResponse<{ error?: string }>(response);
331
+
332
+ expect(result.error).toBeDefined();
333
+ // Could be rate limit or not found - both are valid error handling
334
+ expect(
335
+ result.error.includes("not found") ||
336
+ result.error.includes("rate limit"),
337
+ ).toBe(true);
338
+ });
339
+ });
340
+
341
+ describe("repo_search", () => {
342
+ test("searches code in repo", async () => {
343
+ const response = await repo_search.execute(
344
+ { repo: TEST_REPO, query: "useRouter" },
345
+ {} as never,
346
+ );
347
+
348
+ const result = parseResponse<{
349
+ repo: string;
350
+ query: string;
351
+ totalCount: number;
352
+ results: Array<{
353
+ path: string;
354
+ url: string;
355
+ matches: string[];
356
+ }>;
357
+ error?: string;
358
+ }>(response);
359
+
360
+ // GitHub Code Search API requires authentication for most repos
361
+ if (
362
+ result.error?.includes("rate limit") ||
363
+ result.error?.includes("secondary rate limit")
364
+ ) {
365
+ console.warn(
366
+ "⚠️ Skipping test: GitHub API rate limit hit (set GITHUB_TOKEN for higher limits)",
367
+ );
368
+ return;
369
+ }
370
+
371
+ // If there's any error, log it and skip
372
+ if (result.error) {
373
+ console.warn(`⚠️ Skipping test: ${result.error}`);
374
+ return;
375
+ }
376
+
377
+ expect(result.repo).toBe(TEST_REPO);
378
+ expect(result.query).toBe("useRouter");
379
+ expect(result.totalCount).toBeGreaterThan(0);
380
+ expect(Array.isArray(result.results)).toBe(true);
381
+
382
+ // First result should have required fields
383
+ if (result.results.length > 0) {
384
+ const firstResult = result.results[0];
385
+ expect(firstResult.path).toBeDefined();
386
+ expect(firstResult.url).toContain("github.com");
387
+ expect(Array.isArray(firstResult.matches)).toBe(true);
388
+ }
389
+ });
390
+
391
+ test("respects maxResults parameter", async () => {
392
+ const response = await repo_search.execute(
393
+ { repo: TEST_REPO, query: "useRouter", maxResults: 3 },
394
+ {} as never,
395
+ );
396
+
397
+ const result = parseResponse<{
398
+ results: Array<{ path: string }>;
399
+ error?: string;
400
+ }>(response);
401
+
402
+ if (result.error) {
403
+ console.warn(`⚠️ Skipping test: ${result.error}`);
404
+ return;
405
+ }
406
+
407
+ expect(result.results.length).toBeLessThanOrEqual(3);
408
+ });
409
+
410
+ test("handles no results gracefully", async () => {
411
+ const response = await repo_search.execute(
412
+ { repo: TEST_REPO, query: "zzz-nonexistent-query-12345-zzz" },
413
+ {} as never,
414
+ );
415
+
416
+ const result = parseResponse<{
417
+ totalCount: number;
418
+ results: Array<unknown>;
419
+ error?: string;
420
+ }>(response);
421
+
422
+ if (result.error) {
423
+ console.warn(`⚠️ Skipping test: ${result.error}`);
424
+ return;
425
+ }
426
+
427
+ expect(result.totalCount).toBe(0);
428
+ expect(result.results.length).toBe(0);
429
+ });
430
+ });
431
+
432
+ describe("RepoCrawlError", () => {
433
+ test("has correct properties", () => {
434
+ const error = new RepoCrawlError("Test error", 404, "/test/endpoint");
435
+
436
+ expect(error.message).toBe("Test error");
437
+ expect(error.statusCode).toBe(404);
438
+ expect(error.endpoint).toBe("/test/endpoint");
439
+ expect(error.name).toBe("RepoCrawlError");
440
+ });
441
+ });