@hasna/mementos 0.14.21 → 0.14.22

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 (239) hide show
  1. package/LICENSE +3 -189
  2. package/README.md +15 -27
  3. package/dist/agent-setup.d.ts +34 -0
  4. package/dist/agent-setup.d.ts.map +1 -0
  5. package/dist/cli.d.ts +3 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +517 -0
  8. package/dist/index.d.ts +3 -27
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +455 -14652
  11. package/dist/mcp-runtime.d.ts +23 -0
  12. package/dist/mcp-runtime.d.ts.map +1 -0
  13. package/dist/mcp.d.ts +3 -0
  14. package/dist/mcp.d.ts.map +1 -0
  15. package/dist/mcp.js +300 -0
  16. package/dist/remote-client.d.ts +44 -0
  17. package/dist/remote-client.d.ts.map +1 -0
  18. package/package.json +13 -53
  19. package/dashboard/dist/assets/index-DqyMbv89.js +0 -270
  20. package/dashboard/dist/assets/index-UBCddFo_.css +0 -1
  21. package/dashboard/dist/index.html +0 -13
  22. package/dist/cli/brains.d.ts +0 -3
  23. package/dist/cli/brains.d.ts.map +0 -1
  24. package/dist/cli/index.d.ts +0 -3
  25. package/dist/cli/index.d.ts.map +0 -1
  26. package/dist/cli/index.js +0 -25738
  27. package/dist/db/acl.d.ts +0 -34
  28. package/dist/db/acl.d.ts.map +0 -1
  29. package/dist/db/agents.d.ts +0 -15
  30. package/dist/db/agents.d.ts.map +0 -1
  31. package/dist/db/audit.d.ts +0 -39
  32. package/dist/db/audit.d.ts.map +0 -1
  33. package/dist/db/database.d.ts +0 -10
  34. package/dist/db/database.d.ts.map +0 -1
  35. package/dist/db/entities.d.ts +0 -62
  36. package/dist/db/entities.d.ts.map +0 -1
  37. package/dist/db/entity-memories.d.ts +0 -34
  38. package/dist/db/entity-memories.d.ts.map +0 -1
  39. package/dist/db/locks.d.ts +0 -63
  40. package/dist/db/locks.d.ts.map +0 -1
  41. package/dist/db/machines.d.ts +0 -16
  42. package/dist/db/machines.d.ts.map +0 -1
  43. package/dist/db/memories.d.ts +0 -40
  44. package/dist/db/memories.d.ts.map +0 -1
  45. package/dist/db/pg-migrations.d.ts +0 -8
  46. package/dist/db/pg-migrations.d.ts.map +0 -1
  47. package/dist/db/projects.d.ts +0 -6
  48. package/dist/db/projects.d.ts.map +0 -1
  49. package/dist/db/ratings.d.ts +0 -23
  50. package/dist/db/ratings.d.ts.map +0 -1
  51. package/dist/db/relations.d.ts +0 -29
  52. package/dist/db/relations.d.ts.map +0 -1
  53. package/dist/db/session-jobs.d.ts +0 -49
  54. package/dist/db/session-jobs.d.ts.map +0 -1
  55. package/dist/db/synthesis.d.ts +0 -101
  56. package/dist/db/synthesis.d.ts.map +0 -1
  57. package/dist/db/tool-events.d.ts +0 -27
  58. package/dist/db/tool-events.d.ts.map +0 -1
  59. package/dist/db/webhook_hooks.d.ts +0 -25
  60. package/dist/db/webhook_hooks.d.ts.map +0 -1
  61. package/dist/lib/activation-matcher.d.ts +0 -16
  62. package/dist/lib/activation-matcher.d.ts.map +0 -1
  63. package/dist/lib/asmr/categorizer.d.ts +0 -31
  64. package/dist/lib/asmr/categorizer.d.ts.map +0 -1
  65. package/dist/lib/asmr/context-agent.d.ts +0 -4
  66. package/dist/lib/asmr/context-agent.d.ts.map +0 -1
  67. package/dist/lib/asmr/ensemble.d.ts +0 -23
  68. package/dist/lib/asmr/ensemble.d.ts.map +0 -1
  69. package/dist/lib/asmr/fact-agent.d.ts +0 -4
  70. package/dist/lib/asmr/fact-agent.d.ts.map +0 -1
  71. package/dist/lib/asmr/index.d.ts +0 -7
  72. package/dist/lib/asmr/index.d.ts.map +0 -1
  73. package/dist/lib/asmr/orchestrator.d.ts +0 -4
  74. package/dist/lib/asmr/orchestrator.d.ts.map +0 -1
  75. package/dist/lib/asmr/temporal-agent.d.ts +0 -4
  76. package/dist/lib/asmr/temporal-agent.d.ts.map +0 -1
  77. package/dist/lib/asmr/types.d.ts +0 -27
  78. package/dist/lib/asmr/types.d.ts.map +0 -1
  79. package/dist/lib/auto-inject-orchestrator.d.ts +0 -57
  80. package/dist/lib/auto-inject-orchestrator.d.ts.map +0 -1
  81. package/dist/lib/auto-memory-queue.d.ts +0 -46
  82. package/dist/lib/auto-memory-queue.d.ts.map +0 -1
  83. package/dist/lib/auto-memory.d.ts +0 -18
  84. package/dist/lib/auto-memory.d.ts.map +0 -1
  85. package/dist/lib/bench.d.ts +0 -20
  86. package/dist/lib/bench.d.ts.map +0 -1
  87. package/dist/lib/built-in-hooks.d.ts +0 -12
  88. package/dist/lib/built-in-hooks.d.ts.map +0 -1
  89. package/dist/lib/channel-pusher.d.ts +0 -39
  90. package/dist/lib/channel-pusher.d.ts.map +0 -1
  91. package/dist/lib/config.d.ts +0 -9
  92. package/dist/lib/config.d.ts.map +0 -1
  93. package/dist/lib/connectors/files.d.ts +0 -8
  94. package/dist/lib/connectors/files.d.ts.map +0 -1
  95. package/dist/lib/connectors/github.d.ts +0 -7
  96. package/dist/lib/connectors/github.d.ts.map +0 -1
  97. package/dist/lib/connectors/index.d.ts +0 -12
  98. package/dist/lib/connectors/index.d.ts.map +0 -1
  99. package/dist/lib/connectors/notion.d.ts +0 -7
  100. package/dist/lib/connectors/notion.d.ts.map +0 -1
  101. package/dist/lib/connectors/types.d.ts +0 -27
  102. package/dist/lib/connectors/types.d.ts.map +0 -1
  103. package/dist/lib/context-extractor.d.ts +0 -14
  104. package/dist/lib/context-extractor.d.ts.map +0 -1
  105. package/dist/lib/context.d.ts +0 -35
  106. package/dist/lib/context.d.ts.map +0 -1
  107. package/dist/lib/contradiction.d.ts +0 -50
  108. package/dist/lib/contradiction.d.ts.map +0 -1
  109. package/dist/lib/decay.d.ts +0 -35
  110. package/dist/lib/decay.d.ts.map +0 -1
  111. package/dist/lib/dedup.d.ts +0 -33
  112. package/dist/lib/dedup.d.ts.map +0 -1
  113. package/dist/lib/duration.d.ts +0 -28
  114. package/dist/lib/duration.d.ts.map +0 -1
  115. package/dist/lib/embeddings.d.ts +0 -20
  116. package/dist/lib/embeddings.d.ts.map +0 -1
  117. package/dist/lib/export-v1.d.ts +0 -30
  118. package/dist/lib/export-v1.d.ts.map +0 -1
  119. package/dist/lib/extractor.d.ts +0 -9
  120. package/dist/lib/extractor.d.ts.map +0 -1
  121. package/dist/lib/extractors/audio.d.ts +0 -8
  122. package/dist/lib/extractors/audio.d.ts.map +0 -1
  123. package/dist/lib/extractors/index.d.ts +0 -12
  124. package/dist/lib/extractors/index.d.ts.map +0 -1
  125. package/dist/lib/extractors/ocr.d.ts +0 -7
  126. package/dist/lib/extractors/ocr.d.ts.map +0 -1
  127. package/dist/lib/extractors/pdf.d.ts +0 -7
  128. package/dist/lib/extractors/pdf.d.ts.map +0 -1
  129. package/dist/lib/extractors/types.d.ts +0 -12
  130. package/dist/lib/extractors/types.d.ts.map +0 -1
  131. package/dist/lib/file-deps.d.ts +0 -27
  132. package/dist/lib/file-deps.d.ts.map +0 -1
  133. package/dist/lib/focus.d.ts +0 -58
  134. package/dist/lib/focus.d.ts.map +0 -1
  135. package/dist/lib/gatherer.d.ts +0 -16
  136. package/dist/lib/gatherer.d.ts.map +0 -1
  137. package/dist/lib/gdpr.d.ts +0 -24
  138. package/dist/lib/gdpr.d.ts.map +0 -1
  139. package/dist/lib/hooks.d.ts +0 -50
  140. package/dist/lib/hooks.d.ts.map +0 -1
  141. package/dist/lib/importers/index.d.ts +0 -38
  142. package/dist/lib/importers/index.d.ts.map +0 -1
  143. package/dist/lib/injector.d.ts +0 -86
  144. package/dist/lib/injector.d.ts.map +0 -1
  145. package/dist/lib/matryoshka.d.ts +0 -50
  146. package/dist/lib/matryoshka.d.ts.map +0 -1
  147. package/dist/lib/memory-lock.d.ts +0 -58
  148. package/dist/lib/memory-lock.d.ts.map +0 -1
  149. package/dist/lib/model-config.d.ts +0 -14
  150. package/dist/lib/model-config.d.ts.map +0 -1
  151. package/dist/lib/open-sessions-connector.d.ts +0 -60
  152. package/dist/lib/open-sessions-connector.d.ts.map +0 -1
  153. package/dist/lib/poisoning.d.ts +0 -19
  154. package/dist/lib/poisoning.d.ts.map +0 -1
  155. package/dist/lib/poll.d.ts +0 -17
  156. package/dist/lib/poll.d.ts.map +0 -1
  157. package/dist/lib/procedural-extractor.d.ts +0 -21
  158. package/dist/lib/procedural-extractor.d.ts.map +0 -1
  159. package/dist/lib/profile-sync.d.ts +0 -20
  160. package/dist/lib/profile-sync.d.ts.map +0 -1
  161. package/dist/lib/profile-synthesizer.d.ts +0 -20
  162. package/dist/lib/profile-synthesizer.d.ts.map +0 -1
  163. package/dist/lib/project-detect.d.ts +0 -18
  164. package/dist/lib/project-detect.d.ts.map +0 -1
  165. package/dist/lib/providers/anthropic.d.ts +0 -21
  166. package/dist/lib/providers/anthropic.d.ts.map +0 -1
  167. package/dist/lib/providers/base.d.ts +0 -96
  168. package/dist/lib/providers/base.d.ts.map +0 -1
  169. package/dist/lib/providers/cerebras.d.ts +0 -20
  170. package/dist/lib/providers/cerebras.d.ts.map +0 -1
  171. package/dist/lib/providers/grok.d.ts +0 -19
  172. package/dist/lib/providers/grok.d.ts.map +0 -1
  173. package/dist/lib/providers/index.d.ts +0 -7
  174. package/dist/lib/providers/index.d.ts.map +0 -1
  175. package/dist/lib/providers/openai-compat.d.ts +0 -18
  176. package/dist/lib/providers/openai-compat.d.ts.map +0 -1
  177. package/dist/lib/providers/openai.d.ts +0 -20
  178. package/dist/lib/providers/openai.d.ts.map +0 -1
  179. package/dist/lib/providers/registry.d.ts +0 -38
  180. package/dist/lib/providers/registry.d.ts.map +0 -1
  181. package/dist/lib/quality.d.ts +0 -16
  182. package/dist/lib/quality.d.ts.map +0 -1
  183. package/dist/lib/redact.d.ts +0 -10
  184. package/dist/lib/redact.d.ts.map +0 -1
  185. package/dist/lib/remote-sync.d.ts +0 -49
  186. package/dist/lib/remote-sync.d.ts.map +0 -1
  187. package/dist/lib/retention.d.ts +0 -17
  188. package/dist/lib/retention.d.ts.map +0 -1
  189. package/dist/lib/search.d.ts +0 -52
  190. package/dist/lib/search.d.ts.map +0 -1
  191. package/dist/lib/session-auto-resolve.d.ts +0 -28
  192. package/dist/lib/session-auto-resolve.d.ts.map +0 -1
  193. package/dist/lib/session-processor.d.ts +0 -38
  194. package/dist/lib/session-processor.d.ts.map +0 -1
  195. package/dist/lib/session-queue.d.ts +0 -28
  196. package/dist/lib/session-queue.d.ts.map +0 -1
  197. package/dist/lib/session-registry.d.ts +0 -47
  198. package/dist/lib/session-registry.d.ts.map +0 -1
  199. package/dist/lib/session-start-briefing.d.ts +0 -10
  200. package/dist/lib/session-start-briefing.d.ts.map +0 -1
  201. package/dist/lib/session-watcher.d.ts +0 -30
  202. package/dist/lib/session-watcher.d.ts.map +0 -1
  203. package/dist/lib/sync.d.ts +0 -10
  204. package/dist/lib/sync.d.ts.map +0 -1
  205. package/dist/lib/synthesis/corpus-builder.d.ts +0 -30
  206. package/dist/lib/synthesis/corpus-builder.d.ts.map +0 -1
  207. package/dist/lib/synthesis/executor.d.ts +0 -14
  208. package/dist/lib/synthesis/executor.d.ts.map +0 -1
  209. package/dist/lib/synthesis/index.d.ts +0 -37
  210. package/dist/lib/synthesis/index.d.ts.map +0 -1
  211. package/dist/lib/synthesis/llm-analyzer.d.ts +0 -18
  212. package/dist/lib/synthesis/llm-analyzer.d.ts.map +0 -1
  213. package/dist/lib/synthesis/metrics.d.ts +0 -13
  214. package/dist/lib/synthesis/metrics.d.ts.map +0 -1
  215. package/dist/lib/synthesis/scheduler.d.ts +0 -18
  216. package/dist/lib/synthesis/scheduler.d.ts.map +0 -1
  217. package/dist/lib/synthesis/validator.d.ts +0 -19
  218. package/dist/lib/synthesis/validator.d.ts.map +0 -1
  219. package/dist/lib/tool-lesson-extractor.d.ts +0 -24
  220. package/dist/lib/tool-lesson-extractor.d.ts.map +0 -1
  221. package/dist/lib/tool-memory-synthesizer.d.ts +0 -28
  222. package/dist/lib/tool-memory-synthesizer.d.ts.map +0 -1
  223. package/dist/lib/topic-clusterer.d.ts +0 -21
  224. package/dist/lib/topic-clusterer.d.ts.map +0 -1
  225. package/dist/lib/when-to-use-generator.d.ts +0 -22
  226. package/dist/lib/when-to-use-generator.d.ts.map +0 -1
  227. package/dist/mcp/index.d.ts +0 -5
  228. package/dist/mcp/index.d.ts.map +0 -1
  229. package/dist/mcp/index.js +0 -30113
  230. package/dist/mcp/memory-broadcast.d.ts +0 -12
  231. package/dist/mcp/memory-broadcast.d.ts.map +0 -1
  232. package/dist/sdk/index.js +0 -397
  233. package/dist/server/index.d.ts +0 -7
  234. package/dist/server/index.d.ts.map +0 -1
  235. package/dist/server/index.js +0 -18221
  236. package/dist/types/hooks.d.ts +0 -136
  237. package/dist/types/hooks.d.ts.map +0 -1
  238. package/dist/types/index.d.ts +0 -345
  239. package/dist/types/index.d.ts.map +0 -1
