@agentmemory/agentmemory 0.7.0 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/AGENTS.md +2 -2
  2. package/README.md +76 -82
  3. package/dist/cli.mjs +99 -32
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/index.mjs +4 -2
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/{src-QxitMPfJ.mjs → src-sYZDDbiA.mjs} +5 -3
  8. package/dist/src-sYZDDbiA.mjs.map +1 -0
  9. package/dist/standalone.mjs +1 -1
  10. package/dist/standalone.mjs.map +1 -1
  11. package/package.json +11 -1
  12. package/plugin/.claude-plugin/plugin.json +1 -1
  13. package/plugin/scripts/notification.d.mts +1 -0
  14. package/plugin/scripts/notification.mjs.map +1 -0
  15. package/plugin/scripts/post-tool-failure.d.mts +1 -0
  16. package/plugin/scripts/post-tool-failure.mjs.map +1 -0
  17. package/plugin/scripts/post-tool-use.d.mts +1 -0
  18. package/plugin/scripts/post-tool-use.mjs.map +1 -0
  19. package/plugin/scripts/pre-compact.d.mts +1 -0
  20. package/plugin/scripts/pre-compact.mjs.map +1 -0
  21. package/plugin/scripts/pre-tool-use.d.mts +1 -0
  22. package/plugin/scripts/pre-tool-use.mjs.map +1 -0
  23. package/plugin/scripts/prompt-submit.d.mts +1 -0
  24. package/plugin/scripts/prompt-submit.mjs.map +1 -0
  25. package/plugin/scripts/session-end.d.mts +1 -0
  26. package/plugin/scripts/session-end.mjs.map +1 -0
  27. package/plugin/scripts/session-start.d.mts +1 -0
  28. package/plugin/scripts/session-start.mjs.map +1 -0
  29. package/plugin/scripts/stop.d.mts +1 -0
  30. package/plugin/scripts/stop.mjs.map +1 -0
  31. package/plugin/scripts/subagent-start.d.mts +1 -0
  32. package/plugin/scripts/subagent-start.mjs.map +1 -0
  33. package/plugin/scripts/subagent-stop.d.mts +1 -0
  34. package/plugin/scripts/subagent-stop.mjs.map +1 -0
  35. package/plugin/scripts/task-completed.d.mts +1 -0
  36. package/plugin/scripts/task-completed.mjs.map +1 -0
  37. package/.claude-plugin/marketplace.json +0 -14
  38. package/.github/workflows/ci.yml +0 -22
  39. package/.github/workflows/publish.yml +0 -28
  40. package/assets/banner.png +0 -0
  41. package/assets/demo.gif +0 -0
  42. package/assets/demo.mp4 +0 -0
  43. package/benchmark/QUALITY.md +0 -73
  44. package/benchmark/REAL-EMBEDDINGS.md +0 -67
  45. package/benchmark/SCALE.md +0 -110
  46. package/benchmark/dataset.ts +0 -293
  47. package/benchmark/quality-eval.ts +0 -643
  48. package/benchmark/real-embeddings-eval.ts +0 -405
  49. package/benchmark/scale-eval.ts +0 -398
  50. package/dist/src-QxitMPfJ.mjs.map +0 -1
  51. package/src/auth.ts +0 -12
  52. package/src/cli.ts +0 -159
  53. package/src/config.ts +0 -221
  54. package/src/eval/metrics-store.ts +0 -65
  55. package/src/eval/quality.ts +0 -51
  56. package/src/eval/schemas.ts +0 -124
  57. package/src/eval/self-correct.ts +0 -28
  58. package/src/eval/validator.ts +0 -31
  59. package/src/functions/actions.ts +0 -288
  60. package/src/functions/audit.ts +0 -61
  61. package/src/functions/auto-forget.ts +0 -169
  62. package/src/functions/branch-aware.ts +0 -169
  63. package/src/functions/cascade.ts +0 -80
  64. package/src/functions/checkpoints.ts +0 -209
  65. package/src/functions/claude-bridge.ts +0 -161
  66. package/src/functions/compress.ts +0 -194
  67. package/src/functions/consolidate.ts +0 -212
  68. package/src/functions/consolidation-pipeline.ts +0 -258
  69. package/src/functions/context.ts +0 -169
  70. package/src/functions/crystallize.ts +0 -293
  71. package/src/functions/dedup.ts +0 -57
  72. package/src/functions/diagnostics.ts +0 -785
  73. package/src/functions/enrich.ts +0 -132
  74. package/src/functions/evict.ts +0 -163
  75. package/src/functions/export-import.ts +0 -508
  76. package/src/functions/facets.ts +0 -248
  77. package/src/functions/file-index.ts +0 -106
  78. package/src/functions/flow-compress.ts +0 -214
  79. package/src/functions/frontier.ts +0 -196
  80. package/src/functions/governance.ts +0 -131
  81. package/src/functions/graph-retrieval.ts +0 -277
  82. package/src/functions/graph.ts +0 -275
  83. package/src/functions/leases.ts +0 -216
  84. package/src/functions/lessons.ts +0 -253
  85. package/src/functions/mesh.ts +0 -434
  86. package/src/functions/migrate.ts +0 -165
  87. package/src/functions/observe.ts +0 -144
  88. package/src/functions/obsidian-export.ts +0 -310
  89. package/src/functions/patterns.ts +0 -138
  90. package/src/functions/privacy.ts +0 -39
  91. package/src/functions/profile.ts +0 -155
  92. package/src/functions/query-expansion.ts +0 -186
  93. package/src/functions/relations.ts +0 -237
  94. package/src/functions/remember.ts +0 -162
  95. package/src/functions/retention.ts +0 -235
  96. package/src/functions/routines.ts +0 -289
  97. package/src/functions/search.ts +0 -80
  98. package/src/functions/sentinels.ts +0 -417
  99. package/src/functions/signals.ts +0 -186
  100. package/src/functions/sketches.ts +0 -274
  101. package/src/functions/sliding-window.ts +0 -257
  102. package/src/functions/smart-search.ts +0 -115
  103. package/src/functions/snapshot.ts +0 -219
  104. package/src/functions/summarize.ts +0 -155
  105. package/src/functions/team.ts +0 -147
  106. package/src/functions/temporal-graph.ts +0 -476
  107. package/src/functions/timeline.ts +0 -138
  108. package/src/functions/verify.ts +0 -117
  109. package/src/health/monitor.ts +0 -110
  110. package/src/health/thresholds.ts +0 -73
  111. package/src/hooks/notification.ts +0 -52
  112. package/src/hooks/post-tool-failure.ts +0 -58
  113. package/src/hooks/post-tool-use.ts +0 -62
  114. package/src/hooks/pre-compact.ts +0 -60
  115. package/src/hooks/pre-tool-use.ts +0 -72
  116. package/src/hooks/prompt-submit.ts +0 -46
  117. package/src/hooks/session-end.ts +0 -71
  118. package/src/hooks/session-start.ts +0 -48
  119. package/src/hooks/stop.ts +0 -39
  120. package/src/hooks/subagent-start.ts +0 -49
  121. package/src/hooks/subagent-stop.ts +0 -54
  122. package/src/hooks/task-completed.ts +0 -54
  123. package/src/index.ts +0 -342
  124. package/src/mcp/in-memory-kv.ts +0 -61
  125. package/src/mcp/server.ts +0 -1455
  126. package/src/mcp/standalone.ts +0 -177
  127. package/src/mcp/tools-registry.ts +0 -769
  128. package/src/mcp/transport.ts +0 -91
  129. package/src/prompts/compression.ts +0 -67
  130. package/src/prompts/consolidation.ts +0 -48
  131. package/src/prompts/graph-extraction.ts +0 -35
  132. package/src/prompts/summary.ts +0 -38
  133. package/src/prompts/xml.ts +0 -26
  134. package/src/providers/agent-sdk.ts +0 -34
  135. package/src/providers/anthropic.ts +0 -35
  136. package/src/providers/circuit-breaker.ts +0 -82
  137. package/src/providers/embedding/cohere.ts +0 -46
  138. package/src/providers/embedding/gemini.ts +0 -54
  139. package/src/providers/embedding/index.ts +0 -39
  140. package/src/providers/embedding/local.ts +0 -52
  141. package/src/providers/embedding/openai.ts +0 -45
  142. package/src/providers/embedding/openrouter.ts +0 -51
  143. package/src/providers/embedding/voyage.ts +0 -46
  144. package/src/providers/fallback-chain.ts +0 -31
  145. package/src/providers/index.ts +0 -84
  146. package/src/providers/openrouter.ts +0 -71
  147. package/src/providers/resilient.ts +0 -37
  148. package/src/state/hybrid-search.ts +0 -295
  149. package/src/state/index-persistence.ts +0 -63
  150. package/src/state/keyed-mutex.ts +0 -18
  151. package/src/state/kv.ts +0 -33
  152. package/src/state/schema.ts +0 -71
  153. package/src/state/search-index.ts +0 -245
  154. package/src/state/stemmer.ts +0 -104
  155. package/src/state/synonyms.ts +0 -63
  156. package/src/state/vector-index.ts +0 -130
  157. package/src/telemetry/setup.ts +0 -116
  158. package/src/triggers/api.ts +0 -1904
  159. package/src/triggers/events.ts +0 -71
  160. package/src/types.ts +0 -769
  161. package/src/version.ts +0 -1
  162. package/src/viewer/index.html +0 -2497
  163. package/src/viewer/server.ts +0 -207
  164. package/src/xenova.d.ts +0 -3
  165. package/test/actions.test.ts +0 -490
  166. package/test/audit.test.ts +0 -108
  167. package/test/auto-forget.test.ts +0 -188
  168. package/test/cascade.test.ts +0 -277
  169. package/test/checkpoints.test.ts +0 -493
  170. package/test/circuit-breaker.test.ts +0 -107
  171. package/test/claude-bridge.test.ts +0 -178
  172. package/test/confidence.test.ts +0 -247
  173. package/test/consistency.test.ts +0 -61
  174. package/test/consolidation-pipeline.test.ts +0 -251
  175. package/test/crystallize.test.ts +0 -521
  176. package/test/diagnostics.test.ts +0 -638
  177. package/test/embedding-provider.test.ts +0 -49
  178. package/test/enrich.test.ts +0 -209
  179. package/test/eval.test.ts +0 -300
  180. package/test/export-import.test.ts +0 -251
  181. package/test/facets.test.ts +0 -448
  182. package/test/fallback-chain.test.ts +0 -93
  183. package/test/frontier.test.ts +0 -485
  184. package/test/governance.test.ts +0 -147
  185. package/test/graph-retrieval.test.ts +0 -186
  186. package/test/graph.test.ts +0 -160
  187. package/test/helpers/mocks.ts +0 -40
  188. package/test/hybrid-search.test.ts +0 -145
  189. package/test/index-persistence.test.ts +0 -124
  190. package/test/integration.test.ts +0 -265
  191. package/test/leases.test.ts +0 -399
  192. package/test/mcp-prompts.test.ts +0 -218
  193. package/test/mcp-resources.test.ts +0 -286
  194. package/test/mcp-standalone.test.ts +0 -113
  195. package/test/mesh.test.ts +0 -700
  196. package/test/privacy.test.ts +0 -87
  197. package/test/profile.test.ts +0 -161
  198. package/test/query-expansion.test.ts +0 -154
  199. package/test/relations.test.ts +0 -198
  200. package/test/retention.test.ts +0 -245
  201. package/test/routines.test.ts +0 -497
  202. package/test/schema-fingerprint.test.ts +0 -81
  203. package/test/schema.test.ts +0 -42
  204. package/test/search-index.test.ts +0 -128
  205. package/test/sentinels.test.ts +0 -626
  206. package/test/signals.test.ts +0 -410
  207. package/test/sketches.test.ts +0 -549
  208. package/test/sliding-window.test.ts +0 -199
  209. package/test/smart-search.test.ts +0 -169
  210. package/test/snapshot.test.ts +0 -165
  211. package/test/team.test.ts +0 -156
  212. package/test/temporal-graph.test.ts +0 -378
  213. package/test/timeline.test.ts +0 -148
  214. package/test/vector-index.test.ts +0 -79
  215. package/test/verify.test.ts +0 -209
  216. package/test/xml.test.ts +0 -65
  217. package/tsconfig.json +0 -22
  218. package/tsdown.config.ts +0 -62
