opencode-swarm-plugin 0.29.0 → 0.30.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/.turbo/turbo-build.log +4 -4
  2. package/CHANGELOG.md +94 -0
  3. package/README.md +3 -6
  4. package/bin/swarm.test.ts +163 -0
  5. package/bin/swarm.ts +304 -72
  6. package/dist/hive.d.ts.map +1 -1
  7. package/dist/index.d.ts +94 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +18825 -3469
  10. package/dist/memory-tools.d.ts +209 -0
  11. package/dist/memory-tools.d.ts.map +1 -0
  12. package/dist/memory.d.ts +124 -0
  13. package/dist/memory.d.ts.map +1 -0
  14. package/dist/plugin.js +18775 -3430
  15. package/dist/schemas/index.d.ts +7 -0
  16. package/dist/schemas/index.d.ts.map +1 -1
  17. package/dist/schemas/worker-handoff.d.ts +78 -0
  18. package/dist/schemas/worker-handoff.d.ts.map +1 -0
  19. package/dist/swarm-orchestrate.d.ts +50 -0
  20. package/dist/swarm-orchestrate.d.ts.map +1 -1
  21. package/dist/swarm-prompts.d.ts +1 -1
  22. package/dist/swarm-prompts.d.ts.map +1 -1
  23. package/dist/swarm-review.d.ts +4 -0
  24. package/dist/swarm-review.d.ts.map +1 -1
  25. package/docs/planning/ADR-008-worker-handoff-protocol.md +293 -0
  26. package/examples/plugin-wrapper-template.ts +157 -28
  27. package/package.json +3 -1
  28. package/src/hive.integration.test.ts +114 -0
  29. package/src/hive.ts +33 -22
  30. package/src/index.ts +41 -8
  31. package/src/memory-tools.test.ts +111 -0
  32. package/src/memory-tools.ts +273 -0
  33. package/src/memory.integration.test.ts +266 -0
  34. package/src/memory.test.ts +334 -0
  35. package/src/memory.ts +441 -0
  36. package/src/schemas/index.ts +18 -0
  37. package/src/schemas/worker-handoff.test.ts +271 -0
  38. package/src/schemas/worker-handoff.ts +131 -0
  39. package/src/swarm-orchestrate.ts +262 -24
  40. package/src/swarm-prompts.ts +48 -5
  41. package/src/swarm-review.ts +7 -0
  42. package/src/swarm.integration.test.ts +386 -9
