opencode-swarm-plugin 0.43.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/cass.characterization.test.ts +422 -0
- package/bin/swarm.serve.test.ts +6 -4
- package/bin/swarm.test.ts +68 -0
- package/bin/swarm.ts +81 -8
- package/dist/compaction-prompt-scoring.js +139 -0
- package/dist/contributor-tools.d.ts +42 -0
- package/dist/contributor-tools.d.ts.map +1 -0
- package/dist/eval-capture.js +12811 -0
- package/dist/hive.d.ts.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7728 -62590
- package/dist/plugin.js +23833 -78695
- package/dist/sessions/agent-discovery.d.ts +59 -0
- package/dist/sessions/agent-discovery.d.ts.map +1 -0
- package/dist/sessions/index.d.ts +10 -0
- package/dist/sessions/index.d.ts.map +1 -0
- 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 -2255
- 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/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/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 -2426
- 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/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 -935
- 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/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-tools.test.ts
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Tools Integration Tests
|
|
3
|
-
*
|
|
4
|
-
* Tests for semantic-memory_* tool registration and execution.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { describe, test, expect, beforeAll, afterAll } from "bun:test";
|
|
8
|
-
import { memoryTools, resetMemoryCache } from "./memory-tools";
|
|
9
|
-
import { closeAllSwarmMail } from "swarm-mail";
|
|
10
|
-
|
|
11
|
-
describe("memory tools integration", () => {
|
|
12
|
-
afterAll(async () => {
|
|
13
|
-
resetMemoryCache();
|
|
14
|
-
await closeAllSwarmMail();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test("all tools are registered with correct names", () => {
|
|
18
|
-
const toolNames = Object.keys(memoryTools);
|
|
19
|
-
expect(toolNames).toContain("semantic-memory_store");
|
|
20
|
-
expect(toolNames).toContain("semantic-memory_find");
|
|
21
|
-
expect(toolNames).toContain("semantic-memory_get");
|
|
22
|
-
expect(toolNames).toContain("semantic-memory_remove");
|
|
23
|
-
expect(toolNames).toContain("semantic-memory_validate");
|
|
24
|
-
expect(toolNames).toContain("semantic-memory_list");
|
|
25
|
-
expect(toolNames).toContain("semantic-memory_stats");
|
|
26
|
-
expect(toolNames).toContain("semantic-memory_check");
|
|
27
|
-
expect(toolNames).toContain("semantic-memory_upsert");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("tools have execute functions", () => {
|
|
31
|
-
for (const [name, tool] of Object.entries(memoryTools)) {
|
|
32
|
-
expect(typeof tool.execute).toBe("function");
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe("semantic-memory_store", () => {
|
|
37
|
-
test("executes and returns JSON", async () => {
|
|
38
|
-
const tool = memoryTools["semantic-memory_store"];
|
|
39
|
-
const result = await tool.execute(
|
|
40
|
-
{
|
|
41
|
-
information: "Test memory for tools integration",
|
|
42
|
-
tags: "test",
|
|
43
|
-
},
|
|
44
|
-
{ sessionID: "test-session" } as any,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
expect(typeof result).toBe("string");
|
|
48
|
-
const parsed = JSON.parse(result);
|
|
49
|
-
expect(parsed.id).toBeDefined();
|
|
50
|
-
expect(parsed.id).toMatch(/^mem_/);
|
|
51
|
-
expect(parsed.message).toContain("Stored memory");
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("semantic-memory_find", () => {
|
|
56
|
-
test("executes and returns JSON array", async () => {
|
|
57
|
-
// Store a memory first
|
|
58
|
-
const storeTool = memoryTools["semantic-memory_store"];
|
|
59
|
-
await storeTool.execute(
|
|
60
|
-
{
|
|
61
|
-
information: "Findable test memory with unique keyword xyztest123",
|
|
62
|
-
},
|
|
63
|
-
{ sessionID: "test-session" } as any,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
// Search for it
|
|
67
|
-
const findTool = memoryTools["semantic-memory_find"];
|
|
68
|
-
const result = await findTool.execute(
|
|
69
|
-
{
|
|
70
|
-
query: "xyztest123",
|
|
71
|
-
limit: 5,
|
|
72
|
-
},
|
|
73
|
-
{ sessionID: "test-session" } as any,
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
expect(typeof result).toBe("string");
|
|
77
|
-
const parsed = JSON.parse(result);
|
|
78
|
-
expect(parsed.results).toBeDefined();
|
|
79
|
-
expect(Array.isArray(parsed.results)).toBe(true);
|
|
80
|
-
expect(parsed.count).toBeGreaterThanOrEqual(0);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe("semantic-memory_stats", () => {
|
|
85
|
-
test("returns memory and embedding counts", async () => {
|
|
86
|
-
const tool = memoryTools["semantic-memory_stats"];
|
|
87
|
-
const result = await tool.execute(
|
|
88
|
-
{},
|
|
89
|
-
{ sessionID: "test-session" } as any,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
expect(typeof result).toBe("string");
|
|
93
|
-
const parsed = JSON.parse(result);
|
|
94
|
-
expect(typeof parsed.memories).toBe("number");
|
|
95
|
-
expect(typeof parsed.embeddings).toBe("number");
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("semantic-memory_check", () => {
|
|
100
|
-
test("checks Ollama health", async () => {
|
|
101
|
-
const tool = memoryTools["semantic-memory_check"];
|
|
102
|
-
const result = await tool.execute(
|
|
103
|
-
{},
|
|
104
|
-
{ sessionID: "test-session" } as any,
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
expect(typeof result).toBe("string");
|
|
108
|
-
const parsed = JSON.parse(result);
|
|
109
|
-
expect(typeof parsed.ollama).toBe("boolean");
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe("semantic-memory_upsert", () => {
|
|
114
|
-
test("returns valid ADD operation result", async () => {
|
|
115
|
-
const tool = memoryTools["semantic-memory_upsert"];
|
|
116
|
-
const result = await tool.execute(
|
|
117
|
-
{
|
|
118
|
-
information: "Test memory for plugin tool",
|
|
119
|
-
tags: "test,plugin",
|
|
120
|
-
},
|
|
121
|
-
{ sessionID: "test-session" } as any,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
const parsed = JSON.parse(result);
|
|
125
|
-
|
|
126
|
-
expect(parsed.operation).toBe("ADD");
|
|
127
|
-
expect(parsed.reason).toBeDefined();
|
|
128
|
-
expect(parsed.memoryId).toBeDefined();
|
|
129
|
-
expect(parsed.memoryId).toMatch(/^mem_/);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test("includes autoTags when enabled", async () => {
|
|
133
|
-
const tool = memoryTools["semantic-memory_upsert"];
|
|
134
|
-
const result = await tool.execute(
|
|
135
|
-
{
|
|
136
|
-
information: "TypeScript is a typed superset of JavaScript",
|
|
137
|
-
autoTag: true,
|
|
138
|
-
},
|
|
139
|
-
{ sessionID: "test-session" } as any,
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
const parsed = JSON.parse(result);
|
|
143
|
-
|
|
144
|
-
expect(parsed.autoTags).toBeDefined();
|
|
145
|
-
expect(parsed.autoTags.tags).toBeInstanceOf(Array);
|
|
146
|
-
expect(parsed.autoTags.keywords).toBeInstanceOf(Array);
|
|
147
|
-
expect(parsed.autoTags.category).toBe("general");
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
test("includes linksCreated when autoLink enabled", async () => {
|
|
151
|
-
const tool = memoryTools["semantic-memory_upsert"];
|
|
152
|
-
const result = await tool.execute(
|
|
153
|
-
{
|
|
154
|
-
information: "React hooks enable functional components to use state",
|
|
155
|
-
autoLink: true,
|
|
156
|
-
},
|
|
157
|
-
{ sessionID: "test-session" } as any,
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
const parsed = JSON.parse(result);
|
|
161
|
-
|
|
162
|
-
expect(parsed.linksCreated).toBeDefined();
|
|
163
|
-
expect(typeof parsed.linksCreated).toBe("number");
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test("includes entitiesExtracted when extractEntities enabled", async () => {
|
|
167
|
-
const tool = memoryTools["semantic-memory_upsert"];
|
|
168
|
-
const result = await tool.execute(
|
|
169
|
-
{
|
|
170
|
-
information: "Next.js 15 was released by Vercel in October 2024",
|
|
171
|
-
extractEntities: true,
|
|
172
|
-
},
|
|
173
|
-
{ sessionID: "test-session" } as any,
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
const parsed = JSON.parse(result);
|
|
177
|
-
|
|
178
|
-
expect(parsed.entitiesExtracted).toBeDefined();
|
|
179
|
-
expect(typeof parsed.entitiesExtracted).toBe("number");
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
test("throws error when information is missing", async () => {
|
|
183
|
-
const tool = memoryTools["semantic-memory_upsert"];
|
|
184
|
-
|
|
185
|
-
await expect(async () => {
|
|
186
|
-
await tool.execute(
|
|
187
|
-
{
|
|
188
|
-
tags: "test",
|
|
189
|
-
} as any,
|
|
190
|
-
{ sessionID: "test-session" } as any,
|
|
191
|
-
);
|
|
192
|
-
}).toThrow("information is required");
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
package/src/memory-tools.ts
DELETED
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Semantic Memory Plugin Tools - Embedded implementation
|
|
3
|
-
*
|
|
4
|
-
* Provides semantic memory operations using swarm-mail's MemoryStore + Ollama.
|
|
5
|
-
* Replaces external MCP-based semantic-memory calls with embedded storage.
|
|
6
|
-
*
|
|
7
|
-
* Key features:
|
|
8
|
-
* - Vector similarity search with Ollama embeddings
|
|
9
|
-
* - Full-text search fallback
|
|
10
|
-
* - Memory decay tracking (TODO: implement in MemoryStore)
|
|
11
|
-
* - Collection-based organization
|
|
12
|
-
*
|
|
13
|
-
* Tool signatures maintained for backward compatibility with existing prompts.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { tool } from "@opencode-ai/plugin";
|
|
17
|
-
import { getSwarmMailLibSQL } from "swarm-mail";
|
|
18
|
-
import {
|
|
19
|
-
createMemoryAdapter,
|
|
20
|
-
type MemoryAdapter,
|
|
21
|
-
type StoreArgs,
|
|
22
|
-
type FindArgs,
|
|
23
|
-
type IdArgs,
|
|
24
|
-
type ListArgs,
|
|
25
|
-
type StoreResult,
|
|
26
|
-
type FindResult,
|
|
27
|
-
type StatsResult,
|
|
28
|
-
type HealthResult,
|
|
29
|
-
type OperationResult,
|
|
30
|
-
type UpsertArgs,
|
|
31
|
-
type UpsertResult,
|
|
32
|
-
type AutoTags,
|
|
33
|
-
} from "./memory";
|
|
34
|
-
|
|
35
|
-
// Re-export types for external use
|
|
36
|
-
export type {
|
|
37
|
-
MemoryAdapter,
|
|
38
|
-
StoreArgs,
|
|
39
|
-
FindArgs,
|
|
40
|
-
IdArgs,
|
|
41
|
-
ListArgs,
|
|
42
|
-
StoreResult,
|
|
43
|
-
FindResult,
|
|
44
|
-
StatsResult,
|
|
45
|
-
HealthResult,
|
|
46
|
-
OperationResult,
|
|
47
|
-
UpsertArgs,
|
|
48
|
-
UpsertResult,
|
|
49
|
-
AutoTags,
|
|
50
|
-
} from "./memory";
|
|
51
|
-
|
|
52
|
-
// ============================================================================
|
|
53
|
-
// Types
|
|
54
|
-
// ============================================================================
|
|
55
|
-
|
|
56
|
-
/** Tool execution context from OpenCode plugin */
|
|
57
|
-
interface ToolContext {
|
|
58
|
-
sessionID: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// ============================================================================
|
|
62
|
-
// Memory Adapter Cache
|
|
63
|
-
// ============================================================================
|
|
64
|
-
|
|
65
|
-
let cachedAdapter: MemoryAdapter | null = null;
|
|
66
|
-
let cachedProjectPath: string | null = null;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Get or create memory adapter for the current project
|
|
70
|
-
*
|
|
71
|
-
* @param projectPath - Project path (uses CWD if not provided)
|
|
72
|
-
* @returns Memory adapter instance
|
|
73
|
-
*/
|
|
74
|
-
export async function getMemoryAdapter(
|
|
75
|
-
projectPath?: string,
|
|
76
|
-
): Promise<MemoryAdapter> {
|
|
77
|
-
const path = projectPath || process.cwd();
|
|
78
|
-
|
|
79
|
-
// Return cached adapter if same project
|
|
80
|
-
if (cachedAdapter && cachedProjectPath === path) {
|
|
81
|
-
return cachedAdapter;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Create new adapter
|
|
85
|
-
const swarmMail = await getSwarmMailLibSQL(path);
|
|
86
|
-
const dbAdapter = await swarmMail.getDatabase();
|
|
87
|
-
|
|
88
|
-
// createMemoryAdapter now accepts DatabaseAdapter directly and converts internally
|
|
89
|
-
cachedAdapter = await createMemoryAdapter(dbAdapter);
|
|
90
|
-
cachedProjectPath = path;
|
|
91
|
-
|
|
92
|
-
return cachedAdapter;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Reset adapter cache (for testing)
|
|
97
|
-
*/
|
|
98
|
-
export function resetMemoryCache(): void {
|
|
99
|
-
cachedAdapter = null;
|
|
100
|
-
cachedProjectPath = null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Re-export createMemoryAdapter for external use
|
|
104
|
-
export { createMemoryAdapter };
|
|
105
|
-
|
|
106
|
-
// ============================================================================
|
|
107
|
-
// Plugin Tools
|
|
108
|
-
// ============================================================================
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Store a memory with semantic embedding
|
|
112
|
-
*/
|
|
113
|
-
export const semantic_memory_store = tool({
|
|
114
|
-
description:
|
|
115
|
-
"Store a memory with semantic embedding. Memories are searchable by semantic similarity and can be organized into collections. Confidence affects decay rate: high confidence (1.0) = 135 day half-life, low confidence (0.0) = 45 day half-life. Supports auto-tagging, auto-linking, and entity extraction via LLM.",
|
|
116
|
-
args: {
|
|
117
|
-
information: tool.schema
|
|
118
|
-
.string()
|
|
119
|
-
.describe("The information to store (required)"),
|
|
120
|
-
collection: tool.schema
|
|
121
|
-
.string()
|
|
122
|
-
.optional()
|
|
123
|
-
.describe("Collection name (defaults to 'default')"),
|
|
124
|
-
tags: tool.schema
|
|
125
|
-
.string()
|
|
126
|
-
.optional()
|
|
127
|
-
.describe("Comma-separated tags (e.g., 'auth,tokens,oauth')"),
|
|
128
|
-
metadata: tool.schema
|
|
129
|
-
.string()
|
|
130
|
-
.optional()
|
|
131
|
-
.describe("JSON string with additional metadata"),
|
|
132
|
-
confidence: tool.schema
|
|
133
|
-
.number()
|
|
134
|
-
.optional()
|
|
135
|
-
.describe("Confidence level (0.0-1.0) affecting decay rate. Higher = slower decay. Default 0.7"),
|
|
136
|
-
autoTag: tool.schema
|
|
137
|
-
.boolean()
|
|
138
|
-
.optional()
|
|
139
|
-
.describe("Auto-generate tags using LLM. Default false"),
|
|
140
|
-
autoLink: tool.schema
|
|
141
|
-
.boolean()
|
|
142
|
-
.optional()
|
|
143
|
-
.describe("Auto-link to related memories. Default false"),
|
|
144
|
-
extractEntities: tool.schema
|
|
145
|
-
.boolean()
|
|
146
|
-
.optional()
|
|
147
|
-
.describe("Extract entities (people, places, technologies). Default false"),
|
|
148
|
-
},
|
|
149
|
-
async execute(args, ctx: ToolContext) {
|
|
150
|
-
const adapter = await getMemoryAdapter();
|
|
151
|
-
const result = await adapter.store(args);
|
|
152
|
-
return JSON.stringify(result, null, 2);
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Find memories by semantic similarity or full-text search
|
|
158
|
-
*/
|
|
159
|
-
export const semantic_memory_find = tool({
|
|
160
|
-
description:
|
|
161
|
-
"Search memories by semantic similarity (vector search) or full-text search. Returns results ranked by relevance score.",
|
|
162
|
-
args: {
|
|
163
|
-
query: tool.schema.string().describe("Search query (required)"),
|
|
164
|
-
limit: tool.schema
|
|
165
|
-
.number()
|
|
166
|
-
.optional()
|
|
167
|
-
.describe("Maximum number of results (default: 10)"),
|
|
168
|
-
collection: tool.schema
|
|
169
|
-
.string()
|
|
170
|
-
.optional()
|
|
171
|
-
.describe("Filter by collection name"),
|
|
172
|
-
expand: tool.schema
|
|
173
|
-
.boolean()
|
|
174
|
-
.optional()
|
|
175
|
-
.describe("Return full content instead of truncated preview (default: false)"),
|
|
176
|
-
fts: tool.schema
|
|
177
|
-
.boolean()
|
|
178
|
-
.optional()
|
|
179
|
-
.describe("Use full-text search instead of vector search (default: false)"),
|
|
180
|
-
},
|
|
181
|
-
async execute(args, ctx: ToolContext) {
|
|
182
|
-
const adapter = await getMemoryAdapter();
|
|
183
|
-
const result = await adapter.find(args);
|
|
184
|
-
return JSON.stringify(result, null, 2);
|
|
185
|
-
},
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Get a single memory by ID
|
|
190
|
-
*/
|
|
191
|
-
export const semantic_memory_get = tool({
|
|
192
|
-
description: "Retrieve a specific memory by its ID.",
|
|
193
|
-
args: {
|
|
194
|
-
id: tool.schema.string().describe("Memory ID (required)"),
|
|
195
|
-
},
|
|
196
|
-
async execute(args, ctx: ToolContext) {
|
|
197
|
-
const adapter = await getMemoryAdapter();
|
|
198
|
-
const memory = await adapter.get(args);
|
|
199
|
-
return memory ? JSON.stringify(memory, null, 2) : "Memory not found";
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Remove a memory
|
|
205
|
-
*/
|
|
206
|
-
export const semantic_memory_remove = tool({
|
|
207
|
-
description: "Delete a memory by ID. Use this to remove outdated or incorrect memories.",
|
|
208
|
-
args: {
|
|
209
|
-
id: tool.schema.string().describe("Memory ID (required)"),
|
|
210
|
-
},
|
|
211
|
-
async execute(args, ctx: ToolContext) {
|
|
212
|
-
const adapter = await getMemoryAdapter();
|
|
213
|
-
const result = await adapter.remove(args);
|
|
214
|
-
return JSON.stringify(result, null, 2);
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Validate a memory (reset decay timer)
|
|
220
|
-
*/
|
|
221
|
-
export const semantic_memory_validate = tool({
|
|
222
|
-
description:
|
|
223
|
-
"Validate that a memory is still accurate and reset its decay timer. Use when you confirm a memory is correct.",
|
|
224
|
-
args: {
|
|
225
|
-
id: tool.schema.string().describe("Memory ID (required)"),
|
|
226
|
-
},
|
|
227
|
-
async execute(args, ctx: ToolContext) {
|
|
228
|
-
const adapter = await getMemoryAdapter();
|
|
229
|
-
const result = await adapter.validate(args);
|
|
230
|
-
return JSON.stringify(result, null, 2);
|
|
231
|
-
},
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* List memories
|
|
236
|
-
*/
|
|
237
|
-
export const semantic_memory_list = tool({
|
|
238
|
-
description: "List all stored memories, optionally filtered by collection.",
|
|
239
|
-
args: {
|
|
240
|
-
collection: tool.schema
|
|
241
|
-
.string()
|
|
242
|
-
.optional()
|
|
243
|
-
.describe("Filter by collection name"),
|
|
244
|
-
},
|
|
245
|
-
async execute(args, ctx: ToolContext) {
|
|
246
|
-
const adapter = await getMemoryAdapter();
|
|
247
|
-
const memories = await adapter.list(args);
|
|
248
|
-
return JSON.stringify(memories, null, 2);
|
|
249
|
-
},
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Get memory statistics
|
|
254
|
-
*/
|
|
255
|
-
export const semantic_memory_stats = tool({
|
|
256
|
-
description: "Get statistics about stored memories and embeddings.",
|
|
257
|
-
args: {},
|
|
258
|
-
async execute(args, ctx: ToolContext) {
|
|
259
|
-
const adapter = await getMemoryAdapter();
|
|
260
|
-
const stats = await adapter.stats();
|
|
261
|
-
return JSON.stringify(stats, null, 2);
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Check Ollama health
|
|
267
|
-
*/
|
|
268
|
-
export const semantic_memory_check = tool({
|
|
269
|
-
description:
|
|
270
|
-
"Check if Ollama is running and available for embedding generation.",
|
|
271
|
-
args: {},
|
|
272
|
-
async execute(args, ctx: ToolContext) {
|
|
273
|
-
const adapter = await getMemoryAdapter();
|
|
274
|
-
const health = await adapter.checkHealth();
|
|
275
|
-
return JSON.stringify(health, null, 2);
|
|
276
|
-
},
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Smart upsert - ADD, UPDATE, DELETE, or NOOP based on existing memories
|
|
281
|
-
*/
|
|
282
|
-
export const semantic_memory_upsert = tool({
|
|
283
|
-
description:
|
|
284
|
-
"Smart memory storage that decides whether to ADD, UPDATE, DELETE, or skip (NOOP) based on existing memories. Uses LLM to detect duplicates, refinements, and contradictions. Auto-generates tags, links, and entities when enabled.",
|
|
285
|
-
args: {
|
|
286
|
-
information: tool.schema
|
|
287
|
-
.string()
|
|
288
|
-
.describe("The information to store (required)"),
|
|
289
|
-
collection: tool.schema
|
|
290
|
-
.string()
|
|
291
|
-
.optional()
|
|
292
|
-
.describe("Collection name (defaults to 'default')"),
|
|
293
|
-
tags: tool.schema
|
|
294
|
-
.string()
|
|
295
|
-
.optional()
|
|
296
|
-
.describe("Comma-separated tags (e.g., 'auth,tokens,oauth')"),
|
|
297
|
-
metadata: tool.schema
|
|
298
|
-
.string()
|
|
299
|
-
.optional()
|
|
300
|
-
.describe("JSON string with additional metadata"),
|
|
301
|
-
confidence: tool.schema
|
|
302
|
-
.number()
|
|
303
|
-
.optional()
|
|
304
|
-
.describe("Confidence level (0.0-1.0) affecting decay rate. Higher = slower decay. Default 0.7"),
|
|
305
|
-
autoTag: tool.schema
|
|
306
|
-
.boolean()
|
|
307
|
-
.optional()
|
|
308
|
-
.describe("Auto-generate tags using LLM. Default true"),
|
|
309
|
-
autoLink: tool.schema
|
|
310
|
-
.boolean()
|
|
311
|
-
.optional()
|
|
312
|
-
.describe("Auto-link to related memories. Default true"),
|
|
313
|
-
extractEntities: tool.schema
|
|
314
|
-
.boolean()
|
|
315
|
-
.optional()
|
|
316
|
-
.describe("Extract entities (people, places, technologies). Default false"),
|
|
317
|
-
},
|
|
318
|
-
async execute(args, ctx: ToolContext) {
|
|
319
|
-
const adapter = await getMemoryAdapter();
|
|
320
|
-
const result = await adapter.upsert(args);
|
|
321
|
-
return JSON.stringify(result, null, 2);
|
|
322
|
-
},
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
// ============================================================================
|
|
326
|
-
// Tool Registry
|
|
327
|
-
// ============================================================================
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* All semantic memory tools
|
|
331
|
-
*
|
|
332
|
-
* Register these in the plugin with spread operator: { ...memoryTools }
|
|
333
|
-
*/
|
|
334
|
-
export const memoryTools = {
|
|
335
|
-
"semantic-memory_store": semantic_memory_store,
|
|
336
|
-
"semantic-memory_find": semantic_memory_find,
|
|
337
|
-
"semantic-memory_get": semantic_memory_get,
|
|
338
|
-
"semantic-memory_remove": semantic_memory_remove,
|
|
339
|
-
"semantic-memory_validate": semantic_memory_validate,
|
|
340
|
-
"semantic-memory_list": semantic_memory_list,
|
|
341
|
-
"semantic-memory_stats": semantic_memory_stats,
|
|
342
|
-
"semantic-memory_check": semantic_memory_check,
|
|
343
|
-
"semantic-memory_upsert": semantic_memory_upsert,
|
|
344
|
-
} as const;
|