@agentmemory/agentmemory 0.7.2 → 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 (217) hide show
  1. package/AGENTS.md +2 -2
  2. package/README.md +41 -68
  3. package/dist/cli.mjs +3 -3
  4. package/dist/index.mjs +3 -2
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/{src-1fTKFEtN.mjs → src-sYZDDbiA.mjs} +4 -3
  7. package/dist/src-sYZDDbiA.mjs.map +1 -0
  8. package/dist/standalone.mjs +1 -1
  9. package/dist/standalone.mjs.map +1 -1
  10. package/package.json +10 -1
  11. package/plugin/.claude-plugin/plugin.json +1 -1
  12. package/plugin/scripts/notification.d.mts +1 -0
  13. package/plugin/scripts/notification.mjs.map +1 -0
  14. package/plugin/scripts/post-tool-failure.d.mts +1 -0
  15. package/plugin/scripts/post-tool-failure.mjs.map +1 -0
  16. package/plugin/scripts/post-tool-use.d.mts +1 -0
  17. package/plugin/scripts/post-tool-use.mjs.map +1 -0
  18. package/plugin/scripts/pre-compact.d.mts +1 -0
  19. package/plugin/scripts/pre-compact.mjs.map +1 -0
  20. package/plugin/scripts/pre-tool-use.d.mts +1 -0
  21. package/plugin/scripts/pre-tool-use.mjs.map +1 -0
  22. package/plugin/scripts/prompt-submit.d.mts +1 -0
  23. package/plugin/scripts/prompt-submit.mjs.map +1 -0
  24. package/plugin/scripts/session-end.d.mts +1 -0
  25. package/plugin/scripts/session-end.mjs.map +1 -0
  26. package/plugin/scripts/session-start.d.mts +1 -0
  27. package/plugin/scripts/session-start.mjs.map +1 -0
  28. package/plugin/scripts/stop.d.mts +1 -0
  29. package/plugin/scripts/stop.mjs.map +1 -0
  30. package/plugin/scripts/subagent-start.d.mts +1 -0
  31. package/plugin/scripts/subagent-start.mjs.map +1 -0
  32. package/plugin/scripts/subagent-stop.d.mts +1 -0
  33. package/plugin/scripts/subagent-stop.mjs.map +1 -0
  34. package/plugin/scripts/task-completed.d.mts +1 -0
  35. package/plugin/scripts/task-completed.mjs.map +1 -0
  36. package/.claude-plugin/marketplace.json +0 -14
  37. package/.github/workflows/ci.yml +0 -22
  38. package/.github/workflows/publish.yml +0 -28
  39. package/assets/banner.png +0 -0
  40. package/assets/demo.gif +0 -0
  41. package/assets/demo.mp4 +0 -0
  42. package/benchmark/QUALITY.md +0 -73
  43. package/benchmark/REAL-EMBEDDINGS.md +0 -67
  44. package/benchmark/SCALE.md +0 -110
  45. package/benchmark/dataset.ts +0 -293
  46. package/benchmark/quality-eval.ts +0 -643
  47. package/benchmark/real-embeddings-eval.ts +0 -405
  48. package/benchmark/scale-eval.ts +0 -398
  49. package/dist/src-1fTKFEtN.mjs.map +0 -1
  50. package/src/auth.ts +0 -12
  51. package/src/cli.ts +0 -251
  52. package/src/config.ts +0 -221
  53. package/src/eval/metrics-store.ts +0 -65
  54. package/src/eval/quality.ts +0 -51
  55. package/src/eval/schemas.ts +0 -124
  56. package/src/eval/self-correct.ts +0 -28
  57. package/src/eval/validator.ts +0 -31
  58. package/src/functions/actions.ts +0 -288
  59. package/src/functions/audit.ts +0 -61
  60. package/src/functions/auto-forget.ts +0 -169
  61. package/src/functions/branch-aware.ts +0 -169
  62. package/src/functions/cascade.ts +0 -80
  63. package/src/functions/checkpoints.ts +0 -209
  64. package/src/functions/claude-bridge.ts +0 -161
  65. package/src/functions/compress.ts +0 -194
  66. package/src/functions/consolidate.ts +0 -212
  67. package/src/functions/consolidation-pipeline.ts +0 -258
  68. package/src/functions/context.ts +0 -169
  69. package/src/functions/crystallize.ts +0 -293
  70. package/src/functions/dedup.ts +0 -57
  71. package/src/functions/diagnostics.ts +0 -785
  72. package/src/functions/enrich.ts +0 -132
  73. package/src/functions/evict.ts +0 -163
  74. package/src/functions/export-import.ts +0 -508
  75. package/src/functions/facets.ts +0 -248
  76. package/src/functions/file-index.ts +0 -106
  77. package/src/functions/flow-compress.ts +0 -214
  78. package/src/functions/frontier.ts +0 -196
  79. package/src/functions/governance.ts +0 -131
  80. package/src/functions/graph-retrieval.ts +0 -277
  81. package/src/functions/graph.ts +0 -275
  82. package/src/functions/leases.ts +0 -216
  83. package/src/functions/lessons.ts +0 -253
  84. package/src/functions/mesh.ts +0 -434
  85. package/src/functions/migrate.ts +0 -165
  86. package/src/functions/observe.ts +0 -144
  87. package/src/functions/obsidian-export.ts +0 -310
  88. package/src/functions/patterns.ts +0 -138
  89. package/src/functions/privacy.ts +0 -39
  90. package/src/functions/profile.ts +0 -155
  91. package/src/functions/query-expansion.ts +0 -186
  92. package/src/functions/relations.ts +0 -237
  93. package/src/functions/remember.ts +0 -162
  94. package/src/functions/retention.ts +0 -235
  95. package/src/functions/routines.ts +0 -289
  96. package/src/functions/search.ts +0 -80
  97. package/src/functions/sentinels.ts +0 -417
  98. package/src/functions/signals.ts +0 -186
  99. package/src/functions/sketches.ts +0 -274
  100. package/src/functions/sliding-window.ts +0 -257
  101. package/src/functions/smart-search.ts +0 -115
  102. package/src/functions/snapshot.ts +0 -219
  103. package/src/functions/summarize.ts +0 -155
  104. package/src/functions/team.ts +0 -147
  105. package/src/functions/temporal-graph.ts +0 -476
  106. package/src/functions/timeline.ts +0 -138
  107. package/src/functions/verify.ts +0 -117
  108. package/src/health/monitor.ts +0 -110
  109. package/src/health/thresholds.ts +0 -73
  110. package/src/hooks/notification.ts +0 -52
  111. package/src/hooks/post-tool-failure.ts +0 -58
  112. package/src/hooks/post-tool-use.ts +0 -62
  113. package/src/hooks/pre-compact.ts +0 -60
  114. package/src/hooks/pre-tool-use.ts +0 -72
  115. package/src/hooks/prompt-submit.ts +0 -46
  116. package/src/hooks/session-end.ts +0 -71
  117. package/src/hooks/session-start.ts +0 -48
  118. package/src/hooks/stop.ts +0 -39
  119. package/src/hooks/subagent-start.ts +0 -49
  120. package/src/hooks/subagent-stop.ts +0 -54
  121. package/src/hooks/task-completed.ts +0 -54
  122. package/src/index.ts +0 -342
  123. package/src/mcp/in-memory-kv.ts +0 -61
  124. package/src/mcp/server.ts +0 -1455
  125. package/src/mcp/standalone.ts +0 -177
  126. package/src/mcp/tools-registry.ts +0 -769
  127. package/src/mcp/transport.ts +0 -91
  128. package/src/prompts/compression.ts +0 -67
  129. package/src/prompts/consolidation.ts +0 -48
  130. package/src/prompts/graph-extraction.ts +0 -35
  131. package/src/prompts/summary.ts +0 -38
  132. package/src/prompts/xml.ts +0 -26
  133. package/src/providers/agent-sdk.ts +0 -34
  134. package/src/providers/anthropic.ts +0 -35
  135. package/src/providers/circuit-breaker.ts +0 -82
  136. package/src/providers/embedding/cohere.ts +0 -46
  137. package/src/providers/embedding/gemini.ts +0 -54
  138. package/src/providers/embedding/index.ts +0 -39
  139. package/src/providers/embedding/local.ts +0 -52
  140. package/src/providers/embedding/openai.ts +0 -45
  141. package/src/providers/embedding/openrouter.ts +0 -51
  142. package/src/providers/embedding/voyage.ts +0 -46
  143. package/src/providers/fallback-chain.ts +0 -31
  144. package/src/providers/index.ts +0 -84
  145. package/src/providers/openrouter.ts +0 -71
  146. package/src/providers/resilient.ts +0 -37
  147. package/src/state/hybrid-search.ts +0 -295
  148. package/src/state/index-persistence.ts +0 -63
  149. package/src/state/keyed-mutex.ts +0 -18
  150. package/src/state/kv.ts +0 -33
  151. package/src/state/schema.ts +0 -71
  152. package/src/state/search-index.ts +0 -245
  153. package/src/state/stemmer.ts +0 -104
  154. package/src/state/synonyms.ts +0 -63
  155. package/src/state/vector-index.ts +0 -130
  156. package/src/telemetry/setup.ts +0 -116
  157. package/src/triggers/api.ts +0 -1904
  158. package/src/triggers/events.ts +0 -71
  159. package/src/types.ts +0 -769
  160. package/src/version.ts +0 -1
  161. package/src/viewer/index.html +0 -2556
  162. package/src/viewer/server.ts +0 -207
  163. package/src/xenova.d.ts +0 -3
  164. package/test/actions.test.ts +0 -490
  165. package/test/audit.test.ts +0 -108
  166. package/test/auto-forget.test.ts +0 -188
  167. package/test/cascade.test.ts +0 -277
  168. package/test/checkpoints.test.ts +0 -493
  169. package/test/circuit-breaker.test.ts +0 -107
  170. package/test/claude-bridge.test.ts +0 -178
  171. package/test/confidence.test.ts +0 -247
  172. package/test/consistency.test.ts +0 -61
  173. package/test/consolidation-pipeline.test.ts +0 -251
  174. package/test/crystallize.test.ts +0 -521
  175. package/test/diagnostics.test.ts +0 -638
  176. package/test/embedding-provider.test.ts +0 -49
  177. package/test/enrich.test.ts +0 -209
  178. package/test/eval.test.ts +0 -300
  179. package/test/export-import.test.ts +0 -251
  180. package/test/facets.test.ts +0 -448
  181. package/test/fallback-chain.test.ts +0 -93
  182. package/test/frontier.test.ts +0 -485
  183. package/test/governance.test.ts +0 -147
  184. package/test/graph-retrieval.test.ts +0 -186
  185. package/test/graph.test.ts +0 -160
  186. package/test/helpers/mocks.ts +0 -40
  187. package/test/hybrid-search.test.ts +0 -145
  188. package/test/index-persistence.test.ts +0 -124
  189. package/test/integration.test.ts +0 -265
  190. package/test/leases.test.ts +0 -399
  191. package/test/mcp-prompts.test.ts +0 -218
  192. package/test/mcp-resources.test.ts +0 -286
  193. package/test/mcp-standalone.test.ts +0 -113
  194. package/test/mesh.test.ts +0 -700
  195. package/test/privacy.test.ts +0 -87
  196. package/test/profile.test.ts +0 -161
  197. package/test/query-expansion.test.ts +0 -154
  198. package/test/relations.test.ts +0 -198
  199. package/test/retention.test.ts +0 -245
  200. package/test/routines.test.ts +0 -497
  201. package/test/schema-fingerprint.test.ts +0 -81
  202. package/test/schema.test.ts +0 -42
  203. package/test/search-index.test.ts +0 -128
  204. package/test/sentinels.test.ts +0 -626
  205. package/test/signals.test.ts +0 -410
  206. package/test/sketches.test.ts +0 -549
  207. package/test/sliding-window.test.ts +0 -199
  208. package/test/smart-search.test.ts +0 -169
  209. package/test/snapshot.test.ts +0 -165
  210. package/test/team.test.ts +0 -156
  211. package/test/temporal-graph.test.ts +0 -378
  212. package/test/timeline.test.ts +0 -148
  213. package/test/vector-index.test.ts +0 -79
  214. package/test/verify.test.ts +0 -209
  215. package/test/xml.test.ts +0 -65
  216. package/tsconfig.json +0 -22
  217. package/tsdown.config.ts +0 -62
