chat-recall 0.7.68 → 0.7.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/watch.js CHANGED
@@ -6307,6 +6307,25 @@ var init_session = __esm({
6307
6307
  function detach(s) {
6308
6308
  return JSON.parse(JSON.stringify(s));
6309
6309
  }
6310
+ function payloadLength(v) {
6311
+ if (v === void 0 || v === null)
6312
+ return 0;
6313
+ if (typeof v === "string")
6314
+ return v.length;
6315
+ try {
6316
+ return JSON.stringify(v)?.length ?? 0;
6317
+ } catch {
6318
+ return 0;
6319
+ }
6320
+ }
6321
+ function budgetedCut(capChars, budgetChars = SYNC_PAYLOAD_BUDGET, tightChars = SYNC_PAYLOAD_CAP_TIGHT) {
6322
+ let kept = 0;
6323
+ return (v) => {
6324
+ const out = capPayload(v, kept >= budgetChars ? Math.min(tightChars, capChars) : capChars);
6325
+ kept += payloadLength(out);
6326
+ return out;
6327
+ };
6328
+ }
6310
6329
  function capPayload(v, capChars = SYNC_PAYLOAD_CAP) {
6311
6330
  if (v === void 0)
6312
6331
  return void 0;
@@ -6331,10 +6350,12 @@ function capPayload(v, capChars = SYNC_PAYLOAD_CAP) {
6331
6350
  }
6332
6351
  return v;
6333
6352
  }
6334
- var SYNC_PAYLOAD_CAP;
6353
+ var SYNC_PAYLOAD_BUDGET, SYNC_PAYLOAD_CAP_TIGHT, SYNC_PAYLOAD_CAP;
6335
6354
  var init_trim = __esm({
6336
6355
  "../engine/dist/transcript/trim.js"() {
6337
6356
  "use strict";
6357
+ SYNC_PAYLOAD_BUDGET = 48 * 1024 * 1024;
6358
+ SYNC_PAYLOAD_CAP_TIGHT = 200;
6338
6359
  SYNC_PAYLOAD_CAP = 2e3;
6339
6360
  }
6340
6361
  });
@@ -6352,7 +6373,7 @@ async function parseClaudeTranscript(sessionPath, opts = {}) {
6352
6373
  return parseMessagesFromFile(sessionPath, opts);
6353
6374
  }
6354
6375
  function parseClaudeTranscriptText(text, opts = {}) {
6355
- const builder = new MessageBuilder(opts.payloadCap);
6376
+ const builder = new MessageBuilder(opts.payloadCap, opts.cut);
6356
6377
  let lineNumber = 0;
6357
6378
  for (const line of text.split("\n")) {
6358
6379
  lineNumber++;
@@ -6370,7 +6391,7 @@ function parseClaudeTranscriptText(text, opts = {}) {
6370
6391
  }
6371
6392
  async function parseMessagesFromFile(sessionPath, opts) {
6372
6393
  const file = await open(sessionPath);
6373
- const builder = new MessageBuilder(opts.payloadCap);
6394
+ const builder = new MessageBuilder(opts.payloadCap, opts.cut);
6374
6395
  try {
6375
6396
  let lineNumber = 0;
6376
6397
  for await (const line of file.readLines()) {
@@ -6475,8 +6496,8 @@ var init_claude = __esm({
6475
6496
  calls = /* @__PURE__ */ new Map();
6476
6497
  /** The last result of each tool_use id. */
6477
6498
  results = /* @__PURE__ */ new Map();
6478
- constructor(payloadCap) {
6479
- this.cap = payloadCap ? (v) => capPayload(v, payloadCap) : (v) => v;
6499
+ constructor(payloadCap, cut) {
6500
+ this.cap = cut ?? (payloadCap ? (v) => capPayload(v, payloadCap) : (v) => v);
6480
6501
  }
6481
6502
  add(line, obj) {
6482
6503
  if (!obj || typeof obj !== "object")
@@ -6689,7 +6710,7 @@ function parseCodexTranscriptText(text, opts = {}) {
6689
6710
  return messages;
6690
6711
  }
6691
6712
  function codexLineHandler(messages, opts) {
6692
- const cap = opts.payloadCap ? (v) => capPayload(v, opts.payloadCap) : (v) => v;
6713
+ const cap = opts.cut ?? (opts.payloadCap ? (v) => capPayload(v, opts.payloadCap) : (v) => v);
6693
6714
  return (lineNum, line) => {
6694
6715
  if (!line.trim())
6695
6716
  return;
@@ -15441,6 +15462,9 @@ function walkSessionLimit(env = process.env) {
15441
15462
  if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0) return DEFAULT_WALK_MAX_SESSIONS;
15442
15463
  return n;
15443
15464
  }
15465
+ function hasAckedMtime(row) {
15466
+ return typeof row?.m === "number" && row.m > 0;
15467
+ }
15444
15468
  function orderRefsForWalk(refs, isAcked) {
15445
15469
  const fresh = [];
15446
15470
  const acked = [];
@@ -16168,7 +16192,7 @@ async function parseOpenCodeTranscript(sessionId, opts = {}) {
16168
16192
  WHERE p.session_id = ?
16169
16193
  ORDER BY p.time_created ASC
16170
16194
  `).iterate(realId, realId);
16171
- const cap = opts.payloadCap ? (v) => capPayload(v, opts.payloadCap) : (v) => v;
16195
+ const cap = opts.cut ?? (opts.payloadCap ? (v) => capPayload(v, opts.payloadCap) : (v) => v);
16172
16196
  let lastMsgData = "";
16173
16197
  let lastRole = "assistant";
16174
16198
  let lineNum = 0;
@@ -16215,9 +16239,12 @@ var init_opencode2 = __esm({
16215
16239
  var transcript_exports = {};
16216
16240
  __export(transcript_exports, {
16217
16241
  RAW_PARSE_MAX_BYTES: () => RAW_PARSE_MAX_BYTES,
16242
+ SYNC_PAYLOAD_BUDGET: () => SYNC_PAYLOAD_BUDGET,
16218
16243
  SYNC_PAYLOAD_CAP: () => SYNC_PAYLOAD_CAP,
16244
+ SYNC_PAYLOAD_CAP_TIGHT: () => SYNC_PAYLOAD_CAP_TIGHT,
16219
16245
  TRANSCRIPT_VERSION: () => TRANSCRIPT_VERSION,
16220
16246
  archiveRawSession: () => archiveRawSession,
16247
+ budgetedCut: () => budgetedCut,
16221
16248
  buildRawContainer: () => buildRawContainer,
16222
16249
  canonicalEventsToMessages: () => canonicalEventsToMessages,
16223
16250
  capPayload: () => capPayload,
@@ -16273,7 +16300,7 @@ async function parseTranscriptUncut(sessionId, opts) {
16273
16300
  return null;
16274
16301
  const primaryPath = mainGroup.paths[0];
16275
16302
  const merged = readSessionGroupText(mainGroup);
16276
- const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
16303
+ const cut = opts.payloadCap ? { payloadCap: opts.payloadCap, cut: budgetedCut(opts.payloadCap, opts.payloadBudget) } : {};
16277
16304
  const [tail, allSubagents] = await Promise.all([
16278
16305
  Promise.resolve(parseClaudeTranscriptText(merged.text, cut)),
16279
16306
  parseClaudeSubagents(primaryPath, cut)
@@ -16296,7 +16323,7 @@ async function parseTranscriptUncut(sessionId, opts) {
16296
16323
  return { messages, subagents, mtime: merged.mtime || safeMtime(primaryPath), ...opts.payloadCap ? { payloadCap: opts.payloadCap } : {} };
16297
16324
  }
16298
16325
  if (tool === "opencode") {
16299
- const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
16326
+ const cut = opts.payloadCap ? { payloadCap: opts.payloadCap, cut: budgetedCut(opts.payloadCap, opts.payloadBudget) } : {};
16300
16327
  const messages = await parseOpenCodeTranscript(sessionId, cut);
16301
16328
  if (messages.length === 0)
16302
16329
  return null;
@@ -16308,7 +16335,7 @@ async function parseTranscriptUncut(sessionId, opts) {
16308
16335
  const loc = getBackend("codex").findSession(sessionId);
16309
16336
  if (!loc)
16310
16337
  return null;
16311
- const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
16338
+ const cut = opts.payloadCap ? { payloadCap: opts.payloadCap, cut: budgetedCut(opts.payloadCap, opts.payloadBudget) } : {};
16312
16339
  const [messages, subagents] = await Promise.all([
16313
16340
  parseCodexTranscript(loc.path, cut),
16314
16341
  parseCodexSubagents(loc.path, cut)
@@ -30470,7 +30497,7 @@ async function syncToTargetInScope(cred, opts = {}) {
30470
30497
  };
30471
30498
  let scanMs = 0, scanned = 0;
30472
30499
  const walkMax = opts.limit ?? walkSessionLimit();
30473
- const ordered = walkMax > 0 ? orderRefsForWalk(refs, (id) => Boolean(ledger?.get(id))) : refs;
30500
+ const ordered = walkMax > 0 ? orderRefsForWalk(refs, (id) => hasAckedMtime(ledger?.get(id))) : refs;
30474
30501
  const slice = walkMax > 0 ? ordered.slice(0, walkMax) : ordered;
30475
30502
  const unackedCount = walkMax > 0 ? refs.reduce((n, r) => n + (ledger?.get(r.prefixedId) ? 0 : 1), 0) : refs.length;
30476
30503
  const trace = process.env.CHAT_RECALL_SYNC_TRACE === "1" ? (msg) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chat-recall",
3
- "version": "0.7.68",
3
+ "version": "0.7.70",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/munhq/chat-recall.git"