@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,71 +0,0 @@
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();
@@ -1,48 +0,0 @@
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();
package/src/hooks/stop.ts DELETED
@@ -1,39 +0,0 @@
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();
@@ -1,49 +0,0 @@
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();
@@ -1,54 +0,0 @@
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();
@@ -1,54 +0,0 @@
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 DELETED
@@ -1,342 +0,0 @@
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
- });