@@ -1,209 +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 { registerEnrichFunction } from "../src/functions/enrich.js";
10
- import type { 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 makeMemory(overrides: Partial<Memory> = {}): Memory {
34
- return {
35
- id: "mem_1",
36
- createdAt: new Date().toISOString(),
37
- updatedAt: new Date().toISOString(),
38
- type: "bug",
39
- title: "Known bug",
40
- content: "Null pointer in handler",
41
- concepts: ["bug"],
42
- files: ["src/handler.ts"],
43
- sessionIds: ["ses_1"],
44
- strength: 5,
45
- version: 1,
46
- isLatest: true,
47
- ...overrides,
48
- };
49
- }
50
-
51
- function mockSdk() {
52
- const functions = new Map<string, Function>();
53
- const triggerOverrides = new Map<string, Function>();
54
- return {
55
- registerFunction: (opts: { id: string }, handler: Function) => {
56
- functions.set(opts.id, handler);
57
- },
58
- registerTrigger: () => {},
59
- trigger: async (id: string, data: unknown) => {
60
- if (triggerOverrides.has(id)) {
61
- return triggerOverrides.get(id)!(data);
62
- }
63
- const fn = functions.get(id);
64
- if (!fn) throw new Error(`No function: ${id}`);
65
- return fn(data);
66
- },
67
- overrideTrigger: (id: string, handler: Function) => {
68
- triggerOverrides.set(id, handler);
69
- },
70
- getFunction: (id: string) => functions.get(id),
71
- };
72
- }
73
-
74
- describe("Enrich Function", () => {
75
- let sdk: ReturnType<typeof mockSdk>;
76
- let kv: ReturnType<typeof mockKV>;
77
-
78
- beforeEach(() => {
79
- sdk = mockSdk();
80
- kv = mockKV();
81
- registerEnrichFunction(sdk as never, kv as never);
82
- });
83
-
84
- it("returns file context and relevant memories", async () => {
85
- sdk.overrideTrigger(
86
- "mem::file-context",
87
- async () => ({ context: "File was edited in session ses_1" }),
88
- );
89
- sdk.overrideTrigger("mem::search", async () => ({
90
- results: [
91
- { observation: { narrative: "User fixed a bug in handler" } },
92
- ],
93
- }));
94
-
95
- const bugMem = makeMemory({
96
- id: "bug_1",
97
- files: ["src/handler.ts"],
98
- type: "bug",
99
- });
100
- await kv.set("mem:memories", "bug_1", bugMem);
101
-
102
- const result = (await sdk.trigger("mem::enrich", {
103
- sessionId: "ses_1",
104
- files: ["src/handler.ts"],
105
- })) as { context: string; truncated: boolean };
106
-
107
- expect(result.context).toContain("File was edited in session ses_1");
108
- expect(result.context).toContain("agentmemory-relevant-context");
109
- expect(result.context).toContain("agentmemory-past-errors");
110
- expect(result.truncated).toBe(false);
111
- });
112
-
113
- it("extracts terms from Grep/Glob pattern for search", async () => {
114
- let capturedQuery = "";
115
- sdk.overrideTrigger("mem::file-context", async () => ({ context: "" }));
116
- sdk.overrideTrigger("mem::search", async (data: any) => {
117
- capturedQuery = data.query;
118
- return { results: [] };
119
- });
120
-
121
- await sdk.trigger("mem::enrich", {
122
- sessionId: "ses_1",
123
- files: ["src/utils.ts"],
124
- terms: ["handleError"],
125
- toolName: "Grep",
126
- });
127
-
128
- expect(capturedQuery).toContain("handleError");
129
- });
130
-
131
- it("truncates context at 4000 chars", async () => {
132
- const longContext = "x".repeat(5000);
133
- sdk.overrideTrigger(
134
- "mem::file-context",
135
- async () => ({ context: longContext }),
136
- );
137
- sdk.overrideTrigger("mem::search", async () => ({ results: [] }));
138
-
139
- const result = (await sdk.trigger("mem::enrich", {
140
- sessionId: "ses_1",
141
- files: ["src/big.ts"],
142
- })) as { context: string; truncated: boolean };
143
-
144
- expect(result.context.length).toBe(4000);
145
- expect(result.truncated).toBe(true);
146
- });
147
-
148
- it("returns empty context when no data found", async () => {
149
- sdk.overrideTrigger("mem::file-context", async () => ({ context: "" }));
150
- sdk.overrideTrigger("mem::search", async () => ({ results: [] }));
151
-
152
- const result = (await sdk.trigger("mem::enrich", {
153
- sessionId: "ses_1",
154
- files: ["src/new-file.ts"],
155
- })) as { context: string; truncated: boolean };
156
-
157
- expect(result.context).toBe("");
158
- expect(result.truncated).toBe(false);
159
- });
160
-
161
- it("handles failed triggers without crashing", async () => {
162
- sdk.overrideTrigger("mem::file-context", async () => {
163
- throw new Error("file-context failed");
164
- });
165
- sdk.overrideTrigger("mem::search", async () => {
166
- throw new Error("search failed");
167
- });
168
-
169
- const result = (await sdk.trigger("mem::enrich", {
170
- sessionId: "ses_1",
171
- files: ["src/handler.ts"],
172
- })) as { context: string; truncated: boolean };
173
-
174
- expect(result.context).toBeDefined();
175
- expect(result.truncated).toBe(false);
176
- });
177
-
178
- it("includes bug memories that overlap with requested files", async () => {
179
- sdk.overrideTrigger("mem::file-context", async () => ({ context: "" }));
180
- sdk.overrideTrigger("mem::search", async () => ({ results: [] }));
181
-
182
- const bugMem = makeMemory({
183
- id: "bug_match",
184
- type: "bug",
185
- title: "Race condition",
186
- content: "Race condition in worker pool",
187
- files: ["src/worker.ts"],
188
- isLatest: true,
189
- });
190
- const nonBugMem = makeMemory({
191
- id: "pattern_1",
192
- type: "pattern",
193
- title: "Code pattern",
194
- content: "Singleton pattern used",
195
- files: ["src/worker.ts"],
196
- isLatest: true,
197
- });
198
- await kv.set("mem:memories", "bug_match", bugMem);
199
- await kv.set("mem:memories", "pattern_1", nonBugMem);
200
-
201
- const result = (await sdk.trigger("mem::enrich", {
202
- sessionId: "ses_1",
203
- files: ["src/worker.ts"],
204
- })) as { context: string; truncated: boolean };
205
-
206
- expect(result.context).toContain("Race condition");
207
- expect(result.context).not.toContain("Singleton pattern");
208
- });
209
- });
package/test/eval.test.ts DELETED
@@ -1,300 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import {
3
- ObserveInputSchema,
4
- CompressOutputSchema,
5
- SummaryOutputSchema,
6
- SearchInputSchema,
7
- ContextInputSchema,
8
- RememberInputSchema,
9
- } from "../src/eval/schemas.js";
10
- import { validateInput, validateOutput } from "../src/eval/validator.js";
11
- import {
12
- scoreCompression,
13
- scoreSummary,
14
- scoreContextRelevance,
15
- } from "../src/eval/quality.js";
16
-
17
- describe("Zod Schemas", () => {
18
- describe("ObserveInputSchema", () => {
19
- it("accepts valid input", () => {
20
- const result = ObserveInputSchema.safeParse({
21
- hookType: "post_tool_use",
22
- sessionId: "ses_abc",
23
- project: "my-project",
24
- cwd: "/home/user",
25
- timestamp: "2026-01-01T00:00:00Z",
26
- data: { tool_name: "Read" },
27
- });
28
- expect(result.success).toBe(true);
29
- });
30
-
31
- it("rejects missing sessionId", () => {
32
- const result = ObserveInputSchema.safeParse({
33
- hookType: "post_tool_use",
34
- project: "my-project",
35
- cwd: "/home/user",
36
- timestamp: "2026-01-01T00:00:00Z",
37
- data: {},
38
- });
39
- expect(result.success).toBe(false);
40
- });
41
-
42
- it("rejects invalid hookType", () => {
43
- const result = ObserveInputSchema.safeParse({
44
- hookType: "invalid_hook",
45
- sessionId: "ses_abc",
46
- project: "my-project",
47
- cwd: "/home/user",
48
- timestamp: "2026-01-01T00:00:00Z",
49
- data: {},
50
- });
51
- expect(result.success).toBe(false);
52
- });
53
- });
54
-
55
- describe("CompressOutputSchema", () => {
56
- it("accepts valid output", () => {
57
- const result = CompressOutputSchema.safeParse({
58
- type: "file_edit",
59
- title: "Edit auth module",
60
- facts: ["Added JWT validation"],
61
- narrative: "Modified the auth middleware to validate tokens",
62
- concepts: ["auth"],
63
- files: ["src/auth.ts"],
64
- importance: 7,
65
- });
66
- expect(result.success).toBe(true);
67
- });
68
-
69
- it("rejects empty facts array", () => {
70
- const result = CompressOutputSchema.safeParse({
71
- type: "file_edit",
72
- title: "Edit auth module",
73
- facts: [],
74
- narrative: "Modified the auth middleware to validate tokens",
75
- concepts: [],
76
- files: [],
77
- importance: 5,
78
- });
79
- expect(result.success).toBe(false);
80
- });
81
-
82
- it("rejects title over 120 chars", () => {
83
- const result = CompressOutputSchema.safeParse({
84
- type: "file_edit",
85
- title: "x".repeat(121),
86
- facts: ["fact"],
87
- narrative: "A narrative that is long enough",
88
- concepts: [],
89
- files: [],
90
- importance: 5,
91
- });
92
- expect(result.success).toBe(false);
93
- });
94
-
95
- it("rejects importance outside 1-10", () => {
96
- const result = CompressOutputSchema.safeParse({
97
- type: "file_edit",
98
- title: "Test",
99
- facts: ["fact"],
100
- narrative: "A valid narrative here",
101
- concepts: [],
102
- files: [],
103
- importance: 11,
104
- });
105
- expect(result.success).toBe(false);
106
- });
107
-
108
- it("rejects narrative under 10 chars", () => {
109
- const result = CompressOutputSchema.safeParse({
110
- type: "file_edit",
111
- title: "Test",
112
- facts: ["fact"],
113
- narrative: "short",
114
- concepts: [],
115
- files: [],
116
- importance: 5,
117
- });
118
- expect(result.success).toBe(false);
119
- });
120
- });
121
-
122
- describe("SummaryOutputSchema", () => {
123
- it("accepts valid summary", () => {
124
- const result = SummaryOutputSchema.safeParse({
125
- title: "Session Summary",
126
- narrative: "This session focused on implementing authentication features and fixing bugs",
127
- keyDecisions: ["Use JWT"],
128
- filesModified: ["auth.ts"],
129
- concepts: ["auth"],
130
- });
131
- expect(result.success).toBe(true);
132
- });
133
-
134
- it("rejects short narrative", () => {
135
- const result = SummaryOutputSchema.safeParse({
136
- title: "Summary",
137
- narrative: "Too short",
138
- keyDecisions: [],
139
- filesModified: [],
140
- concepts: [],
141
- });
142
- expect(result.success).toBe(false);
143
- });
144
- });
145
-
146
- describe("SearchInputSchema", () => {
147
- it("accepts valid search", () => {
148
- expect(SearchInputSchema.safeParse({ query: "auth" }).success).toBe(true);
149
- });
150
-
151
- it("accepts search with limit", () => {
152
- expect(
153
- SearchInputSchema.safeParse({ query: "auth", limit: 10 }).success,
154
- ).toBe(true);
155
- });
156
-
157
- it("rejects empty query", () => {
158
- expect(SearchInputSchema.safeParse({ query: "" }).success).toBe(false);
159
- });
160
- });
161
-
162
- describe("ContextInputSchema", () => {
163
- it("accepts valid input", () => {
164
- expect(
165
- ContextInputSchema.safeParse({
166
- sessionId: "ses_1",
167
- project: "proj",
168
- }).success,
169
- ).toBe(true);
170
- });
171
- });
172
-
173
- describe("RememberInputSchema", () => {
174
- it("accepts valid input", () => {
175
- expect(
176
- RememberInputSchema.safeParse({
177
- content: "Always use TypeScript",
178
- type: "preference",
179
- }).success,
180
- ).toBe(true);
181
- });
182
-
183
- it("rejects empty content", () => {
184
- expect(
185
- RememberInputSchema.safeParse({ content: "" }).success,
186
- ).toBe(false);
187
- });
188
- });
189
- });
190
-
191
- describe("Validator", () => {
192
- it("returns valid with correct data", () => {
193
- const result = validateInput(SearchInputSchema, { query: "test" }, "search");
194
- expect(result.valid).toBe(true);
195
- if (result.valid) {
196
- expect(result.data.query).toBe("test");
197
- }
198
- });
199
-
200
- it("returns invalid with error details", () => {
201
- const result = validateInput(SearchInputSchema, { query: "" }, "search");
202
- expect(result.valid).toBe(false);
203
- if (!result.valid) {
204
- expect(result.result.functionId).toBe("search");
205
- expect(result.result.errors.length).toBeGreaterThan(0);
206
- }
207
- });
208
-
209
- it("validateOutput works same as validateInput", () => {
210
- const result = validateOutput(
211
- CompressOutputSchema,
212
- {
213
- type: "file_edit",
214
- title: "Test",
215
- facts: ["a"],
216
- narrative: "A long enough narrative",
217
- concepts: [],
218
- files: [],
219
- importance: 5,
220
- },
221
- "compress",
222
- );
223
- expect(result.valid).toBe(true);
224
- });
225
- });
226
-
227
- describe("Quality Scoring", () => {
228
- describe("scoreCompression", () => {
229
- it("returns 0 for empty object", () => {
230
- expect(scoreCompression({})).toBe(0);
231
- });
232
-
233
- it("returns 100 for perfect observation", () => {
234
- const score = scoreCompression({
235
- type: "file_edit",
236
- title: "A good title",
237
- facts: ["fact 1", "fact 2", "fact 3"],
238
- narrative: "A narrative that is definitely more than fifty characters long and provides good context",
239
- concepts: ["auth", "jwt"],
240
- importance: 7,
241
- });
242
- expect(score).toBe(100);
243
- });
244
-
245
- it("scores partial observations between 0 and 100", () => {
246
- const score = scoreCompression({
247
- title: "Test",
248
- facts: ["one"],
249
- narrative: "Short but valid narrative",
250
- });
251
- expect(score).toBeGreaterThan(0);
252
- expect(score).toBeLessThan(100);
253
- });
254
- });
255
-
256
- describe("scoreSummary", () => {
257
- it("returns 0 for empty object", () => {
258
- expect(scoreSummary({})).toBe(0);
259
- });
260
-
261
- it("returns high score for complete summary", () => {
262
- const score = scoreSummary({
263
- title: "Session Summary Title",
264
- narrative:
265
- "This is a detailed narrative about what happened during the session with enough content to be meaningful and complete for review purposes",
266
- keyDecisions: ["Used JWT for auth", "Chose PostgreSQL"],
267
- filesModified: ["src/auth.ts", "src/db.ts"],
268
- concepts: ["authentication", "database"],
269
- });
270
- expect(score).toBeGreaterThanOrEqual(90);
271
- });
272
- });
273
-
274
- describe("scoreContextRelevance", () => {
275
- it("returns 0 for empty context", () => {
276
- expect(scoreContextRelevance("", "proj")).toBe(0);
277
- });
278
-
279
- it("scores higher when project is mentioned", () => {
280
- const withProject = scoreContextRelevance(
281
- "<context>This is for my-project with details</context>",
282
- "my-project",
283
- );
284
- const without = scoreContextRelevance(
285
- "<context>Some generic context details</context>",
286
- "my-project",
287
- );
288
- expect(withProject).toBeGreaterThan(without);
289
- });
290
-
291
- it("scores higher with more XML sections", () => {
292
- const multi = scoreContextRelevance(
293
- "<summary>A</summary><observations>B</observations><memories>C</memories><patterns>D</patterns>",
294
- "test",
295
- );
296
- const single = scoreContextRelevance("<summary>A</summary>", "test");
297
- expect(multi).toBeGreaterThan(single);
298
- });
299
- });
300
- });