@@ -1,199 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import type { CompressedObservation, MemoryProvider } from "../src/types.js";
3
-
4
- function makeObs(
5
- id: string,
6
- title: string,
7
- narrative: string,
8
- overrides: Partial<CompressedObservation> = {},
9
- ): CompressedObservation {
10
- return {
11
- id,
12
- sessionId: "ses_1",
13
- timestamp: new Date().toISOString(),
14
- type: "file_edit",
15
- title,
16
- subtitle: "",
17
- facts: [],
18
- narrative,
19
- concepts: [],
20
- files: [],
21
- importance: 5,
22
- ...overrides,
23
- };
24
- }
25
-
26
- function mockKV(observations: CompressedObservation[] = []) {
27
- const store = new Map<string, Map<string, unknown>>();
28
- const obsMap = new Map<string, unknown>();
29
- for (const obs of observations) {
30
- obsMap.set(obs.id, obs);
31
- }
32
- store.set("mem:obs:ses_1", obsMap);
33
-
34
- return {
35
- get: async <T>(scope: string, key: string): Promise<T | null> => {
36
- return (store.get(scope)?.get(key) as T) ?? null;
37
- },
38
- set: async <T>(scope: string, key: string, data: T): Promise<T> => {
39
- if (!store.has(scope)) store.set(scope, new Map());
40
- store.get(scope)!.set(key, data);
41
- return data;
42
- },
43
- delete: async (scope: string, key: string): Promise<void> => {
44
- store.get(scope)?.delete(key);
45
- },
46
- list: async <T>(scope: string): Promise<T[]> => {
47
- const entries = store.get(scope);
48
- return entries ? (Array.from(entries.values()) as T[]) : [];
49
- },
50
- };
51
- }
52
-
53
- function mockSdk() {
54
- const functions = new Map<string, Function>();
55
- return {
56
- registerFunction: (opts: { id: string }, fn: Function) => {
57
- functions.set(opts.id, fn);
58
- },
59
- trigger: async (id: string, data: unknown) => {
60
- const fn = functions.get(id);
61
- if (fn) return fn(data);
62
- return null;
63
- },
64
- triggerVoid: () => {},
65
- };
66
- }
67
-
68
- function mockProvider(response: string): MemoryProvider {
69
- return {
70
- name: "test",
71
- compress: vi.fn().mockResolvedValue(response),
72
- summarize: vi.fn().mockResolvedValue(response),
73
- };
74
- }
75
-
76
- vi.mock("iii-sdk", () => ({
77
- getContext: () => ({
78
- logger: {
79
- info: () => {},
80
- warn: () => {},
81
- error: () => {},
82
- },
83
- }),
84
- }));
85
-
86
- describe("SlidingWindow", () => {
87
- it("imports without errors", async () => {
88
- const mod = await import("../src/functions/sliding-window.js");
89
- expect(mod.registerSlidingWindowFunction).toBeDefined();
90
- });
91
-
92
- it("registers both functions", async () => {
93
- const { registerSlidingWindowFunction } = await import(
94
- "../src/functions/sliding-window.js"
95
- );
96
- const sdk = mockSdk();
97
- const kv = mockKV();
98
- const provider = mockProvider("");
99
- registerSlidingWindowFunction(sdk as never, kv as never, provider);
100
-
101
- expect(sdk.trigger).toBeDefined();
102
- });
103
-
104
- it("enriches observation with sliding window context", async () => {
105
- const { registerSlidingWindowFunction } = await import(
106
- "../src/functions/sliding-window.js"
107
- );
108
-
109
- const obs1 = makeObs(
110
- "obs_1",
111
- "User discussed React framework",
112
- "The user mentioned they are working with React for their frontend.",
113
- { timestamp: "2024-01-01T00:00:00Z" },
114
- );
115
- const obs2 = makeObs(
116
- "obs_2",
117
- "Framework frustration",
118
- "The user said they hate that framework and find it hard to debug.",
119
- { timestamp: "2024-01-01T00:01:00Z" },
120
- );
121
- const obs3 = makeObs(
122
- "obs_3",
123
- "Switching to Vue",
124
- "The user decided to switch to Vue for the project.",
125
- { timestamp: "2024-01-01T00:02:00Z" },
126
- );
127
-
128
- const kv = mockKV([obs1, obs2, obs3]);
129
- const sdk = mockSdk();
130
-
131
- const enrichedXml = `<enriched>
132
- <content>The user (working with React for frontend) expressed strong frustration with React framework, finding it difficult to debug.</content>
133
- <resolved_entities>
134
- <entity original="that framework" resolved="React"/>
135
- </resolved_entities>
136
- <preferences>
137
- <preference>User dislikes React due to debugging difficulty</preference>
138
- </preferences>
139
- <context_bridges>
140
- <bridge>User was working with React before expressing frustration</bridge>
141
- </context_bridges>
142
- </enriched>`;
143
-
144
- const provider = mockProvider(enrichedXml);
145
- registerSlidingWindowFunction(sdk as never, kv as never, provider);
146
-
147
- const result = (await sdk.trigger("mem::enrich-window", {
148
- observationId: "obs_2",
149
- sessionId: "ses_1",
150
- lookback: 1,
151
- lookahead: 1,
152
- })) as { success: boolean; enriched: any };
153
-
154
- expect(result.success).toBe(true);
155
- expect(result.enriched).toBeDefined();
156
- expect(result.enriched.resolvedEntities["that framework"]).toBe("React");
157
- expect(result.enriched.preferences).toContain(
158
- "User dislikes React due to debugging difficulty",
159
- );
160
- expect(result.enriched.contextBridges.length).toBeGreaterThan(0);
161
- });
162
-
163
- it("returns null enrichment when no adjacent observations", async () => {
164
- const { registerSlidingWindowFunction } = await import(
165
- "../src/functions/sliding-window.js"
166
- );
167
- const obs = makeObs("obs_solo", "Solo observation", "Just one.");
168
- const kv = mockKV([obs]);
169
- const sdk = mockSdk();
170
- const provider = mockProvider("");
171
- registerSlidingWindowFunction(sdk as never, kv as never, provider);
172
-
173
- const result = (await sdk.trigger("mem::enrich-window", {
174
- observationId: "obs_solo",
175
- sessionId: "ses_1",
176
- })) as { success: boolean; enriched: any; reason: string };
177
-
178
- expect(result.success).toBe(true);
179
- expect(result.enriched).toBeNull();
180
- });
181
-
182
- it("returns error for missing observation", async () => {
183
- const { registerSlidingWindowFunction } = await import(
184
- "../src/functions/sliding-window.js"
185
- );
186
- const kv = mockKV([]);
187
- const sdk = mockSdk();
188
- const provider = mockProvider("");
189
- registerSlidingWindowFunction(sdk as never, kv as never, provider);
190
-
191
- const result = (await sdk.trigger("mem::enrich-window", {
192
- observationId: "nonexistent",
193
- sessionId: "ses_1",
194
- })) as { success: boolean; error: string };
195
-
196
- expect(result.success).toBe(false);
197
- expect(result.error).toBe("Observation not found");
198
- });
199
- });
@@ -1,169 +0,0 @@
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 { registerSmartSearchFunction } from "../src/functions/smart-search.js";
10
- import type {
11
- CompressedObservation,
12
- HybridSearchResult,
13
- CompactSearchResult,
14
- Session,
15
- } from "../src/types.js";
16
-
17
- function mockKV() {
18
- const store = new Map<string, Map<string, unknown>>();
19
- return {
20
- get: async <T>(scope: string, key: string): Promise<T | null> => {
21
- return (store.get(scope)?.get(key) as T) ?? null;
22
- },
23
- set: async <T>(scope: string, key: string, data: T): Promise<T> => {
24
- if (!store.has(scope)) store.set(scope, new Map());
25
- store.get(scope)!.set(key, data);
26
- return data;
27
- },
28
- delete: async (scope: string, key: string): Promise<void> => {
29
- store.get(scope)?.delete(key);
30
- },
31
- list: async <T>(scope: string): Promise<T[]> => {
32
- const entries = store.get(scope);
33
- return entries ? (Array.from(entries.values()) as T[]) : [];
34
- },
35
- };
36
- }
37
-
38
- function mockSdk() {
39
- const functions = new Map<string, Function>();
40
- return {
41
- registerFunction: (opts: { id: string }, handler: Function) => {
42
- functions.set(opts.id, handler);
43
- },
44
- registerTrigger: () => {},
45
- trigger: async (id: string, data: unknown) => {
46
- const fn = functions.get(id);
47
- if (!fn) throw new Error(`No function: ${id}`);
48
- return fn(data);
49
- },
50
- };
51
- }
52
-
53
- function makeObs(
54
- overrides: Partial<CompressedObservation> = {},
55
- ): CompressedObservation {
56
- return {
57
- id: "obs_1",
58
- sessionId: "ses_1",
59
- timestamp: "2026-02-01T10:00:00Z",
60
- type: "file_edit",
61
- title: "Edit auth handler",
62
- facts: [],
63
- narrative: "Modified auth",
64
- concepts: ["auth"],
65
- files: ["src/auth.ts"],
66
- importance: 7,
67
- ...overrides,
68
- };
69
- }
70
-
71
- describe("Smart Search Function", () => {
72
- let sdk: ReturnType<typeof mockSdk>;
73
- let kv: ReturnType<typeof mockKV>;
74
- let searchResults: HybridSearchResult[];
75
-
76
- beforeEach(async () => {
77
- sdk = mockSdk();
78
- kv = mockKV();
79
-
80
- const obs1 = makeObs({ id: "obs_1", sessionId: "ses_1", title: "Auth handler" });
81
- const obs2 = makeObs({ id: "obs_2", sessionId: "ses_1", title: "Database setup" });
82
-
83
- searchResults = [
84
- {
85
- observation: obs1,
86
- bm25Score: 0.8,
87
- vectorScore: 0,
88
- combinedScore: 0.8,
89
- sessionId: "ses_1",
90
- },
91
- {
92
- observation: obs2,
93
- bm25Score: 0.3,
94
- vectorScore: 0,
95
- combinedScore: 0.3,
96
- sessionId: "ses_1",
97
- },
98
- ];
99
-
100
- const session: Session = {
101
- id: "ses_1",
102
- project: "my-project",
103
- cwd: "/tmp",
104
- startedAt: "2026-02-01T00:00:00Z",
105
- status: "completed",
106
- observationCount: 2,
107
- };
108
- await kv.set("mem:sessions", "ses_1", session);
109
- await kv.set("mem:obs:ses_1", "obs_1", obs1);
110
- await kv.set("mem:obs:ses_1", "obs_2", obs2);
111
-
112
- const searchFn = async (_query: string, _limit: number) => searchResults;
113
- registerSmartSearchFunction(sdk as never, kv as never, searchFn);
114
- });
115
-
116
- it("compact mode returns CompactSearchResult array", async () => {
117
- const result = (await sdk.trigger("mem::smart-search", {
118
- query: "auth",
119
- })) as { mode: string; results: CompactSearchResult[] };
120
-
121
- expect(result.mode).toBe("compact");
122
- expect(result.results.length).toBe(2);
123
- expect(result.results[0]).toHaveProperty("obsId");
124
- expect(result.results[0]).toHaveProperty("title");
125
- expect(result.results[0]).toHaveProperty("type");
126
- expect(result.results[0]).toHaveProperty("score");
127
- expect(result.results[0]).toHaveProperty("timestamp");
128
- expect(result.results[0]).not.toHaveProperty("narrative");
129
- });
130
-
131
- it("expand mode returns full observations for given IDs", async () => {
132
- const result = (await sdk.trigger("mem::smart-search", {
133
- expandIds: ["obs_1"],
134
- })) as { mode: string; results: Array<{ obsId: string; observation: CompressedObservation }> };
135
-
136
- expect(result.mode).toBe("expanded");
137
- expect(result.results.length).toBe(1);
138
- expect(result.results[0].observation.title).toBe("Auth handler");
139
- });
140
-
141
- it("returns error when query is missing and no expandIds", async () => {
142
- const result = (await sdk.trigger("mem::smart-search", {})) as {
143
- mode: string;
144
- error: string;
145
- };
146
-
147
- expect(result.mode).toBe("compact");
148
- expect(result.error).toBe("query is required");
149
- expect((result as { results: unknown[] }).results).toEqual([]);
150
- });
151
-
152
- it("respects limit parameter in compact mode", async () => {
153
- const result = (await sdk.trigger("mem::smart-search", {
154
- query: "auth",
155
- limit: 1,
156
- })) as { mode: string; results: CompactSearchResult[] };
157
-
158
- expect(result.results.length).toBeLessThanOrEqual(2);
159
- });
160
-
161
- it("expand returns empty for nonexistent observation IDs", async () => {
162
- const result = (await sdk.trigger("mem::smart-search", {
163
- expandIds: ["obs_nonexistent_ses_xxx"],
164
- })) as { mode: string; results: unknown[] };
165
-
166
- expect(result.mode).toBe("expanded");
167
- expect(result.results.length).toBe(0);
168
- });
169
- });
@@ -1,165 +0,0 @@
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:child_process", () => ({
10
- execFile: vi.fn(
11
- (_cmd: string, _args: string[], _opts: unknown, cb: Function) => {
12
- cb(null, { stdout: "abc1234\n", stderr: "" });
13
- },
14
- ),
15
- }));
16
-
17
- vi.mock("node:util", async () => {
18
- const actual = (await vi.importActual("node:util")) as Record<
19
- string,
20
- unknown
21
- >;
22
- return {
23
- ...actual,
24
- promisify: () => async () => ({ stdout: "abc1234\n", stderr: "" }),
25
- };
26
- });
27
-
28
- vi.mock("node:fs", () => ({
29
- existsSync: vi.fn().mockReturnValue(true),
30
- mkdirSync: vi.fn(),
31
- writeFileSync: vi.fn(),
32
- readFileSync: vi
33
- .fn()
34
- .mockReturnValue('{"version":"0.4.0","sessions":[],"memories":[]}'),
35
- }));
36
-
37
- import { registerSnapshotFunction } from "../src/functions/snapshot.js";
38
- import type { Session, Memory, SnapshotMeta } from "../src/types.js";
39
-
40
- function mockKV() {
41
- const store = new Map<string, Map<string, unknown>>();
42
- return {
43
- get: async <T>(scope: string, key: string): Promise<T | null> => {
44
- return (store.get(scope)?.get(key) as T) ?? null;
45
- },
46
- set: async <T>(scope: string, key: string, data: T): Promise<T> => {
47
- if (!store.has(scope)) store.set(scope, new Map());
48
- store.get(scope)!.set(key, data);
49
- return data;
50
- },
51
- delete: async (scope: string, key: string): Promise<void> => {
52
- store.get(scope)?.delete(key);
53
- },
54
- list: async <T>(scope: string): Promise<T[]> => {
55
- const entries = store.get(scope);
56
- return entries ? (Array.from(entries.values()) as T[]) : [];
57
- },
58
- };
59
- }
60
-
61
- function mockSdk() {
62
- const functions = new Map<string, Function>();
63
- return {
64
- registerFunction: (opts: { id: string }, handler: Function) => {
65
- functions.set(opts.id, handler);
66
- },
67
- registerTrigger: () => {},
68
- trigger: async (id: string, data: unknown) => {
69
- const fn = functions.get(id);
70
- if (!fn) throw new Error(`No function: ${id}`);
71
- return fn(data);
72
- },
73
- };
74
- }
75
-
76
- describe("Snapshot Functions", () => {
77
- let sdk: ReturnType<typeof mockSdk>;
78
- let kv: ReturnType<typeof mockKV>;
79
- const snapshotDir = "/tmp/agentmemory-snapshots";
80
-
81
- beforeEach(async () => {
82
- sdk = mockSdk();
83
- kv = mockKV();
84
- vi.clearAllMocks();
85
- registerSnapshotFunction(sdk as never, kv as never, snapshotDir);
86
-
87
- const session: Session = {
88
- id: "ses_1",
89
- project: "test",
90
- cwd: "/tmp",
91
- startedAt: "2026-02-01T00:00:00Z",
92
- status: "completed",
93
- observationCount: 1,
94
- };
95
- await kv.set("mem:sessions", "ses_1", session);
96
-
97
- const mem: Memory = {
98
- id: "mem_1",
99
- createdAt: "2026-02-01T00:00:00Z",
100
- updatedAt: "2026-02-01T00:00:00Z",
101
- type: "pattern",
102
- title: "Test pattern",
103
- content: "Always test",
104
- concepts: [],
105
- files: [],
106
- sessionIds: ["ses_1"],
107
- strength: 5,
108
- version: 1,
109
- isLatest: true,
110
- };
111
- await kv.set("mem:memories", "mem_1", mem);
112
- });
113
-
114
- it("snapshot-create serializes state and returns meta", async () => {
115
- const result = (await sdk.trigger("mem::snapshot-create", {
116
- message: "Test snapshot",
117
- })) as { success: boolean; snapshot: SnapshotMeta };
118
-
119
- expect(result.success).toBe(true);
120
- expect(result.snapshot).toBeDefined();
121
- expect(result.snapshot.commitHash).toBe("abc1234");
122
- expect(result.snapshot.message).toBe("Test snapshot");
123
- expect(result.snapshot.stats.sessions).toBe(1);
124
- expect(result.snapshot.stats.memories).toBe(1);
125
- });
126
-
127
- it("snapshot-list returns snapshots from git log", async () => {
128
- const result = (await sdk.trigger("mem::snapshot-list", {})) as {
129
- snapshots: Array<{
130
- commitHash: string;
131
- createdAt: string;
132
- message: string;
133
- }>;
134
- };
135
-
136
- expect(result.snapshots).toBeDefined();
137
- expect(Array.isArray(result.snapshots)).toBe(true);
138
- });
139
-
140
- it("snapshot-restore requires commitHash", async () => {
141
- const result = (await sdk.trigger("mem::snapshot-restore", {})) as {
142
- success: boolean;
143
- error: string;
144
- };
145
-
146
- expect(result.success).toBe(false);
147
- expect(result.error).toContain("commitHash");
148
- });
149
-
150
- it("snapshot-restore loads state from commit", async () => {
151
- const result = (await sdk.trigger("mem::snapshot-restore", {
152
- commitHash: "abc1234",
153
- })) as { success: boolean; commitHash: string };
154
-
155
- expect(result.success).toBe(true);
156
- expect(result.commitHash).toBe("abc1234");
157
- });
158
-
159
- it("snapshot-create records an audit entry", async () => {
160
- await sdk.trigger("mem::snapshot-create", { message: "Audit test" });
161
-
162
- const audits = await kv.list("mem:audit");
163
- expect(audits.length).toBe(1);
164
- });
165
- });
package/test/team.test.ts DELETED
@@ -1,156 +0,0 @@
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 { registerTeamFunction } from "../src/functions/team.js";
10
- import type { Memory, TeamConfig, TeamSharedItem, TeamProfile } 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
- return {
36
- registerFunction: (opts: { id: string }, handler: Function) => {
37
- functions.set(opts.id, handler);
38
- },
39
- registerTrigger: () => {},
40
- trigger: async (id: string, data: unknown) => {
41
- const fn = functions.get(id);
42
- if (!fn) throw new Error(`No function: ${id}`);
43
- return fn(data);
44
- },
45
- };
46
- }
47
-
48
- const teamConfig: TeamConfig = {
49
- teamId: "test-team",
50
- userId: "user-1",
51
- mode: "shared" as const,
52
- };
53
-
54
- const testMemory: Memory = {
55
- id: "mem_1",
56
- createdAt: "2026-02-01T00:00:00Z",
57
- updatedAt: "2026-02-01T00:00:00Z",
58
- type: "pattern",
59
- title: "Auth pattern",
60
- content: "Always validate tokens",
61
- concepts: ["auth", "security"],
62
- files: ["src/auth.ts"],
63
- sessionIds: ["ses_1"],
64
- strength: 5,
65
- version: 1,
66
- isLatest: true,
67
- };
68
-
69
- describe("Team Functions", () => {
70
- let sdk: ReturnType<typeof mockSdk>;
71
- let kv: ReturnType<typeof mockKV>;
72
-
73
- beforeEach(async () => {
74
- sdk = mockSdk();
75
- kv = mockKV();
76
- registerTeamFunction(sdk as never, kv as never, teamConfig);
77
- await kv.set("mem:memories", "mem_1", testMemory);
78
- });
79
-
80
- it("team-share stores item in team namespace", async () => {
81
- const result = (await sdk.trigger("mem::team-share", {
82
- itemId: "mem_1",
83
- itemType: "memory",
84
- })) as { success: boolean; sharedItem: TeamSharedItem };
85
-
86
- expect(result.success).toBe(true);
87
- expect(result.sharedItem.sharedBy).toBe("user-1");
88
- expect(result.sharedItem.type).toBe("memory");
89
- expect(result.sharedItem.visibility).toBe("shared");
90
-
91
- const items = await kv.list<TeamSharedItem>("mem:team:test-team:shared");
92
- expect(items.length).toBe(1);
93
- });
94
-
95
- it("team-share fails for missing itemId", async () => {
96
- const result = (await sdk.trigger("mem::team-share", {
97
- itemType: "memory",
98
- })) as { success: boolean; error: string };
99
-
100
- expect(result.success).toBe(false);
101
- expect(result.error).toContain("required");
102
- });
103
-
104
- it("team-feed returns shared items sorted by date", async () => {
105
- await sdk.trigger("mem::team-share", {
106
- itemId: "mem_1",
107
- itemType: "memory",
108
- });
109
-
110
- const mem2: Memory = { ...testMemory, id: "mem_2", title: "Second pattern" };
111
- await kv.set("mem:memories", "mem_2", mem2);
112
-
113
- await new Promise((r) => setTimeout(r, 10));
114
- await sdk.trigger("mem::team-share", {
115
- itemId: "mem_2",
116
- itemType: "memory",
117
- });
118
-
119
- const result = (await sdk.trigger("mem::team-feed", {})) as {
120
- items: TeamSharedItem[];
121
- total: number;
122
- };
123
-
124
- expect(result.items.length).toBe(2);
125
- expect(result.total).toBe(2);
126
- expect(
127
- new Date(result.items[0].sharedAt).getTime(),
128
- ).toBeGreaterThanOrEqual(new Date(result.items[1].sharedAt).getTime());
129
- });
130
-
131
- it("team-profile aggregates concepts and files", async () => {
132
- await sdk.trigger("mem::team-share", {
133
- itemId: "mem_1",
134
- itemType: "pattern",
135
- });
136
-
137
- const result = (await sdk.trigger("mem::team-profile", {})) as TeamProfile;
138
-
139
- expect(result.teamId).toBe("test-team");
140
- expect(result.members).toContain("user-1");
141
- expect(result.totalSharedItems).toBe(1);
142
- expect(result.topConcepts.length).toBeGreaterThan(0);
143
- expect(result.topConcepts.some((c) => c.concept === "auth")).toBe(true);
144
- expect(result.topFiles.some((f) => f.file === "src/auth.ts")).toBe(true);
145
- });
146
-
147
- it("team-share fails when item not found in KV", async () => {
148
- const result = (await sdk.trigger("mem::team-share", {
149
- itemId: "nonexistent",
150
- itemType: "memory",
151
- })) as { success: boolean; error: string };
152
-
153
- expect(result.success).toBe(false);
154
- expect(result.error).toContain("not found");
155
- });
156
- });