@nightloom/isy 1.0.2 → 1.0.4
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 +1 -1
- package/dist/agents/codex-records.js +13 -1
- package/dist/agents/codex-records.js.map +1 -1
- package/dist/api.d.ts +3 -0
- package/dist/api.js +5 -2
- package/dist/api.js.map +1 -1
- package/dist/commands/health.js +2 -2
- package/dist/commands/health.js.map +1 -1
- package/dist/commands/init.js +9 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/upload.d.ts +2 -0
- package/dist/commands/upload.js +30 -3
- package/dist/commands/upload.js.map +1 -1
- package/dist/detectors.js +10 -4
- package/dist/detectors.js.map +1 -1
- package/dist/mask-paths.js +36 -16
- package/dist/mask-paths.js.map +1 -1
- package/dist/parser.d.ts +5 -0
- package/dist/parser.js +21 -8
- package/dist/parser.js.map +1 -1
- package/dist/plan.d.ts +3 -1
- package/dist/plan.js +5 -1
- package/dist/plan.js.map +1 -1
- package/dist/queue.d.ts +14 -2
- package/dist/queue.js +25 -3
- package/dist/queue.js.map +1 -1
- package/dist/redact.d.ts +7 -0
- package/dist/redact.js +281 -8
- package/dist/redact.js.map +1 -1
- package/dist/state.d.ts +9 -3
- package/dist/state.js +4 -4
- package/dist/state.js.map +1 -1
- package/dist/subagents.d.ts +8 -4
- package/dist/subagents.js +13 -7
- package/dist/subagents.js.map +1 -1
- package/dist/test/codex.test.js +15 -0
- package/dist/test/codex.test.js.map +1 -1
- package/dist/test/init.test.js +9 -0
- package/dist/test/init.test.js.map +1 -1
- package/dist/test/mask-paths.test.js +45 -0
- package/dist/test/mask-paths.test.js.map +1 -1
- package/dist/test/parser.test.js +16 -0
- package/dist/test/parser.test.js.map +1 -1
- package/dist/test/plan.test.js +7 -6
- package/dist/test/plan.test.js.map +1 -1
- package/dist/test/redact.test.js +239 -11
- package/dist/test/redact.test.js.map +1 -1
- package/dist/test/stage0.test.js +11 -0
- package/dist/test/stage0.test.js.map +1 -1
- package/dist/test/subagents.test.js +18 -0
- package/dist/test/subagents.test.js.map +1 -1
- package/dist/test/sweep.test.js +33 -0
- package/dist/test/sweep.test.js.map +1 -1
- package/dist/test/upload.test.js +68 -6
- package/dist/test/upload.test.js.map +1 -1
- package/package.json +3 -2
- package/src/agents/codex-records.ts +14 -1
- package/src/api.ts +9 -3
- package/src/commands/health.ts +2 -2
- package/src/commands/init.ts +9 -0
- package/src/commands/upload.ts +38 -3
- package/src/detectors.ts +9 -4
- package/src/mask-paths.ts +36 -15
- package/src/parser.ts +17 -8
- package/src/plan.ts +4 -1
- package/src/queue.ts +30 -4
- package/src/redact.ts +287 -9
- package/src/state.ts +10 -4
- package/src/subagents.ts +20 -11
package/src/redact.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import { basename } from "node:path";
|
|
3
3
|
import { fileLines } from "./lines.js";
|
|
4
|
+
import { HEREDOC, commandSegments, withoutHeredocs } from "./parser.js";
|
|
4
5
|
import {
|
|
5
6
|
PATH_KEYS,
|
|
6
7
|
REDACTION_MARKER,
|
|
@@ -22,10 +23,44 @@ export interface RedactionRule {
|
|
|
22
23
|
replacement: string;
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
/** `[pP][aA]…`: case by hand, so a rule can still tell a camelCase hump from a glued prefix. */
|
|
27
|
+
function anyCase(source: string): string {
|
|
28
|
+
return source.replace(/[a-z]/g, (letter) => `[${letter}${letter.toUpperCase()}]`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const SECRET_WORD = anyCase("(?:password|passwd|secret|token|api[-_]?key|private[-_]?key|access[-_]?key)");
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A name that holds a secret: one of the words, wherever it sits in an
|
|
35
|
+
* identifier — `PGPASSWORD`, `STRIPE_SECRET_KEY`, `aws_secret_access_key`,
|
|
36
|
+
* `x-api-key` — and followed by nothing but `KEY` and `BASE` (`SECRET_KEY_BASE`).
|
|
37
|
+
* That tail is the line between the secret and what is said about it:
|
|
38
|
+
* `tokenHash`, `max_tokens`, `TOKENS_PER_ANALYSIS` and `PASSWORD_FILE` turn up
|
|
39
|
+
* in a real corpus as often as the secrets do, and none of them is one.
|
|
40
|
+
*/
|
|
41
|
+
function secretName(atWord = ""): string {
|
|
42
|
+
return String.raw`[A-Za-z0-9_.-]*?${atWord}${SECRET_WORD}${anyCase("(?:[-_]?key)?(?:[-_]?base)?")}(?![A-Za-z0-9_.-])`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The word glued to what came before, but not as a camelCase hump. */
|
|
46
|
+
const PLAIN_NAME = secretName("(?!(?<=[a-z0-9])[A-Z])");
|
|
47
|
+
/** `adminPassword`, `_authToken`: as often a variable in code as a key in a file. */
|
|
48
|
+
const CAMEL_NAME = secretName("(?<=[a-z0-9])(?=[A-Z])");
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* What an assigned secret looks like: long enough to be one, and not code. A
|
|
52
|
+
* bare number under a quoted name is JSON's own (`"token": 1234567890`), where a
|
|
53
|
+
* secret would be a string; anywhere else a number is a password like any other
|
|
54
|
+
* — `DB_PASSWORD=1234567890123`, `MYSQL_ROOT_PASSWORD: 12345678`. The digit is
|
|
55
|
+
* looked for first so the lookbehind runs only where a number starts.
|
|
56
|
+
*/
|
|
57
|
+
const SECRET_VALUE = String.raw`(?!\[ISY_REDACTED)(?!(?=-?\d)(?<=["']\s*:\s*)-?\d[\d.,eE+-]*(?![^\s"'{}()[\]<>$]))[^\s"'{}()[\]<>$]{8,}`;
|
|
58
|
+
|
|
25
59
|
export const BUILTIN_RULES: RedactionRule[] = [
|
|
26
60
|
{
|
|
27
61
|
type: "private_key",
|
|
28
|
-
|
|
62
|
+
// `BLOCK` is how PGP armors one.
|
|
63
|
+
pattern: /-----BEGIN [A-Z0-9 ]*PRIVATE KEY(?: BLOCK)?-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY(?: BLOCK)?-----|$)/g,
|
|
29
64
|
replacement: marker("private_key"),
|
|
30
65
|
},
|
|
31
66
|
{
|
|
@@ -64,25 +99,67 @@ export const BUILTIN_RULES: RedactionRule[] = [
|
|
|
64
99
|
replacement: marker("google_key"),
|
|
65
100
|
},
|
|
66
101
|
{
|
|
102
|
+
// Secret and restricted keys; `pk_` is publishable by design.
|
|
103
|
+
type: "stripe_key",
|
|
104
|
+
pattern: /\b[rs]k_(?:live|test)_[A-Za-z0-9]{16,}/g,
|
|
105
|
+
replacement: marker("stripe_key"),
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: "slack_token",
|
|
109
|
+
pattern: /\bxox[abposr]-[A-Za-z0-9-]{10,}/g,
|
|
110
|
+
replacement: marker("slack_token"),
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
type: "npm_token",
|
|
114
|
+
pattern: /\bnpm_[A-Za-z0-9]{36}\b/g,
|
|
115
|
+
replacement: marker("npm_token"),
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
// After every shape a bearer token can have, so a JWT or a GitHub token
|
|
119
|
+
// keeps its own label and its marker is not marked again.
|
|
120
|
+
type: "bearer_token",
|
|
121
|
+
pattern: /\b(Bearer\s+)(?!\[ISY_REDACTED)[A-Za-z0-9._~+/-]{20,}=*/gi,
|
|
122
|
+
replacement: `$1${marker("bearer_token")}`,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
// Any scheme: a password in a URL is one whatever speaks it — rediss,
|
|
126
|
+
// amqps, https to a bare IP. The scheme is capped because `\b` lets a match
|
|
127
|
+
// start inside a dotted or dashed run: unbounded, every start rescans the
|
|
128
|
+
// rest of the run, and a long one costs minutes.
|
|
67
129
|
type: "connection_string",
|
|
68
|
-
pattern: /\b(
|
|
130
|
+
pattern: /\b([A-Za-z][A-Za-z0-9+.-]{0,31}):\/\/([^\s:/@]+):([^\s/@]+)@/g,
|
|
69
131
|
replacement: `$1://$2:${marker("connection_string")}@`,
|
|
70
132
|
},
|
|
71
133
|
{
|
|
72
134
|
// After the connection string: its password sits right before an `@` too.
|
|
135
|
+
// Starts only where a run of local-part characters starts: with `\b`, every
|
|
136
|
+
// dot, dash and `%` in a run began a new scan of the rest of it, and a
|
|
137
|
+
// version list or a URL-encoded query took minutes to get through.
|
|
73
138
|
type: "email",
|
|
74
|
-
pattern:
|
|
139
|
+
pattern: /(?<![A-Za-z0-9._%+-])[A-Za-z0-9._%+-]+@(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,}\b/g,
|
|
75
140
|
replacement: marker("email"),
|
|
76
141
|
},
|
|
77
142
|
{
|
|
143
|
+
// The name may close a quote of its own: `"password": "…"`.
|
|
78
144
|
type: "assignment",
|
|
79
|
-
pattern:
|
|
80
|
-
/(?<![A-Za-z0-9])(password|passwd|secret|token|api[-_]?key|private[-_]?key)(\s*[=:]\s*)(["']?)(?!\[ISY_REDACTED)[^\s"'{}()[\]<>$]{8,}/gi,
|
|
145
|
+
pattern: new RegExp(String.raw`(?<![A-Za-z0-9_.-])(${PLAIN_NAME})(["']?\s*[=:]\s*)(["']?)${SECRET_VALUE}`, "g"),
|
|
81
146
|
replacement: `$1$2$3${marker("assignment")}`,
|
|
82
147
|
},
|
|
148
|
+
{
|
|
149
|
+
// A camelCase name counts where it is plainly data — a quoted key with a
|
|
150
|
+
// quoted value (`{"accessToken":"…"}`) or `name=value` with no space, as
|
|
151
|
+
// `.npmrc` writes `_authToken=` — and not in `adminPassword = someVariable`.
|
|
152
|
+
type: "assignment",
|
|
153
|
+
pattern: new RegExp(
|
|
154
|
+
String.raw`(?<=["'])(${CAMEL_NAME})(["']\s*:\s*["'])${SECRET_VALUE}|(?<![A-Za-z0-9_.-])(${CAMEL_NAME})(=)${SECRET_VALUE}`,
|
|
155
|
+
"g",
|
|
156
|
+
),
|
|
157
|
+
replacement: `$1$2$3$4${marker("assignment")}`,
|
|
158
|
+
},
|
|
83
159
|
];
|
|
84
160
|
|
|
85
|
-
|
|
161
|
+
/** A JSON key is data, never code, so any spelling of a secret's name counts. */
|
|
162
|
+
const SENSITIVE_KEY = new RegExp(`^${secretName()}$`);
|
|
86
163
|
const MIN_SENSITIVE_VALUE = 8;
|
|
87
164
|
const EDIT_INPUT_FIELDS = ["content", "old_string", "new_string", "new_source"];
|
|
88
165
|
|
|
@@ -151,6 +228,121 @@ function isDotenvPath(filePath: unknown): boolean {
|
|
|
151
228
|
return typeof filePath === "string" && basename(filePath).startsWith(".env");
|
|
152
229
|
}
|
|
153
230
|
|
|
231
|
+
/** Commands that print a file they are given, or load it into the shell. */
|
|
232
|
+
const SHELL_READER =
|
|
233
|
+
/^\s*(?:sudo\s+)?(?:cat|head|tail|less|more|bat|nl|grep|egrep|fgrep|rg|sed|awk|jq|xxd|od|diff|source|\.|git\s+(?:show|diff|log|blame)|get-content|gc|type)(?:\s|$)/i;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* `cat .env`, `grep KEY config/.env.local`, `source .env`: a shell call that
|
|
237
|
+
* reads a dotenv file is as much a read of it as `Read {file_path}` is, and
|
|
238
|
+
* its output is the file. The command itself stays — it names the file, not
|
|
239
|
+
* what is in it.
|
|
240
|
+
*/
|
|
241
|
+
function readsDotenv(command: unknown): boolean {
|
|
242
|
+
if (typeof command !== "string" || !command.includes(".env")) return false;
|
|
243
|
+
return commandSegments(withoutHeredocs(command)).some(
|
|
244
|
+
(segment) =>
|
|
245
|
+
SHELL_READER.test(segment) &&
|
|
246
|
+
segment.trim().split(/\s+/).slice(1).some((word) => isDotenvPath(word.replace(/["'`]/g, "").replace(/^\w*:/, ""))),
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Commands that write the file they are given: `tee` and PowerShell's own. */
|
|
251
|
+
const SHELL_WRITER = /^\s*(?:sudo\s+)?(?:tee|set-content|sc|add-content|ac|out-file)(?:\s|$)/i;
|
|
252
|
+
|
|
253
|
+
const unquoted = (word: string): string => word.replace(/["'`]/g, "");
|
|
254
|
+
|
|
255
|
+
/** The dotenv file a statement redirects or tees into, if it writes one. */
|
|
256
|
+
function dotenvTarget(statement: string): string | undefined {
|
|
257
|
+
for (const segment of commandSegments(statement)) {
|
|
258
|
+
for (const redirect of segment.matchAll(/>\|?\s*([^\s;&|<>]+)/g)) {
|
|
259
|
+
if (isDotenvPath(unquoted(redirect[1]!))) return unquoted(redirect[1]!);
|
|
260
|
+
}
|
|
261
|
+
if (!SHELL_WRITER.test(segment)) continue;
|
|
262
|
+
const named = segment.trim().split(/\s+/).slice(1).map(unquoted).find(isDotenvPath);
|
|
263
|
+
if (named) return named;
|
|
264
|
+
}
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* A line cut where `&&`, `||` or `;` end a statement outside quotes, the
|
|
270
|
+
* separators kept, and whether a quote is still open where the line ends.
|
|
271
|
+
*/
|
|
272
|
+
function statements(line: string): { parts: string[]; open: boolean } {
|
|
273
|
+
const parts: string[] = [];
|
|
274
|
+
let start = 0;
|
|
275
|
+
let quote: string | undefined;
|
|
276
|
+
for (let i = 0; i < line.length; i += 1) {
|
|
277
|
+
const char = line[i]!;
|
|
278
|
+
if (quote !== undefined) {
|
|
279
|
+
if (char === quote && (quote === "'" || line[i - 1] !== "\\")) quote = undefined;
|
|
280
|
+
} else if (char === '"' || char === "'" || char === "`") {
|
|
281
|
+
quote = char;
|
|
282
|
+
} else if (char === ";" || ((char === "&" || char === "|") && line[i + 1] === char)) {
|
|
283
|
+
const width = char === ";" ? 1 : 2;
|
|
284
|
+
parts.push(line.slice(start, i), line.slice(i, i + width));
|
|
285
|
+
start = i + width;
|
|
286
|
+
i += width - 1;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
parts.push(line.slice(start));
|
|
290
|
+
return { parts, open: quote !== undefined };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** A write that closes a group or a substitution: `{ …; } > .env`, `(…) | tee .env`. */
|
|
294
|
+
const GROUP_WRITE = /[})]\s*(?:\d?>|&>|\|)/;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* `cat > .env << 'EOF'`, `echo "KEY=…" >> .env.local`, `… | tee .env`: a shell
|
|
298
|
+
* call that writes a dotenv file holds what it writes, so unlike a read the
|
|
299
|
+
* command is cut too. Only what carries the values goes — the statement that
|
|
300
|
+
* writes, with the heredoc it feeds, and a heredoc body that names the file
|
|
301
|
+
* itself (`python - <<PY` opening `.env`) — and the statement keeps its target,
|
|
302
|
+
* so `sed -i` beside it is still an edit and the parse still sees a write.
|
|
303
|
+
*/
|
|
304
|
+
function cutDotenvWrites(command: string): string {
|
|
305
|
+
if (!command.includes(".env")) return command;
|
|
306
|
+
const lines = command.split("\n");
|
|
307
|
+
const kept: string[] = [];
|
|
308
|
+
let written: string | undefined;
|
|
309
|
+
let spread = false;
|
|
310
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
311
|
+
let writes = false;
|
|
312
|
+
const { parts, open } = statements(lines[i]!);
|
|
313
|
+
if (open) spread = true;
|
|
314
|
+
kept.push(
|
|
315
|
+
parts
|
|
316
|
+
.map((part) => {
|
|
317
|
+
const target = dotenvTarget(part);
|
|
318
|
+
if (target === undefined) return part;
|
|
319
|
+
writes = true;
|
|
320
|
+
written ??= target;
|
|
321
|
+
if (GROUP_WRITE.test(part)) spread = true;
|
|
322
|
+
return `${/^\s*/.exec(part)![0]}${marker("dotenv")} > ${target}`;
|
|
323
|
+
})
|
|
324
|
+
.join(""),
|
|
325
|
+
);
|
|
326
|
+
const terminator = HEREDOC.exec(lines[i]!)?.[2];
|
|
327
|
+
if (terminator === undefined) continue;
|
|
328
|
+
let end = lines.findIndex((line, j) => j > i && line.trim() === terminator);
|
|
329
|
+
if (end === -1) end = lines.length;
|
|
330
|
+
const body = lines.slice(i + 1, end);
|
|
331
|
+
if (writes) {
|
|
332
|
+
i = end;
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
const namesDotenv = body.some((line) => line.split(/[\s"'`()=,;|&<>]+/).some(isDotenvPath));
|
|
336
|
+
kept.push(...(namesDotenv ? [marker("dotenv")] : body), ...lines.slice(end, end + 1));
|
|
337
|
+
i = end;
|
|
338
|
+
}
|
|
339
|
+
// A group or a quoted string over several lines holds the values outside the
|
|
340
|
+
// statement that names the file (`{ echo A=1; echo B=2; } > .env`), so the
|
|
341
|
+
// whole command goes, and only the write is left for the parse to see.
|
|
342
|
+
if (written !== undefined && spread) return `${marker("dotenv")} > ${written}`;
|
|
343
|
+
return kept.join("\n");
|
|
344
|
+
}
|
|
345
|
+
|
|
154
346
|
function cutDotenvInput(input: Record<string, unknown>, context: RedactContext): void {
|
|
155
347
|
for (const field of EDIT_INPUT_FIELDS) {
|
|
156
348
|
if (typeof input[field] === "string") {
|
|
@@ -171,6 +363,17 @@ function scanDotenv(record: Record<string, unknown>, context: RedactContext): vo
|
|
|
171
363
|
if (block.type === "tool_use") {
|
|
172
364
|
const input = isObject(block.input) ? block.input : undefined;
|
|
173
365
|
if (!input) continue;
|
|
366
|
+
if (block.name === "Bash" || block.name === "PowerShell") {
|
|
367
|
+
const command = input.command;
|
|
368
|
+
const cut = typeof command === "string" ? cutDotenvWrites(command) : command;
|
|
369
|
+
if (cut === command && !readsDotenv(command)) continue;
|
|
370
|
+
if (typeof block.id === "string") context.envToolUseIds.add(block.id);
|
|
371
|
+
if (cut !== command) {
|
|
372
|
+
input.command = cut;
|
|
373
|
+
count(context, "dotenv", 1);
|
|
374
|
+
}
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
174
377
|
if (!isDotenvPath(input.file_path) && !isDotenvPath(input.notebook_path)) continue;
|
|
175
378
|
if (typeof block.id === "string") context.envToolUseIds.add(block.id);
|
|
176
379
|
cutDotenvInput(input, context);
|
|
@@ -241,12 +444,37 @@ function learnRoot(record: Record<string, unknown>, context: RedactContext): voi
|
|
|
241
444
|
* Claude Code 2.1.30x also records the request it sends: `api-request-shape`
|
|
242
445
|
* carries the system prompt and the tool definitions, `api-request-blob` the
|
|
243
446
|
* context blocks sent beside the conversation — memory, CLAUDE.md, the email
|
|
244
|
-
* again
|
|
447
|
+
* again — and `api-request` the parameters, whose `safeguards` hand a
|
|
448
|
+
* classifier the account's user name, home directory and permission rules.
|
|
449
|
+
* `bridge-session` and `artifact-autoreact-ledger` are cut the same way: one
|
|
450
|
+
* names the account and organisation that own the session's bridge, the other
|
|
451
|
+
* the account. The parser reads none of them past their type, so only the
|
|
452
|
+
* fields that name them go — and the ones that say a subagent made the request
|
|
453
|
+
* (`subagents.ts:asSidechain`), or it is counted as the session's own.
|
|
245
454
|
*/
|
|
246
|
-
const REQUEST_RECORD_KEYS = new Set([
|
|
455
|
+
const REQUEST_RECORD_KEYS = new Set([
|
|
456
|
+
"type",
|
|
457
|
+
"uuid",
|
|
458
|
+
"parentUuid",
|
|
459
|
+
"sessionId",
|
|
460
|
+
"timestamp",
|
|
461
|
+
"version",
|
|
462
|
+
"shapeHash",
|
|
463
|
+
"hash",
|
|
464
|
+
"isSidechain",
|
|
465
|
+
"parentToolUseID",
|
|
466
|
+
"agentId",
|
|
467
|
+
]);
|
|
468
|
+
const STRIPPED_RECORD_TYPES = new Set([
|
|
469
|
+
"api-request",
|
|
470
|
+
"api-request-shape",
|
|
471
|
+
"api-request-blob",
|
|
472
|
+
"bridge-session",
|
|
473
|
+
"artifact-autoreact-ledger",
|
|
474
|
+
]);
|
|
247
475
|
|
|
248
476
|
function stripAttachment(record: Record<string, unknown>, context: RedactContext): void {
|
|
249
|
-
if (record.type === "
|
|
477
|
+
if (typeof record.type === "string" && STRIPPED_RECORD_TYPES.has(record.type)) {
|
|
250
478
|
for (const key of Object.keys(record)) if (!REQUEST_RECORD_KEYS.has(key)) delete record[key];
|
|
251
479
|
count(context, "attachment", 1);
|
|
252
480
|
return;
|
|
@@ -259,6 +487,47 @@ function stripAttachment(record: Record<string, unknown>, context: RedactContext
|
|
|
259
487
|
count(context, "attachment", 1);
|
|
260
488
|
}
|
|
261
489
|
|
|
490
|
+
/**
|
|
491
|
+
* Harness bookkeeping Claude Code writes beside a turn, read by nothing here or
|
|
492
|
+
* on the server. `wireToolInputs` repeats every call's input, out of reach of
|
|
493
|
+
* the dotenv cut, which edits the copy in `message` (`scanDotenv`);
|
|
494
|
+
* `serverClassifierRequest` and `serverClassifierContext` are what a permission
|
|
495
|
+
* classifier was shown, the working tree's git state included;
|
|
496
|
+
* `wireIngestContext` and `permissionDecision` say where a call ran and what
|
|
497
|
+
* allowed it.
|
|
498
|
+
*/
|
|
499
|
+
const HARNESS_FIELDS = [
|
|
500
|
+
"wireToolInputs",
|
|
501
|
+
"serverClassifierRequest",
|
|
502
|
+
"serverClassifierContext",
|
|
503
|
+
"wireIngestContext",
|
|
504
|
+
"permissionDecision",
|
|
505
|
+
];
|
|
506
|
+
|
|
507
|
+
function stripHarnessFields(record: Record<string, unknown>, context: RedactContext): void {
|
|
508
|
+
let stripped = false;
|
|
509
|
+
for (const field of HARNESS_FIELDS) {
|
|
510
|
+
if (!(field in record)) continue;
|
|
511
|
+
delete record[field];
|
|
512
|
+
stripped = true;
|
|
513
|
+
}
|
|
514
|
+
if (stripped) count(context, "attachment", 1);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* A user record marked `isMeta` is the harness talking in the user's place: a
|
|
519
|
+
* skill's body, a `<system-reminder>`, a command's caveat, an extension's
|
|
520
|
+
* instructions, a peer agent's message. Read as text it is a turn the
|
|
521
|
+
* developer never typed, holding files the developer never sent, so only a
|
|
522
|
+
* marker goes. None carries a tool result, and the record stays where it is:
|
|
523
|
+
* the next one names it as its `parentUuid`.
|
|
524
|
+
*/
|
|
525
|
+
function stripMeta(record: Record<string, unknown>, context: RedactContext): void {
|
|
526
|
+
if (record.type !== "user" || record.isMeta !== true || !isObject(record.message)) return;
|
|
527
|
+
record.message = { ...record.message, content: marker("meta") };
|
|
528
|
+
count(context, "attachment", 1);
|
|
529
|
+
}
|
|
530
|
+
|
|
262
531
|
function redactRecord(
|
|
263
532
|
record: Record<string, unknown>,
|
|
264
533
|
context: RedactContext,
|
|
@@ -266,6 +535,8 @@ function redactRecord(
|
|
|
266
535
|
learnRoot(record, context);
|
|
267
536
|
scanDotenv(record, context);
|
|
268
537
|
stripAttachment(record, context);
|
|
538
|
+
stripHarnessFields(record, context);
|
|
539
|
+
stripMeta(record, context);
|
|
269
540
|
return redactValue(record, context) as Record<string, unknown>;
|
|
270
541
|
}
|
|
271
542
|
|
|
@@ -322,6 +593,13 @@ function redactOneLine(line: string, context: RedactContext): { line: string; un
|
|
|
322
593
|
return { line: JSON.stringify(redactRecord(parsed, context)), unparsed: false };
|
|
323
594
|
}
|
|
324
595
|
|
|
596
|
+
/**
|
|
597
|
+
* A transcript's lines, redacted. With no `cwd`, paths are rooted at the first
|
|
598
|
+
* record that names one; with no `home`, at the home that directory implies,
|
|
599
|
+
* else this machine's. Exported as `isy/redact` so the server can re-run the
|
|
600
|
+
* rules over a transcript an older client uploaded: there the machine is the
|
|
601
|
+
* server, so it passes `home: ""` and roots paths in the transcript alone.
|
|
602
|
+
*/
|
|
325
603
|
export function redactLines(
|
|
326
604
|
lines: Iterable<string>,
|
|
327
605
|
options: RedactOptions = {},
|
package/src/state.ts
CHANGED
|
@@ -25,6 +25,12 @@ export interface CommitMark {
|
|
|
25
25
|
export interface SessionState {
|
|
26
26
|
/** contentHash of the last upload the server accepted. */
|
|
27
27
|
uploadedHash?: string;
|
|
28
|
+
/**
|
|
29
|
+
* contentHash of an upload refused for what it holds — too large, or a body
|
|
30
|
+
* the server will not take. The same bytes would be refused again, so the
|
|
31
|
+
* fingerprint below is taken at the refusal too and a scan passes them over.
|
|
32
|
+
*/
|
|
33
|
+
rejectedHash?: string;
|
|
28
34
|
/**
|
|
29
35
|
* Transcript size and mtime at that upload. Both unchanged means the bytes
|
|
30
36
|
* are unchanged, which lets a scan skip reading a transcript entirely.
|
|
@@ -213,15 +219,15 @@ export function withCommit(
|
|
|
213
219
|
}
|
|
214
220
|
|
|
215
221
|
/**
|
|
216
|
-
* Whether the transcript or its commit marks changed since the last
|
|
217
|
-
*
|
|
218
|
-
* not be read at all.
|
|
222
|
+
* Whether the transcript or its commit marks changed since the last upload the
|
|
223
|
+
* server accepted or refused for good. Size and mtime both matching means the
|
|
224
|
+
* bytes match, so the file need not be read at all.
|
|
219
225
|
*/
|
|
220
226
|
export function looksUnchanged(
|
|
221
227
|
state: SessionState,
|
|
222
228
|
file: { sizeBytes: number; modifiedAt: Date },
|
|
223
229
|
): boolean {
|
|
224
|
-
if (state.uploadedHash === undefined) return false;
|
|
230
|
+
if (state.uploadedHash === undefined && state.rejectedHash === undefined) return false;
|
|
225
231
|
if (state.commits?.at(-1)?.sha !== state.uploadedCommit) return false;
|
|
226
232
|
return state.sizeBytes === file.sizeBytes && state.modifiedMs === file.modifiedAt.getTime();
|
|
227
233
|
}
|
package/src/subagents.ts
CHANGED
|
@@ -7,10 +7,12 @@ import { fileLines } from "./lines.js";
|
|
|
7
7
|
* Claude Code 2.1 writes every subagent to a file of its own beside the session:
|
|
8
8
|
* `<session>/subagents/agent-<id>.jsonl`, with `agent-<id>.meta.json` next to it
|
|
9
9
|
* naming the `Agent` call that started it (`toolUseId`). Workflow agents go one
|
|
10
|
-
* level deeper (`subagents/workflows/<run>/`)
|
|
11
|
-
* call
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* level deeper (`subagents/workflows/<run>/`), and their meta names no call: the
|
|
11
|
+
* `Workflow` call's result names the run (`toolUseResult.runId`). The session
|
|
12
|
+
* file keeps only the call and its result, so read alone it hid most of the
|
|
13
|
+
* work — in one session 12 calls stood in the session file and 134 in its
|
|
14
|
+
* subagents — and a session whose files were all edited by a subagent read as
|
|
15
|
+
* one that edited nothing.
|
|
14
16
|
*
|
|
15
17
|
* So the session is read as one transcript, each subagent's records merged in
|
|
16
18
|
* as sidechain records carrying `parentToolUseID`: by time, and never ahead of
|
|
@@ -27,6 +29,8 @@ interface Subagent {
|
|
|
27
29
|
path: string;
|
|
28
30
|
/** The `Agent` call that started it, from the meta file. */
|
|
29
31
|
toolUseId?: string;
|
|
32
|
+
/** The workflow run it worked in: its directory under `subagents/workflows/`. */
|
|
33
|
+
run?: string;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
function isObject(value: unknown): value is Record<string, unknown> {
|
|
@@ -74,7 +78,9 @@ export async function subagentsOf(sessionPath: string): Promise<Subagent[]> {
|
|
|
74
78
|
for (const path of await agentFiles(subagentsDir(sessionPath))) {
|
|
75
79
|
const meta = await readMeta(path);
|
|
76
80
|
const toolUseId = typeof meta?.toolUseId === "string" && meta.toolUseId.length > 0 ? meta.toolUseId : undefined;
|
|
77
|
-
|
|
81
|
+
const dir = dirname(path);
|
|
82
|
+
const run = basename(dirname(dir)) === "workflows" ? basename(dir) : undefined;
|
|
83
|
+
agents.push({ agentId: basename(path, ".jsonl").slice("agent-".length), path, toolUseId, run });
|
|
78
84
|
}
|
|
79
85
|
return agents;
|
|
80
86
|
}
|
|
@@ -156,11 +162,14 @@ function callsIn(record: Record<string, unknown> | undefined): string[] {
|
|
|
156
162
|
}
|
|
157
163
|
|
|
158
164
|
/**
|
|
159
|
-
* The call a subagent
|
|
160
|
-
* names the agent (`toolUseResult.agentId`),
|
|
165
|
+
* The call a subagent answered when its meta file names none: its result in the
|
|
166
|
+
* session names the agent (`toolUseResult.agentId`), or a workflow's agent by
|
|
167
|
+
* its run (`runId`), and the result names the call.
|
|
161
168
|
*/
|
|
162
|
-
function answeredCall(record: Record<string, unknown> | undefined,
|
|
163
|
-
if (!isObject(record?.toolUseResult)
|
|
169
|
+
function answeredCall(record: Record<string, unknown> | undefined, agent: Subagent): string | undefined {
|
|
170
|
+
if (!isObject(record?.toolUseResult)) return undefined;
|
|
171
|
+
const { agentId, runId } = record.toolUseResult;
|
|
172
|
+
if (agentId !== agent.agentId && (agent.run === undefined || runId !== agent.run)) return undefined;
|
|
164
173
|
const content = isObject(record.message) ? record.message.content : undefined;
|
|
165
174
|
const result = Array.isArray(content)
|
|
166
175
|
? content.find((block) => isObject(block) && block.type === "tool_result")
|
|
@@ -237,7 +246,7 @@ export async function* sessionLines(sessionPath: string): AsyncGenerator<string>
|
|
|
237
246
|
const unlinked = agents.filter((agent) => agent.toolUseId === undefined);
|
|
238
247
|
const placed = new Set<string>();
|
|
239
248
|
|
|
240
|
-
/** The subagents a record starts: by the call it makes, or by the result that names one
|
|
249
|
+
/** The subagents a record starts: by the call it makes, or by the result that names one whose meta file names no call. */
|
|
241
250
|
const startedBy = (record: Record<string, unknown> | undefined): { agent: Subagent; call: string }[] => {
|
|
242
251
|
const started: { agent: Subagent; call: string }[] = [];
|
|
243
252
|
for (const call of callsIn(record)) {
|
|
@@ -245,7 +254,7 @@ export async function* sessionLines(sessionPath: string): AsyncGenerator<string>
|
|
|
245
254
|
}
|
|
246
255
|
for (const agent of unlinked) {
|
|
247
256
|
if (placed.has(agent.agentId)) continue;
|
|
248
|
-
const call = answeredCall(record, agent
|
|
257
|
+
const call = answeredCall(record, agent);
|
|
249
258
|
if (call !== undefined) started.push({ agent, call });
|
|
250
259
|
}
|
|
251
260
|
return started;
|