chat-recall 0.7.80 → 0.7.82

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,49 @@
1
+ /**
2
+ * The CPU-bound work on a session too large to hold in memory: the secret scan
3
+ * and the redacted raw archive, both read from disk a piece at a time.
4
+ *
5
+ * The worker thread (scan-worker.ts) and the main thread (the fallback when the
6
+ * pool is off) run these same functions, so the result does not depend on which
7
+ * thread ran them. Each of them reads the session itself, so a task carries an
8
+ * id and small options, and only findings or the path of a temp file come back.
9
+ * A session of any size then costs the main thread one message in and one out.
10
+ */
11
+ import '@chat-recall/engine/core/backends/index.js';
12
+ import type { SessionRef } from '@chat-recall/engine/core/tool-backend.js';
13
+ import { type ArchiveFile, type ArchiveSource } from './raw-archive-parts.js';
14
+ /** The part of a session reference these functions read. */
15
+ export type SessionHandle = Pick<SessionRef, 'prefixedId' | 'rawId' | 'toolId'> & {
16
+ mtime?: number;
17
+ };
18
+ export interface SessionFinding {
19
+ session_id: string;
20
+ detector: string;
21
+ rule: string;
22
+ line: number;
23
+ preview: string;
24
+ }
25
+ /** Bytes of transcript one chunk of a chunked sync carries: the head of an
26
+ * oversized FULL sync, each append, and each piece of the secret scan. */
27
+ export declare const SYNC_CHUNK_BYTES: number;
28
+ /**
29
+ * Secret findings for a whole transcript, read one chunk at a time.
30
+ *
31
+ * A chunked session never holds its full text, so it cannot use the one-pass
32
+ * scan of the in-memory build. Line numbers are absolute: each chunk's
33
+ * findings are shifted by the lines of the chunks before it. A line longer
34
+ * than a chunk is skipped by the reader, and it counts as one line.
35
+ */
36
+ export declare function scanTranscriptFindingsChunked(ref: SessionHandle, tenantRules?: Array<{
37
+ name: string;
38
+ regex: string;
39
+ }>): Promise<SessionFinding[]>;
40
+ /** The files of a Claude session on disk, one file per transcript, or null when a copy lives in several homes. */
41
+ export declare function diskArchiveSource(ref: SessionHandle): ArchiveSource | null;
42
+ /** The archive source of a session that is streamed from disk, or from the rows of a database. */
43
+ export declare function streamedArchiveSource(ref: SessionHandle): ArchiveSource | null;
44
+ /**
45
+ * Write the redacted raw archive of a streamed session to a temp file.
46
+ * Null when the session has no source to stream from.
47
+ */
48
+ export declare function writeStreamedArchive(ref: SessionHandle, redact: (text: string) => string): Promise<ArchiveFile | null>;
49
+ //# sourceMappingURL=heavy-session-work.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heavy-session-work.d.ts","sourceRoot":"","sources":["../src/heavy-session-work.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,4CAA4C,CAAC;AAMpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OAAO,EAAoB,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGhG,4DAA4D;AAC5D,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErG,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;2EAC2E;AAC3E,eAAO,MAAM,gBAAgB,QAAkB,CAAC;AAEhD;;;;;;;GAOG;AACH,wBAAsB,6BAA6B,CACjD,GAAG,EAAE,aAAa,EAClB,WAAW,CAAC,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,GACnD,OAAO,CAAC,cAAc,EAAE,CAAC,CA2B3B;AAED,kHAAkH;AAClH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,aAAa,GAAG,aAAa,GAAG,IAAI,CAQ1E;AAED,kGAAkG;AAClG,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,aAAa,GAAG,aAAa,GAAG,IAAI,CAO9E;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,aAAa,EAClB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAC/B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAI7B"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The CPU-bound work on a session too large to hold in memory: the secret scan
3
+ * and the redacted raw archive, both read from disk a piece at a time.
4
+ *
5
+ * The worker thread (scan-worker.ts) and the main thread (the fallback when the
6
+ * pool is off) run these same functions, so the result does not depend on which
7
+ * thread ran them. Each of them reads the session itself, so a task carries an
8
+ * id and small options, and only findings or the path of a temp file come back.
9
+ * A session of any size then costs the main thread one message in and one out.
10
+ */
11
+ import '@chat-recall/engine/core/backends/index.js'; // register the tool backends
12
+ import { getBackendForId } from '@chat-recall/engine/core/tool-backend.js';
13
+ import { resolveSessionContentGroups } from '@chat-recall/engine/core/live-session-scan.js';
14
+ import { scanTextForFindings } from '@chat-recall/engine/core/secret-redactor.js';
15
+ import { scanTenantRules } from '@chat-recall/engine/core/secret-scanner.js';
16
+ import { dropFuzzyFindings } from '@chat-recall/engine/core/secret-precision.js';
17
+ import { writeArchiveFile } from './raw-archive-parts.js';
18
+ import { yieldToEventLoop } from './yield-loop.js';
19
+ /** Bytes of transcript one chunk of a chunked sync carries: the head of an
20
+ * oversized FULL sync, each append, and each piece of the secret scan. */
21
+ export const SYNC_CHUNK_BYTES = 8 * 1024 * 1024;
22
+ /**
23
+ * Secret findings for a whole transcript, read one chunk at a time.
24
+ *
25
+ * A chunked session never holds its full text, so it cannot use the one-pass
26
+ * scan of the in-memory build. Line numbers are absolute: each chunk's
27
+ * findings are shifted by the lines of the chunks before it. A line longer
28
+ * than a chunk is skipped by the reader, and it counts as one line.
29
+ */
30
+ export async function scanTranscriptFindingsChunked(ref, tenantRules) {
31
+ const backend = getBackendForId(ref.prefixedId);
32
+ const findings = [];
33
+ if (!backend?.readFromOffset)
34
+ return findings;
35
+ let offset = 0;
36
+ let lineBase = 0;
37
+ for (;;) {
38
+ // Each chunk is a scan of 8 MB of text, and readFromOffset settles without a wait for I/O,
39
+ // so without this turn the chunks of a 150 MB session ran as one block of 7 s.
40
+ await yieldToEventLoop();
41
+ const chunk = await backend.readFromOffset(ref.prefixedId, offset, SYNC_CHUNK_BYTES);
42
+ if (chunk.newOffset <= offset)
43
+ break;
44
+ offset = chunk.newOffset;
45
+ if (chunk.skippedBytes) {
46
+ lineBase += 1;
47
+ continue;
48
+ }
49
+ try {
50
+ for (const f of scanTextForFindings(chunk.text)) {
51
+ findings.push({ session_id: ref.prefixedId, detector: 'builtin', rule: f.rule, line: lineBase + f.line, preview: f.preview });
52
+ }
53
+ if (tenantRules && tenantRules.length > 0) {
54
+ for (const f of scanTenantRules(chunk.text, tenantRules)) {
55
+ findings.push({ session_id: ref.prefixedId, detector: f.detector, rule: f.rule, line: lineBase + f.line, preview: f.preview });
56
+ }
57
+ }
58
+ }
59
+ catch { /* best-effort */ }
60
+ for (let i = chunk.text.indexOf('\n'); i >= 0; i = chunk.text.indexOf('\n', i + 1))
61
+ lineBase++;
62
+ }
63
+ return dropFuzzyFindings(findings, (f) => ({ detector: f.detector, rule: f.rule }));
64
+ }
65
+ /** The files of a Claude session on disk, one file per transcript, or null when a copy lives in several homes. */
66
+ export function diskArchiveSource(ref) {
67
+ if (ref.toolId !== 'claude')
68
+ return null;
69
+ const groups = resolveSessionContentGroups(ref.rawId);
70
+ if (groups.length === 0 || groups.some((g) => g.paths.length !== 1))
71
+ return null;
72
+ return {
73
+ kind: 'disk',
74
+ files: groups.map((g) => ({ name: g.name === 'main' ? `${ref.rawId}.jsonl` : g.name, path: g.paths[0] })),
75
+ };
76
+ }
77
+ /** The archive source of a session that is streamed from disk, or from the rows of a database. */
78
+ export function streamedArchiveSource(ref) {
79
+ const disk = diskArchiveSource(ref);
80
+ if (disk)
81
+ return disk;
82
+ // A tool with a database gives its dump one row at a time, in the order and with the name of the export.
83
+ const backend = getBackendForId(ref.prefixedId);
84
+ if (ref.toolId === 'claude' || !backend?.iterateRawSessionLines)
85
+ return null;
86
+ return { kind: 'lines', files: [{ name: `${ref.rawId}.dump.jsonl`, lines: () => backend.iterateRawSessionLines(ref.prefixedId) }] };
87
+ }
88
+ /**
89
+ * Write the redacted raw archive of a streamed session to a temp file.
90
+ * Null when the session has no source to stream from.
91
+ */
92
+ export async function writeStreamedArchive(ref, redact) {
93
+ const source = streamedArchiveSource(ref);
94
+ if (!source)
95
+ return null;
96
+ return writeArchiveFile(source, { tool: ref.toolId, mtime: Math.floor(ref.mtime ?? 0) || 0 }, redact);
97
+ }
98
+ //# sourceMappingURL=heavy-session-work.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heavy-session-work.js","sourceRoot":"","sources":["../src/heavy-session-work.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,4CAA4C,CAAC,CAAC,6BAA6B;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AAC5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAAwC,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAanD;2EAC2E;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,GAAkB,EAClB,WAAoD;IAEpD,MAAM,OAAO,GAAG,eAAe,CAAC,GAA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