chat-recall 0.7.59 → 0.7.61

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);
9202
- }
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;
9243
+ return builder.messages;
9285
9244
  }
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
 
@@ -10729,6 +10787,52 @@ var init_opencode = __esm({
10729
10787
  getCommits(id, files, startMs, endMs, bufferMinutes) {
10730
10788
  return getSessionCommits(this.toPrefixedId(id), files, startMs, endMs, bufferMinutes);
10731
10789
  }
10790
+ /** The bytes of the dump of a session, summed in SQLite: no row is read into the process. */
10791
+ rawSessionBytes(id) {
10792
+ const dbPath = this.dbPath();
10793
+ if (!existsSync11(dbPath))
10794
+ return 0;
10795
+ const realId = this.toRawId(id);
10796
+ const db = openOpencodeDbOrThrow(dbPath);
10797
+ try {
10798
+ const row = db.prepare(`
10799
+ SELECT COALESCE(SUM(LENGTH(CAST(p.data AS BLOB)) + LENGTH(CAST(m.data AS BLOB))), 0) AS bytes
10800
+ FROM part p JOIN (SELECT id, data FROM message WHERE session_id = ?) m ON p.message_id = m.id
10801
+ WHERE p.session_id = ?
10802
+ `).get(realId, realId);
10803
+ return Number(row?.bytes ?? 0);
10804
+ } catch {
10805
+ return 0;
10806
+ } finally {
10807
+ db.close();
10808
+ }
10809
+ }
10810
+ /** The lines of the dump, one row at a time. Every line ends with a newline. */
10811
+ *iterateRawSessionLines(id) {
10812
+ const dbPath = this.dbPath();
10813
+ if (!existsSync11(dbPath))
10814
+ return;
10815
+ const realId = this.toRawId(id);
10816
+ const db = openOpencodeDbOrThrow(dbPath);
10817
+ try {
10818
+ const session = db.prepare(`SELECT * FROM session WHERE id = ?`).get(realId);
10819
+ if (!session)
10820
+ return;
10821
+ yield `${JSON.stringify({ kind: "session", row: session })}
10822
+ `;
10823
+ const rows = db.prepare(`
10824
+ SELECT m.id AS message_id, m.data AS message_data, p.id AS part_id, p.data AS part_data, p.time_created
10825
+ FROM part p JOIN (SELECT id, data FROM message WHERE session_id = ?) m ON p.message_id = m.id
10826
+ WHERE p.session_id = ?
10827
+ ORDER BY p.time_created ASC, p.id ASC
10828
+ `);
10829
+ for (const r of rows.iterate(realId, realId))
10830
+ yield `${JSON.stringify({ kind: "part", row: r })}
10831
+ `;
10832
+ } finally {
10833
+ db.close();
10834
+ }
10835
+ }
10732
10836
  exportRawSession(id) {
10733
10837
  const dbPath = this.dbPath();
10734
10838
  if (!existsSync11(dbPath))
@@ -16908,7 +17012,7 @@ var init_types = __esm({
16908
17012
  });
16909
17013
 
16910
17014
  // ../engine/dist/transcript/opencode.js
16911
- async function parseOpenCodeSubagents(parentSessionId) {
17015
+ async function parseOpenCodeSubagents(parentSessionId, opts = {}) {
16912
17016
  const { existsSync: existsSync63 } = await import("fs");
16913
17017
  const { opencodeBackend: opencodeBackend2 } = await Promise.resolve().then(() => (init_opencode(), opencode_exports));
16914
17018
  const dbPath = opencodeBackend2.dbPath();
@@ -16928,7 +17032,7 @@ async function parseOpenCodeSubagents(parentSessionId) {
16928
17032
  const childId = `opencode_${c.id}`;
16929
17033
  let messages = [];
16930
17034
  try {
16931
- messages = await parseOpenCodeTranscript(childId);
17035
+ messages = await parseOpenCodeTranscript(childId, opts);
16932
17036
  } catch (e) {
16933
17037
  log5.error({ err: e, sessionId: c.id }, "Failed to parse OpenCode sub-session");
16934
17038
  }
@@ -16952,7 +17056,7 @@ async function parseOpenCodeSubagents(parentSessionId) {
16952
17056
  db.close();
16953
17057
  }
16954
17058
  }
16955
- async function parseOpenCodeTranscript(sessionId) {
17059
+ async function parseOpenCodeTranscript(sessionId, opts = {}) {
16956
17060
  const { existsSync: existsSync63 } = await import("fs");
16957
17061
  const { opencodeBackend: opencodeBackend2 } = await Promise.resolve().then(() => (init_opencode(), opencode_exports));
16958
17062
  const dbPath = opencodeBackend2.dbPath();
@@ -16968,13 +17072,19 @@ async function parseOpenCodeTranscript(sessionId) {
16968
17072
  JOIN (SELECT id, data FROM message WHERE session_id = ?) m ON p.message_id = m.id
16969
17073
  WHERE p.session_id = ?
16970
17074
  ORDER BY p.time_created ASC
16971
- `).all(realId, realId);
17075
+ `).iterate(realId, realId);
17076
+ const cap = opts.payloadCap ? (v) => capPayload(v, opts.payloadCap) : (v) => v;
17077
+ let lastMsgData = "";
17078
+ let lastRole = "assistant";
16972
17079
  let lineNum = 0;
16973
17080
  for (const part of parts) {
16974
17081
  try {
16975
17082
  const partData = JSON.parse(part.data);
16976
- const msgData = JSON.parse(part.msg_data);
16977
- const role = msgData.role === "user" ? "user" : "assistant";
17083
+ if (part.msg_data !== lastMsgData) {
17084
+ lastRole = JSON.parse(part.msg_data).role === "user" ? "user" : "assistant";
17085
+ lastMsgData = part.msg_data;
17086
+ }
17087
+ const role = lastRole;
16978
17088
  if (partData.type === "text" && partData.text?.trim()) {
16979
17089
  lineNum++;
16980
17090
  messages.push({ line: lineNum, role, content: partData.text });
@@ -16984,7 +17094,7 @@ async function parseOpenCodeTranscript(sessionId) {
16984
17094
  line: lineNum,
16985
17095
  role: "assistant",
16986
17096
  content: `Tool: ${partData.tool}`,
16987
- toolCalls: [{ name: partData.tool, input: partData.state || {} }]
17097
+ toolCalls: [{ name: partData.tool, input: cap(partData.state || {}) }]
16988
17098
  });
16989
17099
  }
16990
17100
  } catch {
@@ -17001,6 +17111,7 @@ var init_opencode2 = __esm({
17001
17111
  "use strict";
17002
17112
  init_opencode_v2();
17003
17113
  init_logger();
17114
+ init_trim();
17004
17115
  log5 = createLogger("transcript-opencode");
17005
17116
  }
17006
17117
  });
@@ -17009,10 +17120,12 @@ var init_opencode2 = __esm({
17009
17120
  var transcript_exports = {};
17010
17121
  __export(transcript_exports, {
17011
17122
  RAW_PARSE_MAX_BYTES: () => RAW_PARSE_MAX_BYTES,
17123
+ SYNC_PAYLOAD_CAP: () => SYNC_PAYLOAD_CAP,
17012
17124
  TRANSCRIPT_VERSION: () => TRANSCRIPT_VERSION,
17013
17125
  archiveRawSession: () => archiveRawSession,
17014
17126
  buildRawContainer: () => buildRawContainer,
17015
17127
  canonicalEventsToMessages: () => canonicalEventsToMessages,
17128
+ capPayload: () => capPayload,
17016
17129
  containerSrcHash: () => containerSrcHash,
17017
17130
  detectForkPredecessor: () => detectForkPredecessor,
17018
17131
  gunzipContainer: () => gunzipContainer,
@@ -17047,7 +17160,14 @@ __export(transcript_exports, {
17047
17160
  writeTranscriptEnvelope: () => writeTranscriptEnvelope
17048
17161
  });
17049
17162
  import { statSync as statSync21 } from "fs";
17050
- async function parseTranscript(sessionId) {
17163
+ async function parseTranscript(sessionId, opts = {}) {
17164
+ const t = await parseTranscriptUncut(sessionId, opts);
17165
+ const cap = opts.payloadCap;
17166
+ if (!t || !cap || t.payloadCap === cap)
17167
+ return t;
17168
+ return { ...t, ...trimTranscriptForSync(t, cap), payloadCap: cap };
17169
+ }
17170
+ async function parseTranscriptUncut(sessionId, opts) {
17051
17171
  const tool = detectTool(sessionId);
17052
17172
  if (tool === "claude") {
17053
17173
  const groups = resolveSessionContentGroups(sessionId);
@@ -17058,9 +17178,10 @@ async function parseTranscript(sessionId) {
17058
17178
  return null;
17059
17179
  const primaryPath = mainGroup.paths[0];
17060
17180
  const merged = readSessionGroupText(mainGroup);
17181
+ const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
17061
17182
  const [tail, allSubagents] = await Promise.all([
17062
- Promise.resolve(parseClaudeTranscriptText(merged.text)),
17063
- parseClaudeSubagents(primaryPath)
17183
+ Promise.resolve(parseClaudeTranscriptText(merged.text, cut)),
17184
+ parseClaudeSubagents(primaryPath, cut)
17064
17185
  ]);
17065
17186
  const compacts = allSubagents.filter((s) => s.kind === "compact");
17066
17187
  const subagents = allSubagents.filter((s) => s.kind !== "compact");
@@ -17077,15 +17198,16 @@ async function parseTranscript(sessionId) {
17077
17198
  }
17078
17199
  messages = [...stitched, ...tail].map((m, i) => ({ ...m, line: i + 1 }));
17079
17200
  }
17080
- return { messages, subagents, mtime: merged.mtime || safeMtime(primaryPath) };
17201
+ return { messages, subagents, mtime: merged.mtime || safeMtime(primaryPath), ...opts.payloadCap ? { payloadCap: opts.payloadCap } : {} };
17081
17202
  }
17082
17203
  if (tool === "opencode") {
17083
- const messages = await parseOpenCodeTranscript(sessionId);
17204
+ const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
17205
+ const messages = await parseOpenCodeTranscript(sessionId, cut);
17084
17206
  if (messages.length === 0)
17085
17207
  return null;
17086
- const subagents = await parseOpenCodeSubagents(sessionId);
17208
+ const subagents = await parseOpenCodeSubagents(sessionId, cut);
17087
17209
  const loc = getBackend("opencode").findSession(sessionId);
17088
- return { messages, subagents, mtime: loc?.mtime || 0 };
17210
+ return { messages, subagents, mtime: loc?.mtime || 0, ...opts.payloadCap ? { payloadCap: opts.payloadCap } : {} };
17089
17211
  }
17090
17212
  if (tool === "codex") {
17091
17213
  const loc = getBackend("codex").findSession(sessionId);
@@ -17119,31 +17241,8 @@ function safeMtime(path) {
17119
17241
  return 0;
17120
17242
  }
17121
17243
  }
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
- };
17244
+ function trimTranscriptForSync(t, capChars = SYNC_PAYLOAD_CAP) {
17245
+ const cap = (v) => capPayload(v, capChars);
17147
17246
  const trimMsg = (m) => ({
17148
17247
  ...m,
17149
17248
  thinking: m.thinking !== void 0 ? cap(m.thinking) : void 0,
@@ -17175,7 +17274,9 @@ var init_transcript = __esm({
17175
17274
  init_opencode2();
17176
17275
  init_codex();
17177
17276
  init_from_events();
17277
+ init_trim();
17178
17278
  init_types();
17279
+ init_trim();
17179
17280
  init_raw();
17180
17281
  init_shadow();
17181
17282
  init_claude2();
@@ -29429,8 +29530,134 @@ var init_collector_health = __esm({
29429
29530
  }
29430
29531
  });
29431
29532
 
29533
+ // src/session-file-scan.ts
29534
+ import { open as open3 } from "node:fs/promises";
29535
+ import { statSync as statSync39 } from "node:fs";
29536
+ function sessionGroupsBytes(groups) {
29537
+ let total = 0;
29538
+ for (const g of groups) {
29539
+ for (const p of g.paths) {
29540
+ try {
29541
+ total += statSync39(p).size;
29542
+ } catch {
29543
+ }
29544
+ }
29545
+ }
29546
+ return total;
29547
+ }
29548
+ async function* readLinePieces(path, pieceBytes = SCAN_PIECE_BYTES) {
29549
+ const fh = await open3(path, "r");
29550
+ try {
29551
+ const buf = Buffer.allocUnsafe(pieceBytes);
29552
+ let carry = Buffer.alloc(0);
29553
+ for (; ; ) {
29554
+ const { bytesRead } = await fh.read(buf, 0, pieceBytes, null);
29555
+ if (bytesRead === 0) break;
29556
+ const joined = carry.length ? Buffer.concat([carry, buf.subarray(0, bytesRead)]) : buf.subarray(0, bytesRead);
29557
+ const cut = joined.lastIndexOf(NEWLINE);
29558
+ if (cut < 0) {
29559
+ carry = Buffer.from(joined);
29560
+ continue;
29561
+ }
29562
+ const piece = joined.subarray(0, cut + 1);
29563
+ carry = Buffer.from(joined.subarray(cut + 1));
29564
+ yield { text: piece.toString("utf8"), newlines: countNewlines(piece) };
29565
+ }
29566
+ if (carry.length) yield { text: carry.toString("utf8"), newlines: 0 };
29567
+ } finally {
29568
+ await fh.close();
29569
+ }
29570
+ }
29571
+ function countNewlines(b) {
29572
+ let n = 0;
29573
+ for (let i = b.indexOf(NEWLINE); i >= 0; i = b.indexOf(NEWLINE, i + 1)) n++;
29574
+ return n;
29575
+ }
29576
+ async function scanSessionGroupsChunked(sessionId, groups, tenantRules, pieceBytes = SCAN_PIECE_BYTES) {
29577
+ const findings = [];
29578
+ let lineBase = 0;
29579
+ const scan = (text) => {
29580
+ try {
29581
+ for (const x of scanTextForFindings(text)) {
29582
+ findings.push({ session_id: sessionId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
29583
+ }
29584
+ } catch {
29585
+ }
29586
+ if (tenantRules && tenantRules.length > 0) {
29587
+ try {
29588
+ for (const x of scanTenantRules(text, tenantRules)) {
29589
+ findings.push({ session_id: sessionId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
29590
+ }
29591
+ } catch {
29592
+ }
29593
+ }
29594
+ };
29595
+ for (const group of groups) {
29596
+ if (group.paths.length === 1) {
29597
+ let any = false;
29598
+ for await (const piece of readLinePieces(group.paths[0], pieceBytes)) {
29599
+ any = true;
29600
+ scan(piece.text);
29601
+ lineBase += piece.newlines;
29602
+ }
29603
+ if (any) lineBase += 1;
29604
+ } else {
29605
+ const { text } = readSessionGroupText(group);
29606
+ if (!text) continue;
29607
+ scan(text);
29608
+ lineBase += (text.match(/\n/g)?.length ?? 0) + 1;
29609
+ }
29610
+ }
29611
+ return findings;
29612
+ }
29613
+ function scanLinesChunked(sessionId, lines, tenantRules, pieceBytes = SCAN_PIECE_BYTES) {
29614
+ const findings = [];
29615
+ let lineBase = 0;
29616
+ let piece = [];
29617
+ let bytes = 0;
29618
+ const flush2 = () => {
29619
+ if (piece.length === 0) return;
29620
+ const text = piece.join("");
29621
+ try {
29622
+ for (const x of scanTextForFindings(text)) {
29623
+ findings.push({ session_id: sessionId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
29624
+ }
29625
+ } catch {
29626
+ }
29627
+ if (tenantRules && tenantRules.length > 0) {
29628
+ try {
29629
+ for (const x of scanTenantRules(text, tenantRules)) {
29630
+ findings.push({ session_id: sessionId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
29631
+ }
29632
+ } catch {
29633
+ }
29634
+ }
29635
+ lineBase += piece.length;
29636
+ piece = [];
29637
+ bytes = 0;
29638
+ };
29639
+ for (const line of lines) {
29640
+ piece.push(line);
29641
+ bytes += line.length;
29642
+ if (bytes >= pieceBytes) flush2();
29643
+ }
29644
+ flush2();
29645
+ return findings;
29646
+ }
29647
+ var SCAN_PIECE_BYTES, NEWLINE;
29648
+ var init_session_file_scan = __esm({
29649
+ "src/session-file-scan.ts"() {
29650
+ "use strict";
29651
+ init_secret_redactor();
29652
+ init_secret_scanner();
29653
+ init_live_session_scan();
29654
+ SCAN_PIECE_BYTES = 1024 * 1024;
29655
+ NEWLINE = 10;
29656
+ }
29657
+ });
29658
+
29432
29659
  // 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";
29660
+ import { createReadStream as createReadStream4, createWriteStream, openSync as openSync10, readSync as readSync9, closeSync as closeSync10, rmSync as rmSync5, statSync as statSync40 } from "node:fs";
29434
29661
  import { tmpdir as tmpdir2 } from "node:os";
29435
29662
  import { join as join46 } from "node:path";
29436
29663
  import { randomBytes } from "node:crypto";
@@ -29498,7 +29725,7 @@ async function writeArchiveFile(source, meta, redact, dir = tmpdir2()) {
29498
29725
  rmSync5(path, { force: true });
29499
29726
  throw err;
29500
29727
  }
29501
- return { path, gzSize: statSync39(path).size, size };
29728
+ return { path, gzSize: statSync40(path).size, size };
29502
29729
  }
29503
29730
  async function putPart(url, body2) {
29504
29731
  let last;
@@ -29801,7 +30028,7 @@ __export(auto_update_exports, {
29801
30028
  import { execSync as execSync2, execFileSync as execFileSync3 } from "node:child_process";
29802
30029
  import { readFileSync as readFileSync41, existsSync as existsSync43 } from "node:fs";
29803
30030
  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";
30031
+ import { writeFileSync as writeFileSync10, mkdtempSync as mkdtempSync3, rmSync as rmSync6, readdirSync as readdirSync31, statSync as statSync41, mkdirSync as mkdirSync10 } from "node:fs";
29805
30032
  import { join as join47, dirname as dirname19, sep as sep2, posix as pathPosix, win32 as pathWin32 } from "node:path";
29806
30033
  import { tmpdir as tmpdir3, homedir as homedir16 } from "node:os";
29807
30034
  import { createHash as createHash10 } from "node:crypto";
@@ -29854,7 +30081,7 @@ function sweepStaleStaging(root = tmpdir3(), now = Date.now()) {
29854
30081
  if (!MKDTEMP_SUFFIX.test(name)) continue;
29855
30082
  const dir = join47(root, name);
29856
30083
  try {
29857
- const st = statSync40(dir);
30084
+ const st = statSync41(dir);
29858
30085
  if (!st.isDirectory() || now - st.mtimeMs < COLD_MS) continue;
29859
30086
  const inside = readdirSync31(dir);
29860
30087
  if (inside.length > 1 || inside.length === 1 && inside[0] !== "chat-recall.tgz") continue;
@@ -30138,7 +30365,7 @@ __export(sync_client_exports, {
30138
30365
  syncSessions: () => syncSessions
30139
30366
  });
30140
30367
  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";
30368
+ 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
30369
  import { tmpdir as tmpdir4, hostname as hostname2 } from "node:os";
30143
30370
  import { createHash as createHash11 } from "node:crypto";
30144
30371
  import { fileURLToPath as fileURLToPath3 } from "node:url";
@@ -30615,7 +30842,7 @@ function reapStaleScanDirs(dir = tmpdir4(), maxAgeMs = 6 * 36e5, now = Date.now(
30615
30842
  if (!name.startsWith("cr-batchscan-")) continue;
30616
30843
  const p = join48(dir, name);
30617
30844
  try {
30618
- if (now - statSync41(p).mtimeMs < maxAgeMs) continue;
30845
+ if (now - statSync42(p).mtimeMs < maxAgeMs) continue;
30619
30846
  rmSync7(p, { recursive: true, force: true });
30620
30847
  reaped++;
30621
30848
  } catch {
@@ -31519,6 +31746,10 @@ function sessionFileBytes(ref) {
31519
31746
  if (!backend?.isAppendOnly?.()) return 0;
31520
31747
  return backend.fileSize?.(ref.prefixedId) ?? 0;
31521
31748
  }
31749
+ function syncTranscript(t) {
31750
+ const cut = t.payloadCap ? { messages: t.messages, subagents: t.subagents } : trimTranscriptForSync(t);
31751
+ return { messages: cut.messages, subagents: cut.subagents.map((s) => ({ ...s, filePath: "" })) };
31752
+ }
31522
31753
  function sessionBuildBytes(ref) {
31523
31754
  const main = sessionFileBytes(ref);
31524
31755
  if (main === 0) return 0;
@@ -31555,11 +31786,15 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31555
31786
  } else {
31556
31787
  try {
31557
31788
  const backend = getBackendForId(ref.prefixedId) ?? getBackend("claude");
31558
- const exp = backend.exportRawSession(ref.prefixedId);
31789
+ const streamGroups = ref.toolId === "claude" ? resolveSessionContentGroups(ref.rawId) : [];
31790
+ const streamsLines = ref.toolId !== "claude" && !!backend.rawSessionBytes && !!backend.iterateRawSessionLines;
31791
+ const streamedBytes = ref.toolId === "claude" ? sessionGroupsBytes(streamGroups) : streamsLines ? backend.rawSessionBytes(ref.prefixedId) : 0;
31792
+ const streamed = streamedBytes > FULL_BUILD_MAX_BYTES;
31793
+ const exp = streamed ? null : backend.exportRawSession(ref.prefixedId);
31559
31794
  let built;
31560
- const exportBytes = exportByteLength(exp);
31795
+ const exportBytes = streamed ? streamedBytes : exportByteLength(exp);
31561
31796
  const overCeiling = exportBytes > FULL_BUILD_MAX_BYTES;
31562
- if (exp && overCeiling) {
31797
+ if ((exp || streamed) && overCeiling) {
31563
31798
  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`);
31564
31799
  record({
31565
31800
  kind: "oversized_session",
@@ -31570,25 +31805,29 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31570
31805
  includeRaw = false;
31571
31806
  includeMeta = false;
31572
31807
  exportOverCeiling = true;
31573
- overCeilingFindings = [];
31574
- let lineBase = 0;
31575
- for (const f of exp.files) {
31576
- const text = f.bytes.toString("utf8");
31577
- try {
31578
- for (const x of scanTextForFindings(text)) {
31579
- overCeilingFindings.push({ session_id: ref.prefixedId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
31580
- }
31581
- } catch {
31582
- }
31583
- if (opts.tenantRules && opts.tenantRules.length > 0) {
31808
+ if (streamed) {
31809
+ overCeilingFindings = ref.toolId === "claude" ? await scanSessionGroupsChunked(ref.prefixedId, streamGroups, opts.tenantRules) : scanLinesChunked(ref.prefixedId, backend.iterateRawSessionLines(ref.prefixedId), opts.tenantRules);
31810
+ } else if (exp) {
31811
+ overCeilingFindings = [];
31812
+ let lineBase = 0;
31813
+ for (const f of exp.files) {
31814
+ const text = f.bytes.toString("utf8");
31584
31815
  try {
31585
- for (const x of scanTenantRules(text, opts.tenantRules)) {
31586
- overCeilingFindings.push({ session_id: ref.prefixedId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
31816
+ for (const x of scanTextForFindings(text)) {
31817
+ overCeilingFindings.push({ session_id: ref.prefixedId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
31587
31818
  }
31588
31819
  } catch {
31589
31820
  }
31821
+ if (opts.tenantRules && opts.tenantRules.length > 0) {
31822
+ try {
31823
+ for (const x of scanTenantRules(text, opts.tenantRules)) {
31824
+ overCeilingFindings.push({ session_id: ref.prefixedId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
31825
+ }
31826
+ } catch {
31827
+ }
31828
+ }
31829
+ lineBase += (text.match(/\n/g)?.length ?? 0) + 1;
31590
31830
  }
31591
- lineBase += (text.match(/\n/g)?.length ?? 0) + 1;
31592
31831
  }
31593
31832
  }
31594
31833
  if (exp && !overCeiling) {
@@ -31628,7 +31867,7 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31628
31867
  }
31629
31868
  if (!transcript) {
31630
31869
  try {
31631
- const t = await parseTranscript(ref.prefixedId);
31870
+ const t = await parseTranscript(ref.prefixedId, { payloadCap: SYNC_PAYLOAD_CAP });
31632
31871
  if (t && (t.messages.length > 0 || t.subagents.length > 0)) transcript = t;
31633
31872
  } catch {
31634
31873
  }
@@ -31641,7 +31880,9 @@ async function buildConversationSync(ref, mtime, opts = {}) {
31641
31880
  if (isInternalToolPrompt(firstUser?.content)) return null;
31642
31881
  const count = { redactions: 0 };
31643
31882
  const envelope = redactDeep(
31644
- { v: TRANSCRIPT_VERSION, ...trimTranscriptForSync(transcript) },
31883
+ // A transcript the parser already cut is not cut again: the cut is not idempotent.
31884
+ // The path of a subagent file on this machine does not leave it: the container parse gives ''.
31885
+ { v: TRANSCRIPT_VERSION, ...syncTranscript(transcript) },
31645
31886
  count
31646
31887
  );
31647
31888
  let projectPath = ref.projectPath;
@@ -32013,6 +32254,7 @@ var init_sync_client = __esm({
32013
32254
  init_telemetry();
32014
32255
  init_collector_health();
32015
32256
  init_live_session_scan();
32257
+ init_session_file_scan();
32016
32258
  init_raw_archive_parts();
32017
32259
  init_backends();
32018
32260
  ownVersion = "0.0.0";
@@ -32174,11 +32416,11 @@ var init_update_notice = __esm({
32174
32416
  });
32175
32417
 
32176
32418
  // ../engine/dist/core/which.js
32177
- import { existsSync as existsSync44, statSync as statSync42, accessSync, constants } from "node:fs";
32419
+ import { existsSync as existsSync44, statSync as statSync43, accessSync, constants } from "node:fs";
32178
32420
  import { join as join50, isAbsolute as isAbsolute3, delimiter as delimiter2, sep as sep3 } from "node:path";
32179
32421
  function executable(p) {
32180
32422
  try {
32181
- if (!statSync42(p).isFile())
32423
+ if (!statSync43(p).isFile())
32182
32424
  return false;
32183
32425
  } catch {
32184
32426
  return false;
@@ -33395,14 +33637,14 @@ var init_opencode_tui_config = __esm({
33395
33637
  return this.array(t);
33396
33638
  throw new SyntaxError(`unexpected "${t.v}" at ${t.start}`);
33397
33639
  }
33398
- object(open3) {
33640
+ object(open4) {
33399
33641
  this.i += 1;
33400
33642
  const props = [];
33401
33643
  for (; ; ) {
33402
33644
  const k = this.at();
33403
33645
  if (this.isP(k, "}")) {
33404
33646
  this.i += 1;
33405
- return { k: "obj", start: open3.start, end: k.end, closeStart: k.start, props };
33647
+ return { k: "obj", start: open4.start, end: k.end, closeStart: k.start, props };
33406
33648
  }
33407
33649
  if (!k || k.t !== "s")
33408
33650
  throw new SyntaxError(`expected a key at ${k ? k.start : "end"}`);
@@ -33421,7 +33663,7 @@ var init_opencode_tui_config = __esm({
33421
33663
  throw new SyntaxError(`expected "," or "}" at ${n ? n.start : "end"}`);
33422
33664
  }
33423
33665
  }
33424
- array(open3) {
33666
+ array(open4) {
33425
33667
  this.i += 1;
33426
33668
  const items = [];
33427
33669
  const commas = [];
@@ -33429,7 +33671,7 @@ var init_opencode_tui_config = __esm({
33429
33671
  const n = this.at();
33430
33672
  if (this.isP(n, "]")) {
33431
33673
  this.i += 1;
33432
- return { k: "arr", start: open3.start, end: n.end, closeStart: n.start, items, commas };
33674
+ return { k: "arr", start: open4.start, end: n.end, closeStart: n.start, items, commas };
33433
33675
  }
33434
33676
  items.push(this.value());
33435
33677
  const c = this.at();
@@ -34347,7 +34589,7 @@ __export(companions_exports, {
34347
34589
  uninstallCodeindex: () => uninstallCodeindex,
34348
34590
  unregisterCodeindexMcp: () => unregisterCodeindexMcp
34349
34591
  });
34350
- 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";
34592
+ 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";
34351
34593
  import { homedir as homedir21 } from "node:os";
34352
34594
  import { join as join59 } from "node:path";
34353
34595
  import { execSync as execSync3 } from "node:child_process";
@@ -34398,7 +34640,7 @@ function checkCodeindexStatus() {
34398
34640
  status.installed = true;
34399
34641
  status.path = foundPath;
34400
34642
  try {
34401
- status.size = statSync43(foundPath).size;
34643
+ status.size = statSync44(foundPath).size;
34402
34644
  } catch {
34403
34645
  }
34404
34646
  try {
@@ -34548,7 +34790,7 @@ __export(install_skills_exports, {
34548
34790
  skillsSourceDir: () => skillsSourceDir,
34549
34791
  uninstallSkills: () => uninstallSkills
34550
34792
  });
34551
- 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";
34793
+ 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";
34552
34794
  import { createHash as createHash14 } from "crypto";
34553
34795
  import { join as join60, basename as basename23 } from "path";
34554
34796
  function skillsSourceDir() {
@@ -35563,11 +35805,11 @@ __export(toolkit_pull_exports, {
35563
35805
  platformRefusal: () => platformRefusal,
35564
35806
  portableCommand: () => portableCommand
35565
35807
  });
35566
- import { existsSync as existsSync52, mkdirSync as mkdirSync18, statSync as statSync45, writeFileSync as writeFileSync20 } from "node:fs";
35808
+ import { existsSync as existsSync52, mkdirSync as mkdirSync18, statSync as statSync46, writeFileSync as writeFileSync20 } from "node:fs";
35567
35809
  import { dirname as dirname26, join as join63, basename as basename26, isAbsolute as isAbsolute4 } from "node:path";
35568
35810
  function isExecutableFile(p) {
35569
35811
  try {
35570
- return statSync45(p).isFile();
35812
+ return statSync46(p).isFile();
35571
35813
  } catch {
35572
35814
  return false;
35573
35815
  }
@@ -37976,7 +38218,7 @@ __export(project_tasks_exports, {
37976
38218
  pushProjectTaskStatuses: () => pushProjectTaskStatuses,
37977
38219
  renderTeamTasksMd: () => renderTeamTasksMd
37978
38220
  });
37979
- import { existsSync as existsSync56, readFileSync as readFileSync53, writeFileSync as writeFileSync22, mkdirSync as mkdirSync20, statSync as statSync46 } from "node:fs";
38221
+ import { existsSync as existsSync56, readFileSync as readFileSync53, writeFileSync as writeFileSync22, mkdirSync as mkdirSync20, statSync as statSync47 } from "node:fs";
37980
38222
  import { join as join67, dirname as dirname28 } from "node:path";
37981
38223
  import { homedir as homedir24 } from "node:os";
37982
38224
  function isTeamTaskStatus(v) {
@@ -37989,7 +38231,7 @@ function isValidStatus(kind, v) {
37989
38231
  return kind === "secret" ? isSecretTaskStatus(v) : kind === "team" ? isTeamTaskStatus(v) : isCodeTaskStatus(v);
37990
38232
  }
37991
38233
  function reconcile(kind, was, token, checked) {
37992
- const open3 = defaultWas(kind);
38234
+ const open4 = defaultWas(kind);
37993
38235
  const done = kind === "secret" ? "rotated" : "done";
37994
38236
  if (token && token !== was) return token;
37995
38237
  if (kind === "team") {
@@ -37997,8 +38239,8 @@ function reconcile(kind, was, token, checked) {
37997
38239
  if (!checked && was === "done") return "todo";
37998
38240
  return token ?? was;
37999
38241
  }
38000
- if (checked && was === open3) return done;
38001
- if (!checked && was !== open3) return open3;
38242
+ if (checked && was === open4) return done;
38243
+ if (!checked && was !== open4) return open4;
38002
38244
  return token ?? was;
38003
38245
  }
38004
38246
  function parseAnchorLine(line) {
@@ -38065,7 +38307,7 @@ async function pushProjectTaskStatuses(base4, authHeaders, opts = {}) {
38065
38307
  if (!existsSync56(file)) continue;
38066
38308
  let mtime;
38067
38309
  try {
38068
- mtime = statSync46(file).mtimeMs;
38310
+ mtime = statSync47(file).mtimeMs;
38069
38311
  } catch {
38070
38312
  continue;
38071
38313
  }
@@ -38578,7 +38820,7 @@ var team_merge_exports = {};
38578
38820
  __export(team_merge_exports, {
38579
38821
  mergePullResult: () => mergePullResult
38580
38822
  });
38581
- import { existsSync as existsSync58, mkdirSync as mkdirSync22, readFileSync as readFileSync55, rmSync as rmSync11, writeFileSync as writeFileSync24, statSync as statSync47 } from "fs";
38823
+ import { existsSync as existsSync58, mkdirSync as mkdirSync22, readFileSync as readFileSync55, rmSync as rmSync11, writeFileSync as writeFileSync24, statSync as statSync48 } from "fs";
38582
38824
  import { dirname as dirname30, join as join69 } from "path";
38583
38825
  import { createHash as createHash17 } from "crypto";
38584
38826
  function installPathFor(art, tool) {
@@ -38715,7 +38957,7 @@ function readFileIfExists(path) {
38715
38957
  try {
38716
38958
  if (!existsSync58(path))
38717
38959
  return null;
38718
- const s = statSync47(path);
38960
+ const s = statSync48(path);
38719
38961
  if (!s.isFile())
38720
38962
  return null;
38721
38963
  return readFileSync55(path);
@@ -38799,7 +39041,7 @@ var init_vault_crypto = __esm({
38799
39041
  });
38800
39042
 
38801
39043
  // ../engine/dist/core/vault-source.js
38802
- import { existsSync as existsSync59, readdirSync as readdirSync35, statSync as statSync48 } from "fs";
39044
+ import { existsSync as existsSync59, readdirSync as readdirSync35, statSync as statSync49 } from "fs";
38803
39045
  import { extname, join as join70 } from "path";
38804
39046
  function* walkVaultSources() {
38805
39047
  const t = loadSettings().team.vault;
@@ -38815,7 +39057,7 @@ function* walkVaultSources() {
38815
39057
  }
38816
39058
  function safeStat(path) {
38817
39059
  try {
38818
- const s = statSync48(path);
39060
+ const s = statSync49(path);
38819
39061
  if (!s.isFile())
38820
39062
  return null;
38821
39063
  return { mtimeMs: s.mtimeMs, size: s.size };
@@ -38918,7 +39160,7 @@ function* walkAgy() {
38918
39160
  for (const rawId of sessionDirs) {
38919
39161
  const sessionPath = join70(brainDir, rawId);
38920
39162
  try {
38921
- if (!statSync48(sessionPath).isDirectory())
39163
+ if (!statSync49(sessionPath).isDirectory())
38922
39164
  continue;
38923
39165
  } catch {
38924
39166
  continue;
@@ -41521,7 +41763,7 @@ program.command("feedback").argument("<message...>", "what you want to say \u201
41521
41763
  }
41522
41764
  });
41523
41765
  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) => {
41524
- const { existsSync: existsSync63, readFileSync: readFileSync60, statSync: statSync49 } = await import("fs");
41766
+ const { existsSync: existsSync63, readFileSync: readFileSync60, statSync: statSync50 } = await import("fs");
41525
41767
  const { execSync: execSync6 } = await import("child_process");
41526
41768
  const rows = [];
41527
41769
  const note = (ok, label, detail) => rows.push({ ok, label, detail });
@@ -41589,7 +41831,7 @@ program.command("doctor").description("Quick health check across login, server,
41589
41831
  note(false, "Credentials file", `missing \u2014 run \`chat-recall login <server-url>\``);
41590
41832
  } else {
41591
41833
  try {
41592
- const mode = statSync49(credFile).mode & 511;
41834
+ const mode = statSync50(credFile).mode & 511;
41593
41835
  const isWin = process.platform === "win32";
41594
41836
  const safe = isWin || (mode & 63) === 0;
41595
41837
  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"})`);