chat-recall 0.7.58 → 0.7.60

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
@@ -9154,6 +9154,42 @@ var init_session = __esm({
9154
9154
  }
9155
9155
  });
9156
9156
 
9157
+ // ../engine/dist/transcript/trim.js
9158
+ function detach(s) {
9159
+ return JSON.parse(JSON.stringify(s));
9160
+ }
9161
+ function capPayload(v, capChars = SYNC_PAYLOAD_CAP) {
9162
+ if (v === void 0)
9163
+ return void 0;
9164
+ if (typeof v === "string") {
9165
+ return v.length > capChars ? detach(v.slice(0, capChars)) + `\u2026 [+${v.length - capChars} chars]` : v;
9166
+ }
9167
+ let s = "";
9168
+ try {
9169
+ s = JSON.stringify(v) ?? "";
9170
+ } catch {
9171
+ return void 0;
9172
+ }
9173
+ if (s.length <= capChars * 4)
9174
+ return v;
9175
+ if (Array.isArray(v))
9176
+ return detach(s.slice(0, capChars)) + `\u2026 [+${s.length - capChars} chars]`;
9177
+ if (v && typeof v === "object") {
9178
+ const o = {};
9179
+ for (const [k, val] of Object.entries(v))
9180
+ o[k] = capPayload(val, capChars);
9181
+ return o;
9182
+ }
9183
+ return v;
9184
+ }
9185
+ var SYNC_PAYLOAD_CAP;
9186
+ var init_trim = __esm({
9187
+ "../engine/dist/transcript/trim.js"() {
9188
+ "use strict";
9189
+ SYNC_PAYLOAD_CAP = 2e3;
9190
+ }
9191
+ });
9192
+
9157
9193
  // ../engine/dist/transcript/claude.js
9158
9194
  import { open, readdir, readFile, stat } from "fs/promises";
9159
9195
  import { dirname as dirname8, join as join12, basename as basename7 } from "path";
@@ -9163,127 +9199,50 @@ function stripBanners2(text) {
9163
9199
  out = out.replace(re, " ");
9164
9200
  return out.replace(/[ \t]{2,}/g, " ").trim();
9165
9201
  }
