chat-recall 0.7.67 → 0.7.69

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
@@ -12967,6 +12967,25 @@ var init_session = __esm({
12967
12967
  function detach(s) {
12968
12968
  return JSON.parse(JSON.stringify(s));
12969
12969
  }
12970
+ function payloadLength(v) {
12971
+ if (v === void 0 || v === null)
12972
+ return 0;
12973
+ if (typeof v === "string")
12974
+ return v.length;
12975
+ try {
12976
+ return JSON.stringify(v)?.length ?? 0;
12977
+ } catch {
12978
+ return 0;
12979
+ }
12980
+ }
12981
+ function budgetedCut(capChars, budgetChars = SYNC_PAYLOAD_BUDGET, tightChars = SYNC_PAYLOAD_CAP_TIGHT) {
12982
+ let kept = 0;
12983
+ return (v) => {
12984
+ const out = capPayload(v, kept >= budgetChars ? Math.min(tightChars, capChars) : capChars);
12985
+ kept += payloadLength(out);
12986
+ return out;
12987
+ };
12988
+ }
12970
12989
  function capPayload(v, capChars = SYNC_PAYLOAD_CAP) {
12971
12990
  if (v === void 0)
12972
12991
  return void 0;
@@ -12991,10 +13010,12 @@ function capPayload(v, capChars = SYNC_PAYLOAD_CAP) {
12991
13010
  }
12992
13011
  return v;
12993
13012
  }
12994
- var SYNC_PAYLOAD_CAP;
13013
+ var SYNC_PAYLOAD_BUDGET, SYNC_PAYLOAD_CAP_TIGHT, SYNC_PAYLOAD_CAP;
12995
13014
  var init_trim = __esm({
12996
13015
  "../engine/dist/transcript/trim.js"() {
12997
13016
  "use strict";
13017
+ SYNC_PAYLOAD_BUDGET = 48 * 1024 * 1024;
13018
+ SYNC_PAYLOAD_CAP_TIGHT = 200;
12998
13019
  SYNC_PAYLOAD_CAP = 2e3;
12999
13020
  }
13000
13021
  });
@@ -13009,7 +13030,7 @@ function stripBanners2(text) {
13009
13030
  return out.replace(/[ \t]{2,}/g, " ").trim();
13010
13031
  }
13011
13032
  function parseClaudeTranscriptText(text, opts = {}) {
13012
- const builder = new MessageBuilder(opts.payloadCap);
13033
+ const builder = new MessageBuilder(opts.payloadCap, opts.cut);
13013
13034
  let lineNumber = 0;
13014
13035
  for (const line of text.split("\n")) {
13015
13036
  lineNumber++;
@@ -13027,7 +13048,7 @@ function parseClaudeTranscriptText(text, opts = {}) {
13027
13048
  }
13028
13049
  async function parseMessagesFromFile(sessionPath, opts) {
13029
13050
  const file = await open(sessionPath);
13030
- const builder = new MessageBuilder(opts.payloadCap);
13051
+ const builder = new MessageBuilder(opts.payloadCap, opts.cut);
13031
13052
  try {
13032
13053
  let lineNumber = 0;
13033
13054
  for await (const line of file.readLines()) {
@@ -13132,8 +13153,8 @@ var init_claude2 = __esm({
13132
13153
  calls = /* @__PURE__ */ new Map();
13133
13154
  /** The last result of each tool_use id. */
13134
13155
  results = /* @__PURE__ */ new Map();
13135
- constructor(payloadCap) {
13136
- this.cap = payloadCap ? (v) => capPayload(v, payloadCap) : (v) => v;
13156
+ constructor(payloadCap, cut) {
13157
+ this.cap = cut ?? (payloadCap ? (v) => capPayload(v, payloadCap) : (v) => v);
13137
13158
  }
13138
13159
  add(line, obj2) {
13139
13160
  if (!obj2 || typeof obj2 !== "object")
@@ -13346,7 +13367,7 @@ function parseCodexTranscriptText(text, opts = {}) {
13346
13367
  return messages;
13347
13368
  }
13348
13369
  function codexLineHandler(messages, opts) {
13349
- const cap = opts.payloadCap ? (v) => capPayload(v, opts.payloadCap) : (v) => v;
13370
+ const cap = opts.cut ?? (opts.payloadCap ? (v) => capPayload(v, opts.payloadCap) : (v) => v);
13350
13371
  return (lineNum, line) => {
13351
13372
  if (!line.trim())
13352
13373
  return;
@@ -14463,7 +14484,7 @@ async function parseOpenCodeTranscript(sessionId, opts = {}) {
14463
14484
  WHERE p.session_id = ?
14464
14485
  ORDER BY p.time_created ASC
14465
14486
  `).iterate(realId, realId);
14466
- const cap = opts.payloadCap ? (v) => capPayload(v, opts.payloadCap) : (v) => v;
14487
+ const cap = opts.cut ?? (opts.payloadCap ? (v) => capPayload(v, opts.payloadCap) : (v) => v);
14467
14488
  let lastMsgData = "";
14468
14489
  let lastRole = "assistant";
14469
14490
  let lineNum = 0;
@@ -14526,7 +14547,7 @@ async function parseTranscriptUncut(sessionId, opts) {
14526
14547
  return null;
14527
14548
  const primaryPath = mainGroup.paths[0];
14528
14549
  const merged = readSessionGroupText(mainGroup);
14529
- const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
14550
+ const cut = opts.payloadCap ? { payloadCap: opts.payloadCap, cut: budgetedCut(opts.payloadCap, opts.payloadBudget) } : {};
14530
14551
  const [tail, allSubagents] = await Promise.all([
14531
14552
  Promise.resolve(parseClaudeTranscriptText(merged.text, cut)),
14532
14553
  parseClaudeSubagents(primaryPath, cut)
@@ -14549,7 +14570,7 @@ async function parseTranscriptUncut(sessionId, opts) {
14549
14570
  return { messages, subagents, mtime: merged.mtime || safeMtime(primaryPath), ...opts.payloadCap ? { payloadCap: opts.payloadCap } : {} };
14550
14571
  }
14551
14572
  if (tool === "opencode") {
14552
- const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
14573
+ const cut = opts.payloadCap ? { payloadCap: opts.payloadCap, cut: budgetedCut(opts.payloadCap, opts.payloadBudget) } : {};
14553
14574
  const messages = await parseOpenCodeTranscript(sessionId, cut);
14554
14575
  if (messages.length === 0)
14555
14576
  return null;
@@ -14561,7 +14582,7 @@ async function parseTranscriptUncut(sessionId, opts) {
14561
14582
  const loc = getBackend("codex").findSession(sessionId);
14562
14583
  if (!loc)
14563
14584
  return null;
14564
- const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
14585
+ const cut = opts.payloadCap ? { payloadCap: opts.payloadCap, cut: budgetedCut(opts.payloadCap, opts.payloadBudget) } : {};
14565
14586
  const [messages, subagents] = await Promise.all([
14566
14587
  parseCodexTranscript(loc.path, cut),
14567
14588
  parseCodexSubagents(loc.path, cut)
@@ -17651,6 +17672,9 @@ function walkSessionLimit(env = process.env) {
17651
17672
  if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0) return DEFAULT_WALK_MAX_SESSIONS;
17652
17673
  return n;
17653
17674
  }
17675
+ function hasAckedMtime(row) {
17676
+ return typeof row?.m === "number" && row.m > 0;
17677
+ }
17654
17678
  function orderRefsForWalk(refs, isAcked) {
17655
17679
  const fresh = [];
17656
17680
  const acked = [];
@@ -31987,7 +32011,7 @@ async function syncToTargetInScope(cred, opts = {}) {
31987
32011
  };
31988
32012
  let scanMs = 0, scanned = 0;
31989
32013
  const walkMax = opts.limit ?? walkSessionLimit();
31990
- const ordered = walkMax > 0 ? orderRefsForWalk(refs, (id) => Boolean(ledger?.get(id))) : refs;
32014
+ const ordered = walkMax > 0 ? orderRefsForWalk(refs, (id) => hasAckedMtime(ledger?.get(id))) : refs;
31991
32015
  const slice = walkMax > 0 ? ordered.slice(0, walkMax) : ordered;
31992
32016
  const unackedCount = walkMax > 0 ? refs.reduce((n, r) => n + (ledger?.get(r.prefixedId) ? 0 : 1), 0) : refs.length;
31993
32017
  const trace = process.env.CHAT_RECALL_SYNC_TRACE === "1" ? (msg) => {
@@ -5353,9 +5353,11 @@ var init_claude_prompt_origin = __esm({
5353
5353
  });
5354
5354
 
5355
5355
  // ../engine/dist/transcript/trim.js
5356
+ var SYNC_PAYLOAD_BUDGET;
5356
5357
  var init_trim = __esm({
5357
5358
  "../engine/dist/transcript/trim.js"() {
5358
5359
  "use strict";
5360
+ SYNC_PAYLOAD_BUDGET = 48 * 1024 * 1024;
5359
5361
  }
5360
5362
  });
5361
5363
 
@@ -47,7 +47,7 @@ import { isInternalToolPrompt } from '@chat-recall/engine/core/internal-prompts.
47
47
  import { dropFuzzyFindings } from '@chat-recall/engine/core/secret-precision.js';
48
48
  import { loadSettings, saveSettings, isProjectSyncable } from '@chat-recall/engine/core/settings.js';
49
49
  import { getDataDir } from '@chat-recall/engine/core/paths.js';
50
- import { walkSessionLimit, orderRefsForWalk, mayTombstone } from './walk-budget.js';
50
+ import { walkSessionLimit, orderRefsForWalk, hasAckedMtime, mayTombstone } from './walk-budget.js';
51
51
  import { tombstoneMode, planTombstones, describeTombstonePlan } from './tombstone-rule.js';
52
52
  import { probeSessionSource } from './session-source-probe.js';
53
53
  import { reconcileLedgerIfDue } from './ledger-reconcile.js';
@@ -1767,7 +1767,7 @@ async function syncToTargetInScope(cred, opts = {}) {
1767
1767
  // unbounded pass that a restart repeats from the first session. An explicit
1768
1768
  // `opts.limit` from the caller still wins.
1769
1769
  const walkMax = opts.limit ?? walkSessionLimit();
1770
- const ordered = walkMax > 0 ? orderRefsForWalk(refs, (id) => Boolean(ledger?.get(id))) : refs;
1770
+ const ordered = walkMax > 0 ? orderRefsForWalk(refs, (id) => hasAckedMtime(ledger?.get(id))) : refs;
1771
1771
  const slice = walkMax > 0 ? ordered.slice(0, walkMax) : ordered;
1772
1772
  // Sessions the ledger has not acknowledged come first, so a walk is complete when its slice
1773
1773
  // holds all of them and it did not pause: the acknowledged ones behind them are checked by the