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.
Files changed (215) hide show
  1. package/bin/swarm.serve.test.ts +6 -4
  2. package/bin/swarm.ts +18 -12
  3. package/dist/compaction-prompt-scoring.js +139 -0
  4. package/dist/eval-capture.js +12811 -0
  5. package/dist/hive.d.ts.map +1 -1
  6. package/dist/hive.js +14834 -0
  7. package/dist/index.d.ts +18 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +7743 -62593
  10. package/dist/plugin.js +24052 -78907
  11. package/dist/swarm-orchestrate.d.ts.map +1 -1
  12. package/dist/swarm-prompts.d.ts.map +1 -1
  13. package/dist/swarm-prompts.js +39407 -0
  14. package/dist/swarm-review.d.ts.map +1 -1
  15. package/dist/swarm-validation.d.ts +127 -0
  16. package/dist/swarm-validation.d.ts.map +1 -0
  17. package/dist/validators/index.d.ts +7 -0
  18. package/dist/validators/index.d.ts.map +1 -0
  19. package/dist/validators/schema-validator.d.ts +58 -0
  20. package/dist/validators/schema-validator.d.ts.map +1 -0
  21. package/package.json +17 -5
  22. package/.changeset/swarm-insights-data-layer.md +0 -63
  23. package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
  24. package/.hive/analysis/session-data-quality-audit.md +0 -320
  25. package/.hive/eval-results.json +0 -483
  26. package/.hive/issues.jsonl +0 -138
  27. package/.hive/memories.jsonl +0 -729
  28. package/.opencode/eval-history.jsonl +0 -327
  29. package/.turbo/turbo-build.log +0 -9
  30. package/CHANGELOG.md +0 -2286
  31. package/SCORER-ANALYSIS.md +0 -598
  32. package/docs/analysis/subagent-coordination-patterns.md +0 -902
  33. package/docs/analysis-socratic-planner-pattern.md +0 -504
  34. package/docs/planning/ADR-001-monorepo-structure.md +0 -171
  35. package/docs/planning/ADR-002-package-extraction.md +0 -393
  36. package/docs/planning/ADR-003-performance-improvements.md +0 -451
  37. package/docs/planning/ADR-004-message-queue-features.md +0 -187
  38. package/docs/planning/ADR-005-devtools-observability.md +0 -202
  39. package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
  40. package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
  41. package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
  42. package/docs/planning/ADR-010-cass-inhousing.md +0 -1215
  43. package/docs/planning/ROADMAP.md +0 -368
  44. package/docs/semantic-memory-cli-syntax.md +0 -123
  45. package/docs/swarm-mail-architecture.md +0 -1147
  46. package/docs/testing/context-recovery-test.md +0 -470
  47. package/evals/ARCHITECTURE.md +0 -1189
  48. package/evals/README.md +0 -768
  49. package/evals/compaction-prompt.eval.ts +0 -149
  50. package/evals/compaction-resumption.eval.ts +0 -289
  51. package/evals/coordinator-behavior.eval.ts +0 -307
  52. package/evals/coordinator-session.eval.ts +0 -154
  53. package/evals/evalite.config.ts.bak +0 -15
  54. package/evals/example.eval.ts +0 -31
  55. package/evals/fixtures/cass-baseline.ts +0 -217
  56. package/evals/fixtures/compaction-cases.ts +0 -350
  57. package/evals/fixtures/compaction-prompt-cases.ts +0 -311
  58. package/evals/fixtures/coordinator-sessions.ts +0 -328
  59. package/evals/fixtures/decomposition-cases.ts +0 -105
  60. package/evals/lib/compaction-loader.test.ts +0 -248
  61. package/evals/lib/compaction-loader.ts +0 -320
  62. package/evals/lib/data-loader.evalite-test.ts +0 -289
  63. package/evals/lib/data-loader.test.ts +0 -345
  64. package/evals/lib/data-loader.ts +0 -281
  65. package/evals/lib/llm.ts +0 -115
  66. package/evals/scorers/compaction-prompt-scorers.ts +0 -145
  67. package/evals/scorers/compaction-scorers.ts +0 -305
  68. package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
  69. package/evals/scorers/coordinator-discipline.ts +0 -325
  70. package/evals/scorers/index.test.ts +0 -146
  71. package/evals/scorers/index.ts +0 -328
  72. package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
  73. package/evals/scorers/outcome-scorers.ts +0 -349
  74. package/evals/swarm-decomposition.eval.ts +0 -121
  75. package/examples/commands/swarm.md +0 -745
  76. package/examples/plugin-wrapper-template.ts +0 -2515
  77. package/examples/skills/hive-workflow/SKILL.md +0 -212
  78. package/examples/skills/skill-creator/SKILL.md +0 -223
  79. package/examples/skills/swarm-coordination/SKILL.md +0 -292
  80. package/global-skills/cli-builder/SKILL.md +0 -344
  81. package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
  82. package/global-skills/learning-systems/SKILL.md +0 -644
  83. package/global-skills/skill-creator/LICENSE.txt +0 -202
  84. package/global-skills/skill-creator/SKILL.md +0 -352
  85. package/global-skills/skill-creator/references/output-patterns.md +0 -82
  86. package/global-skills/skill-creator/references/workflows.md +0 -28
  87. package/global-skills/swarm-coordination/SKILL.md +0 -995
  88. package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
  89. package/global-skills/swarm-coordination/references/strategies.md +0 -138
  90. package/global-skills/system-design/SKILL.md +0 -213
  91. package/global-skills/testing-patterns/SKILL.md +0 -430
  92. package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
  93. package/opencode-swarm-plugin-0.30.7.tgz +0 -0
  94. package/opencode-swarm-plugin-0.31.0.tgz +0 -0
  95. package/scripts/cleanup-test-memories.ts +0 -346
  96. package/scripts/init-skill.ts +0 -222
  97. package/scripts/migrate-unknown-sessions.ts +0 -349
  98. package/scripts/validate-skill.ts +0 -204
  99. package/src/agent-mail.ts +0 -1724
  100. package/src/anti-patterns.test.ts +0 -1167
  101. package/src/anti-patterns.ts +0 -448
  102. package/src/compaction-capture.integration.test.ts +0 -257
  103. package/src/compaction-hook.test.ts +0 -838
  104. package/src/compaction-hook.ts +0 -1204
  105. package/src/compaction-observability.integration.test.ts +0 -139
  106. package/src/compaction-observability.test.ts +0 -187
  107. package/src/compaction-observability.ts +0 -324
  108. package/src/compaction-prompt-scorers.test.ts +0 -475
  109. package/src/compaction-prompt-scoring.ts +0 -300
  110. package/src/contributor-tools.test.ts +0 -133
  111. package/src/contributor-tools.ts +0 -201
  112. package/src/dashboard.test.ts +0 -611
  113. package/src/dashboard.ts +0 -462
  114. package/src/error-enrichment.test.ts +0 -403
  115. package/src/error-enrichment.ts +0 -219
  116. package/src/eval-capture.test.ts +0 -1015
  117. package/src/eval-capture.ts +0 -929
  118. package/src/eval-gates.test.ts +0 -306
  119. package/src/eval-gates.ts +0 -218
  120. package/src/eval-history.test.ts +0 -508
  121. package/src/eval-history.ts +0 -214
  122. package/src/eval-learning.test.ts +0 -378
  123. package/src/eval-learning.ts +0 -360
  124. package/src/eval-runner.test.ts +0 -223
  125. package/src/eval-runner.ts +0 -402
  126. package/src/export-tools.test.ts +0 -476
  127. package/src/export-tools.ts +0 -257
  128. package/src/hive.integration.test.ts +0 -2241
  129. package/src/hive.ts +0 -1628
  130. package/src/index.ts +0 -940
  131. package/src/learning.integration.test.ts +0 -1815
  132. package/src/learning.ts +0 -1079
  133. package/src/logger.test.ts +0 -189
  134. package/src/logger.ts +0 -135
  135. package/src/mandate-promotion.test.ts +0 -473
  136. package/src/mandate-promotion.ts +0 -239
  137. package/src/mandate-storage.integration.test.ts +0 -601
  138. package/src/mandate-storage.test.ts +0 -578
  139. package/src/mandate-storage.ts +0 -794
  140. package/src/mandates.ts +0 -540
  141. package/src/memory-tools.test.ts +0 -195
  142. package/src/memory-tools.ts +0 -344
  143. package/src/memory.integration.test.ts +0 -334
  144. package/src/memory.test.ts +0 -158
  145. package/src/memory.ts +0 -527
  146. package/src/model-selection.test.ts +0 -188
  147. package/src/model-selection.ts +0 -68
  148. package/src/observability-tools.test.ts +0 -359
  149. package/src/observability-tools.ts +0 -871
  150. package/src/output-guardrails.test.ts +0 -438
  151. package/src/output-guardrails.ts +0 -381
  152. package/src/pattern-maturity.test.ts +0 -1160
  153. package/src/pattern-maturity.ts +0 -525
  154. package/src/planning-guardrails.test.ts +0 -491
  155. package/src/planning-guardrails.ts +0 -438
  156. package/src/plugin.ts +0 -23
  157. package/src/post-compaction-tracker.test.ts +0 -251
  158. package/src/post-compaction-tracker.ts +0 -237
  159. package/src/query-tools.test.ts +0 -636
  160. package/src/query-tools.ts +0 -324
  161. package/src/rate-limiter.integration.test.ts +0 -466
  162. package/src/rate-limiter.ts +0 -774
  163. package/src/replay-tools.test.ts +0 -496
  164. package/src/replay-tools.ts +0 -240
  165. package/src/repo-crawl.integration.test.ts +0 -441
  166. package/src/repo-crawl.ts +0 -610
  167. package/src/schemas/cell-events.test.ts +0 -347
  168. package/src/schemas/cell-events.ts +0 -807
  169. package/src/schemas/cell.ts +0 -257
  170. package/src/schemas/evaluation.ts +0 -166
  171. package/src/schemas/index.test.ts +0 -199
  172. package/src/schemas/index.ts +0 -286
  173. package/src/schemas/mandate.ts +0 -232
  174. package/src/schemas/swarm-context.ts +0 -115
  175. package/src/schemas/task.ts +0 -161
  176. package/src/schemas/worker-handoff.test.ts +0 -302
  177. package/src/schemas/worker-handoff.ts +0 -131
  178. package/src/sessions/agent-discovery.test.ts +0 -137
  179. package/src/sessions/agent-discovery.ts +0 -112
  180. package/src/sessions/index.ts +0 -15
  181. package/src/skills.integration.test.ts +0 -1192
  182. package/src/skills.test.ts +0 -643
  183. package/src/skills.ts +0 -1549
  184. package/src/storage.integration.test.ts +0 -341
  185. package/src/storage.ts +0 -884
  186. package/src/structured.integration.test.ts +0 -817
  187. package/src/structured.test.ts +0 -1046
  188. package/src/structured.ts +0 -762
  189. package/src/swarm-decompose.test.ts +0 -188
  190. package/src/swarm-decompose.ts +0 -1302
  191. package/src/swarm-deferred.integration.test.ts +0 -157
  192. package/src/swarm-deferred.test.ts +0 -38
  193. package/src/swarm-insights.test.ts +0 -214
  194. package/src/swarm-insights.ts +0 -459
  195. package/src/swarm-mail.integration.test.ts +0 -970
  196. package/src/swarm-mail.ts +0 -739
  197. package/src/swarm-orchestrate.integration.test.ts +0 -282
  198. package/src/swarm-orchestrate.test.ts +0 -548
  199. package/src/swarm-orchestrate.ts +0 -3084
  200. package/src/swarm-prompts.test.ts +0 -1270
  201. package/src/swarm-prompts.ts +0 -2077
  202. package/src/swarm-research.integration.test.ts +0 -701
  203. package/src/swarm-research.test.ts +0 -698
  204. package/src/swarm-research.ts +0 -472
  205. package/src/swarm-review.integration.test.ts +0 -285
  206. package/src/swarm-review.test.ts +0 -879
  207. package/src/swarm-review.ts +0 -709
  208. package/src/swarm-strategies.ts +0 -407
  209. package/src/swarm-worktree.test.ts +0 -501
  210. package/src/swarm-worktree.ts +0 -575
  211. package/src/swarm.integration.test.ts +0 -2377
  212. package/src/swarm.ts +0 -38
  213. package/src/tool-adapter.integration.test.ts +0 -1221
  214. package/src/tool-availability.ts +0 -461
  215. package/tsconfig.json +0 -28
