acp-kernel 0.0.58-pr.218.71 → 0.0.59-pr.219.73

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/index.js CHANGED
@@ -1652,10 +1652,6 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
1652
1652
  }
1653
1653
 
1654
1654
  // src/recommend.ts
1655
- function refNum(ref) {
1656
- const n = parseInt(ref.slice(1), 10);
1657
- return Number.isNaN(n) ? -1 : n;
1658
- }
1659
1655
  function estimateTextTokens(text) {
1660
1656
  return Math.ceil(text.length / 4);
1661
1657
  }
@@ -1708,42 +1704,50 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
1708
1704
  const compressibleMsgs = [];
1709
1705
  const protectedMsgs = [];
1710
1706
  const protectedCallIds = collectProtectedToolCallIds(messages, config);
1707
+ let skipSinceCompressible = false;
1708
+ let skipSinceProtected = false;
1711
1709
  for (const msg of messages) {
1712
- if (isSyntheticOrPruned(msg, state)) continue;
1713
1710
  const ref = state.messageRefs.byRaw[msg.id];
1714
1711
  if (!ref || ref === "BLOCKED") continue;
1715
- const rn = refNum(ref);
1712
+ if (isSyntheticOrPruned(msg, state)) {
1713
+ skipSinceCompressible = true;
1714
+ skipSinceProtected = true;
1715
+ continue;
1716
+ }
1716
1717
  if (isMessageProtectedWithPairing(msg, config, protectedCallIds)) {
1717
1718
  protectedMsgs.push({
1718
1719
  ref,
1719
- refNum: rn,
1720
+ gapBefore: skipSinceProtected,
1720
1721
  tokens: countTokens(msg.text ?? ""),
1721
1722
  tools: msg.toolName ? [msg.toolName] : []
1722
1723
  });
1724
+ skipSinceProtected = false;
1725
+ skipSinceCompressible = true;
1723
1726
  continue;
1724
1727
  }
1725
1728
  if (protectedZoneRefs?.has(ref)) {
1729
+ skipSinceCompressible = true;
1730
+ skipSinceProtected = true;
1726
1731
  continue;
1727
1732
  }
1728
1733
  compressibleMsgs.push({
1729
1734
  ref,
1730
- refNum: rn,
1735
+ gapBefore: skipSinceCompressible,
1731
1736
  tokens: countTokens(msg.text ?? ""),
1732
1737
  chars: (msg.text ?? "").length,
1733
1738
  isTool: isToolMessage(msg),
1734
1739
  isUser: msg.role === "user"
1735
1740
  });
1741
+ skipSinceCompressible = false;
1742
+ skipSinceProtected = true;
1736
1743
  }
1737
1744
  const compressible = [];
1738
1745
  let cur = null;
