@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,93 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { FallbackChainProvider } from "../src/providers/fallback-chain.js";
3
- import type { MemoryProvider } from "../src/types.js";
4
-
5
- function makeProvider(
6
- name: string,
7
- impl?: Partial<MemoryProvider>,
8
- ): MemoryProvider {
9
- return {
10
- name,
11
- compress: impl?.compress ?? (async () => `compressed by ${name}`),
12
- summarize: impl?.summarize ?? (async () => `summarized by ${name}`),
13
- };
14
- }
15
-
16
- describe("FallbackChainProvider", () => {
17
- it("returns result from first provider when it succeeds", async () => {
18
- const chain = new FallbackChainProvider([
19
- makeProvider("primary"),
20
- makeProvider("secondary"),
21
- ]);
22
- const result = await chain.compress("sys", "user");
23
- expect(result).toBe("compressed by primary");
24
- });
25
-
26
- it("falls back to second provider when first fails", async () => {
27
- const failing: MemoryProvider = {
28
- name: "failing",
29
- compress: async () => {
30
- throw new Error("primary down");
31
- },
32
- summarize: async () => {
33
- throw new Error("primary down");
34
- },
35
- };
36
- const chain = new FallbackChainProvider([
37
- failing,
38
- makeProvider("backup"),
39
- ]);
40
- const result = await chain.compress("sys", "user");
41
- expect(result).toBe("compressed by backup");
42
- });
43
-
44
- it("throws the last error when all providers fail", async () => {
45
- const failing1: MemoryProvider = {
46
- name: "fail1",
47
- compress: async () => {
48
- throw new Error("fail1 error");
49
- },
50
- summarize: async () => {
51
- throw new Error("fail1 error");
52
- },
53
- };
54
- const failing2: MemoryProvider = {
55
- name: "fail2",
56
- compress: async () => {
57
- throw new Error("fail2 error");
58
- },
59
- summarize: async () => {
60
- throw new Error("fail2 error");
61
- },
62
- };
63
- const chain = new FallbackChainProvider([failing1, failing2]);
64
- await expect(chain.compress("sys", "user")).rejects.toThrow("fail2 error");
65
- });
66
-
67
- it("formats the name correctly", () => {
68
- const chain = new FallbackChainProvider([
69
- makeProvider("anthropic"),
70
- makeProvider("gemini"),
71
- makeProvider("openrouter"),
72
- ]);
73
- expect(chain.name).toBe("fallback(anthropic -> gemini -> openrouter)");
74
- });
75
-
76
- it("summarize also uses fallback chain", async () => {
77
- const failing: MemoryProvider = {
78
- name: "failing",
79
- compress: async () => {
80
- throw new Error("down");
81
- },
82
- summarize: async () => {
83
- throw new Error("down");
84
- },
85
- };
86
- const chain = new FallbackChainProvider([
87
- failing,
88
- makeProvider("backup"),
89
- ]);
90
- const result = await chain.summarize("sys", "user");
91
- expect(result).toBe("summarized by backup");
92
- });
93
- });
@@ -1,485 +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 { registerFrontierFunction } from "../src/functions/frontier.js";
10
- import { registerActionsFunction } from "../src/functions/actions.js";
11
- import type { Action, ActionEdge, Checkpoint, Lease } from "../src/types.js";
12
- import type { FrontierItem } from "../src/functions/frontier.js";
13
-
14
- function mockKV() {
15
- const store = new Map<string, Map<string, unknown>>();
16
- return {
17
- get: async <T>(scope: string, key: string): Promise<T | null> => {
18
- return (store.get(scope)?.get(key) as T) ?? null;
19
- },
20
- set: async <T>(scope: string, key: string, data: T): Promise<T> => {
21
- if (!store.has(scope)) store.set(scope, new Map());
22
- store.get(scope)!.set(key, data);
23
- return data;
24
- },
25
- delete: async (scope: string, key: string): Promise<void> => {
26
- store.get(scope)?.delete(key);
27
- },
28
- list: async <T>(scope: string): Promise<T[]> => {
29
- const entries = store.get(scope);
30
- return entries ? (Array.from(entries.values()) as T[]) : [];
31
- },
32
- };
33
- }
34
-
35
- function mockSdk() {
36
- const functions = new Map<string, Function>();
37
- return {
38
- registerFunction: (opts: { id: string }, handler: Function) => {
39
- functions.set(opts.id, handler);
40
- },
41
- registerTrigger: () => {},
42
- trigger: async (id: string, data: unknown) => {
43
- const fn = functions.get(id);
44
- if (!fn) throw new Error(`No function: ${id}`);
45
- return fn(data);
46
- },
47
- };
48
- }
49
-
50
- function makeAction(overrides: Partial<Action>): Action {
51
- const now = new Date().toISOString();
52
- return {
53
- id: overrides.id || `act_${Math.random().toString(36).slice(2, 10)}`,
54
- title: overrides.title || "Test action",
55
- description: overrides.description || "",
56
- status: overrides.status || "pending",
57
- priority: overrides.priority || 5,
58
- createdAt: overrides.createdAt || now,
59
- updatedAt: overrides.updatedAt || now,
60
- createdBy: overrides.createdBy || "agent-1",
61
- assignedTo: overrides.assignedTo,
62
- project: overrides.project,
63
- tags: overrides.tags || [],
64
- sourceObservationIds: overrides.sourceObservationIds || [],
65
- sourceMemoryIds: overrides.sourceMemoryIds || [],
66
- result: overrides.result,
67
- parentId: overrides.parentId,
68
- metadata: overrides.metadata,
69
- };
70
- }
71
-
72
- describe("Frontier Functions", () => {
73
- let sdk: ReturnType<typeof mockSdk>;
74
- let kv: ReturnType<typeof mockKV>;
75
-
76
- beforeEach(() => {
77
- sdk = mockSdk();
78
- kv = mockKV();
79
- registerActionsFunction(sdk as never, kv as never);
80
- registerFrontierFunction(sdk as never, kv as never);
81
- });
82
-
83
- describe("mem::frontier", () => {
84
- it("returns empty frontier when no actions exist", async () => {
85
- const result = (await sdk.trigger("mem::frontier", {})) as {
86
- success: boolean;
87
- frontier: FrontierItem[];
88
- totalActions: number;
89
- totalUnblocked: number;
90
- };
91
-
92
- expect(result.success).toBe(true);
93
- expect(result.frontier).toEqual([]);
94
- expect(result.totalActions).toBe(0);
95
- expect(result.totalUnblocked).toBe(0);
96
- });
97
-
98
- it("returns pending actions sorted by score", async () => {
99
- const lowPriority = makeAction({
100
- id: "act_low",
101
- title: "Low priority",
102
- priority: 2,
103
- });
104
- const highPriority = makeAction({
105
- id: "act_high",
106
- title: "High priority",
107
- priority: 9,
108
- });
109
-
110
- await kv.set("mem:actions", lowPriority.id, lowPriority);
111
- await kv.set("mem:actions", highPriority.id, highPriority);
112
-
113
- const result = (await sdk.trigger("mem::frontier", {})) as {
114
- success: boolean;
115
- frontier: FrontierItem[];
116
- };
117
-
118
- expect(result.success).toBe(true);
119
- expect(result.frontier.length).toBe(2);
120
- expect(result.frontier[0].action.id).toBe("act_high");
121
- expect(result.frontier[1].action.id).toBe("act_low");
122
- expect(result.frontier[0].score).toBeGreaterThan(
123
- result.frontier[1].score,
124
- );
125
- });
126
-
127
- it("excludes done and cancelled actions", async () => {
128
- const pending = makeAction({
129
- id: "act_pending",
130
- title: "Pending",
131
- status: "pending",
132
- });
133
- const done = makeAction({
134
- id: "act_done",
135
- title: "Done",
136
- status: "done",
137
- });
138
- const cancelled = makeAction({
139
- id: "act_cancelled",
140
- title: "Cancelled",
141
- status: "cancelled",
142
- });
143
-
144
- await kv.set("mem:actions", pending.id, pending);
145
- await kv.set("mem:actions", done.id, done);
146
- await kv.set("mem:actions", cancelled.id, cancelled);
147
-
148
- const result = (await sdk.trigger("mem::frontier", {})) as {
149
- success: boolean;
150
- frontier: FrontierItem[];
151
- totalActions: number;
152
- };
153
-
154
- expect(result.success).toBe(true);
155
- expect(result.frontier.length).toBe(1);
156
- expect(result.frontier[0].action.id).toBe("act_pending");
157
- expect(result.totalActions).toBe(3);
158
- });
159
-
160
- it("excludes blocked actions with unsatisfied requires edge", async () => {
161
- const dependency = makeAction({
162
- id: "act_dep",
163
- title: "Dependency",
164
- status: "pending",
165
- });
166
- const blocked = makeAction({
167
- id: "act_blocked",
168
- title: "Blocked",
169
- status: "blocked",
170
- });
171
-
172
- await kv.set("mem:actions", dependency.id, dependency);
173
- await kv.set("mem:actions", blocked.id, blocked);
174
-
175
- const edge: ActionEdge = {
176
- id: "ae_1",
177
- type: "requires",
178
- sourceActionId: blocked.id,
179
- targetActionId: dependency.id,
180
- createdAt: new Date().toISOString(),
181
- };
182
- await kv.set("mem:action-edges", edge.id, edge);
183
-
184
- const result = (await sdk.trigger("mem::frontier", {})) as {
185
- success: boolean;
186
- frontier: FrontierItem[];
187
- };
188
-
189
- expect(result.success).toBe(true);
190
- const ids = result.frontier.map((f) => f.action.id);
191
- expect(ids).toContain("act_dep");
192
- expect(ids).not.toContain("act_blocked");
193
- });
194
-
195
- it("respects project filter", async () => {
196
- const alphaAction = makeAction({
197
- id: "act_alpha",
198
- title: "Alpha task",
199
- project: "alpha",
200
- });
201
- const betaAction = makeAction({
202
- id: "act_beta",
203
- title: "Beta task",
204
- project: "beta",
205
- });
206
-
207
- await kv.set("mem:actions", alphaAction.id, alphaAction);
208
- await kv.set("mem:actions", betaAction.id, betaAction);
209
-
210
- const result = (await sdk.trigger("mem::frontier", {
211
- project: "alpha",
212
- })) as { success: boolean; frontier: FrontierItem[] };
213
-
214
- expect(result.success).toBe(true);
215
- expect(result.frontier.length).toBe(1);
216
- expect(result.frontier[0].action.project).toBe("alpha");
217
- });
218
-
219
- it("higher priority scores higher", async () => {
220
- const low = makeAction({
221
- id: "act_low",
222
- title: "Low",
223
- priority: 1,
224
- createdAt: new Date().toISOString(),
225
- });
226
- const high = makeAction({
227
- id: "act_high",
228
- title: "High",
229
- priority: 10,
230
- createdAt: new Date().toISOString(),
231
- });
232
-
233
- await kv.set("mem:actions", low.id, low);
234
- await kv.set("mem:actions", high.id, high);
235
-
236
- const result = (await sdk.trigger("mem::frontier", {})) as {
237
- success: boolean;
238
- frontier: FrontierItem[];
239
- };
240
-
241
- expect(result.frontier[0].action.id).toBe("act_high");
242
- expect(result.frontier[0].score).toBeGreaterThan(
243
- result.frontier[1].score,
244
- );
245
- });
246
-
247
- it("excludes actions gated by pending checkpoint", async () => {
248
- const gatedAction = makeAction({
249
- id: "act_gated",
250
- title: "Gated action",
251
- status: "pending",
252
- });
253
-
254
- const checkpoint: Checkpoint = {
255
- id: "ckpt_1",
256
- name: "CI check",
257
- description: "Waiting for CI",
258
- status: "pending",
259
- type: "ci",
260
- createdAt: new Date().toISOString(),
261
- linkedActionIds: ["act_gated"],
262
- };
263
-
264
- await kv.set("mem:actions", gatedAction.id, gatedAction);
265
- await kv.set("mem:checkpoints", checkpoint.id, checkpoint);
266
-
267
- const gateEdge: ActionEdge = {
268
- id: "ae_gate",
269
- type: "gated_by",
270
- sourceActionId: gatedAction.id,
271
- targetActionId: checkpoint.id,
272
- createdAt: new Date().toISOString(),
273
- };
274
- await kv.set("mem:action-edges", gateEdge.id, gateEdge);
275
-
276
- const result = (await sdk.trigger("mem::frontier", {})) as {
277
- success: boolean;
278
- frontier: FrontierItem[];
279
- };
280
-
281
- expect(result.frontier.length).toBe(0);
282
- });
283
-
284
- it("excludes actions conflicting with active actions", async () => {
285
- const activeAction = makeAction({
286
- id: "act_active",
287
- title: "Active task",
288
- status: "active",
289
- });
290
- const conflictAction = makeAction({
291
- id: "act_conflict",
292
- title: "Conflicting task",
293
- status: "pending",
294
- });
295
-
296
- await kv.set("mem:actions", activeAction.id, activeAction);
297
- await kv.set("mem:actions", conflictAction.id, conflictAction);
298
-
299
- const conflictEdge: ActionEdge = {
300
- id: "ae_conflict",
301
- type: "conflicts_with",
302
- sourceActionId: conflictAction.id,
303
- targetActionId: activeAction.id,
304
- createdAt: new Date().toISOString(),
305
- };
306
- await kv.set("mem:action-edges", conflictEdge.id, conflictEdge);
307
-
308
- const result = (await sdk.trigger("mem::frontier", {})) as {
309
- success: boolean;
310
- frontier: FrontierItem[];
311
- };
312
-
313
- const ids = result.frontier.map((f) => f.action.id);
314
- expect(ids).toContain("act_active");
315
- expect(ids).not.toContain("act_conflict");
316
- });
317
-
318
- it("active actions get score bonus", async () => {
319
- const pendingAction = makeAction({
320
- id: "act_pending",
321
- title: "Pending",
322
- status: "pending",
323
- priority: 5,
324
- createdAt: new Date().toISOString(),
325
- });
326
- const activeAction = makeAction({
327
- id: "act_active",
328
- title: "Active",
329
- status: "active",
330
- priority: 5,
331
- createdAt: new Date().toISOString(),
332
- });
333
-
334
- await kv.set("mem:actions", pendingAction.id, pendingAction);
335
- await kv.set("mem:actions", activeAction.id, activeAction);
336
-
337
- const result = (await sdk.trigger("mem::frontier", {})) as {
338
- success: boolean;
339
- frontier: FrontierItem[];
340
- };
341
-
342
- const activeItem = result.frontier.find(
343
- (f) => f.action.id === "act_active",
344
- )!;
345
- const pendingItem = result.frontier.find(
346
- (f) => f.action.id === "act_pending",
347
- )!;
348
-
349
- expect(activeItem.score).toBeGreaterThan(pendingItem.score);
350
- });
351
- });
352
-
353
- describe("mem::next", () => {
354
- it("returns top suggestion when actions exist", async () => {
355
- const action = makeAction({
356
- id: "act_1",
357
- title: "Top task",
358
- priority: 8,
359
- tags: ["urgent"],
360
- });
361
- await kv.set("mem:actions", action.id, action);
362
-
363
- const result = (await sdk.trigger("mem::next", {})) as {
364
- success: boolean;
365
- suggestion: {
366
- actionId: string;
367
- title: string;
368
- description: string;
369
- priority: number;
370
- score: number;
371
- tags: string[];
372
- } | null;
373
- message: string;
374
- totalActions: number;
375
- };
376
-
377
- expect(result.success).toBe(true);
378
- expect(result.suggestion).not.toBeNull();
379
- expect(result.suggestion!.actionId).toBe("act_1");
380
- expect(result.suggestion!.title).toBe("Top task");
381
- expect(result.suggestion!.priority).toBe(8);
382
- expect(result.suggestion!.tags).toEqual(["urgent"]);
383
- expect(result.message).toContain("Top task");
384
- expect(result.totalActions).toBe(1);
385
- });
386
-
387
- it("returns null suggestion when no actions exist", async () => {
388
- const result = (await sdk.trigger("mem::next", {})) as {
389
- success: boolean;
390
- suggestion: null;
391
- message: string;
392
- totalActions: number;
393
- };
394
-
395
- expect(result.success).toBe(true);
396
- expect(result.suggestion).toBeNull();
397
- expect(result.message).toContain("No actionable work");
398
- expect(result.totalActions).toBe(0);
399
- });
400
-
401
- it("returns null when all actions are done", async () => {
402
- const doneAction = makeAction({
403
- id: "act_done",
404
- title: "Completed",
405
- status: "done",
406
- });
407
- await kv.set("mem:actions", doneAction.id, doneAction);
408
-
409
- const result = (await sdk.trigger("mem::next", {})) as {
410
- success: boolean;
411
- suggestion: null;
412
- message: string;
413
- totalActions: number;
414
- };
415
-
416
- expect(result.success).toBe(true);
417
- expect(result.suggestion).toBeNull();
418
- expect(result.totalActions).toBe(1);
419
- });
420
-
421
- it("propagates failure when frontier fails", async () => {
422
- const originalFunctions = new Map<string, Function>();
423
-
424
- const failSdk = {
425
- registerFunction: (opts: { id: string }, handler: Function) => {
426
- originalFunctions.set(opts.id, handler);
427
- },
428
- registerTrigger: () => {},
429
- trigger: async (id: string, data: unknown) => {
430
- if (id === "mem::frontier") {
431
- return { success: false, error: "internal failure" };
432
- }
433
- const fn = originalFunctions.get(id);
434
- if (!fn) throw new Error(`No function: ${id}`);
435
- return fn(data);
436
- },
437
- };
438
-
439
- const failKv = mockKV();
440
- registerFrontierFunction(failSdk as never, failKv as never);
441
-
442
- const nextFn = originalFunctions.get("mem::next")!;
443
- const result = (await nextFn({})) as {
444
- success: boolean;
445
- suggestion: null;
446
- message: string;
447
- totalActions: number;
448
- };
449
-
450
- expect(result.success).toBe(false);
451
- expect(result.suggestion).toBeNull();
452
- expect(result.message).toContain("Failed to compute frontier");
453
- expect(result.totalActions).toBe(0);
454
- });
455
-
456
- it("respects project filter", async () => {
457
- const alphaAction = makeAction({
458
- id: "act_alpha",
459
- title: "Alpha task",
460
- project: "alpha",
461
- priority: 5,
462
- });
463
- const betaAction = makeAction({
464
- id: "act_beta",
465
- title: "Beta task",
466
- project: "beta",
467
- priority: 10,
468
- });
469
-
470
- await kv.set("mem:actions", alphaAction.id, alphaAction);
471
- await kv.set("mem:actions", betaAction.id, betaAction);
472
-
473
- const result = (await sdk.trigger("mem::next", {
474
- project: "alpha",
475
- })) as {
476
- success: boolean;
477
- suggestion: { actionId: string; title: string } | null;
478
- };
479
-
480
- expect(result.success).toBe(true);
481
- expect(result.suggestion).not.toBeNull();
482
- expect(result.suggestion!.actionId).toBe("act_alpha");
483
- });
484
- });
485
- });