chat-recall 0.7.59 → 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/mcp.js CHANGED
@@ -12917,6 +12917,42 @@ var init_session = __esm({
12917
12917
  }
12918
12918
  });
12919
12919
 
12920
+ // ../engine/dist/transcript/trim.js
12921
+ function detach(s) {
12922
+ return JSON.parse(JSON.stringify(s));
12923
+ }
12924
+ function capPayload(v, capChars = SYNC_PAYLOAD_CAP) {
12925
+ if (v === void 0)
12926
+ return void 0;
12927
+ if (typeof v === "string") {
12928
+ return v.length > capChars ? detach(v.slice(0, capChars)) + `\u2026 [+${v.length - capChars} chars]` : v;
12929
+ }
12930
+ let s = "";
12931
+ try {
12932
+ s = JSON.stringify(v) ?? "";
12933
+ } catch {
12934
+ return void 0;
12935
+ }
12936
+ if (s.length <= capChars * 4)
12937
+ return v;
12938
+ if (Array.isArray(v))
12939
+ return detach(s.slice(0, capChars)) + `\u2026 [+${s.length - capChars} chars]`;
12940
+ if (v && typeof v === "object") {
12941
+ const o = {};
12942
+ for (const [k, val] of Object.entries(v))
12943
+ o[k] = capPayload(val, capChars);
12944
+ return o;
12945
+ }
12946
+ return v;
12947
+ }
12948
+ var SYNC_PAYLOAD_CAP;
12949
+ var init_trim = __esm({
12950
+ "../engine/dist/transcript/trim.js"() {
12951
+ "use strict";
12952
+ SYNC_PAYLOAD_CAP = 2e3;
12953
+ }
12954
+ });
12955
+
12920
12956
  // ../engine/dist/transcript/claude.js
12921
12957
  import { open, readdir, readFile, stat } from "fs/promises";
12922
12958
  import { dirname as dirname11, join as join18, basename as basename11 } from "path";
@@ -12926,124 +12962,47 @@ function stripBanners2(text) {
12926
12962
  out = out.replace(re, " ");
12927
12963
  return out.replace(/[ \t]{2,}/g, " ").trim();
12928
12964
  }