1739
- let prevRefNum = -2;
1740
1746
  for (const info of compressibleMsgs) {
1741
- const hasGap = info.refNum > prevRefNum + 1;
1742
- if (cur && (info.isUser && cur.count >= 3 || hasGap)) {
1747
+ if (cur && (info.isUser && cur.count >= 3 || info.gapBefore)) {
1743
1748
  compressible.push(cur);
1744
1749
  cur = null;
1745
1750
  }
1746
- prevRefNum = info.refNum;
1747
1751
  if (!cur) {
1748
1752
  cur = {
1749
1753
  startRef: info.ref,
@@ -1770,14 +1774,11 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
1770
1774
  if (cur) compressible.push(cur);
1771
1775
  const protectedRanges = [];
1772
1776
  let pcur = null;
1773
- let pPrevRefNum = -2;
1774
1777
  for (const info of protectedMsgs) {
1775
- const hasGap = info.refNum > pPrevRefNum + 1;
1776
- if (pcur && hasGap) {
1778
+ if (pcur && info.gapBefore) {
1777
1779
  protectedRanges.push(pcur);
1778
1780
  pcur = null;
1779
1781
  }
1780
- pPrevRefNum = info.refNum;
1781
1782
  if (!pcur) {
1782
1783
  pcur = {
1783
1784
  startRef: info.ref,
@@ -3047,7 +3048,7 @@ function renderUncompressedRanges(visible) {
3047
3048
  lines.push(" (no uncompressed messages)");
3048
3049
  return lines.join("\n");
3049
3050
  }
3050
- const refNum2 = (ref) => {
3051
+ const refNum = (ref) => {
3051
3052
  const m = ref.match(/\d+/);
3052
3053
  return m ? parseInt(m[0], 10) : 0;
3053
3054
  };
@@ -3064,7 +3065,7 @@ function renderUncompressedRanges(visible) {
3064
3065
  };
3065
3066
  const merged = [];
3066
3067
  for (const m of visible) {
3067
- const num = refNum2(m.ref);
3068
+ const num = refNum(m.ref);
3068
3069
  const last = merged[merged.length - 1];
3069
3070
  if (last && num === last.startNum + last.count) {
3070
3071
  last.endRef = m.ref;
@@ -3262,6 +3263,23 @@ function parseStringInput(raw, callId, diag) {
3262
3263
  diag.rawPrefix = raw.slice(0, 800);
3263
3264
  diag.length = raw.length;
3264
3265
  const cleaned = stripFence(raw.trim());
3266
+ const first = parseStringCore(cleaned, callId, diag);
3267
+ if (first.ranges.length === 0 || first.diagnostics.invalidItems > 0) {
3268
+ const normalized = normalizeSingleQuotes(cleaned);
3269
+ if (normalized !== void 0) {
3270
+ const retryDiag = { ok: false, kind: "ok", invalidItems: 0 };
3271
+ retryDiag.rawPrefix = diag.rawPrefix;
3272
+ retryDiag.length = diag.length;
3273
+ const retry = parseStringCore(normalized, callId, retryDiag);
3274
+ if (retry.ranges.length > first.ranges.length) {
3275
+ retryDiag.quoteSalvage = true;
3276
+ return retry;
3277
+ }
3278
+ }
3279
+ }
3280
+ return first;
3281
+ }
3282
+ function parseStringCore(cleaned, callId, diag) {
3265
3283
  if (cleaned === "") {
3266
3284
  diag.kind = "empty-input";
3267
3285
  return finish([], diag);
@@ -3305,6 +3323,7 @@ function parseObjectValue(value, callId, diag) {
3305
3323
  }
3306
3324
  entries = parsed.entries;
3307
3325
  salvaged = parsed.salvaged;
3326
+ if (parsed.quoteRepaired) diag.quoteSalvage = true;
3308
3327
  } else {
3309
3328
  diag.kind = "content-not-array";
3310
3329
  return finish([], diag);
@@ -3326,7 +3345,17 @@ function parseObjectValue(value, callId, diag) {
3326
3345
  }
3327
3346
  function parseContentArray(s) {
3328
3347
  const cleaned = stripFence(s.trim());
3329
- let value = cleaned === "" ? void 0 : tryParseLenient(cleaned);
3348
+ const direct = parseContentArrayCore(cleaned);
3349
+ if (direct !== null && direct.entries.length > 0) return direct;
3350
+ const normalized = normalizeSingleQuotes(cleaned);
3351
+ if (normalized !== void 0) {
3352
+ const retry = parseContentArrayCore(normalized);
3353
+ if (retry !== null && retry.entries.length > 0) return { ...retry, quoteRepaired: true };
3354
+ }
3355
+ return direct;
3356
+ }
3357
+ function parseContentArrayCore(s) {
3358
+ let value = s === "" ? void 0 : tryParseLenient(s);
3330
3359
  if (typeof value === "string") {
3331
3360
  value = tryParseLenient(stripFence(value));
3332
3361
  }
@@ -3334,7 +3363,7 @@ function parseContentArray(s) {
3334
3363
  return { entries: value, salvaged: false };
3335
3364
  }
3336
3365
  if (value === void 0) {
3337
- const entries = salvageContentEntries('{"content": ' + cleaned);
3366
+ const entries = salvageContentEntries('{"content": ' + s);
3338
3367
  return { entries, salvaged: entries.length > 0 };
3339
3368
  }
3340
3369
  return null;
@@ -3407,6 +3436,71 @@ function tryParseLenient(s) {
3407
3436
  }
3408
3437
  return void 0;
3409
3438
  }
3439
+ function normalizeSingleQuotes(raw) {
3440
+ if (!raw.includes("'") || !raw.includes("{") && !raw.includes("[")) return void 0;
3441
+ let out = "";
3442
+ let changed = false;
3443
+ let inDouble = false;
3444
+ let inSingle = false;
3445
+ for (let i = 0; i < raw.length; i++) {
3446
+ const ch = raw.charAt(i);
3447
+ if (inDouble) {
3448
+ out += ch;
3449
+ if (ch === "\\" && i + 1 < raw.length) {
3450
+ out += raw.charAt(i + 1);
3451
+ i++;
3452
+ } else if (ch === '"') {
3453
+ inDouble = false;
3454
+ }
3455
+ continue;
3456
+ }
3457
+ if (inSingle) {
3458
+ if (ch === "\\" && i + 1 < raw.length) {
3459
+ const next = raw.charAt(i + 1);
3460
+ out += next === "'" ? "'" : "\\" + next;
3461
+ i++;
3462
+ continue;
3463
+ }
3464
+ if (ch === "'") {
3465
+ out += '"';
3466
+ inSingle = false;
3467
+ changed = true;
3468
+ continue;
3469
+ }
3470
+ if (ch === '"') {
3471
+ out += '\\"';
3472
+ continue;
3473
+ }
3474
+ if (ch === "\n") {
3475
+ out += "\\n";
3476
+ continue;
3477
+ }
3478
+ if (ch === "\r") {
3479
+ out += "\\r";
3480
+ continue;
3481
+ }
3482
+ if (ch === " ") {
3483
+ out += "\\t";
3484
+ continue;
3485
+ }
3486
+ out += ch;
3487
+ continue;
3488
+ }
3489
+ if (ch === '"') {
3490
+ inDouble = true;
3491
+ out += ch;
3492
+ continue;
3493
+ }
3494
+ if (ch === "'") {
3495
+ inSingle = true;
3496
+ out += '"';
3497
+ changed = true;
3498
+ continue;
3499
+ }
3500
+ out += ch;
3501
+ }
3502
+ return changed ? out : void 0;
3503
+ }
3410
3504
  function stripFence(s) {
3411
3505
  if (!s.startsWith("```")) return s;
3412
3506
  const firstNewline = s.indexOf("\n");