acp-kernel 0.0.62 → 0.0.63-pr.229.94

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.
@@ -1 +1 @@
1
- {"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkC,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAehF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AASvD,OAAO,EAGL,KAAK,YAAY,EAElB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAEhB,MAAM,EAEN,WAAW,EAGX,iBAAiB,EAEjB,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,KAAK;IACpB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACxC;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;IACxD,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,sBAAsB,CAAC;IACvE,YAAY,IAAI,YAAY,EAAE,CAAC;IAC/B,UAAU,CACR,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,gBAAgB,GACtB,gBAAgB,GAAG,SAAS,CAAC;IAChC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,EAAE,CAAC;IACnE,MAAM,CACJ,KAAK,EAAE,gBAAgB,EACvB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,YAAY,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;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C/B,UAAU,CACR,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,gBAAgB,GACtB,gBAAgB,GAAG,SAAS,CAAC;IAChC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,EAAE,CAAC;IACnE,MAAM,CACJ,KAAK,EAAE,gBAAgB,EACvB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,YAAY,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,EAAE,CAAC;IACJ,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACnC;AA2DD,wBAAgB,UAAU,CAAC,KAAK,GAAE,KAAU,GAAG,eAAe,CAyU7D;AAwgCD,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -1687,8 +1687,12 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
1687
1687
  j++;
1688
1688
  }
1689
1689
  const companion = messages[j + 1];
1690
- if (companion !== void 0 && companion.role === "assistant" && (companion.contentType === "text" || companion.contentType === "tool-call") && j + 1 > newEndIndex) {
1691
- newEndIndex = j + 1;
1690
+ if (companion !== void 0 && companion.role === "assistant" && (companion.contentType === "text" || companion.contentType === "tool-call")) {
1691
+ let e = j + 1;
1692
+ while (e + 1 < messages.length && messages[e + 1].role === "assistant" && (messages[e + 1].contentType === "text" || messages[e + 1].contentType === "tool-call")) {
1693
+ e++;
1694
+ }
1695
+ if (e > newEndIndex) newEndIndex = e;
1692
1696
  }
1693
1697
  }
1694
1698
  if (msg.role === "assistant" && (msg.contentType === "text" || msg.contentType === "tool-call")) {
@@ -1705,6 +1709,66 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
1705
1709
  return { startIndex: newStartIndex, endIndex: newEndIndex };
1706
1710
  }
1707
1711
 
1712
+ // src/turn-integrity.ts
1713
+ function isAssistantAct(msg) {
1714
+ return msg.role === "assistant" && (msg.contentType === "text" || msg.contentType === "tool-call");
1715
+ }
1716
+ function computeTurnGroups(messages) {
1717
+ const resultIdByCallId = /* @__PURE__ */ new Map();
1718
+ for (const msg of messages) {
1719
+ if (msg.contentType === "tool-result" && typeof msg.toolCallId === "string" && msg.id) {
1720
+ if (!resultIdByCallId.has(msg.toolCallId))
1721
+ resultIdByCallId.set(msg.toolCallId, msg.id);
1722
+ }
1723
+ }
1724
+ const grouped = /* @__PURE__ */ new Set();
1725
+ const groups = [];
1726
+ for (let i = 0; i < messages.length; i++) {
1727
+ const msg = messages[i];
1728
+ if (!msg.id || grouped.has(msg.id)) continue;
1729
+ if (!(msg.contentType === "reasoning" || isAssistantAct(msg))) continue;
1730
+ let reasoningStart = i;
1731
+ if (msg.contentType === "reasoning") {
1732
+ while (reasoningStart > 0 && messages[reasoningStart - 1].contentType === "reasoning") {
1733
+ reasoningStart--;
1734
+ }
1735
+ } else {
1736
+ let s = i;
1737
+ while (s > 0 && isAssistantAct(messages[s - 1])) s--;
1738
+ reasoningStart = s;
1739
+ while (reasoningStart > 0 && messages[reasoningStart - 1].contentType === "reasoning") {
1740
+ reasoningStart--;
1741
+ }
1742
+ }
1743
+ const burstStart = (() => {
1744
+ let s = reasoningStart;
1745
+ while (s < messages.length && messages[s].contentType === "reasoning")
1746
+ s++;
1747
+ return s;
1748
+ })();
1749
+ if (burstStart >= messages.length || !isAssistantAct(messages[burstStart])) {
1750
+ continue;
1751
+ }
1752
+ let burstEnd = burstStart;
1753
+ while (burstEnd + 1 < messages.length && isAssistantAct(messages[burstEnd + 1])) {
1754
+ burstEnd++;
1755
+ }
1756
+ const members = /* @__PURE__ */ new Set();
1757
+ for (let k = reasoningStart; k <= burstEnd; k++) {
1758
+ const m = messages[k];
1759
+ if (!m.id) continue;
1760
+ members.add(m.id);
1761
+ if (m.role === "assistant" && m.contentType === "tool-call" && typeof m.toolCallId === "string") {
1762
+ const rid = resultIdByCallId.get(m.toolCallId);
1763
+ if (rid) members.add(rid);
1764
+ }
1765
+ }
1766
+ for (const id of members) grouped.add(id);
1767
+ groups.push([...members]);
1768
+ }
1769
+ return groups;
1770
+ }
1771
+
1708
1772
  // src/recommend.ts
