@agentmemory/agentmemory 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/.claude-plugin/marketplace.json +14 -0
  2. package/.github/workflows/ci.yml +22 -0
  3. package/.github/workflows/publish.yml +28 -0
  4. package/AGENTS.md +113 -0
  5. package/LICENSE +190 -0
  6. package/README.md +828 -0
  7. package/assets/banner.png +0 -0
  8. package/assets/demo.gif +0 -0
  9. package/assets/demo.mp4 +0 -0
  10. package/benchmark/QUALITY.md +73 -0
  11. package/benchmark/REAL-EMBEDDINGS.md +67 -0
  12. package/benchmark/SCALE.md +110 -0
  13. package/benchmark/dataset.ts +293 -0
  14. package/benchmark/quality-eval.ts +643 -0
  15. package/benchmark/real-embeddings-eval.ts +405 -0
  16. package/benchmark/scale-eval.ts +398 -0
  17. package/dist/cli.d.mts +1 -0
  18. package/dist/cli.mjs +137 -0
  19. package/dist/cli.mjs.map +1 -0
  20. package/dist/docker-compose.yml +14 -0
  21. package/dist/hooks/notification.d.mts +1 -0
  22. package/dist/hooks/notification.mjs +45 -0
  23. package/dist/hooks/notification.mjs.map +1 -0
  24. package/dist/hooks/post-tool-failure.d.mts +1 -0
  25. package/dist/hooks/post-tool-failure.mjs +45 -0
  26. package/dist/hooks/post-tool-failure.mjs.map +1 -0
  27. package/dist/hooks/post-tool-use.d.mts +1 -0
  28. package/dist/hooks/post-tool-use.mjs +53 -0
  29. package/dist/hooks/post-tool-use.mjs.map +1 -0
  30. package/dist/hooks/pre-compact.d.mts +1 -0
  31. package/dist/hooks/pre-compact.mjs +50 -0
  32. package/dist/hooks/pre-compact.mjs.map +1 -0
  33. package/dist/hooks/pre-tool-use.d.mts +1 -0
  34. package/dist/hooks/pre-tool-use.mjs +69 -0
  35. package/dist/hooks/pre-tool-use.mjs.map +1 -0
  36. package/dist/hooks/prompt-submit.d.mts +1 -0
  37. package/dist/hooks/prompt-submit.mjs +40 -0
  38. package/dist/hooks/prompt-submit.mjs.map +1 -0
  39. package/dist/hooks/session-end.d.mts +1 -0
  40. package/dist/hooks/session-end.mjs +61 -0
  41. package/dist/hooks/session-end.mjs.map +1 -0
  42. package/dist/hooks/session-start.d.mts +1 -0
  43. package/dist/hooks/session-start.mjs +42 -0
  44. package/dist/hooks/session-start.mjs.map +1 -0
  45. package/dist/hooks/stop.d.mts +1 -0
  46. package/dist/hooks/stop.mjs +33 -0
  47. package/dist/hooks/stop.mjs.map +1 -0
  48. package/dist/hooks/subagent-start.d.mts +1 -0
  49. package/dist/hooks/subagent-start.mjs +43 -0
  50. package/dist/hooks/subagent-start.mjs.map +1 -0
  51. package/dist/hooks/subagent-stop.d.mts +1 -0
  52. package/dist/hooks/subagent-stop.mjs +45 -0
  53. package/dist/hooks/subagent-stop.mjs.map +1 -0
  54. package/dist/hooks/task-completed.d.mts +1 -0
  55. package/dist/hooks/task-completed.mjs +46 -0
  56. package/dist/hooks/task-completed.mjs.map +1 -0
  57. package/dist/iii-config.yaml +51 -0
  58. package/dist/index.d.mts +2 -0
  59. package/dist/index.mjs +13776 -0
  60. package/dist/index.mjs.map +1 -0
  61. package/dist/src-QxitMPfJ.mjs +13775 -0
  62. package/dist/src-QxitMPfJ.mjs.map +1 -0
  63. package/dist/standalone.d.mts +1 -0
  64. package/dist/standalone.mjs +1155 -0
  65. package/dist/standalone.mjs.map +1 -0
  66. package/dist/transformers-BX_tgxdO.mjs +38684 -0
  67. package/dist/transformers-BX_tgxdO.mjs.map +1 -0
  68. package/dist/transformers-KMm1i9no.mjs +38683 -0
  69. package/dist/transformers-KMm1i9no.mjs.map +1 -0
  70. package/docker-compose.yml +14 -0
  71. package/iii-config.yaml +51 -0
  72. package/package.json +59 -0
  73. package/plugin/.claude-plugin/plugin.json +10 -0
  74. package/plugin/hooks/hooks.json +77 -0
  75. package/plugin/scripts/diagnostics.mjs +551 -0
  76. package/plugin/scripts/notification.mjs +45 -0
  77. package/plugin/scripts/post-tool-failure.mjs +45 -0
  78. package/plugin/scripts/post-tool-use.mjs +53 -0
  79. package/plugin/scripts/pre-compact.mjs +50 -0
  80. package/plugin/scripts/pre-tool-use.mjs +69 -0
  81. package/plugin/scripts/prompt-submit.mjs +40 -0
  82. package/plugin/scripts/session-end.mjs +61 -0
  83. package/plugin/scripts/session-start.mjs +42 -0
  84. package/plugin/scripts/stop.mjs +33 -0
  85. package/plugin/scripts/subagent-start.mjs +43 -0
  86. package/plugin/scripts/subagent-stop.mjs +45 -0
  87. package/plugin/scripts/task-completed.mjs +46 -0
  88. package/plugin/skills/forget/SKILL.md +32 -0
  89. package/plugin/skills/recall/SKILL.md +18 -0
  90. package/plugin/skills/remember/SKILL.md +25 -0
  91. package/plugin/skills/session-history/SKILL.md +17 -0
  92. package/src/auth.ts +12 -0
  93. package/src/cli.ts +159 -0
  94. package/src/config.ts +221 -0
  95. package/src/eval/metrics-store.ts +65 -0
  96. package/src/eval/quality.ts +51 -0
  97. package/src/eval/schemas.ts +124 -0
  98. package/src/eval/self-correct.ts +28 -0
  99. package/src/eval/validator.ts +31 -0
  100. package/src/functions/actions.ts +288 -0
  101. package/src/functions/audit.ts +61 -0
  102. package/src/functions/auto-forget.ts +169 -0
  103. package/src/functions/branch-aware.ts +169 -0
  104. package/src/functions/cascade.ts +80 -0
  105. package/src/functions/checkpoints.ts +209 -0
  106. package/src/functions/claude-bridge.ts +161 -0
  107. package/src/functions/compress.ts +194 -0
  108. package/src/functions/consolidate.ts +212 -0
  109. package/src/functions/consolidation-pipeline.ts +258 -0
  110. package/src/functions/context.ts +169 -0
  111. package/src/functions/crystallize.ts +293 -0
  112. package/src/functions/dedup.ts +57 -0
  113. package/src/functions/diagnostics.ts +785 -0
  114. package/src/functions/enrich.ts +132 -0
  115. package/src/functions/evict.ts +163 -0
  116. package/src/functions/export-import.ts +508 -0
  117. package/src/functions/facets.ts +248 -0
  118. package/src/functions/file-index.ts +106 -0
  119. package/src/functions/flow-compress.ts +214 -0
  120. package/src/functions/frontier.ts +196 -0
  121. package/src/functions/governance.ts +131 -0
  122. package/src/functions/graph-retrieval.ts +277 -0
  123. package/src/functions/graph.ts +275 -0
  124. package/src/functions/leases.ts +216 -0
  125. package/src/functions/lessons.ts +253 -0
  126. package/src/functions/mesh.ts +434 -0
  127. package/src/functions/migrate.ts +165 -0
  128. package/src/functions/observe.ts +144 -0
  129. package/src/functions/obsidian-export.ts +310 -0
  130. package/src/functions/patterns.ts +138 -0
  131. package/src/functions/privacy.ts +39 -0
  132. package/src/functions/profile.ts +155 -0
  133. package/src/functions/query-expansion.ts +186 -0
  134. package/src/functions/relations.ts +237 -0
  135. package/src/functions/remember.ts +162 -0
  136. package/src/functions/retention.ts +235 -0
  137. package/src/functions/routines.ts +289 -0
  138. package/src/functions/search.ts +80 -0
  139. package/src/functions/sentinels.ts +417 -0
  140. package/src/functions/signals.ts +186 -0
  141. package/src/functions/sketches.ts +274 -0
  142. package/src/functions/sliding-window.ts +257 -0
  143. package/src/functions/smart-search.ts +115 -0
  144. package/src/functions/snapshot.ts +219 -0
  145. package/src/functions/summarize.ts +155 -0
  146. package/src/functions/team.ts +147 -0
  147. package/src/functions/temporal-graph.ts +476 -0
  148. package/src/functions/timeline.ts +138 -0
  149. package/src/functions/verify.ts +117 -0
  150. package/src/health/monitor.ts +110 -0
  151. package/src/health/thresholds.ts +73 -0
  152. package/src/hooks/notification.ts +52 -0
  153. package/src/hooks/post-tool-failure.ts +58 -0
  154. package/src/hooks/post-tool-use.ts +62 -0
  155. package/src/hooks/pre-compact.ts +60 -0
  156. package/src/hooks/pre-tool-use.ts +72 -0
  157. package/src/hooks/prompt-submit.ts +46 -0
  158. package/src/hooks/session-end.ts +71 -0
  159. package/src/hooks/session-start.ts +48 -0
  160. package/src/hooks/stop.ts +39 -0
  161. package/src/hooks/subagent-start.ts +49 -0
  162. package/src/hooks/subagent-stop.ts +54 -0
  163. package/src/hooks/task-completed.ts +54 -0
  164. package/src/index.ts +342 -0
  165. package/src/mcp/in-memory-kv.ts +61 -0
  166. package/src/mcp/server.ts +1455 -0
  167. package/src/mcp/standalone.ts +177 -0
  168. package/src/mcp/tools-registry.ts +769 -0
  169. package/src/mcp/transport.ts +91 -0
  170. package/src/prompts/compression.ts +67 -0
  171. package/src/prompts/consolidation.ts +48 -0
  172. package/src/prompts/graph-extraction.ts +35 -0
  173. package/src/prompts/summary.ts +38 -0
  174. package/src/prompts/xml.ts +26 -0
  175. package/src/providers/agent-sdk.ts +34 -0
  176. package/src/providers/anthropic.ts +35 -0
  177. package/src/providers/circuit-breaker.ts +82 -0
  178. package/src/providers/embedding/cohere.ts +46 -0
  179. package/src/providers/embedding/gemini.ts +54 -0
  180. package/src/providers/embedding/index.ts +39 -0
  181. package/src/providers/embedding/local.ts +52 -0
  182. package/src/providers/embedding/openai.ts +45 -0
  183. package/src/providers/embedding/openrouter.ts +51 -0
  184. package/src/providers/embedding/voyage.ts +46 -0
  185. package/src/providers/fallback-chain.ts +31 -0
  186. package/src/providers/index.ts +84 -0
  187. package/src/providers/openrouter.ts +71 -0
  188. package/src/providers/resilient.ts +37 -0
  189. package/src/state/hybrid-search.ts +295 -0
  190. package/src/state/index-persistence.ts +63 -0
  191. package/src/state/keyed-mutex.ts +18 -0
  192. package/src/state/kv.ts +33 -0
  193. package/src/state/schema.ts +71 -0
  194. package/src/state/search-index.ts +245 -0
  195. package/src/state/stemmer.ts +104 -0
  196. package/src/state/synonyms.ts +63 -0
  197. package/src/state/vector-index.ts +130 -0
  198. package/src/telemetry/setup.ts +116 -0
  199. package/src/triggers/api.ts +1904 -0
  200. package/src/triggers/events.ts +71 -0
  201. package/src/types.ts +769 -0
  202. package/src/version.ts +1 -0
  203. package/src/viewer/index.html +2497 -0
  204. package/src/viewer/server.ts +207 -0
  205. package/src/xenova.d.ts +3 -0
  206. package/test/actions.test.ts +490 -0
  207. package/test/audit.test.ts +108 -0
  208. package/test/auto-forget.test.ts +188 -0
  209. package/test/cascade.test.ts +277 -0
  210. package/test/checkpoints.test.ts +493 -0
  211. package/test/circuit-breaker.test.ts +107 -0
  212. package/test/claude-bridge.test.ts +178 -0
  213. package/test/confidence.test.ts +247 -0
  214. package/test/consistency.test.ts +61 -0
  215. package/test/consolidation-pipeline.test.ts +251 -0
  216. package/test/crystallize.test.ts +521 -0
  217. package/test/diagnostics.test.ts +638 -0
  218. package/test/embedding-provider.test.ts +49 -0
  219. package/test/enrich.test.ts +209 -0
  220. package/test/eval.test.ts +300 -0
  221. package/test/export-import.test.ts +251 -0
  222. package/test/facets.test.ts +448 -0
  223. package/test/fallback-chain.test.ts +93 -0
  224. package/test/frontier.test.ts +485 -0
  225. package/test/governance.test.ts +147 -0
  226. package/test/graph-retrieval.test.ts +186 -0
  227. package/test/graph.test.ts +160 -0
  228. package/test/helpers/mocks.ts +40 -0
  229. package/test/hybrid-search.test.ts +145 -0
  230. package/test/index-persistence.test.ts +124 -0
  231. package/test/integration.test.ts +265 -0
  232. package/test/leases.test.ts +399 -0
  233. package/test/mcp-prompts.test.ts +218 -0
  234. package/test/mcp-resources.test.ts +286 -0
  235. package/test/mcp-standalone.test.ts +113 -0
  236. package/test/mesh.test.ts +700 -0
  237. package/test/privacy.test.ts +87 -0
  238. package/test/profile.test.ts +161 -0
  239. package/test/query-expansion.test.ts +154 -0
  240. package/test/relations.test.ts +198 -0
  241. package/test/retention.test.ts +245 -0
  242. package/test/routines.test.ts +497 -0
  243. package/test/schema-fingerprint.test.ts +81 -0
  244. package/test/schema.test.ts +42 -0
  245. package/test/search-index.test.ts +128 -0
  246. package/test/sentinels.test.ts +626 -0
  247. package/test/signals.test.ts +410 -0
  248. package/test/sketches.test.ts +549 -0
  249. package/test/sliding-window.test.ts +199 -0
  250. package/test/smart-search.test.ts +169 -0
  251. package/test/snapshot.test.ts +165 -0
  252. package/test/team.test.ts +156 -0
  253. package/test/temporal-graph.test.ts +378 -0
  254. package/test/timeline.test.ts +148 -0
  255. package/test/vector-index.test.ts +79 -0
  256. package/test/verify.test.ts +209 -0
  257. package/test/xml.test.ts +65 -0
  258. package/tsconfig.json +22 -0
  259. package/tsdown.config.ts +62 -0
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env node
2
+
3
+ const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
4
+ const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
5
+
6
+ function authHeaders(): Record<string, string> {
7
+ const h: Record<string, string> = { "Content-Type": "application/json" };
8
+ if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
9
+ return h;
10
+ }
11
+
12
+ async function main() {
13
+ let input = "";
14
+ for await (const chunk of process.stdin) {
15
+ input += chunk;
16
+ }
17
+
18
+ let data: Record<string, unknown>;
19
+ try {
20
+ data = JSON.parse(input);
21
+ } catch {
22
+ return;
23
+ }
24
+
25
+ const sessionId = (data.session_id as string) || "unknown";
26
+
27
+ try {
28
+ await fetch(`${REST_URL}/agentmemory/session/end`, {
29
+ method: "POST",
30
+ headers: authHeaders(),
31
+ body: JSON.stringify({ sessionId }),
32
+ signal: AbortSignal.timeout(5000),
33
+ });
34
+ } catch {
35
+ // best-effort
36
+ }
37
+
38
+ if (process.env["CONSOLIDATION_ENABLED"] === "true") {
39
+ try {
40
+ await fetch(`${REST_URL}/agentmemory/crystals/auto`, {
41
+ method: "POST",
42
+ headers: authHeaders(),
43
+ body: JSON.stringify({ olderThanDays: 0 }),
44
+ signal: AbortSignal.timeout(15000),
45
+ });
46
+ } catch {}
47
+
48
+ try {
49
+ await fetch(`${REST_URL}/agentmemory/consolidate-pipeline`, {
50
+ method: "POST",
51
+ headers: authHeaders(),
52
+ body: JSON.stringify({ tier: "all", force: true }),
53
+ signal: AbortSignal.timeout(30000),
54
+ });
55
+ } catch {}
56
+ }
57
+
58
+ if (process.env["CLAUDE_MEMORY_BRIDGE"] === "true") {
59
+ try {
60
+ await fetch(`${REST_URL}/agentmemory/claude-bridge/sync`, {
61
+ method: "POST",
62
+ headers: authHeaders(),
63
+ signal: AbortSignal.timeout(5000),
64
+ });
65
+ } catch {
66
+ // best-effort
67
+ }
68
+ }
69
+ }
70
+
71
+ main();
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+
3
+ const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
4
+ const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
5
+
6
+ function authHeaders(): Record<string, string> {
7
+ const h: Record<string, string> = { "Content-Type": "application/json" };
8
+ if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
9
+ return h;
10
+ }
11
+
12
+ async function main() {
13
+ let input = "";
14
+ for await (const chunk of process.stdin) {
15
+ input += chunk;
16
+ }
17
+
18
+ let data: Record<string, unknown>;
19
+ try {
20
+ data = JSON.parse(input);
21
+ } catch {
22
+ return;
23
+ }
24
+
25
+ const sessionId =
26
+ (data.session_id as string) || `ses_${Date.now().toString(36)}`;
27
+ const project = (data.cwd as string) || process.cwd();
28
+
29
+ try {
30
+ const res = await fetch(`${REST_URL}/agentmemory/session/start`, {
31
+ method: "POST",
32
+ headers: authHeaders(),
33
+ body: JSON.stringify({ sessionId, project, cwd: project }),
34
+ signal: AbortSignal.timeout(5000),
35
+ });
36
+
37
+ if (res.ok) {
38
+ const result = (await res.json()) as { context?: string };
39
+ if (result.context) {
40
+ process.stdout.write(result.context);
41
+ }
42
+ }
43
+ } catch {
44
+ // silently fail -- don't block Claude Code startup
45
+ }
46
+ }
47
+
48
+ main();
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+
3
+ const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
4
+ const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
5
+
6
+ function authHeaders(): Record<string, string> {
7
+ const h: Record<string, string> = { "Content-Type": "application/json" };
8
+ if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
9
+ return h;
10
+ }
11
+
12
+ async function main() {
13
+ let input = "";
14
+ for await (const chunk of process.stdin) {
15
+ input += chunk;
16
+ }
17
+
18
+ let data: Record<string, unknown>;
19
+ try {
20
+ data = JSON.parse(input);
21
+ } catch {
22
+ return;
23
+ }
24
+
25
+ const sessionId = (data.session_id as string) || "unknown";
26
+
27
+ try {
28
+ await fetch(`${REST_URL}/agentmemory/summarize`, {
29
+ method: "POST",
30
+ headers: authHeaders(),
31
+ body: JSON.stringify({ sessionId }),
32
+ signal: AbortSignal.timeout(30000),
33
+ });
34
+ } catch {
35
+ // summarize is best-effort
36
+ }
37
+ }
38
+
39
+ main();
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+
3
+ const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
4
+ const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
5
+
6
+ function authHeaders(): Record<string, string> {
7
+ const h: Record<string, string> = { "Content-Type": "application/json" };
8
+ if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
9
+ return h;
10
+ }
11
+
12
+ async function main() {
13
+ let input = "";
14
+ for await (const chunk of process.stdin) {
15
+ input += chunk;
16
+ }
17
+
18
+ let data: Record<string, unknown>;
19
+ try {
20
+ data = JSON.parse(input);
21
+ } catch {
22
+ return;
23
+ }
24
+
25
+ const sessionId = (data.session_id as string) || "unknown";
26
+
27
+ try {
28
+ await fetch(`${REST_URL}/agentmemory/observe`, {
29
+ method: "POST",
30
+ headers: authHeaders(),
31
+ body: JSON.stringify({
32
+ hookType: "subagent_start",
33
+ sessionId,
34
+ project: data.cwd || process.cwd(),
35
+ cwd: data.cwd || process.cwd(),
36
+ timestamp: new Date().toISOString(),
37
+ data: {
38
+ agent_id: data.agent_id,
39
+ agent_type: data.agent_type,
40
+ },
41
+ }),
42
+ signal: AbortSignal.timeout(2000),
43
+ });
44
+ } catch {
45
+ // fire and forget
46
+ }
47
+ }
48
+
49
+ main();
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+
3
+ const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
4
+ const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
5
+
6
+ function authHeaders(): Record<string, string> {
7
+ const h: Record<string, string> = { "Content-Type": "application/json" };
8
+ if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
9
+ return h;
10
+ }
11
+
12
+ async function main() {
13
+ let input = "";
14
+ for await (const chunk of process.stdin) {
15
+ input += chunk;
16
+ }
17
+
18
+ let data: Record<string, unknown>;
19
+ try {
20
+ data = JSON.parse(input);
21
+ } catch {
22
+ return;
23
+ }
24
+
25
+ const sessionId = (data.session_id as string) || "unknown";
26
+ const lastMsg =
27
+ typeof data.last_assistant_message === "string"
28
+ ? data.last_assistant_message.slice(0, 4000)
29
+ : "";
30
+
31
+ try {
32
+ await fetch(`${REST_URL}/agentmemory/observe`, {
33
+ method: "POST",
34
+ headers: authHeaders(),
35
+ body: JSON.stringify({
36
+ hookType: "subagent_stop",
37
+ sessionId,
38
+ project: data.cwd || process.cwd(),
39
+ cwd: data.cwd || process.cwd(),
40
+ timestamp: new Date().toISOString(),
41
+ data: {
42
+ agent_id: data.agent_id,
43
+ agent_type: data.agent_type,
44
+ last_message: lastMsg,
45
+ },
46
+ }),
47
+ signal: AbortSignal.timeout(2000),
48
+ });
49
+ } catch {
50
+ // fire and forget
51
+ }
52
+ }
53
+
54
+ main();
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+
3
+ const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
4
+ const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
5
+
6
+ function authHeaders(): Record<string, string> {
7
+ const h: Record<string, string> = { "Content-Type": "application/json" };
8
+ if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
9
+ return h;
10
+ }
11
+
12
+ async function main() {
13
+ let input = "";
14
+ for await (const chunk of process.stdin) {
15
+ input += chunk;
16
+ }
17
+
18
+ let data: Record<string, unknown>;
19
+ try {
20
+ data = JSON.parse(input);
21
+ } catch {
22
+ return;
23
+ }
24
+
25
+ const sessionId = (data.session_id as string) || "unknown";
26
+
27
+ try {
28
+ await fetch(`${REST_URL}/agentmemory/observe`, {
29
+ method: "POST",
30
+ headers: authHeaders(),
31
+ body: JSON.stringify({
32
+ hookType: "task_completed",
33
+ sessionId,
34
+ project: data.cwd || process.cwd(),
35
+ cwd: data.cwd || process.cwd(),
36
+ timestamp: new Date().toISOString(),
37
+ data: {
38
+ task_id: data.task_id,
39
+ task_subject: data.task_subject,
40
+ task_description: typeof data.task_description === "string"
41
+ ? data.task_description.slice(0, 2000)
42
+ : "",
43
+ teammate_name: data.teammate_name,
44
+ team_name: data.team_name,
45
+ },
46
+ }),
47
+ signal: AbortSignal.timeout(2000),
48
+ });
49
+ } catch {
50
+ // fire and forget
51
+ }
52
+ }
53
+
54
+ main();
package/src/index.ts ADDED
@@ -0,0 +1,342 @@
1
+ import { init } from "iii-sdk";
2
+ import {
3
+ loadConfig,
4
+ getEnvVar,
5
+ loadEmbeddingConfig,
6
+ loadFallbackConfig,
7
+ loadClaudeBridgeConfig,
8
+ loadTeamConfig,
9
+ loadSnapshotConfig,
10
+ isGraphExtractionEnabled,
11
+ isConsolidationEnabled,
12
+ } from "./config.js";
13
+ import {
14
+ createProvider,
15
+ createFallbackProvider,
16
+ createEmbeddingProvider,
17
+ } from "./providers/index.js";
18
+ import { StateKV } from "./state/kv.js";
19
+ import { VectorIndex } from "./state/vector-index.js";
20
+ import { HybridSearch } from "./state/hybrid-search.js";
21
+ import { IndexPersistence } from "./state/index-persistence.js";
22
+ import { registerPrivacyFunction } from "./functions/privacy.js";
23
+ import { registerObserveFunction } from "./functions/observe.js";
24
+ import { registerCompressFunction } from "./functions/compress.js";
25
+ import {
26
+ registerSearchFunction,
27
+ rebuildIndex,
28
+ getSearchIndex,
29
+ } from "./functions/search.js";
30
+ import { registerContextFunction } from "./functions/context.js";
31
+ import { registerSummarizeFunction } from "./functions/summarize.js";
32
+ import { registerMigrateFunction } from "./functions/migrate.js";
33
+ import { registerFileIndexFunction } from "./functions/file-index.js";
34
+ import { registerConsolidateFunction } from "./functions/consolidate.js";
35
+ import { registerPatternsFunction } from "./functions/patterns.js";
36
+ import { registerRememberFunction } from "./functions/remember.js";
37
+ import { registerEvictFunction } from "./functions/evict.js";
38
+ import { registerRelationsFunction } from "./functions/relations.js";
39
+ import { registerTimelineFunction } from "./functions/timeline.js";
40
+ import { registerSmartSearchFunction } from "./functions/smart-search.js";
41
+ import { registerProfileFunction } from "./functions/profile.js";
42
+ import { registerAutoForgetFunction } from "./functions/auto-forget.js";
43
+ import { registerExportImportFunction } from "./functions/export-import.js";
44
+ import { registerEnrichFunction } from "./functions/enrich.js";
45
+ import { registerClaudeBridgeFunction } from "./functions/claude-bridge.js";
46
+ import { registerGraphFunction } from "./functions/graph.js";
47
+ import { registerConsolidationPipelineFunction } from "./functions/consolidation-pipeline.js";
48
+ import { registerTeamFunction } from "./functions/team.js";
49
+ import { registerGovernanceFunction } from "./functions/governance.js";
50
+ import { registerSnapshotFunction } from "./functions/snapshot.js";
51
+ import { registerActionsFunction } from "./functions/actions.js";
52
+ import { registerFrontierFunction } from "./functions/frontier.js";
53
+ import { registerLeasesFunction } from "./functions/leases.js";
54
+ import { registerRoutinesFunction } from "./functions/routines.js";
55
+ import { registerSignalsFunction } from "./functions/signals.js";
56
+ import { registerCheckpointsFunction } from "./functions/checkpoints.js";
57
+ import { registerFlowCompressFunction } from "./functions/flow-compress.js";
58
+ import { registerMeshFunction } from "./functions/mesh.js";
59
+ import { registerBranchAwareFunction } from "./functions/branch-aware.js";
60
+ import { registerSentinelsFunction } from "./functions/sentinels.js";
61
+ import { registerSketchesFunction } from "./functions/sketches.js";
62
+ import { registerCrystallizeFunction } from "./functions/crystallize.js";
63
+ import { registerDiagnosticsFunction } from "./functions/diagnostics.js";
64
+ import { registerFacetsFunction } from "./functions/facets.js";
65
+ import { registerVerifyFunction } from "./functions/verify.js";
66
+ import { registerCascadeFunction } from "./functions/cascade.js";
67
+ import { registerLessonsFunctions } from "./functions/lessons.js";
68
+ import { registerObsidianExportFunction } from "./functions/obsidian-export.js";
69
+ import { registerSlidingWindowFunction } from "./functions/sliding-window.js";
70
+ import { registerQueryExpansionFunction } from "./functions/query-expansion.js";
71
+ import { registerTemporalGraphFunctions } from "./functions/temporal-graph.js";
72
+ import { registerRetentionFunctions } from "./functions/retention.js";
73
+ import { registerApiTriggers } from "./triggers/api.js";
74
+ import { registerEventTriggers } from "./triggers/events.js";
75
+ import { registerMcpEndpoints } from "./mcp/server.js";
76
+ import { startViewerServer } from "./viewer/server.js";
77
+ import { MetricsStore } from "./eval/metrics-store.js";
78
+ import { DedupMap } from "./functions/dedup.js";
79
+ import { registerHealthMonitor } from "./health/monitor.js";
80
+ import { initMetrics, OTEL_CONFIG } from "./telemetry/setup.js";
81
+ import { VERSION } from "./version.js";
82
+
83
+ async function main() {
84
+ const config = loadConfig();
85
+ const embeddingConfig = loadEmbeddingConfig();
86
+ const fallbackConfig = loadFallbackConfig();
87
+
88
+ const provider =
89
+ fallbackConfig.providers.length > 0
90
+ ? createFallbackProvider(config.provider, fallbackConfig)
91
+ : createProvider(config.provider);
92
+
93
+ const embeddingProvider = createEmbeddingProvider();
94
+
95
+ console.log(`[agentmemory] Starting worker v${VERSION}...`);
96
+ console.log(`[agentmemory] Engine: ${config.engineUrl}`);
97
+ console.log(
98
+ `[agentmemory] Provider: ${config.provider.provider} (${config.provider.model})`,
99
+ );
100
+ if (embeddingProvider) {
101
+ console.log(
102
+ `[agentmemory] Embedding provider: ${embeddingProvider.name} (${embeddingProvider.dimensions} dims)`,
103
+ );
104
+ } else {
105
+ console.log(`[agentmemory] Embedding provider: none (BM25-only mode)`);
106
+ }
107
+ console.log(
108
+ `[agentmemory] REST API: http://localhost:${config.restPort}/agentmemory/*`,
109
+ );
110
+ console.log(`[agentmemory] Streams: ws://localhost:${config.streamsPort}`);
111
+
112
+ const sdk = init(config.engineUrl, {
113
+ workerName: "agentmemory",
114
+ otel: {
115
+ serviceName: OTEL_CONFIG.serviceName,
116
+ serviceVersion: OTEL_CONFIG.serviceVersion,
117
+ metricsExportIntervalMs: OTEL_CONFIG.metricsExportIntervalMs,
118
+ },
119
+ });
120
+
121
+ const kv = new StateKV(sdk);
122
+ const secret = getEnvVar("AGENTMEMORY_SECRET");
123
+ const metricsStore = new MetricsStore(kv);
124
+ const dedupMap = new DedupMap();
125
+
126
+ const vectorIndex = embeddingProvider ? new VectorIndex() : null;
127
+
128
+ initMetrics(
129
+ typeof (sdk as any).getMeter === "function"
130
+ ? (sdk as any).getMeter.bind(sdk)
131
+ : undefined,
132
+ );
133
+
134
+ registerPrivacyFunction(sdk);
135
+ registerObserveFunction(sdk, kv, dedupMap, config.maxObservationsPerSession);
136
+ registerCompressFunction(sdk, kv, provider, metricsStore);
137
+ registerSearchFunction(sdk, kv);
138
+ registerContextFunction(sdk, kv, config.tokenBudget);
139
+ registerSummarizeFunction(sdk, kv, provider, metricsStore);
140
+ registerMigrateFunction(sdk, kv);
141
+ registerFileIndexFunction(sdk, kv);
142
+ registerConsolidateFunction(sdk, kv, provider);
143
+ registerPatternsFunction(sdk, kv);
144
+ registerRememberFunction(sdk, kv);
145
+ registerEvictFunction(sdk, kv);
146
+
147
+ registerRelationsFunction(sdk, kv);
148
+ registerTimelineFunction(sdk, kv);
149
+ registerProfileFunction(sdk, kv);
150
+ registerAutoForgetFunction(sdk, kv);
151
+ registerExportImportFunction(sdk, kv);
152
+ registerEnrichFunction(sdk, kv);
153
+
154
+ const claudeBridgeConfig = loadClaudeBridgeConfig();
155
+ if (claudeBridgeConfig.enabled) {
156
+ registerClaudeBridgeFunction(sdk, kv, claudeBridgeConfig);
157
+ console.log(
158
+ `[agentmemory] Claude bridge: syncing to ${claudeBridgeConfig.memoryFilePath}`,
159
+ );
160
+ }
161
+
162
+ if (isGraphExtractionEnabled()) {
163
+ registerGraphFunction(sdk, kv, provider);
164
+ console.log(`[agentmemory] Knowledge graph: extraction enabled`);
165
+ }
166
+
167
+ registerConsolidationPipelineFunction(sdk, kv, provider);
168
+ console.log(`[agentmemory] Consolidation pipeline: registered (CONSOLIDATION_ENABLED=${isConsolidationEnabled() ? "true" : "false"})`);
169
+
170
+ const teamConfig = loadTeamConfig();
171
+ if (teamConfig) {
172
+ registerTeamFunction(sdk, kv, teamConfig);
173
+ console.log(
174
+ `[agentmemory] Team memory: ${teamConfig.teamId} (${teamConfig.mode})`,
175
+ );
176
+ }
177
+
178
+ registerGovernanceFunction(sdk, kv);
179
+
180
+ registerActionsFunction(sdk, kv);
181
+ registerFrontierFunction(sdk, kv);
182
+ registerLeasesFunction(sdk, kv);
183
+ registerRoutinesFunction(sdk, kv);
184
+ registerSignalsFunction(sdk, kv);
185
+ registerCheckpointsFunction(sdk, kv);
186
+ registerMeshFunction(sdk, kv);
187
+ registerBranchAwareFunction(sdk, kv);
188
+ registerFlowCompressFunction(sdk, kv, provider);
189
+ registerSentinelsFunction(sdk, kv);
190
+ registerSketchesFunction(sdk, kv);
191
+ registerCrystallizeFunction(sdk, kv, provider);
192
+ registerDiagnosticsFunction(sdk, kv);
193
+ registerFacetsFunction(sdk, kv);
194
+ registerVerifyFunction(sdk, kv);
195
+ registerLessonsFunctions(sdk, kv);
196
+ registerObsidianExportFunction(sdk, kv);
197
+ registerCascadeFunction(sdk, kv);
198
+
199
+ registerSlidingWindowFunction(sdk, kv, provider);
200
+ registerQueryExpansionFunction(sdk, provider);
201
+ registerTemporalGraphFunctions(sdk, kv, provider);
202
+ registerRetentionFunctions(sdk, kv);
203
+ console.log(
204
+ `[agentmemory] v0.6 advanced retrieval: sliding-window, query-expansion, temporal-graph, retention-scoring`,
205
+ );
206
+ console.log(
207
+ `[agentmemory] Orchestration layer: actions, frontier, leases, routines, signals, checkpoints, flow-compress, mesh, branch-aware, sentinels, sketches, crystallize, diagnostics, facets`,
208
+ );
209
+
210
+ const snapshotConfig = loadSnapshotConfig();
211
+ if (snapshotConfig.enabled) {
212
+ registerSnapshotFunction(sdk, kv, snapshotConfig.dir);
213
+ console.log(
214
+ `[agentmemory] Git snapshots: ${snapshotConfig.dir} (every ${snapshotConfig.interval}s)`,
215
+ );
216
+ }
217
+
218
+ const bm25Index = getSearchIndex();
219
+ const graphWeight = parseFloat(getEnvVar("AGENTMEMORY_GRAPH_WEIGHT") || "0.3");
220
+ const hybridSearch = new HybridSearch(
221
+ bm25Index,
222
+ vectorIndex,
223
+ embeddingProvider,
224
+ kv,
225
+ embeddingConfig.bm25Weight,
226
+ embeddingConfig.vectorWeight,
227
+ graphWeight,
228
+ );
229
+
230
+ registerSmartSearchFunction(sdk, kv, (query, limit) =>
231
+ hybridSearch.search(query, limit),
232
+ );
233
+
234
+ registerApiTriggers(sdk, kv, secret, metricsStore, provider);
235
+ registerEventTriggers(sdk, kv);
236
+ registerMcpEndpoints(sdk, kv, secret);
237
+
238
+ const healthMonitor = registerHealthMonitor(sdk, kv);
239
+
240
+ const indexPersistence = new IndexPersistence(kv, bm25Index, vectorIndex);
241
+
242
+ const loaded = await indexPersistence.load().catch((err) => {
243
+ console.warn(`[agentmemory] Failed to load persisted index:`, err);
244
+ return null;
245
+ });
246
+ if (loaded?.bm25 && loaded.bm25.size > 0) {
247
+ bm25Index.restoreFrom(loaded.bm25);
248
+ console.log(
249
+ `[agentmemory] Loaded persisted BM25 index (${bm25Index.size} docs)`,
250
+ );
251
+ }
252
+ if (loaded?.vector && vectorIndex && loaded.vector.size > 0) {
253
+ vectorIndex.restoreFrom(loaded.vector);
254
+ console.log(
255
+ `[agentmemory] Loaded persisted vector index (${vectorIndex.size} vectors)`,
256
+ );
257
+ }
258
+
259
+ const needsRebuild = bm25Index.size === 0;
260
+
261
+ if (needsRebuild) {
262
+ const indexCount = await rebuildIndex(kv).catch((err) => {
263
+ console.warn(`[agentmemory] Failed to rebuild search index:`, err);
264
+ return 0;
265
+ });
266
+ if (indexCount > 0) {
267
+ console.log(
268
+ `[agentmemory] Search index rebuilt: ${indexCount} observations`,
269
+ );
270
+ indexPersistence.scheduleSave();
271
+ }
272
+ }
273
+
274
+ console.log(
275
+ `[agentmemory] Ready. ${embeddingProvider ? "Triple-stream (BM25+Vector+Graph)" : "BM25+Graph"} search active.`,
276
+ );
277
+ console.log(
278
+ `[agentmemory] Endpoints: 100 REST + 41 MCP tools + 6 MCP resources + 3 MCP prompts`,
279
+ );
280
+
281
+ const viewerPort = config.restPort + 2;
282
+ const viewerServer = startViewerServer(
283
+ viewerPort,
284
+ kv,
285
+ sdk,
286
+ secret,
287
+ config.restPort,
288
+ );
289
+
290
+ const autoForgetIntervalMs = parseInt(process.env.AUTO_FORGET_INTERVAL_MS || "3600000", 10);
291
+ const consolidationIntervalMs = parseInt(process.env.CONSOLIDATION_INTERVAL_MS || "7200000", 10);
292
+
293
+ if (process.env.AUTO_FORGET_ENABLED !== "false") {
294
+ const autoForgetTimer = setInterval(async () => {
295
+ try {
296
+ await sdk.trigger("mem::auto-forget", { dryRun: false });
297
+ } catch {}
298
+ }, autoForgetIntervalMs);
299
+ autoForgetTimer.unref();
300
+ console.log(`[agentmemory] Auto-forget: enabled (every ${autoForgetIntervalMs / 60000}m)`);
301
+ }
302
+
303
+ if (process.env.LESSON_DECAY_ENABLED !== "false") {
304
+ const lessonDecayTimer = setInterval(async () => {
305
+ try {
306
+ await sdk.trigger("mem::lesson-decay-sweep", {});
307
+ } catch {}
308
+ }, 86400000);
309
+ lessonDecayTimer.unref();
310
+ console.log(`[agentmemory] Lesson decay sweep: enabled (every 24h)`);
311
+ }
312
+
313
+ if (isConsolidationEnabled()) {
314
+ const consolidationTimer = setInterval(async () => {
315
+ try {
316
+ await sdk.trigger("mem::consolidate-pipeline", {});
317
+ } catch {}
318
+ }, consolidationIntervalMs);
319
+ consolidationTimer.unref();
320
+ console.log(`[agentmemory] Auto-consolidation: enabled (every ${consolidationIntervalMs / 60000}m)`);
321
+ }
322
+
323
+ const shutdown = async () => {
324
+ console.log(`\n[agentmemory] Shutting down...`);
325
+ healthMonitor.stop();
326
+ dedupMap.stop();
327
+ indexPersistence.stop();
328
+ await new Promise<void>((resolve) => viewerServer.close(() => resolve()));
329
+ await indexPersistence.save().catch((err) => {
330
+ console.warn(`[agentmemory] Failed to save index on shutdown:`, err);
331
+ });
332
+ await sdk.shutdown();
333
+ process.exit(0);
334
+ };
335
+ process.on("SIGINT", shutdown);
336
+ process.on("SIGTERM", shutdown);
337
+ }
338
+
339
+ main().catch((err) => {
340
+ console.error(`[agentmemory] Fatal:`, err);
341
+ process.exit(1);
342
+ });