9166
- async function parseClaudeTranscript(sessionPath) {
9167
- return parseMessagesFromFile(sessionPath);
9202
+ async function parseClaudeTranscript(sessionPath, opts = {}) {
9203
+ return parseMessagesFromFile(sessionPath, opts);
9168
9204
  }
9169
- function parseClaudeTranscriptText(text) {
9170
- const raw = [];
9205
+ function parseClaudeTranscriptText(text, opts = {}) {
9206
+ const builder = new MessageBuilder(opts.payloadCap);
9171
9207
  let lineNumber = 0;
9172
9208
  for (const line of text.split("\n")) {
9173
9209
  lineNumber++;
9174
9210
  if (!line.trim())
9175
9211
  continue;
9212
+ let obj2;
9176
9213
  try {
9177
- raw.push({ line: lineNumber, obj: JSON.parse(line) });
9214
+ obj2 = JSON.parse(line);
9178
9215
  } catch {
9216
+ continue;
9179
9217
  }
9218
+ builder.add(lineNumber, obj2);
9180
9219
  }
9181
- return messagesFromRawLines(raw);
9220
+ return builder.messages;
9182
9221
  }
9183
- async function parseMessagesFromFile(sessionPath) {
9222
+ async function parseMessagesFromFile(sessionPath, opts) {
9184
9223
  const file = await open(sessionPath);
9185
- const raw = [];
9224
+ const builder = new MessageBuilder(opts.payloadCap);
9186
9225
  try {
9187
9226
  let lineNumber = 0;
9188
9227
  for await (const line of file.readLines()) {
9189
9228
  lineNumber++;
9190
9229
  if (!line.trim())
9191
9230
  continue;
9231
+ let obj2;
9192
9232
  try {
9193
- raw.push({ line: lineNumber, obj: JSON.parse(line) });
9233
+ obj2 = JSON.parse(line);
9194
9234
  } catch {
9195
9235
  log2.debug({ line: lineNumber, file: sessionPath }, "skipped malformed transcript line");
9236
+ continue;
9196
9237
  }
9238
+ builder.add(lineNumber, obj2);
9197
9239
  }
9198
9240
  } finally {
9199
9241
  await file.close();
9200
9242
  }
9201
- return messagesFromRawLines(raw);
9243
+ return builder.messages;
9202
9244
  }
9203
- function messagesFromRawLines(raw) {
9204
- const toolResults = /* @__PURE__ */ new Map();
9205
- for (const { obj: obj2 } of raw) {
9206
- if (obj2?.type !== "user")
9207
- continue;
9208
- const content = obj2.message?.content;
9209
- if (!Array.isArray(content))
9210
- continue;
9211
- for (const block of content) {
9212
- if (block?.type === "tool_result" && block.tool_use_id) {
9213
- toolResults.set(block.tool_use_id, {
9214
- content: block.content,
9215
- isError: block.is_error === true
9216
- });
9217
- }
9218
- }
9219
- }
9220
- const messages = [];
9221
- for (const { line, obj: obj2 } of raw) {
9222
- if (!obj2 || typeof obj2 !== "object")
9223
- continue;
9224
- const timestamp = typeof obj2.timestamp === "string" ? obj2.timestamp : void 0;
9225
- if (obj2.type === "user") {
9226
- const content = obj2.message?.content;
9227
- let text = "";
9228
- if (typeof content === "string") {
9229
- text = content;
9230
- } else if (Array.isArray(content)) {
9231
- text = content.filter((c) => c?.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
9232
- }
9233
- if (!text.trim())
9234
- continue;
9235
- const cleaned = stripBanners2(text);
9236
- if (!cleaned)
9237
- continue;
9238
- const origin = userRecordOrigin(obj2, cleaned);
9239
- messages.push({ line, role: "user", content: cleaned, timestamp, ...origin === "human" ? {} : { origin } });
9240
- } else if (obj2.type === "attachment") {
9241
- const queued = queuedCommandPrompt(obj2);
9242
- if (!queued)
9243
- continue;
9244
- const cleaned = stripBanners2(queued.text);
9245
- if (!cleaned)
9246
- continue;
9247
- messages.push({ line, role: "user", content: cleaned, timestamp, ...queued.origin === "human" ? {} : { origin: queued.origin } });
9248
- } else if (obj2.type === "assistant") {
9249
- const blocks = Array.isArray(obj2.message?.content) ? obj2.message.content : [];
9250
- const thinkingBlock = blocks.find((c) => c?.type === "thinking");
9251
- const textBlock = blocks.find((c) => c?.type === "text");
9252
- const toolUses = blocks.filter((c) => c?.type === "tool_use");
9253
- const toolCalls = toolUses.map((toolUse) => {
9254
- const result = toolUse.id ? toolResults.get(toolUse.id) : void 0;
9255
- return {
9256
- name: toolUse.name || "unknown",
9257
- input: toolUse.input,
9258
- result: result?.content,
9259
- isError: result?.isError
9260
- };
9261
- });
9262
- const hasThinking = thinkingBlock !== void 0;
9263
- const text = textBlock?.text ?? "";
9264
- const thinking = thinkingBlock?.thinking ?? (hasThinking ? "" : void 0);
9265
- if (!text && !hasThinking && toolCalls.length === 0)
9266
- continue;
9267
- messages.push({
9268
- line,
9269
- role: "assistant",
9270
- content: text,
9271
- thinking,
9272
- toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
9273
- timestamp
9274
- });
9275
- } else if (obj2.type === "summary" && typeof obj2.summary === "string") {
9276
- messages.push({ line, role: "summary", content: obj2.summary });
9277
- } else if (obj2.type === "system" && obj2.subtype === "away_summary") {
9278
- const c = obj2.content;
9279
- const text = typeof c === "string" ? c : Array.isArray(c) ? c.filter((b) => b?.type === "text" && typeof b.text === "string").map((b) => b.text).join("\n") : "";
9280
- if (text.trim())
9281
- messages.push({ line, role: "summary", content: stripBanners2(text), timestamp });
9282
- }
9283
- }
9284
- return messages;
9285
- }
9286
- async function parseClaudeSubagents(sessionPath) {
9245
+ async function parseClaudeSubagents(sessionPath, opts = {}) {
9287
9246
  const sessionId = basename7(sessionPath).replace(/\.jsonl$/i, "");
9288
9247
  const subagentsDir = join12(dirname8(sessionPath), sessionId, "subagents");
9289
9248
  let entries;
@@ -9310,7 +9269,7 @@ async function parseClaudeSubagents(sessionPath) {
9310
9269
  }
9311
9270
  let messages = [];
9312
9271
  try {
9313
- messages = await parseMessagesFromFile(filePath);
9272
+ messages = await parseMessagesFromFile(filePath, opts);
9314
9273
  } catch (e) {
9315
9274
  log2.error({ err: e, filePath }, "Failed to parse subagent");
9316
9275
  }
@@ -9335,12 +9294,13 @@ async function parseClaudeSubagents(sessionPath) {
9335
9294
  }));
9336
9295
  return subagents.map((s, i) => ({ s, mtime: stats[i] })).sort((a, b) => a.mtime - b.mtime).map(({ s }) => s);
9337
9296
  }
9338
- var log2, INJECTED_BANNERS2;
9297
+ var log2, INJECTED_BANNERS2, MessageBuilder;
9339
9298
  var init_claude2 = __esm({
9340
9299
  "../engine/dist/transcript/claude.js"() {
9341
9300
  "use strict";
9342
9301
  init_logger();
9343
9302
  init_claude_prompt_origin();
9303
+ init_trim();
9344
9304
  log2 = createLogger("transcript-claude");
9345
9305
  INJECTED_BANNERS2 = [
9346
9306
  /MCP issues detected\. ?Run \/mcp list for status\.?/g,
@@ -9359,6 +9319,104 @@ var init_claude2 = __esm({
9359
9319
  // eslint-disable-next-line no-control-regex
9360
9320
  /\[[0-9;]*m/g
9361
9321
  ];
9322
+ MessageBuilder = class {
9323
+ messages = [];
9324
+ cap;
9325
+ /** The calls of each tool_use id. */
9326
+ calls = /* @__PURE__ */ new Map();
9327
+ /** The last result of each tool_use id. */
9328
+ results = /* @__PURE__ */ new Map();
9329
+ constructor(payloadCap) {
9330
+ this.cap = payloadCap ? (v) => capPayload(v, payloadCap) : (v) => v;
9331
+ }
9332
+ add(line, obj2) {
9333
+ if (!obj2 || typeof obj2 !== "object")
9334
+ return;
9335
+ const timestamp = typeof obj2.timestamp === "string" ? obj2.timestamp : void 0;
9336
+ if (obj2.type === "user") {
9337
+ const content = obj2.message?.content;
9338
+ if (Array.isArray(content)) {
9339
+ for (const block of content) {
9340
+ if (block?.type === "tool_result" && block.tool_use_id) {
9341
+ this.addResult(block.tool_use_id, this.cap(block.content), block.is_error === true);
9342
+ }
9343
+ }
9344
+ }
9345
+ let text = "";
9346
+ if (typeof content === "string") {
9347
+ text = content;
9348
+ } else if (Array.isArray(content)) {
9349
+ text = content.filter((c) => c?.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
9350
+ }
9351
+ if (!text.trim())
9352
+ return;
9353
+ const cleaned = stripBanners2(text);
9354
+ if (!cleaned)
9355
+ return;
9356
+ const origin = userRecordOrigin(obj2, cleaned);
9357
+ this.messages.push({ line, role: "user", content: cleaned, timestamp, ...origin === "human" ? {} : { origin } });
9358
+ } else if (obj2.type === "attachment") {
9359
+ const queued = queuedCommandPrompt(obj2);
9360
+ if (!queued)
9361
+ return;
9362
+ const cleaned = stripBanners2(queued.text);
9363
+ if (!cleaned)
9364
+ return;
9365
+ this.messages.push({ line, role: "user", content: cleaned, timestamp, ...queued.origin === "human" ? {} : { origin: queued.origin } });
9366
+ } else if (obj2.type === "assistant") {
9367
+ const blocks = Array.isArray(obj2.message?.content) ? obj2.message.content : [];
9368
+ const thinkingBlock = blocks.find((c) => c?.type === "thinking");
9369
+ const textBlock = blocks.find((c) => c?.type === "text");
9370
+ const toolUses = blocks.filter((c) => c?.type === "tool_use");
9371
+ const toolCalls = toolUses.map((toolUse) => {
9372
+ const known = toolUse.id ? this.results.get(toolUse.id) : void 0;
9373
+ const call2 = {
9374
+ name: toolUse.name || "unknown",
9375
+ input: this.cap(toolUse.input),
9376
+ result: known?.content,
9377
+ isError: known?.isError
9378
+ };
9379
+ if (toolUse.id) {
9380
+ const list = this.calls.get(toolUse.id);
9381
+ if (list)
9382
+ list.push(call2);
9383
+ else
9384
+ this.calls.set(toolUse.id, [call2]);
9385
+ }
9386
+ return call2;
9387
+ });
9388
+ const hasThinking = thinkingBlock !== void 0;
9389
+ const text = textBlock?.text ?? "";
9390
+ const thinking = thinkingBlock?.thinking != null ? this.cap(thinkingBlock.thinking) : hasThinking ? "" : void 0;
9391
+ if (!text && !hasThinking && toolCalls.length === 0)
9392
+ return;
9393
+ this.messages.push({
9394
+ line,
9395
+ role: "assistant",
9396
+ content: text,
9397
+ thinking,
9398
+ toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
9399
+ timestamp
9400
+ });
9401
+ } else if (obj2.type === "summary" && typeof obj2.summary === "string") {
9402
+ this.messages.push({ line, role: "summary", content: obj2.summary });
9403
+ } else if (obj2.type === "system" && obj2.subtype === "away_summary") {
9404
+ const c = obj2.content;
9405
+ const text = typeof c === "string" ? c : Array.isArray(c) ? c.filter((b) => b?.type === "text" && typeof b.text === "string").map((b) => b.text).join("\n") : "";
9406
+ if (text.trim())
9407
+ this.messages.push({ line, role: "summary", content: stripBanners2(text), timestamp });
9408
+ }
9409
+ }
9410
+ addResult(id, content, isError) {
9411
+ this.results.set(id, { content, isError });
9412
+ const list = this.calls.get(id);
9413
+ if (list)
9414
+ for (const call2 of list) {
9415
+ call2.result = content;
9416
+ call2.isError = isError;
9417
+ }
9418
+ }
9419
+ };
9362
9420
  }
9363
9421
  });
9364
9422
 
@@ -17009,10 +17067,12 @@ var init_opencode2 = __esm({
17009
17067
  var transcript_exports = {};
17010
17068
  __export(transcript_exports, {
17011
17069
  RAW_PARSE_MAX_BYTES: () => RAW_PARSE_MAX_BYTES,
17070
+ SYNC_PAYLOAD_CAP: () => SYNC_PAYLOAD_CAP,
17012
17071
  TRANSCRIPT_VERSION: () => TRANSCRIPT_VERSION,
17013
17072
  archiveRawSession: () => archiveRawSession,
17014
17073
  buildRawContainer: () => buildRawContainer,
17015
17074
  canonicalEventsToMessages: () => canonicalEventsToMessages,
17075
+ capPayload: () => capPayload,
17016
17076
  containerSrcHash: () => containerSrcHash,
17017
17077
  detectForkPredecessor: () => detectForkPredecessor,
17018
17078
  gunzipContainer: () => gunzipContainer,
@@ -17047,7 +17107,14 @@ __export(transcript_exports, {
17047
17107
  writeTranscriptEnvelope: () => writeTranscriptEnvelope
17048
17108
  });
17049
17109
  import { statSync as statSync21 } from "fs";
17050
- async function parseTranscript(sessionId) {
17110
+ async function parseTranscript(sessionId, opts = {}) {
17111
+ const t = await parseTranscriptUncut(sessionId, opts);
17112
+ const cap = opts.payloadCap;
17113
+ if (!t || !cap || t.payloadCap === cap)
17114
+ return t;
17115
+ return { ...t, ...trimTranscriptForSync(t, cap), payloadCap: cap };
17116
+ }
17117
+ async function parseTranscriptUncut(sessionId, opts) {
17051
17118
  const tool = detectTool(sessionId);
17052
17119
  if (tool === "claude") {
17053
17120
  const groups = resolveSessionContentGroups(sessionId);
@@ -17058,9 +17125,10 @@ async function parseTranscript(sessionId) {
17058
17125
  return null;
17059
17126
  const primaryPath = mainGroup.paths[0];
17060
17127
  const merged = readSessionGroupText(mainGroup);
17128
+ const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
17061
17129
  const [tail, allSubagents] = await Promise.all([
17062
- Promise.resolve(parseClaudeTranscriptText(merged.text)),
17063
- parseClaudeSubagents(primaryPath)
17130
+ Promise.resolve(parseClaudeTranscriptText(merged.text, cut)),
17131
+ parseClaudeSubagents(primaryPath, cut)
17064
17132
  ]);
17065
17133
  const compacts = allSubagents.filter((s) => s.kind === "compact");
17066
17134
  const subagents = allSubagents.filter((s) => s.kind !== "compact");
@@ -17077,7 +17145,7 @@ async function parseTranscript(sessionId) {
17077
17145
  }
17078
17146
  messages = [...stitched, ...tail].map((m, i) => ({ ...m, line: i + 1 }));
17079
17147
  }
17080
- return { messages, subagents, mtime: merged.mtime || safeMtime(primaryPath) };
17148
+ return { messages, subagents, mtime: merged.mtime || safeMtime(primaryPath), ...opts.payloadCap ? { payloadCap: opts.payloadCap } : {} };
17081
17149
  }
17082
17150
  if (tool === "opencode") {
17083
17151
  const messages = await parseOpenCodeTranscript(sessionId);
@@ -17119,31 +17187,8 @@ function safeMtime(path) {
17119
17187
  return 0;
17120
17188
  }
17121
17189
  }
17122
- function trimTranscriptForSync(t, capChars = 2e3) {
17123
- const cap = (v) => {
17124
- if (v === void 0)
17125
- return void 0;
17126
- if (typeof v === "string") {
17127
- return v.length > capChars ? v.slice(0, capChars) + `\u2026 [+${v.length - capChars} chars]` : v;
17128
- }
17129
- let s = "";
17130
- try {
17131
- s = JSON.stringify(v) ?? "";
17132
- } catch {
17133
- return void 0;
17134
- }
17135
- if (s.length <= capChars * 4)
17136
- return v;
17137
- if (Array.isArray(v))
17138
- return s.slice(0, capChars) + `\u2026 [+${s.length - capChars} chars]`;
17139
- if (v && typeof v === "object") {
17140
- const o = {};
17141
- for (const [k, val] of Object.entries(v))
17142
- o[k] = cap(val);
17143
- return o;
17144
- }
17145
- return v;
17146
- };
17190
+ function trimTranscriptForSync(t, capChars = SYNC_PAYLOAD_CAP) {
17191
+ const cap = (v) => capPayload(v, capChars);
17147
17192
  const trimMsg = (m) => ({
17148
17193
  ...m,
17149
17194
  thinking: m.thinking !== void 0 ? cap(m.thinking) : void 0,
@@ -17175,7 +17220,9 @@ var init_transcript = __esm({
17175
17220
  init_opencode2();
17176
17221
  init_codex();
17177
17222
  init_from_events();
17223
+ init_trim();
17178
17224
  init_types();
17225
+ init_trim();
17179
17226
  init_raw();
17180
17227
  init_shadow();
17181
17228
  init_claude2();
@@ -29429,8 +29476,100 @@ var init_collector_health = __esm({
29429
29476
  }
29430
29477
  });
29431
29478
 
29479
+ // src/session-file-scan.ts
29480
+ import { open as open3 } from "node:fs/promises";
29481
+ import { statSync as statSync39 } from "node:fs";
29482
+ function sessionGroupsBytes(groups) {
29483
+ let total = 0;
29484
+ for (const g of groups) {
29485
+ for (const p of g.paths) {
29486
+ try {
29487
+ total += statSync39(p).size;
29488
+ } catch {
29489
+ }
29490
+ }
29491
+ }
29492
+ return total;
29493
+ }
29494
+ async function* readLinePieces(path, pieceBytes = SCAN_PIECE_BYTES) {
29495
+ const fh = await open3(path, "r");
29496
+ try {
29497
+ const buf = Buffer.allocUnsafe(pieceBytes);
29498
+ let carry = Buffer.alloc(0);
29499
+ for (; ; ) {
29500
+ const { bytesRead } = await fh.read(buf, 0, pieceBytes, null);
29501
+ if (bytesRead === 0) break;
29502
+ const joined = carry.length ? Buffer.concat([carry, buf.subarray(0, bytesRead)]) : buf.subarray(0, bytesRead);
29503
+ const cut = joined.lastIndexOf(NEWLINE);
29504
+ if (cut < 0) {
29505
+ carry = Buffer.from(joined);
29506
+ continue;
29507
+ }
29508
+ const piece = joined.subarray(0, cut + 1);
29509
+ carry = Buffer.from(joined.subarray(cut + 1));
29510
+ yield { text: piece.toString("utf8"), newlines: countNewlines(piece) };
29511
+ }
29512
+ if (carry.length) yield { text: carry.toString("utf8"), newlines: 0 };
29513
+ } finally {
29514
+ await fh.close();
29515
+ }
29516
+ }
29517
+ function countNewlines(b) {
29518
+ let n = 0;
29519
+ for (let i = b.indexOf(NEWLINE); i >= 0; i = b.indexOf(NEWLINE, i + 1)) n++;
29520
+ return n;
29521
+ }
29522
+ async function scanSessionGroupsChunked(sessionId, groups, tenantRules, pieceBytes = SCAN_PIECE_BYTES) {
29523
+ const findings = [];
29524
+ let lineBase = 0;
29525
+ const scan = (text) => {
29526
+ try {
29527
+ for (const x of scanTextForFindings(text)) {
29528
+ findings.push({ session_id: sessionId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
29529
+ }
29530
+ } catch {
29531
+ }
29532
+ if (tenantRules && tenantRules.length > 0) {
29533
+ try {
29534
+ for (const x of scanTenantRules(text, tenantRules)) {
29535
+ findings.push({ session_id: sessionId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
29536
+ }
29537
+ } catch {
29538
+ }
29539
+ }
29540
+ };
29541
+ for (const group of groups) {
29542
+ if (group.paths.length === 1) {
29543
+ let any = false;
29544
+ for await (const piece of readLinePieces(group.paths[0], pieceBytes)) {
29545
+ any = true;
29546
+ scan(piece.text);
29547
+ lineBase += piece.newlines;
29548
+ }
29549
+ if (any) lineBase += 1;
29550
+ } else {
29551
+ const { text } = readSessionGroupText(group);
29552
+ if (!text) continue;
29553
+ scan(text);
29554
+ lineBase += (text.match(/\n/g)?.length ?? 0) + 1;
29555
+ }
29556
+ }
29557
+ return findings;
29558
+ }
29559
+ var SCAN_PIECE_BYTES, NEWLINE;
29560
+ var init_session_file_scan = __esm({
29561
+ "src/session-file-scan.ts"() {
29562
+ "use strict";
29563
+ init_secret_redactor();
29564
+ init_secret_scanner();
29565
+ init_live_session_scan();
29566
+ SCAN_PIECE_BYTES = 8 * 1024 * 1024;
29567
+ NEWLINE = 10;
29568
+ }
29569
+ });
29570
+
29432
29571
  // src/raw-archive-parts.ts
29433
- import { createReadStream as createReadStream4, createWriteStream, openSync as openSync10, readSync as readSync9, closeSync as closeSync10, rmSync as rmSync5, statSync as statSync39 } from "node:fs";
29572
+ import { createReadStream as createReadStream4, createWriteStream, openSync as openSync10, readSync as readSync9, closeSync as closeSync10, rmSync as rmSync5, statSync as statSync40 } from "node:fs";
29434
29573
  import { tmpdir as tmpdir2 } from "node:os";
29435
29574
  import { join as join46 } from "node:path";
29436
29575
  import { randomBytes } from "node:crypto";
@@ -29498,7 +29637,7 @@ async function writeArchiveFile(source, meta, redact, dir = tmpdir2()) {
29498
29637
  rmSync5(path, { force: true });
29499
29638
  throw err;
29500
29639
  }
29501
- return { path, gzSize: statSync39(path).size, size };
29640
+ return { path, gzSize: statSync40(path).size, size };
29502
29641
  }
29503
29642
  async function putPart(url, body2) {
29504
29643
  let last;
@@ -29801,7 +29940,7 @@ __export(auto_update_exports, {
29801
29940
  import { execSync as execSync2, execFileSync as execFileSync3 } from "node:child_process";
29802
29941
  import { readFileSync as readFileSync41, existsSync as existsSync43 } from "node:fs";
29803
29942
  import { fileURLToPath as fileURLToPath2 } from "node:url";
29804
- import { writeFileSync as writeFileSync10, mkdtempSync as mkdtempSync3, rmSync as rmSync6, readdirSync as readdirSync31, statSync as statSync40, mkdirSync as mkdirSync10 } from "node:fs";
29943
+ import { writeFileSync as writeFileSync10, mkdtempSync as mkdtempSync3, rmSync as rmSync6, readdirSync as readdirSync31, statSync as statSync41, mkdirSync as mkdirSync10 } from "node:fs";
29805
29944
  import { join as join47, dirname as dirname19, sep as sep2, posix as pathPosix, win32 as pathWin32 } from "node:path";
29806
29945
  import { tmpdir as tmpdir3, homedir as homedir16 } from "node:os";
29807
29946
  import { createHash as createHash10 } from "node:crypto";
@@ -29854,7 +29993,7 @@ function sweepStaleStaging(root = tmpdir3(), now = Date.now()) {
29854
29993
  if (!MKDTEMP_SUFFIX.test(name)) continue;
29855
29994
  const dir = join47(root, name);
29856
29995
  try {
29857
- const st = statSync40(dir);
29996
+ const st = statSync41(dir);
29858
29997
  if (!st.isDirectory() || now - st.mtimeMs < COLD_MS) continue;
29859
29998
  const inside = readdirSync31(dir);
29860
29999
  if (inside.length > 1 || inside.length === 1 && inside[0] !== "chat-recall.tgz") continue;
@@ -30138,7 +30277,7 @@ __export(sync_client_exports, {
30138
30277
  syncSessions: () => syncSessions
30139
30278
  });
30140
30279
  import { join as join48, dirname as dirname20, basename as basename22 } from "node:path";
30141
- import { readFileSync as readFileSync42, writeFileSync as writeFileSync11, mkdirSync as mkdirSync11, mkdtempSync as mkdtempSync4, rmSync as rmSync7, chmodSync as chmodSync4, unlinkSync as unlinkSync2, readdirSync as readdirSync32, statSync as statSync41 } from "node:fs";
30280
+ import { readFileSync as readFileSync42, writeFileSync as writeFileSync11, mkdirSync as mkdirSync11, mkdtempSync as mkdtempSync4, rmSync as rmSync7, chmodSync as chmodSync4, unlinkSync as unlinkSync2, readdirSync as readdirSync32, statSync as statSync42 } from "node:fs";
30142
30281
  import { tmpdir as tmpdir4, hostname as hostname2 } from "node:os";
30143
30282
  import { createHash as createHash11 } from "node:crypto";
30144
30283
  import { fileURLToPath as fileURLToPath3 } from "node:url";
@@ -30615,7 +30754,7 @@ function reapStaleScanDirs(dir = tmpdir4(), maxAgeMs = 6 * 36e5, now = Date.now(
30615
30754
  if (!name.startsWith("cr-batchscan-")) continue;
30616
30755
  const p = join48(dir, name);
30617
30756
  try {
30618
- if (now - statSync41(p).mtimeMs < maxAgeMs) continue;
30757
+ if (now - statSync42(p).mtimeMs < maxAgeMs) continue;
30619
30758
  rmSync7(p, { recursive: true, force: true });
30620
30759
  reaped++;
30621
30760
  } catch {
@@ -31519,6 +31658,10 @@ function sessionFileBytes(ref) {
31519
31658
  if (!backend?.isAppendOnly?.()) return 0;
31520
31659
  return backend.fileSize?.(ref.prefixedId) ?? 0;
31521
31660
  }
31661
+ function syncTranscript(t) {
31662
+ const cut = t.payloadCap ? { messages: t.messages, subagents: t.subagents } : trimTranscriptForSync(t);
31663
+ return { messages: cut.messages, subagents: cut.subagents.map((s) => ({ ...s, filePath: "" })) };
31664
+ }
31522
31665
  function sessionBuildBytes(ref) {
31523
31666
  const main = sessionFileBytes(ref);
31524
31667
  if (main === 0) return 0;
@@ -31533,6 +31676,8 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31533
31676
  const oversized = sessionBuildBytes(ref) > FULL_BUILD_MAX_BYTES;
31534
31677
  let headOffsetEnd = 0;
31535
31678
  let oversizedFindings = null;
31679
+ let exportOverCeiling = false;
31680
+ let overCeilingFindings = null;
31536
31681
  let transcript = null;
31537
31682
  let fullestContainer = null;
31538
31683
  if (oversized) {
@@ -31553,11 +31698,14 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31553
31698
  } else {
31554
31699
  try {
31555
31700
  const backend = getBackendForId(ref.prefixedId) ?? getBackend("claude");
31556
- const exp = backend.exportRawSession(ref.prefixedId);
31701
+ const streamGroups = ref.toolId === "claude" ? resolveSessionContentGroups(ref.rawId) : [];
31702
+ const streamedBytes = sessionGroupsBytes(streamGroups);
31703
+ const streamed = streamedBytes > FULL_BUILD_MAX_BYTES;
31704
+ const exp = streamed ? null : backend.exportRawSession(ref.prefixedId);
31557
31705
  let built;
31558
- const exportBytes = exportByteLength(exp);
31706
+ const exportBytes = streamed ? streamedBytes : exportByteLength(exp);
31559
31707
  const overCeiling = exportBytes > FULL_BUILD_MAX_BYTES;
31560
- if (exp && overCeiling) {
31708
+ if ((exp || streamed) && overCeiling) {
31561
31709
  console.error(`[sync] ${ref.prefixedId} export is ${(exportBytes / 1048576).toFixed(0)}MB (over the ${(FULL_BUILD_MAX_BYTES / 1048576).toFixed(0)}MB ceiling) \u2014 parsing it in place, no container copy, no shadow merge, no raw archive`);
31562
31710
  record({
31563
31711
  kind: "oversized_session",
@@ -31567,6 +31715,31 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31567
31715
  });
31568
31716
  includeRaw = false;
31569
31717
  includeMeta = false;
31718
+ exportOverCeiling = true;
31719
+ if (streamed) {
31720
+ overCeilingFindings = await scanSessionGroupsChunked(ref.prefixedId, streamGroups, opts.tenantRules);
31721
+ } else if (exp) {
31722
+ overCeilingFindings = [];
31723
+ let lineBase = 0;
31724
+ for (const f of exp.files) {
31725
+ const text = f.bytes.toString("utf8");
31726
+ try {
31727
+ for (const x of scanTextForFindings(text)) {
31728
+ overCeilingFindings.push({ session_id: ref.prefixedId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
31729
+ }
31730
+ } catch {
31731
+ }
31732
+ if (opts.tenantRules && opts.tenantRules.length > 0) {
31733
+ try {
31734
+ for (const x of scanTenantRules(text, opts.tenantRules)) {
31735
+ overCeilingFindings.push({ session_id: ref.prefixedId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
31736
+ }
31737
+ } catch {
31738
+ }
31739
+ }
31740
+ lineBase += (text.match(/\n/g)?.length ?? 0) + 1;
31741
+ }
31742
+ }
31570
31743
  }
31571
31744
  if (exp && !overCeiling) {
31572
31745
  try {
@@ -31605,7 +31778,7 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31605
31778
  }
31606
31779
  if (!transcript) {
31607
31780
  try {
31608
- const t = await parseTranscript(ref.prefixedId);
31781
+ const t = await parseTranscript(ref.prefixedId, { payloadCap: SYNC_PAYLOAD_CAP });
31609
31782
  if (t && (t.messages.length > 0 || t.subagents.length > 0)) transcript = t;
31610
31783
  } catch {
31611
31784
  }
@@ -31618,7 +31791,9 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31618
31791
  if (isInternalToolPrompt(firstUser?.content)) return null;
31619
31792
  const count = { redactions: 0 };
31620
31793
  const envelope = redactDeep(
31621
- { v: TRANSCRIPT_VERSION, ...trimTranscriptForSync(transcript) },
31794
+ // A transcript the parser already cut is not cut again: the cut is not idempotent.
31795
+ // The path of a subagent file on this machine does not leave it: the container parse gives ''.
31796
+ { v: TRANSCRIPT_VERSION, ...syncTranscript(transcript) },
31622
31797
  count
31623
31798
  );
31624
31799
  let projectPath = ref.projectPath;
@@ -31660,7 +31835,7 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31660
31835
  }
31661
31836
  }
31662
31837
  let container = fullestContainer;
31663
- if (!container && !oversized) {
31838
+ if (!container && !oversized && !exportOverCeiling) {
31664
31839
  try {
31665
31840
  const backend = getBackendForId(ref.prefixedId) ?? getBackend("claude");
31666
31841
  const exp = backend.exportRawSession(ref.prefixedId);
@@ -31737,6 +31912,7 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31737
31912
  scanMs = performance.now() - t0;
31738
31913
  }
31739
31914
  if (oversizedFindings) findings.push(...oversizedFindings);
31915
+ if (overCeilingFindings) findings.push(...overCeilingFindings);
31740
31916
  const keptFindings = dropFuzzyFindings(findings, (f) => ({ detector: f.detector, rule: f.rule }));
31741
31917
  findings.length = 0;
31742
31918
  findings.push(...keptFindings);
@@ -31989,6 +32165,7 @@ var init_sync_client = __esm({
31989
32165
  init_telemetry();
31990
32166
  init_collector_health();
31991
32167
  init_live_session_scan();
32168
+ init_session_file_scan();
31992
32169
  init_raw_archive_parts();
31993
32170
  init_backends();
31994
32171
  ownVersion = "0.0.0";
@@ -32150,11 +32327,11 @@ var init_update_notice = __esm({
32150
32327
  });
32151
32328
 
32152
32329
  // ../engine/dist/core/which.js
32153
- import { existsSync as existsSync44, statSync as statSync42, accessSync, constants } from "node:fs";
32330
+ import { existsSync as existsSync44, statSync as statSync43, accessSync, constants } from "node:fs";
32154
32331
  import { join as join50, isAbsolute as isAbsolute3, delimiter as delimiter2, sep as sep3 } from "node:path";
32155
32332
  function executable(p) {
32156
32333
  try {
32157
- if (!statSync42(p).isFile())
32334
+ if (!statSync43(p).isFile())
32158
32335
  return false;
32159
32336
  } catch {
32160
32337
  return false;
@@ -33371,14 +33548,14 @@ var init_opencode_tui_config = __esm({
33371
33548
  return this.array(t);
33372
33549
  throw new SyntaxError(`unexpected "${t.v}" at ${t.start}`);
33373
33550
  }
33374
- object(open3) {
33551
+ object(open4) {
33375
33552
  this.i += 1;
33376
33553
  const props = [];
33377
33554
  for (; ; ) {
33378
33555
  const k = this.at();
33379
33556
  if (this.isP(k, "}")) {
33380
33557
  this.i += 1;
33381
- return { k: "obj", start: open3.start, end: k.end, closeStart: k.start, props };
33558
+ return { k: "obj", start: open4.start, end: k.end, closeStart: k.start, props };
33382
33559
  }
33383
33560
  if (!k || k.t !== "s")
33384
33561
  throw new SyntaxError(`expected a key at ${k ? k.start : "end"}`);
@@ -33397,7 +33574,7 @@ var init_opencode_tui_config = __esm({
33397
33574
  throw new SyntaxError(`expected "," or "}" at ${n ? n.start : "end"}`);
33398
33575
  }
33399
33576
  }
33400
- array(open3) {
33577
+ array(open4) {
33401
33578
  this.i += 1;
33402
33579
  const items = [];
33403
33580
  const commas = [];
@@ -33405,7 +33582,7 @@ var init_opencode_tui_config = __esm({
33405
33582
  const n = this.at();
33406
33583
  if (this.isP(n, "]")) {
33407
33584
  this.i += 1;
33408
- return { k: "arr", start: open3.start, end: n.end, closeStart: n.start, items, commas };
33585
+ return { k: "arr", start: open4.start, end: n.end, closeStart: n.start, items, commas };
33409
33586
  }
33410
33587
  items.push(this.value());
33411
33588
  const c = this.at();
@@ -34323,7 +34500,7 @@ __export(companions_exports, {
34323
34500
  uninstallCodeindex: () => uninstallCodeindex,
34324
34501
  unregisterCodeindexMcp: () => unregisterCodeindexMcp
34325
34502
  });
34326
- import { existsSync as existsSync49, mkdirSync as mkdirSync15, statSync as statSync43, chmodSync as chmodSync6, unlinkSync as unlinkSync3, renameSync as renameSync7, createWriteStream as createWriteStream2, readFileSync as readFileSync47, writeFileSync as writeFileSync17 } from "node:fs";
34503
+ import { existsSync as existsSync49, mkdirSync as mkdirSync15, statSync as statSync44, chmodSync as chmodSync6, unlinkSync as unlinkSync3, renameSync as renameSync7, createWriteStream as createWriteStream2, readFileSync as readFileSync47, writeFileSync as writeFileSync17 } from "node:fs";
34327
34504
  import { homedir as homedir21 } from "node:os";
34328
34505
  import { join as join59 } from "node:path";
34329
34506
  import { execSync as execSync3 } from "node:child_process";
@@ -34374,7 +34551,7 @@ function checkCodeindexStatus() {
34374
34551
  status.installed = true;
34375
34552
  status.path = foundPath;
34376
34553
  try {
34377
- status.size = statSync43(foundPath).size;
34554
+ status.size = statSync44(foundPath).size;
34378
34555
  } catch {
34379
34556
  }
34380
34557
  try {
@@ -34524,7 +34701,7 @@ __export(install_skills_exports, {
34524
34701
  skillsSourceDir: () => skillsSourceDir,
34525
34702
  uninstallSkills: () => uninstallSkills
34526
34703
  });
34527
- import { readdirSync as readdirSync33, existsSync as existsSync50, mkdirSync as mkdirSync16, rmSync as rmSync8, cpSync, writeFileSync as writeFileSync18, readFileSync as readFileSync48, statSync as statSync44, realpathSync as realpathSync5 } from "fs";
34704
+ import { readdirSync as readdirSync33, existsSync as existsSync50, mkdirSync as mkdirSync16, rmSync as rmSync8, cpSync, writeFileSync as writeFileSync18, readFileSync as readFileSync48, statSync as statSync45, realpathSync as realpathSync5 } from "fs";
34528
34705
  import { createHash as createHash14 } from "crypto";
34529
34706
  import { join as join60, basename as basename23 } from "path";
34530
34707
  function skillsSourceDir() {
@@ -35539,11 +35716,11 @@ __export(toolkit_pull_exports, {
35539
35716
  platformRefusal: () => platformRefusal,
35540
35717
  portableCommand: () => portableCommand
35541
35718
  });
35542
- import { existsSync as existsSync52, mkdirSync as mkdirSync18, statSync as statSync45, writeFileSync as writeFileSync20 } from "node:fs";
35719
+ import { existsSync as existsSync52, mkdirSync as mkdirSync18, statSync as statSync46, writeFileSync as writeFileSync20 } from "node:fs";
35543
35720
  import { dirname as dirname26, join as join63, basename as basename26, isAbsolute as isAbsolute4 } from "node:path";
35544
35721
  function isExecutableFile(p) {
35545
35722
  try {
35546
- return statSync45(p).isFile();
35723
+ return statSync46(p).isFile();
35547
35724
  } catch {
35548
35725
  return false;
35549
35726
  }
@@ -37952,7 +38129,7 @@ __export(project_tasks_exports, {
37952
38129
  pushProjectTaskStatuses: () => pushProjectTaskStatuses,
37953
38130
  renderTeamTasksMd: () => renderTeamTasksMd
37954
38131
  });
37955
- import { existsSync as existsSync56, readFileSync as readFileSync53, writeFileSync as writeFileSync22, mkdirSync as mkdirSync20, statSync as statSync46 } from "node:fs";
38132
+ import { existsSync as existsSync56, readFileSync as readFileSync53, writeFileSync as writeFileSync22, mkdirSync as mkdirSync20, statSync as statSync47 } from "node:fs";
37956
38133
  import { join as join67, dirname as dirname28 } from "node:path";
37957
38134
  import { homedir as homedir24 } from "node:os";
37958
38135
  function isTeamTaskStatus(v) {
@@ -37965,7 +38142,7 @@ function isValidStatus(kind, v) {
37965
38142
  return kind === "secret" ? isSecretTaskStatus(v) : kind === "team" ? isTeamTaskStatus(v) : isCodeTaskStatus(v);
37966
38143
  }
37967
38144
  function reconcile(kind, was, token, checked) {
37968
- const open3 = defaultWas(kind);
38145
+ const open4 = defaultWas(kind);
37969
38146
  const done = kind === "secret" ? "rotated" : "done";
37970
38147
  if (token && token !== was) return token;
37971
38148
  if (kind === "team") {
@@ -37973,8 +38150,8 @@ function reconcile(kind, was, token, checked) {
37973
38150
  if (!checked && was === "done") return "todo";
37974
38151
  return token ?? was;
37975
38152
  }
37976
- if (checked && was === open3) return done;
37977
- if (!checked && was !== open3) return open3;
38153
+ if (checked && was === open4) return done;
38154
+ if (!checked && was !== open4) return open4;
37978
38155
  return token ?? was;
37979
38156
  }
37980
38157
  function parseAnchorLine(line) {
@@ -38041,7 +38218,7 @@ async function pushProjectTaskStatuses(base4, authHeaders, opts = {}) {
38041
38218
  if (!existsSync56(file)) continue;
38042
38219
  let mtime;
38043
38220
  try {
38044
- mtime = statSync46(file).mtimeMs;
38221
+ mtime = statSync47(file).mtimeMs;
38045
38222
  } catch {
38046
38223
  continue;
38047
38224
  }
@@ -38554,7 +38731,7 @@ var team_merge_exports = {};
38554
38731
  __export(team_merge_exports, {
38555
38732
  mergePullResult: () => mergePullResult
38556
38733
  });
38557
- import { existsSync as existsSync58, mkdirSync as mkdirSync22, readFileSync as readFileSync55, rmSync as rmSync11, writeFileSync as writeFileSync24, statSync as statSync47 } from "fs";
38734
+ import { existsSync as existsSync58, mkdirSync as mkdirSync22, readFileSync as readFileSync55, rmSync as rmSync11, writeFileSync as writeFileSync24, statSync as statSync48 } from "fs";
38558
38735
  import { dirname as dirname30, join as join69 } from "path";
38559
38736
  import { createHash as createHash17 } from "crypto";
38560
38737
  function installPathFor(art, tool) {
@@ -38691,7 +38868,7 @@ function readFileIfExists(path) {
38691
38868
  try {
38692
38869
  if (!existsSync58(path))
38693
38870
  return null;
38694
- const s = statSync47(path);
38871
+ const s = statSync48(path);
38695
38872
  if (!s.isFile())
38696
38873
  return null;
38697
38874
  return readFileSync55(path);
@@ -38775,7 +38952,7 @@ var init_vault_crypto = __esm({
38775
38952
  });
38776
38953
 
38777
38954
  // ../engine/dist/core/vault-source.js
38778
- import { existsSync as existsSync59, readdirSync as readdirSync35, statSync as statSync48 } from "fs";
38955
+ import { existsSync as existsSync59, readdirSync as readdirSync35, statSync as statSync49 } from "fs";
38779
38956
  import { extname, join as join70 } from "path";
38780
38957
  function* walkVaultSources() {
38781
38958
  const t = loadSettings().team.vault;
@@ -38791,7 +38968,7 @@ function* walkVaultSources() {
38791
38968
  }
38792
38969
  function safeStat(path) {
38793
38970
  try {
38794
- const s = statSync48(path);
38971
+ const s = statSync49(path);
38795
38972
  if (!s.isFile())
38796
38973
  return null;
38797
38974
  return { mtimeMs: s.mtimeMs, size: s.size };
@@ -38894,7 +39071,7 @@ function* walkAgy() {
38894
39071
  for (const rawId of sessionDirs) {
38895
39072
  const sessionPath = join70(brainDir, rawId);
38896
39073
  try {
38897
- if (!statSync48(sessionPath).isDirectory())
39074
+ if (!statSync49(sessionPath).isDirectory())
38898
39075
  continue;
38899
39076
  } catch {
38900
39077
  continue;
@@ -41497,7 +41674,7 @@ program.command("feedback").argument("<message...>", "what you want to say \u201
41497
41674
  }
41498
41675
  });
41499
41676
  program.command("doctor").description("Quick health check across login, server, credentials, hooks, MCP server, and codeindex").option("--purge-local", "Remove the legacy local index (cache.db + vector/KG files) left by pre-thin-collector versions \u2014 storage is server-side now. Requires login; keeps credentials, sync ledger, identity, and the audit log.").action(async (opts) => {
41500
- const { existsSync: existsSync63, readFileSync: readFileSync60, statSync: statSync49 } = await import("fs");
41677
+ const { existsSync: existsSync63, readFileSync: readFileSync60, statSync: statSync50 } = await import("fs");
41501
41678
  const { execSync: execSync6 } = await import("child_process");
41502
41679
  const rows = [];
41503
41680
  const note = (ok, label, detail) => rows.push({ ok, label, detail });
@@ -41565,7 +41742,7 @@ program.command("doctor").description("Quick health check across login, server,
41565
41742
  note(false, "Credentials file", `missing \u2014 run \`chat-recall login <server-url>\``);
41566
41743
  } else {
41567
41744
  try {
41568
- const mode = statSync49(credFile).mode & 511;
41745
+ const mode = statSync50(credFile).mode & 511;
41569
41746
  const isWin = process.platform === "win32";
41570
41747
  const safe = isWin || (mode & 63) === 0;
41571
41748
  note(safe, "Credentials file", isWin ? `${credFile} (Windows ACL \u2014 POSIX mode does not apply)` : `${credFile} (mode ${mode.toString(8).padStart(3, "0")}${safe ? "" : " \u2014 should be 600"})`);