@echomem/mcp 1.4.71 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -6
- package/dist/agent-messages-fallback.js +45 -0
- package/dist/backend-network-guard.js +48 -0
- package/dist/backend-policy.js +46 -0
- package/dist/claude-evidence.js +91 -0
- package/dist/codex-sync.js +2 -1
- package/dist/cowork-source.js +140 -0
- package/dist/desktop-presence.js +40 -0
- package/dist/desktop-save-activity.js +128 -0
- package/dist/durable-entry.js +20 -5
- package/dist/headless-runtime.js +4 -0
- package/dist/hud/cli.js +16 -17
- package/dist/hud/diagnostics.js +2 -1
- package/dist/hud/hooks.js +97 -62
- package/dist/hud/server.js +2 -1
- package/dist/index.js +727 -170
- package/dist/lifecycle-entry.js +29 -0
- package/dist/local-data-paths.js +15 -1
- package/dist/local-usage.js +72 -0
- package/dist/memory-intent.js +150 -0
- package/dist/memory-links.js +6 -0
- package/dist/migrate.js +2 -1
- package/dist/package-metadata.js +7 -7
- package/dist/pending-save.js +49 -0
- package/dist/save-local-trace.js +26 -0
- package/dist/save-note-store.js +50 -0
- package/dist/save-receipt-store.js +58 -0
- package/dist/save-receipt.js +42 -0
- package/dist/save-retry.js +43 -0
- package/dist/setup-page/client-extraction.js +2 -1
- package/dist/setup.js +13 -13
- package/dist/source-session-hook.js +16 -2
- package/dist/source-session-local.js +241 -0
- package/dist/source-session-pretool-hook.js +54 -0
- package/dist/source-session.js +4 -0
- package/dist/source-snapshot-export.js +68 -0
- package/dist/source-snapshot.js +99 -0
- package/dist/strict-ingest-contract.js +31 -0
- package/dist/strict-raw-session.js +473 -0
- package/dist/tool-map-cache.js +62 -0
- package/dist/turn-end-saves.js +104 -0
- package/dist/v1-contract.js +92 -45
- package/package.json +5 -3
- package/templates/codex-skills/echomem-save/SKILL.md +26 -27
- package/templates/echomem-recall.md +27 -21
- package/dist/save-checkpoint-hook.js +0 -122
package/dist/durable-entry.js
CHANGED
|
@@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { ensureHudLauncher, installHeadlessRuntimeSync, readHeadlessRuntimeInstallation } from "./headless-runtime.js";
|
|
5
|
+
import { ensureHudLauncher, ensureLifecycleLauncher, installHeadlessRuntimeSync, readHeadlessRuntimeInstallation } from "./headless-runtime.js";
|
|
6
6
|
import { MCP_PACKAGE_NAME, MCP_PACKAGE_VERSION } from "./package-metadata.js";
|
|
7
7
|
/**
|
|
8
8
|
* Resolving a DURABLE path to this package's own files.
|
|
@@ -52,14 +52,29 @@ function runningDistDir() {
|
|
|
52
52
|
* caller should say so rather than fail silently.
|
|
53
53
|
*/
|
|
54
54
|
export function resolveDurableDistPath(relative) {
|
|
55
|
+
const local = path.join(runningDistDir(), relative);
|
|
56
|
+
const localIsEphemeral = isEphemeralNpxPath(local);
|
|
57
|
+
// Desktop explicitly owns this runtime. A separate ~/.echomem installation
|
|
58
|
+
// must not redirect its completion hooks to another version of the bridge.
|
|
59
|
+
const marker = `${path.sep}Echo${path.sep}MCP${path.sep}`;
|
|
60
|
+
if ((process.env.ECHO_DESKTOP_MANAGED === "1" || local.includes(marker)) && !localIsEphemeral && fs.existsSync(local)) {
|
|
61
|
+
const at = local.indexOf(marker);
|
|
62
|
+
if (at >= 0) {
|
|
63
|
+
const current = path.join(local.slice(0, at + marker.length), "current", "dist", relative);
|
|
64
|
+
try {
|
|
65
|
+
if (fs.realpathSync(current) === fs.realpathSync(local))
|
|
66
|
+
return { path: current, ephemeral: false };
|
|
67
|
+
}
|
|
68
|
+
catch { /* An explicitly invoked older installation remains pinned to itself. */ }
|
|
69
|
+
}
|
|
70
|
+
return { path: local, ephemeral: false };
|
|
71
|
+
}
|
|
55
72
|
const managed = readHeadlessRuntimeInstallation();
|
|
56
73
|
if (managed?.entry) {
|
|
57
74
|
const candidate = path.join(path.dirname(managed.entry), relative);
|
|
58
75
|
if (fs.existsSync(candidate))
|
|
59
76
|
return { path: candidate, ephemeral: false };
|
|
60
77
|
}
|
|
61
|
-
const local = path.join(runningDistDir(), relative);
|
|
62
|
-
const localIsEphemeral = isEphemeralNpxPath(local);
|
|
63
78
|
if (!localIsEphemeral && fs.existsSync(local))
|
|
64
79
|
return { path: local, ephemeral: false };
|
|
65
80
|
const globalEntry = resolveGlobalEntry();
|
|
@@ -105,12 +120,12 @@ export function desktopCurrentPaths(distDir = runningDistDir(), execPath = proce
|
|
|
105
120
|
export function stableHudCommandTarget() {
|
|
106
121
|
const desktop = desktopCurrentPaths();
|
|
107
122
|
if (desktop)
|
|
108
|
-
return { node: desktop.node, cli: path.join(desktop.dist, "hud", "cli.js") };
|
|
123
|
+
return { node: desktop.node, cli: path.join(desktop.dist, "hud", "cli.js"), lifecycle: path.join(desktop.dist, "lifecycle-entry.js") };
|
|
109
124
|
const standalone = readHeadlessRuntimeInstallation();
|
|
110
125
|
if (!standalone || !isSamePath(runningDistDir(), path.dirname(standalone.entry)))
|
|
111
126
|
return null;
|
|
112
127
|
try {
|
|
113
|
-
return { node: process.execPath, cli: ensureHudLauncher() };
|
|
128
|
+
return { node: process.execPath, cli: ensureHudLauncher(), lifecycle: ensureLifecycleLauncher() };
|
|
114
129
|
}
|
|
115
130
|
catch {
|
|
116
131
|
return null;
|
package/dist/headless-runtime.js
CHANGED
|
@@ -57,6 +57,10 @@ function ensureLauncher() {
|
|
|
57
57
|
export function ensureHudLauncher() {
|
|
58
58
|
return ensureLauncherFile(headlessHudLauncherPath(), 'path.join(path.dirname(path.resolve(root, active.entry)), "hud", "cli.js")');
|
|
59
59
|
}
|
|
60
|
+
/** The same for the lifecycle entry, which the per-call proof hook runs. */
|
|
61
|
+
export function ensureLifecycleLauncher() {
|
|
62
|
+
return ensureLauncherFile(path.join(headlessRuntimeRoot(), "lifecycle-launcher.mjs"), 'path.join(path.dirname(path.resolve(root, active.entry)), "lifecycle-entry.js")');
|
|
63
|
+
}
|
|
60
64
|
function ensureLauncherFile(launcher, entryExpression) {
|
|
61
65
|
const root = headlessRuntimeRoot();
|
|
62
66
|
fs.mkdirSync(root, { recursive: true, mode: 0o700 });
|
package/dist/hud/cli.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import "../backend-network-guard.js";
|
|
2
3
|
import { spawn } from "node:child_process";
|
|
3
4
|
import { createRequire } from "node:module";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
import { adapterList } from "./adapters.js";
|
|
6
7
|
import { autostartPlistPath, autostartSupported, disableAutostart, enableAutostart, isAutostartEnabled } from "./autostart.js";
|
|
7
8
|
import { statSignature } from "./fs.js";
|
|
8
|
-
import { installHooks,
|
|
9
|
+
import { installHooks, installSourceSessionHooks } from "./hooks.js";
|
|
9
10
|
import { HudMonitor } from "./monitor.js";
|
|
10
11
|
import { renderStateText } from "./render.js";
|
|
11
12
|
import { renderReportText, runReport } from "./report.js";
|
|
12
13
|
import { createHudServer } from "./server.js";
|
|
13
|
-
import { runSaveCheckpointHook } from "../save-checkpoint-hook.js";
|
|
14
14
|
import { runSourceSessionStartHook } from "../source-session-hook.js";
|
|
15
|
+
import { runSourceSessionPreToolHook } from "../source-session-pretool-hook.js";
|
|
15
16
|
const argv = process.argv.slice(2);
|
|
16
17
|
const command = argv[0] || "summary";
|
|
17
18
|
const flags = parseFlags(argv.slice(1));
|
|
@@ -26,14 +27,17 @@ try {
|
|
|
26
27
|
await cmdApp(flags);
|
|
27
28
|
else if (command === "install-hooks")
|
|
28
29
|
await cmdInstallHooks(flags);
|
|
29
|
-
else if (command === "install-save-hooks")
|
|
30
|
-
await cmdInstallSaveHooks(flags);
|
|
31
30
|
else if (command === "install-source-session-hooks")
|
|
32
31
|
await cmdInstallSourceSessionHooks(flags);
|
|
33
32
|
else if (command === "save-checkpoint")
|
|
34
33
|
await cmdSaveCheckpoint();
|
|
35
34
|
else if (command === "bind-source-session")
|
|
36
35
|
await cmdBindSourceSession();
|
|
36
|
+
// A retired Stop hook an open session may still run: say nothing, so the host shows nothing.
|
|
37
|
+
else if (command === "echomem-auto-save-memory")
|
|
38
|
+
process.exitCode = 0;
|
|
39
|
+
else if (command === "source-session-proof")
|
|
40
|
+
await cmdSourceSessionProof();
|
|
37
41
|
else if (command === "autostart")
|
|
38
42
|
cmdAutostart(argv[1] || "status", flags);
|
|
39
43
|
else if (command === "status")
|
|
@@ -124,31 +128,27 @@ async function cmdInstallHooks(flags) {
|
|
|
124
128
|
console.log(`Installed EchoMem HUD hook support:\n${paths.map((p) => `- ${p}`).join("\n")}`);
|
|
125
129
|
console.log("Codex users: run /hooks in a new Codex session to review and trust changed hooks.");
|
|
126
130
|
}
|
|
127
|
-
async function cmdInstallSaveHooks(flags) {
|
|
128
|
-
const mode = parseMode(flags.client);
|
|
129
|
-
const paths = [...new Set([
|
|
130
|
-
...installSourceSessionHooks(mode),
|
|
131
|
-
...installSaveCheckpointHooks(mode),
|
|
132
|
-
])];
|
|
133
|
-
console.log(`Installed EchoMem source-session and private-save hooks:\n${paths.map((p) => `- ${p}`).join("\n")}`);
|
|
134
|
-
console.log("Codex users: run /hooks in a new Codex session to review and trust changed hooks.");
|
|
135
|
-
}
|
|
136
131
|
async function cmdInstallSourceSessionHooks(flags) {
|
|
137
132
|
const paths = installSourceSessionHooks(parseMode(flags.client));
|
|
138
133
|
console.log(`Installed EchoMem source-session hooks:\n${paths.map((p) => `- ${p}`).join("\n")}`);
|
|
139
134
|
console.log("Codex users: run /hooks in a new Codex session to review and trust changed hooks.");
|
|
140
135
|
}
|
|
136
|
+
/** Retired: the model's save_conversation call is the only save trigger. A Stop hook installed by
|
|
137
|
+
* an earlier runtime may still call this until the next MCP start removes it, so it stays silent. */
|
|
141
138
|
async function cmdSaveCheckpoint() {
|
|
139
|
+
for await (const _ of process.stdin) { /* drain */ }
|
|
140
|
+
}
|
|
141
|
+
async function cmdBindSourceSession() {
|
|
142
142
|
let input = "";
|
|
143
143
|
for await (const chunk of process.stdin)
|
|
144
144
|
input += String(chunk);
|
|
145
|
-
process.stdout.write(
|
|
145
|
+
process.stdout.write(await runSourceSessionStartHook(input));
|
|
146
146
|
}
|
|
147
|
-
async function
|
|
147
|
+
async function cmdSourceSessionProof() {
|
|
148
148
|
let input = "";
|
|
149
149
|
for await (const chunk of process.stdin)
|
|
150
150
|
input += String(chunk);
|
|
151
|
-
process.stdout.write(
|
|
151
|
+
process.stdout.write(runSourceSessionPreToolHook(input));
|
|
152
152
|
}
|
|
153
153
|
async function cmdReport(flags) {
|
|
154
154
|
const result = runReport(parseMode(flags.client), { limit: readNumber(flags.limit, 40) });
|
|
@@ -202,7 +202,6 @@ Usage:
|
|
|
202
202
|
echomem-hud serve [--client codex|claude-code|claude-desktop|both|auto] [--port 17377]
|
|
203
203
|
echomem-hud app [--client codex|claude-code|claude-desktop|both|auto]
|
|
204
204
|
echomem-hud install-hooks [--client codex|claude-code|both]
|
|
205
|
-
echomem-hud install-save-hooks [--client codex|claude-code|both] (installs both lifecycle hooks)
|
|
206
205
|
echomem-hud install-source-session-hooks [--client codex|claude-code|both]
|
|
207
206
|
echomem-hud autostart on|off|status (show the HUD after restart — macOS)
|
|
208
207
|
echomem-hud status
|
package/dist/hud/diagnostics.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { resolveBackendURL } from "../backend-policy.js";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
4
5
|
import { echoConfigDir, KeyStore } from "../keystore.js";
|
|
5
|
-
const API_BASE = (
|
|
6
|
+
const API_BASE = (resolveBackendURL()).replace(/\/$/, "");
|
|
6
7
|
const EVENTS_TAIL_LINES = 400;
|
|
7
8
|
function record(value) {
|
|
8
9
|
return typeof value === "object" && value !== null && !Array.isArray(value)
|
package/dist/hud/hooks.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { readBackendPolicy, resolveBackendURL } from "../backend-policy.js";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import os from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
4
6
|
import { atomicWriteJsonObject, readJsonObjectFile } from "../config-files.js";
|
|
5
7
|
import { isEphemeralNpxPath, resolveDurableDistPath, stableHudCommandTarget } from "../durable-entry.js";
|
|
6
8
|
/**
|
|
@@ -10,11 +12,26 @@ import { isEphemeralNpxPath, resolveDurableDistPath, stableHudCommandTarget } fr
|
|
|
10
12
|
* that points at nothing. Always resolve through the durable-entry helper instead.
|
|
11
13
|
*/
|
|
12
14
|
function hookCommandFor(distRelative, subcommand) {
|
|
13
|
-
const
|
|
15
|
+
const lifecycle = distRelative === path.join("hud", "cli.js");
|
|
16
|
+
const entry = lifecycle ? "lifecycle-entry.js" : distRelative;
|
|
17
|
+
const cli = resolveDurableDistPath(entry);
|
|
14
18
|
if (cli.ephemeral) {
|
|
15
19
|
console.warn(`⚠️ EchoMem hooks are being pinned to a temporary npx path (${cli.path}). They will stop working once npm clears its cache — install the durable runtime or a global package to make them permanent.`);
|
|
16
20
|
}
|
|
17
|
-
|
|
21
|
+
const distRoot = cli.path.slice(0, -entry.length);
|
|
22
|
+
const desktopNode = path.resolve(distRoot, "..", "node");
|
|
23
|
+
const desktopOwned = process.env.ECHO_DESKTOP_MANAGED === "1" || cli.path.includes(`${path.sep}Echo${path.sep}MCP${path.sep}`);
|
|
24
|
+
const executable = desktopOwned && fs.existsSync(desktopNode)
|
|
25
|
+
? desktopNode : process.execPath;
|
|
26
|
+
const endpoint = lifecycle && (readBackendPolicy() ? resolveBackendURL() : process.env.ECHO_API_BASE_URL?.trim());
|
|
27
|
+
const options = [
|
|
28
|
+
endpoint ? `--api-base-url ${JSON.stringify(endpoint)}` : "",
|
|
29
|
+
lifecycle && desktopOwned ? "--desktop-managed" : "",
|
|
30
|
+
].filter(Boolean).join(" ");
|
|
31
|
+
const machineGuard = path.join(os.homedir(), ".echomem", "backend-network-guard.mjs");
|
|
32
|
+
const preload = readBackendPolicy() && fs.existsSync(machineGuard)
|
|
33
|
+
? ` --import ${JSON.stringify(pathToFileURL(machineGuard).href)}` : "";
|
|
34
|
+
return `${JSON.stringify(executable)}${preload} ${JSON.stringify(cli.path)} ${subcommand}${options ? ` ${options}` : ""}`;
|
|
18
35
|
}
|
|
19
36
|
export function installHooks(mode) {
|
|
20
37
|
const written = [];
|
|
@@ -26,16 +43,6 @@ export function installHooks(mode) {
|
|
|
26
43
|
}
|
|
27
44
|
return written;
|
|
28
45
|
}
|
|
29
|
-
export function installSaveCheckpointHooks(mode) {
|
|
30
|
-
const written = [];
|
|
31
|
-
if (mode === "codex" || mode === "both" || mode === "auto") {
|
|
32
|
-
written.push(installCodexSaveCheckpointHook());
|
|
33
|
-
}
|
|
34
|
-
if (mode === "claude-code" || mode === "both" || mode === "auto") {
|
|
35
|
-
written.push(installClaudeCodeSaveCheckpointHook());
|
|
36
|
-
}
|
|
37
|
-
return written;
|
|
38
|
-
}
|
|
39
46
|
export function installSourceSessionHooks(mode) {
|
|
40
47
|
const written = [];
|
|
41
48
|
if (mode === "codex" || mode === "both" || mode === "auto") {
|
|
@@ -88,14 +95,17 @@ export function removeLifecycleHooks(mode) {
|
|
|
88
95
|
}
|
|
89
96
|
return { files, removedGroups };
|
|
90
97
|
}
|
|
91
|
-
const LIFECYCLE_COMMAND = /^"((?:[^"\\]|\\.)*)" "((?:[^"\\]|\\.)*)" (
|
|
98
|
+
const LIFECYCLE_COMMAND = /^"((?:[^"\\]|\\.)*)" "((?:[^"\\]|\\.)*)" (bind-source-session)$/;
|
|
99
|
+
// The proof hook also carries a preload and endpoint options; both stay as setup wrote them.
|
|
100
|
+
const PROOF_COMMAND = /^"((?:[^"\\]|\\.)*)"((?: --import "(?:[^"\\]|\\.)*")?) "((?:[^"\\]|\\.)*)" (source-session-proof(?: .*)?)$/;
|
|
92
101
|
/**
|
|
93
102
|
* Repoint installed EchoMem lifecycle hooks that are pinned to a runtime version folder or the npx
|
|
94
103
|
* cache, or that name a file that no longer exists. Runtime updates never rerun setup, so such a
|
|
95
104
|
* hook keeps running whichever version wrote it. Only the copy Echo Desktop or the standalone
|
|
96
105
|
* runtime currently runs does this; see stableHudCommandTarget. Only EchoMem's own commands change
|
|
97
|
-
* and no hook is ever added
|
|
98
|
-
* every changed hook. Returns the files written; any
|
|
106
|
+
* and no hook is ever added; retired save hooks are removed. Working Codex hooks are
|
|
107
|
+
* kept, because Codex makes the user re-trust every changed hook. Returns the files written; any
|
|
108
|
+
* failure leaves that file untouched.
|
|
99
109
|
*/
|
|
100
110
|
export function refreshInstalledLifecycleHooks() {
|
|
101
111
|
const target = stableHudCommandTarget();
|
|
@@ -111,7 +121,8 @@ export function refreshInstalledLifecycleHooks() {
|
|
|
111
121
|
if (fs.lstatSync(file).isSymbolicLink())
|
|
112
122
|
continue;
|
|
113
123
|
const content = readHooksFile(file);
|
|
114
|
-
|
|
124
|
+
const dropped = dropRetiredSaveGroups(content.hooks);
|
|
125
|
+
if (!refreshLifecycleCommands(content.hooks, target, repairPinned) && !dropped)
|
|
115
126
|
continue;
|
|
116
127
|
atomicWriteJsonObject(file, content);
|
|
117
128
|
files.push(file);
|
|
@@ -151,13 +162,17 @@ function refreshLifecycleCommands(hooks, target, repairPinned) {
|
|
|
151
162
|
return changed;
|
|
152
163
|
}
|
|
153
164
|
function refreshedLifecycleCommand(command, target, repairPinned) {
|
|
154
|
-
const
|
|
155
|
-
|
|
165
|
+
const bind = typeof command === "string" ? LIFECYCLE_COMMAND.exec(command) : null;
|
|
166
|
+
const proof = typeof command === "string" && !bind ? PROOF_COMMAND.exec(command) : null;
|
|
167
|
+
// A runtime from before the proof hook has no entry for it; the hook then stays as it is.
|
|
168
|
+
if (!bind && !(proof && fs.existsSync(target.lifecycle)))
|
|
156
169
|
return null;
|
|
157
|
-
const replacement =
|
|
170
|
+
const replacement = bind
|
|
171
|
+
? `${JSON.stringify(target.node)} ${JSON.stringify(target.cli)} ${bind[3]}`
|
|
172
|
+
: `${JSON.stringify(target.node)}${proof[2]} ${JSON.stringify(target.lifecycle)} ${proof[4]}`;
|
|
158
173
|
if (replacement === command)
|
|
159
174
|
return null;
|
|
160
|
-
const [node, script] = [
|
|
175
|
+
const [node, script] = (bind ? [bind[1], bind[2]] : [proof[1], proof[3]]).map((quoted) => JSON.parse(`"${quoted}"`));
|
|
161
176
|
if (!fs.existsSync(node) || !fs.existsSync(script))
|
|
162
177
|
return replacement;
|
|
163
178
|
return repairPinned && isPinnedRuntimePath(script) ? replacement : null;
|
|
@@ -181,19 +196,26 @@ function installCodexHooks() {
|
|
|
181
196
|
atomicWriteJsonObject(file, content);
|
|
182
197
|
return file;
|
|
183
198
|
}
|
|
184
|
-
function saveCheckpointCommand() {
|
|
185
|
-
return lifecycleHookCommand("save-checkpoint");
|
|
186
|
-
}
|
|
187
199
|
function sourceSessionCommand() {
|
|
188
200
|
return lifecycleHookCommand("bind-source-session");
|
|
189
201
|
}
|
|
190
|
-
/** Prefer a target that follows runtime updates: a hook pinned to one version keeps running it.
|
|
202
|
+
/** Prefer a target that follows runtime updates: a hook pinned to one version keeps running it.
|
|
203
|
+
* The command must not vary with device settings: Codex skips a hook whose command changed until the
|
|
204
|
+
* user re-trusts it. The hud CLI reads the backend policy itself, so only an endpoint that exists
|
|
205
|
+
* nowhere but this process's environment is written into the command. */
|
|
191
206
|
function lifecycleHookCommand(subcommand) {
|
|
192
207
|
const target = stableHudCommandTarget();
|
|
193
|
-
if (!target)
|
|
208
|
+
if (!target || (process.env.ECHO_API_BASE_URL?.trim() && !readBackendPolicy()))
|
|
194
209
|
return hookCommandFor(path.join("hud", "cli.js"), subcommand);
|
|
195
210
|
return `${JSON.stringify(target.node)} ${JSON.stringify(target.cli)} ${subcommand}`;
|
|
196
211
|
}
|
|
212
|
+
function sourceSessionProofCommand() {
|
|
213
|
+
return hookCommandFor(path.join("hud", "cli.js"), "source-session-proof");
|
|
214
|
+
}
|
|
215
|
+
/** The Stop hook that once showed save receipts. Every host printed what it handed the agent
|
|
216
|
+
* as hook text in the chat, so the receipt now comes back in the save call itself and this
|
|
217
|
+
* hook is removed wherever an earlier install wrote it. */
|
|
218
|
+
export const RETIRED_STOP_RECEIPT_COMMAND = "echomem-auto-save-memory";
|
|
197
219
|
function installCodexSourceSessionHook() {
|
|
198
220
|
const dir = profileDirectory("CODEX_HOME", ".codex");
|
|
199
221
|
const file = path.join(dir, "hooks.json");
|
|
@@ -201,8 +223,9 @@ function installCodexSourceSessionHook() {
|
|
|
201
223
|
const content = readHooksFile(file);
|
|
202
224
|
content.hooks = content.hooks || {};
|
|
203
225
|
content.hooks.SessionStart = mergeSourceSessionGroup(content.hooks.SessionStart, {
|
|
204
|
-
hooks: [codexCommandHook(sourceSessionCommand(), 5
|
|
226
|
+
hooks: [codexCommandHook(sourceSessionCommand(), 5)],
|
|
205
227
|
});
|
|
228
|
+
dropRetiredSaveGroups(content.hooks);
|
|
206
229
|
atomicWriteJsonObject(file, content);
|
|
207
230
|
return file;
|
|
208
231
|
}
|
|
@@ -217,38 +240,13 @@ function installClaudeCodeSourceSessionHook() {
|
|
|
217
240
|
type: "command",
|
|
218
241
|
command: sourceSessionCommand(),
|
|
219
242
|
timeout: 5,
|
|
220
|
-
statusMessage: "Binding EchoMem to this conversation",
|
|
221
243
|
}],
|
|
222
244
|
});
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
function installCodexSaveCheckpointHook() {
|
|
227
|
-
const dir = profileDirectory("CODEX_HOME", ".codex");
|
|
228
|
-
const file = path.join(dir, "hooks.json");
|
|
229
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
230
|
-
const content = readHooksFile(file);
|
|
231
|
-
content.hooks = content.hooks || {};
|
|
232
|
-
content.hooks.Stop = mergeSaveCheckpointGroup(content.hooks.Stop, {
|
|
233
|
-
hooks: [codexCommandHook(saveCheckpointCommand(), 10, "Checking whether completed work should be remembered")],
|
|
234
|
-
});
|
|
235
|
-
atomicWriteJsonObject(file, content);
|
|
236
|
-
return file;
|
|
237
|
-
}
|
|
238
|
-
function installClaudeCodeSaveCheckpointHook() {
|
|
239
|
-
const dir = profileDirectory("CLAUDE_CONFIG_DIR", ".claude");
|
|
240
|
-
const file = path.join(dir, "settings.json");
|
|
241
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
242
|
-
const content = readHooksFile(file);
|
|
243
|
-
content.hooks = content.hooks || {};
|
|
244
|
-
content.hooks.Stop = mergeSaveCheckpointGroup(content.hooks.Stop, {
|
|
245
|
-
hooks: [{
|
|
246
|
-
type: "command",
|
|
247
|
-
command: saveCheckpointCommand(),
|
|
248
|
-
timeout: 10,
|
|
249
|
-
statusMessage: "Checking whether completed work should be remembered",
|
|
250
|
-
}],
|
|
245
|
+
content.hooks.PreToolUse = mergeSourceSessionProofGroup(content.hooks.PreToolUse, {
|
|
246
|
+
matcher: "^mcp__echomem__",
|
|
247
|
+
hooks: [{ type: "command", command: sourceSessionProofCommand(), timeout: 5 }],
|
|
251
248
|
});
|
|
249
|
+
dropRetiredSaveGroups(content.hooks);
|
|
252
250
|
atomicWriteJsonObject(file, content);
|
|
253
251
|
return file;
|
|
254
252
|
}
|
|
@@ -275,13 +273,12 @@ function profileDirectory(envKey, fallbackName) {
|
|
|
275
273
|
}
|
|
276
274
|
return path.normalize(configured);
|
|
277
275
|
}
|
|
278
|
-
function codexCommandHook(command, timeout
|
|
276
|
+
function codexCommandHook(command, timeout) {
|
|
279
277
|
return {
|
|
280
278
|
type: "command",
|
|
281
279
|
command,
|
|
282
280
|
commandWindows: command,
|
|
283
281
|
timeout,
|
|
284
|
-
...(statusMessage ? { statusMessage } : {}),
|
|
285
282
|
};
|
|
286
283
|
}
|
|
287
284
|
function mergeHookGroup(existing, group) {
|
|
@@ -289,16 +286,43 @@ function mergeHookGroup(existing, group) {
|
|
|
289
286
|
groups.push(group);
|
|
290
287
|
return groups;
|
|
291
288
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
289
|
+
/** The model's save_conversation call is the only save trigger: checkpoint and receipt hooks
|
|
290
|
+
* from earlier installs, on any event, are removed. */
|
|
291
|
+
function dropRetiredSaveGroups(hooks) {
|
|
292
|
+
if (!hooks || typeof hooks !== "object" || Array.isArray(hooks))
|
|
293
|
+
return false;
|
|
294
|
+
const byEvent = hooks;
|
|
295
|
+
let changed = false;
|
|
296
|
+
for (const event of Object.keys(byEvent)) {
|
|
297
|
+
const groups = byEvent[event];
|
|
298
|
+
if (!Array.isArray(groups))
|
|
299
|
+
continue;
|
|
300
|
+
const kept = groups.filter((item) => !isEchoSaveCheckpointGroup(item) && !isEchoReceiptGroup(item) && !isEchoStopReceiptGroup(item));
|
|
301
|
+
if (kept.length === groups.length)
|
|
302
|
+
continue;
|
|
303
|
+
changed = true;
|
|
304
|
+
if (kept.length)
|
|
305
|
+
byEvent[event] = kept;
|
|
306
|
+
else
|
|
307
|
+
delete byEvent[event];
|
|
308
|
+
}
|
|
309
|
+
return changed;
|
|
296
310
|
}
|
|
297
311
|
function mergeSourceSessionGroup(existing, group) {
|
|
298
312
|
const groups = Array.isArray(existing) ? existing.filter((item) => !isEchoSourceSessionGroup(item)) : [];
|
|
299
313
|
groups.push(group);
|
|
300
314
|
return groups;
|
|
301
315
|
}
|
|
316
|
+
function mergeSourceSessionProofGroup(existing, group) {
|
|
317
|
+
const groups = Array.isArray(existing) ? existing.filter((item) => !isEchoSourceSessionProofGroup(item)) : [];
|
|
318
|
+
groups.push(group);
|
|
319
|
+
return groups;
|
|
320
|
+
}
|
|
321
|
+
function isEchoStopReceiptGroup(value) {
|
|
322
|
+
if (typeof value !== "object" || value === null)
|
|
323
|
+
return false;
|
|
324
|
+
return JSON.stringify(value).includes(RETIRED_STOP_RECEIPT_COMMAND);
|
|
325
|
+
}
|
|
302
326
|
function isEchoHudGroup(value) {
|
|
303
327
|
if (typeof value !== "object" || value === null)
|
|
304
328
|
return false;
|
|
@@ -309,11 +333,22 @@ function isEchoSourceSessionGroup(value) {
|
|
|
309
333
|
return false;
|
|
310
334
|
return JSON.stringify(value).includes("bind-source-session");
|
|
311
335
|
}
|
|
336
|
+
function isEchoSourceSessionProofGroup(value) {
|
|
337
|
+
if (typeof value !== "object" || value === null)
|
|
338
|
+
return false;
|
|
339
|
+
return JSON.stringify(value).includes("source-session-proof");
|
|
340
|
+
}
|
|
312
341
|
function isEchoSaveCheckpointGroup(value) {
|
|
313
342
|
if (typeof value !== "object" || value === null)
|
|
314
343
|
return false;
|
|
315
344
|
return JSON.stringify(value).includes("save-checkpoint");
|
|
316
345
|
}
|
|
346
|
+
function isEchoReceiptGroup(value) {
|
|
347
|
+
if (typeof value !== "object" || value === null)
|
|
348
|
+
return false;
|
|
349
|
+
return JSON.stringify(value).includes("receipt-hook");
|
|
350
|
+
}
|
|
317
351
|
function isEchoLifecycleGroup(value) {
|
|
318
|
-
return isEchoHudGroup(value) || isEchoSourceSessionGroup(value) || isEchoSaveCheckpointGroup(value)
|
|
352
|
+
return isEchoHudGroup(value) || isEchoSourceSessionGroup(value) || isEchoSourceSessionProofGroup(value) || isEchoSaveCheckpointGroup(value)
|
|
353
|
+
|| isEchoReceiptGroup(value) || isEchoStopReceiptGroup(value);
|
|
319
354
|
}
|
package/dist/hud/server.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveBackendURL } from "../backend-policy.js";
|
|
1
2
|
import http from "node:http";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
@@ -12,7 +13,7 @@ import { KeyStore } from "../keystore.js";
|
|
|
12
13
|
import { assembleCodex, assembleClaude } from "../migrate.js";
|
|
13
14
|
import { readBillingAlert } from "../billing-alert.js";
|
|
14
15
|
import { readSessionWorkingDirectory, } from "./session-launcher.js";
|
|
15
|
-
const API_BASE = (
|
|
16
|
+
const API_BASE = (resolveBackendURL()).replace(/\/$/, "");
|
|
16
17
|
const PRICING_URL = (process.env.ECHO_PRICING_URL || "https://echoknows.com/dashboard/account").replace(/\/$/, "");
|
|
17
18
|
export async function createHudServer(opts = {}) {
|
|
18
19
|
const mode = opts.mode || "auto";
|