acp-kernel 0.0.62 → 0.0.63-pr.246.91
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/compress.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AAUvD,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;;;;;;;;;;;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;AA2/BD,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")
|
|
1691
|
-
|
|
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,30 @@ function applySingleRange(input) {
|
|
|
2427
2491
|
)} from compression range (recent/last-user zone).`
|
|
2428
2492
|
);
|
|
2429
2493
|
}
|
|
2494
|
+
{
|
|
2495
|
+
const splitTurnIds = /* @__PURE__ */ new Set();
|
|
2496
|
+
let splitTurnCount = 0;
|
|
2497
|
+
for (const group of computeTurnGroups(input.messages)) {
|
|
2498
|
+
const inFold = group.filter((id) => effectiveMessageIds.has(id));
|
|
2499
|
+
if (inFold.length > 0 && inFold.length < group.length) {
|
|
2500
|
+
splitTurnCount++;
|
|
2501
|
+
for (const id of group) splitTurnIds.add(id);
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
if (splitTurnIds.size > 0) {
|
|
2505
|
+
for (const id of splitTurnIds) effectiveMessageIds.delete(id);
|
|
2506
|
+
const beforeWithdraw = filteredIds.length;
|
|
2507
|
+
filteredIds = filteredIds.filter((id) => !splitTurnIds.has(id));
|
|
2508
|
+
if (filteredIds.length === 0 && consumedBlockIds.length === 0) {
|
|
2509
|
+
throw new Error(
|
|
2510
|
+
`Range would split ${splitTurnCount} turn(s) at the protected-zone boundary: part of each turn must stay visible, so none of it can fold (reasoning and tool-calls are atomic \u2014 providers reject a half turn). Shrink the range to end before the turn starts, or wait until the whole turn ages out of the protected zone.`
|
|
2511
|
+
);
|
|
2512
|
+
}
|
|
2513
|
+
warnings.push(
|
|
2514
|
+
`Withdrawn ${beforeWithdraw - filteredIds.length} message(s) from compression range to keep ${splitTurnCount} turn(s) atomic (reasoning/tool-call split at the protected boundary).`
|
|
2515
|
+
);
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2430
2518
|
if (!isBlockBoundary && filteredIds.length === 0 && consumedBlockIds.length > 0) {
|
|
2431
2519
|
const first = consumedBlockIds[0];
|
|
2432
2520
|
const last = consumedBlockIds[consumedBlockIds.length - 1];
|