@nightloom/isy 1.0.1 → 1.0.3
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/claude.js +18 -7
- package/dist/agents/claude.js.map +1 -1
- package/dist/agents/codex-records.js +16 -2
- package/dist/agents/codex-records.js.map +1 -1
- package/dist/agents/index.d.ts +16 -5
- package/dist/agents/index.js +21 -6
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/kimi-cli-wire.d.ts +17 -0
- package/dist/agents/kimi-cli-wire.js +312 -0
- package/dist/agents/kimi-cli-wire.js.map +1 -0
- package/dist/agents/kimi-config.d.ts +29 -0
- package/dist/agents/kimi-config.js +193 -0
- package/dist/agents/kimi-config.js.map +1 -0
- package/dist/agents/kimi-records.d.ts +0 -6
- package/dist/agents/kimi-records.js +51 -31
- package/dist/agents/kimi-records.js.map +1 -1
- package/dist/agents/kimi-tools.d.ts +30 -0
- package/dist/agents/kimi-tools.js +100 -0
- package/dist/agents/kimi-tools.js.map +1 -0
- package/dist/agents/kimi-wire.d.ts +8 -0
- package/dist/agents/kimi-wire.js +245 -80
- package/dist/agents/kimi-wire.js.map +1 -1
- package/dist/agents/kimi.d.ts +13 -2
- package/dist/agents/kimi.js +633 -114
- package/dist/agents/kimi.js.map +1 -1
- package/dist/agents/timeline.d.ts +36 -0
- package/dist/agents/timeline.js +61 -0
- package/dist/agents/timeline.js.map +1 -0
- package/dist/agents/types.d.ts +12 -0
- package/dist/api.d.ts +3 -0
- package/dist/api.js +1 -1
- package/dist/api.js.map +1 -1
- package/dist/commands/analyze.d.ts +2 -0
- package/dist/commands/analyze.js +63 -6
- package/dist/commands/analyze.js.map +1 -1
- package/dist/commands/check.js +11 -0
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/health.js +2 -2
- package/dist/commands/health.js.map +1 -1
- package/dist/commands/init.js +25 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/upload.d.ts +2 -0
- package/dist/commands/upload.js +38 -7
- package/dist/commands/upload.js.map +1 -1
- package/dist/detectors.js +40 -5
- package/dist/detectors.js.map +1 -1
- package/dist/hook.d.ts +12 -5
- package/dist/hook.js +73 -17
- package/dist/hook.js.map +1 -1
- package/dist/lines.d.ts +8 -0
- package/dist/lines.js +32 -0
- package/dist/lines.js.map +1 -0
- package/dist/mask-paths.js +31 -15
- package/dist/mask-paths.js.map +1 -1
- package/dist/parser.d.ts +41 -0
- package/dist/parser.js +345 -36
- package/dist/parser.js.map +1 -1
- package/dist/paths.d.ts +4 -0
- package/dist/paths.js +39 -39
- package/dist/paths.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 +17 -0
- package/dist/redact.js +202 -12
- package/dist/redact.js.map +1 -1
- package/dist/state.d.ts +15 -6
- package/dist/state.js +25 -9
- package/dist/state.js.map +1 -1
- package/dist/subagents.d.ts +53 -0
- package/dist/subagents.js +243 -0
- package/dist/subagents.js.map +1 -0
- package/dist/test/check.test.js +25 -3
- package/dist/test/check.test.js.map +1 -1
- package/dist/test/codex.test.js +21 -0
- package/dist/test/codex.test.js.map +1 -1
- package/dist/test/commit.test.js +9 -1
- package/dist/test/commit.test.js.map +1 -1
- package/dist/test/hook.test.js +66 -2
- package/dist/test/hook.test.js.map +1 -1
- package/dist/test/init.test.d.ts +1 -0
- package/dist/test/init.test.js +102 -0
- package/dist/test/init.test.js.map +1 -0
- package/dist/test/kimi-cli.test.d.ts +1 -0
- package/dist/test/kimi-cli.test.js +231 -0
- package/dist/test/kimi-cli.test.js.map +1 -0
- package/dist/test/kimi-code.test.d.ts +1 -0
- package/dist/test/kimi-code.test.js +302 -0
- package/dist/test/kimi-code.test.js.map +1 -0
- package/dist/test/kimi-config.test.d.ts +1 -0
- package/dist/test/kimi-config.test.js +224 -0
- package/dist/test/kimi-config.test.js.map +1 -0
- package/dist/test/kimi-hook.test.d.ts +1 -0
- package/dist/test/kimi-hook.test.js +163 -0
- package/dist/test/kimi-hook.test.js.map +1 -0
- package/dist/test/kimi-listing.test.d.ts +1 -0
- package/dist/test/kimi-listing.test.js +193 -0
- package/dist/test/kimi-listing.test.js.map +1 -0
- package/dist/test/kimi.test.js +52 -7
- package/dist/test/kimi.test.js.map +1 -1
- package/dist/test/mask-paths.test.js +31 -0
- package/dist/test/mask-paths.test.js.map +1 -1
- package/dist/test/parser.test.js +208 -5
- 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 +245 -8
- package/dist/test/redact.test.js.map +1 -1
- package/dist/test/stage0.test.js +49 -0
- package/dist/test/stage0.test.js.map +1 -1
- package/dist/test/subagents.test.d.ts +1 -0
- package/dist/test/subagents.test.js +290 -0
- package/dist/test/subagents.test.js.map +1 -0
- package/dist/test/sweep.test.js +25 -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/dist/types.d.ts +16 -0
- package/package.json +5 -3
- package/src/agents/claude.ts +17 -7
- package/src/agents/codex-records.ts +17 -2
- package/src/agents/index.ts +21 -6
- package/src/agents/kimi-cli-wire.ts +350 -0
- package/src/agents/kimi-config.ts +210 -0
- package/src/agents/kimi-records.ts +52 -29
- package/src/agents/kimi-tools.ts +128 -0
- package/src/agents/kimi-wire.ts +270 -82
- package/src/agents/kimi.ts +653 -113
- package/src/agents/timeline.ts +68 -0
- package/src/agents/types.ts +12 -0
- package/src/api.ts +5 -2
- package/src/commands/analyze.ts +62 -6
- package/src/commands/check.ts +11 -0
- package/src/commands/health.ts +2 -2
- package/src/commands/init.ts +26 -2
- package/src/commands/upload.ts +46 -7
- package/src/detectors.ts +39 -5
- package/src/hook.ts +81 -24
- package/src/lines.ts +31 -0
- package/src/mask-paths.ts +31 -14
- package/src/parser.ts +356 -35
- package/src/paths.ts +36 -33
- package/src/plan.ts +4 -1
- package/src/queue.ts +30 -4
- package/src/redact.ts +218 -15
- package/src/state.ts +34 -9
- package/src/subagents.ts +292 -0
- package/src/types.ts +16 -0
package/dist/paths.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export declare function claudeProjectsDir(): string;
|
|
|
15
15
|
export declare function claudeSettingsPath(): string;
|
|
16
16
|
export declare function projectSlug(cwd: string): string;
|
|
17
17
|
export declare function projectDir(cwd: string): string;
|
|
18
|
+
/** When a session itself last wrote (`SessionFile.activeAt`), for ordering sessions by recency. */
|
|
19
|
+
export declare function lastActive(file: SessionFile): number;
|
|
18
20
|
export declare function findSessions(cwd: string): Promise<SessionFile[]>;
|
|
19
21
|
export declare function latestSession(cwd: string): Promise<SessionFile | undefined>;
|
|
20
22
|
/**
|
|
@@ -33,6 +35,8 @@ export declare function allClaudeSessions(): Promise<SessionFile[]>;
|
|
|
33
35
|
export declare function firstCwd(path: string, limit?: number): Promise<string | undefined>;
|
|
34
36
|
/** The first line of a file, without reading the rest: transcripts get large. */
|
|
35
37
|
export declare function firstLine(path: string): Promise<string>;
|
|
38
|
+
/** The first `count` lines of a file, without reading the rest. */
|
|
39
|
+
export declare function firstLines(path: string, count: number): Promise<string[]>;
|
|
36
40
|
/**
|
|
37
41
|
* What this client already did with each session: what was uploaded, what was
|
|
38
42
|
* printed, which commits it spans. A cache — losing it costs one repeated
|
package/dist/paths.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createReadStream } from "node:fs";
|
|
2
1
|
import { readFile, readdir, stat } from "node:fs/promises";
|
|
3
|
-
import { createInterface } from "node:readline";
|
|
4
2
|
import { homedir } from "node:os";
|
|
5
3
|
import { basename, join } from "node:path";
|
|
4
|
+
import { fileLines } from "./lines.js";
|
|
5
|
+
import { sessionFingerprint } from "./subagents.js";
|
|
6
6
|
export async function packageVersion() {
|
|
7
7
|
try {
|
|
8
8
|
const contents = await readFile(join(import.meta.dirname, "..", "package.json"), "utf8");
|
|
@@ -71,11 +71,15 @@ async function sessionsInDir(dir) {
|
|
|
71
71
|
const info = await stat(path);
|
|
72
72
|
if (!info.isFile())
|
|
73
73
|
continue;
|
|
74
|
+
// Size and mtime of the session as a whole: its subagents write files of
|
|
75
|
+
// their own, and a sweep compares against these to decide what grew.
|
|
76
|
+
const whole = await sessionFingerprint(path);
|
|
74
77
|
sessions.push({
|
|
75
78
|
sessionId: basename(entry, ".jsonl"),
|
|
76
79
|
path,
|
|
77
|
-
sizeBytes:
|
|
78
|
-
modifiedAt:
|
|
80
|
+
sizeBytes: whole.sizeBytes,
|
|
81
|
+
modifiedAt: whole.modifiedAt,
|
|
82
|
+
activeAt: info.mtime,
|
|
79
83
|
});
|
|
80
84
|
}
|
|
81
85
|
catch {
|
|
@@ -84,8 +88,12 @@ async function sessionsInDir(dir) {
|
|
|
84
88
|
}
|
|
85
89
|
return sessions;
|
|
86
90
|
}
|
|
91
|
+
/** When a session itself last wrote (`SessionFile.activeAt`), for ordering sessions by recency. */
|
|
92
|
+
export function lastActive(file) {
|
|
93
|
+
return (file.activeAt ?? file.modifiedAt).getTime();
|
|
94
|
+
}
|
|
87
95
|
function newestFirst(sessions) {
|
|
88
|
-
return sessions.sort((a, b) => b
|
|
96
|
+
return sessions.sort((a, b) => lastActive(b) - lastActive(a));
|
|
89
97
|
}
|
|
90
98
|
export async function findSessions(cwd) {
|
|
91
99
|
return newestFirst(await sessionsInDir(projectDir(cwd)));
|
|
@@ -128,47 +136,39 @@ const CWD_SCAN_LINES = 40;
|
|
|
128
136
|
* same field `mask-paths` roots its rewriting on.
|
|
129
137
|
*/
|
|
130
138
|
export async function firstCwd(path, limit = CWD_SCAN_LINES) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
try {
|
|
141
|
-
const parsed = JSON.parse(line);
|
|
142
|
-
if (typeof parsed !== "object" || parsed === null)
|
|
143
|
-
continue;
|
|
144
|
-
const cwd = parsed.cwd;
|
|
145
|
-
if (typeof cwd === "string" && cwd.length > 0)
|
|
146
|
-
return cwd;
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
139
|
+
let seen = 0;
|
|
140
|
+
for await (const line of fileLines(path)) {
|
|
141
|
+
if (seen++ >= limit)
|
|
142
|
+
return undefined;
|
|
143
|
+
if (line.length === 0)
|
|
144
|
+
continue;
|
|
145
|
+
try {
|
|
146
|
+
const parsed = JSON.parse(line);
|
|
147
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
149
148
|
continue;
|
|
150
|
-
|
|
149
|
+
const cwd = parsed.cwd;
|
|
150
|
+
if (typeof cwd === "string" && cwd.length > 0)
|
|
151
|
+
return cwd;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
continue;
|
|
151
155
|
}
|
|
152
|
-
return undefined;
|
|
153
|
-
}
|
|
154
|
-
finally {
|
|
155
|
-
reader.close();
|
|
156
|
-
input.destroy();
|
|
157
156
|
}
|
|
157
|
+
return undefined;
|
|
158
158
|
}
|
|
159
159
|
/** The first line of a file, without reading the rest: transcripts get large. */
|
|
160
160
|
export async function firstLine(path) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
input.destroy();
|
|
161
|
+
return (await firstLines(path, 1))[0] ?? "";
|
|
162
|
+
}
|
|
163
|
+
/** The first `count` lines of a file, without reading the rest. */
|
|
164
|
+
export async function firstLines(path, count) {
|
|
165
|
+
const lines = [];
|
|
166
|
+
for await (const line of fileLines(path)) {
|
|
167
|
+
lines.push(line);
|
|
168
|
+
if (lines.length >= count)
|
|
169
|
+
break;
|
|
171
170
|
}
|
|
171
|
+
return lines;
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
174
|
* What this client already did with each session: what was uploaded, what was
|
package/dist/paths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGpD,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC;QACzF,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC7C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;YACzE,MAAM,OAAO,GAAI,MAA+B,CAAC,OAAO,CAAC;YACzD,IAAI,OAAO,OAAO,KAAK,QAAQ;gBAAE,OAAO,OAAO,CAAC;QAClD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,OAAO;IACrB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,U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G,CAAC;YAC9C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO,GAAG,CAAC;QAC5D,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAY;IAC1C,OAAO,CAAC,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC9C,CAAC;AAED,mEAAmE;AACnE,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAY,EAAE,KAAa;IAC1D,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK;YAAE,MAAM;IACnC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,eAAe,CAAC,CAAC;AAC1C,CAAC"}
|
package/dist/plan.d.ts
CHANGED
|
@@ -21,5 +21,7 @@ export declare function parsePlan(value: unknown): PlanStatus | undefined;
|
|
|
21
21
|
/**
|
|
22
22
|
* The line, or nothing while there is still room. Credits count as room: they
|
|
23
23
|
* are what the gate spends once the allowance is gone (`billing.ts:checkQuota`).
|
|
24
|
+
* So does a cycle that has rolled over since: the snapshot is only as new as
|
|
25
|
+
* the last upload, which can be days old.
|
|
24
26
|
*/
|
|
25
|
-
export declare function planNotice(plan: PlanStatus | undefined): string | undefined;
|
|
27
|
+
export declare function planNotice(plan: PlanStatus | undefined, now?: number): string | undefined;
|
package/dist/plan.js
CHANGED
|
@@ -29,10 +29,14 @@ function resetDay(iso) {
|
|
|
29
29
|
/**
|
|
30
30
|
* The line, or nothing while there is still room. Credits count as room: they
|
|
31
31
|
* are what the gate spends once the allowance is gone (`billing.ts:checkQuota`).
|
|
32
|
+
* So does a cycle that has rolled over since: the snapshot is only as new as
|
|
33
|
+
* the last upload, which can be days old.
|
|
32
34
|
*/
|
|
33
|
-
export function planNotice(plan) {
|
|
35
|
+
export function planNotice(plan, now = Date.now()) {
|
|
34
36
|
if (!plan || plan.analysesLeft > 0 || plan.credits > 0)
|
|
35
37
|
return undefined;
|
|
38
|
+
if (plan.resetsAt && Date.parse(plan.resetsAt) <= now)
|
|
39
|
+
return undefined;
|
|
36
40
|
const day = resetDay(plan.resetsAt);
|
|
37
41
|
return `plan limit reached on ${plan.tier} — pull requests are not analysed${day ? ` until ${day}` : ""}. Add credits or upgrade the plan.`;
|
|
38
42
|
}
|
package/dist/plan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan.js","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AAmBA,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC7D,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAClE,MAAM,MAAM,GAAG,KAAgC,CAAC;IAChD,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACtD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAClF,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,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AC;AACvC,CAAC"}
|
package/dist/queue.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import type { UploadPayload } from "./api.js";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Attempts are spaced rather than made once per run: the wait before the next
|
|
4
|
+
* one doubles from ten minutes, so the last comes nearly two days after the
|
|
5
|
+
* session was queued. Runs come minutes apart — a session's start and end,
|
|
6
|
+
* every commit — so counted per run, one short outage would use them all up.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MAX_ATTEMPTS = 8;
|
|
3
9
|
export interface QueueEntry {
|
|
4
10
|
sessionId: string;
|
|
5
11
|
contentHash: string;
|
|
6
12
|
attempts: number;
|
|
7
13
|
queuedAt: string;
|
|
14
|
+
/** When the last attempt failed. isy 1.0 did not record it; `queuedAt` stands in. */
|
|
15
|
+
lastAttemptAt?: string;
|
|
8
16
|
lastError?: string;
|
|
9
17
|
payload: UploadPayload;
|
|
10
18
|
}
|
|
@@ -15,10 +23,14 @@ export interface QueueItem {
|
|
|
15
23
|
export declare function isAbandoned(sessionId: string, contentHash: string): Promise<boolean>;
|
|
16
24
|
export declare function enqueue(payload: UploadPayload, lastError?: string): Promise<string>;
|
|
17
25
|
export declare function listPending(): Promise<QueueItem[]>;
|
|
26
|
+
/** Whether a queued upload has waited out the delay since it last failed. */
|
|
27
|
+
export declare function isDue(entry: QueueEntry, now?: number): boolean;
|
|
18
28
|
/** Uploads that ran out of attempts. Their `lastError` is the only record of why. */
|
|
19
29
|
export declare function listFailed(): Promise<QueueItem[]>;
|
|
20
30
|
export declare function recordFailure(item: QueueItem, error: string): Promise<"retained" | "abandoned">;
|
|
21
|
-
export declare function drop(item: QueueItem): Promise<void>;
|
|
31
|
+
export declare function drop(item: Pick<QueueItem, "path">): Promise<void>;
|
|
32
|
+
/** Bytes that went up some other way: a copy waiting out its delay here is done. */
|
|
33
|
+
export declare function forget(sessionId: string, contentHash: string): Promise<void>;
|
|
22
34
|
export declare function abandon(item: QueueItem, error: string): Promise<void>;
|
|
23
35
|
export declare function countQueue(): Promise<{
|
|
24
36
|
pending: number;
|
package/dist/queue.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { access, chmod, mkdir, readFile, readdir, rename, unlink, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { queueDir } from "./paths.js";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Attempts are spaced rather than made once per run: the wait before the next
|
|
6
|
+
* one doubles from ten minutes, so the last comes nearly two days after the
|
|
7
|
+
* session was queued. Runs come minutes apart — a session's start and end,
|
|
8
|
+
* every commit — so counted per run, one short outage would use them all up.
|
|
9
|
+
*/
|
|
10
|
+
export const MAX_ATTEMPTS = 8;
|
|
11
|
+
const RETRY_AFTER_MS = 10 * 60_000;
|
|
5
12
|
const FAILED_SUFFIX = ".failed";
|
|
6
13
|
function entryName(sessionId, contentHash) {
|
|
7
14
|
const safeSession = sessionId.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
@@ -23,11 +30,16 @@ export async function enqueue(payload, lastError) {
|
|
|
23
30
|
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
24
31
|
const path = join(dir, entryName(payload.sessionId, payload.contentHash));
|
|
25
32
|
const existing = await readEntry(path);
|
|
33
|
+
const now = new Date().toISOString();
|
|
26
34
|
const entry = {
|
|
27
35
|
sessionId: payload.sessionId,
|
|
28
36
|
contentHash: payload.contentHash,
|
|
29
37
|
attempts: existing ? existing.attempts : 0,
|
|
30
|
-
queuedAt: existing ? existing.queuedAt :
|
|
38
|
+
queuedAt: existing ? existing.queuedAt : now,
|
|
39
|
+
// The send that failed starts the wait, or the drain closing the same run
|
|
40
|
+
// would try again a second later. Queued again by a later failed send, an
|
|
41
|
+
// entry keeps both this and `attempts`: the queue keeps its own schedule.
|
|
42
|
+
lastAttemptAt: existing ? existing.lastAttemptAt : now,
|
|
31
43
|
lastError,
|
|
32
44
|
payload,
|
|
33
45
|
};
|
|
@@ -72,13 +84,19 @@ async function listBySuffix(suffix) {
|
|
|
72
84
|
export async function listPending() {
|
|
73
85
|
return listBySuffix(".json");
|
|
74
86
|
}
|
|
87
|
+
/** Whether a queued upload has waited out the delay since it last failed. */
|
|
88
|
+
export function isDue(entry, now = Date.now()) {
|
|
89
|
+
const last = Date.parse(entry.lastAttemptAt ?? entry.queuedAt);
|
|
90
|
+
return Number.isNaN(last) || now - last >= RETRY_AFTER_MS * 2 ** entry.attempts;
|
|
91
|
+
}
|
|
75
92
|
/** Uploads that ran out of attempts. Their `lastError` is the only record of why. */
|
|
76
93
|
export async function listFailed() {
|
|
77
94
|
return listBySuffix(FAILED_SUFFIX);
|
|
78
95
|
}
|
|
79
96
|
export async function recordFailure(item, error) {
|
|
80
97
|
const attempts = item.entry.attempts + 1;
|
|
81
|
-
const
|
|
98
|
+
const lastAttemptAt = new Date().toISOString();
|
|
99
|
+
const updated = { ...item.entry, attempts, lastAttemptAt, lastError: error };
|
|
82
100
|
await writeFile(item.path, JSON.stringify(updated), { mode: 0o600 });
|
|
83
101
|
if (attempts >= MAX_ATTEMPTS) {
|
|
84
102
|
await rename(item.path, `${item.path}${FAILED_SUFFIX}`);
|
|
@@ -94,6 +112,10 @@ export async function drop(item) {
|
|
|
94
112
|
return;
|
|
95
113
|
}
|
|
96
114
|
}
|
|
115
|
+
/** Bytes that went up some other way: a copy waiting out its delay here is done. */
|
|
116
|
+
export async function forget(sessionId, contentHash) {
|
|
117
|
+
await drop({ path: join(queueDir(), entryName(sessionId, contentHash)) });
|
|
118
|
+
}
|
|
97
119
|
export async function abandon(item, error) {
|
|
98
120
|
const updated = { ...item.entry, attempts: MAX_ATTEMPTS, lastError: error };
|
|
99
121
|
await writeFile(item.path, JSON.stringify(updated), { mode: 0o600 });
|
package/dist/queue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,OA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EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC;YAAE,MAAM,IAAI,CAAC,CAAC;aAC1C,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC7B,CAAC"}
|
package/dist/redact.d.ts
CHANGED
|
@@ -19,10 +19,27 @@ export declare function applyRules(text: string, rules: readonly RedactionRule[]
|
|
|
19
19
|
export interface RedactOptions extends MaskRoots {
|
|
20
20
|
extraPatterns?: readonly string[];
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* A transcript's lines, redacted. With no `cwd`, paths are rooted at the first
|
|
24
|
+
* record that names one; with no `home`, at the home that directory implies,
|
|
25
|
+
* else this machine's. Exported as `isy/redact` so the server can re-run the
|
|
26
|
+
* rules over a transcript an older client uploaded: there the machine is the
|
|
27
|
+
* server, so it passes `home: ""` and roots paths in the transcript alone.
|
|
28
|
+
*/
|
|
22
29
|
export declare function redactLines(lines: Iterable<string>, options?: RedactOptions): {
|
|
23
30
|
lines: string[];
|
|
24
31
|
summary: RedactionSummary;
|
|
25
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* `redactLines` for lines that arrive one at a time — a file read as it streams,
|
|
35
|
+
* or a Claude session with its subagents spliced in (`subagents.ts`). One
|
|
36
|
+
* context for the whole stream, so the working directory the first record names
|
|
37
|
+
* roots every path after it, the subagents' included.
|
|
38
|
+
*/
|
|
39
|
+
export declare function redactLineStream(lines: AsyncIterable<string>, options?: RedactOptions): Promise<{
|
|
40
|
+
lines: string[];
|
|
41
|
+
summary: RedactionSummary;
|
|
42
|
+
}>;
|
|
26
43
|
export declare function redactTranscriptFile(filePath: string, options?: RedactOptions): Promise<{
|
|
27
44
|
lines: string[];
|
|
28
45
|
summary: RedactionSummary;
|
package/dist/redact.js
CHANGED
|
@@ -1,15 +1,42 @@
|
|
|
1
|
-
import { createReadStream } from "node:fs";
|
|
2
1
|
import { homedir } from "node:os";
|
|
3
2
|
import { basename } from "node:path";
|
|
4
|
-
import {
|
|
3
|
+
import { fileLines } from "./lines.js";
|
|
4
|
+
import { commandSegments, withoutHeredocs } from "./parser.js";
|
|
5
5
|
import { PATH_KEYS, REDACTION_MARKER, marker, maskPath, maskPaths, resolveRoots, rootOf, } from "./mask-paths.js";
|
|
6
6
|
// The marker vocabulary lives with the path rules, which cannot import this
|
|
7
7
|
// module back without a cycle. Re-exported so every caller has one import.
|
|
8
8
|
export { REDACTION_MARKER, marker };
|
|
9
|
+
/** `[pP][aA]…`: case by hand, so a rule can still tell a camelCase hump from a glued prefix. */
|
|
10
|
+
function anyCase(source) {
|
|
11
|
+
return source.replace(/[a-z]/g, (letter) => `[${letter}${letter.toUpperCase()}]`);
|
|
12
|
+
}
|
|
13
|
+
const SECRET_WORD = anyCase("(?:password|passwd|secret|token|api[-_]?key|private[-_]?key|access[-_]?key)");
|
|
14
|
+
/**
|
|
15
|
+
* A name that holds a secret: one of the words, wherever it sits in an
|
|
16
|
+
* identifier — `PGPASSWORD`, `STRIPE_SECRET_KEY`, `aws_secret_access_key`,
|
|
17
|
+
* `x-api-key` — and followed by nothing but `KEY` and `BASE` (`SECRET_KEY_BASE`).
|
|
18
|
+
* That tail is the line between the secret and what is said about it:
|
|
19
|
+
* `tokenHash`, `max_tokens`, `TOKENS_PER_ANALYSIS` and `PASSWORD_FILE` turn up
|
|
20
|
+
* in a real corpus as often as the secrets do, and none of them is one.
|
|
21
|
+
*/
|
|
22
|
+
function secretName(atWord = "") {
|
|
23
|
+
return String.raw `[A-Za-z0-9_.-]*?${atWord}${SECRET_WORD}${anyCase("(?:[-_]?key)?(?:[-_]?base)?")}(?![A-Za-z0-9_.-])`;
|
|
24
|
+
}
|
|
25
|
+
/** The word glued to what came before, but not as a camelCase hump. */
|
|
26
|
+
const PLAIN_NAME = secretName("(?!(?<=[a-z0-9])[A-Z])");
|
|
27
|
+
/** `adminPassword`, `_authToken`: as often a variable in code as a key in a file. */
|
|
28
|
+
const CAMEL_NAME = secretName("(?<=[a-z0-9])(?=[A-Z])");
|
|
29
|
+
/**
|
|
30
|
+
* What an assigned secret looks like: long enough to be one, and not code. A
|
|
31
|
+
* number never is — usage counts sit under names like these in every record,
|
|
32
|
+
* and stdout quotes them as JSON text.
|
|
33
|
+
*/
|
|
34
|
+
const SECRET_VALUE = String.raw `(?!\[ISY_REDACTED)(?!-?\d[\d.,eE+-]*(?![^\s"'{}()[\]<>$]))[^\s"'{}()[\]<>$]{8,}`;
|
|
9
35
|
export const BUILTIN_RULES = [
|
|
10
36
|
{
|
|
11
37
|
type: "private_key",
|
|
12
|
-
|
|
38
|
+
// `BLOCK` is how PGP armors one.
|
|
39
|
+
pattern: /-----BEGIN [A-Z0-9 ]*PRIVATE KEY(?: BLOCK)?-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY(?: BLOCK)?-----|$)/g,
|
|
13
40
|
replacement: marker("private_key"),
|
|
14
41
|
},
|
|
15
42
|
{
|
|
@@ -48,17 +75,63 @@ export const BUILTIN_RULES = [
|
|
|
48
75
|
replacement: marker("google_key"),
|
|
49
76
|
},
|
|
50
77
|
{
|
|
78
|
+
// Secret and restricted keys; `pk_` is publishable by design.
|
|
79
|
+
type: "stripe_key",
|
|
80
|
+
pattern: /\b[rs]k_(?:live|test)_[A-Za-z0-9]{16,}/g,
|
|
81
|
+
replacement: marker("stripe_key"),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: "slack_token",
|
|
85
|
+
pattern: /\bxox[abposr]-[A-Za-z0-9-]{10,}/g,
|
|
86
|
+
replacement: marker("slack_token"),
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
type: "npm_token",
|
|
90
|
+
pattern: /\bnpm_[A-Za-z0-9]{36}\b/g,
|
|
91
|
+
replacement: marker("npm_token"),
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
// After every shape a bearer token can have, so a JWT or a GitHub token
|
|
95
|
+
// keeps its own label and its marker is not marked again.
|
|
96
|
+
type: "bearer_token",
|
|
97
|
+
pattern: /\b(Bearer\s+)(?!\[ISY_REDACTED)[A-Za-z0-9._~+/-]{20,}=*/gi,
|
|
98
|
+
replacement: `$1${marker("bearer_token")}`,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
// Any scheme: a password in a URL is one whatever speaks it — rediss,
|
|
102
|
+
// amqps, https to a bare IP. The scheme is capped because `\b` lets a match
|
|
103
|
+
// start inside a dotted or dashed run: unbounded, every start rescans the
|
|
104
|
+
// rest of the run, and a long one costs minutes.
|
|
51
105
|
type: "connection_string",
|
|
52
|
-
pattern: /\b(
|
|
106
|
+
pattern: /\b([A-Za-z][A-Za-z0-9+.-]{0,31}):\/\/([^\s:/@]+):([^\s/@]+)@/g,
|
|
53
107
|
replacement: `$1://$2:${marker("connection_string")}@`,
|
|
54
108
|
},
|
|
55
109
|
{
|
|
110
|
+
// After the connection string: its password sits right before an `@` too.
|
|
111
|
+
// Starts only where a run of local-part characters starts: with `\b`, every
|
|
112
|
+
// dot, dash and `%` in a run began a new scan of the rest of it, and a
|
|
113
|
+
// version list or a URL-encoded query took minutes to get through.
|
|
114
|
+
type: "email",
|
|
115
|
+
pattern: /(?<![A-Za-z0-9._%+-])[A-Za-z0-9._%+-]+@(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,}\b/g,
|
|
116
|
+
replacement: marker("email"),
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
// The name may close a quote of its own: `"password": "…"`.
|
|
56
120
|
type: "assignment",
|
|
57
|
-
pattern:
|
|
121
|
+
pattern: new RegExp(String.raw `(?<![A-Za-z0-9_.-])(${PLAIN_NAME})(["']?\s*[=:]\s*)(["']?)${SECRET_VALUE}`, "g"),
|
|
58
122
|
replacement: `$1$2$3${marker("assignment")}`,
|
|
59
123
|
},
|
|
124
|
+
{
|
|
125
|
+
// A camelCase name counts where it is plainly data — a quoted key with a
|
|
126
|
+
// quoted value (`{"accessToken":"…"}`) or `name=value` with no space, as
|
|
127
|
+
// `.npmrc` writes `_authToken=` — and not in `adminPassword = someVariable`.
|
|
128
|
+
type: "assignment",
|
|
129
|
+
pattern: new RegExp(String.raw `(?<=["'])(${CAMEL_NAME})(["']\s*:\s*["'])${SECRET_VALUE}|(?<![A-Za-z0-9_.-])(${CAMEL_NAME})(=)${SECRET_VALUE}`, "g"),
|
|
130
|
+
replacement: `$1$2$3$4${marker("assignment")}`,
|
|
131
|
+
},
|
|
60
132
|
];
|
|
61
|
-
|
|
133
|
+
/** A JSON key is data, never code, so any spelling of a secret's name counts. */
|
|
134
|
+
const SENSITIVE_KEY = new RegExp(`^${secretName()}$`);
|
|
62
135
|
const MIN_SENSITIVE_VALUE = 8;
|
|
63
136
|
const EDIT_INPUT_FIELDS = ["content", "old_string", "new_string", "new_source"];
|
|
64
137
|
function isObject(value) {
|
|
@@ -93,6 +166,20 @@ export function applyRules(text, rules, onMatch) {
|
|
|
93
166
|
function isDotenvPath(filePath) {
|
|
94
167
|
return typeof filePath === "string" && basename(filePath).startsWith(".env");
|
|
95
168
|
}
|
|
169
|
+
/** Commands that print a file they are given, or load it into the shell. */
|
|
170
|
+
const SHELL_READER = /^\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;
|
|
171
|
+
/**
|
|
172
|
+
* `cat .env`, `grep KEY config/.env.local`, `source .env`: a shell call that
|
|
173
|
+
* reads a dotenv file is as much a read of it as `Read {file_path}` is, and
|
|
174
|
+
* its output is the file. The command itself stays — it names the file, not
|
|
175
|
+
* what is in it.
|
|
176
|
+
*/
|
|
177
|
+
function readsDotenv(command) {
|
|
178
|
+
if (typeof command !== "string" || !command.includes(".env"))
|
|
179
|
+
return false;
|
|
180
|
+
return commandSegments(withoutHeredocs(command)).some((segment) => SHELL_READER.test(segment) &&
|
|
181
|
+
segment.trim().split(/\s+/).slice(1).some((word) => isDotenvPath(word.replace(/["'`]/g, "").replace(/^\w*:/, ""))));
|
|
182
|
+
}
|
|
96
183
|
function cutDotenvInput(input, context) {
|
|
97
184
|
for (const field of EDIT_INPUT_FIELDS) {
|
|
98
185
|
if (typeof input[field] === "string") {
|
|
@@ -113,6 +200,11 @@ function scanDotenv(record, context) {
|
|
|
113
200
|
const input = isObject(block.input) ? block.input : undefined;
|
|
114
201
|
if (!input)
|
|
115
202
|
continue;
|
|
203
|
+
if ((block.name === "Bash" || block.name === "PowerShell") && readsDotenv(input.command)) {
|
|
204
|
+
if (typeof block.id === "string")
|
|
205
|
+
context.envToolUseIds.add(block.id);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
116
208
|
if (!isDotenvPath(input.file_path) && !isDotenvPath(input.notebook_path))
|
|
117
209
|
continue;
|
|
118
210
|
if (typeof block.id === "string")
|
|
@@ -170,9 +262,95 @@ function learnRoot(record, context) {
|
|
|
170
262
|
return;
|
|
171
263
|
context.roots = { ...context.roots, ...resolveRoots({ cwd }) };
|
|
172
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Claude Code's `attachment` records are the harness's context for the model:
|
|
267
|
+
* the account's email (`session_context`), its organisation (`credential_org`),
|
|
268
|
+
* the whole system prompt with memory and CLAUDE.md (`prompt_snapshot`), the
|
|
269
|
+
* connectors' instructions. Nothing downstream reads past their `type`, so that
|
|
270
|
+
* is all that goes. The record itself stays: the next record names it as its
|
|
271
|
+
* `parentUuid`, and the parser walks that chain.
|
|
272
|
+
*
|
|
273
|
+
* Claude Code 2.1.30x also records the request it sends: `api-request-shape`
|
|
274
|
+
* carries the system prompt and the tool definitions, `api-request-blob` the
|
|
275
|
+
* context blocks sent beside the conversation — memory, CLAUDE.md, the email
|
|
276
|
+
* again — and `api-request` the parameters, whose `safeguards` hand a
|
|
277
|
+
* classifier the account's user name, home directory and permission rules.
|
|
278
|
+
* `bridge-session` and `artifact-autoreact-ledger` are cut the same way: one
|
|
279
|
+
* names the account and organisation that own the session's bridge, the other
|
|
280
|
+
* the account. The parser reads none of them past their type, so only the
|
|
281
|
+
* fields that name them go.
|
|
282
|
+
*/
|
|
283
|
+
const REQUEST_RECORD_KEYS = new Set(["type", "uuid", "parentUuid", "sessionId", "timestamp", "version", "shapeHash", "hash"]);
|
|
284
|
+
const STRIPPED_RECORD_TYPES = new Set([
|
|
285
|
+
"api-request",
|
|
286
|
+
"api-request-shape",
|
|
287
|
+
"api-request-blob",
|
|
288
|
+
"bridge-session",
|
|
289
|
+
"artifact-autoreact-ledger",
|
|
290
|
+
]);
|
|
291
|
+
function stripAttachment(record, context) {
|
|
292
|
+
if (typeof record.type === "string" && STRIPPED_RECORD_TYPES.has(record.type)) {
|
|
293
|
+
for (const key of Object.keys(record))
|
|
294
|
+
if (!REQUEST_RECORD_KEYS.has(key))
|
|
295
|
+
delete record[key];
|
|
296
|
+
count(context, "attachment", 1);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (record.type !== "attachment")
|
|
300
|
+
return;
|
|
301
|
+
const kind = isObject(record.attachment) ? record.attachment.type : undefined;
|
|
302
|
+
record.attachment = typeof kind === "string" ? { type: kind } : {};
|
|
303
|
+
delete record.rendered;
|
|
304
|
+
delete record.renderedRole;
|
|
305
|
+
count(context, "attachment", 1);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Harness bookkeeping Claude Code writes beside a turn, read by nothing here or
|
|
309
|
+
* on the server. `wireToolInputs` repeats every call's input, out of reach of
|
|
310
|
+
* the dotenv cut, which edits the copy in `message` (`scanDotenv`);
|
|
311
|
+
* `serverClassifierRequest` and `serverClassifierContext` are what a permission
|
|
312
|
+
* classifier was shown, the working tree's git state included;
|
|
313
|
+
* `wireIngestContext` and `permissionDecision` say where a call ran and what
|
|
314
|
+
* allowed it.
|
|
315
|
+
*/
|
|
316
|
+
const HARNESS_FIELDS = [
|
|
317
|
+
"wireToolInputs",
|
|
318
|
+
"serverClassifierRequest",
|
|
319
|
+
"serverClassifierContext",
|
|
320
|
+
"wireIngestContext",
|
|
321
|
+
"permissionDecision",
|
|
322
|
+
];
|
|
323
|
+
function stripHarnessFields(record, context) {
|
|
324
|
+
let stripped = false;
|
|
325
|
+
for (const field of HARNESS_FIELDS) {
|
|
326
|
+
if (!(field in record))
|
|
327
|
+
continue;
|
|
328
|
+
delete record[field];
|
|
329
|
+
stripped = true;
|
|
330
|
+
}
|
|
331
|
+
if (stripped)
|
|
332
|
+
count(context, "attachment", 1);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* A user record marked `isMeta` is the harness talking in the user's place: a
|
|
336
|
+
* skill's body, a `<system-reminder>`, a command's caveat, an extension's
|
|
337
|
+
* instructions, a peer agent's message. Read as text it is a turn the
|
|
338
|
+
* developer never typed, holding files the developer never sent, so only a
|
|
339
|
+
* marker goes. None carries a tool result, and the record stays where it is:
|
|
340
|
+
* the next one names it as its `parentUuid`.
|
|
341
|
+
*/
|
|
342
|
+
function stripMeta(record, context) {
|
|
343
|
+
if (record.type !== "user" || record.isMeta !== true || !isObject(record.message))
|
|
344
|
+
return;
|
|
345
|
+
record.message = { ...record.message, content: marker("meta") };
|
|
346
|
+
count(context, "attachment", 1);
|
|
347
|
+
}
|
|
173
348
|
function redactRecord(record, context) {
|
|
174
349
|
learnRoot(record, context);
|
|
175
350
|
scanDotenv(record, context);
|
|
351
|
+
stripAttachment(record, context);
|
|
352
|
+
stripHarnessFields(record, context);
|
|
353
|
+
stripMeta(record, context);
|
|
176
354
|
return redactValue(record, context);
|
|
177
355
|
}
|
|
178
356
|
function createContext(options, invalid) {
|
|
@@ -213,6 +391,13 @@ function redactOneLine(line, context) {
|
|
|
213
391
|
}
|
|
214
392
|
return { line: JSON.stringify(redactRecord(parsed, context)), unparsed: false };
|
|
215
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* A transcript's lines, redacted. With no `cwd`, paths are rooted at the first
|
|
396
|
+
* record that names one; with no `home`, at the home that directory implies,
|
|
397
|
+
* else this machine's. Exported as `isy/redact` so the server can re-run the
|
|
398
|
+
* rules over a transcript an older client uploaded: there the machine is the
|
|
399
|
+
* server, so it passes `home: ""` and roots paths in the transcript alone.
|
|
400
|
+
*/
|
|
216
401
|
export function redactLines(lines, options = {}) {
|
|
217
402
|
const invalid = [];
|
|
218
403
|
const context = createContext(options, invalid);
|
|
@@ -230,17 +415,19 @@ export function redactLines(lines, options = {}) {
|
|
|
230
415
|
}
|
|
231
416
|
return { lines: output, summary: summarize(context, total, unparsed, invalid) };
|
|
232
417
|
}
|
|
233
|
-
|
|
418
|
+
/**
|
|
419
|
+
* `redactLines` for lines that arrive one at a time — a file read as it streams,
|
|
420
|
+
* or a Claude session with its subagents spliced in (`subagents.ts`). One
|
|
421
|
+
* context for the whole stream, so the working directory the first record names
|
|
422
|
+
* roots every path after it, the subagents' included.
|
|
423
|
+
*/
|
|
424
|
+
export async function redactLineStream(lines, options = {}) {
|
|
234
425
|
const invalid = [];
|
|
235
426
|
const context = createContext(options, invalid);
|
|
236
|
-
const reader = createInterface({
|
|
237
|
-
input: createReadStream(filePath, { encoding: "utf8" }),
|
|
238
|
-
crlfDelay: Infinity,
|
|
239
|
-
});
|
|
240
427
|
const output = [];
|
|
241
428
|
let total = 0;
|
|
242
429
|
let unparsed = 0;
|
|
243
|
-
for await (const line of
|
|
430
|
+
for await (const line of lines) {
|
|
244
431
|
total += 1;
|
|
245
432
|
const result = redactOneLine(line, context);
|
|
246
433
|
if (result.line.length === 0)
|
|
@@ -251,4 +438,7 @@ export async function redactTranscriptFile(filePath, options = {}) {
|
|
|
251
438
|
}
|
|
252
439
|
return { lines: output, summary: summarize(context, total, unparsed, invalid) };
|
|
253
440
|
}
|
|
441
|
+
export function redactTranscriptFile(filePath, options = {}) {
|
|
442
|
+
return redactLineStream(fileLines(filePath), options);
|
|
443
|
+
}
|
|
254
444
|
//# sourceMappingURL=redact.js.map
|