@agentmemory/agentmemory 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +14 -0
- package/.github/workflows/ci.yml +22 -0
- package/.github/workflows/publish.yml +28 -0
- package/AGENTS.md +113 -0
- package/LICENSE +190 -0
- package/README.md +828 -0
- package/assets/banner.png +0 -0
- package/assets/demo.gif +0 -0
- package/assets/demo.mp4 +0 -0
- package/benchmark/QUALITY.md +73 -0
- package/benchmark/REAL-EMBEDDINGS.md +67 -0
- package/benchmark/SCALE.md +110 -0
- package/benchmark/dataset.ts +293 -0
- package/benchmark/quality-eval.ts +643 -0
- package/benchmark/real-embeddings-eval.ts +405 -0
- package/benchmark/scale-eval.ts +398 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +137 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/docker-compose.yml +14 -0
- package/dist/hooks/notification.d.mts +1 -0
- package/dist/hooks/notification.mjs +45 -0
- package/dist/hooks/notification.mjs.map +1 -0
- package/dist/hooks/post-tool-failure.d.mts +1 -0
- package/dist/hooks/post-tool-failure.mjs +45 -0
- package/dist/hooks/post-tool-failure.mjs.map +1 -0
- package/dist/hooks/post-tool-use.d.mts +1 -0
- package/dist/hooks/post-tool-use.mjs +53 -0
- package/dist/hooks/post-tool-use.mjs.map +1 -0
- package/dist/hooks/pre-compact.d.mts +1 -0
- package/dist/hooks/pre-compact.mjs +50 -0
- package/dist/hooks/pre-compact.mjs.map +1 -0
- package/dist/hooks/pre-tool-use.d.mts +1 -0
- package/dist/hooks/pre-tool-use.mjs +69 -0
- package/dist/hooks/pre-tool-use.mjs.map +1 -0
- package/dist/hooks/prompt-submit.d.mts +1 -0
- package/dist/hooks/prompt-submit.mjs +40 -0
- package/dist/hooks/prompt-submit.mjs.map +1 -0
- package/dist/hooks/session-end.d.mts +1 -0
- package/dist/hooks/session-end.mjs +61 -0
- package/dist/hooks/session-end.mjs.map +1 -0
- package/dist/hooks/session-start.d.mts +1 -0
- package/dist/hooks/session-start.mjs +42 -0
- package/dist/hooks/session-start.mjs.map +1 -0
- package/dist/hooks/stop.d.mts +1 -0
- package/dist/hooks/stop.mjs +33 -0
- package/dist/hooks/stop.mjs.map +1 -0
- package/dist/hooks/subagent-start.d.mts +1 -0
- package/dist/hooks/subagent-start.mjs +43 -0
- package/dist/hooks/subagent-start.mjs.map +1 -0
- package/dist/hooks/subagent-stop.d.mts +1 -0
- package/dist/hooks/subagent-stop.mjs +45 -0
- package/dist/hooks/subagent-stop.mjs.map +1 -0
- package/dist/hooks/task-completed.d.mts +1 -0
- package/dist/hooks/task-completed.mjs +46 -0
- package/dist/hooks/task-completed.mjs.map +1 -0
- package/dist/iii-config.yaml +51 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +13776 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src-QxitMPfJ.mjs +13775 -0
- package/dist/src-QxitMPfJ.mjs.map +1 -0
- package/dist/standalone.d.mts +1 -0
- package/dist/standalone.mjs +1155 -0
- package/dist/standalone.mjs.map +1 -0
- package/dist/transformers-BX_tgxdO.mjs +38684 -0
- package/dist/transformers-BX_tgxdO.mjs.map +1 -0
- package/dist/transformers-KMm1i9no.mjs +38683 -0
- package/dist/transformers-KMm1i9no.mjs.map +1 -0
- package/docker-compose.yml +14 -0
- package/iii-config.yaml +51 -0
- package/package.json +59 -0
- package/plugin/.claude-plugin/plugin.json +10 -0
- package/plugin/hooks/hooks.json +77 -0
- package/plugin/scripts/diagnostics.mjs +551 -0
- package/plugin/scripts/notification.mjs +45 -0
- package/plugin/scripts/post-tool-failure.mjs +45 -0
- package/plugin/scripts/post-tool-use.mjs +53 -0
- package/plugin/scripts/pre-compact.mjs +50 -0
- package/plugin/scripts/pre-tool-use.mjs +69 -0
- package/plugin/scripts/prompt-submit.mjs +40 -0
- package/plugin/scripts/session-end.mjs +61 -0
- package/plugin/scripts/session-start.mjs +42 -0
- package/plugin/scripts/stop.mjs +33 -0
- package/plugin/scripts/subagent-start.mjs +43 -0
- package/plugin/scripts/subagent-stop.mjs +45 -0
- package/plugin/scripts/task-completed.mjs +46 -0
- package/plugin/skills/forget/SKILL.md +32 -0
- package/plugin/skills/recall/SKILL.md +18 -0
- package/plugin/skills/remember/SKILL.md +25 -0
- package/plugin/skills/session-history/SKILL.md +17 -0
- package/src/auth.ts +12 -0
- package/src/cli.ts +159 -0
- package/src/config.ts +221 -0
- package/src/eval/metrics-store.ts +65 -0
- package/src/eval/quality.ts +51 -0
- package/src/eval/schemas.ts +124 -0
- package/src/eval/self-correct.ts +28 -0
- package/src/eval/validator.ts +31 -0
- package/src/functions/actions.ts +288 -0
- package/src/functions/audit.ts +61 -0
- package/src/functions/auto-forget.ts +169 -0
- package/src/functions/branch-aware.ts +169 -0
- package/src/functions/cascade.ts +80 -0
- package/src/functions/checkpoints.ts +209 -0
- package/src/functions/claude-bridge.ts +161 -0
- package/src/functions/compress.ts +194 -0
- package/src/functions/consolidate.ts +212 -0
- package/src/functions/consolidation-pipeline.ts +258 -0
- package/src/functions/context.ts +169 -0
- package/src/functions/crystallize.ts +293 -0
- package/src/functions/dedup.ts +57 -0
- package/src/functions/diagnostics.ts +785 -0
- package/src/functions/enrich.ts +132 -0
- package/src/functions/evict.ts +163 -0
- package/src/functions/export-import.ts +508 -0
- package/src/functions/facets.ts +248 -0
- package/src/functions/file-index.ts +106 -0
- package/src/functions/flow-compress.ts +214 -0
- package/src/functions/frontier.ts +196 -0
- package/src/functions/governance.ts +131 -0
- package/src/functions/graph-retrieval.ts +277 -0
- package/src/functions/graph.ts +275 -0
- package/src/functions/leases.ts +216 -0
- package/src/functions/lessons.ts +253 -0
- package/src/functions/mesh.ts +434 -0
- package/src/functions/migrate.ts +165 -0
- package/src/functions/observe.ts +144 -0
- package/src/functions/obsidian-export.ts +310 -0
- package/src/functions/patterns.ts +138 -0
- package/src/functions/privacy.ts +39 -0
- package/src/functions/profile.ts +155 -0
- package/src/functions/query-expansion.ts +186 -0
- package/src/functions/relations.ts +237 -0
- package/src/functions/remember.ts +162 -0
- package/src/functions/retention.ts +235 -0
- package/src/functions/routines.ts +289 -0
- package/src/functions/search.ts +80 -0
- package/src/functions/sentinels.ts +417 -0
- package/src/functions/signals.ts +186 -0
- package/src/functions/sketches.ts +274 -0
- package/src/functions/sliding-window.ts +257 -0
- package/src/functions/smart-search.ts +115 -0
- package/src/functions/snapshot.ts +219 -0
- package/src/functions/summarize.ts +155 -0
- package/src/functions/team.ts +147 -0
- package/src/functions/temporal-graph.ts +476 -0
- package/src/functions/timeline.ts +138 -0
- package/src/functions/verify.ts +117 -0
- package/src/health/monitor.ts +110 -0
- package/src/health/thresholds.ts +73 -0
- package/src/hooks/notification.ts +52 -0
- package/src/hooks/post-tool-failure.ts +58 -0
- package/src/hooks/post-tool-use.ts +62 -0
- package/src/hooks/pre-compact.ts +60 -0
- package/src/hooks/pre-tool-use.ts +72 -0
- package/src/hooks/prompt-submit.ts +46 -0
- package/src/hooks/session-end.ts +71 -0
- package/src/hooks/session-start.ts +48 -0
- package/src/hooks/stop.ts +39 -0
- package/src/hooks/subagent-start.ts +49 -0
- package/src/hooks/subagent-stop.ts +54 -0
- package/src/hooks/task-completed.ts +54 -0
- package/src/index.ts +342 -0
- package/src/mcp/in-memory-kv.ts +61 -0
- package/src/mcp/server.ts +1455 -0
- package/src/mcp/standalone.ts +177 -0
- package/src/mcp/tools-registry.ts +769 -0
- package/src/mcp/transport.ts +91 -0
- package/src/prompts/compression.ts +67 -0
- package/src/prompts/consolidation.ts +48 -0
- package/src/prompts/graph-extraction.ts +35 -0
- package/src/prompts/summary.ts +38 -0
- package/src/prompts/xml.ts +26 -0
- package/src/providers/agent-sdk.ts +34 -0
- package/src/providers/anthropic.ts +35 -0
- package/src/providers/circuit-breaker.ts +82 -0
- package/src/providers/embedding/cohere.ts +46 -0
- package/src/providers/embedding/gemini.ts +54 -0
- package/src/providers/embedding/index.ts +39 -0
- package/src/providers/embedding/local.ts +52 -0
- package/src/providers/embedding/openai.ts +45 -0
- package/src/providers/embedding/openrouter.ts +51 -0
- package/src/providers/embedding/voyage.ts +46 -0
- package/src/providers/fallback-chain.ts +31 -0
- package/src/providers/index.ts +84 -0
- package/src/providers/openrouter.ts +71 -0
- package/src/providers/resilient.ts +37 -0
- package/src/state/hybrid-search.ts +295 -0
- package/src/state/index-persistence.ts +63 -0
- package/src/state/keyed-mutex.ts +18 -0
- package/src/state/kv.ts +33 -0
- package/src/state/schema.ts +71 -0
- package/src/state/search-index.ts +245 -0
- package/src/state/stemmer.ts +104 -0
- package/src/state/synonyms.ts +63 -0
- package/src/state/vector-index.ts +130 -0
- package/src/telemetry/setup.ts +116 -0
- package/src/triggers/api.ts +1904 -0
- package/src/triggers/events.ts +71 -0
- package/src/types.ts +769 -0
- package/src/version.ts +1 -0
- package/src/viewer/index.html +2497 -0
- package/src/viewer/server.ts +207 -0
- package/src/xenova.d.ts +3 -0
- package/test/actions.test.ts +490 -0
- package/test/audit.test.ts +108 -0
- package/test/auto-forget.test.ts +188 -0
- package/test/cascade.test.ts +277 -0
- package/test/checkpoints.test.ts +493 -0
- package/test/circuit-breaker.test.ts +107 -0
- package/test/claude-bridge.test.ts +178 -0
- package/test/confidence.test.ts +247 -0
- package/test/consistency.test.ts +61 -0
- package/test/consolidation-pipeline.test.ts +251 -0
- package/test/crystallize.test.ts +521 -0
- package/test/diagnostics.test.ts +638 -0
- package/test/embedding-provider.test.ts +49 -0
- package/test/enrich.test.ts +209 -0
- package/test/eval.test.ts +300 -0
- package/test/export-import.test.ts +251 -0
- package/test/facets.test.ts +448 -0
- package/test/fallback-chain.test.ts +93 -0
- package/test/frontier.test.ts +485 -0
- package/test/governance.test.ts +147 -0
- package/test/graph-retrieval.test.ts +186 -0
- package/test/graph.test.ts +160 -0
- package/test/helpers/mocks.ts +40 -0
- package/test/hybrid-search.test.ts +145 -0
- package/test/index-persistence.test.ts +124 -0
- package/test/integration.test.ts +265 -0
- package/test/leases.test.ts +399 -0
- package/test/mcp-prompts.test.ts +218 -0
- package/test/mcp-resources.test.ts +286 -0
- package/test/mcp-standalone.test.ts +113 -0
- package/test/mesh.test.ts +700 -0
- package/test/privacy.test.ts +87 -0
- package/test/profile.test.ts +161 -0
- package/test/query-expansion.test.ts +154 -0
- package/test/relations.test.ts +198 -0
- package/test/retention.test.ts +245 -0
- package/test/routines.test.ts +497 -0
- package/test/schema-fingerprint.test.ts +81 -0
- package/test/schema.test.ts +42 -0
- package/test/search-index.test.ts +128 -0
- package/test/sentinels.test.ts +626 -0
- package/test/signals.test.ts +410 -0
- package/test/sketches.test.ts +549 -0
- package/test/sliding-window.test.ts +199 -0
- package/test/smart-search.test.ts +169 -0
- package/test/snapshot.test.ts +165 -0
- package/test/team.test.ts +156 -0
- package/test/temporal-graph.test.ts +378 -0
- package/test/timeline.test.ts +148 -0
- package/test/vector-index.test.ts +79 -0
- package/test/verify.test.ts +209 -0
- package/test/xml.test.ts +65 -0
- package/tsconfig.json +22 -0
- package/tsdown.config.ts +62 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("iii-sdk", () => ({
|
|
4
|
+
getContext: () => ({
|
|
5
|
+
logger: { info: vi.fn(), error: vi.fn(), warn: vi.fn() },
|
|
6
|
+
}),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
import { registerMcpEndpoints } from "../src/mcp/server.js";
|
|
10
|
+
import type { Session, SessionSummary, Memory } from "../src/types.js";
|
|
11
|
+
|
|
12
|
+
function mockKV() {
|
|
13
|
+
const store = new Map<string, Map<string, unknown>>();
|
|
14
|
+
return {
|
|
15
|
+
get: async <T>(scope: string, key: string): Promise<T | null> => {
|
|
16
|
+
return (store.get(scope)?.get(key) as T) ?? null;
|
|
17
|
+
},
|
|
18
|
+
set: async <T>(scope: string, key: string, data: T): Promise<T> => {
|
|
19
|
+
if (!store.has(scope)) store.set(scope, new Map());
|
|
20
|
+
store.get(scope)!.set(key, data);
|
|
21
|
+
return data;
|
|
22
|
+
},
|
|
23
|
+
delete: async (scope: string, key: string): Promise<void> => {
|
|
24
|
+
store.get(scope)?.delete(key);
|
|
25
|
+
},
|
|
26
|
+
list: async <T>(scope: string): Promise<T[]> => {
|
|
27
|
+
const entries = store.get(scope);
|
|
28
|
+
return entries ? (Array.from(entries.values()) as T[]) : [];
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function mockSdk() {
|
|
34
|
+
const functions = new Map<string, Function>();
|
|
35
|
+
const triggerOverrides = new Map<string, Function>();
|
|
36
|
+
return {
|
|
37
|
+
registerFunction: (opts: { id: string }, handler: Function) => {
|
|
38
|
+
functions.set(opts.id, handler);
|
|
39
|
+
},
|
|
40
|
+
registerTrigger: () => {},
|
|
41
|
+
trigger: async (id: string, data: unknown) => {
|
|
42
|
+
if (triggerOverrides.has(id)) {
|
|
43
|
+
return triggerOverrides.get(id)!(data);
|
|
44
|
+
}
|
|
45
|
+
const fn = functions.get(id);
|
|
46
|
+
if (!fn) throw new Error(`No function: ${id}`);
|
|
47
|
+
return fn(data);
|
|
48
|
+
},
|
|
49
|
+
overrideTrigger: (id: string, handler: Function) => {
|
|
50
|
+
triggerOverrides.set(id, handler);
|
|
51
|
+
},
|
|
52
|
+
getFunction: (id: string) => functions.get(id),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function makeReq(body?: unknown, headers?: Record<string, string>) {
|
|
57
|
+
return {
|
|
58
|
+
body,
|
|
59
|
+
headers: headers || {},
|
|
60
|
+
query_params: {},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe("MCP Resources", () => {
|
|
65
|
+
let sdk: ReturnType<typeof mockSdk>;
|
|
66
|
+
let kv: ReturnType<typeof mockKV>;
|
|
67
|
+
|
|
68
|
+
beforeEach(() => {
|
|
69
|
+
sdk = mockSdk();
|
|
70
|
+
kv = mockKV();
|
|
71
|
+
registerMcpEndpoints(sdk as never, kv as never);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("lists 6 resources", async () => {
|
|
75
|
+
const fn = sdk.getFunction("mcp::resources::list")!;
|
|
76
|
+
const result = (await fn(makeReq())) as {
|
|
77
|
+
status_code: number;
|
|
78
|
+
body: { resources: unknown[] };
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
expect(result.status_code).toBe(200);
|
|
82
|
+
expect(result.body.resources).toHaveLength(6);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("reads agentmemory://status", async () => {
|
|
86
|
+
const session: Session = {
|
|
87
|
+
id: "ses_1",
|
|
88
|
+
project: "/test",
|
|
89
|
+
cwd: "/test",
|
|
90
|
+
startedAt: new Date().toISOString(),
|
|
91
|
+
status: "active",
|
|
92
|
+
observationCount: 5,
|
|
93
|
+
};
|
|
94
|
+
await kv.set("mem:sessions", "ses_1", session);
|
|
95
|
+
|
|
96
|
+
const fn = sdk.getFunction("mcp::resources::read")!;
|
|
97
|
+
const result = (await fn(makeReq({ uri: "agentmemory://status" }))) as {
|
|
98
|
+
status_code: number;
|
|
99
|
+
body: { contents: Array<{ text: string }> };
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
expect(result.status_code).toBe(200);
|
|
103
|
+
const data = JSON.parse(result.body.contents[0].text);
|
|
104
|
+
expect(data.sessionCount).toBe(1);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("reads agentmemory://project/{name}/profile", async () => {
|
|
108
|
+
sdk.overrideTrigger("mem::profile", async () => ({
|
|
109
|
+
project: "/myapp",
|
|
110
|
+
topConcepts: [{ concept: "auth", frequency: 5 }],
|
|
111
|
+
}));
|
|
112
|
+
|
|
113
|
+
const fn = sdk.getFunction("mcp::resources::read")!;
|
|
114
|
+
const result = (await fn(
|
|
115
|
+
makeReq({ uri: "agentmemory://project/myapp/profile" }),
|
|
116
|
+
)) as {
|
|
117
|
+
status_code: number;
|
|
118
|
+
body: { contents: Array<{ text: string }> };
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
expect(result.status_code).toBe(200);
|
|
122
|
+
const data = JSON.parse(result.body.contents[0].text);
|
|
123
|
+
expect(data.project).toBe("/myapp");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("reads agentmemory://project/{name}/recent with sorted summaries", async () => {
|
|
127
|
+
const summaries: SessionSummary[] = [
|
|
128
|
+
{
|
|
129
|
+
sessionId: "ses_1",
|
|
130
|
+
project: "myapp",
|
|
131
|
+
createdAt: "2026-01-01T00:00:00Z",
|
|
132
|
+
title: "Old session",
|
|
133
|
+
narrative: "old",
|
|
134
|
+
keyDecisions: [],
|
|
135
|
+
filesModified: [],
|
|
136
|
+
concepts: [],
|
|
137
|
+
observationCount: 1,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
sessionId: "ses_2",
|
|
141
|
+
project: "myapp",
|
|
142
|
+
createdAt: "2026-02-01T00:00:00Z",
|
|
143
|
+
title: "New session",
|
|
144
|
+
narrative: "new",
|
|
145
|
+
keyDecisions: [],
|
|
146
|
+
filesModified: [],
|
|
147
|
+
concepts: [],
|
|
148
|
+
observationCount: 2,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
sessionId: "ses_3",
|
|
152
|
+
project: "other",
|
|
153
|
+
createdAt: "2026-02-15T00:00:00Z",
|
|
154
|
+
title: "Other project",
|
|
155
|
+
narrative: "other",
|
|
156
|
+
keyDecisions: [],
|
|
157
|
+
filesModified: [],
|
|
158
|
+
concepts: [],
|
|
159
|
+
observationCount: 3,
|
|
160
|
+
},
|
|
161
|
+
];
|
|
162
|
+
for (const s of summaries) {
|
|
163
|
+
await kv.set("mem:summaries", s.sessionId, s);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const fn = sdk.getFunction("mcp::resources::read")!;
|
|
167
|
+
const result = (await fn(
|
|
168
|
+
makeReq({ uri: "agentmemory://project/myapp/recent" }),
|
|
169
|
+
)) as {
|
|
170
|
+
status_code: number;
|
|
171
|
+
body: { contents: Array<{ text: string }> };
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
expect(result.status_code).toBe(200);
|
|
175
|
+
const data = JSON.parse(result.body.contents[0].text);
|
|
176
|
+
expect(data).toHaveLength(2);
|
|
177
|
+
expect(data[0].sessionId).toBe("ses_2");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("reads agentmemory://memories/latest", async () => {
|
|
181
|
+
const memories: Memory[] = [
|
|
182
|
+
{
|
|
183
|
+
id: "mem_1",
|
|
184
|
+
createdAt: "2026-01-01T00:00:00Z",
|
|
185
|
+
updatedAt: "2026-02-01T00:00:00Z",
|
|
186
|
+
type: "pattern",
|
|
187
|
+
title: "Latest pattern",
|
|
188
|
+
content: "content",
|
|
189
|
+
concepts: [],
|
|
190
|
+
files: [],
|
|
191
|
+
sessionIds: [],
|
|
192
|
+
strength: 5,
|
|
193
|
+
version: 1,
|
|
194
|
+
isLatest: true,
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
id: "mem_2",
|
|
198
|
+
createdAt: "2026-01-01T00:00:00Z",
|
|
199
|
+
updatedAt: "2026-01-15T00:00:00Z",
|
|
200
|
+
type: "bug",
|
|
201
|
+
title: "Old bug",
|
|
202
|
+
content: "content",
|
|
203
|
+
concepts: [],
|
|
204
|
+
files: [],
|
|
205
|
+
sessionIds: [],
|
|
206
|
+
strength: 3,
|
|
207
|
+
version: 2,
|
|
208
|
+
isLatest: false,
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
for (const m of memories) {
|
|
212
|
+
await kv.set("mem:memories", m.id, m);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const fn = sdk.getFunction("mcp::resources::read")!;
|
|
216
|
+
const result = (await fn(
|
|
217
|
+
makeReq({ uri: "agentmemory://memories/latest" }),
|
|
218
|
+
)) as {
|
|
219
|
+
status_code: number;
|
|
220
|
+
body: { contents: Array<{ text: string }> };
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
expect(result.status_code).toBe(200);
|
|
224
|
+
const data = JSON.parse(result.body.contents[0].text);
|
|
225
|
+
expect(data).toHaveLength(1);
|
|
226
|
+
expect(data[0].id).toBe("mem_1");
|
|
227
|
+
expect(data[0].title).toBe("Latest pattern");
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("returns 404 for unknown URI", async () => {
|
|
231
|
+
const fn = sdk.getFunction("mcp::resources::read")!;
|
|
232
|
+
const result = (await fn(
|
|
233
|
+
makeReq({ uri: "agentmemory://nonexistent" }),
|
|
234
|
+
)) as { status_code: number };
|
|
235
|
+
|
|
236
|
+
expect(result.status_code).toBe(404);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("returns 401 when auth fails", async () => {
|
|
240
|
+
const authedSdk = mockSdk();
|
|
241
|
+
const authedKv = mockKV();
|
|
242
|
+
registerMcpEndpoints(authedSdk as never, authedKv as never, "test-secret");
|
|
243
|
+
|
|
244
|
+
const fn = authedSdk.getFunction("mcp::resources::list")!;
|
|
245
|
+
const result = (await fn(makeReq())) as { status_code: number };
|
|
246
|
+
expect(result.status_code).toBe(401);
|
|
247
|
+
|
|
248
|
+
const authedResult = (await fn(
|
|
249
|
+
makeReq(undefined, { authorization: "Bearer test-secret" }),
|
|
250
|
+
)) as { status_code: number };
|
|
251
|
+
expect(authedResult.status_code).toBe(200);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("handles URI with special characters via decodeURIComponent", async () => {
|
|
255
|
+
sdk.overrideTrigger("mem::profile", async (data: any) => ({
|
|
256
|
+
project: data.project,
|
|
257
|
+
topConcepts: [],
|
|
258
|
+
}));
|
|
259
|
+
|
|
260
|
+
const fn = sdk.getFunction("mcp::resources::read")!;
|
|
261
|
+
const result = (await fn(
|
|
262
|
+
makeReq({
|
|
263
|
+
uri: "agentmemory://project/my%20app%2Fsubdir/profile",
|
|
264
|
+
}),
|
|
265
|
+
)) as {
|
|
266
|
+
status_code: number;
|
|
267
|
+
body: { contents: Array<{ text: string }> };
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
expect(result.status_code).toBe(200);
|
|
271
|
+
const data = JSON.parse(result.body.contents[0].text);
|
|
272
|
+
expect(data.project).toBe("my app/subdir");
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("returns 400 for malformed percent-encoding in URI", async () => {
|
|
276
|
+
const fn = sdk.getFunction("mcp::resources::read")!;
|
|
277
|
+
const result = (await fn(
|
|
278
|
+
makeReq({
|
|
279
|
+
uri: "agentmemory://project/bad%E0encoding/profile",
|
|
280
|
+
}),
|
|
281
|
+
)) as { status_code: number; body: { error: string } };
|
|
282
|
+
|
|
283
|
+
expect(result.status_code).toBe(400);
|
|
284
|
+
expect(result.body.error).toContain("percent-encoding");
|
|
285
|
+
});
|
|
286
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("iii-sdk", () => ({
|
|
4
|
+
getContext: () => ({
|
|
5
|
+
logger: { info: vi.fn(), error: vi.fn(), warn: vi.fn() },
|
|
6
|
+
}),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
vi.mock("node:fs", () => ({
|
|
10
|
+
existsSync: vi.fn().mockReturnValue(false),
|
|
11
|
+
readFileSync: vi.fn(),
|
|
12
|
+
writeFileSync: vi.fn(),
|
|
13
|
+
mkdirSync: vi.fn(),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
getAllTools,
|
|
18
|
+
CORE_TOOLS,
|
|
19
|
+
V040_TOOLS,
|
|
20
|
+
} from "../src/mcp/tools-registry.js";
|
|
21
|
+
import { InMemoryKV } from "../src/mcp/in-memory-kv.js";
|
|
22
|
+
import { writeFileSync } from "node:fs";
|
|
23
|
+
|
|
24
|
+
describe("Tools Registry", () => {
|
|
25
|
+
it("getAllTools returns all tools with unique names", () => {
|
|
26
|
+
const tools = getAllTools();
|
|
27
|
+
expect(tools.length).toBeGreaterThanOrEqual(41);
|
|
28
|
+
const names = new Set(tools.map((t) => t.name));
|
|
29
|
+
expect(names.size).toBe(tools.length);
|
|
30
|
+
for (const required of [
|
|
31
|
+
"memory_verify",
|
|
32
|
+
"memory_lesson_save",
|
|
33
|
+
"memory_lesson_recall",
|
|
34
|
+
"memory_obsidian_export",
|
|
35
|
+
"memory_save",
|
|
36
|
+
"memory_recall",
|
|
37
|
+
]) {
|
|
38
|
+
expect(tools.some((t) => t.name === required)).toBe(true);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("CORE_TOOLS has 10 items", () => {
|
|
43
|
+
expect(CORE_TOOLS.length).toBe(10);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("V040_TOOLS has 8 items", () => {
|
|
47
|
+
expect(V040_TOOLS.length).toBe(8);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("all tools have required name, description, inputSchema fields", () => {
|
|
51
|
+
const tools = getAllTools();
|
|
52
|
+
for (const tool of tools) {
|
|
53
|
+
expect(tool.name).toBeDefined();
|
|
54
|
+
expect(typeof tool.name).toBe("string");
|
|
55
|
+
expect(tool.name.length).toBeGreaterThan(0);
|
|
56
|
+
expect(tool.description).toBeDefined();
|
|
57
|
+
expect(typeof tool.description).toBe("string");
|
|
58
|
+
expect(tool.inputSchema).toBeDefined();
|
|
59
|
+
expect(tool.inputSchema.type).toBe("object");
|
|
60
|
+
expect(tool.inputSchema.properties).toBeDefined();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("InMemoryKV", () => {
|
|
66
|
+
let kv: InMemoryKV;
|
|
67
|
+
|
|
68
|
+
beforeEach(() => {
|
|
69
|
+
kv = new InMemoryKV();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("get/set/list/delete operations work", async () => {
|
|
73
|
+
await kv.set("scope1", "key1", { value: "hello" });
|
|
74
|
+
const result = await kv.get<{ value: string }>("scope1", "key1");
|
|
75
|
+
expect(result).toEqual({ value: "hello" });
|
|
76
|
+
|
|
77
|
+
const list = await kv.list("scope1");
|
|
78
|
+
expect(list.length).toBe(1);
|
|
79
|
+
|
|
80
|
+
await kv.delete("scope1", "key1");
|
|
81
|
+
const afterDelete = await kv.get("scope1", "key1");
|
|
82
|
+
expect(afterDelete).toBeNull();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("list returns empty array for unknown scope", async () => {
|
|
86
|
+
const result = await kv.list("nonexistent");
|
|
87
|
+
expect(result).toEqual([]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("persist writes JSON", async () => {
|
|
91
|
+
const kvWithPersist = new InMemoryKV("/tmp/test-kv.json");
|
|
92
|
+
await kvWithPersist.set("scope1", "key1", { data: "test" });
|
|
93
|
+
kvWithPersist.persist();
|
|
94
|
+
|
|
95
|
+
expect(writeFileSync).toHaveBeenCalledWith(
|
|
96
|
+
"/tmp/test-kv.json",
|
|
97
|
+
expect.any(String),
|
|
98
|
+
"utf-8",
|
|
99
|
+
);
|
|
100
|
+
const written = vi.mocked(writeFileSync).mock.calls[0][1] as string;
|
|
101
|
+
const parsed = JSON.parse(written);
|
|
102
|
+
expect(parsed.scope1.key1).toEqual({ data: "test" });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("set overwrites existing values", async () => {
|
|
106
|
+
await kv.set("scope1", "key1", "first");
|
|
107
|
+
await kv.set("scope1", "key1", "second");
|
|
108
|
+
const result = await kv.get("scope1", "key1");
|
|
109
|
+
expect(result).toBe("second");
|
|
110
|
+
const list = await kv.list("scope1");
|
|
111
|
+
expect(list.length).toBe(1);
|
|
112
|
+
});
|
|
113
|
+
});
|