@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,207 +0,0 @@
1
- import {
2
- createServer,
3
- type Server,
4
- type IncomingMessage,
5
- type ServerResponse,
6
- } from "node:http";
7
- import { readFileSync } from "node:fs";
8
- import { join, dirname } from "node:path";
9
- import { fileURLToPath } from "node:url";
10
- import { timingSafeCompare, VIEWER_CSP } from "../auth.js";
11
-
12
- const ALLOWED_ORIGINS = (
13
- process.env.VIEWER_ALLOWED_ORIGINS ||
14
- "http://localhost:3111,http://localhost:3113,http://127.0.0.1:3111,http://127.0.0.1:3113"
15
- )
16
- .split(",")
17
- .map((o) => o.trim());
18
-
19
- function corsHeaders(req: IncomingMessage): Record<string, string> {
20
- const origin = req.headers.origin || "";
21
- const allowed = ALLOWED_ORIGINS.includes(origin)
22
- ? origin
23
- : ALLOWED_ORIGINS[0];
24
- return {
25
- "Access-Control-Allow-Origin": allowed,
26
- "Access-Control-Allow-Methods": "GET, POST, DELETE, OPTIONS",
27
- "Access-Control-Allow-Headers": "Content-Type, Authorization",
28
- Vary: "Origin",
29
- };
30
- }
31
-
32
- function json(
33
- res: ServerResponse,
34
- status: number,
35
- data: unknown,
36
- req?: IncomingMessage,
37
- ): void {
38
- const body = JSON.stringify(data);
39
- const cors = req
40
- ? corsHeaders(req)
41
- : { "Access-Control-Allow-Origin": ALLOWED_ORIGINS[0], Vary: "Origin" };
42
- res.writeHead(status, { ...cors, "Content-Type": "application/json" });
43
- res.end(body);
44
- }
45
-
46
- function readBody(req: IncomingMessage): Promise<string> {
47
- return new Promise((resolve, reject) => {
48
- let data = "";
49
- let size = 0;
50
- req.on("data", (chunk: Buffer) => {
51
- size += chunk.length;
52
- if (size > 1_000_000) {
53
- req.destroy();
54
- reject(new Error("too large"));
55
- return;
56
- }
57
- data += chunk.toString();
58
- });
59
- req.on("end", () => resolve(data));
60
- req.on("error", reject);
61
- });
62
- }
63
-
64
- function checkAuth(req: IncomingMessage, secret: string | undefined): boolean {
65
- if (!secret) return true;
66
- const auth = req.headers["authorization"] || "";
67
- return (
68
- typeof auth === "string" && timingSafeCompare(auth, `Bearer ${secret}`)
69
- );
70
- }
71
-
72
- export function startViewerServer(
73
- port: number,
74
- _kv: unknown,
75
- _sdk: unknown,
76
- secret?: string,
77
- restPort?: number,
78
- ): Server {
79
- const resolvedRestPort = restPort ?? port - 2;
80
-
81
- const server = createServer(async (req, res) => {
82
- const raw = req.url || "/";
83
- const qIdx = raw.indexOf("?");
84
- const pathname = qIdx >= 0 ? raw.slice(0, qIdx) : raw;
85
- const qs = qIdx >= 0 ? raw.slice(qIdx + 1) : "";
86
- const method = req.method || "GET";
87
-
88
- if (method === "OPTIONS") {
89
- res.writeHead(204, {
90
- ...corsHeaders(req),
91
- "Access-Control-Max-Age": "86400",
92
- });
93
- res.end();
94
- return;
95
- }
96
-
97
- if (
98
- method === "GET" &&
99
- (pathname === "/" ||
100
- pathname === "/viewer" ||
101
- pathname === "/agentmemory/viewer")
102
- ) {
103
- const base = dirname(fileURLToPath(import.meta.url));
104
- const candidates = [
105
- join(base, "..", "src", "viewer", "index.html"),
106
- join(base, "..", "viewer", "index.html"),
107
- join(base, "viewer", "index.html"),
108
- ];
109
- for (const p of candidates) {
110
- try {
111
- const html = readFileSync(p, "utf-8");
112
- res.writeHead(200, {
113
- "Content-Type": "text/html; charset=utf-8",
114
- "Content-Security-Policy": VIEWER_CSP,
115
- "Cache-Control": "no-cache",
116
- });
117
- res.end(html);
118
- return;
119
- } catch {}
120
- }
121
- res.writeHead(404, { "Content-Type": "text/plain" });
122
- res.end("viewer not found");
123
- return;
124
- }
125
-
126
- if (!checkAuth(req, secret)) {
127
- json(res, 401, { error: "unauthorized" }, req);
128
- return;
129
- }
130
-
131
- try {
132
- await proxyToRestApi(resolvedRestPort, pathname, qs, method, req, res, secret);
133
- } catch (err) {
134
- console.error(`[viewer] proxy error on ${method} ${pathname}:`, err);
135
- json(res, 502, { error: "upstream error" }, req);
136
- }
137
- });
138
-
139
- server.listen(port, "127.0.0.1", () => {
140
- console.log(`[agentmemory] Viewer: http://localhost:${port}`);
141
- });
142
-
143
- return server;
144
- }
145
-
146
- async function proxyToRestApi(
147
- restPort: number,
148
- pathname: string,
149
- qs: string,
150
- method: string,
151
- req: IncomingMessage,
152
- res: ServerResponse,
153
- secret?: string,
154
- ): Promise<void> {
155
- const upstreamPath = pathname.startsWith("/agentmemory/")
156
- ? pathname
157
- : `/agentmemory${pathname.startsWith("/") ? pathname : "/" + pathname}`;
158
-
159
- const upstreamUrl = `http://127.0.0.1:${restPort}${upstreamPath}${qs ? "?" + qs : ""}`;
160
-
161
- const headers: Record<string, string> = {};
162
- if (secret) {
163
- headers["Authorization"] = `Bearer ${secret}`;
164
- }
165
- const ct = req.headers["content-type"];
166
- if (ct) {
167
- headers["Content-Type"] = ct;
168
- }
169
-
170
- let body: string | undefined;
171
- if (method === "POST" || method === "PUT" || method === "DELETE" || method === "PATCH") {
172
- body = await readBody(req);
173
- }
174
-
175
- const controller = new AbortController();
176
- const fetchTimeout = setTimeout(() => controller.abort(), 10000);
177
- let upstream: Response;
178
- try {
179
- upstream = await fetch(upstreamUrl, {
180
- method,
181
- headers,
182
- body: body || undefined,
183
- signal: controller.signal,
184
- });
185
- clearTimeout(fetchTimeout);
186
- } catch (err) {
187
- clearTimeout(fetchTimeout);
188
- if (err instanceof Error && err.name === "AbortError") {
189
- json(res, 504, { error: "upstream timeout" }, req);
190
- return;
191
- }
192
- throw err;
193
- }
194
-
195
- const cors = corsHeaders(req);
196
- const responseBody = await upstream.text();
197
- const responseHeaders: Record<string, string> = {
198
- ...cors,
199
- };
200
- const upstreamCt = upstream.headers.get("content-type");
201
- if (upstreamCt) {
202
- responseHeaders["Content-Type"] = upstreamCt;
203
- }
204
-
205
- res.writeHead(upstream.status, responseHeaders);
206
- res.end(responseBody);
207
- }
package/src/xenova.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare module "@xenova/transformers" {
2
- export function pipeline(task: string, model: string): Promise<any>;
3
- }
@@ -1,490 +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 { registerActionsFunction } from "../src/functions/actions.js";
10
- import type { Action, ActionEdge } 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
- describe("Actions Functions", () => {
49
- let sdk: ReturnType<typeof mockSdk>;
50
- let kv: ReturnType<typeof mockKV>;
51
-
52
- beforeEach(() => {
53
- sdk = mockSdk();
54
- kv = mockKV();
55
- registerActionsFunction(sdk as never, kv as never);
56
- });
57
-
58
- describe("mem::action-create", () => {
59
- it("creates an action with valid data", async () => {
60
- const result = (await sdk.trigger("mem::action-create", {
61
- title: "Fix login bug",
62
- description: "Users cannot log in with SSO",
63
- priority: 7,
64
- createdBy: "agent-1",
65
- project: "webapp",
66
- tags: ["bug", "auth"],
67
- })) as { success: boolean; action: Action; edges: ActionEdge[] };
68
-
69
- expect(result.success).toBe(true);
70
- expect(result.action.id).toMatch(/^act_/);
71
- expect(result.action.title).toBe("Fix login bug");
72
- expect(result.action.description).toBe("Users cannot log in with SSO");
73
- expect(result.action.status).toBe("pending");
74
- expect(result.action.priority).toBe(7);
75
- expect(result.action.createdBy).toBe("agent-1");
76
- expect(result.action.project).toBe("webapp");
77
- expect(result.action.tags).toEqual(["bug", "auth"]);
78
- expect(result.action.createdAt).toBeDefined();
79
- expect(result.action.updatedAt).toBeDefined();
80
- expect(result.edges).toEqual([]);
81
- });
82
-
83
- it("returns error when title is missing", async () => {
84
- const result = (await sdk.trigger("mem::action-create", {
85
- description: "No title provided",
86
- })) as { success: boolean; error: string };
87
-
88
- expect(result.success).toBe(false);
89
- expect(result.error).toContain("title is required");
90
- });
91
-
92
- it("clamps priority 0 to default 5 (falsy fallback)", async () => {
93
- const result = (await sdk.trigger("mem::action-create", {
94
- title: "Zero priority task",
95
- priority: 0,
96
- })) as { success: boolean; action: Action };
97
-
98
- expect(result.success).toBe(true);
99
- expect(result.action.priority).toBe(5);
100
- });
101
-
102
- it("clamps negative priority to 1", async () => {
103
- const result = (await sdk.trigger("mem::action-create", {
104
- title: "Negative priority task",
105
- priority: -3,
106
- })) as { success: boolean; action: Action };
107
-
108
- expect(result.success).toBe(true);
109
- expect(result.action.priority).toBe(1);
110
- });
111
-
112
- it("clamps priority 15 to 10", async () => {
113
- const result = (await sdk.trigger("mem::action-create", {
114
- title: "High priority task",
115
- priority: 15,
116
- })) as { success: boolean; action: Action };
117
-
118
- expect(result.success).toBe(true);
119
- expect(result.action.priority).toBe(10);
120
- });
121
-
122
- it("validates parent action exists", async () => {
123
- const result = (await sdk.trigger("mem::action-create", {
124
- title: "Child task",
125
- parentId: "nonexistent_parent",
126
- })) as { success: boolean; error: string };
127
-
128
- expect(result.success).toBe(false);
129
- expect(result.error).toContain("parent action not found");
130
- });
131
-
132
- it("creates action with valid parent", async () => {
133
- const parentResult = (await sdk.trigger("mem::action-create", {
134
- title: "Parent task",
135
- })) as { success: boolean; action: Action };
136
-
137
- const childResult = (await sdk.trigger("mem::action-create", {
138
- title: "Child task",
139
- parentId: parentResult.action.id,
140
- })) as { success: boolean; action: Action };
141
-
142
- expect(childResult.success).toBe(true);
143
- expect(childResult.action.parentId).toBe(parentResult.action.id);
144
- });
145
-
146
- it("creates inline edges with valid types", async () => {
147
- const targetResult = (await sdk.trigger("mem::action-create", {
148
- title: "Target action",
149
- })) as { success: boolean; action: Action };
150
-
151
- const result = (await sdk.trigger("mem::action-create", {
152
- title: "Source action",
153
- edges: [
154
- { type: "requires", targetActionId: targetResult.action.id },
155
- { type: "unlocks", targetActionId: targetResult.action.id },
156
- ],
157
- })) as { success: boolean; action: Action; edges: ActionEdge[] };
158
-
159
- expect(result.success).toBe(true);
160
- expect(result.edges.length).toBe(2);
161
- expect(result.edges[0].id).toMatch(/^ae_/);
162
- expect(result.edges[0].type).toBe("requires");
163
- expect(result.edges[0].sourceActionId).toBe(result.action.id);
164
- expect(result.edges[0].targetActionId).toBe(targetResult.action.id);
165
- expect(result.edges[1].type).toBe("unlocks");
166
- });
167
-
168
- it("returns error for inline edge with invalid type", async () => {
169
- const targetResult = (await sdk.trigger("mem::action-create", {
170
- title: "Target action",
171
- })) as { success: boolean; action: Action };
172
-
173
- const result = (await sdk.trigger("mem::action-create", {
174
- title: "Source action",
175
- edges: [
176
- { type: "invalid_type", targetActionId: targetResult.action.id },
177
- ],
178
- })) as { success: boolean; error: string };
179
-
180
- expect(result.success).toBe(false);
181
- expect(result.error).toContain("invalid edge type");
182
- });
183
-
184
- it("returns error for inline edge with nonexistent target", async () => {
185
- const result = (await sdk.trigger("mem::action-create", {
186
- title: "Source action",
187
- edges: [{ type: "requires", targetActionId: "nonexistent_id" }],
188
- })) as { success: boolean; error: string };
189
-
190
- expect(result.success).toBe(false);
191
- expect(result.error).toContain("target action not found");
192
- });
193
- });
194
-
195
- describe("mem::action-update", () => {
196
- it("updates an action with valid data", async () => {
197
- const createResult = (await sdk.trigger("mem::action-create", {
198
- title: "Original title",
199
- priority: 5,
200
- })) as { success: boolean; action: Action };
201
-
202
- const updateResult = (await sdk.trigger("mem::action-update", {
203
- actionId: createResult.action.id,
204
- title: "Updated title",
205
- priority: 8,
206
- status: "active",
207
- assignedTo: "agent-2",
208
- tags: ["updated"],
209
- })) as { success: boolean; action: Action };
210
-
211
- expect(updateResult.success).toBe(true);
212
- expect(updateResult.action.title).toBe("Updated title");
213
- expect(updateResult.action.priority).toBe(8);
214
- expect(updateResult.action.status).toBe("active");
215
- expect(updateResult.action.assignedTo).toBe("agent-2");
216
- expect(updateResult.action.tags).toEqual(["updated"]);
217
- });
218
-
219
- it("returns error when actionId is missing", async () => {
220
- const result = (await sdk.trigger("mem::action-update", {
221
- title: "no id",
222
- })) as { success: boolean; error: string };
223
-
224
- expect(result.success).toBe(false);
225
- expect(result.error).toContain("actionId is required");
226
- });
227
-
228
- it("returns error for nonexistent action", async () => {
229
- const result = (await sdk.trigger("mem::action-update", {
230
- actionId: "nonexistent_id",
231
- status: "done",
232
- })) as { success: boolean; error: string };
233
-
234
- expect(result.success).toBe(false);
235
- expect(result.error).toContain("action not found");
236
- });
237
-
238
- it("propagates completion when status set to done", async () => {
239
- const actionB = (await sdk.trigger("mem::action-create", {
240
- title: "Dependency B",
241
- })) as { success: boolean; action: Action };
242
-
243
- const actionA = (await sdk.trigger("mem::action-create", {
244
- title: "Action A depends on B",
245
- edges: [{ type: "requires", targetActionId: actionB.action.id }],
246
- })) as { success: boolean; action: Action };
247
-
248
- await sdk.trigger("mem::action-update", {
249
- actionId: actionA.action.id,
250
- status: "blocked",
251
- });
252
-
253
- await sdk.trigger("mem::action-update", {
254
- actionId: actionB.action.id,
255
- status: "done",
256
- });
257
-
258
- const getResult = (await sdk.trigger("mem::action-get", {
259
- actionId: actionA.action.id,
260
- })) as { success: boolean; action: Action };
261
-
262
- expect(getResult.action.status).toBe("pending");
263
- });
264
- });
265
-
266
- describe("mem::action-edge-create", () => {
267
- it("creates an edge between two actions", async () => {
268
- const source = (await sdk.trigger("mem::action-create", {
269
- title: "Source",
270
- })) as { success: boolean; action: Action };
271
-
272
- const target = (await sdk.trigger("mem::action-create", {
273
- title: "Target",
274
- })) as { success: boolean; action: Action };
275
-
276
- const result = (await sdk.trigger("mem::action-edge-create", {
277
- sourceActionId: source.action.id,
278
- targetActionId: target.action.id,
279
- type: "requires",
280
- })) as { success: boolean; edge: ActionEdge };
281
-
282
- expect(result.success).toBe(true);
283
- expect(result.edge.id).toMatch(/^ae_/);
284
- expect(result.edge.type).toBe("requires");
285
- expect(result.edge.sourceActionId).toBe(source.action.id);
286
- expect(result.edge.targetActionId).toBe(target.action.id);
287
- expect(result.edge.createdAt).toBeDefined();
288
- });
289
-
290
- it("returns error when required fields are missing", async () => {
291
- const result = (await sdk.trigger("mem::action-edge-create", {
292
- sourceActionId: "some_id",
293
- })) as { success: boolean; error: string };
294
-
295
- expect(result.success).toBe(false);
296
- expect(result.error).toContain("required");
297
- });
298
-
299
- it("returns error for invalid edge type", async () => {
300
- const source = (await sdk.trigger("mem::action-create", {
301
- title: "Source",
302
- })) as { success: boolean; action: Action };
303
-
304
- const target = (await sdk.trigger("mem::action-create", {
305
- title: "Target",
306
- })) as { success: boolean; action: Action };
307
-
308
- const result = (await sdk.trigger("mem::action-edge-create", {
309
- sourceActionId: source.action.id,
310
- targetActionId: target.action.id,
311
- type: "invalid_type",
312
- })) as { success: boolean; error: string };
313
-
314
- expect(result.success).toBe(false);
315
- expect(result.error).toContain("type must be one of");
316
- });
317
-
318
- it("returns error for nonexistent source action", async () => {
319
- const target = (await sdk.trigger("mem::action-create", {
320
- title: "Target",
321
- })) as { success: boolean; action: Action };
322
-
323
- const result = (await sdk.trigger("mem::action-edge-create", {
324
- sourceActionId: "nonexistent",
325
- targetActionId: target.action.id,
326
- type: "requires",
327
- })) as { success: boolean; error: string };
328
-
329
- expect(result.success).toBe(false);
330
- expect(result.error).toContain("source action not found");
331
- });
332
-
333
- it("returns error for nonexistent target action", async () => {
334
- const source = (await sdk.trigger("mem::action-create", {
335
- title: "Source",
336
- })) as { success: boolean; action: Action };
337
-
338
- const result = (await sdk.trigger("mem::action-edge-create", {
339
- sourceActionId: source.action.id,
340
- targetActionId: "nonexistent",
341
- type: "requires",
342
- })) as { success: boolean; error: string };
343
-
344
- expect(result.success).toBe(false);
345
- expect(result.error).toContain("target action not found");
346
- });
347
- });
348
-
349
- describe("mem::action-list", () => {
350
- beforeEach(async () => {
351
- await sdk.trigger("mem::action-create", {
352
- title: "Task A",
353
- status: "pending",
354
- project: "alpha",
355
- tags: ["frontend"],
356
- });
357
- await new Promise((r) => setTimeout(r, 5));
358
- await sdk.trigger("mem::action-create", {
359
- title: "Task B",
360
- project: "alpha",
361
- tags: ["backend"],
362
- });
363
- await new Promise((r) => setTimeout(r, 5));
364
- await sdk.trigger("mem::action-create", {
365
- title: "Task C",
366
- project: "beta",
367
- tags: ["frontend", "backend"],
368
- });
369
- });
370
-
371
- it("returns all actions", async () => {
372
- const result = (await sdk.trigger("mem::action-list", {})) as {
373
- success: boolean;
374
- actions: Action[];
375
- };
376
-
377
- expect(result.success).toBe(true);
378
- expect(result.actions.length).toBe(3);
379
- });
380
-
381
- it("filters by status", async () => {
382
- const all = (await sdk.trigger("mem::action-list", {})) as {
383
- actions: Action[];
384
- };
385
- const firstAction = all.actions[0];
386
-
387
- await sdk.trigger("mem::action-update", {
388
- actionId: firstAction.id,
389
- status: "done",
390
- });
391
-
392
- const result = (await sdk.trigger("mem::action-list", {
393
- status: "done",
394
- })) as { success: boolean; actions: Action[] };
395
-
396
- expect(result.success).toBe(true);
397
- expect(result.actions.length).toBe(1);
398
- expect(result.actions[0].status).toBe("done");
399
- });
400
-
401
- it("filters by project", async () => {
402
- const result = (await sdk.trigger("mem::action-list", {
403
- project: "alpha",
404
- })) as { success: boolean; actions: Action[] };
405
-
406
- expect(result.success).toBe(true);
407
- expect(result.actions.length).toBe(2);
408
- expect(result.actions.every((a) => a.project === "alpha")).toBe(true);
409
- });
410
-
411
- it("filters by tags", async () => {
412
- const result = (await sdk.trigger("mem::action-list", {
413
- tags: ["backend"],
414
- })) as { success: boolean; actions: Action[] };
415
-
416
- expect(result.success).toBe(true);
417
- expect(result.actions.length).toBe(2);
418
- expect(
419
- result.actions.every((a) => a.tags.includes("backend")),
420
- ).toBe(true);
421
- });
422
-
423
- it("respects limit", async () => {
424
- const result = (await sdk.trigger("mem::action-list", {
425
- limit: 2,
426
- })) as { success: boolean; actions: Action[] };
427
-
428
- expect(result.success).toBe(true);
429
- expect(result.actions.length).toBe(2);
430
- });
431
- });
432
-
433
- describe("mem::action-get", () => {
434
- it("returns action with edges and children", async () => {
435
- const parent = (await sdk.trigger("mem::action-create", {
436
- title: "Parent",
437
- })) as { success: boolean; action: Action };
438
-
439
- const child = (await sdk.trigger("mem::action-create", {
440
- title: "Child",
441
- parentId: parent.action.id,
442
- })) as { success: boolean; action: Action };
443
-
444
- const other = (await sdk.trigger("mem::action-create", {
445
- title: "Other",
446
- })) as { success: boolean; action: Action };
447
-
448
- await sdk.trigger("mem::action-edge-create", {
449
- sourceActionId: parent.action.id,
450
- targetActionId: other.action.id,
451
- type: "unlocks",
452
- });
453
-
454
- const result = (await sdk.trigger("mem::action-get", {
455
- actionId: parent.action.id,
456
- })) as {
457
- success: boolean;
458
- action: Action;
459
- edges: ActionEdge[];
460
- children: Action[];
461
- };
462
-
463
- expect(result.success).toBe(true);
464
- expect(result.action.id).toBe(parent.action.id);
465
- expect(result.edges.length).toBe(1);
466
- expect(result.edges[0].type).toBe("unlocks");
467
- expect(result.children.length).toBe(1);
468
- expect(result.children[0].id).toBe(child.action.id);
469
- });
470
-
471
- it("returns error for missing actionId", async () => {
472
- const result = (await sdk.trigger("mem::action-get", {})) as {
473
- success: boolean;
474
- error: string;
475
- };
476
-
477
- expect(result.success).toBe(false);
478
- expect(result.error).toContain("actionId is required");
479
- });
480
-
481
- it("returns error for nonexistent action", async () => {
482
- const result = (await sdk.trigger("mem::action-get", {
483
- actionId: "nonexistent",
484
- })) as { success: boolean; error: string };
485
-
486
- expect(result.success).toBe(false);
487
- expect(result.error).toContain("action not found");
488
- });
489
- });
490
- });