1709
1773
  function estimateTextTokens(text) {
1710
1774
  return Math.ceil(text.length / 4);
@@ -2427,6 +2491,42 @@ function applySingleRange(input) {
2427
2491
  )} from compression range (recent/last-user zone).`
2428
2492
  );
2429
2493
  }
2494
+ {
2495
+ const reasoningIds = /* @__PURE__ */ new Set();
2496
+ const callIds = /* @__PURE__ */ new Set();
2497
+ for (const m of input.messages) {
2498
+ if (!m.id) continue;
2499
+ if (m.contentType === "reasoning") reasoningIds.add(m.id);
2500
+ if (m.role === "assistant" && m.contentType === "tool-call") callIds.add(m.id);
2501
+ }
2502
+ const withdrawIds = /* @__PURE__ */ new Set();
2503
+ let splitTurnCount = 0;
2504
+ for (const group of computeTurnGroups(input.messages)) {
2505
+ const foldHasReasoning = group.some(
2506
+ (id) => effectiveMessageIds.has(id) && reasoningIds.has(id)
2507
+ );
2508
+ if (!foldHasReasoning) continue;
2509
+ const keptHasCall = group.some(
2510
+ (id) => !effectiveMessageIds.has(id) && callIds.has(id)
2511
+ );
2512
+ if (!keptHasCall) continue;
2513
+ splitTurnCount++;
2514
+ for (const id of group) withdrawIds.add(id);
2515
+ }
2516
+ if (withdrawIds.size > 0) {
2517
+ for (const id of withdrawIds) effectiveMessageIds.delete(id);
2518
+ const beforeWithdraw = filteredIds.length;
2519
+ filteredIds = filteredIds.filter((id) => !withdrawIds.has(id));
2520
+ if (filteredIds.length === 0 && consumedBlockIds.length === 0) {
2521
+ throw new Error(
2522
+ `Range would split ${splitTurnCount} turn(s) at the protected-zone boundary: a visible tool-call must keep its reasoning run (strict-echo providers reject a rebuilt request that lost it). Shrink the range to end before the turn starts, or wait until the whole turn ages out of the protected zone.`
2523
+ );
2524
+ }
2525
+ warnings.push(
2526
+ `Withdrawn ${beforeWithdraw - filteredIds.length} message(s) from compression range to keep ${splitTurnCount} turn(s) intact (visible tool-call would lose its reasoning run).`
2527
+ );
2528
+ }
2529
+ }
2430
2530
  if (!isBlockBoundary && filteredIds.length === 0 && consumedBlockIds.length > 0) {
2431
2531
  const first = consumedBlockIds[0];
2432
2532
  const last = consumedBlockIds[consumedBlockIds.length - 1];
@@ -3819,7 +3919,11 @@ function build(text) {
3819
3919
  }
3820
3920
  function docFeatures(text) {
3821
3921
  const hit = cache.get(text);
3822
- if (hit) return hit;
3922
+ if (hit) {
3923
+ cache.delete(text);
3924
+ cache.set(text, hit);
3925
+ return hit;
3926
+ }
3823
3927
  const f = build(text);
3824
3928
  if (text.length > 0 && text.length <= capChars) {
3825
3929
  while (cachedChars + text.length > capChars && cache.size > 0) {
@@ -3930,8 +4034,8 @@ var hybridAlgorithm = {
3930
4034
  score(docs, query) {
3931
4035
  const bm = bm25Algorithm.score(docs, query);
3932
4036
  const fz = fuzzyAlgorithm.score(docs, query);
3933
- const maxBm = Math.max(...bm.map((r) => r.score), 1e-9);
3934
- const maxFz = Math.max(...fz.map((r) => r.score), 1e-9);
4037
+ const maxBm = bm.reduce((m, r) => r.score > m ? r.score : m, 1e-9);
4038
+ const maxFz = fz.reduce((m, r) => r.score > m ? r.score : m, 1e-9);
3935
4039
  const bmMap = new Map(bm.map((r) => [r.ref, r.score / maxBm]));
3936
4040
  const fzMap = new Map(fz.map((r) => [r.ref, r.score / maxFz]));
3937
4041
  return docs.map((d) => ({