package/dist/cli.js ADDED
@@ -0,0 +1,517 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // src/agent-setup.ts
5
+ import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
6
+ import { homedir } from "os";
7
+ import { dirname, join } from "path";
8
+ var SUPPORTED_AGENT_HOSTS = ["claude-code", "codex", "opencode", "antigravity"];
9
+ function buildAgentSetupPlan(options = {}) {
10
+ const home = options.homeDir ?? homedir();
11
+ const baseDir = join(home, ".config", "mementos", "agent-integrations");
12
+ const hosts = uniqueHosts(options.hosts ?? [...SUPPORTED_AGENT_HOSTS]);
13
+ const apiUrl = options.apiUrl ?? "https://mementos.md";
14
+ const mcpCommand = "mementos-mcp";
15
+ const hookCommand = "mementos hook stop";
16
+ const injectCommand = "mementos inject";
17
+ const files = [
18
+ {
19
+ path: join(baseDir, "mementos-injection.md"),
20
+ content: renderInjectionInstructions({ apiUrl, injectCommand })
21
+ },
22
+ {
23
+ path: join(baseDir, "mementos-stop-hook.sh"),
24
+ executable: true,
25
+ content: renderHookScript(hookCommand)
26
+ },
27
+ {
28
+ path: join(baseDir, "mcp-server.json"),
29
+ content: `${JSON.stringify(renderMcpServerConfig({ apiUrl, mcpCommand }), null, 2)}
30
+ `
31
+ }
32
+ ];
33
+ for (const host of hosts) {
34
+ files.push({
35
+ path: join(baseDir, `${host}.json`),
36
+ content: `${JSON.stringify(renderHostConfig(host, { apiUrl, hookCommand, injectCommand, mcpCommand }), null, 2)}
37
+ `
38
+ });
39
+ files.push({
40
+ path: hostManagedConfigPath(home, host),
41
+ content: `${JSON.stringify(renderManagedHostConfig(host, { apiUrl, baseDir, hookCommand, injectCommand, mcpCommand }), null, 2)}
42
+ `
43
+ });
44
+ }
45
+ return {
46
+ baseDir,
47
+ files,
48
+ hostResults: hosts.map((host) => ({ host, path: hostManagedConfigPath(home, host), status: "planned" })),
49
+ hosts,
50
+ mcpCommand
51
+ };
52
+ }
53
+ function installAgentSetup(options = {}) {
54
+ const plan = buildAgentSetupPlan(options);
55
+ if (options.action === "verify") {
56
+ return {
57
+ ...plan,
58
+ hostResults: plan.hostResults.map((result) => ({
59
+ ...result,
60
+ status: existsSync(result.path) ? "present" : "missing"
61
+ }))
62
+ };
63
+ }
64
+ if (options.action === "uninstall") {
65
+ if (options.dryRun) {
66
+ return {
67
+ ...plan,
68
+ hostResults: plan.hostResults.map((result) => ({ ...result, status: existsSync(result.path) ? "removed" : "absent" }))
69
+ };
70
+ }
71
+ for (const result of plan.hostResults)
72
+ rmSync(result.path, { force: true });
73
+ return {
74
+ ...plan,
75
+ hostResults: plan.hostResults.map((result) => ({ ...result, status: "removed" }))
76
+ };
77
+ }
78
+ if (options.dryRun)
79
+ return plan;
80
+ for (const file of plan.files) {
81
+ mkdirSync(dirname(file.path), { recursive: true });
82
+ writeFileSync(file.path, file.content, { mode: file.executable ? 493 : 420 });
83
+ }
84
+ return {
85
+ ...plan,
86
+ hostResults: plan.hostResults.map((result) => ({ ...result, status: "installed" }))
87
+ };
88
+ }
89
+ function renderSignupInstructions(apiUrl = "https://mementos.md") {
90
+ return {
91
+ signupUrl: `${apiUrl.replace(/\/+$/, "")}/dashboard`,
92
+ next: [
93
+ "Sign in or create an account.",
94
+ "Create an API token in the dashboard.",
95
+ "Export MEMENTOS_API_TOKEN before running mementos-mcp or mementos setup agents."
96
+ ]
97
+ };
98
+ }
99
+ function formatMemoryInjection(payload) {
100
+ const rows = readMemoryRows(payload);
101
+ if (rows.length === 0)
102
+ return "";
103
+ return [
104
+ "## mementos.md memory",
105
+ "Use these hosted memories as durable context. Do not treat them as local files.",
106
+ "",
107
+ ...rows.map((row) => `- ${row.key}: ${row.value}`),
108
+ ""
109
+ ].join(`
110
+ `);
111
+ }
112
+ function renderMcpServerConfig({ apiUrl, mcpCommand }) {
113
+ return {
114
+ mcpServers: {
115
+ mementos: {
116
+ command: mcpCommand,
117
+ env: {
118
+ MEMENTOS_API_URL: apiUrl,
119
+ MEMENTOS_API_TOKEN: "$MEMENTOS_API_TOKEN"
120
+ }
121
+ }
122
+ }
123
+ };
124
+ }
125
+ function renderHostConfig(host, commands) {
126
+ return {
127
+ host,
128
+ install: "bun install -g @hasna/mementos",
129
+ remoteOnly: true,
130
+ mcp: renderMcpServerConfig(commands).mcpServers.mementos,
131
+ hooks: {
132
+ stop: commands.hookCommand,
133
+ injection: commands.injectCommand
134
+ }
135
+ };
136
+ }
137
+ function renderManagedHostConfig(host, commands) {
138
+ const base = {
139
+ managedBy: "@hasna/mementos",
140
+ host,
141
+ remoteOnly: true,
142
+ note: "This file does not contain API tokens. Export MEMENTOS_API_TOKEN in your shell or secret manager.",
143
+ mcpServers: renderMcpServerConfig(commands).mcpServers,
144
+ commands: {
145
+ inject: commands.injectCommand,
146
+ stopHook: commands.hookCommand
147
+ },
148
+ files: {
149
+ integrationDir: commands.baseDir,
150
+ injectionInstructions: join(commands.baseDir, "mementos-injection.md"),
151
+ stopHook: join(commands.baseDir, "mementos-stop-hook.sh")
152
+ }
153
+ };
154
+ if (host === "claude-code") {
155
+ return {
156
+ ...base,
157
+ hooks: {
158
+ Stop: [{ hooks: [{ type: "command", command: commands.hookCommand }] }]
159
+ }
160
+ };
161
+ }
162
+ if (host === "codex") {
163
+ return {
164
+ ...base,
165
+ mcp_servers: {
166
+ mementos: {
167
+ command: commands.mcpCommand,
168
+ env: { MEMENTOS_API_URL: commands.apiUrl, MEMENTOS_API_TOKEN: "$MEMENTOS_API_TOKEN" }
169
+ }
170
+ }
171
+ };
172
+ }
173
+ return base;
174
+ }
175
+ function hostManagedConfigPath(home, host) {
176
+ switch (host) {
177
+ case "claude-code":
178
+ return join(home, ".claude", "mementos.managed.json");
179
+ case "codex":
180
+ return join(home, ".codex", "mementos.managed.json");
181
+ case "opencode":
182
+ return join(home, ".config", "opencode", "mementos.managed.json");
183
+ case "antigravity":
184
+ return join(home, ".config", "antigravity", "mementos.managed.json");
185
+ }
186
+ }
187
+ function renderInjectionInstructions({ apiUrl, injectCommand }) {
188
+ return `# mementos.md Memory Injection
189
+
190
+ Run this before or after an agent turn when it needs durable project context:
191
+
192
+ \`\`\`bash
193
+ MEMENTOS_API_URL=${apiUrl} MEMENTOS_API_TOKEN=$MEMENTOS_API_TOKEN ${injectCommand} "$MEMENTOS_INJECTION_QUERY"
194
+ \`\`\`
195
+
196
+ This command reads hosted memory through the mementos.md API and prints a prompt-ready block.
197
+ `;
198
+ }
199
+ function renderHookScript(command) {
200
+ return `#!/usr/bin/env bash
201
+ set -euo pipefail
202
+
203
+ ${command}
204
+ `;
205
+ }
206
+ function uniqueHosts(hosts) {
207
+ const allowed = new Set(SUPPORTED_AGENT_HOSTS);
208
+ return [...new Set(hosts)].filter((host) => allowed.has(host));
209
+ }
210
+ function readMemoryRows(payload) {
211
+ if (typeof payload !== "object" || payload === null)
212
+ return [];
213
+ const maybeRows = "memories" in payload ? payload.memories : payload;
214
+ if (!Array.isArray(maybeRows))
215
+ return [];
216
+ return maybeRows.flatMap((row) => {
217
+ if (typeof row !== "object" || row === null)
218
+ return [];
219
+ const key = readText(row.key);
220
+ const value = readText(row.value ?? row.content);
221
+ return key && value ? [{ key, value }] : [];
222
+ });
223
+ }
224
+ function readText(input) {
225
+ return typeof input === "string" && input.trim() ? input.trim() : undefined;
226
+ }
227
+
228
+ // src/remote-client.ts
229
+ var DEFAULT_API_URL = "https://mementos.md/api/v1";
230
+
231
+ class MementosRemoteError extends Error {
232
+ status;
233
+ response;
234
+ constructor(message, status, response) {
235
+ super(message);
236
+ this.name = "MementosRemoteError";
237
+ this.status = status;
238
+ this.response = response;
239
+ }
240
+ }
241
+
242
+ class MementosRemoteClient {
243
+ apiUrl;
244
+ token;
245
+ fetchImpl;
246
+ constructor(config = {}) {
247
+ this.apiUrl = normalizeApiUrl(config.apiUrl ?? DEFAULT_API_URL);
248
+ this.token = config.token;
249
+ this.fetchImpl = config.fetch ?? fetch;
250
+ }
251
+ listCapabilities() {
252
+ return this.request("/capabilities", { requiresAuth: false });
253
+ }
254
+ listAgents() {
255
+ return this.request("/agents");
256
+ }
257
+ registerAgent(input) {
258
+ return this.request("/agents/register", { method: "POST", body: input });
259
+ }
260
+ heartbeatAgent(input) {
261
+ return this.request("/agents/heartbeat", { method: "POST", body: input });
262
+ }
263
+ saveMemory(input) {
264
+ return this.request("/memories", { method: "POST", body: input });
265
+ }
266
+ searchMemories(input = {}) {
267
+ return this.request("/memories", { query: input });
268
+ }
269
+ injectionContext(input = {}) {
270
+ return this.request("/injections/context", { method: "POST", body: input });
271
+ }
272
+ getMemory(id) {
273
+ return this.request(`/memories/${encodeURIComponent(id)}`);
274
+ }
275
+ updateMemory(id, input) {
276
+ return this.request(`/memories/${encodeURIComponent(id)}`, { method: "PATCH", body: input });
277
+ }
278
+ deleteMemory(id) {
279
+ return this.request(`/memories/${encodeURIComponent(id)}`, { method: "DELETE" });
280
+ }
281
+ memoryUsage() {
282
+ return this.request("/usage");
283
+ }
284
+ listRuns(input = {}) {
285
+ return this.request("/runs", { query: input });
286
+ }
287
+ createRun(slug, input = {}) {
288
+ return this.request(`/runs/${encodeURIComponent(slug)}`, { method: "POST", body: input });
289
+ }
290
+ getRun(id) {
291
+ return this.request(`/runs/${encodeURIComponent(id)}`);
292
+ }
293
+ listApprovals() {
294
+ return this.request("/approvals");
295
+ }
296
+ billingStatus() {
297
+ return this.request("/billing/status");
298
+ }
299
+ async request(path, options = {}) {
300
+ const method = options.method ?? "GET";
301
+ const requiresAuth = options.requiresAuth !== false;
302
+ if (requiresAuth && !this.token) {
303
+ throw new MementosRemoteError("MEMENTOS_API_TOKEN is required for hosted mementos.md requests", 401, null);
304
+ }
305
+ const url = new URL(`${this.apiUrl}${path.startsWith("/") ? path : `/${path}`}`);
306
+ for (const [key, value] of Object.entries(options.query ?? {})) {
307
+ if (value === undefined || value === null || value === "")
308
+ continue;
309
+ url.searchParams.set(key, String(value));
310
+ }
311
+ const headers = new Headers({ accept: "application/json" });
312
+ if (requiresAuth)
313
+ headers.set("authorization", `Bearer ${this.token}`);
314
+ if (options.body !== undefined)
315
+ headers.set("content-type", "application/json");
316
+ const response = await this.fetchImpl(url, {
317
+ method,
318
+ headers,
319
+ body: options.body === undefined ? undefined : JSON.stringify(options.body)
320
+ });
321
+ const payload = await readPayload(response);
322
+ if (!response.ok) {
323
+ throw new MementosRemoteError(readErrorMessage(payload, response.status), response.status, payload);
324
+ }
325
+ return payload;
326
+ }
327
+ }
328
+ function createRemoteClientFromEnv(env = process.env) {
329
+ return new MementosRemoteClient({
330
+ apiUrl: env.MEMENTOS_API_URL,
331
+ token: env.MEMENTOS_API_TOKEN ?? env.MEMENTOS_PLATFORM_TOKEN ?? env.PLATFORM_API_TOKEN ?? env.APP_API_KEY
332
+ });
333
+ }
334
+ function normalizeApiUrl(input) {
335
+ const trimmed = input.trim().replace(/\/+$/, "");
336
+ if (!trimmed)
337
+ return DEFAULT_API_URL;
338
+ return trimmed.endsWith("/api/v1") ? trimmed : `${trimmed}/api/v1`;
339
+ }
340
+ async function readPayload(response) {
341
+ const text = await response.text();
342
+ if (!text)
343
+ return null;
344
+ try {
345
+ return JSON.parse(text);
346
+ } catch {
347
+ return text;
348
+ }
349
+ }
350
+ function readErrorMessage(payload, status) {
351
+ if (typeof payload === "object" && payload !== null && "error" in payload) {
352
+ const value = payload.error;
353
+ if (typeof value === "string" && value.trim())
354
+ return value;
355
+ }
356
+ return `mementos.md request failed with status ${status}`;
357
+ }
358
+
359
+ // src/cli.ts
360
+ var command = process.argv[2] ?? "help";
361
+ var client = createRemoteClientFromEnv();
362
+ try {
363
+ const result = await run(command, process.argv.slice(3));
364
+ if (result !== undefined) {
365
+ process.stdout.write(`${JSON.stringify(result, null, 2)}
366
+ `);
367
+ }
368
+ } catch (error) {
369
+ if (error instanceof MementosRemoteError) {
370
+ process.stderr.write(`${error.message}
371
+ `);
372
+ process.exit(error.status === 401 || error.status === 403 ? 2 : 1);
373
+ }
374
+ process.stderr.write(`${error.message}
375
+ `);
376
+ process.exit(1);
377
+ }
378
+ async function run(name, args) {
379
+ switch (name) {
380
+ case "help":
381
+ case "--help":
382
+ case "-h":
383
+ process.stdout.write(helpText());
384
+ return;
385
+ case "auth":
386
+ return runAuth(args);
387
+ case "setup":
388
+ return runSetup(args);
389
+ case "inject":
390
+ return injectMemory(args);
391
+ case "hook":
392
+ return runHook(args);
393
+ case "capabilities":
394
+ return client.listCapabilities();
395
+ case "agents":
396
+ return client.listAgents();
397
+ case "usage":
398
+ return client.memoryUsage();
399
+ case "search":
400
+ return client.searchMemories({ q: args.join(" ").trim() });
401
+ case "save": {
402
+ const key = args[0];
403
+ const value = args.slice(1).join(" ");
404
+ if (!key || !value)
405
+ throw new Error("usage: mementos save <key> <value>");
406
+ return client.saveMemory({ key, value });
407
+ }
408
+ default:
409
+ throw new Error(`Unknown command: ${name}
410
+
411
+ ${helpText()}`);
412
+ }
413
+ }
414
+ async function runAuth(args) {
415
+ const subcommand = args[0] ?? "help";
416
+ if (subcommand !== "signup" && subcommand !== "login") {
417
+ throw new Error("usage: mementos auth signup");
418
+ }
419
+ return renderSignupInstructions(baseProductUrl());
420
+ }
421
+ async function runSetup(args) {
422
+ const subcommand = args[0] ?? "help";
423
+ if (subcommand !== "agents") {
424
+ throw new Error("usage: mementos setup agents [--dry-run] [--home <path>] [--hosts <list>]");
425
+ }
426
+ const options = parseSetupOptions(args.slice(1));
427
+ const plan = installAgentSetup({
428
+ action: options.action,
429
+ apiUrl: baseProductUrl(),
430
+ dryRun: options.dryRun,
431
+ homeDir: options.homeDir,
432
+ hosts: options.hosts
433
+ });
434
+ return {
435
+ installed: !options.dryRun,
436
+ action: options.action ?? "install",
437
+ baseDir: plan.baseDir,
438
+ hosts: plan.hosts,
439
+ files: plan.files.map((file) => file.path),
440
+ hostResults: plan.hostResults,
441
+ mcpCommand: plan.mcpCommand
442
+ };
443
+ }
444
+ async function injectMemory(args) {
445
+ const query = args.filter((arg) => !arg.startsWith("--")).join(" ").trim();
446
+ const payload = await client.injectionContext({ query, limit: 12 });
447
+ const block = readTextPayload(payload) ?? formatMemoryInjection(payload);
448
+ if (block) {
449
+ process.stdout.write(block);
450
+ return;
451
+ }
452
+ return { memories: 0 };
453
+ }
454
+ async function runHook(args) {
455
+ const subcommand = args[0] ?? "help";
456
+ if (subcommand !== "stop") {
457
+ throw new Error("usage: mementos hook stop");
458
+ }
459
+ const query = process.env.MEMENTOS_INJECTION_QUERY ?? process.cwd();
460
+ return injectMemory([query]);
461
+ }
462
+ function parseSetupOptions(args) {
463
+ const options = {};
464
+ for (let index = 0;index < args.length; index += 1) {
465
+ const arg = args[index];
466
+ if (arg === "--dry-run") {
467
+ options.dryRun = true;
468
+ } else if (arg === "--verify") {
469
+ options.action = "verify";
470
+ } else if (arg === "--uninstall") {
471
+ options.action = "uninstall";
472
+ } else if (arg === "--home") {
473
+ options.homeDir = args[++index];
474
+ } else if (arg === "--hosts") {
475
+ options.hosts = parseHosts(args[++index] ?? "");
476
+ } else {
477
+ throw new Error(`Unknown setup option: ${arg}`);
478
+ }
479
+ }
480
+ return options;
481
+ }
482
+ function parseHosts(input) {
483
+ const requested = input.split(",").map((host) => host.trim()).filter(Boolean);
484
+ const unknown = requested.filter((host) => !SUPPORTED_AGENT_HOSTS.includes(host));
485
+ if (unknown.length > 0)
486
+ throw new Error(`Unknown agent host: ${unknown.join(", ")}`);
487
+ return requested;
488
+ }
489
+ function baseProductUrl() {
490
+ return (process.env.MEMENTOS_API_URL ?? DEFAULT_API_URL).replace(/\/api\/v1\/?$/, "").replace(/\/+$/, "");
491
+ }
492
+ function readTextPayload(payload) {
493
+ if (typeof payload !== "object" || payload === null)
494
+ return;
495
+ const text = payload.text;
496
+ return typeof text === "string" && text.trim() ? text : undefined;
497
+ }
498
+ function helpText() {
499
+ return `mementos remote-only SaaS client
500
+
501
+ Usage:
502
+ mementos auth signup
503
+ mementos setup agents [--dry-run|--verify|--uninstall]
504
+ mementos inject <query>
505
+ mementos hook stop
506
+ mementos capabilities
507
+ mementos agents
508
+ mementos usage
509
+ mementos search <query>
510
+ mementos save <key> <value>
511
+ MEMENTOS_API_TOKEN=<token> mementos-mcp
512
+
513
+ Environment:
514
+ MEMENTOS_API_URL Defaults to https://mementos.md/api/v1
515
+ MEMENTOS_API_TOKEN Required for hosted private operations
516
+ `;
517
+ }
package/dist/index.d.ts CHANGED
@@ -1,28 +1,4 @@
1
- export type { Memory, MemoryWithRelations, MemoryScope, MemoryCategory, MemorySource, MemoryStatus, MemoryFilter, MemorySearchResult, MemoryStats, CreateMemoryInput, UpdateMemoryInput, DedupeMode, Agent, Project, MementosConfig, SyncDirection, SyncOptions, SyncResult, ConflictResolution, Entity, Relation, EntityMemory, EntityType, RelationType, EntityRole, EntityWithRelations, CreateEntityInput, UpdateEntityInput, CreateRelationInput, } from "./types/index.js";
2
- export { MemoryNotFoundError, DuplicateMemoryError, MemoryExpiredError, InvalidScopeError, VersionConflictError, EntityNotFoundError, } from "./types/index.js";
3
- export { getDatabase, closeDatabase, resetDatabase, getDbPath, resolvePartialId, now, uuid, shortUuid, } from "./db/database.js";
4
- export { createMemory, getMemory, getMemoryByKey, getMemoriesByKey, listMemories, updateMemory, deleteMemory, bulkDeleteMemories, touchMemory, cleanExpiredMemories, getMemoryVersions, } from "./db/memories.js";
5
- export { registerAgent, getAgent, listAgents, listAgentsByProject, updateAgent, touchAgent, } from "./db/agents.js";
6
- export { acquireLock, releaseLock, releaseResourceLocks, releaseAllAgentLocks, checkLock, agentHoldsLock, listAgentLocks, cleanExpiredLocks, } from "./db/locks.js";
7
- export type { ResourceLock, ResourceType, LockType } from "./db/locks.js";
8
- export { acquireMemoryWriteLock, releaseMemoryWriteLock, checkMemoryWriteLock, withMemoryLock, MemoryLockConflictError, memoryLockId, } from "./lib/memory-lock.js";
9
- export { setFocus, getFocus, unfocus, resolveProjectId, buildFocusFilter, focusFilterSQL, } from "./lib/focus.js";
10
- export { registerProject, getProject, listProjects, } from "./db/projects.js";
11
- export { searchMemories } from "./lib/search.js";
12
- export { loadConfig, DEFAULT_CONFIG, getActiveProfile, setActiveProfile, listProfiles, deleteProfile, } from "./lib/config.js";
13
- export { MemoryInjector } from "./lib/injector.js";
14
- export type { InjectionOptions, InjectionStrategy } from "./lib/injector.js";
15
- export { enforceQuotas, archiveStale, archiveUnused, deprioritizeStale, runCleanup } from "./lib/retention.js";
16
- export { syncMemories, defaultSyncAgents } from "./lib/sync.js";
17
- export { redactSecrets, containsSecrets } from "./lib/redact.js";
18
- export { createEntity, getEntity, getEntityByName, listEntities, updateEntity, deleteEntity, mergeEntities, parseEntityRow, } from "./db/entities.js";
19
- export { createRelation, getRelation, listRelations, deleteRelation, getRelatedEntities, getEntityGraph, findPath, parseRelationRow, } from "./db/relations.js";
20
- export { linkEntityToMemory, unlinkEntityFromMemory, getMemoriesForEntity, getEntitiesForMemory, bulkLinkEntities, getEntityMemoryLinks, } from "./db/entity-memories.js";
21
- export { processConversationTurn, getAutoMemoryStats, configureAutoMemory, } from "./lib/auto-memory.js";
22
- export type { LLMProvider, ExtractedMemory, ExtractedEntity, EntityExtractionResult, AutoMemoryConfig, ProviderName, ProviderConfig, } from "./lib/providers/base.js";
23
- export { providerRegistry } from "./lib/providers/registry.js";
24
- export { dedup, getDedupStats } from "./lib/dedup.js";
25
- export { incrementRecallCount } from "./db/memories.js";
26
- export { gatherTrainingData } from "./lib/gatherer.js";
27
- export { getActiveModel, setActiveModel, clearActiveModel, DEFAULT_MODEL, } from "./lib/model-config.js";
1
+ export { DEFAULT_API_URL, MementosRemoteClient, MementosRemoteError, createRemoteClientFromEnv, normalizeApiUrl, type RemoteClientConfig, type RemoteRequestOptions, } from "./remote-client";
2
+ export { REMOTE_MCP_TOOLS, callRemoteMcpTool, handleMcpMessage, startMcpStdio, type RemoteMcpTool, } from "./mcp-runtime";
3
+ export { SUPPORTED_AGENT_HOSTS, buildAgentSetupPlan, formatMemoryInjection, installAgentSetup, renderSignupInstructions, type AgentSetupFile, type AgentSetupOptions, type AgentSetupPlan, type SupportedAgentHost, } from "./agent-setup";
28
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,MAAM,EACN,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,KAAK,EACL,OAAO,EACP,cAAc,EACd,aAAa,EACb,WAAW,EACX,UAAU,EACV,kBAAkB,EAElB,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,UAAU,EACV,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,WAAW,EACX,aAAa,EACb,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,GAAG,EACH,IAAI,E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OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,wBAAwB,EACxB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC"}