@@ -0,0 +1,334 @@
1
+ /**
2
+ * Memory Tool Tests
3
+ *
4
+ * Tests for semantic-memory_* tool handlers that use embedded MemoryStore.
5
+ */
6
+
7
+ import { describe, test, expect, beforeAll, afterAll, beforeEach } from "bun:test";
8
+ import {
9
+ createMemoryAdapter,
10
+ type MemoryAdapter,
11
+ resetMigrationCheck,
12
+ } from "./memory";
13
+ import { createInMemorySwarmMail } from "swarm-mail";
14
+ import type { SwarmMailAdapter } from "swarm-mail";
15
+
16
+ describe("memory adapter", () => {
17
+ let swarmMail: SwarmMailAdapter;
18
+ let adapter: MemoryAdapter;
19
+
20
+ beforeAll(async () => {
21
+ // Create in-memory SwarmMail with memory support
22
+ swarmMail = await createInMemorySwarmMail("test-memory");
23
+ const db = await swarmMail.getDatabase();
24
+ adapter = await createMemoryAdapter(db);
25
+ });
26
+
27
+ afterAll(async () => {
28
+ await swarmMail.close();
29
+ });
30
+
31
+ describe("store", () => {
32
+ test("stores memory with auto-generated ID", async () => {
33
+ const result = await adapter.store({
34
+ information: "OAuth refresh tokens need 5min buffer",
35
+ tags: "auth,tokens",
36
+ metadata: JSON.stringify({ project: "test" }),
37
+ });
38
+
39
+ expect(result.id).toBeDefined();
40
+ expect(result.id).toMatch(/^mem_/);
41
+ expect(result.message).toContain("Stored memory");
42
+ });
43
+
44
+ test("stores memory with explicit collection", async () => {
45
+ const result = await adapter.store({
46
+ information: "Test memory",
47
+ collection: "project-alpha",
48
+ });
49
+
50
+ expect(result.id).toMatch(/^mem_/);
51
+ expect(result.message).toContain("collection: project-alpha");
52
+ });
53
+ });
54
+
55
+ describe("find", () => {
56
+ test("returns results sorted by relevance score", async () => {
57
+ // Store some test memories
58
+ await adapter.store({ information: "Test memory about cats" });
59
+ await adapter.store({ information: "Test memory about dogs" });
60
+
61
+ // Query for cats - should return relevant results first
62
+ const results = await adapter.find({
63
+ query: "cats felines",
64
+ limit: 5,
65
+ });
66
+
67
+ // Should find at least the cat memory
68
+ expect(results.count).toBeGreaterThan(0);
69
+ // Results should be in descending score order
70
+ for (let i = 1; i < results.results.length; i++) {
71
+ expect(results.results[i - 1].score).toBeGreaterThanOrEqual(results.results[i].score);
72
+ }
73
+ });
74
+
75
+ test("finds stored memories by semantic similarity", async () => {
76
+ // Store a memory
77
+ await adapter.store({
78
+ information: "Next.js 16 Cache Components need Suspense boundaries",
79
+ tags: "nextjs,caching",
80
+ });
81
+
82
+ // Search for it
83
+ const results = await adapter.find({
84
+ query: "Next.js caching suspense",
85
+ limit: 5,
86
+ });
87
+
88
+ expect(results.count).toBeGreaterThan(0);
89
+ expect(results.results[0].content).toContain("Cache Components");
90
+ });
91
+
92
+ test("respects collection filter", async () => {
93
+ await adapter.store({
94
+ information: "Collection A memory",
95
+ collection: "collection-a",
96
+ });
97
+
98
+ const results = await adapter.find({
99
+ query: "collection",
100
+ collection: "collection-b",
101
+ });
102
+
103
+ // Should not find collection-a memory
104
+ expect(
105
+ results.results.some((r) => r.content.includes("Collection A"))
106
+ ).toBe(false);
107
+ });
108
+
109
+ test("supports full-text search fallback", async () => {
110
+ await adapter.store({
111
+ information: "FTSTEST unique-keyword-12345",
112
+ });
113
+
114
+ const results = await adapter.find({
115
+ query: "unique-keyword-12345",
116
+ fts: true,
117
+ });
118
+
119
+ expect(results.count).toBeGreaterThan(0);
120
+ });
121
+
122
+ test("expand option returns full content", async () => {
123
+ const stored = await adapter.store({
124
+ information: "A".repeat(500), // Long content
125
+ });
126
+
127
+ // Without expand - should truncate
128
+ const withoutExpand = await adapter.find({
129
+ query: "AAA",
130
+ limit: 1,
131
+ });
132
+ expect(withoutExpand.results[0].content.length).toBeLessThan(500);
133
+
134
+ // With expand - should return full content
135
+ const withExpand = await adapter.find({
136
+ query: "AAA",
137
+ limit: 1,
138
+ expand: true,
139
+ });
140
+ expect(withExpand.results[0].content.length).toBe(500);
141
+ });
142
+ });
143
+
144
+ describe("get", () => {
145
+ test("retrieves memory by ID", async () => {
146
+ const stored = await adapter.store({
147
+ information: "Get test memory",
148
+ });
149
+
150
+ const memory = await adapter.get({ id: stored.id });
151
+
152
+ expect(memory).toBeDefined();
153
+ expect(memory?.content).toBe("Get test memory");
154
+ });
155
+
156
+ test("returns null for nonexistent ID", async () => {
157
+ const memory = await adapter.get({ id: "mem_nonexistent" });
158
+ expect(memory).toBeNull();
159
+ });
160
+ });
161
+
162
+ describe("remove", () => {
163
+ test("deletes memory by ID", async () => {
164
+ const stored = await adapter.store({
165
+ information: "Memory to delete",
166
+ });
167
+
168
+ const result = await adapter.remove({ id: stored.id });
169
+ expect(result.success).toBe(true);
170
+
171
+ // Verify it's gone
172
+ const memory = await adapter.get({ id: stored.id });
173
+ expect(memory).toBeNull();
174
+ });
175
+
176
+ test("handles nonexistent ID gracefully", async () => {
177
+ const result = await adapter.remove({ id: "mem_nonexistent" });
178
+ expect(result.success).toBe(true); // No-op
179
+ });
180
+ });
181
+
182
+ describe("list", () => {
183
+ test("lists all memories", async () => {
184
+ await adapter.store({ information: "List test 1" });
185
+ await adapter.store({ information: "List test 2" });
186
+
187
+ const memories = await adapter.list({});
188
+
189
+ expect(memories.length).toBeGreaterThanOrEqual(2);
190
+ });
191
+
192
+ test("filters by collection", async () => {
193
+ await adapter.store({
194
+ information: "Collection X",
195
+ collection: "col-x",
196
+ });
197
+ await adapter.store({
198
+ information: "Collection Y",
199
+ collection: "col-y",
200
+ });
201
+
202
+ const results = await adapter.list({ collection: "col-x" });
203
+
204
+ expect(results.every((m) => m.collection === "col-x")).toBe(true);
205
+ });
206
+ });
207
+
208
+ describe("stats", () => {
209
+ test("returns memory and embedding counts", async () => {
210
+ const stats = await adapter.stats();
211
+
212
+ expect(stats.memories).toBeGreaterThanOrEqual(0);
213
+ expect(stats.embeddings).toBeGreaterThanOrEqual(0);
214
+ });
215
+ });
216
+
217
+ describe("validate", () => {
218
+ test("resets decay timer for memory", async () => {
219
+ const stored = await adapter.store({
220
+ information: "Validate test memory",
221
+ });
222
+
223
+ const result = await adapter.validate({ id: stored.id });
224
+
225
+ expect(result.success).toBe(true);
226
+ expect(result.message).toContain("validated");
227
+ });
228
+
229
+ test("handles nonexistent ID", async () => {
230
+ const result = await adapter.validate({ id: "mem_nonexistent" });
231
+ expect(result.success).toBe(false);
232
+ });
233
+ });
234
+
235
+ describe("checkHealth", () => {
236
+ test("checks Ollama availability", async () => {
237
+ const health = await adapter.checkHealth();
238
+
239
+ expect(health.ollama).toBeDefined();
240
+ // May be true or false depending on local setup
241
+ // Just verify structure
242
+ expect(typeof health.ollama).toBe("boolean");
243
+ });
244
+ });
245
+ });
246
+
247
+ describe("auto-migration on createMemoryAdapter", () => {
248
+ // Reset migration flag before each test for isolation
249
+ beforeEach(() => {
250
+ resetMigrationCheck();
251
+ });
252
+
253
+ test("auto-migrates when legacy DB exists and target is empty", async () => {
254
+ // Note: This test will actually migrate if ~/.semantic-memory/memory exists
255
+ // For this implementation, we're testing the happy path
256
+ const swarmMail = await createInMemorySwarmMail("test-auto-migrate");
257
+ const db = await swarmMail.getDatabase();
258
+
259
+ // Should not throw even if legacy DB exists
260
+ const adapter = await createMemoryAdapter(db);
261
+ expect(adapter).toBeDefined();
262
+
263
+ // If legacy DB existed and was migrated, there should be memories
264
+ const stats = await adapter.stats();
265
+ // Don't assert specific count - depends on whether legacy DB exists
266
+ expect(stats.memories).toBeGreaterThanOrEqual(0);
267
+
268
+ await swarmMail.close();
269
+ });
270
+
271
+ test("skips auto-migration when legacy DB doesn't exist", async () => {
272
+ // Reset flag to ensure fresh check
273
+ resetMigrationCheck();
274
+
275
+ const swarmMail = await createInMemorySwarmMail("test-no-legacy");
276
+ const db = await swarmMail.getDatabase();
277
+
278
+ // Should not throw or log errors
279
+ const adapter = await createMemoryAdapter(db);
280
+
281
+ expect(adapter).toBeDefined();
282
+ await swarmMail.close();
283
+ });
284
+
285
+ test("skips auto-migration when target already has data", async () => {
286
+ const swarmMail = await createInMemorySwarmMail("test-has-data");
287
+ const db = await swarmMail.getDatabase();
288
+
289
+ // Reset flag to ensure first call checks migration
290
+ resetMigrationCheck();
291
+
292
+ // Pre-populate with a memory
293
+ const adapter1 = await createMemoryAdapter(db);
294
+ await adapter1.store({ information: "Existing memory" });
295
+
296
+ // Get count before second call
297
+ const statsBefore = await adapter1.stats();
298
+
299
+ // Reset flag to force re-check on second call
300
+ resetMigrationCheck();
301
+
302
+ // Second call should skip migration because target has data
303
+ const adapter2 = await createMemoryAdapter(db);
304
+ const statsAfter = await adapter2.stats();
305
+
306
+ // Should not have added more memories (no migration ran)
307
+ expect(statsAfter.memories).toBe(statsBefore.memories);
308
+
309
+ await swarmMail.close();
310
+ });
311
+
312
+ test("migration check only runs once per module lifetime", async () => {
313
+ const swarmMail = await createInMemorySwarmMail("test-once");
314
+ const db = await swarmMail.getDatabase();
315
+
316
+ // First call - may do migration
317
+ const adapter1 = await createMemoryAdapter(db);
318
+
319
+ // Subsequent calls should be fast (no migration check)
320
+ const startTime = Date.now();
321
+ const adapter2 = await createMemoryAdapter(db);
322
+ const adapter3 = await createMemoryAdapter(db);
323
+ const elapsed = Date.now() - startTime;
324
+
325
+ // Second and third calls should be very fast since flag is set
326
+ expect(elapsed).toBeLessThan(100);
327
+
328
+ expect(adapter1).toBeDefined();
329
+ expect(adapter2).toBeDefined();
330
+ expect(adapter3).toBeDefined();
331
+
332
+ await swarmMail.close();
333
+ });
334
+ });