chat-recall 0.7.81 → 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.
package/dist/cli.js CHANGED
@@ -29372,7 +29372,7 @@ var init_scan_pool = __esm({
29372
29372
  slot.pending = null;
29373
29373
  this.slots = this.slots.filter((s) => s !== slot);
29374
29374
  if (this.slots.length === 0) this.disabled = true;
29375
- resolve3?.({ id: -1, findings: [], redactions: 0, rows: null, error: `scan worker died: ${err}` });
29375
+ resolve3?.({ id: -1, findings: [], redactions: 0, rows: null, archive: null, error: `scan worker died: ${err}` });
29376
29376
  this.pump();
29377
29377
  };
29378
29378
  worker.on("error", die);
@@ -29449,6 +29449,22 @@ var init_scan_pool = __esm({
29449
29449
  async runDerived(task) {
29450
29450
  return this.dispatch({ ...task, task: "derived", id: 0 });
29451
29451
  }
29452
+ /**
29453
+ * The secret scan of a session read in chunks, on a worker.
29454
+ *
29455
+ * The worker reads the session itself. Null means the caller scans inline.
29456
+ */
29457
+ async runFindings(task) {
29458
+ return this.dispatch({ ...task, task: "findings", id: 0 });
29459
+ }
29460
+ /**
29461
+ * The redacted raw archive of a streamed session, written to a temp file on a worker.
29462
+ *
29463
+ * Null means the caller writes it inline.
29464
+ */
29465
+ async runArchive(task) {
29466
+ return this.dispatch({ ...task, task: "archive", id: 0 });
29467
+ }
29452
29468
  async dispatch(task) {
29453
29469
  this.start();
29454
29470
  if (this.disabled) return null;
@@ -30157,6 +30173,74 @@ var init_yield_loop = __esm({
30157
30173
  }
30158
30174
  });
30159
30175
 
30176
+ // src/heavy-session-work.ts
30177
+ async function scanTranscriptFindingsChunked(ref, tenantRules) {
30178
+ const backend = getBackendForId(ref.prefixedId);
30179
+ const findings = [];
30180
+ if (!backend?.readFromOffset) return findings;
30181
+ let offset = 0;
30182
+ let lineBase = 0;
30183
+ for (; ; ) {
30184
+ await yieldToEventLoop();
30185
+ const chunk = await backend.readFromOffset(ref.prefixedId, offset, SYNC_CHUNK_BYTES);
30186
+ if (chunk.newOffset <= offset) break;
30187
+ offset = chunk.newOffset;
30188
+ if (chunk.skippedBytes) {
30189
+ lineBase += 1;
30190
+ continue;
30191
+ }
30192
+ try {
30193
+ for (const f of scanTextForFindings(chunk.text)) {
30194
+ findings.push({ session_id: ref.prefixedId, detector: "builtin", rule: f.rule, line: lineBase + f.line, preview: f.preview });
30195
+ }
30196
+ if (tenantRules && tenantRules.length > 0) {
30197
+ for (const f of scanTenantRules(chunk.text, tenantRules)) {
30198
+ findings.push({ session_id: ref.prefixedId, detector: f.detector, rule: f.rule, line: lineBase + f.line, preview: f.preview });
30199
+ }
30200
+ }
30201
+ } catch {
30202
+ }
30203
+ for (let i = chunk.text.indexOf("\n"); i >= 0; i = chunk.text.indexOf("\n", i + 1)) lineBase++;
30204
+ }
30205
+ return dropFuzzyFindings(findings, (f) => ({ detector: f.detector, rule: f.rule }));
30206
+ }
30207
+ function diskArchiveSource(ref) {
30208
+ if (ref.toolId !== "claude") return null;
30209
+ const groups = resolveSessionContentGroups(ref.rawId);
30210
+ if (groups.length === 0 || groups.some((g) => g.paths.length !== 1)) return null;
30211
+ return {
30212
+ kind: "disk",
30213
+ files: groups.map((g) => ({ name: g.name === "main" ? `${ref.rawId}.jsonl` : g.name, path: g.paths[0] }))
30214
+ };
30215
+ }
30216
+ function streamedArchiveSource(ref) {
30217
+ const disk = diskArchiveSource(ref);
30218
+ if (disk) return disk;
30219
+ const backend = getBackendForId(ref.prefixedId);
30220
+ if (ref.toolId === "claude" || !backend?.iterateRawSessionLines) return null;
30221
+ return { kind: "lines", files: [{ name: `${ref.rawId}.dump.jsonl`, lines: () => backend.iterateRawSessionLines(ref.prefixedId) }] };
30222
+ }
30223
+ async function writeStreamedArchive(ref, redact) {
30224
+ const source = streamedArchiveSource(ref);
30225
+ if (!source) return null;
30226
+ return writeArchiveFile(source, { tool: ref.toolId, mtime: Math.floor(ref.mtime ?? 0) || 0 }, redact);
30227
+ }
30228
+ var SYNC_CHUNK_BYTES;
30229
+ var init_heavy_session_work = __esm({
30230
+ "src/heavy-session-work.ts"() {
30231
+ "use strict";
30232
+ init_backends();
30233
+ init_tool_backend();
30234
+ init_live_session_scan();
30235
+ init_secret_redactor();
30236
+ init_secret_scanner();
30237
+ init_secret_precision();
30238
+ init_raw_archive_parts();
30239
+ init_yield_loop();
30240
+ SYNC_CHUNK_BYTES = 8 * 1024 * 1024;
30241
+ }
30242
+ });
30243
+
30160
30244
  // src/server-probe.ts
30161
30245
  var server_probe_exports = {};
30162
30246
  __export(server_probe_exports, {
@@ -31766,7 +31850,7 @@ async function syncToTargetInScope(cred, opts = {}) {
31766
31850
  await appendAdd(tail.conv, tail.bytes);
31767
31851
  if (tail.findings.length > 0) {
31768
31852
  await appendFlush();
31769
- const all = await scanTranscriptFindingsChunked(ref, tenantRules);
31853
+ const all = await scanFindingsOffloaded(ref, tenantRules);
31770
31854
  if (all.length > 0) await findingsBatch.add(all);
31771
31855
  }
31772
31856
  walked++;
@@ -32074,36 +32158,6 @@ function exportByteLength(exp) {
32074
32158
  if (!exp) return 0;
32075
32159
  return exp.files.reduce((n, f) => n + f.bytes.length, 0);
32076
32160
  }
32077
- async function scanTranscriptFindingsChunked(ref, tenantRules) {
32078
- const backend = getBackendForId(ref.prefixedId);
32079
- const findings = [];
32080
- if (!backend?.readFromOffset) return findings;
32081
- let offset = 0;
32082
- let lineBase = 0;
32083
- for (; ; ) {
32084
- await yieldToEventLoop();
32085
- const chunk = await backend.readFromOffset(ref.prefixedId, offset, SYNC_CHUNK_BYTES);
32086
- if (chunk.newOffset <= offset) break;
32087
- offset = chunk.newOffset;
32088
- if (chunk.skippedBytes) {
32089
- lineBase += 1;
32090
- continue;
32091
- }
32092
- try {
32093
- for (const f of scanTextForFindings(chunk.text)) {
32094
- findings.push({ session_id: ref.prefixedId, detector: "builtin", rule: f.rule, line: lineBase + f.line, preview: f.preview });
32095
- }
32096
- if (tenantRules && tenantRules.length > 0) {
32097
- for (const f of scanTenantRules(chunk.text, tenantRules)) {
32098
- findings.push({ session_id: ref.prefixedId, detector: f.detector, rule: f.rule, line: lineBase + f.line, preview: f.preview });
32099
- }
32100
- }
32101
- } catch {
32102
- }
32103
- for (let i = chunk.text.indexOf("\n"); i >= 0; i = chunk.text.indexOf("\n", i + 1)) lineBase++;
32104
- }
32105
- return dropFuzzyFindings(findings, (f) => ({ detector: f.detector, rule: f.rule }));
32106
- }
32107
32161
  function sessionFileBytes(ref) {
32108
32162
  const backend = getBackendForId(ref.prefixedId);
32109
32163
  if (!backend?.isAppendOnly?.()) return 0;
@@ -32121,6 +32175,42 @@ function sessionBuildBytes(ref) {
32121
32175
  if (main === 0) return 0;
32122
32176
  return Math.max(main, shadowUncompressedBytes(ref.toolId, ref.rawId));
32123
32177
  }
32178
+ async function scanFindingsOffloaded(ref, tenantRules) {
32179
+ const pool = scanPool();
32180
+ if (pool.enabled) {
32181
+ const packVersion = lastServerPackSpec?.version ?? "";
32182
+ const sendPack = lastServerPackSpec !== null && pool.needsPack(packVersion);
32183
+ const result = await pool.runFindings({
32184
+ ref: { prefixedId: ref.prefixedId, rawId: ref.rawId, toolId: ref.toolId },
32185
+ tenantRules,
32186
+ pack: sendPack && lastServerPackSpec ? { version: packVersion, rules: lastServerPackSpec.rules } : void 0,
32187
+ packVersion
32188
+ });
32189
+ if (result) {
32190
+ if (sendPack) pool.markPackSent(packVersion);
32191
+ return result.findings;
32192
+ }
32193
+ }
32194
+ return scanTranscriptFindingsChunked(ref, tenantRules);
32195
+ }
32196
+ async function writeStreamedArchiveOffloaded(ref, count) {
32197
+ const pool = scanPool();
32198
+ if (pool.enabled) {
32199
+ const packVersion = lastServerPackSpec?.version ?? "";
32200
+ const sendPack = lastServerPackSpec !== null && pool.needsPack(packVersion);
32201
+ const result = await pool.runArchive({
32202
+ ref: { prefixedId: ref.prefixedId, rawId: ref.rawId, toolId: ref.toolId, mtime: ref.mtime },
32203
+ pack: sendPack && lastServerPackSpec ? { version: packVersion, rules: lastServerPackSpec.rules } : void 0,
32204
+ packVersion
32205
+ });
32206
+ if (result) {
32207
+ if (sendPack) pool.markPackSent(packVersion);
32208
+ count.redactions += result.redactions;
32209
+ return result.archive;
32210
+ }
32211
+ }
32212
+ return writeStreamedArchive(ref, (t) => redactSecrets(t, { force: true, count }));
32213
+ }
32124
32214
  async function buildConversationSync(ref, mtime, opts = {}) {
32125
32215
  const mapPath = opts.mapPath ?? ((p) => p);
32126
32216
  let includeRaw = opts.includeRaw !== false;
@@ -32149,7 +32239,7 @@ async function buildConversationSync(ref, mtime, opts = {}) {
32149
32239
  } catch {
32150
32240
  }
32151
32241
  includeRaw = false;
32152
- oversizedFindings = await scanTranscriptFindingsChunked(ref, opts.tenantRules);
32242
+ oversizedFindings = await scanFindingsOffloaded(ref, opts.tenantRules);
32153
32243
  } else {
32154
32244
  try {
32155
32245
  const backend = getBackendForId(ref.prefixedId) ?? getBackend("claude");
@@ -32410,17 +32500,13 @@ async function buildConversationSync(ref, mtime, opts = {}) {
32410
32500
  if (wantRaw && !raw_b64) {
32411
32501
  try {
32412
32502
  const redact = (t) => redactSecrets(t, { force: true, count });
32413
- let source = null;
32414
- let archiveMtime = Math.floor(ref.mtime) || 0;
32415
- let archiveTool = ref.toolId;
32416
32503
  if (container) {
32417
- source = { kind: "memory", files: container.files };
32418
- archiveMtime = container.mtime;
32419
- archiveTool = container.tool;
32504
+ const source = { kind: "memory", files: container.files };
32505
+ archive = { file: await writeArchiveFile(source, { tool: container.tool, mtime: container.mtime }, redact), tool: container.tool, mtime: container.mtime };
32420
32506
  } else if (oversized || exportOverCeiling) {
32421
- source = streamedArchiveSource(ref);
32507
+ const file = await writeStreamedArchiveOffloaded(ref, count);
32508
+ if (file) archive = { file, tool: ref.toolId, mtime: Math.floor(ref.mtime) || 0 };
32422
32509
  }
32423
- if (source) archive = { file: await writeArchiveFile(source, { tool: archiveTool, mtime: archiveMtime }, redact), tool: archiveTool, mtime: archiveMtime };
32424
32510
  } catch (err) {
32425
32511
  console.error(`[sync] raw archive for ${ref.prefixedId} not written: ${err instanceof Error ? err.message : err}`);
32426
32512
  }
@@ -32460,22 +32546,6 @@ async function buildConversationSync(ref, mtime, opts = {}) {
32460
32546
  archive
32461
32547
  };
32462
32548
  }
32463
- function streamedArchiveSource(ref) {
32464
- const disk = diskArchiveSource(ref);
32465
- if (disk) return disk;
32466
- const backend = getBackendForId(ref.prefixedId);
32467
- if (ref.toolId === "claude" || !backend?.iterateRawSessionLines) return null;
32468
- return { kind: "lines", files: [{ name: `${ref.rawId}.dump.jsonl`, lines: () => backend.iterateRawSessionLines(ref.prefixedId) }] };
32469
- }
32470
- function diskArchiveSource(ref) {
32471
- if (ref.toolId !== "claude") return null;
32472
- const groups = resolveSessionContentGroups(ref.rawId);
32473
- if (groups.length === 0 || groups.some((g) => g.paths.length !== 1)) return null;
32474
- return {
32475
- kind: "disk",
32476
- files: groups.map((g) => ({ name: g.name === "main" ? `${ref.rawId}.jsonl` : g.name, path: g.paths[0] }))
32477
- };
32478
- }
32479
32549
  function parseTailMessages(tool, text, backend = null) {
32480
32550
  if (!text || !text.trim()) return [];
32481
32551
  if (tool === "claude") return parseClaudeTranscriptText(text);
@@ -32593,7 +32663,7 @@ async function syncIncremental(opts = {}) {
32593
32663
  lock.release();
32594
32664
  }
32595
32665
  }
32596
- var ownVersion, ERROR_CLASS, STANDING_FAILURE, walkProgressForUpload, lastServerPackSpec, credPath, fileTarget, _securityConfigCache, SECURITY_CONFIG_TTL_MS, _syncConfigCache, EMPTY_SYNC_CONFIG, _fetchTenantSyncConfigForTests, SYNC_RULES_REFUSAL, hashPath, acceptedUploads, MAX_DERIVED_ROW_BYTES, isLocalHost, FULL_KEY, CAPS_TTL_MS, capsOk, advertisedIngestConc, advertisedGzipBody, FULL_BUILD_MAX_BYTES, DERIVED_MAX_BYTES, SYNC_CHUNK_BYTES, TOOLKIT_INVENTORY_TYPES, BATCH_SCAN_MAX_BYTES;
32666
+ var ownVersion, ERROR_CLASS, STANDING_FAILURE, walkProgressForUpload, lastServerPackSpec, credPath, fileTarget, _securityConfigCache, SECURITY_CONFIG_TTL_MS, _syncConfigCache, EMPTY_SYNC_CONFIG, _fetchTenantSyncConfigForTests, SYNC_RULES_REFUSAL, hashPath, acceptedUploads, MAX_DERIVED_ROW_BYTES, isLocalHost, FULL_KEY, CAPS_TTL_MS, capsOk, advertisedIngestConc, advertisedGzipBody, FULL_BUILD_MAX_BYTES, DERIVED_MAX_BYTES, TOOLKIT_INVENTORY_TYPES, BATCH_SCAN_MAX_BYTES;
32597
32667
  var init_sync_client = __esm({
32598
32668
  "src/sync-client.ts"() {
32599
32669
  "use strict";
@@ -32642,6 +32712,7 @@ var init_sync_client = __esm({
32642
32712
  init_session_file_scan();
32643
32713
  init_raw_archive_parts();
32644
32714
  init_yield_loop();
32715
+ init_heavy_session_work();
32645
32716
  init_backends();
32646
32717
  ownVersion = "0.0.0";
32647
32718
  try {
@@ -32680,7 +32751,6 @@ var init_sync_client = __esm({
32680
32751
  advertisedGzipBody = /* @__PURE__ */ new Set();
32681
32752
  FULL_BUILD_MAX_BYTES = Math.max(8, parseInt(process.env.CHAT_RECALL_FULL_BUILD_MAX_MB || "12", 10)) * 1024 * 1024;
32682
32753
  DERIVED_MAX_BYTES = Math.max(8, parseInt(process.env.CHAT_RECALL_DERIVED_MAX_MB || "64", 10)) * 1024 * 1024;
32683
- SYNC_CHUNK_BYTES = 8 * 1024 * 1024;
32684
32754
  TOOLKIT_INVENTORY_TYPES = /* @__PURE__ */ new Set(["skill", "mcp", "command", "agent", "plugin"]);
32685
32755
  BATCH_SCAN_MAX_BYTES = Math.max(1, parseInt(process.env.CHAT_RECALL_BATCHSCAN_MAX_MB || "64", 10)) * 1024 * 1024;
32686
32756
  }
@@ -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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
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,GAAG,CAAC,UAAU,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAqB,EAAE,CAAC;IACtC,IAAI,CAAC,OAAO,EAAE,cAAc;QAAE,OAAO,QAAQ,CAAC;IAC9C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,SAAS,CAAC;QACR,2FAA2F;QAC3F,+EAA+E;QAC/E,MAAM,gBAAg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