passcontrol 1.7.2 → 1.9.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.
@@ -0,0 +1,444 @@
1
+ // Idea 13: memory with a chain of custody. The pure core, shared by the sidecar (Node)
2
+ // and the gateway (edge): no `node:` imports, no network, no clock.
3
+ //
4
+ // Three things live here, and nothing else:
5
+ //
6
+ // 1. ENTRIES. A memory file (CLAUDE.md, AGENTS.md, MEMORY.md, a note in a memory folder)
7
+ // is split into entries, so an honest edit to one paragraph does not orphan the rest.
8
+ // An entry is a heading line, a paragraph, a top-level list item with its continuation
9
+ // lines, a fenced block (blank lines included), or YAML front matter. Its identity binds
10
+ // the parser version, its heading ancestry, its exact text, its file and which
11
+ // duplicate it is. Not a CommonMark parser, and not a semantic model: a reorder inside
12
+ // one heading changes no key, and can still change meaning (RED-TEAM.md, accepted limit).
13
+ //
14
+ // Normalised, because it is transport and cannot carry an instruction: CRLF and CR to
15
+ // LF; ASCII spaces and tabs at the end of a line; lines that are only ASCII spaces and
16
+ // tabs, between entries. Nothing else. No NFC, no NFKC, no case folding: a lookalike
17
+ // letter or an invisible character is a different key, so it arrives. Folding would
18
+ // run the risk the wrong way, making a hostile variant equal to an accepted entry.
19
+ //
20
+ // 2. KEYS. HMAC-SHA256 under a per-device salt the gateway never sees: only these hashes
21
+ // leave the machine, and a guessable note ("use pnpm") cannot be confirmed by hashing
22
+ // it at the gateway.
23
+ //
24
+ // 3. OUTSIDE CONTENT. Which tool calls put content from outside the owner and this
25
+ // machine into the session's context. Decided from the TOOL and where its data came
26
+ // from (a URL's host, a network command), never from what the content says. So a
27
+ // payload that fools every scanner is stamped anyway: the whole point (property 1).
28
+ // A classifier may rank or explain an arrival later; it never decides one exists.
29
+ import { hmac } from "@noble/hashes/hmac";
30
+ import { sha256 } from "@noble/hashes/sha256";
31
+
32
+ export const PARSER_VERSION = 1;
33
+
34
+ const enc = new TextEncoder();
35
+ const hex = (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
36
+ export const sha256Hex = (text) => hex(sha256(enc.encode(text)));
37
+ export const hmacHex = (saltHex, text) => hex(hmac(sha256, hexToBytes(saltHex), enc.encode(text)));
38
+
39
+ function hexToBytes(h) {
40
+ if (typeof h !== "string" || !/^[0-9a-f]{64}$/.test(h)) throw new Error("custody salt must be 32 bytes of hex");
41
+ const out = new Uint8Array(32);
42
+ for (let i = 0; i < 32; i++) out[i] = parseInt(h.slice(i * 2, i * 2 + 2), 16);
43
+ return out;
44
+ }
45
+
46
+ // ── 1. Entries ──────────────────────────────────────────────────────────────────
47
+
48
+ const FENCE_OPEN = /^ {0,3}(`{3,}|~{3,})/;
49
+ const HEADING = /^ {0,3}(#{1,6})(?:[ \t]|$)/;
50
+ // Top-level: at most one space of indent. Deeper items are continuation lines.
51
+ const LIST_ITEM = /^ ?(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/;
52
+ const isBlank = (line) => /^[ \t]*$/.test(line);
53
+
54
+ /**
55
+ * The entries of one memory file, in order: `{ text, scope, digest, occurrence }`.
56
+ * `digest` binds the parser version, the heading ancestry and the text; `occurrence`
57
+ * counts identical digests in this file (1, 2, …).
58
+ */
59
+ export function memoryEntries(raw) {
60
+ const lines = String(raw ?? "")
61
+ .replace(/\r\n?/g, "\n")
62
+ .split("\n")
63
+ .map((l) => l.replace(/[ \t]+$/, ""));
64
+ const out = [];
65
+ const headings = [];
66
+ let scope = [];
67
+ let buffer = [];
68
+ let bufStart = 0;
69
+ // `start`/`end`: the entry's first and last line (0-based), so it can be cut out exactly.
70
+ const flush = (endLine) => {
71
+ if (buffer.length) out.push({ text: buffer.join("\n"), scope: [...scope], start: bufStart, end: endLine });
72
+ buffer = [];
73
+ };
74
+ const push = (line, at) => {
75
+ if (!buffer.length) bufStart = at;
76
+ buffer.push(line);
77
+ };
78
+
79
+ let i = 0;
80
+ // Front matter: one entry, only at the very top.
81
+ if (lines[0] === "---") {
82
+ const end = lines.indexOf("---", 1);
83
+ if (end > 0) {
84
+ bufStart = 0;
85
+ buffer = lines.slice(0, end + 1);
86
+ flush(end);
87
+ i = end + 1;
88
+ }
89
+ }
90
+
91
+ let fence = null; // the opening marker while inside a fenced block
92
+ for (; i < lines.length; i++) {
93
+ const line = lines[i];
94
+ if (fence) {
95
+ push(line, i);
96
+ const m = line.match(FENCE_OPEN);
97
+ if (m && m[1][0] === fence[0] && m[1].length >= fence.length && /^ {0,3}(`+|~+)[ \t]*$/.test(line)) {
98
+ fence = null;
99
+ flush(i);
100
+ }
101
+ continue;
102
+ }
103
+ if (isBlank(line)) {
104
+ flush(i - 1);
105
+ continue;
106
+ }
107
+ const open = line.match(FENCE_OPEN);
108
+ if (open) {
109
+ flush(i - 1);
110
+ fence = open[1];
111
+ push(line, i);
112
+ continue;
113
+ }
114
+ const heading = line.match(HEADING);
115
+ if (heading) {
116
+ flush(i - 1);
117
+ const level = heading[1].length;
118
+ while (headings.length && headings[headings.length - 1].level >= level) headings.pop();
119
+ headings.push({ level, title: line.trim() });
120
+ scope = headings.map((h) => h.title);
121
+ push(line, i);
122
+ flush(i);
123
+ continue;
124
+ }
125
+ if (LIST_ITEM.test(line)) {
126
+ flush(i - 1);
127
+ push(line, i);
128
+ continue;
129
+ }
130
+ // A paragraph line, or a list item's continuation (indented or lazy).
131
+ push(line, i);
132
+ }
133
+ flush(lines.length - 1); // an unclosed fence runs to the end of the file: nothing can hide after it
134
+
135
+ const seen = new Map();
136
+ return out.map((e) => {
137
+ const digest = sha256Hex(JSON.stringify(["pc-memory-entry", PARSER_VERSION, "blocks", e.scope, e.text]));
138
+ const occurrence = (seen.get(digest) ?? 0) + 1;
139
+ seen.set(digest, occurrence);
140
+ return { ...e, digest, occurrence };
141
+ });
142
+ }
143
+
144
+ // ── 2. Keys ─────────────────────────────────────────────────────────────────────
145
+
146
+ /** A file's key: its logical id (e.g. `project:CLAUDE.md`) under the device's salt. */
147
+ export const fileKey = (salt, fileId) => hmacHex(salt, JSON.stringify(["pc-memory-file", PARSER_VERSION, fileId]));
148
+
149
+ /** Each entry's key, binding the file and the duplicate count. Only these leave the machine. */
150
+ export function entryKeys(salt, fileId, entries) {
151
+ return entries.map((e) => hmacHex(salt, JSON.stringify(["pc-memory-key", PARSER_VERSION, fileId, e.digest, e.occurrence])));
152
+ }
153
+
154
+ /**
155
+ * The salt's public fingerprint: lets the gateway see a salt change without learning it.
156
+ * It binds the parser version too, so a parser upgrade (which changes every key) reads as
157
+ * one integrity fault the owner re-enrols from, not as every entry arriving (red team R2-2).
158
+ */
159
+ export const saltFingerprint = (salt, version = PARSER_VERSION) => hmacHex(salt, `pc-memory-salt-fingerprint\u0000v${version}`);
160
+
161
+ /** Keys in `next` that `prev` did not have, in `next`'s order. */
162
+ export function diffKeys(prev, next) {
163
+ const had = new Set(prev);
164
+ return next.filter((k) => !had.has(k));
165
+ }
166
+
167
+ // ── 3. Outside content ──────────────────────────────────────────────────────────
168
+
169
+ /** Exactly loopback: `localhost`, 127.0.0.0/8, ::1, 0.0.0.0. Never a name that merely starts so. */
170
+ export function isLoopbackHost(host) {
171
+ const h = String(host ?? "").toLowerCase().replace(/^\[|\]$/g, "");
172
+ if (h === "localhost" || h === "::1" || h === "0.0.0.0") return true;
173
+ return /^127\.(?:\d{1,3})\.(?:\d{1,3})\.(?:\d{1,3})$/.test(h) && h.split(".").every((p) => Number(p) <= 255);
174
+ }
175
+
176
+ function urlHost(value) {
177
+ try {
178
+ return new URL(String(value)).hostname.toLowerCase();
179
+ } catch {
180
+ return null;
181
+ }
182
+ }
183
+
184
+ const NETWORK_PROGRAMS = new Set([
185
+ "curl", "wget", "gh", "ssh", "scp", "sftp", "ftp", "nc", "ncat", "netcat", "telnet", "http", "https", "xh",
186
+ "aria2c", "lynx", "w3m", "links", "mail", "mutt", "himalaya", "aws", "gcloud", "gsutil", "az", "doctl",
187
+ "kubectl", "vercel", "supabase", "glab", "hub", "tea", "yt-dlp", "socat",
188
+ ]);
189
+ const GIT_NETWORK = new Set(["clone", "fetch", "pull", "ls-remote", "submodule", "remote"]);
190
+ const PACKAGE_INFO = new Set(["view", "info", "show", "search", "docs", "repo"]);
191
+ const INTERPRETERS = new Set(["python", "python3", "node", "ruby", "perl", "php", "deno", "bun", "pwsh", "osascript"]);
192
+ const PREFIXES = new Set(["sudo", "env", "time", "nohup", "exec", "command", "nice", "timeout", "stdbuf", "xargs", "builtin"]);
193
+
194
+ const basename = (word) => word.replace(/^.*\//, "");
195
+ const words = (segment) => segment.trim().split(/\s+/).filter(Boolean).map((w) => w.replace(/^['"(]+|['")]+$/g, ""));
196
+
197
+ /** Every http(s) host literally named in a command, lowercased. */
198
+ function commandHosts(text) {
199
+ const hosts = [];
200
+ for (const m of String(text).matchAll(/https?:\/\/(\[[^\]\s]+\]|[^/\s'"`:)]+)/gi)) hosts.push(m[1].toLowerCase());
201
+ return hosts;
202
+ }
203
+
204
+ /**
205
+ * Whether a shell command pulls content from the network into its output: a label for
206
+ * the source (`"curl"`, `"git fetch"`, `"python3 url"`) or null. A provenance rule over
207
+ * the command, not over what comes back. It sees programs it knows; a program that
208
+ * fetches without saying so is the limit named in RED-TEAM.md (L4).
209
+ */
210
+ export function bashNetworkSource(command) {
211
+ const text = String(command ?? "");
212
+ // Split into simple commands, including inside $( … ) and backticks.
213
+ const segments = text.split(/\$\(|`|&&|\|\||[;|&\n]/);
214
+ let interpreter = null;
215
+ for (const segment of segments) {
216
+ const w = words(segment);
217
+ let k = 0;
218
+ while (k < w.length && (/^[A-Za-z_][A-Za-z0-9_]*=/.test(w[k]) || PREFIXES.has(w[k]) || /^-/.test(w[k]) && k > 0 && PREFIXES.has(w[k - 1]))) k++;
219
+ if (k >= w.length) continue;
220
+ const program = basename(w[k]);
221
+ const args = w.slice(k + 1);
222
+ if (program === "curl" || program === "wget" || program === "http" || program === "xh") {
223
+ const hosts = commandHosts(segment);
224
+ if (hosts.length && hosts.every(isLoopbackHost)) continue;
225
+ return program;
226
+ }
227
+ if (NETWORK_PROGRAMS.has(program)) return program;
228
+ if (program === "git") {
229
+ // Skip global options (`-C dir`, `-c k=v`) to the subcommand.
230
+ let j = 0;
231
+ while (j < args.length && args[j].startsWith("-")) j += args[j] === "-C" || args[j] === "-c" ? 2 : 1;
232
+ const sub = args[j];
233
+ if (GIT_NETWORK.has(sub)) return `git ${sub}`;
234
+ continue;
235
+ }
236
+ if (["npm", "pnpm", "yarn"].includes(program) && PACKAGE_INFO.has(args[0])) return `${program} ${args[0]}`;
237
+ if (program === "pip" || program === "pip3") {
238
+ if (args[0] === "download") return "pip download";
239
+ continue;
240
+ }
241
+ if (program === "docker" && (args[0] === "pull" || args[0] === "search")) return `docker ${args[0]}`;
242
+ // An interpreter's program text may itself contain `;`, so its URL is looked for in
243
+ // the whole command, not in the segment the split left it.
244
+ if (INTERPRETERS.has(program)) interpreter ??= program;
245
+ }
246
+ if (interpreter && commandHosts(text).some((h) => !isLoopbackHost(h))) return `${interpreter} url`;
247
+ return null;
248
+ }
249
+
250
+ /** POSIX path normalisation with no `node:path` (edge-safe). */
251
+ export function normalizePath(p, cwd = "/") {
252
+ const abs = String(p).startsWith("/") ? String(p) : `${cwd}/${p}`;
253
+ const parts = [];
254
+ for (const part of abs.split("/")) {
255
+ if (!part || part === ".") continue;
256
+ if (part === "..") parts.pop();
257
+ else parts.push(part);
258
+ }
259
+ return `/${parts.join("/")}`;
260
+ }
261
+ const within = (path, root) => path === root || path.startsWith(root.endsWith("/") ? root : `${root}/`);
262
+
263
+ const READ_TOOLS = new Set(["Read", "Grep", "NotebookRead"]);
264
+
265
+ /**
266
+ * The outside-content marks one tool call adds to its session: `[{ kind, host? }]`.
267
+ *
268
+ * web WebFetch to a non-loopback host, WebSearch
269
+ * mcp any MCP tool (browser automation included: a page shows whatever it shows)
270
+ * shell_network a shell command that pulls from the network (bashNetworkSource)
271
+ * outside_read with `outsideReads`, a Read/Grep outside the workspace and the agent's own roots
272
+ * workspace_read with `workspaceTrust: "third_party"`, any read or shell call in the workspace
273
+ *
274
+ * `ctx`: `{ cwd, outsideReads?, localRoots?, workspaceTrust? }`.
275
+ */
276
+ export function outsideMarks(event, ctx = {}) {
277
+ const tool = String(event?.tool_name ?? "");
278
+ const input = event?.tool_input && typeof event.tool_input === "object" ? event.tool_input : {};
279
+ if (tool === "WebFetch") {
280
+ const host = urlHost(input.url);
281
+ if (host && isLoopbackHost(host)) return [];
282
+ return [host ? { kind: "web", host: host.slice(0, 253) } : { kind: "web" }];
283
+ }
284
+ if (tool === "WebSearch") return [{ kind: "web" }];
285
+ if (tool.startsWith("mcp__") && tool.length > 5) {
286
+ const server = tool.slice(5).split("__")[0];
287
+ return [server ? { kind: "mcp", host: server.slice(0, 64) } : { kind: "mcp" }];
288
+ }
289
+ if (ctx.workspaceTrust === "third_party" && (READ_TOOLS.has(tool) || tool === "Bash" || tool === "Glob")) {
290
+ return [{ kind: "workspace_read" }];
291
+ }
292
+ if (tool === "Bash" || tool === "BashOutput") {
293
+ const source = bashNetworkSource(input.command);
294
+ return source ? [{ kind: "shell_network", host: source }] : [];
295
+ }
296
+ if (ctx.outsideReads && READ_TOOLS.has(tool)) {
297
+ const target = input.file_path ?? input.path ?? input.notebook_path;
298
+ if (typeof target !== "string" || !ctx.cwd) return [];
299
+ const path = normalizePath(target, ctx.cwd);
300
+ const roots = [ctx.cwd, ...(ctx.localRoots ?? [])].map((r) => normalizePath(r));
301
+ if (roots.some((r) => within(path, r))) return [];
302
+ return [{ kind: "outside_read" }];
303
+ }
304
+ return [];
305
+ }
306
+
307
+ // ── API mode: what the model was actually given ─────────────────────────────────
308
+
309
+ const SECTION = /Contents of (\/[^\n]*?) \(([^\n]*)\):\n\n/g;
310
+
311
+ /**
312
+ * Claude Code's memory sections inside an Anthropic Messages request body:
313
+ * `[{ path, text }]`. Only from the system prompt and the user's own text blocks, never
314
+ * from a tool result: a tool result that quotes the marker is content, not a load.
315
+ */
316
+ export function requestMemorySections(body) {
317
+ const texts = [];
318
+ const take = (block) => {
319
+ if (typeof block === "string") texts.push(block);
320
+ else if (block && typeof block === "object" && block.type === "text" && typeof block.text === "string") texts.push(block.text);
321
+ };
322
+ if (typeof body?.system === "string") texts.push(body.system);
323
+ else if (Array.isArray(body?.system)) body.system.forEach(take);
324
+ for (const message of Array.isArray(body?.messages) ? body.messages : []) {
325
+ if (message?.role !== "user") continue;
326
+ if (typeof message.content === "string") texts.push(message.content);
327
+ else if (Array.isArray(message.content)) message.content.forEach(take);
328
+ }
329
+ const out = [];
330
+ for (const text of texts) {
331
+ const marks = [...text.matchAll(SECTION)];
332
+ marks.forEach((m, n) => {
333
+ const start = m.index + m[0].length;
334
+ const next = n + 1 < marks.length ? marks[n + 1].index : text.length;
335
+ let section = text.slice(start, next);
336
+ const close = section.indexOf("</system-reminder>");
337
+ if (close >= 0) section = section.slice(0, close);
338
+ out.push({ path: m[1], text: section.replace(/\s+$/, "") });
339
+ });
340
+ }
341
+ return out;
342
+ }
343
+
344
+ // ── Direction 1: withhold pending entries from what the model reads ─────────────
345
+
346
+ export const WITHHELD_ENTRY = (n) =>
347
+ `[PassControl withheld ${n} memory ${n === 1 ? "entry" : "entries"} here: waiting for the owner's review. Do not try to recover ${n === 1 ? "it" : "them"}.]`;
348
+ export const WITHHELD_LINE = "[PassControl withheld a line of a memory entry waiting for the owner's review]";
349
+ // Claude Code's Read prints ` 1\ttext` (or ` 12→text` in newer versions): match the text after the number.
350
+ const NUMBERED = /^(\s*\d+(?:\t|\u2192))(.*)$/;
351
+
352
+ /**
353
+ * A copy of an Anthropic Messages request with pending memory taken out (idea 13, direction 1).
354
+ *
355
+ * - every Claude Code memory section ("Contents of <path> (…):") in the system prompt or the
356
+ * user's text is parsed with the SAME parser as the disk (so the keys agree), and
357
+ * `decide({ path, entries })` names the entries to cut (a Set of indices, or "all");
358
+ * - every tool result has any line equal to one of `stripLines` replaced (a Read of a memory
359
+ * file shows its lines, numbered or not);
360
+ * - `probes` (pending text) still found anywhere in the result is counted as `residue`: text
361
+ * that could not be cut, so the caller holds instead.
362
+ * The input is not mutated.
363
+ */
364
+ export function withholdRequest(body, { decide, stripLines = [], probes = [] }) {
365
+ const copy = structuredClone(body);
366
+ let sectionsChanged = 0, entriesWithheld = 0, linesWithheld = 0;
367
+ const strip = new Set(stripLines.map((l) => String(l).replace(/[ \t]+$/, "")).filter((l) => l.trim().length >= 6));
368
+
369
+ const cutSections = (text) => {
370
+ const marks = [...text.matchAll(SECTION)];
371
+ if (!marks.length) return text;
372
+ let out = "";
373
+ let cursor = 0;
374
+ marks.forEach((m, n) => {
375
+ const start = m.index + m[0].length;
376
+ let end = n + 1 < marks.length ? marks[n + 1].index : text.length;
377
+ const close = text.slice(start, end).indexOf("</system-reminder>");
378
+ if (close >= 0) end = start + close;
379
+ const section = text.slice(start, end);
380
+ const entries = memoryEntries(section);
381
+ const verdict = decide({ path: m[1], entries });
382
+ const cut = verdict === "all" ? new Set(entries.map((_, k) => k)) : verdict ?? new Set();
383
+ out += text.slice(cursor, start);
384
+ if (!cut.size) {
385
+ out += section;
386
+ } else {
387
+ const raw = section.split(/\r\n|\r|\n/);
388
+ const drop = new Set();
389
+ let firstCut = Infinity;
390
+ for (const k of cut) {
391
+ const e = entries[k];
392
+ if (!e) continue;
393
+ for (let l = e.start; l <= e.end; l++) drop.add(l);
394
+ firstCut = Math.min(firstCut, e.start);
395
+ }
396
+ const kept = [];
397
+ raw.forEach((line, l) => {
398
+ if (l === firstCut) kept.push(WITHHELD_ENTRY(cut.size));
399
+ if (!drop.has(l)) kept.push(line);
400
+ });
401
+ out += kept.join("\n");
402
+ sectionsChanged++;
403
+ entriesWithheld += cut.size;
404
+ }
405
+ cursor = end;
406
+ });
407
+ return out + text.slice(cursor);
408
+ };
409
+ const cutLines = (text) => {
410
+ if (!strip.size) return text;
411
+ return text
412
+ .split("\n")
413
+ .map((line) => {
414
+ const m = line.replace(/\r$/, "").match(NUMBERED);
415
+ const bare = (m ? m[2] : line.replace(/\r$/, "")).replace(/[ \t]+$/, "");
416
+ // A long pending line shown cut short (Read truncates very long lines) is cut too (R4-3).
417
+ const hit = strip.has(bare) || (bare.length >= 32 && [...strip].some((l) => l.startsWith(bare)));
418
+ if (!hit) return line;
419
+ linesWithheld++;
420
+ return m ? `${m[1]}${WITHHELD_LINE}` : WITHHELD_LINE;
421
+ })
422
+ .join("\n");
423
+ };
424
+
425
+ if (typeof copy?.system === "string") copy.system = cutSections(copy.system);
426
+ else if (Array.isArray(copy?.system)) for (const b of copy.system) if (b?.type === "text" && typeof b.text === "string") b.text = cutSections(b.text);
427
+ for (const message of Array.isArray(copy?.messages) ? copy.messages : []) {
428
+ if (message?.role !== "user") continue;
429
+ if (typeof message.content === "string") {
430
+ message.content = cutSections(message.content);
431
+ continue;
432
+ }
433
+ for (const b of Array.isArray(message.content) ? message.content : []) {
434
+ if (b?.type === "text" && typeof b.text === "string") b.text = cutSections(b.text);
435
+ if (b?.type === "tool_result") {
436
+ if (typeof b.content === "string") b.content = cutLines(b.content);
437
+ else if (Array.isArray(b.content)) for (const c of b.content) if (c?.type === "text" && typeof c.text === "string") c.text = cutLines(c.text);
438
+ }
439
+ }
440
+ }
441
+ const serialized = JSON.stringify(copy);
442
+ const residue = probes.filter((p) => String(p).trim().length >= 16 && serialized.includes(JSON.stringify(String(p).trim()).slice(1, -1))).length;
443
+ return { body: copy, sectionsChanged, entriesWithheld, linesWithheld, residue };
444
+ }
@@ -0,0 +1,15 @@
1
+ export const FILE_LIMIT_BYTES: number;
2
+ export const TOTAL_LIMIT_BYTES: number;
3
+ export const MAX_FILES: number;
4
+ export const LABELS: string[];
5
+ export function custodySalt(options?: { env?: Record<string, string | undefined> }): string;
6
+ export function workspaceRoot(cwd: string): string;
7
+ export function claudeProjectDirName(root: string): string;
8
+ export function importsOf(text: string): string[];
9
+ export interface MemoryFile { id: string; label: string; path: string }
10
+ export function memoryFiles(options: { cwd: string; agent?: "claude-code" | "codex"; env?: Record<string, string | undefined>; ownerPaths?: string[]; touchedDirs?: string[]; touchedFiles?: string[] }): { root: string; files: MemoryFile[]; overflow: boolean; truncated: boolean };
11
+ export interface ScannedFile { id: string; label: string; path: string; fileKey: string; keys: string[]; entries: { key: string; text: string; scope: string[] }[]; bytes: number; link: boolean }
12
+ export interface Scan { root: string; workspace: string; saltFp: string; files: ScannedFile[]; errors: { id: string; label: string; reason: string }[] }
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ export function scanMemory(options: { salt: string; cwd: string; agent?: "claude-code" | "codex"; env?: Record<string, string | undefined>; ownerPaths?: string[]; touchedDirs?: string[]; touchedFiles?: string[] }): any;
15
+ export function scanKeys(scan: Scan): string[];