@getengram/cli 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +112 -0
- package/README.md +1 -1
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +38 -11
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/conversations.d.ts.map +1 -1
- package/dist/commands/conversations.js +8 -2
- package/dist/commands/conversations.js.map +1 -1
- package/dist/commands/exclude.d.ts.map +1 -1
- package/dist/commands/exclude.js +73 -21
- package/dist/commands/exclude.js.map +1 -1
- package/dist/commands/import.d.ts +30 -3
- package/dist/commands/import.d.ts.map +1 -1
- package/dist/commands/import.js +374 -45
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +144 -29
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/search.js +2 -2
- package/dist/commands/search.js.map +1 -1
- package/dist/commands/status.d.ts +16 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +51 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/store.d.ts.map +1 -1
- package/dist/commands/store.js +19 -3
- package/dist/commands/store.js.map +1 -1
- package/dist/commands/upgrade.d.ts +24 -0
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +64 -15
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/usage.d.ts +44 -0
- package/dist/commands/usage.d.ts.map +1 -1
- package/dist/commands/usage.js +79 -19
- package/dist/commands/usage.js.map +1 -1
- package/dist/commands/vault.d.ts +11 -2
- package/dist/commands/vault.d.ts.map +1 -1
- package/dist/commands/vault.js +372 -53
- package/dist/commands/vault.js.map +1 -1
- package/dist/config-file.d.ts +74 -0
- package/dist/config-file.d.ts.map +1 -0
- package/dist/config-file.js +152 -0
- package/dist/config-file.js.map +1 -0
- package/dist/config-guard.d.ts +96 -0
- package/dist/config-guard.d.ts.map +1 -0
- package/dist/config-guard.js +184 -0
- package/dist/config-guard.js.map +1 -0
- package/dist/config.d.ts +48 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +101 -12
- package/dist/config.js.map +1 -1
- package/dist/daemon/as-root.d.ts +46 -0
- package/dist/daemon/as-root.d.ts.map +1 -0
- package/dist/daemon/as-root.js +64 -0
- package/dist/daemon/as-root.js.map +1 -0
- package/dist/daemon/backoff.d.ts +26 -0
- package/dist/daemon/backoff.d.ts.map +1 -0
- package/dist/daemon/backoff.js +37 -0
- package/dist/daemon/backoff.js.map +1 -0
- package/dist/daemon/codex-parser.d.ts +38 -4
- package/dist/daemon/codex-parser.d.ts.map +1 -1
- package/dist/daemon/codex-parser.js +111 -23
- package/dist/daemon/codex-parser.js.map +1 -1
- package/dist/daemon/command-path.d.ts +13 -0
- package/dist/daemon/command-path.d.ts.map +1 -0
- package/dist/daemon/command-path.js +35 -0
- package/dist/daemon/command-path.js.map +1 -0
- package/dist/daemon/commands.d.ts +153 -3
- package/dist/daemon/commands.d.ts.map +1 -1
- package/dist/daemon/commands.js +2775 -235
- package/dist/daemon/commands.js.map +1 -1
- package/dist/daemon/db.d.ts +255 -27
- package/dist/daemon/db.d.ts.map +1 -1
- package/dist/daemon/db.js +749 -53
- package/dist/daemon/db.js.map +1 -1
- package/dist/daemon/exclusions.d.ts +23 -3
- package/dist/daemon/exclusions.d.ts.map +1 -1
- package/dist/daemon/exclusions.js +91 -21
- package/dist/daemon/exclusions.js.map +1 -1
- package/dist/daemon/homebrew.d.ts +26 -0
- package/dist/daemon/homebrew.d.ts.map +1 -0
- package/dist/daemon/homebrew.js +43 -0
- package/dist/daemon/homebrew.js.map +1 -0
- package/dist/daemon/instance.d.ts +427 -0
- package/dist/daemon/instance.d.ts.map +1 -0
- package/dist/daemon/instance.js +1201 -0
- package/dist/daemon/instance.js.map +1 -0
- package/dist/daemon/key-source.d.ts +41 -0
- package/dist/daemon/key-source.d.ts.map +1 -0
- package/dist/daemon/key-source.js +89 -0
- package/dist/daemon/key-source.js.map +1 -0
- package/dist/daemon/launch.d.ts +56 -0
- package/dist/daemon/launch.d.ts.map +1 -0
- package/dist/daemon/launch.js +153 -0
- package/dist/daemon/launch.js.map +1 -0
- package/dist/daemon/launchd.d.ts +215 -0
- package/dist/daemon/launchd.d.ts.map +1 -0
- package/dist/daemon/launchd.js +527 -0
- package/dist/daemon/launchd.js.map +1 -0
- package/dist/daemon/login-start.d.ts +2 -0
- package/dist/daemon/login-start.d.ts.map +1 -0
- package/dist/daemon/login-start.js +25 -0
- package/dist/daemon/login-start.js.map +1 -0
- package/dist/daemon/ownership.d.ts +123 -0
- package/dist/daemon/ownership.d.ts.map +1 -0
- package/dist/daemon/ownership.js +245 -0
- package/dist/daemon/ownership.js.map +1 -0
- package/dist/daemon/package-runner.d.ts +28 -0
- package/dist/daemon/package-runner.d.ts.map +1 -0
- package/dist/daemon/package-runner.js +113 -0
- package/dist/daemon/package-runner.js.map +1 -0
- package/dist/daemon/parser.d.ts +50 -5
- package/dist/daemon/parser.d.ts.map +1 -1
- package/dist/daemon/parser.js +224 -47
- package/dist/daemon/parser.js.map +1 -1
- package/dist/daemon/powershell.d.ts +25 -0
- package/dist/daemon/powershell.d.ts.map +1 -0
- package/dist/daemon/powershell.js +30 -0
- package/dist/daemon/powershell.js.map +1 -0
- package/dist/daemon/preflight.d.ts +0 -17
- package/dist/daemon/preflight.d.ts.map +1 -1
- package/dist/daemon/preflight.js +32 -6
- package/dist/daemon/preflight.js.map +1 -1
- package/dist/daemon/prune.d.ts +101 -0
- package/dist/daemon/prune.d.ts.map +1 -0
- package/dist/daemon/prune.js +287 -0
- package/dist/daemon/prune.js.map +1 -0
- package/dist/daemon/queue-error.d.ts +47 -0
- package/dist/daemon/queue-error.d.ts.map +1 -0
- package/dist/daemon/queue-error.js +59 -0
- package/dist/daemon/queue-error.js.map +1 -0
- package/dist/daemon/root-daemon.d.ts +60 -0
- package/dist/daemon/root-daemon.d.ts.map +1 -0
- package/dist/daemon/root-daemon.js +86 -0
- package/dist/daemon/root-daemon.js.map +1 -0
- package/dist/daemon/scoop.d.ts +52 -0
- package/dist/daemon/scoop.d.ts.map +1 -0
- package/dist/daemon/scoop.js +84 -0
- package/dist/daemon/scoop.js.map +1 -0
- package/dist/daemon/scrubber.d.ts +456 -0
- package/dist/daemon/scrubber.d.ts.map +1 -0
- package/dist/daemon/scrubber.js +994 -0
- package/dist/daemon/scrubber.js.map +1 -0
- package/dist/daemon/status.d.ts +306 -11
- package/dist/daemon/status.d.ts.map +1 -1
- package/dist/daemon/status.js +568 -43
- package/dist/daemon/status.js.map +1 -1
- package/dist/daemon/supervise.d.ts +78 -0
- package/dist/daemon/supervise.d.ts.map +1 -0
- package/dist/daemon/supervise.js +121 -0
- package/dist/daemon/supervise.js.map +1 -0
- package/dist/daemon/supervisor.d.ts +18 -0
- package/dist/daemon/supervisor.d.ts.map +1 -0
- package/dist/daemon/supervisor.js +56 -0
- package/dist/daemon/supervisor.js.map +1 -0
- package/dist/daemon/syncer.d.ts +382 -21
- package/dist/daemon/syncer.d.ts.map +1 -1
- package/dist/daemon/syncer.js +1448 -178
- package/dist/daemon/syncer.js.map +1 -1
- package/dist/daemon/systemd.d.ts +109 -0
- package/dist/daemon/systemd.d.ts.map +1 -0
- package/dist/daemon/systemd.js +363 -0
- package/dist/daemon/systemd.js.map +1 -0
- package/dist/daemon/types.d.ts +58 -6
- package/dist/daemon/types.d.ts.map +1 -1
- package/dist/daemon/vault-changed.d.ts +29 -0
- package/dist/daemon/vault-changed.d.ts.map +1 -0
- package/dist/daemon/vault-changed.js +47 -0
- package/dist/daemon/vault-changed.js.map +1 -0
- package/dist/daemon/vault-key-missing.d.ts +70 -0
- package/dist/daemon/vault-key-missing.d.ts.map +1 -0
- package/dist/daemon/vault-key-missing.js +125 -0
- package/dist/daemon/vault-key-missing.js.map +1 -0
- package/dist/daemon/watcher.d.ts +87 -4
- package/dist/daemon/watcher.d.ts.map +1 -1
- package/dist/daemon/watcher.js +286 -36
- package/dist/daemon/watcher.js.map +1 -1
- package/dist/daemon/worker-main.js +363 -51
- package/dist/daemon/worker-main.js.map +1 -1
- package/dist/daemon/worker.js +19 -1
- package/dist/daemon/worker.js.map +1 -1
- package/dist/import-resume.d.ts +163 -0
- package/dist/import-resume.d.ts.map +1 -0
- package/dist/import-resume.js +267 -0
- package/dist/import-resume.js.map +1 -0
- package/dist/index.js +242 -33
- package/dist/index.js.map +1 -1
- package/dist/message-bounds.d.ts +52 -0
- package/dist/message-bounds.d.ts.map +1 -0
- package/dist/message-bounds.js +157 -0
- package/dist/message-bounds.js.map +1 -0
- package/dist/output.d.ts +14 -0
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +33 -5
- package/dist/output.js.map +1 -1
- package/dist/private-files.d.ts +126 -0
- package/dist/private-files.d.ts.map +1 -0
- package/dist/private-files.js +372 -0
- package/dist/private-files.js.map +1 -0
- package/dist/server-url.d.ts +31 -0
- package/dist/server-url.d.ts.map +1 -0
- package/dist/server-url.js +47 -0
- package/dist/server-url.js.map +1 -0
- package/dist/vault-key.d.ts +122 -0
- package/dist/vault-key.d.ts.map +1 -0
- package/dist/vault-key.js +273 -0
- package/dist/vault-key.js.map +1 -0
- package/package.json +11 -12
package/dist/daemon/parser.js
CHANGED
|
@@ -5,6 +5,67 @@ const SKIP_TYPES = new Set([
|
|
|
5
5
|
"queue-operation",
|
|
6
6
|
"last-prompt",
|
|
7
7
|
]);
|
|
8
|
+
/**
|
|
9
|
+
* Engram stores text, so an image cannot be kept as pixels — but it must not
|
|
10
|
+
* vanish either. A turn that read "what is wrong with this?" next to a
|
|
11
|
+
* screenshot is nonsense on its own, and that is exactly what recall used to
|
|
12
|
+
* return. This records that something visual was attached, with enough detail
|
|
13
|
+
* to recognise it later and to decide whether it is worth running OCR over.
|
|
14
|
+
*/
|
|
15
|
+
function describeImage(block) {
|
|
16
|
+
const src = block.source ?? {};
|
|
17
|
+
const kind = (src.media_type || "image").replace(/^image\//, "").toUpperCase();
|
|
18
|
+
// base64 encodes 3 bytes per 4 chars; close enough to show scale.
|
|
19
|
+
const bytes = src.data ? Math.floor((src.data.length * 3) / 4) : 0;
|
|
20
|
+
const size = bytes >= 1_048_576
|
|
21
|
+
? `${(bytes / 1_048_576).toFixed(1)} MB`
|
|
22
|
+
: bytes >= 1024
|
|
23
|
+
? `${Math.round(bytes / 1024)} KB`
|
|
24
|
+
: bytes > 0 ? `${bytes} B` : "";
|
|
25
|
+
const where = src.url ? ` ${src.url}` : "";
|
|
26
|
+
return `[image attached: ${kind}${size ? `, ${size}` : ""}${where}]`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Commands whose entire purpose is to print a secret. Their output must
|
|
30
|
+
* never be captured, no matter what it looks like.
|
|
31
|
+
*
|
|
32
|
+
* `engram vault get NAME` decrypts and prints a vault value; `engram vault
|
|
33
|
+
* keygen` prints the vault KEY. Both are first-party, and docs/vault.md
|
|
34
|
+
* tells users to run the first one from inside an agent session. Before
|
|
35
|
+
* this check, that session's transcript — tool output included — was shipped
|
|
36
|
+
* to the server and vector-indexed, so the one feature built to keep a
|
|
37
|
+
* secret out of memory was the one putting it there. The server-side regex
|
|
38
|
+
* cannot help: a password or a PIN has no shape to match.
|
|
39
|
+
*
|
|
40
|
+
* Reading the key file directly is the same leak by a different door.
|
|
41
|
+
*/
|
|
42
|
+
//
|
|
43
|
+
// Matched on the subcommand, not the binary name: `node dist/index.js vault
|
|
44
|
+
// get`, `npx engram vault get` and `./engram vault get` all print the same
|
|
45
|
+
// value. Withholding the output of some other tool's `vault get` by mistake
|
|
46
|
+
// is a harmless over-redaction; missing one of these is the leak.
|
|
47
|
+
//
|
|
48
|
+
// The key file is matched by its name alone, without regard to case
|
|
49
|
+
// (engram#619): `type %USERPROFILE%\.Engram\vault-key`, `cd ~/.engram && cat
|
|
50
|
+
// vault-key` and a Read of its path all print the key, and macOS and Windows
|
|
51
|
+
// ignore case in file names. ENGRAM_VAULT_KEY is the same key, kept in the
|
|
52
|
+
// environment.
|
|
53
|
+
const REVEALS_SECRET = /\bvault\s+(?:get|keygen)\b|\bvault-key\b|\bENGRAM_VAULT_KEY\b/i;
|
|
54
|
+
/**
|
|
55
|
+
* Every string in a tool call's input, nested ones included: a shell
|
|
56
|
+
* command, a file-reading tool's path, an MCP tool's arguments. Looking only
|
|
57
|
+
* at `command` let a Read of the key file through (engram#619).
|
|
58
|
+
*/
|
|
59
|
+
function stringsOf(value, out = [], depth = 0) {
|
|
60
|
+
if (typeof value === "string")
|
|
61
|
+
out.push(value);
|
|
62
|
+
else if (value && typeof value === "object" && depth < 8) {
|
|
63
|
+
for (const v of Object.values(value))
|
|
64
|
+
stringsOf(v, out, depth + 1);
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
export const REDACTED_TOOL_OUTPUT = "[output withheld by engram: this command prints a secret]";
|
|
8
69
|
/**
|
|
9
70
|
* Parses Claude Code JSONL transcript lines into Engram messages.
|
|
10
71
|
*
|
|
@@ -12,16 +73,37 @@ const SKIP_TYPES = new Set([
|
|
|
12
73
|
* response may span multiple lines sharing the same `message.id`. We
|
|
13
74
|
* accumulate blocks and flush when the message is complete (stop_reason
|
|
14
75
|
* is set) or a new message begins.
|
|
76
|
+
*
|
|
77
|
+
* One parser reads every transcript of the host, interleaved: a session's
|
|
78
|
+
* subagents and workflows write files of their own next to it. So the
|
|
79
|
+
* accumulator is kept per file, and a message is emitted under the session
|
|
80
|
+
* of its own lines (engram#579). It used to be a single accumulator emitted
|
|
81
|
+
* under whichever session the parser had seen last, from any file — a
|
|
82
|
+
* reply could be filed under another session, or dropped along with it when
|
|
83
|
+
* that session was opted out.
|
|
15
84
|
*/
|
|
16
85
|
export class Parser {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Every line names its session, so resuming a file needs no context but
|
|
88
|
+
* the recent tool calls: a `vault get` whose output is still to come.
|
|
89
|
+
* Wide enough to reach back past parallel tool calls with large outputs;
|
|
90
|
+
* past it, the value-exact scrubber (scrubber.ts) still applies.
|
|
91
|
+
*/
|
|
92
|
+
resumeContext = { headBytes: 0, tailBytes: 2 * 1024 * 1024 };
|
|
93
|
+
/** The buffered assistant message of each file that has one. */
|
|
94
|
+
pending = new Map();
|
|
95
|
+
/**
|
|
96
|
+
* tool_use ids whose result must not be captured. Bounded: an id is
|
|
97
|
+
* removed once its result is queued, and a session produces a few
|
|
98
|
+
* hundred tool calls at most. Tool ids are unique, so one set serves
|
|
99
|
+
* every file.
|
|
100
|
+
*/
|
|
101
|
+
secretToolIds = new Set();
|
|
20
102
|
onMessages;
|
|
21
103
|
constructor(onMessages) {
|
|
22
104
|
this.onMessages = onMessages;
|
|
23
105
|
}
|
|
24
|
-
processLine(line, filePath) {
|
|
106
|
+
processLine(line, filePath, offset) {
|
|
25
107
|
let data;
|
|
26
108
|
try {
|
|
27
109
|
data = JSON.parse(line);
|
|
@@ -29,6 +111,8 @@ export class Parser {
|
|
|
29
111
|
catch {
|
|
30
112
|
return; // malformed line, skip
|
|
31
113
|
}
|
|
114
|
+
if (!data || typeof data !== "object")
|
|
115
|
+
return; // valid JSON, not a record
|
|
32
116
|
// Skip noise
|
|
33
117
|
if (SKIP_TYPES.has(data.type))
|
|
34
118
|
return;
|
|
@@ -47,22 +131,61 @@ export class Parser {
|
|
|
47
131
|
version: data.version,
|
|
48
132
|
host: "claude-code",
|
|
49
133
|
};
|
|
50
|
-
this.lastSessionId = sessionId;
|
|
51
|
-
this.lastMeta = meta;
|
|
52
134
|
if (!data.message)
|
|
53
135
|
return;
|
|
54
136
|
if (data.type === "user") {
|
|
55
|
-
//
|
|
56
|
-
this.flushPending();
|
|
137
|
+
// A user turn ends this file's buffered assistant message
|
|
138
|
+
this.flushPending(filePath);
|
|
57
139
|
this.processUserLine(sessionId, meta, data);
|
|
58
140
|
}
|
|
59
141
|
else if (data.type === "assistant") {
|
|
60
|
-
this.processAssistantLine(sessionId, meta, data);
|
|
142
|
+
this.processAssistantLine(sessionId, meta, data, filePath, offset);
|
|
61
143
|
}
|
|
62
144
|
}
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Replays a line an earlier daemon process already handled — the watcher
|
|
147
|
+
* does this for the lines just before where it resumes a file. Only one
|
|
148
|
+
* thing spans lines across a restart: which tool calls print a secret.
|
|
149
|
+
* Without it, a `vault get` whose output was written after the daemon
|
|
150
|
+
* restarted had that output captured. Never emits.
|
|
151
|
+
*/
|
|
152
|
+
restoreLine(line, _filePath) {
|
|
153
|
+
// Cheap pre-check: only tool_use and tool_result lines matter here.
|
|
154
|
+
if (!line.includes("tool_"))
|
|
155
|
+
return;
|
|
156
|
+
let data;
|
|
157
|
+
try {
|
|
158
|
+
data = JSON.parse(line);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const content = data?.message?.content;
|
|
164
|
+
if (!Array.isArray(content))
|
|
165
|
+
return;
|
|
166
|
+
for (const block of content) {
|
|
167
|
+
if (data.type === "assistant" && block.type === "tool_use") {
|
|
168
|
+
this.trackSecretTool(block);
|
|
169
|
+
}
|
|
170
|
+
else if (data.type === "user" && block.type === "tool_result" && block.tool_use_id) {
|
|
171
|
+
this.secretToolIds.delete(block.tool_use_id);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
bufferedFrom(filePath) {
|
|
176
|
+
return this.pending.get(filePath)?.from ?? null;
|
|
177
|
+
}
|
|
178
|
+
discard(filePath) {
|
|
179
|
+
this.pending.delete(filePath);
|
|
180
|
+
}
|
|
181
|
+
/** Emit buffered assistant messages: one file's, or every file's. */
|
|
182
|
+
flush(filePath) {
|
|
183
|
+
if (filePath !== undefined) {
|
|
184
|
+
this.flushPending(filePath);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
for (const path of [...this.pending.keys()])
|
|
188
|
+
this.flushPending(path);
|
|
66
189
|
}
|
|
67
190
|
processUserLine(sessionId, meta, data) {
|
|
68
191
|
const content = data.message.content;
|
|
@@ -75,15 +198,39 @@ export class Parser {
|
|
|
75
198
|
}
|
|
76
199
|
return;
|
|
77
200
|
}
|
|
78
|
-
// Array content
|
|
201
|
+
// Array content. Claude Code switches a user turn from a plain string to
|
|
202
|
+
// an array of blocks the moment anything is attached — an image, most
|
|
203
|
+
// commonly. This loop used to look only for tool_result, so every such
|
|
204
|
+
// turn was dropped WHOLE: not just the image, but the question typed
|
|
205
|
+
// alongside it. Measured on the owner's own transcripts before the fix:
|
|
206
|
+
// 214 user turns and 413,471 characters of their own words never reached
|
|
207
|
+
// Engram, 106 of those turns because a screenshot was attached.
|
|
79
208
|
if (!Array.isArray(content))
|
|
80
209
|
return;
|
|
81
210
|
const messages = [];
|
|
211
|
+
const parts = [];
|
|
212
|
+
// Forgotten only once the withheld output is queued: when queuing
|
|
213
|
+
// fails, the watcher reads this line again, and the output must be
|
|
214
|
+
// withheld again (engram#584).
|
|
215
|
+
const withheldIds = [];
|
|
82
216
|
for (const block of content) {
|
|
83
|
-
if (block.type === "
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
217
|
+
if (block.type === "text" && block.text?.trim()) {
|
|
218
|
+
parts.push(block.text);
|
|
219
|
+
}
|
|
220
|
+
else if (block.type === "image") {
|
|
221
|
+
parts.push(describeImage(block));
|
|
222
|
+
}
|
|
223
|
+
else if (block.type === "tool_result") {
|
|
224
|
+
let withheld = false;
|
|
225
|
+
if (block.tool_use_id && this.secretToolIds.has(block.tool_use_id)) {
|
|
226
|
+
withheld = true;
|
|
227
|
+
withheldIds.push(block.tool_use_id);
|
|
228
|
+
}
|
|
229
|
+
const text = withheld
|
|
230
|
+
? REDACTED_TOOL_OUTPUT
|
|
231
|
+
: typeof block.content === "string"
|
|
232
|
+
? block.content
|
|
233
|
+
: JSON.stringify(block.content ?? "");
|
|
87
234
|
if (text.trim()) {
|
|
88
235
|
messages.push({
|
|
89
236
|
role: "tool",
|
|
@@ -93,51 +240,73 @@ export class Parser {
|
|
|
93
240
|
}
|
|
94
241
|
}
|
|
95
242
|
}
|
|
243
|
+
// The user's own words come first; tool results are the machinery that
|
|
244
|
+
// followed them.
|
|
245
|
+
if (parts.length > 0) {
|
|
246
|
+
messages.unshift({ role: "user", content: parts.join("\n\n") });
|
|
247
|
+
}
|
|
96
248
|
if (messages.length > 0) {
|
|
97
249
|
this.onMessages(sessionId, meta, messages);
|
|
98
250
|
}
|
|
251
|
+
for (const id of withheldIds)
|
|
252
|
+
this.secretToolIds.delete(id);
|
|
99
253
|
}
|
|
100
|
-
processAssistantLine(sessionId, meta, data) {
|
|
254
|
+
processAssistantLine(sessionId, meta, data, filePath, offset) {
|
|
101
255
|
const msg = data.message;
|
|
102
256
|
const messageId = msg.id ?? "";
|
|
103
257
|
const content = msg.content;
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
258
|
+
// A new message ID in this file ends the previous one
|
|
259
|
+
let pending = this.pending.get(filePath);
|
|
260
|
+
if (pending && pending.messageId !== messageId) {
|
|
261
|
+
this.flushPending(filePath);
|
|
262
|
+
pending = undefined;
|
|
107
263
|
}
|
|
108
264
|
// Initialize accumulator if needed
|
|
109
|
-
if (!
|
|
110
|
-
|
|
265
|
+
if (!pending) {
|
|
266
|
+
pending = { messageId, textParts: [], toolUses: [], sessionId, meta, from: offset };
|
|
267
|
+
this.pending.set(filePath, pending);
|
|
111
268
|
}
|
|
269
|
+
pending.sessionId = sessionId;
|
|
270
|
+
pending.meta = meta;
|
|
112
271
|
// Accumulate content blocks
|
|
113
272
|
if (typeof content === "string") {
|
|
114
273
|
if (content.trim()) {
|
|
115
|
-
|
|
274
|
+
pending.textParts.push(content);
|
|
116
275
|
}
|
|
117
276
|
}
|
|
118
277
|
else if (Array.isArray(content)) {
|
|
119
278
|
for (const block of content) {
|
|
120
279
|
if (block.type === "text" && block.text?.trim()) {
|
|
121
|
-
|
|
280
|
+
pending.textParts.push(block.text);
|
|
122
281
|
}
|
|
123
|
-
else if (block.type === "tool_use"
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
282
|
+
else if (block.type === "tool_use") {
|
|
283
|
+
if (block.name) {
|
|
284
|
+
pending.toolUses.push({
|
|
285
|
+
name: block.name,
|
|
286
|
+
input: block.input,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
this.trackSecretTool(block);
|
|
128
290
|
}
|
|
129
291
|
// Skip thinking blocks — internal reasoning, not conversation
|
|
130
292
|
}
|
|
131
293
|
}
|
|
132
294
|
// If stop_reason is set, message is complete
|
|
133
295
|
if (msg.stop_reason) {
|
|
134
|
-
this.flushPending();
|
|
296
|
+
this.flushPending(filePath);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
trackSecretTool(block) {
|
|
300
|
+
if (block.id && stringsOf(block.input).some((s) => REVEALS_SECRET.test(s))) {
|
|
301
|
+
this.secretToolIds.add(block.id);
|
|
135
302
|
}
|
|
136
303
|
}
|
|
137
|
-
flushPending() {
|
|
138
|
-
|
|
304
|
+
flushPending(filePath) {
|
|
305
|
+
const pending = this.pending.get(filePath);
|
|
306
|
+
if (!pending)
|
|
139
307
|
return;
|
|
140
|
-
|
|
308
|
+
this.pending.delete(filePath);
|
|
309
|
+
const { textParts, toolUses, sessionId, meta } = pending;
|
|
141
310
|
const messages = [];
|
|
142
311
|
// Emit text content as assistant message
|
|
143
312
|
const text = textParts.join("\n\n").trim();
|
|
@@ -148,22 +317,30 @@ export class Parser {
|
|
|
148
317
|
messages.push({ role: "assistant", content: text, metadata });
|
|
149
318
|
}
|
|
150
319
|
if (messages.length > 0) {
|
|
151
|
-
this.onMessages(
|
|
320
|
+
this.onMessages(sessionId, meta, messages);
|
|
152
321
|
}
|
|
153
|
-
this.pending = null;
|
|
154
322
|
}
|
|
155
323
|
extractProjectDir(filePath) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
324
|
+
return claudeProjectDir(filePath);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Project name from a Claude Code transcript path:
|
|
329
|
+
* ~/.claude/projects/-Users-op-code-engram/session.jsonl → "engram"
|
|
330
|
+
* C:\Users\op\.claude\projects\C--Users-op-code-engram\session.jsonl → "engram"
|
|
331
|
+
* (the last segment of the hyphen-encoded project directory). Either
|
|
332
|
+
* separator: split on "/" alone, every Windows conversation was filed under
|
|
333
|
+
* "unknown" (engram#602).
|
|
334
|
+
*/
|
|
335
|
+
export function claudeProjectDir(filePath) {
|
|
336
|
+
const parts = filePath.split(/[\\/]/);
|
|
337
|
+
const projectsIdx = parts.indexOf("projects");
|
|
338
|
+
if (projectsIdx >= 0 && projectsIdx + 1 < parts.length) {
|
|
339
|
+
const dirName = parts[projectsIdx + 1];
|
|
340
|
+
// Take the last segment of the hyphenated path
|
|
341
|
+
const segments = dirName.split("-").filter(Boolean);
|
|
342
|
+
return segments[segments.length - 1] ?? dirName;
|
|
167
343
|
}
|
|
344
|
+
return "unknown";
|
|
168
345
|
}
|
|
169
346
|
//# sourceMappingURL=parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/daemon/parser.ts"],"names":[],"mappings":"AAEA,8BAA8B;AAC9B,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,uBAAuB;IACvB,UAAU;IACV,iBAAiB;IACjB,aAAa;CACd,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/daemon/parser.ts"],"names":[],"mappings":"AAEA,8BAA8B;AAC9B,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,uBAAuB;IACvB,UAAU;IACV,iBAAiB;IACjB,aAAa;CACd,CAAC,CAAC;AAwBH;;;;;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CAAC;YAEhB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAEO,iBAAiB,CAAC,QAAgB;QACxC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,WAAW,IAAI,CAAC,IAAI,WAAW,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QACvD,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;QACvC,+CAA+C;QAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACpD,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC;IAClD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows PowerShell, for what Node can't do by itself on Windows: show a
|
|
3
|
+
* toast (status.ts, engram#614), and find out whose process a PID is and
|
|
4
|
+
* what it runs (instance.ts, engram#640).
|
|
5
|
+
*
|
|
6
|
+
* Whatever varies, such as a title or a PID, goes to the script in an
|
|
7
|
+
* environment variable, never into it, so nothing in it can become script.
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT: Node built-ins only. instance.ts imports this, and the worker
|
|
10
|
+
* claims its lock through instance.ts before the native-module preflight
|
|
11
|
+
* (see launch.ts).
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Windows PowerShell by its full path under the system root, never a
|
|
15
|
+
* powershell.exe found on PATH or in the working directory. It ships with
|
|
16
|
+
* every Windows 10 and 11.
|
|
17
|
+
*/
|
|
18
|
+
export declare function windowsPowerShellPath(systemRoot?: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* The arguments that run `statements`, one PowerShell statement each, with
|
|
21
|
+
* no profile and never a prompt. The statements have no double quotes,
|
|
22
|
+
* which the Windows command line would have to escape.
|
|
23
|
+
*/
|
|
24
|
+
export declare function powerShellArgs(statements: readonly string[]): string[];
|
|
25
|
+
//# sourceMappingURL=powershell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"powershell.d.ts","sourceRoot":"","sources":["../../src/daemon/powershell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,GAAE,MAAgD,GAAG,MAAM,CAE1G;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAEtE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows PowerShell, for what Node can't do by itself on Windows: show a
|
|
3
|
+
* toast (status.ts, engram#614), and find out whose process a PID is and
|
|
4
|
+
* what it runs (instance.ts, engram#640).
|
|
5
|
+
*
|
|
6
|
+
* Whatever varies, such as a title or a PID, goes to the script in an
|
|
7
|
+
* environment variable, never into it, so nothing in it can become script.
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT: Node built-ins only. instance.ts imports this, and the worker
|
|
10
|
+
* claims its lock through instance.ts before the native-module preflight
|
|
11
|
+
* (see launch.ts).
|
|
12
|
+
*/
|
|
13
|
+
import { win32 } from "node:path";
|
|
14
|
+
/**
|
|
15
|
+
* Windows PowerShell by its full path under the system root, never a
|
|
16
|
+
* powershell.exe found on PATH or in the working directory. It ships with
|
|
17
|
+
* every Windows 10 and 11.
|
|
18
|
+
*/
|
|
19
|
+
export function windowsPowerShellPath(systemRoot = process.env.SystemRoot || "C:\\Windows") {
|
|
20
|
+
return win32.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The arguments that run `statements`, one PowerShell statement each, with
|
|
24
|
+
* no profile and never a prompt. The statements have no double quotes,
|
|
25
|
+
* which the Windows command line would have to escape.
|
|
26
|
+
*/
|
|
27
|
+
export function powerShellArgs(statements) {
|
|
28
|
+
return ["-NoProfile", "-NonInteractive", "-Command", statements.join("; ")];
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=powershell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"powershell.js","sourceRoot":"","sources":["../../src/daemon/powershell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,aAAqB,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,aAAa;IAChG,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAC3F,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,UAA6B;IAC1D,OAAO,CAAC,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Make sure better-sqlite3 can actually load on this Node.
|
|
3
|
-
*
|
|
4
|
-
* The daemon's native module is compiled at install time against whatever
|
|
5
|
-
* Node ran npm/brew. When the runtime Node changes (brew upgrades to a new
|
|
6
|
-
* major, or the user switches between brew's Node and nvm's), the addon
|
|
7
|
-
* throws an ABI-mismatch error and — before this preflight — the daemon
|
|
8
|
-
* died silently in its log while `engram` commands that touch the local DB
|
|
9
|
-
* crashed outright. Now that capture is on by default, that failure mode
|
|
10
|
-
* has to self-heal.
|
|
11
|
-
*
|
|
12
|
-
* Strategy: try to load; on an ABI mismatch, run `npm rebuild
|
|
13
|
-
* better-sqlite3` in the package that owns it (better-sqlite3 ships
|
|
14
|
-
* prebuilds for common ABIs, so this is usually a quick download, not a
|
|
15
|
-
* compile) and try once more. Returns true when the module loads; false
|
|
16
|
-
* after printing the exact manual fix when it can't.
|
|
17
|
-
*/
|
|
18
1
|
export declare function ensureNativeSqlite(log?: (msg: string) => void): boolean;
|
|
19
2
|
//# sourceMappingURL=preflight.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preflight.d.ts","sourceRoot":"","sources":["../../src/daemon/preflight.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preflight.d.ts","sourceRoot":"","sources":["../../src/daemon/preflight.ts"],"names":[],"mappings":"AAmDA,wBAAgB,kBAAkB,CAChC,GAAG,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAA8B,GACnD,OAAO,CAwCT"}
|
package/dist/daemon/preflight.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { execSync } from "node:child_process";
|
|
3
3
|
import { dirname } from "node:path";
|
|
4
|
+
import { engramCommand } from "./package-runner.js";
|
|
4
5
|
// IMPORTANT: this module must never import better-sqlite3 (or anything
|
|
5
6
|
// that does) statically — its whole job is to run before the native
|
|
6
7
|
// module loads and heal an ABI mismatch.
|
|
@@ -17,15 +18,34 @@ const ABI_MISMATCH = /NODE_MODULE_VERSION|was compiled against a different Node\
|
|
|
17
18
|
* crashed outright. Now that capture is on by default, that failure mode
|
|
18
19
|
* has to self-heal.
|
|
19
20
|
*
|
|
20
|
-
* Strategy: try to
|
|
21
|
+
* Strategy: try to OPEN a database; on an ABI mismatch, run `npm rebuild
|
|
21
22
|
* better-sqlite3` in the package that owns it (better-sqlite3 ships
|
|
22
23
|
* prebuilds for common ABIs, so this is usually a quick download, not a
|
|
23
|
-
* compile) and try once more. Returns true when
|
|
24
|
-
* after printing the exact manual fix when it can't.
|
|
24
|
+
* compile) and try once more. Returns true when sqlite actually works;
|
|
25
|
+
* false after printing the exact manual fix when it can't.
|
|
26
|
+
*
|
|
27
|
+
* Opening a database is the whole point, and the reason this function was
|
|
28
|
+
* broken from the day it shipped. `require("better-sqlite3")` does NOT load
|
|
29
|
+
* the native addon — the binding is resolved lazily, on first construction.
|
|
30
|
+
* So the old check returned true on a machine whose addon could not load,
|
|
31
|
+
* the heal never ran, and the daemon died a few lines later inside
|
|
32
|
+
* worker-main with the exact error this was written to repair. The owner's
|
|
33
|
+
* machine crashlooped that way 2,358 times over three weeks (engram#496).
|
|
34
|
+
* Anything cheaper than `new Database(":memory:")` is not a real check.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Load the addon for real. An in-memory database touches no disk and is
|
|
38
|
+
* closed immediately, so this is cheap — and unlike a bare require() it
|
|
39
|
+
* actually dlopens the binary.
|
|
25
40
|
*/
|
|
41
|
+
function probeSqlite() {
|
|
42
|
+
const Database = req("better-sqlite3");
|
|
43
|
+
const db = new Database(":memory:");
|
|
44
|
+
db.close();
|
|
45
|
+
}
|
|
26
46
|
export function ensureNativeSqlite(log = (m) => console.error(m)) {
|
|
27
47
|
try {
|
|
28
|
-
|
|
48
|
+
probeSqlite();
|
|
29
49
|
return true;
|
|
30
50
|
}
|
|
31
51
|
catch (err) {
|
|
@@ -43,15 +63,21 @@ export function ensureNativeSqlite(log = (m) => console.error(m)) {
|
|
|
43
63
|
cwd: ownerDir,
|
|
44
64
|
stdio: "pipe",
|
|
45
65
|
timeout: 180_000,
|
|
66
|
+
// The daemon has no console; on Windows a rebuild would otherwise
|
|
67
|
+
// open one, and the compiler's, in front of the user (engram#602).
|
|
68
|
+
windowsHide: true,
|
|
46
69
|
});
|
|
47
|
-
|
|
70
|
+
// Re-probe, not re-require: the failed module stays in require's
|
|
71
|
+
// cache, so only a fresh open proves the rebuild took.
|
|
72
|
+
delete req.cache?.[req.resolve("better-sqlite3")];
|
|
73
|
+
probeSqlite();
|
|
48
74
|
log("better-sqlite3 rebuilt for this Node — continuing.");
|
|
49
75
|
return true;
|
|
50
76
|
}
|
|
51
77
|
catch {
|
|
52
78
|
log("Automatic rebuild failed. Fix manually with:\n" +
|
|
53
79
|
` cd ${ownerDir || "<the directory containing node_modules/better-sqlite3>"} && npm rebuild better-sqlite3\n` +
|
|
54
|
-
|
|
80
|
+
`then run '${engramCommand("start")}' again.`);
|
|
55
81
|
return false;
|
|
56
82
|
}
|
|
57
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preflight.js","sourceRoot":"","sources":["../../src/daemon/preflight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"preflight.js","sourceRoot":"","sources":["../../src/daemon/preflight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,uEAAuE;AACvE,oEAAoE;AACpE,yCAAyC;AAEzC,MAAM,GAAG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