opencode-swarm-plugin 0.44.0 → 0.44.1
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 +16 -10
- 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/index.js +7644 -62599
- package/dist/plugin.js +23766 -78721
- package/dist/swarm-orchestrate.d.ts.map +1 -1
- package/dist/swarm-prompts.d.ts.map +1 -1
- package/dist/swarm-review.d.ts.map +1 -1
- 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/memory.ts
DELETED
|
@@ -1,527 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Module - Semantic Memory Adapter
|
|
3
|
-
*
|
|
4
|
-
* Provides a high-level adapter around swarm-mail's MemoryStore + Ollama.
|
|
5
|
-
* Used by semantic-memory_* tools in the plugin.
|
|
6
|
-
*
|
|
7
|
-
* ## Design
|
|
8
|
-
* - Wraps MemoryStore (vector storage) + Ollama (embeddings)
|
|
9
|
-
* - Handles ID generation, metadata parsing, error handling
|
|
10
|
-
* - Tool-friendly API (string inputs/outputs, no Effect-TS in signatures)
|
|
11
|
-
*
|
|
12
|
-
* ## Usage
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const adapter = await createMemoryAdapter(swarmMail.db);
|
|
15
|
-
*
|
|
16
|
-
* // Store memory
|
|
17
|
-
* const { id } = await adapter.store({
|
|
18
|
-
* information: "OAuth tokens need 5min buffer",
|
|
19
|
-
* tags: "auth,tokens",
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* // Search memories
|
|
23
|
-
* const results = await adapter.find({
|
|
24
|
-
* query: "token refresh",
|
|
25
|
-
* limit: 5,
|
|
26
|
-
* });
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
import { Effect } from "effect";
|
|
31
|
-
import {
|
|
32
|
-
type DatabaseAdapter,
|
|
33
|
-
createMemoryStore,
|
|
34
|
-
getDefaultConfig,
|
|
35
|
-
makeOllamaLive,
|
|
36
|
-
Ollama,
|
|
37
|
-
type Memory,
|
|
38
|
-
type SearchResult,
|
|
39
|
-
legacyDatabaseExists,
|
|
40
|
-
migrateLegacyMemories,
|
|
41
|
-
toSwarmDb,
|
|
42
|
-
createMemoryAdapter as createSwarmMailAdapter,
|
|
43
|
-
type MemoryConfig,
|
|
44
|
-
} from "swarm-mail";
|
|
45
|
-
|
|
46
|
-
// ============================================================================
|
|
47
|
-
// Auto-Migration State
|
|
48
|
-
// ============================================================================
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Module-level flag to track if migration has been checked.
|
|
52
|
-
* After first check, we skip the expensive legacy DB check.
|
|
53
|
-
*/
|
|
54
|
-
let migrationChecked = false;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Reset migration check flag (for testing)
|
|
58
|
-
* @internal
|
|
59
|
-
*/
|
|
60
|
-
export function resetMigrationCheck(): void {
|
|
61
|
-
migrationChecked = false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ============================================================================
|
|
65
|
-
// Types
|
|
66
|
-
// ============================================================================
|
|
67
|
-
|
|
68
|
-
/** Arguments for store operation */
|
|
69
|
-
export interface StoreArgs {
|
|
70
|
-
readonly information: string;
|
|
71
|
-
readonly collection?: string;
|
|
72
|
-
readonly tags?: string;
|
|
73
|
-
readonly metadata?: string;
|
|
74
|
-
/** Confidence level (0.0-1.0) affecting decay rate. Higher = slower decay. Default 0.7 */
|
|
75
|
-
readonly confidence?: number;
|
|
76
|
-
/** Auto-generate tags using LLM. Default false */
|
|
77
|
-
readonly autoTag?: boolean;
|
|
78
|
-
/** Auto-link to related memories. Default false */
|
|
79
|
-
readonly autoLink?: boolean;
|
|
80
|
-
/** Extract entities (people, places, technologies). Default false */
|
|
81
|
-
readonly extractEntities?: boolean;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** Arguments for find operation */
|
|
85
|
-
export interface FindArgs {
|
|
86
|
-
readonly query: string;
|
|
87
|
-
readonly limit?: number;
|
|
88
|
-
readonly collection?: string;
|
|
89
|
-
readonly expand?: boolean;
|
|
90
|
-
readonly fts?: boolean;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** Arguments for get/remove/validate operations */
|
|
94
|
-
export interface IdArgs {
|
|
95
|
-
readonly id: string;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** Arguments for list operation */
|
|
99
|
-
export interface ListArgs {
|
|
100
|
-
readonly collection?: string;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** Result from store operation */
|
|
104
|
-
export interface StoreResult {
|
|
105
|
-
readonly id: string;
|
|
106
|
-
readonly message: string;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** Result from find operation */
|
|
110
|
-
export interface FindResult {
|
|
111
|
-
readonly results: Array<{
|
|
112
|
-
readonly id: string;
|
|
113
|
-
readonly content: string;
|
|
114
|
-
readonly score: number;
|
|
115
|
-
readonly collection: string;
|
|
116
|
-
readonly metadata: Record<string, unknown>;
|
|
117
|
-
readonly createdAt: string;
|
|
118
|
-
}>;
|
|
119
|
-
readonly count: number;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/** Result from stats operation */
|
|
123
|
-
export interface StatsResult {
|
|
124
|
-
readonly memories: number;
|
|
125
|
-
readonly embeddings: number;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** Result from health check */
|
|
129
|
-
export interface HealthResult {
|
|
130
|
-
readonly ollama: boolean;
|
|
131
|
-
readonly message?: string;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/** Result from validate/remove operations */
|
|
135
|
-
export interface OperationResult {
|
|
136
|
-
readonly success: boolean;
|
|
137
|
-
readonly message?: string;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** Arguments for upsert operation */
|
|
141
|
-
export interface UpsertArgs {
|
|
142
|
-
readonly information: string;
|
|
143
|
-
readonly collection?: string;
|
|
144
|
-
readonly tags?: string;
|
|
145
|
-
readonly metadata?: string;
|
|
146
|
-
readonly confidence?: number;
|
|
147
|
-
/** Auto-generate tags using LLM. Default true */
|
|
148
|
-
readonly autoTag?: boolean;
|
|
149
|
-
/** Auto-link to related memories. Default true */
|
|
150
|
-
readonly autoLink?: boolean;
|
|
151
|
-
/** Extract entities (people, places, technologies). Default false */
|
|
152
|
-
readonly extractEntities?: boolean;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** Auto-generated tags result */
|
|
156
|
-
export interface AutoTags {
|
|
157
|
-
readonly tags: string[];
|
|
158
|
-
readonly keywords: string[];
|
|
159
|
-
readonly category: string;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** Result from upsert operation */
|
|
163
|
-
export interface UpsertResult {
|
|
164
|
-
readonly operation: "ADD" | "UPDATE" | "DELETE" | "NOOP";
|
|
165
|
-
readonly reason: string;
|
|
166
|
-
readonly memoryId?: string;
|
|
167
|
-
readonly affectedMemoryIds?: string[];
|
|
168
|
-
readonly autoTags?: AutoTags;
|
|
169
|
-
readonly linksCreated?: number;
|
|
170
|
-
readonly entitiesExtracted?: number;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// ============================================================================
|
|
174
|
-
// Auto-Migration Logic
|
|
175
|
-
// ============================================================================
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Check and auto-migrate legacy memories if conditions are met
|
|
179
|
-
*
|
|
180
|
-
* Conditions:
|
|
181
|
-
* 1. Legacy database exists
|
|
182
|
-
* 2. Target database has 0 memories (first use)
|
|
183
|
-
*
|
|
184
|
-
* @param db - Target database adapter (for migration and count check)
|
|
185
|
-
*/
|
|
186
|
-
async function maybeAutoMigrate(db: DatabaseAdapter): Promise<void> {
|
|
187
|
-
try {
|
|
188
|
-
// Check if legacy database exists
|
|
189
|
-
if (!legacyDatabaseExists()) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Check if target database is empty using the legacy adapter
|
|
194
|
-
const countResult = await db.query<{ count: string }>(
|
|
195
|
-
"SELECT COUNT(*) as count FROM memories",
|
|
196
|
-
);
|
|
197
|
-
const memoryCount = parseInt(countResult.rows[0]?.count || "0");
|
|
198
|
-
|
|
199
|
-
if (memoryCount > 0) {
|
|
200
|
-
// Target already has memories, skip migration
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
console.log("[memory] Legacy database detected, starting auto-migration...");
|
|
205
|
-
|
|
206
|
-
// Run migration (still uses DatabaseAdapter)
|
|
207
|
-
const result = await migrateLegacyMemories({
|
|
208
|
-
targetDb: db,
|
|
209
|
-
dryRun: false,
|
|
210
|
-
onProgress: console.log,
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
if (result.migrated > 0) {
|
|
214
|
-
console.log(
|
|
215
|
-
`[memory] Auto-migrated ${result.migrated} memories from legacy database`,
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (result.failed > 0) {
|
|
220
|
-
console.warn(
|
|
221
|
-
`[memory] ${result.failed} memories failed to migrate. See errors above.`,
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
} catch (error) {
|
|
225
|
-
// Graceful degradation - log but don't throw
|
|
226
|
-
console.warn(
|
|
227
|
-
`[memory] Auto-migration failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// ============================================================================
|
|
233
|
-
// Memory Adapter
|
|
234
|
-
// ============================================================================
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Memory Adapter Interface
|
|
238
|
-
*
|
|
239
|
-
* High-level API for semantic memory operations.
|
|
240
|
-
*/
|
|
241
|
-
export interface MemoryAdapter {
|
|
242
|
-
readonly store: (args: StoreArgs) => Promise<StoreResult>;
|
|
243
|
-
readonly find: (args: FindArgs) => Promise<FindResult>;
|
|
244
|
-
readonly get: (args: IdArgs) => Promise<Memory | null>;
|
|
245
|
-
readonly remove: (args: IdArgs) => Promise<OperationResult>;
|
|
246
|
-
readonly validate: (args: IdArgs) => Promise<OperationResult>;
|
|
247
|
-
readonly list: (args: ListArgs) => Promise<Memory[]>;
|
|
248
|
-
readonly stats: () => Promise<StatsResult>;
|
|
249
|
-
readonly checkHealth: () => Promise<HealthResult>;
|
|
250
|
-
readonly upsert: (args: UpsertArgs) => Promise<UpsertResult>;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Create Memory Adapter
|
|
255
|
-
*
|
|
256
|
-
* @param db - DatabaseAdapter from swarm-mail's getDatabase()
|
|
257
|
-
* @returns Memory adapter with high-level operations
|
|
258
|
-
*
|
|
259
|
-
* @example
|
|
260
|
-
* ```typescript
|
|
261
|
-
* import { getSwarmMailLibSQL } from 'swarm-mail';
|
|
262
|
-
* import { createMemoryAdapter } from './memory';
|
|
263
|
-
*
|
|
264
|
-
* const swarmMail = await getSwarmMailLibSQL('/path/to/project');
|
|
265
|
-
* const db = await swarmMail.getDatabase();
|
|
266
|
-
* const adapter = await createMemoryAdapter(db);
|
|
267
|
-
*
|
|
268
|
-
* await adapter.store({ information: "Learning X" });
|
|
269
|
-
* const results = await adapter.find({ query: "X" });
|
|
270
|
-
* ```
|
|
271
|
-
*/
|
|
272
|
-
export async function createMemoryAdapter(
|
|
273
|
-
db: DatabaseAdapter,
|
|
274
|
-
): Promise<MemoryAdapter> {
|
|
275
|
-
// Auto-migrate legacy memories on first use
|
|
276
|
-
if (!migrationChecked) {
|
|
277
|
-
migrationChecked = true;
|
|
278
|
-
await maybeAutoMigrate(db);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Convert DatabaseAdapter to SwarmDb (Drizzle client) for real swarm-mail adapter
|
|
282
|
-
const drizzleDb = toSwarmDb(db);
|
|
283
|
-
const config = getDefaultConfig();
|
|
284
|
-
|
|
285
|
-
// Create real swarm-mail adapter with Wave 1-3 features
|
|
286
|
-
const realAdapter = createSwarmMailAdapter(drizzleDb, config);
|
|
287
|
-
|
|
288
|
-
// DEBUG: Check if upsert exists
|
|
289
|
-
if (!realAdapter || typeof realAdapter.upsert !== 'function') {
|
|
290
|
-
console.warn('[memory] realAdapter.upsert is not available:', {
|
|
291
|
-
hasAdapter: !!realAdapter,
|
|
292
|
-
upsertType: typeof realAdapter?.upsert,
|
|
293
|
-
methods: realAdapter ? Object.keys(realAdapter) : []
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// For backward compatibility, keep legacy adapter for methods not yet in real adapter
|
|
298
|
-
const store = createMemoryStore(drizzleDb);
|
|
299
|
-
const ollamaLayer = makeOllamaLive(config);
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Generate unique memory ID
|
|
303
|
-
*/
|
|
304
|
-
const generateId = (): string => {
|
|
305
|
-
const timestamp = Date.now().toString(36);
|
|
306
|
-
const random = Math.random().toString(36).substring(2, 9);
|
|
307
|
-
return `mem_${timestamp}_${random}`;
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Parse tags string to metadata object
|
|
312
|
-
*/
|
|
313
|
-
const parseTags = (tags?: string): string[] => {
|
|
314
|
-
if (!tags) return [];
|
|
315
|
-
return tags
|
|
316
|
-
.split(",")
|
|
317
|
-
.map((t) => t.trim())
|
|
318
|
-
.filter(Boolean);
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Truncate content for preview
|
|
323
|
-
*/
|
|
324
|
-
const truncateContent = (content: string, maxLength = 200): string => {
|
|
325
|
-
if (content.length <= maxLength) return content;
|
|
326
|
-
return `${content.substring(0, maxLength)}...`;
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
return {
|
|
330
|
-
/**
|
|
331
|
-
* Store a memory with embedding and optional auto-features
|
|
332
|
-
*
|
|
333
|
-
* Delegates to real swarm-mail adapter which supports:
|
|
334
|
-
* - autoTag: LLM-powered tag generation
|
|
335
|
-
* - autoLink: Semantic linking to related memories
|
|
336
|
-
* - extractEntities: Entity extraction and knowledge graph building
|
|
337
|
-
*/
|
|
338
|
-
async store(args: StoreArgs): Promise<StoreResult> {
|
|
339
|
-
// Delegate to real swarm-mail adapter
|
|
340
|
-
const result = await realAdapter.store(args.information, {
|
|
341
|
-
collection: args.collection,
|
|
342
|
-
tags: args.tags,
|
|
343
|
-
metadata: args.metadata,
|
|
344
|
-
confidence: args.confidence,
|
|
345
|
-
autoTag: args.autoTag,
|
|
346
|
-
autoLink: args.autoLink,
|
|
347
|
-
extractEntities: args.extractEntities,
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
// Build user-facing message
|
|
351
|
-
let message = `Stored memory ${result.id} in collection: ${args.collection ?? "default"}`;
|
|
352
|
-
|
|
353
|
-
if (result.autoTags) {
|
|
354
|
-
message += `\nAuto-tags: ${result.autoTags.tags.join(", ")}`;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
if (result.links && result.links.length > 0) {
|
|
358
|
-
message += `\nLinked to ${result.links.length} related memor${result.links.length === 1 ? "y" : "ies"}`;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
return {
|
|
362
|
-
id: result.id,
|
|
363
|
-
message,
|
|
364
|
-
};
|
|
365
|
-
},
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Find memories by semantic similarity or full-text search
|
|
369
|
-
*/
|
|
370
|
-
async find(args: FindArgs): Promise<FindResult> {
|
|
371
|
-
const limit = args.limit ?? 10;
|
|
372
|
-
|
|
373
|
-
let results: SearchResult[];
|
|
374
|
-
|
|
375
|
-
if (args.fts) {
|
|
376
|
-
// Full-text search
|
|
377
|
-
results = await store.ftsSearch(args.query, {
|
|
378
|
-
limit,
|
|
379
|
-
collection: args.collection,
|
|
380
|
-
});
|
|
381
|
-
} else {
|
|
382
|
-
// Vector search - generate query embedding
|
|
383
|
-
const program = Effect.gen(function* () {
|
|
384
|
-
const ollama = yield* Ollama;
|
|
385
|
-
return yield* ollama.embed(args.query);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
const queryEmbedding = await Effect.runPromise(
|
|
389
|
-
program.pipe(Effect.provide(ollamaLayer)),
|
|
390
|
-
);
|
|
391
|
-
|
|
392
|
-
results = await store.search(queryEmbedding, {
|
|
393
|
-
limit,
|
|
394
|
-
threshold: 0.3,
|
|
395
|
-
collection: args.collection,
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
return {
|
|
400
|
-
results: results.map((r) => ({
|
|
401
|
-
id: r.memory.id,
|
|
402
|
-
content: args.expand
|
|
403
|
-
? r.memory.content
|
|
404
|
-
: truncateContent(r.memory.content),
|
|
405
|
-
score: r.score,
|
|
406
|
-
collection: r.memory.collection,
|
|
407
|
-
metadata: r.memory.metadata,
|
|
408
|
-
createdAt: r.memory.createdAt.toISOString(),
|
|
409
|
-
})),
|
|
410
|
-
count: results.length,
|
|
411
|
-
};
|
|
412
|
-
},
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Get a single memory by ID
|
|
416
|
-
*/
|
|
417
|
-
async get(args: IdArgs): Promise<Memory | null> {
|
|
418
|
-
return store.get(args.id);
|
|
419
|
-
},
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Remove a memory
|
|
423
|
-
*/
|
|
424
|
-
async remove(args: IdArgs): Promise<OperationResult> {
|
|
425
|
-
await store.delete(args.id);
|
|
426
|
-
return {
|
|
427
|
-
success: true,
|
|
428
|
-
message: `Removed memory ${args.id}`,
|
|
429
|
-
};
|
|
430
|
-
},
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Validate a memory (reset decay timer)
|
|
434
|
-
*
|
|
435
|
-
* TODO: Implement decay tracking in MemoryStore
|
|
436
|
-
* For now, this is a no-op placeholder.
|
|
437
|
-
*/
|
|
438
|
-
async validate(args: IdArgs): Promise<OperationResult> {
|
|
439
|
-
const memory = await store.get(args.id);
|
|
440
|
-
if (!memory) {
|
|
441
|
-
return {
|
|
442
|
-
success: false,
|
|
443
|
-
message: `Memory ${args.id} not found`,
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// TODO: Implement decay reset in MemoryStore
|
|
448
|
-
// For now, just verify it exists
|
|
449
|
-
return {
|
|
450
|
-
success: true,
|
|
451
|
-
message: `Memory ${args.id} validated`,
|
|
452
|
-
};
|
|
453
|
-
},
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* List memories
|
|
457
|
-
*/
|
|
458
|
-
async list(args: ListArgs): Promise<Memory[]> {
|
|
459
|
-
return store.list(args.collection);
|
|
460
|
-
},
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* Get statistics
|
|
464
|
-
*/
|
|
465
|
-
async stats(): Promise<StatsResult> {
|
|
466
|
-
return store.getStats();
|
|
467
|
-
},
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Check Ollama health
|
|
471
|
-
*/
|
|
472
|
-
async checkHealth(): Promise<HealthResult> {
|
|
473
|
-
const program = Effect.gen(function* () {
|
|
474
|
-
const ollama = yield* Ollama;
|
|
475
|
-
return yield* ollama.checkHealth();
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
try {
|
|
479
|
-
await Effect.runPromise(program.pipe(Effect.provide(ollamaLayer)));
|
|
480
|
-
return { ollama: true };
|
|
481
|
-
} catch (error) {
|
|
482
|
-
return {
|
|
483
|
-
ollama: false,
|
|
484
|
-
message:
|
|
485
|
-
error instanceof Error ? error.message : "Ollama not available",
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
},
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Smart upsert - uses LLM to decide ADD, UPDATE, DELETE, or NOOP
|
|
492
|
-
*
|
|
493
|
-
* Delegates to real swarm-mail adapter with Mem0 pattern:
|
|
494
|
-
* - Finds semantically similar memories
|
|
495
|
-
* - LLM analyzes and decides operation
|
|
496
|
-
* - Executes with graceful degradation on LLM failures
|
|
497
|
-
*/
|
|
498
|
-
async upsert(args: UpsertArgs): Promise<UpsertResult> {
|
|
499
|
-
// Validate required fields
|
|
500
|
-
if (!args.information) {
|
|
501
|
-
throw new Error("information is required for upsert");
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
// Delegate to real swarm-mail adapter with useSmartOps enabled
|
|
505
|
-
const result = await realAdapter.upsert(args.information, {
|
|
506
|
-
collection: args.collection,
|
|
507
|
-
tags: args.tags,
|
|
508
|
-
metadata: args.metadata,
|
|
509
|
-
confidence: args.confidence,
|
|
510
|
-
useSmartOps: true, // Enable LLM-powered decision making
|
|
511
|
-
autoTag: args.autoTag,
|
|
512
|
-
autoLink: args.autoLink,
|
|
513
|
-
extractEntities: args.extractEntities,
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
// Map real adapter result to plugin UpsertResult format
|
|
517
|
-
return {
|
|
518
|
-
operation: result.operation,
|
|
519
|
-
reason: result.reason,
|
|
520
|
-
memoryId: result.id,
|
|
521
|
-
affectedMemoryIds: [result.id],
|
|
522
|
-
// Note: Real adapter doesn't return autoTags/links from upsert yet
|
|
523
|
-
// Those are only on store(). This is consistent with current behavior.
|
|
524
|
-
};
|
|
525
|
-
},
|
|
526
|
-
};
|
|
527
|
-
}
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Model Selection Tests
|
|
3
|
-
*
|
|
4
|
-
* Tests for selectWorkerModel function that determines which model
|
|
5
|
-
* a worker should use based on subtask characteristics.
|
|
6
|
-
*/
|
|
7
|
-
import { describe, test, expect } from "bun:test";
|
|
8
|
-
import { selectWorkerModel } from "./model-selection";
|
|
9
|
-
import type { DecomposedSubtask } from "./schemas/task";
|
|
10
|
-
|
|
11
|
-
// Mock config type matching expected SwarmConfig structure
|
|
12
|
-
interface TestConfig {
|
|
13
|
-
primaryModel: string;
|
|
14
|
-
liteModel?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe("selectWorkerModel", () => {
|
|
18
|
-
const mockConfig: TestConfig = {
|
|
19
|
-
primaryModel: "anthropic/claude-sonnet-4-5",
|
|
20
|
-
liteModel: "anthropic/claude-haiku-4-5",
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
test("uses explicit model field from subtask when provided", () => {
|
|
24
|
-
const subtask: DecomposedSubtask & { model?: string } = {
|
|
25
|
-
title: "Update docs",
|
|
26
|
-
description: "Update README",
|
|
27
|
-
files: ["README.md"],
|
|
28
|
-
estimated_effort: "trivial",
|
|
29
|
-
model: "anthropic/claude-opus-4-5", // Explicit override
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const result = selectWorkerModel(subtask, mockConfig);
|
|
33
|
-
expect(result).toBe("anthropic/claude-opus-4-5");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test("uses liteModel for all markdown files", () => {
|
|
37
|
-
const subtask: DecomposedSubtask = {
|
|
38
|
-
title: "Update docs",
|
|
39
|
-
description: "Update all docs",
|
|
40
|
-
files: ["README.md", "CONTRIBUTING.md"],
|
|
41
|
-
estimated_effort: "small",
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const result = selectWorkerModel(subtask, mockConfig);
|
|
45
|
-
expect(result).toBe("anthropic/claude-haiku-4-5");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("uses liteModel for all MDX files", () => {
|
|
49
|
-
const subtask: DecomposedSubtask = {
|
|
50
|
-
title: "Update docs",
|
|
51
|
-
description: "Update content",
|
|
52
|
-
files: ["docs/intro.mdx", "docs/guide.mdx"],
|
|
53
|
-
estimated_effort: "small",
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const result = selectWorkerModel(subtask, mockConfig);
|
|
57
|
-
expect(result).toBe("anthropic/claude-haiku-4-5");
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("uses liteModel for test files with .test. pattern", () => {
|
|
61
|
-
const subtask: DecomposedSubtask = {
|
|
62
|
-
title: "Write tests",
|
|
63
|
-
description: "Add unit tests",
|
|
64
|
-
files: ["src/auth.test.ts", "src/user.test.ts"],
|
|
65
|
-
estimated_effort: "small",
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const result = selectWorkerModel(subtask, mockConfig);
|
|
69
|
-
expect(result).toBe("anthropic/claude-haiku-4-5");
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("uses liteModel for test files with .spec. pattern", () => {
|
|
73
|
-
const subtask: DecomposedSubtask = {
|
|
74
|
-
title: "Write specs",
|
|
75
|
-
description: "Add spec tests",
|
|
76
|
-
files: ["src/auth.spec.ts", "src/user.spec.ts"],
|
|
77
|
-
estimated_effort: "small",
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const result = selectWorkerModel(subtask, mockConfig);
|
|
81
|
-
expect(result).toBe("anthropic/claude-haiku-4-5");
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test("uses primaryModel when files are mixed (code + docs)", () => {
|
|
85
|
-
const subtask: DecomposedSubtask = {
|
|
86
|
-
title: "Implement feature with docs",
|
|
87
|
-
description: "Add feature and document it",
|
|
88
|
-
files: ["src/feature.ts", "README.md"],
|
|
89
|
-
estimated_effort: "medium",
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const result = selectWorkerModel(subtask, mockConfig);
|
|
93
|
-
expect(result).toBe("anthropic/claude-sonnet-4-5");
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test("uses primaryModel when files are mixed (code + tests)", () => {
|
|
97
|
-
const subtask: DecomposedSubtask = {
|
|
98
|
-
title: "Implement feature with tests",
|
|
99
|
-
description: "Add feature and tests",
|
|
100
|
-
files: ["src/feature.ts", "src/feature.test.ts"],
|
|
101
|
-
estimated_effort: "medium",
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const result = selectWorkerModel(subtask, mockConfig);
|
|
105
|
-
expect(result).toBe("anthropic/claude-sonnet-4-5");
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test("uses primaryModel for implementation files", () => {
|
|
109
|
-
const subtask: DecomposedSubtask = {
|
|
110
|
-
title: "Implement auth",
|
|
111
|
-
description: "Add authentication",
|
|
112
|
-
files: ["src/auth.ts", "src/middleware.ts"],
|
|
113
|
-
estimated_effort: "large",
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const result = selectWorkerModel(subtask, mockConfig);
|
|
117
|
-
expect(result).toBe("anthropic/claude-sonnet-4-5");
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test("defaults to primaryModel when liteModel not configured", () => {
|
|
121
|
-
const configWithoutLite: TestConfig = {
|
|
122
|
-
primaryModel: "anthropic/claude-sonnet-4-5",
|
|
123
|
-
// liteModel is undefined
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const subtask: DecomposedSubtask = {
|
|
127
|
-
title: "Update docs",
|
|
128
|
-
description: "Update README",
|
|
129
|
-
files: ["README.md"],
|
|
130
|
-
estimated_effort: "trivial",
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const result = selectWorkerModel(subtask, configWithoutLite);
|
|
134
|
-
expect(result).toBe("anthropic/claude-sonnet-4-5");
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test("falls back to claude-haiku when liteModel not configured but primaryModel missing", () => {
|
|
138
|
-
const emptyConfig: TestConfig = {
|
|
139
|
-
primaryModel: "",
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const subtask: DecomposedSubtask = {
|
|
143
|
-
title: "Update docs",
|
|
144
|
-
description: "Update README",
|
|
145
|
-
files: ["README.md"],
|
|
146
|
-
estimated_effort: "trivial",
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const result = selectWorkerModel(subtask, emptyConfig);
|
|
150
|
-
expect(result).toBe("anthropic/claude-haiku-4-5");
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
test("handles empty files array by defaulting to primaryModel", () => {
|
|
154
|
-
const subtask: DecomposedSubtask = {
|
|
155
|
-
title: "Research task",
|
|
156
|
-
description: "Investigate options",
|
|
157
|
-
files: [],
|
|
158
|
-
estimated_effort: "small",
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const result = selectWorkerModel(subtask, mockConfig);
|
|
162
|
-
expect(result).toBe("anthropic/claude-sonnet-4-5");
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test("handles mixed markdown and mdx files", () => {
|
|
166
|
-
const subtask: DecomposedSubtask = {
|
|
167
|
-
title: "Update all docs",
|
|
168
|
-
description: "Update docs",
|
|
169
|
-
files: ["README.md", "docs/guide.mdx", "CHANGELOG.md"],
|
|
170
|
-
estimated_effort: "small",
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const result = selectWorkerModel(subtask, mockConfig);
|
|
174
|
-
expect(result).toBe("anthropic/claude-haiku-4-5");
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
test("case insensitive file extension matching", () => {
|
|
178
|
-
const subtask: DecomposedSubtask = {
|
|
179
|
-
title: "Update docs",
|
|
180
|
-
description: "Update README",
|
|
181
|
-
files: ["README.MD", "CONTRIBUTING.MD"],
|
|
182
|
-
estimated_effort: "trivial",
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const result = selectWorkerModel(subtask, mockConfig);
|
|
186
|
-
expect(result).toBe("anthropic/claude-haiku-4-5");
|
|
187
|
-
});
|
|
188
|
-
});
|