acp-kernel 0.0.55-pr.208.59 → 0.0.55

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
@@ -1648,6 +1648,10 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
1648
1648
  }
1649
1649
 
1650
1650
  // src/recommend.ts
1651
+ function refNum(ref) {
1652
+ const n = parseInt(ref.slice(1), 10);
1653
+ return Number.isNaN(n) ? -1 : n;
1654
+ }
1651
1655
  function estimateTextTokens(text) {
1652
1656
  return Math.ceil(text.length / 4);
1653
1657
  }
@@ -1700,53 +1704,42 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
1700
1704
  const compressibleMsgs = [];
1701
1705
  const protectedMsgs = [];
1702
1706
  const protectedCallIds = collectProtectedToolCallIds(messages, config);
1703
- let pendingGapC = false;
1704
- let pendingGapP = false;
1705
1707
  for (const msg of messages) {
1708
+ if (isSyntheticOrPruned(msg, state)) continue;
1706
1709
  const ref = state.messageRefs.byRaw[msg.id];
1707
- if (isSyntheticOrPruned(msg, state)) {
1708
- if (ref && ref !== "BLOCKED") {
1709
- pendingGapC = true;
1710
- pendingGapP = true;
1711
- }
1712
- continue;
1713
- }
1714
1710
  if (!ref || ref === "BLOCKED") continue;
1711
+ const rn = refNum(ref);
1715
1712
  if (isMessageProtectedWithPairing(msg, config, protectedCallIds)) {
1716
1713
  protectedMsgs.push({
1717
1714
  ref,
1718
- gapBefore: pendingGapP,
1715
+ refNum: rn,
1719
1716
  tokens: countTokens(msg.text ?? ""),
1720
1717
  tools: msg.toolName ? [msg.toolName] : []
1721
1718
  });
1722
- pendingGapC = true;
1723
- pendingGapP = false;
1724
1719
  continue;
1725
1720
  }
1726
1721
  if (protectedZoneRefs?.has(ref)) {
1727
- pendingGapC = true;
1728
- pendingGapP = true;
1729
1722
  continue;
1730
1723
  }
1731
1724
  compressibleMsgs.push({
1732
1725
  ref,
1733
- gapBefore: pendingGapC,
1726
+ refNum: rn,
1734
1727
  tokens: countTokens(msg.text ?? ""),
1735
1728
  chars: (msg.text ?? "").length,
1736
1729
  isTool: isToolMessage(msg),
1737
1730
  isUser: msg.role === "user"
1738
1731
  });
1739
- pendingGapC = false;
1740
- pendingGapP = true;
1741
1732
  }
1742
1733
  const compressible = [];
1743
1734
  let cur = null;
1735
+ let prevRefNum = -2;
1744
1736
  for (const info of compressibleMsgs) {
1745
- const hasGap = info.gapBefore;
1737
+ const hasGap = info.refNum > prevRefNum + 1;
1746
1738
  if (cur && (info.isUser && cur.count >= 3 || hasGap)) {
1747
1739
  compressible.push(cur);
1748
1740
  cur = null;
1749
1741
  }
1742
+ prevRefNum = info.refNum;
1750
1743
  if (!cur) {
1751
1744
  cur = {
1752
1745
  startRef: info.ref,
@@ -1773,12 +1766,14 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
1773
1766
  if (cur) compressible.push(cur);
1774
1767
  const protectedRanges = [];
1775
1768
  let pcur = null;
1769
+ let pPrevRefNum = -2;
1776
1770
  for (const info of protectedMsgs) {
1777
- const hasGap = info.gapBefore;
1771
+ const hasGap = info.refNum > pPrevRefNum + 1;
1778
1772
  if (pcur && hasGap) {
1779
1773
  protectedRanges.push(pcur);
1780
1774
  pcur = null;
1781
1775
  }
1776
+ pPrevRefNum = info.refNum;
1782
1777
  if (!pcur) {
1783
1778
  pcur = {
1784
1779
  startRef: info.ref,
@@ -3048,7 +3043,7 @@ function renderUncompressedRanges(visible) {
3048
3043
  lines.push(" (no uncompressed messages)");
3049
3044
  return lines.join("\n");
3050
3045
  }
3051
- const refNum = (ref) => {
3046
+ const refNum2 = (ref) => {
3052
3047
  const m = ref.match(/\d+/);
3053
3048
  return m ? parseInt(m[0], 10) : 0;
3054
3049
  };
@@ -3065,7 +3060,7 @@ function renderUncompressedRanges(visible) {
3065
3060
  };
3066
3061
  const merged = [];
3067
3062
  for (const m of visible) {
3068
- const num = refNum(m.ref);
3063
+ const num = refNum2(m.ref);
3069
3064
  const last = merged[merged.length - 1];
3070
3065
  if (last && num === last.startNum + last.count) {
3071
3066
  last.endRef = m.ref;