@@ -1,334 +0,0 @@
1
- /**
2
- * Memory Auto-Migration Integration Tests
3
- *
4
- * Tests the auto-migration flow in createMemoryAdapter():
5
- * 1. Detects legacy database (~/.semantic-memory/memory)
6
- * 2. Checks if target database is empty
7
- * 3. Migrates memories automatically on first createMemoryAdapter() call
8
- * 4. Module-level flag prevents repeated checks (performance optimization)
9
- *
10
- * ## Test Pattern
11
- * - Uses in-memory databases for fast, isolated tests
12
- * - Verifies migration runs when conditions are met
13
- * - Verifies migration is skipped when conditions aren't met
14
- * - Uses resetMigrationCheck() for test isolation between tests
15
- *
16
- * ## Note on Real Legacy Database
17
- * If ~/.semantic-memory/memory exists on the test machine, migration will
18
- * actually run and import real memories. Tests are written to handle both
19
- * scenarios (legacy DB exists vs doesn't exist). This proves the migration
20
- * works end-to-end in real conditions!
21
- */
22
-
23
- import { describe, expect, it, beforeEach, afterEach } from "bun:test";
24
- import {
25
- type DatabaseAdapter,
26
- type SwarmMailAdapter,
27
- createInMemorySwarmMail,
28
- } from "swarm-mail";
29
- import { createMemoryAdapter, resetMigrationCheck } from "./memory";
30
-
31
- /**
32
- * Create complete memory schema for test database
33
- * Matches swarm-mail/src/memory/test-utils.ts createTestMemoryDb()
34
- */
35
- async function createMemorySchema(adapter: DatabaseAdapter): Promise<void> {
36
- // Create memories table with vector column
37
- await adapter.query(`
38
- CREATE TABLE IF NOT EXISTS memories (
39
- id TEXT PRIMARY KEY,
40
- content TEXT NOT NULL,
41
- metadata TEXT DEFAULT '{}',
42
- collection TEXT DEFAULT 'default',
43
- tags TEXT DEFAULT '[]',
44
- created_at TEXT DEFAULT (datetime('now')),
45
- updated_at TEXT DEFAULT (datetime('now')),
46
- decay_factor REAL DEFAULT 0.7,
47
- embedding F32_BLOB(1024)
48
- )
49
- `);
50
-
51
- // Create FTS5 virtual table for full-text search (skip if exists)
52
- try {
53
- await adapter.query(`
54
- CREATE VIRTUAL TABLE memories_fts USING fts5(
55
- content,
56
- content='memories',
57
- content_rowid='rowid'
58
- )
59
- `);
60
- } catch (e) {
61
- // Ignore "table already exists" error
62
- if (!(e instanceof Error && e.message.includes("already exists"))) {
63
- throw e;
64
- }
65
- }
66
-
67
- // Create triggers to keep FTS in sync
68
- await adapter.query(`
69
- CREATE TRIGGER memories_ai AFTER INSERT ON memories BEGIN
70
- INSERT INTO memories_fts(rowid, content) VALUES (NEW.rowid, NEW.content);
71
- END
72
- `);
73
- await adapter.query(`
74
- CREATE TRIGGER memories_ad AFTER DELETE ON memories BEGIN
75
- INSERT INTO memories_fts(memories_fts, rowid, content) VALUES('delete', OLD.rowid, OLD.content);
76
- END
77
- `);
78
- await adapter.query(`
79
- CREATE TRIGGER memories_au AFTER UPDATE ON memories BEGIN
80
- INSERT INTO memories_fts(memories_fts, rowid, content) VALUES('delete', OLD.rowid, OLD.content);
81
- INSERT INTO memories_fts(rowid, content) VALUES (NEW.rowid, NEW.content);
82
- END
83
- `);
84
-
85
- // Create vector index for similarity search (CRITICAL - required for vector_top_k)
86
- await adapter.query(`
87
- CREATE INDEX idx_memories_embedding ON memories(libsql_vector_idx(embedding))
88
- `);
89
-
90
- // Insert a marker memory to prevent auto-migration from running in tests
91
- // (Auto-migration only runs when target DB is empty. These tests are NOT testing migration.)
92
- await insertTestMemory(adapter, "mem_test_init", "Test setup marker");
93
- }
94
-
95
- /**
96
- * Insert test memory directly into database (bypassing adapter)
97
- * Updated for libSQL schema (embedding inline, not separate table)
98
- */
99
- async function insertTestMemory(
100
- adapter: DatabaseAdapter,
101
- id: string,
102
- content: string,
103
- ): Promise<void> {
104
- // Generate a dummy embedding (1024 dimensions)
105
- const dummyEmbedding = new Float32Array(1024);
106
- for (let i = 0; i < 1024; i++) {
107
- dummyEmbedding[i] = 0.1;
108
- }
109
-
110
- // Insert memory with embedding inline (libSQL schema)
111
- await adapter.query(
112
- `INSERT INTO memories (id, content, metadata, collection, created_at, embedding)
113
- VALUES ($1, $2, $3, $4, datetime('now'), vector32($5))`,
114
- [id, content, JSON.stringify({}), "default", JSON.stringify(Array.from(dummyEmbedding))],
115
- );
116
- }
117
-
118
- describe("Memory Auto-Migration Integration", () => {
119
- let legacySwarmMail: SwarmMailAdapter | null = null;
120
- let targetSwarmMail: SwarmMailAdapter | null = null;
121
-
122
- beforeEach(async () => {
123
- // Reset module-level migration flag
124
- resetMigrationCheck();
125
- });
126
-
127
- afterEach(async () => {
128
- // Close databases
129
- if (legacySwarmMail) {
130
- await legacySwarmMail.close();
131
- legacySwarmMail = null;
132
- }
133
- if (targetSwarmMail) {
134
- await targetSwarmMail.close();
135
- targetSwarmMail = null;
136
- }
137
- });
138
-
139
- it("should auto-migrate when legacy exists and target is empty", async () => {
140
- // Setup: Create target DB with proper schema
141
- // Note: createInMemorySwarmMail now creates memory schema automatically
142
- targetSwarmMail = await createInMemorySwarmMail("target-test");
143
- const targetDb = await targetSwarmMail.getDatabase();
144
-
145
- // Insert test marker to skip auto-migration
146
- await insertTestMemory(targetDb, "mem_test_init", "Test setup marker");
147
-
148
- // Verify target has memories (marker inserted)
149
- const countBefore = await targetDb.query<{ count: string }>(
150
- "SELECT COUNT(*) as count FROM memories",
151
- );
152
- expect(parseInt(countBefore.rows[0].count)).toBeGreaterThanOrEqual(1);
153
-
154
- // Action: Call createMemoryAdapter
155
- // Note: Auto-migration will be skipped because target DB is not empty
156
- const adapter = await createMemoryAdapter(targetDb);
157
- expect(adapter).toBeDefined();
158
-
159
- // Verify adapter is functional
160
- const stats = await adapter.stats();
161
- expect(stats.memories).toBeGreaterThanOrEqual(1);
162
- expect(stats.embeddings).toBeGreaterThanOrEqual(1);
163
- });
164
-
165
- it("should skip migration when target already has memories", async () => {
166
- // Setup: Create target DB with existing memory
167
- // Note: createInMemorySwarmMail now creates memory schema automatically
168
- targetSwarmMail = await createInMemorySwarmMail("target-test");
169
- const targetDb = await targetSwarmMail.getDatabase();
170
-
171
- // Insert test marker
172
- await insertTestMemory(targetDb, "mem_test_init", "Test setup marker");
173
-
174
- await insertTestMemory(targetDb, "mem_existing", "Existing memory in target");
175
-
176
- // Verify target has memories (marker + existing = 2)
177
- const countBefore = await targetDb.query<{ count: string }>(
178
- "SELECT COUNT(*) as count FROM memories",
179
- );
180
- expect(parseInt(countBefore.rows[0].count)).toBe(2);
181
-
182
- // Action: Call createMemoryAdapter
183
- const adapter = await createMemoryAdapter(targetDb);
184
- expect(adapter).toBeDefined();
185
-
186
- // Verify no migration occurred (count unchanged)
187
- const countAfter = await targetDb.query<{ count: string }>(
188
- "SELECT COUNT(*) as count FROM memories",
189
- );
190
- expect(parseInt(countAfter.rows[0].count)).toBe(2);
191
-
192
- // Verify adapter works
193
- const stats = await adapter.stats();
194
- expect(stats.memories).toBe(2);
195
- });
196
-
197
- it("should skip migration when no legacy DB exists OR target has memories", async () => {
198
- // Setup: Create target DB (empty)
199
- // Note: createInMemorySwarmMail now creates memory schema automatically
200
- targetSwarmMail = await createInMemorySwarmMail("target-test");
201
- const targetDb = await targetSwarmMail.getDatabase();
202
-
203
- // Insert test marker to skip auto-migration
204
- await insertTestMemory(targetDb, "mem_test_init", "Test setup marker");
205
-
206
- // Verify target has marker memory
207
- const countBefore = await targetDb.query<{ count: string }>(
208
- "SELECT COUNT(*) as count FROM memories",
209
- );
210
- const beforeCount = parseInt(countBefore.rows[0].count);
211
- expect(beforeCount).toBeGreaterThanOrEqual(1);
212
-
213
- // Action: Call createMemoryAdapter
214
- // If legacy DB exists at ~/.semantic-memory/memory, migration will run
215
- // If not, adapter creation succeeds with empty DB
216
- const adapter = await createMemoryAdapter(targetDb);
217
- expect(adapter).toBeDefined();
218
-
219
- // Verify adapter works
220
- const stats = await adapter.stats();
221
- expect(stats.memories).toBeGreaterThanOrEqual(0);
222
- expect(stats.embeddings).toBeGreaterThanOrEqual(0);
223
-
224
- // If migration ran, stats.memories > 0
225
- // If no legacy DB, stats.memories == 0
226
- // Both outcomes are valid for this test
227
- });
228
-
229
- it("should only check migration once (module-level flag)", async () => {
230
- // Setup: Create target DB
231
- // Note: createInMemorySwarmMail now creates memory schema automatically
232
- targetSwarmMail = await createInMemorySwarmMail("target-test");
233
- const targetDb = await targetSwarmMail.getDatabase();
234
-
235
- // Insert test marker
236
- await insertTestMemory(targetDb, "mem_test_init", "Test setup marker");
237
-
238
- // First call - migration check runs (may or may not migrate depending on legacy DB)
239
- const adapter1 = await createMemoryAdapter(targetDb);
240
- expect(adapter1).toBeDefined();
241
-
242
- const stats1 = await adapter1.stats();
243
- const afterFirstCall = stats1.memories;
244
-
245
- // Second call - migration check should be skipped (flag is set)
246
- // Memory count should NOT change between first and second call
247
- const adapter2 = await createMemoryAdapter(targetDb);
248
- expect(adapter2).toBeDefined();
249
-
250
- const stats2 = await adapter2.stats();
251
- expect(stats2.memories).toBe(afterFirstCall); // Same as after first call
252
-
253
- // Both adapters should work
254
- expect(stats1.embeddings).toBe(stats2.embeddings);
255
- });
256
-
257
- it("should reset migration check flag when explicitly called", async () => {
258
- // Setup: Create target DB
259
- // Note: createInMemorySwarmMail now creates memory schema automatically
260
- targetSwarmMail = await createInMemorySwarmMail("target-test");
261
- const targetDb = await targetSwarmMail.getDatabase();
262
-
263
- // Insert test marker
264
- await insertTestMemory(targetDb, "mem_test_init", "Test setup marker");
265
-
266
- // First call
267
- const adapter1 = await createMemoryAdapter(targetDb);
268
- const stats1 = await adapter1.stats();
269
- const afterFirstCall = stats1.memories;
270
-
271
- // Reset flag
272
- resetMigrationCheck();
273
-
274
- // Second call should check migration again (but if target has memories, skip)
275
- const adapter2 = await createMemoryAdapter(targetDb);
276
- expect(adapter2).toBeDefined();
277
-
278
- // If target has memories from first call, migration won't run again
279
- // Count should not increase
280
- const stats2 = await adapter2.stats();
281
- expect(stats2.memories).toBe(afterFirstCall);
282
- expect(stats2.embeddings).toBeGreaterThanOrEqual(0);
283
- });
284
-
285
- it("should handle migration errors gracefully (no throw)", async () => {
286
- // Setup: Create target DB
287
- // Note: createInMemorySwarmMail now creates memory schema automatically
288
- targetSwarmMail = await createInMemorySwarmMail("target-test");
289
- const targetDb = await targetSwarmMail.getDatabase();
290
-
291
- // Insert test marker
292
- await insertTestMemory(targetDb, "mem_test_init", "Test setup marker");
293
-
294
- // Action: Call createMemoryAdapter
295
- // Even if migration fails internally, it should not throw
296
- const adapter = await createMemoryAdapter(targetDb);
297
- expect(adapter).toBeDefined();
298
-
299
- // Adapter should work normally
300
- const stats = await adapter.stats();
301
- expect(stats.memories).toBeGreaterThanOrEqual(0);
302
- expect(stats.embeddings).toBeGreaterThanOrEqual(0);
303
- });
304
-
305
- it("should create functional adapter after migration", async () => {
306
- // Setup: Create target DB
307
- // Note: createInMemorySwarmMail now creates memory schema automatically
308
- targetSwarmMail = await createInMemorySwarmMail("target-test");
309
- const targetDb = await targetSwarmMail.getDatabase();
310
-
311
- // Insert test marker
312
- await insertTestMemory(targetDb, "mem_test_init", "Test setup marker");
313
-
314
- // Action: Create adapter
315
- const adapter = await createMemoryAdapter(targetDb);
316
-
317
- // Verify adapter has all expected methods
318
- expect(typeof adapter.store).toBe("function");
319
- expect(typeof adapter.find).toBe("function");
320
- expect(typeof adapter.get).toBe("function");
321
- expect(typeof adapter.remove).toBe("function");
322
- expect(typeof adapter.validate).toBe("function");
323
- expect(typeof adapter.list).toBe("function");
324
- expect(typeof adapter.stats).toBe("function");
325
- expect(typeof adapter.checkHealth).toBe("function");
326
-
327
- // Verify basic operations work
328
- const stats = await adapter.stats();
329
- expect(stats).toHaveProperty("memories");
330
- expect(stats).toHaveProperty("embeddings");
331
- expect(typeof stats.memories).toBe("number");
332
- expect(typeof stats.embeddings).toBe("number");
333
- });
334
- });
@@ -1,158 +0,0 @@
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, afterEach } 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
22
- // Note: createInMemorySwarmMail now creates memory schema automatically
23
- swarmMail = await createInMemorySwarmMail("test-memory");
24
- const db = await swarmMail.getDatabase();
25
-
26
- // Insert a dummy memory to prevent auto-migration from running
27
- await db.query(`
28
- INSERT INTO memories (id, content, collection, created_at)
29
- VALUES ($1, $2, $3, datetime('now'))
30
- `, ['mem_init', 'Test setup marker', 'default']);
31
-
32
- adapter = await createMemoryAdapter(db);
33
- });
34
-
35
- afterAll(async () => {
36
- await swarmMail.close();
37
- });
38
-
39
- describe("store", () => {
40
- test("stores memory with auto-generated ID", async () => {
41
- const result = await adapter.store({
42
- information: "OAuth refresh tokens need 5min buffer",
43
- tags: "auth,tokens",
44
- metadata: JSON.stringify({ project: "test" }),
45
- });
46
-
47
- expect(result.id).toBeDefined();
48
- expect(result.id).toMatch(/^mem-/); // Real swarm-mail adapter uses 'mem-' prefix
49
- expect(result.message).toContain("Stored memory");
50
- });
51
-
52
- test("stores memory with explicit collection", async () => {
53
- const result = await adapter.store({
54
- information: "Test memory",
55
- collection: "project-alpha",
56
- });
57
-
58
- expect(result.id).toMatch(/^mem-/); // Real swarm-mail adapter uses 'mem-' prefix
59
- expect(result.message).toContain("collection: project-alpha");
60
- });
61
- });
62
-
63
- describe("find", () => {
64
- test("returns results sorted by relevance score", async () => {
65
- // Store some test memories
66
- await adapter.store({ information: "Test memory about cats" });
67
- await adapter.store({ information: "Test memory about dogs" });
68
-
69
- // Query for cats - should return relevant results first
70
- const results = await adapter.find({
71
- query: "cats felines",
72
- limit: 5,
73
- });
74
-
75
- // Should find at least the cat memory
76
- expect(results.count).toBeGreaterThan(0);
77
- // Results should be in descending score order
78
- for (let i = 1; i < results.results.length; i++) {
79
- expect(results.results[i - 1].score).toBeGreaterThanOrEqual(results.results[i].score);
80
- }
81
- });
82
-
83
- test("finds stored memories by semantic similarity", async () => {
84
- // Store a memory
85
- await adapter.store({
86
- information: "Next.js 16 Cache Components need Suspense boundaries",
87
- tags: "nextjs,caching",
88
- });
89
-
90
- // Search for it
91
- const results = await adapter.find({
92
- query: "nextjs cache suspense",
93
- limit: 5,
94
- });
95
-
96
- // Should find at least one result
97
- expect(results.count).toBeGreaterThan(0);
98
- });
99
- });
100
-
101
- describe("stats", () => {
102
- test("returns memory and embedding counts", async () => {
103
- const stats = await adapter.stats();
104
-
105
- expect(typeof stats.memories).toBe("number");
106
- expect(typeof stats.embeddings).toBe("number");
107
- expect(stats.memories).toBeGreaterThanOrEqual(0);
108
- expect(stats.embeddings).toBeGreaterThanOrEqual(0);
109
- });
110
- });
111
-
112
- describe("checkHealth", () => {
113
- test("returns health status", async () => {
114
- const health = await adapter.checkHealth();
115
-
116
- expect(typeof health.ollama).toBe("boolean");
117
- // message is only present when ollama is false
118
- if (!health.ollama) {
119
- expect(typeof health.message).toBe("string");
120
- }
121
- });
122
- });
123
- });
124
-
125
- describe("auto-migration on createMemoryAdapter", () => {
126
- let swarmMail: SwarmMailAdapter;
127
-
128
- beforeEach(() => {
129
- // Reset migration check flag before each test
130
- resetMigrationCheck();
131
- });
132
-
133
- afterEach(async () => {
134
- if (swarmMail) {
135
- await swarmMail.close();
136
- }
137
- });
138
-
139
- test("skips auto-migration when target already has data", async () => {
140
- // Create in-memory SwarmMail
141
- // Note: createInMemorySwarmMail now creates memory schema automatically
142
- swarmMail = await createInMemorySwarmMail("test-migration");
143
- const db = await swarmMail.getDatabase();
144
-
145
- // Insert a marker memory to simulate existing data
146
- await db.query(`
147
- INSERT INTO memories (id, content, collection, created_at)
148
- VALUES ($1, $2, $3, datetime('now'))
149
- `, ['mem_existing', 'Existing memory', 'default']);
150
-
151
- // Create adapter - should skip migration because target has data
152
- const adapter = await createMemoryAdapter(db);
153
-
154
- // Verify adapter works
155
- const stats = await adapter.stats();
156
- expect(stats.memories).toBeGreaterThanOrEqual(1);
157
- });
158
- });