@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.
- package/LICENSE +3 -189
- package/README.md +15 -27
- package/dist/agent-setup.d.ts +34 -0
- package/dist/agent-setup.d.ts.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +517 -0
- package/dist/index.d.ts +3 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +455 -14652
- package/dist/mcp-runtime.d.ts +23 -0
- package/dist/mcp-runtime.d.ts.map +1 -0
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +300 -0
- package/dist/remote-client.d.ts +44 -0
- package/dist/remote-client.d.ts.map +1 -0
- package/package.json +13 -53
- package/dashboard/dist/assets/index-DqyMbv89.js +0 -270
- package/dashboard/dist/assets/index-UBCddFo_.css +0 -1
- package/dashboard/dist/index.html +0 -13
- package/dist/cli/brains.d.ts +0 -3
- package/dist/cli/brains.d.ts.map +0 -1
- package/dist/cli/index.d.ts +0 -3
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js +0 -25738
- package/dist/db/acl.d.ts +0 -34
- package/dist/db/acl.d.ts.map +0 -1
- package/dist/db/agents.d.ts +0 -15
- package/dist/db/agents.d.ts.map +0 -1
- package/dist/db/audit.d.ts +0 -39
- package/dist/db/audit.d.ts.map +0 -1
- package/dist/db/database.d.ts +0 -10
- package/dist/db/database.d.ts.map +0 -1
- package/dist/db/entities.d.ts +0 -62
- package/dist/db/entities.d.ts.map +0 -1
- package/dist/db/entity-memories.d.ts +0 -34
- package/dist/db/entity-memories.d.ts.map +0 -1
- package/dist/db/locks.d.ts +0 -63
- package/dist/db/locks.d.ts.map +0 -1
- package/dist/db/machines.d.ts +0 -16
- package/dist/db/machines.d.ts.map +0 -1
- package/dist/db/memories.d.ts +0 -40
- package/dist/db/memories.d.ts.map +0 -1
- package/dist/db/pg-migrations.d.ts +0 -8
- package/dist/db/pg-migrations.d.ts.map +0 -1
- package/dist/db/projects.d.ts +0 -6
- package/dist/db/projects.d.ts.map +0 -1
- package/dist/db/ratings.d.ts +0 -23
- package/dist/db/ratings.d.ts.map +0 -1
- package/dist/db/relations.d.ts +0 -29
- package/dist/db/relations.d.ts.map +0 -1
- package/dist/db/session-jobs.d.ts +0 -49
- package/dist/db/session-jobs.d.ts.map +0 -1
- package/dist/db/synthesis.d.ts +0 -101
- package/dist/db/synthesis.d.ts.map +0 -1
- package/dist/db/tool-events.d.ts +0 -27
- package/dist/db/tool-events.d.ts.map +0 -1
- package/dist/db/webhook_hooks.d.ts +0 -25
- package/dist/db/webhook_hooks.d.ts.map +0 -1
- package/dist/lib/activation-matcher.d.ts +0 -16
- package/dist/lib/activation-matcher.d.ts.map +0 -1
- package/dist/lib/asmr/categorizer.d.ts +0 -31
- package/dist/lib/asmr/categorizer.d.ts.map +0 -1
- package/dist/lib/asmr/context-agent.d.ts +0 -4
- package/dist/lib/asmr/context-agent.d.ts.map +0 -1
- package/dist/lib/asmr/ensemble.d.ts +0 -23
- package/dist/lib/asmr/ensemble.d.ts.map +0 -1
- package/dist/lib/asmr/fact-agent.d.ts +0 -4
- package/dist/lib/asmr/fact-agent.d.ts.map +0 -1
- package/dist/lib/asmr/index.d.ts +0 -7
- package/dist/lib/asmr/index.d.ts.map +0 -1
- package/dist/lib/asmr/orchestrator.d.ts +0 -4
- package/dist/lib/asmr/orchestrator.d.ts.map +0 -1
- package/dist/lib/asmr/temporal-agent.d.ts +0 -4
- package/dist/lib/asmr/temporal-agent.d.ts.map +0 -1
- package/dist/lib/asmr/types.d.ts +0 -27
- package/dist/lib/asmr/types.d.ts.map +0 -1
- package/dist/lib/auto-inject-orchestrator.d.ts +0 -57
- package/dist/lib/auto-inject-orchestrator.d.ts.map +0 -1
- package/dist/lib/auto-memory-queue.d.ts +0 -46
- package/dist/lib/auto-memory-queue.d.ts.map +0 -1
- package/dist/lib/auto-memory.d.ts +0 -18
- package/dist/lib/auto-memory.d.ts.map +0 -1
- package/dist/lib/bench.d.ts +0 -20
- package/dist/lib/bench.d.ts.map +0 -1
- package/dist/lib/built-in-hooks.d.ts +0 -12
- package/dist/lib/built-in-hooks.d.ts.map +0 -1
- package/dist/lib/channel-pusher.d.ts +0 -39
- package/dist/lib/channel-pusher.d.ts.map +0 -1
- package/dist/lib/config.d.ts +0 -9
- package/dist/lib/config.d.ts.map +0 -1
- package/dist/lib/connectors/files.d.ts +0 -8
- package/dist/lib/connectors/files.d.ts.map +0 -1
- package/dist/lib/connectors/github.d.ts +0 -7
- package/dist/lib/connectors/github.d.ts.map +0 -1
- package/dist/lib/connectors/index.d.ts +0 -12
- package/dist/lib/connectors/index.d.ts.map +0 -1
- package/dist/lib/connectors/notion.d.ts +0 -7
- package/dist/lib/connectors/notion.d.ts.map +0 -1
- package/dist/lib/connectors/types.d.ts +0 -27
- package/dist/lib/connectors/types.d.ts.map +0 -1
- package/dist/lib/context-extractor.d.ts +0 -14
- package/dist/lib/context-extractor.d.ts.map +0 -1
- package/dist/lib/context.d.ts +0 -35
- package/dist/lib/context.d.ts.map +0 -1
- package/dist/lib/contradiction.d.ts +0 -50
- package/dist/lib/contradiction.d.ts.map +0 -1
- package/dist/lib/decay.d.ts +0 -35
- package/dist/lib/decay.d.ts.map +0 -1
- package/dist/lib/dedup.d.ts +0 -33
- package/dist/lib/dedup.d.ts.map +0 -1
- package/dist/lib/duration.d.ts +0 -28
- package/dist/lib/duration.d.ts.map +0 -1
- package/dist/lib/embeddings.d.ts +0 -20
- package/dist/lib/embeddings.d.ts.map +0 -1
- package/dist/lib/export-v1.d.ts +0 -30
- package/dist/lib/export-v1.d.ts.map +0 -1
- package/dist/lib/extractor.d.ts +0 -9
- package/dist/lib/extractor.d.ts.map +0 -1
- package/dist/lib/extractors/audio.d.ts +0 -8
- package/dist/lib/extractors/audio.d.ts.map +0 -1
- package/dist/lib/extractors/index.d.ts +0 -12
- package/dist/lib/extractors/index.d.ts.map +0 -1
- package/dist/lib/extractors/ocr.d.ts +0 -7
- package/dist/lib/extractors/ocr.d.ts.map +0 -1
- package/dist/lib/extractors/pdf.d.ts +0 -7
- package/dist/lib/extractors/pdf.d.ts.map +0 -1
- package/dist/lib/extractors/types.d.ts +0 -12
- package/dist/lib/extractors/types.d.ts.map +0 -1
- package/dist/lib/file-deps.d.ts +0 -27
- package/dist/lib/file-deps.d.ts.map +0 -1
- package/dist/lib/focus.d.ts +0 -58
- package/dist/lib/focus.d.ts.map +0 -1
- package/dist/lib/gatherer.d.ts +0 -16
- package/dist/lib/gatherer.d.ts.map +0 -1
- package/dist/lib/gdpr.d.ts +0 -24
- package/dist/lib/gdpr.d.ts.map +0 -1
- package/dist/lib/hooks.d.ts +0 -50
- package/dist/lib/hooks.d.ts.map +0 -1
- package/dist/lib/importers/index.d.ts +0 -38
- package/dist/lib/importers/index.d.ts.map +0 -1
- package/dist/lib/injector.d.ts +0 -86
- package/dist/lib/injector.d.ts.map +0 -1
- package/dist/lib/matryoshka.d.ts +0 -50
- package/dist/lib/matryoshka.d.ts.map +0 -1
- package/dist/lib/memory-lock.d.ts +0 -58
- package/dist/lib/memory-lock.d.ts.map +0 -1
- package/dist/lib/model-config.d.ts +0 -14
- package/dist/lib/model-config.d.ts.map +0 -1
- package/dist/lib/open-sessions-connector.d.ts +0 -60
- package/dist/lib/open-sessions-connector.d.ts.map +0 -1
- package/dist/lib/poisoning.d.ts +0 -19
- package/dist/lib/poisoning.d.ts.map +0 -1
- package/dist/lib/poll.d.ts +0 -17
- package/dist/lib/poll.d.ts.map +0 -1
- package/dist/lib/procedural-extractor.d.ts +0 -21
- package/dist/lib/procedural-extractor.d.ts.map +0 -1
- package/dist/lib/profile-sync.d.ts +0 -20
- package/dist/lib/profile-sync.d.ts.map +0 -1
- package/dist/lib/profile-synthesizer.d.ts +0 -20
- package/dist/lib/profile-synthesizer.d.ts.map +0 -1
- package/dist/lib/project-detect.d.ts +0 -18
- package/dist/lib/project-detect.d.ts.map +0 -1
- package/dist/lib/providers/anthropic.d.ts +0 -21
- package/dist/lib/providers/anthropic.d.ts.map +0 -1
- package/dist/lib/providers/base.d.ts +0 -96
- package/dist/lib/providers/base.d.ts.map +0 -1
- package/dist/lib/providers/cerebras.d.ts +0 -20
- package/dist/lib/providers/cerebras.d.ts.map +0 -1
- package/dist/lib/providers/grok.d.ts +0 -19
- package/dist/lib/providers/grok.d.ts.map +0 -1
- package/dist/lib/providers/index.d.ts +0 -7
- package/dist/lib/providers/index.d.ts.map +0 -1
- package/dist/lib/providers/openai-compat.d.ts +0 -18
- package/dist/lib/providers/openai-compat.d.ts.map +0 -1
- package/dist/lib/providers/openai.d.ts +0 -20
- package/dist/lib/providers/openai.d.ts.map +0 -1
- package/dist/lib/providers/registry.d.ts +0 -38
- package/dist/lib/providers/registry.d.ts.map +0 -1
- package/dist/lib/quality.d.ts +0 -16
- package/dist/lib/quality.d.ts.map +0 -1
- package/dist/lib/redact.d.ts +0 -10
- package/dist/lib/redact.d.ts.map +0 -1
- package/dist/lib/remote-sync.d.ts +0 -49
- package/dist/lib/remote-sync.d.ts.map +0 -1
- package/dist/lib/retention.d.ts +0 -17
- package/dist/lib/retention.d.ts.map +0 -1
- package/dist/lib/search.d.ts +0 -52
- package/dist/lib/search.d.ts.map +0 -1
- package/dist/lib/session-auto-resolve.d.ts +0 -28
- package/dist/lib/session-auto-resolve.d.ts.map +0 -1
- package/dist/lib/session-processor.d.ts +0 -38
- package/dist/lib/session-processor.d.ts.map +0 -1
- package/dist/lib/session-queue.d.ts +0 -28
- package/dist/lib/session-queue.d.ts.map +0 -1
- package/dist/lib/session-registry.d.ts +0 -47
- package/dist/lib/session-registry.d.ts.map +0 -1
- package/dist/lib/session-start-briefing.d.ts +0 -10
- package/dist/lib/session-start-briefing.d.ts.map +0 -1
- package/dist/lib/session-watcher.d.ts +0 -30
- package/dist/lib/session-watcher.d.ts.map +0 -1
- package/dist/lib/sync.d.ts +0 -10
- package/dist/lib/sync.d.ts.map +0 -1
- package/dist/lib/synthesis/corpus-builder.d.ts +0 -30
- package/dist/lib/synthesis/corpus-builder.d.ts.map +0 -1
- package/dist/lib/synthesis/executor.d.ts +0 -14
- package/dist/lib/synthesis/executor.d.ts.map +0 -1
- package/dist/lib/synthesis/index.d.ts +0 -37
- package/dist/lib/synthesis/index.d.ts.map +0 -1
- package/dist/lib/synthesis/llm-analyzer.d.ts +0 -18
- package/dist/lib/synthesis/llm-analyzer.d.ts.map +0 -1
- package/dist/lib/synthesis/metrics.d.ts +0 -13
- package/dist/lib/synthesis/metrics.d.ts.map +0 -1
- package/dist/lib/synthesis/scheduler.d.ts +0 -18
- package/dist/lib/synthesis/scheduler.d.ts.map +0 -1
- package/dist/lib/synthesis/validator.d.ts +0 -19
- package/dist/lib/synthesis/validator.d.ts.map +0 -1
- package/dist/lib/tool-lesson-extractor.d.ts +0 -24
- package/dist/lib/tool-lesson-extractor.d.ts.map +0 -1
- package/dist/lib/tool-memory-synthesizer.d.ts +0 -28
- package/dist/lib/tool-memory-synthesizer.d.ts.map +0 -1
- package/dist/lib/topic-clusterer.d.ts +0 -21
- package/dist/lib/topic-clusterer.d.ts.map +0 -1
- package/dist/lib/when-to-use-generator.d.ts +0 -22
- package/dist/lib/when-to-use-generator.d.ts.map +0 -1
- package/dist/mcp/index.d.ts +0 -5
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/index.js +0 -30113
- package/dist/mcp/memory-broadcast.d.ts +0 -12
- package/dist/mcp/memory-broadcast.d.ts.map +0 -1
- package/dist/sdk/index.js +0 -397
- package/dist/server/index.d.ts +0 -7
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js +0 -18221
- package/dist/types/hooks.d.ts +0 -136
- package/dist/types/hooks.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -345
- 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
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,eAAe,EACf,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,GAC1B,MAAM,iBAAiB,CAAC;AACzB,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"}
|