12929
- function parseClaudeTranscriptText(text) {
12930
- const raw = [];
12965
+ function parseClaudeTranscriptText(text, opts = {}) {
12966
+ const builder = new MessageBuilder(opts.payloadCap);
12931
12967
  let lineNumber = 0;
12932
12968
  for (const line of text.split("\n")) {
12933
12969
  lineNumber++;
12934
12970
  if (!line.trim())
12935
12971
  continue;
12972
+ let obj2;
12936
12973
  try {
12937
- raw.push({ line: lineNumber, obj: JSON.parse(line) });
12974
+ obj2 = JSON.parse(line);
12938
12975
  } catch {
12976
+ continue;
12939
12977
  }
12978
+ builder.add(lineNumber, obj2);
12940
12979
  }
12941
- return messagesFromRawLines(raw);
12980
+ return builder.messages;
12942
12981
  }
12943
- async function parseMessagesFromFile(sessionPath) {
12982
+ async function parseMessagesFromFile(sessionPath, opts) {
12944
12983
  const file = await open(sessionPath);
12945
- const raw = [];
12984
+ const builder = new MessageBuilder(opts.payloadCap);
12946
12985
  try {
12947
12986
  let lineNumber = 0;
12948
12987
  for await (const line of file.readLines()) {
12949
12988
  lineNumber++;
12950
12989
  if (!line.trim())
12951
12990
  continue;
12991
+ let obj2;
12952
12992
  try {
12953
- raw.push({ line: lineNumber, obj: JSON.parse(line) });
12993
+ obj2 = JSON.parse(line);
12954
12994
  } catch {
12955
12995
  log2.debug({ line: lineNumber, file: sessionPath }, "skipped malformed transcript line");
12996
+ continue;
12956
12997
  }
12998
+ builder.add(lineNumber, obj2);
12957
12999
  }
12958
13000
  } finally {
12959
13001
  await file.close();
12960
13002
  }
12961
- return messagesFromRawLines(raw);
12962
- }
12963
- function messagesFromRawLines(raw) {
12964
- const toolResults = /* @__PURE__ */ new Map();
12965
- for (const { obj: obj2 } of raw) {
12966
- if (obj2?.type !== "user")
12967
- continue;
12968
- const content = obj2.message?.content;
12969
- if (!Array.isArray(content))
12970
- continue;
12971
- for (const block of content) {
12972
- if (block?.type === "tool_result" && block.tool_use_id) {
12973
- toolResults.set(block.tool_use_id, {
12974
- content: block.content,
12975
- isError: block.is_error === true
12976
- });
12977
- }
12978
- }
12979
- }
12980
- const messages = [];
12981
- for (const { line, obj: obj2 } of raw) {
12982
- if (!obj2 || typeof obj2 !== "object")
12983
- continue;
12984
- const timestamp = typeof obj2.timestamp === "string" ? obj2.timestamp : void 0;
12985
- if (obj2.type === "user") {
12986
- const content = obj2.message?.content;
12987
- let text = "";
12988
- if (typeof content === "string") {
12989
- text = content;
12990
- } else if (Array.isArray(content)) {
12991
- text = content.filter((c) => c?.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
12992
- }
12993
- if (!text.trim())
12994
- continue;
12995
- const cleaned = stripBanners2(text);
12996
- if (!cleaned)
12997
- continue;
12998
- const origin = userRecordOrigin(obj2, cleaned);
12999
- messages.push({ line, role: "user", content: cleaned, timestamp, ...origin === "human" ? {} : { origin } });
13000
- } else if (obj2.type === "attachment") {
13001
- const queued = queuedCommandPrompt(obj2);
13002
- if (!queued)
13003
- continue;
13004
- const cleaned = stripBanners2(queued.text);
13005
- if (!cleaned)
13006
- continue;
13007
- messages.push({ line, role: "user", content: cleaned, timestamp, ...queued.origin === "human" ? {} : { origin: queued.origin } });
13008
- } else if (obj2.type === "assistant") {
13009
- const blocks = Array.isArray(obj2.message?.content) ? obj2.message.content : [];
13010
- const thinkingBlock = blocks.find((c) => c?.type === "thinking");
13011
- const textBlock = blocks.find((c) => c?.type === "text");
13012
- const toolUses = blocks.filter((c) => c?.type === "tool_use");
13013
- const toolCalls = toolUses.map((toolUse) => {
13014
- const result = toolUse.id ? toolResults.get(toolUse.id) : void 0;
13015
- return {
13016
- name: toolUse.name || "unknown",
13017
- input: toolUse.input,
13018
- result: result?.content,
13019
- isError: result?.isError
13020
- };
13021
- });
13022
- const hasThinking = thinkingBlock !== void 0;
13023
- const text = textBlock?.text ?? "";
13024
- const thinking = thinkingBlock?.thinking ?? (hasThinking ? "" : void 0);
13025
- if (!text && !hasThinking && toolCalls.length === 0)
13026
- continue;
13027
- messages.push({
13028
- line,
13029
- role: "assistant",
13030
- content: text,
13031
- thinking,
13032
- toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
13033
- timestamp
13034
- });
13035
- } else if (obj2.type === "summary" && typeof obj2.summary === "string") {
13036
- messages.push({ line, role: "summary", content: obj2.summary });
13037
- } else if (obj2.type === "system" && obj2.subtype === "away_summary") {
13038
- const c = obj2.content;
13039
- 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") : "";
13040
- if (text.trim())
13041
- messages.push({ line, role: "summary", content: stripBanners2(text), timestamp });
13042
- }
13043
- }
13044
- return messages;
13003
+ return builder.messages;
13045
13004
  }
13046
- async function parseClaudeSubagents(sessionPath) {
13005
+ async function parseClaudeSubagents(sessionPath, opts = {}) {
13047
13006
  const sessionId = basename11(sessionPath).replace(/\.jsonl$/i, "");
13048
13007
  const subagentsDir = join18(dirname11(sessionPath), sessionId, "subagents");
13049
13008
  let entries;
@@ -13070,7 +13029,7 @@ async function parseClaudeSubagents(sessionPath) {
13070
13029
  }
13071
13030
  let messages = [];
13072
13031
  try {
13073
- messages = await parseMessagesFromFile(filePath);
13032
+ messages = await parseMessagesFromFile(filePath, opts);
13074
13033
  } catch (e) {
13075
13034
  log2.error({ err: e, filePath }, "Failed to parse subagent");
13076
13035
  }
@@ -13095,12 +13054,13 @@ async function parseClaudeSubagents(sessionPath) {
13095
13054
  }));
13096
13055
  return subagents.map((s, i) => ({ s, mtime: stats[i] })).sort((a, b) => a.mtime - b.mtime).map(({ s }) => s);
13097
13056
  }
13098
- var log2, INJECTED_BANNERS2;
13057
+ var log2, INJECTED_BANNERS2, MessageBuilder;
13099
13058
  var init_claude2 = __esm({
13100
13059
  "../engine/dist/transcript/claude.js"() {
13101
13060
  "use strict";
13102
13061
  init_logger();
13103
13062
  init_claude_prompt_origin();
13063
+ init_trim();
13104
13064
  log2 = createLogger("transcript-claude");
13105
13065
  INJECTED_BANNERS2 = [
13106
13066
  /MCP issues detected\. ?Run \/mcp list for status\.?/g,
@@ -13119,6 +13079,104 @@ var init_claude2 = __esm({
13119
13079
  // eslint-disable-next-line no-control-regex
13120
13080
  /\[[0-9;]*m/g
13121
13081
  ];
13082
+ MessageBuilder = class {
13083
+ messages = [];
13084
+ cap;
13085
+ /** The calls of each tool_use id. */
13086
+ calls = /* @__PURE__ */ new Map();
13087
+ /** The last result of each tool_use id. */
13088
+ results = /* @__PURE__ */ new Map();
13089
+ constructor(payloadCap) {
13090
+ this.cap = payloadCap ? (v) => capPayload(v, payloadCap) : (v) => v;
13091
+ }
13092
+ add(line, obj2) {
13093
+ if (!obj2 || typeof obj2 !== "object")
13094
+ return;
13095
+ const timestamp = typeof obj2.timestamp === "string" ? obj2.timestamp : void 0;
13096
+ if (obj2.type === "user") {
13097
+ const content = obj2.message?.content;
13098
+ if (Array.isArray(content)) {
13099
+ for (const block of content) {
13100
+ if (block?.type === "tool_result" && block.tool_use_id) {
13101
+ this.addResult(block.tool_use_id, this.cap(block.content), block.is_error === true);
13102
+ }
13103
+ }
13104
+ }
13105
+ let text = "";
13106
+ if (typeof content === "string") {
13107
+ text = content;
13108
+ } else if (Array.isArray(content)) {
13109
+ text = content.filter((c) => c?.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
13110
+ }
13111
+ if (!text.trim())
13112
+ return;
13113
+ const cleaned = stripBanners2(text);
13114
+ if (!cleaned)
13115
+ return;
13116
+ const origin = userRecordOrigin(obj2, cleaned);
13117
+ this.messages.push({ line, role: "user", content: cleaned, timestamp, ...origin === "human" ? {} : { origin } });
13118
+ } else if (obj2.type === "attachment") {
13119
+ const queued = queuedCommandPrompt(obj2);
13120
+ if (!queued)
13121
+ return;
13122
+ const cleaned = stripBanners2(queued.text);
13123
+ if (!cleaned)
13124
+ return;
13125
+ this.messages.push({ line, role: "user", content: cleaned, timestamp, ...queued.origin === "human" ? {} : { origin: queued.origin } });
13126
+ } else if (obj2.type === "assistant") {
13127
+ const blocks = Array.isArray(obj2.message?.content) ? obj2.message.content : [];
13128
+ const thinkingBlock = blocks.find((c) => c?.type === "thinking");
13129
+ const textBlock = blocks.find((c) => c?.type === "text");
13130
+ const toolUses = blocks.filter((c) => c?.type === "tool_use");
13131
+ const toolCalls = toolUses.map((toolUse) => {
13132
+ const known = toolUse.id ? this.results.get(toolUse.id) : void 0;
13133
+ const call2 = {
13134
+ name: toolUse.name || "unknown",
13135
+ input: this.cap(toolUse.input),
13136
+ result: known?.content,
13137
+ isError: known?.isError
13138
+ };
13139
+ if (toolUse.id) {
13140
+ const list = this.calls.get(toolUse.id);
13141
+ if (list)
13142
+ list.push(call2);
13143
+ else
13144
+ this.calls.set(toolUse.id, [call2]);
13145
+ }
13146
+ return call2;
13147
+ });
13148
+ const hasThinking = thinkingBlock !== void 0;
13149
+ const text = textBlock?.text ?? "";
13150
+ const thinking = thinkingBlock?.thinking != null ? this.cap(thinkingBlock.thinking) : hasThinking ? "" : void 0;
13151
+ if (!text && !hasThinking && toolCalls.length === 0)
13152
+ return;
13153
+ this.messages.push({
13154
+ line,
13155
+ role: "assistant",
13156
+ content: text,
13157
+ thinking,
13158
+ toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
13159
+ timestamp
13160
+ });
13161
+ } else if (obj2.type === "summary" && typeof obj2.summary === "string") {
13162
+ this.messages.push({ line, role: "summary", content: obj2.summary });
13163
+ } else if (obj2.type === "system" && obj2.subtype === "away_summary") {
13164
+ const c = obj2.content;
13165
+ 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") : "";
13166
+ if (text.trim())
13167
+ this.messages.push({ line, role: "summary", content: stripBanners2(text), timestamp });
13168
+ }
13169
+ }
13170
+ addResult(id, content, isError) {
13171
+ this.results.set(id, { content, isError });
13172
+ const list = this.calls.get(id);
13173
+ if (list)
13174
+ for (const call2 of list) {
13175
+ call2.result = content;
13176
+ call2.isError = isError;
13177
+ }
13178
+ }
13179
+ };
13122
13180
  }
13123
13181
  });
13124
13182
 
@@ -14400,7 +14458,14 @@ var init_opencode2 = __esm({
14400
14458
 
14401
14459
  // ../engine/dist/transcript/index.js
14402
14460
  import { statSync as statSync17 } from "fs";
14403
- async function parseTranscript(sessionId) {
14461
+ async function parseTranscript(sessionId, opts = {}) {
14462
+ const t = await parseTranscriptUncut(sessionId, opts);
14463
+ const cap = opts.payloadCap;
14464
+ if (!t || !cap || t.payloadCap === cap)
14465
+ return t;
14466
+ return { ...t, ...trimTranscriptForSync(t, cap), payloadCap: cap };
14467
+ }
14468
+ async function parseTranscriptUncut(sessionId, opts) {
14404
14469
  const tool = detectTool(sessionId);
14405
14470
  if (tool === "claude") {
14406
14471
  const groups = resolveSessionContentGroups(sessionId);
@@ -14411,9 +14476,10 @@ async function parseTranscript(sessionId) {
14411
14476
  return null;
14412
14477
  const primaryPath = mainGroup.paths[0];
14413
14478
  const merged = readSessionGroupText(mainGroup);
14479
+ const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
14414
14480
  const [tail, allSubagents] = await Promise.all([
14415
- Promise.resolve(parseClaudeTranscriptText(merged.text)),
14416
- parseClaudeSubagents(primaryPath)
14481
+ Promise.resolve(parseClaudeTranscriptText(merged.text, cut)),
14482
+ parseClaudeSubagents(primaryPath, cut)
14417
14483
  ]);
14418
14484
  const compacts = allSubagents.filter((s) => s.kind === "compact");
14419
14485
  const subagents = allSubagents.filter((s) => s.kind !== "compact");
@@ -14430,7 +14496,7 @@ async function parseTranscript(sessionId) {
14430
14496
  }
14431
14497
  messages = [...stitched, ...tail].map((m, i) => ({ ...m, line: i + 1 }));
14432
14498
  }
14433
- return { messages, subagents, mtime: merged.mtime || safeMtime(primaryPath) };
14499
+ return { messages, subagents, mtime: merged.mtime || safeMtime(primaryPath), ...opts.payloadCap ? { payloadCap: opts.payloadCap } : {} };
14434
14500
  }
14435
14501
  if (tool === "opencode") {
14436
14502
  const messages = await parseOpenCodeTranscript(sessionId);
@@ -14472,31 +14538,8 @@ function safeMtime(path2) {
14472
14538
  return 0;
14473
14539
  }
14474
14540
  }
14475
- function trimTranscriptForSync(t, capChars = 2e3) {
14476
- const cap = (v) => {
14477
- if (v === void 0)
14478
- return void 0;
14479
- if (typeof v === "string") {
14480
- return v.length > capChars ? v.slice(0, capChars) + `\u2026 [+${v.length - capChars} chars]` : v;
14481
- }
14482
- let s = "";
14483
- try {
14484
- s = JSON.stringify(v) ?? "";
14485
- } catch {
14486
- return void 0;
14487
- }
14488
- if (s.length <= capChars * 4)
14489
- return v;
14490
- if (Array.isArray(v))
14491
- return s.slice(0, capChars) + `\u2026 [+${s.length - capChars} chars]`;
14492
- if (v && typeof v === "object") {
14493
- const o = {};
14494
- for (const [k, val] of Object.entries(v))
14495
- o[k] = cap(val);
14496
- return o;
14497
- }
14498
- return v;
14499
- };
14541
+ function trimTranscriptForSync(t, capChars = SYNC_PAYLOAD_CAP) {
14542
+ const cap = (v) => capPayload(v, capChars);
14500
14543
  const trimMsg = (m) => ({
14501
14544
  ...m,
14502
14545
  thinking: m.thinking !== void 0 ? cap(m.thinking) : void 0,
@@ -14521,7 +14564,9 @@ var init_transcript = __esm({
14521
14564
  init_opencode2();
14522
14565
  init_codex2();
14523
14566
  init_from_events();
14567
+ init_trim();
14524
14568
  init_types();
14569
+ init_trim();
14525
14570
  init_raw();
14526
14571
  init_shadow();
14527
14572
  init_claude2();
@@ -30170,8 +30215,100 @@ var init_telemetry = __esm({
30170
30215
  }
30171
30216
  });
30172
30217
 
30218
+ // src/session-file-scan.ts
30219
+ import { open as open3 } from "node:fs/promises";
30220
+ import { statSync as statSync43 } from "node:fs";
30221
+ function sessionGroupsBytes(groups) {
30222
+ let total = 0;
30223
+ for (const g of groups) {
30224
+ for (const p of g.paths) {
30225
+ try {
30226
+ total += statSync43(p).size;
30227
+ } catch {
30228
+ }
30229
+ }
30230
+ }
30231
+ return total;
30232
+ }
30233
+ async function* readLinePieces(path2, pieceBytes = SCAN_PIECE_BYTES) {
30234
+ const fh = await open3(path2, "r");
30235
+ try {
30236
+ const buf = Buffer.allocUnsafe(pieceBytes);
30237
+ let carry = Buffer.alloc(0);
30238
+ for (; ; ) {
30239
+ const { bytesRead } = await fh.read(buf, 0, pieceBytes, null);
30240
+ if (bytesRead === 0) break;
30241
+ const joined = carry.length ? Buffer.concat([carry, buf.subarray(0, bytesRead)]) : buf.subarray(0, bytesRead);
30242
+ const cut = joined.lastIndexOf(NEWLINE);
30243
+ if (cut < 0) {
30244
+ carry = Buffer.from(joined);
30245
+ continue;
30246
+ }
30247
+ const piece = joined.subarray(0, cut + 1);
30248
+ carry = Buffer.from(joined.subarray(cut + 1));
30249
+ yield { text: piece.toString("utf8"), newlines: countNewlines(piece) };
30250
+ }
30251
+ if (carry.length) yield { text: carry.toString("utf8"), newlines: 0 };
30252
+ } finally {
30253
+ await fh.close();
30254
+ }
30255
+ }
30256
+ function countNewlines(b) {
30257
+ let n = 0;
30258
+ for (let i = b.indexOf(NEWLINE); i >= 0; i = b.indexOf(NEWLINE, i + 1)) n++;
30259
+ return n;
30260
+ }
30261
+ async function scanSessionGroupsChunked(sessionId, groups, tenantRules, pieceBytes = SCAN_PIECE_BYTES) {
30262
+ const findings = [];
30263
+ let lineBase = 0;
30264
+ const scan = (text) => {
30265
+ try {
30266
+ for (const x of scanTextForFindings(text)) {
30267
+ findings.push({ session_id: sessionId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
30268
+ }
30269
+ } catch {
30270
+ }
30271
+ if (tenantRules && tenantRules.length > 0) {
30272
+ try {
30273
+ for (const x of scanTenantRules(text, tenantRules)) {
30274
+ findings.push({ session_id: sessionId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
30275
+ }
30276
+ } catch {
30277
+ }
30278
+ }
30279
+ };
30280
+ for (const group of groups) {
30281
+ if (group.paths.length === 1) {
30282
+ let any = false;
30283
+ for await (const piece of readLinePieces(group.paths[0], pieceBytes)) {
30284
+ any = true;
30285
+ scan(piece.text);
30286
+ lineBase += piece.newlines;
30287
+ }
30288
+ if (any) lineBase += 1;
30289
+ } else {
30290
+ const { text } = readSessionGroupText(group);
30291
+ if (!text) continue;
30292
+ scan(text);
30293
+ lineBase += (text.match(/\n/g)?.length ?? 0) + 1;
30294
+ }
30295
+ }
30296
+ return findings;
30297
+ }
30298
+ var SCAN_PIECE_BYTES, NEWLINE;
30299
+ var init_session_file_scan = __esm({
30300
+ "src/session-file-scan.ts"() {
30301
+ "use strict";
30302
+ init_secret_redactor();
30303
+ init_secret_scanner();
30304
+ init_live_session_scan();
30305
+ SCAN_PIECE_BYTES = 8 * 1024 * 1024;
30306
+ NEWLINE = 10;
30307
+ }
30308
+ });
30309
+
30173
30310
  // src/raw-archive-parts.ts
30174
- import { createReadStream as createReadStream4, createWriteStream as createWriteStream2, openSync as openSync11, readSync as readSync9, closeSync as closeSync11, rmSync as rmSync5, statSync as statSync43 } from "node:fs";
30311
+ import { createReadStream as createReadStream4, createWriteStream as createWriteStream2, openSync as openSync11, readSync as readSync9, closeSync as closeSync11, rmSync as rmSync5, statSync as statSync44 } from "node:fs";
30175
30312
  import { tmpdir as tmpdir2 } from "node:os";
30176
30313
  import { join as join54 } from "node:path";
30177
30314
  import { randomBytes } from "node:crypto";
@@ -30239,7 +30376,7 @@ async function writeArchiveFile(source, meta, redact, dir = tmpdir2()) {
30239
30376
  rmSync5(path2, { force: true });
30240
30377
  throw err;
30241
30378
  }
30242
- return { path: path2, gzSize: statSync43(path2).size, size };
30379
+ return { path: path2, gzSize: statSync44(path2).size, size };
30243
30380
  }
30244
30381
  async function putPart(url, body2) {
30245
30382
  let last;
@@ -30477,7 +30614,7 @@ __export(auto_update_exports, {
30477
30614
  import { execSync as execSync4, execFileSync as execFileSync3 } from "node:child_process";
30478
30615
  import { readFileSync as readFileSync47, existsSync as existsSync47 } from "node:fs";
30479
30616
  import { fileURLToPath as fileURLToPath2 } from "node:url";
30480
- import { writeFileSync as writeFileSync11, mkdtempSync as mkdtempSync3, rmSync as rmSync6, readdirSync as readdirSync33, statSync as statSync44, mkdirSync as mkdirSync12 } from "node:fs";
30617
+ import { writeFileSync as writeFileSync11, mkdtempSync as mkdtempSync3, rmSync as rmSync6, readdirSync as readdirSync33, statSync as statSync45, mkdirSync as mkdirSync12 } from "node:fs";
30481
30618
  import { join as join55, dirname as dirname18, sep as sep3, posix as pathPosix, win32 as pathWin32 } from "node:path";
30482
30619
  import { tmpdir as tmpdir3, homedir as homedir18 } from "node:os";
30483
30620
  import { createHash as createHash11 } from "node:crypto";
@@ -30530,7 +30667,7 @@ function sweepStaleStaging(root = tmpdir3(), now = Date.now()) {
30530
30667
  if (!MKDTEMP_SUFFIX.test(name)) continue;
30531
30668
  const dir = join55(root, name);
30532
30669
  try {
30533
- const st = statSync44(dir);
30670
+ const st = statSync45(dir);
30534
30671
  if (!st.isDirectory() || now - st.mtimeMs < COLD_MS) continue;
30535
30672
  const inside = readdirSync33(dir);
30536
30673
  if (inside.length > 1 || inside.length === 1 && inside[0] !== "chat-recall.tgz") continue;
@@ -30814,7 +30951,7 @@ __export(sync_client_exports, {
30814
30951
  syncSessions: () => syncSessions
30815
30952
  });
30816
30953
  import { join as join56, dirname as dirname19, basename as basename24 } from "node:path";
30817
- import { readFileSync as readFileSync48, writeFileSync as writeFileSync12, mkdirSync as mkdirSync13, mkdtempSync as mkdtempSync4, rmSync as rmSync7, chmodSync as chmodSync6, unlinkSync as unlinkSync3, readdirSync as readdirSync34, statSync as statSync45 } from "node:fs";
30954
+ import { readFileSync as readFileSync48, writeFileSync as writeFileSync12, mkdirSync as mkdirSync13, mkdtempSync as mkdtempSync4, rmSync as rmSync7, chmodSync as chmodSync6, unlinkSync as unlinkSync3, readdirSync as readdirSync34, statSync as statSync46 } from "node:fs";
30818
30955
  import { tmpdir as tmpdir4, hostname as hostname2 } from "node:os";
30819
30956
  import { createHash as createHash12 } from "node:crypto";
30820
30957
  import { fileURLToPath as fileURLToPath3 } from "node:url";
@@ -31291,7 +31428,7 @@ function reapStaleScanDirs(dir = tmpdir4(), maxAgeMs = 6 * 36e5, now = Date.now(
31291
31428
  if (!name.startsWith("cr-batchscan-")) continue;
31292
31429
  const p = join56(dir, name);
31293
31430
  try {
31294
- if (now - statSync45(p).mtimeMs < maxAgeMs) continue;
31431
+ if (now - statSync46(p).mtimeMs < maxAgeMs) continue;
31295
31432
  rmSync7(p, { recursive: true, force: true });
31296
31433
  reaped++;
31297
31434
  } catch {
@@ -32195,6 +32332,10 @@ function sessionFileBytes(ref) {
32195
32332
  if (!backend?.isAppendOnly?.()) return 0;
32196
32333
  return backend.fileSize?.(ref.prefixedId) ?? 0;
32197
32334
  }
32335
+ function syncTranscript(t) {
32336
+ const cut = t.payloadCap ? { messages: t.messages, subagents: t.subagents } : trimTranscriptForSync(t);
32337
+ return { messages: cut.messages, subagents: cut.subagents.map((s) => ({ ...s, filePath: "" })) };
32338
+ }
32198
32339
  function sessionBuildBytes(ref) {
32199
32340
  const main2 = sessionFileBytes(ref);
32200
32341
  if (main2 === 0) return 0;
@@ -32231,11 +32372,14 @@ async function buildConversationSync(ref, mtime, opts = {}) {
32231
32372
  } else {
32232
32373
  try {
32233
32374
  const backend = getBackendForId(ref.prefixedId) ?? getBackend("claude");
32234
- const exp = backend.exportRawSession(ref.prefixedId);
32375
+ const streamGroups = ref.toolId === "claude" ? resolveSessionContentGroups(ref.rawId) : [];
32376
+ const streamedBytes = sessionGroupsBytes(streamGroups);
32377
+ const streamed = streamedBytes > FULL_BUILD_MAX_BYTES;
32378
+ const exp = streamed ? null : backend.exportRawSession(ref.prefixedId);
32235
32379
  let built;
32236
- const exportBytes = exportByteLength(exp);
32380
+ const exportBytes = streamed ? streamedBytes : exportByteLength(exp);
32237
32381
  const overCeiling = exportBytes > FULL_BUILD_MAX_BYTES;
32238
- if (exp && overCeiling) {
32382
+ if ((exp || streamed) && overCeiling) {
32239
32383
  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`);
32240
32384
  record({
32241
32385
  kind: "oversized_session",
@@ -32246,25 +32390,29 @@ async function buildConversationSync(ref, mtime, opts = {}) {
32246
32390
  includeRaw = false;
32247
32391
  includeMeta = false;
32248
32392
  exportOverCeiling = true;
32249
- overCeilingFindings = [];
32250
- let lineBase = 0;
32251
- for (const f of exp.files) {
32252
- const text = f.bytes.toString("utf8");
32253
- try {
32254
- for (const x of scanTextForFindings(text)) {
32255
- overCeilingFindings.push({ session_id: ref.prefixedId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
32256
- }
32257
- } catch {
32258
- }
32259
- if (opts.tenantRules && opts.tenantRules.length > 0) {
32393
+ if (streamed) {
32394
+ overCeilingFindings = await scanSessionGroupsChunked(ref.prefixedId, streamGroups, opts.tenantRules);
32395
+ } else if (exp) {
32396
+ overCeilingFindings = [];
32397
+ let lineBase = 0;
32398
+ for (const f of exp.files) {
32399
+ const text = f.bytes.toString("utf8");
32260
32400
  try {
32261
- for (const x of scanTenantRules(text, opts.tenantRules)) {
32262
- overCeilingFindings.push({ session_id: ref.prefixedId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
32401
+ for (const x of scanTextForFindings(text)) {
32402
+ overCeilingFindings.push({ session_id: ref.prefixedId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
32263
32403
  }
32264
32404
  } catch {
32265
32405
  }
32406
+ if (opts.tenantRules && opts.tenantRules.length > 0) {
32407
+ try {
32408
+ for (const x of scanTenantRules(text, opts.tenantRules)) {
32409
+ overCeilingFindings.push({ session_id: ref.prefixedId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
32410
+ }
32411
+ } catch {
32412
+ }
32413
+ }
32414
+ lineBase += (text.match(/\n/g)?.length ?? 0) + 1;
32266
32415
  }
32267
- lineBase += (text.match(/\n/g)?.length ?? 0) + 1;
32268
32416
  }
32269
32417
  }
32270
32418
  if (exp && !overCeiling) {
@@ -32304,7 +32452,7 @@ async function buildConversationSync(ref, mtime, opts = {}) {
32304
32452
  }
32305
32453
  if (!transcript) {
32306
32454
  try {
32307
- const t = await parseTranscript(ref.prefixedId);
32455
+ const t = await parseTranscript(ref.prefixedId, { payloadCap: SYNC_PAYLOAD_CAP });
32308
32456
  if (t && (t.messages.length > 0 || t.subagents.length > 0)) transcript = t;
32309
32457
  } catch {
32310
32458
  }
@@ -32317,7 +32465,9 @@ async function buildConversationSync(ref, mtime, opts = {}) {
32317
32465
  if (isInternalToolPrompt(firstUser?.content)) return null;
32318
32466
  const count = { redactions: 0 };
32319
32467
  const envelope = redactDeep(
32320
- { v: TRANSCRIPT_VERSION, ...trimTranscriptForSync(transcript) },
32468
+ // A transcript the parser already cut is not cut again: the cut is not idempotent.
32469
+ // The path of a subagent file on this machine does not leave it: the container parse gives ''.
32470
+ { v: TRANSCRIPT_VERSION, ...syncTranscript(transcript) },
32321
32471
  count
32322
32472
  );
32323
32473
  let projectPath = ref.projectPath;
@@ -32689,6 +32839,7 @@ var init_sync_client = __esm({
32689
32839
  init_telemetry();
32690
32840
  init_collector_health();
32691
32841
  init_live_session_scan();
32842
+ init_session_file_scan();
32692
32843
  init_raw_archive_parts();
32693
32844
  init_backends();
32694
32845
  ownVersion = "0.0.0";
@@ -33264,7 +33415,7 @@ __export(install_skills_exports, {
33264
33415
  skillsSourceDir: () => skillsSourceDir,
33265
33416
  uninstallSkills: () => uninstallSkills
33266
33417
  });
33267
- import { readdirSync as readdirSync36, existsSync as existsSync49, mkdirSync as mkdirSync16, rmSync as rmSync9, cpSync, writeFileSync as writeFileSync16, readFileSync as readFileSync54, statSync as statSync47, realpathSync as realpathSync5 } from "fs";
33418
+ import { readdirSync as readdirSync36, existsSync as existsSync49, mkdirSync as mkdirSync16, rmSync as rmSync9, cpSync, writeFileSync as writeFileSync16, readFileSync as readFileSync54, statSync as statSync48, realpathSync as realpathSync5 } from "fs";
33268
33419
  import { createHash as createHash13 } from "crypto";
33269
33420
  import { join as join60, basename as basename25 } from "path";
33270
33421
  function skillsSourceDir() {
@@ -34944,14 +35095,14 @@ var init_opencode_tui_config = __esm({
34944
35095
  return this.array(t);
34945
35096
  throw new SyntaxError(`unexpected "${t.v}" at ${t.start}`);
34946
35097
  }
34947
- object(open3) {
35098
+ object(open4) {
34948
35099
  this.i += 1;
34949
35100
  const props = [];
34950
35101
  for (; ; ) {
34951
35102
  const k = this.at();
34952
35103
  if (this.isP(k, "}")) {
34953
35104
  this.i += 1;
34954
- return { k: "obj", start: open3.start, end: k.end, closeStart: k.start, props };
35105
+ return { k: "obj", start: open4.start, end: k.end, closeStart: k.start, props };
34955
35106
  }
34956
35107
  if (!k || k.t !== "s")
34957
35108
  throw new SyntaxError(`expected a key at ${k ? k.start : "end"}`);
@@ -34970,7 +35121,7 @@ var init_opencode_tui_config = __esm({
34970
35121
  throw new SyntaxError(`expected "," or "}" at ${n ? n.start : "end"}`);
34971
35122
  }
34972
35123
  }
34973
- array(open3) {
35124
+ array(open4) {
34974
35125
  this.i += 1;
34975
35126
  const items = [];
34976
35127
  const commas = [];
@@ -34978,7 +35129,7 @@ var init_opencode_tui_config = __esm({
34978
35129
  const n = this.at();
34979
35130
  if (this.isP(n, "]")) {
34980
35131
  this.i += 1;
34981
- return { k: "arr", start: open3.start, end: n.end, closeStart: n.start, items, commas };
35132
+ return { k: "arr", start: open4.start, end: n.end, closeStart: n.start, items, commas };
34982
35133
  }
34983
35134
  items.push(this.value());
34984
35135
  const c = this.at();
@@ -40953,9 +41104,9 @@ ${lines.join("\n")}
40953
41104
 
40954
41105
  _Call again with \`detail: true\` for the full brief (fix, locations, agent prompt) so you can start work._` }] };
40955
41106
  }
40956
- const open3 = tasks.filter((t) => t.status !== "done" && t.status !== "rejected");
40957
- const claimed = open3.filter((t) => t.status === "in_progress");
40958
- const blocks = open3.map((t, i) => {
41107
+ const open4 = tasks.filter((t) => t.status !== "done" && t.status !== "rejected");
41108
+ const claimed = open4.filter((t) => t.status === "in_progress");
41109
+ const blocks = open4.map((t, i) => {
40959
41110
  const head = `## ${i + 1}. ${t.title}
40960
41111
 
40961
41112
  - id: \`${t.id}\` \xB7 status: ${t.status}${t.projectId ? ` \xB7 project: ${t.projectId}` : ""}${t.linkedSessionId ? ` \xB7 already claimed by session ${t.linkedSessionId.slice(0, 8)}` : ""}`;
@@ -40985,7 +41136,7 @@ ${body2}` : head;
40985
41136
  "Auto-filed cards also close themselves once a re-index no longer reports their finding, so a",
40986
41137
  "real fix ends the task either way."
40987
41138
  ].join("\n");
40988
- const header = `# Tasks ready to work (${open3.length}${tasks.length !== open3.length ? ` of ${tasks.length}` : ""})${params.project ? ` \xB7 ${params.project}` : ""}${claimed.length ? `
41139
+ const header = `# Tasks ready to work (${open4.length}${tasks.length !== open4.length ? ` of ${tasks.length}` : ""})${params.project ? ` \xB7 ${params.project}` : ""}${claimed.length ? `
40989
41140
 
40990
41141
  _${claimed.length} already in progress \u2014 check the session link before starting one of those._` : ""}`;
40991
41142
  return { content: [{ type: "text", text: `${header}
@@ -42673,7 +42824,7 @@ function channelDecision(env = process.env, args = process.argv.slice(2), ancest
42673
42824
  // src/channel-state.ts
42674
42825
  init_data_dir();
42675
42826
  import { execFileSync as execFileSync5 } from "node:child_process";
42676
- import { mkdirSync as mkdirSync14, readFileSync as readFileSync52, readdirSync as readdirSync35, statSync as statSync46, unlinkSync as unlinkSync4, writeFileSync as writeFileSync14 } from "node:fs";
42827
+ import { mkdirSync as mkdirSync14, readFileSync as readFileSync52, readdirSync as readdirSync35, statSync as statSync47, unlinkSync as unlinkSync4, writeFileSync as writeFileSync14 } from "node:fs";
42677
42828
  import { join as join58 } from "node:path";
42678
42829
  function channelStateDir() {
42679
42830
  return join58(getDataDir(), "hook-state", "messages");
@@ -42743,7 +42894,7 @@ function readMarker(sessionId) {
42743
42894
  const [pidText, started] = readFileSync52(path2, "utf-8").trim().split(" ");
42744
42895
  const pid = Number(pidText);
42745
42896
  if (!Number.isInteger(pid) || pid <= 1) return null;
42746
- return { pid, started, mtime: statSync46(path2).mtimeMs };
42897
+ return { pid, started, mtime: statSync47(path2).mtimeMs };
42747
42898
  } catch {
42748
42899
  return null;
42749
42900
  }