acp-kernel 0.0.22 → 0.0.23

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,EAGL,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAapB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAOvD,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;;;;;;;;;;;O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U,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;AAsBD,wBAAgB,UAAU,CAAC,KAAK,GAAE,KAAU,GAAG,eAAe,CAwQ7D;AAiuBD,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -142,9 +142,11 @@ function prune(messages, state, options = {}) {
142
142
  const indexById = /* @__PURE__ */ new Map();
143
143
  messages.forEach((message, index) => indexById.set(message.id, index));
144
144
  const anchors = inject ? collectSummaryAnchors(state, indexById) : [];
145
- return stripOrphanedToolResults(
146
- stripOrphanedToolCalls(
147
- rebuildMessages(messages, covered, firstUserIndex, anchors)
145
+ return stripOrphanedReasoning(
146
+ stripOrphanedToolResults(
147
+ stripOrphanedToolCalls(
148
+ rebuildMessages(messages, covered, firstUserIndex, anchors)
149
+ )
148
150
  )
149
151
  );
150
152
  }
@@ -221,6 +223,24 @@ function stripOrphanedToolCalls(messages) {
221
223
  (m) => m.contentType !== "tool-call" || !m.toolCallId || m.toolName === "compress" || knownResultIds.has(m.toolCallId)
222
224
  );
223
225
  }
226
+ function stripOrphanedReasoning(messages) {
227
+ const drop = /* @__PURE__ */ new Set();
228
+ for (let i = 0; i < messages.length; i++) {
229
+ if (drop.has(i)) continue;
230
+ if (messages[i].contentType !== "reasoning") continue;
231
+ let j = i;
232
+ while (j + 1 < messages.length && messages[j + 1].contentType === "reasoning") {
233
+ j++;
234
+ }
235
+ const companion = messages[j + 1];
236
+ const hasCompanion = companion !== void 0 && companion.role === "assistant" && (companion.contentType === "text" || companion.contentType === "tool-call");
237
+ if (!hasCompanion) {
238
+ for (let k = i; k <= j; k++) drop.add(k);
239
+ }
240
+ }
241
+ if (drop.size === 0) return messages;
242
+ return messages.filter((_, i) => !drop.has(i));
243
+ }
224
244
 
225
245
  // src/sync.ts
226
246
  function syncBlocks(messages, state) {
@@ -889,6 +909,40 @@ function adjustBoundariesForToolPairs(startIndex, endIndex, messages, maxScan =
889
909
  return { startIndex: newStartIndex, endIndex: newEndIndex };
890
910
  }
891
911
 
912
+ // src/reasoning-pairs.ts
913
+ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
914
+ if (startIndex > endIndex) {
915
+ return { startIndex, endIndex };
916
+ }
917
+ let newStartIndex = startIndex;
918
+ let newEndIndex = endIndex;
919
+ for (let i = startIndex; i <= endIndex && i < messages.length; i++) {
920
+ const msg = messages[i];
921
+ if (!msg) continue;
922
+ if (msg.contentType === "reasoning") {
923
+ let j = i;
924
+ while (j + 1 < messages.length && messages[j + 1].contentType === "reasoning") {
925
+ j++;
926
+ }
927
+ const companion = messages[j + 1];
928
+ if (companion !== void 0 && companion.role === "assistant" && (companion.contentType === "text" || companion.contentType === "tool-call") && j + 1 > newEndIndex) {
929
+ newEndIndex = j + 1;
930
+ }
931
+ }
932
+ if (msg.role === "assistant" && (msg.contentType === "text" || msg.contentType === "tool-call")) {
933
+ let k = i - 1;
934
+ while (k >= 0 && messages[k].contentType === "reasoning") {
935
+ k--;
936
+ }
937
+ const runStart = k + 1;
938
+ if (runStart < i && runStart >= 0 && messages[runStart].contentType === "reasoning" && runStart < newStartIndex) {
939
+ newStartIndex = runStart;
940
+ }
941
+ }
942
+ }
943
+ return { startIndex: newStartIndex, endIndex: newEndIndex };
944
+ }
945
+
892
946
  // src/recommend.ts
893
947
  function refNum(ref) {
894
948
  const n = parseInt(ref.slice(1), 10);
@@ -1392,7 +1446,7 @@ function applySingleRange(input) {
1392
1446
  messages: input.messages,
1393
1447
  state: input.state
1394
1448
  });
1395
- const rangeMessageIds = applyToolPairAdjustment(
1449
+ const rangeMessageIds = applyPairBoundaryAdjustments(
1396
1450
  resolved,
1397
1451
  input.messages
1398
1452
  );
@@ -1506,20 +1560,33 @@ function applySingleRange(input) {
1506
1560
  }
1507
1561
  return { tokens: compressedTokens, warnings };
1508
1562
  }
1509
- function applyToolPairAdjustment(resolved, messages) {
1563
+ function applyPairBoundaryAdjustments(resolved, messages) {
1510
1564
  if (resolved.boundaryKind === "block") {
1511
1565
  return resolved.messageIds;
1512
1566
  }
1513
- const adjusted = adjustBoundariesForToolPairs(
1514
- resolved.startIndex,
1515
- resolved.endIndex,
1516
- messages
1517
- );
1518
- if (adjusted.startIndex === resolved.startIndex && adjusted.endIndex === resolved.endIndex) {
1567
+ let startIndex = resolved.startIndex;
1568
+ let endIndex = resolved.endIndex;
1569
+ for (let pass = 0; pass < 2; pass++) {
1570
+ const reasoningAdjusted = adjustBoundariesForReasoningPairs(
1571
+ startIndex,
1572
+ endIndex,
1573
+ messages
1574
+ );
1575
+ const toolAdjusted = adjustBoundariesForToolPairs(
1576
+ reasoningAdjusted.startIndex,
1577
+ reasoningAdjusted.endIndex,
1578
+ messages
1579
+ );
1580
+ const changed = toolAdjusted.startIndex !== startIndex || toolAdjusted.endIndex !== endIndex;
1581
+ startIndex = toolAdjusted.startIndex;
1582
+ endIndex = toolAdjusted.endIndex;
1583
+ if (!changed) break;
1584
+ }
1585
+ if (startIndex === resolved.startIndex && endIndex === resolved.endIndex) {
1519
1586
  return resolved.messageIds;
1520
1587
  }
1521
1588
  const ids = [];
1522
- for (let i = adjusted.startIndex; i <= adjusted.endIndex; i++) {
1589
+ for (let i = startIndex; i <= endIndex; i++) {
1523
1590
  const msg = messages[i];
1524
1591
  if (msg) ids.push(msg.id);
1525
1592
  }