acp-kernel 0.0.55-pr.206.58 → 0.0.55-pr.209.60

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