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/watch.js CHANGED
@@ -28547,7 +28547,7 @@ var init_scan_pool = __esm({
28547
28547
  slot.pending = null;
28548
28548
  this.slots = this.slots.filter((s) => s !== slot);
28549
28549
  if (this.slots.length === 0) this.disabled = true;
28550
- resolve3?.({ id: -1, findings: [], redactions: 0, rows: null, error: `scan worker died: ${err}` });
28550
+ resolve3?.({ id: -1, findings: [], redactions: 0, rows: null, archive: null, error: `scan worker died: ${err}` });
28551
28551
  this.pump();
28552
28552
  };
28553
28553
  worker.on("error", die);
@@ -28624,6 +28624,22 @@ var init_scan_pool = __esm({
28624
28624
  async runDerived(task) {
28625
28625
  return this.dispatch({ ...task, task: "derived", id: 0 });
28626
28626
  }
28627
+ /**
28628
+ * The secret scan of a session read in chunks, on a worker.
28629
+ *
28630
+ * The worker reads the session itself. Null means the caller scans inline.
28631
+ */
28632
+ async runFindings(task) {
28633
+ return this.dispatch({ ...task, task: "findings", id: 0 });
28634
+ }
28635
+ /**
28636
+ * The redacted raw archive of a streamed session, written to a temp file on a worker.
28637
+ *
28638
+ * Null means the caller writes it inline.
28639
+ */
28640
+ async runArchive(task) {
28641
+ return this.dispatch({ ...task, task: "archive", id: 0 });
28642
+ }
28627
28643
  async dispatch(task) {
28628
28644
  this.start();
28629
28645
  if (this.disabled) return null;
@@ -29175,6 +29191,74 @@ var init_yield_loop = __esm({
29175
29191
  }
29176
29192
  });
29177
29193
 
29194
+ // src/heavy-session-work.ts
29195
+ async function scanTranscriptFindingsChunked(ref, tenantRules) {
29196
+ const backend = getBackendForId(ref.prefixedId);
29197
+ const findings = [];
29198
+ if (!backend?.readFromOffset) return findings;
29199
+ let offset = 0;
29200
+ let lineBase = 0;
29201
+ for (; ; ) {
29202
+ await yieldToEventLoop();
29203
+ const chunk = await backend.readFromOffset(ref.prefixedId, offset, SYNC_CHUNK_BYTES);
29204
+ if (chunk.newOffset <= offset) break;
29205
+ offset = chunk.newOffset;
29206
+ if (chunk.skippedBytes) {
29207
+ lineBase += 1;
29208
+ continue;
29209
+ }
29210
+ try {
29211
+ for (const f of scanTextForFindings(chunk.text)) {
29212
+ findings.push({ session_id: ref.prefixedId, detector: "builtin", rule: f.rule, line: lineBase + f.line, preview: f.preview });
29213
+ }
29214
+ if (tenantRules && tenantRules.length > 0) {
29215
+ for (const f of scanTenantRules(chunk.text, tenantRules)) {
29216
+ findings.push({ session_id: ref.prefixedId, detector: f.detector, rule: f.rule, line: lineBase + f.line, preview: f.preview });
29217
+ }
29218
+ }
29219
+ } catch {
29220
+ }
29221
+ for (let i = chunk.text.indexOf("\n"); i >= 0; i = chunk.text.indexOf("\n", i + 1)) lineBase++;
29222
+ }
29223
+ return dropFuzzyFindings(findings, (f) => ({ detector: f.detector, rule: f.rule }));
29224
+ }
29225
+ function diskArchiveSource(ref) {
29226
+ if (ref.toolId !== "claude") return null;
29227
+ const groups = resolveSessionContentGroups(ref.rawId);
29228
+ if (groups.length === 0 || groups.some((g) => g.paths.length !== 1)) return null;
29229
+ return {
29230
+ kind: "disk",
29231
+ files: groups.map((g) => ({ name: g.name === "main" ? `${ref.rawId}.jsonl` : g.name, path: g.paths[0] }))
29232
+ };
29233
+ }
29234
+ function streamedArchiveSource(ref) {
29235
+ const disk = diskArchiveSource(ref);
29236
+ if (disk) return disk;
29237
+ const backend = getBackendForId(ref.prefixedId);
29238
+ if (ref.toolId === "claude" || !backend?.iterateRawSessionLines) return null;
29239
+ return { kind: "lines", files: [{ name: `${ref.rawId}.dump.jsonl`, lines: () => backend.iterateRawSessionLines(ref.prefixedId) }] };
29240
+ }
29241
+ async function writeStreamedArchive(ref, redact) {
29242
+ const source = streamedArchiveSource(ref);
29243
+ if (!source) return null;
29244
+ return writeArchiveFile(source, { tool: ref.toolId, mtime: Math.floor(ref.mtime ?? 0) || 0 }, redact);
29245
+ }
29246
+ var SYNC_CHUNK_BYTES;
29247
+ var init_heavy_session_work = __esm({
29248
+ "src/heavy-session-work.ts"() {
29249
+ "use strict";
29250
+ init_backends();
29251
+ init_tool_backend();
29252
+ init_live_session_scan();
29253
+ init_secret_redactor();
29254
+ init_secret_scanner();
29255
+ init_secret_precision();
29256
+ init_raw_archive_parts();
29257
+ init_yield_loop();
29258
+ SYNC_CHUNK_BYTES = 8 * 1024 * 1024;
29259
+ }
29260
+ });
29261
+
29178
29262
  // src/server-probe.ts
29179
29263
  var server_probe_exports = {};
29180
29264
  __export(server_probe_exports, {
@@ -30675,7 +30759,7 @@ async function syncToTargetInScope(cred, opts = {}) {
30675
30759
  await appendAdd(tail.conv, tail.bytes);
30676
30760
  if (tail.findings.length > 0) {
30677
30761
  await appendFlush();
30678
- const all = await scanTranscriptFindingsChunked(ref, tenantRules);
30762
+ const all = await scanFindingsOffloaded(ref, tenantRules);
30679
30763
  if (all.length > 0) await findingsBatch.add(all);
30680
30764
  }
30681
30765
  walked++;
@@ -30983,36 +31067,6 @@ function exportByteLength(exp) {
30983
31067
  if (!exp) return 0;
30984
31068
  return exp.files.reduce((n, f) => n + f.bytes.length, 0);
30985
31069
  }
30986
- async function scanTranscriptFindingsChunked(ref, tenantRules) {
30987
- const backend = getBackendForId(ref.prefixedId);
30988
- const findings = [];
30989
- if (!backend?.readFromOffset) return findings;
30990
- let offset = 0;
30991
- let lineBase = 0;
30992
- for (; ; ) {
30993
- await yieldToEventLoop();
30994
- const chunk = await backend.readFromOffset(ref.prefixedId, offset, SYNC_CHUNK_BYTES);
30995
- if (chunk.newOffset <= offset) break;
30996
- offset = chunk.newOffset;
30997
- if (chunk.skippedBytes) {
30998
- lineBase += 1;
30999
- continue;
31000
- }
31001
- try {
31002
- for (const f of scanTextForFindings(chunk.text)) {
31003
- findings.push({ session_id: ref.prefixedId, detector: "builtin", rule: f.rule, line: lineBase + f.line, preview: f.preview });
31004
- }
31005
- if (tenantRules && tenantRules.length > 0) {
31006
- for (const f of scanTenantRules(chunk.text, tenantRules)) {
31007
- findings.push({ session_id: ref.prefixedId, detector: f.detector, rule: f.rule, line: lineBase + f.line, preview: f.preview });
31008
- }
31009
- }
31010
- } catch {
31011
- }
31012
- for (let i = chunk.text.indexOf("\n"); i >= 0; i = chunk.text.indexOf("\n", i + 1)) lineBase++;
31013
- }
31014
- return dropFuzzyFindings(findings, (f) => ({ detector: f.detector, rule: f.rule }));
31015
- }
31016
31070
  function sessionFileBytes(ref) {
31017
31071
  const backend = getBackendForId(ref.prefixedId);
31018
31072
  if (!backend?.isAppendOnly?.()) return 0;
@@ -31030,6 +31084,42 @@ function sessionBuildBytes(ref) {
31030
31084
  if (main === 0) return 0;
31031
31085
  return Math.max(main, shadowUncompressedBytes(ref.toolId, ref.rawId));
31032
31086
  }
31087
+ async function scanFindingsOffloaded(ref, tenantRules) {
31088
+ const pool = scanPool();
31089
+ if (pool.enabled) {
31090
+ const packVersion = lastServerPackSpec?.version ?? "";
31091
+ const sendPack = lastServerPackSpec !== null && pool.needsPack(packVersion);
31092
+ const result = await pool.runFindings({
31093
+ ref: { prefixedId: ref.prefixedId, rawId: ref.rawId, toolId: ref.toolId },
31094
+ tenantRules,
31095
+ pack: sendPack && lastServerPackSpec ? { version: packVersion, rules: lastServerPackSpec.rules } : void 0,
31096
+ packVersion
31097
+ });
31098
+ if (result) {
31099
+ if (sendPack) pool.markPackSent(packVersion);
31100
+ return result.findings;
31101
+ }
31102
+ }
31103
+ return scanTranscriptFindingsChunked(ref, tenantRules);
31104
+ }
31105
+ async function writeStreamedArchiveOffloaded(ref, count) {
31106
+ const pool = scanPool();
31107
+ if (pool.enabled) {
31108
+ const packVersion = lastServerPackSpec?.version ?? "";
31109
+ const sendPack = lastServerPackSpec !== null && pool.needsPack(packVersion);
31110
+ const result = await pool.runArchive({
31111
+ ref: { prefixedId: ref.prefixedId, rawId: ref.rawId, toolId: ref.toolId, mtime: ref.mtime },
31112
+ pack: sendPack && lastServerPackSpec ? { version: packVersion, rules: lastServerPackSpec.rules } : void 0,
31113
+ packVersion
31114
+ });
31115
+ if (result) {
31116
+ if (sendPack) pool.markPackSent(packVersion);
31117
+ count.redactions += result.redactions;
31118
+ return result.archive;
31119
+ }
31120
+ }
31121
+ return writeStreamedArchive(ref, (t) => redactSecrets(t, { force: true, count }));
31122
+ }
31033
31123
  async function buildConversationSync(ref, mtime, opts = {}) {
31034
31124
  const mapPath = opts.mapPath ?? ((p) => p);
31035
31125
  let includeRaw = opts.includeRaw !== false;
@@ -31058,7 +31148,7 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31058
31148
  } catch {
31059
31149
  }
31060
31150
  includeRaw = false;
31061
- oversizedFindings = await scanTranscriptFindingsChunked(ref, opts.tenantRules);
31151
+ oversizedFindings = await scanFindingsOffloaded(ref, opts.tenantRules);
31062
31152
  } else {
31063
31153
  try {
31064
31154
  const backend = getBackendForId(ref.prefixedId) ?? getBackend("claude");
@@ -31319,17 +31409,13 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31319
31409
  if (wantRaw && !raw_b64) {
31320
31410
  try {
31321
31411
  const redact = (t) => redactSecrets(t, { force: true, count });
31322
- let source = null;
31323
- let archiveMtime = Math.floor(ref.mtime) || 0;
31324
- let archiveTool = ref.toolId;
31325
31412
  if (container) {
31326
- source = { kind: "memory", files: container.files };
31327
- archiveMtime = container.mtime;
31328
- archiveTool = container.tool;
31413
+ const source = { kind: "memory", files: container.files };
31414
+ archive = { file: await writeArchiveFile(source, { tool: container.tool, mtime: container.mtime }, redact), tool: container.tool, mtime: container.mtime };
31329
31415
  } else if (oversized || exportOverCeiling) {
31330
- source = streamedArchiveSource(ref);
31416
+ const file = await writeStreamedArchiveOffloaded(ref, count);
31417
+ if (file) archive = { file, tool: ref.toolId, mtime: Math.floor(ref.mtime) || 0 };
31331
31418
  }
31332
- if (source) archive = { file: await writeArchiveFile(source, { tool: archiveTool, mtime: archiveMtime }, redact), tool: archiveTool, mtime: archiveMtime };
31333
31419
  } catch (err) {
31334
31420
  console.error(`[sync] raw archive for ${ref.prefixedId} not written: ${err instanceof Error ? err.message : err}`);
31335
31421
  }
@@ -31369,22 +31455,6 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31369
31455
  archive
31370
31456
  };
31371
31457
  }
31372
- function streamedArchiveSource(ref) {
31373
- const disk = diskArchiveSource(ref);
31374
- if (disk) return disk;
31375
- const backend = getBackendForId(ref.prefixedId);
31376
- if (ref.toolId === "claude" || !backend?.iterateRawSessionLines) return null;
31377
- return { kind: "lines", files: [{ name: `${ref.rawId}.dump.jsonl`, lines: () => backend.iterateRawSessionLines(ref.prefixedId) }] };
31378
- }
31379
- function diskArchiveSource(ref) {
31380
- if (ref.toolId !== "claude") return null;
31381
- const groups = resolveSessionContentGroups(ref.rawId);
31382
- if (groups.length === 0 || groups.some((g) => g.paths.length !== 1)) return null;
31383
- return {
31384
- kind: "disk",
31385
- files: groups.map((g) => ({ name: g.name === "main" ? `${ref.rawId}.jsonl` : g.name, path: g.paths[0] }))
31386
- };
31387
- }
31388
31458
  function parseTailMessages(tool, text, backend = null) {
31389
31459
  if (!text || !text.trim()) return [];
31390
31460
  if (tool === "claude") return parseClaudeTranscriptText(text);
@@ -31502,7 +31572,7 @@ async function syncIncremental(opts = {}) {
31502
31572
  lock.release();
31503
31573
  }
31504
31574
  }
31505
- var ownVersion, ERROR_CLASS, STANDING_FAILURE, walkProgressForUpload, lastServerPackSpec, credPath, _securityConfigCache, SECURITY_CONFIG_TTL_MS, _syncConfigCache, EMPTY_SYNC_CONFIG, 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;
31575
+ var ownVersion, ERROR_CLASS, STANDING_FAILURE, walkProgressForUpload, lastServerPackSpec, credPath, _securityConfigCache, SECURITY_CONFIG_TTL_MS, _syncConfigCache, EMPTY_SYNC_CONFIG, 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;
31506
31576
  var init_sync_client = __esm({
31507
31577
  "src/sync-client.ts"() {
31508
31578
  "use strict";
@@ -31551,6 +31621,7 @@ var init_sync_client = __esm({
31551
31621
  init_session_file_scan();
31552
31622
  init_raw_archive_parts();
31553
31623
  init_yield_loop();
31624
+ init_heavy_session_work();
31554
31625
  init_backends();
31555
31626
  ownVersion = "0.0.0";
31556
31627
  try {
@@ -31587,7 +31658,6 @@ var init_sync_client = __esm({
31587
31658
  advertisedGzipBody = /* @__PURE__ */ new Set();
31588
31659
  FULL_BUILD_MAX_BYTES = Math.max(8, parseInt(process.env.CHAT_RECALL_FULL_BUILD_MAX_MB || "12", 10)) * 1024 * 1024;
31589
31660
  DERIVED_MAX_BYTES = Math.max(8, parseInt(process.env.CHAT_RECALL_DERIVED_MAX_MB || "64", 10)) * 1024 * 1024;
31590
- SYNC_CHUNK_BYTES = 8 * 1024 * 1024;
31591
31661
  TOOLKIT_INVENTORY_TYPES = /* @__PURE__ */ new Set(["skill", "mcp", "command", "agent", "plugin"]);
31592
31662
  BATCH_SCAN_MAX_BYTES = Math.max(1, parseInt(process.env.CHAT_RECALL_BATCHSCAN_MAX_MB || "64", 10)) * 1024 * 1024;
31593
31663
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chat-recall",
3
- "version": "0.7.81",
3
+ "version": "0.7.82",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/munhq/chat-recall.git"