acp-kernel 0.0.59-pr.232.80 → 0.0.59-pr.235.82

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.
@@ -42,8 +42,8 @@ export declare function resolveBoundaries(input: ResolveBoundariesInput): Resolv
42
42
  * active block whose raws were pruned becomes unresolvable and cannot be
43
43
  * promoted (dog/billion-context-pi#195).
44
44
  */
45
- export declare function visibleBlockAnchor(block: CompressionBlock, indexByMessageId: Map<string, number>): number | null;
46
- export declare function blockVisibleInRange(block: CompressionBlock, indexByMessageId: Map<string, number>, startIndex: number, endIndex: number): boolean;
47
- export declare function earliestIndexOfIds(ids: string[], indexByMessageId: Map<string, number>): number | null;
45
+ export declare function visibleBlockAnchor(block: CompressionBlock, indexByMessageId: Map<string, number>, baseIndexById?: Map<string, number>): number | null;
46
+ export declare function blockVisibleInRange(block: CompressionBlock, indexByMessageId: Map<string, number>, startIndex: number, endIndex: number, baseIndexById?: Map<string, number>): boolean;
47
+ export declare function earliestIndexOfIds(ids: string[], indexByMessageId: Map<string, number>, baseIndexById?: Map<string, number>): number | null;
48
48
  export declare function toResolvedBoundary(range: ResolvedRange): ResolvedBoundary;
49
49
  //# sourceMappingURL=boundaries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"boundaries.d.ts","sourceRoot":"","sources":["../src/boundaries.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,OAAO,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;CACb;AAKD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAehE;AAED;;;;;;GAMG;AACH,qBA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AAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,2BAA2B,CACvC,QAAQ,EAAE,WAAW,EAAE,EACvB,sBAAsB,EAAE,GAAG,CAAC,MAAM,CAAC,EACnC,KAAK,EAAE,gBAAgB,GACxB,qBAAqB,CAgCvB;AAED,MAAM,WAAW,sBAAsB;IACnC,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,6GAA6G;IAC7G,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IAClC,kKAAkK;IAClK,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,WAAW,EAAE,EACvB,OAAO,GAAE,qBAA0B,GACpC,sBAAsB,CA0CxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"hide-consumed.d.ts","sourceRoot":"","sources":["../src/hide-consumed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAYhE,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAClB;AA0ED,wBAAgB,yBAAyB,CACrC,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,WAAW,EAAE,GACxB,kBAAkB,CAwFpB"}
1
+ {"version":3,"file":"hide-consumed.d.ts","sourceRoot":"","sources":["../src/hide-consumed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAYhE,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAClB;AA8BD,wBAAgB,yBAAyB,CACrC,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,WAAW,EAAE,GACxB,kBAAkB,CAmFpB"}
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { createInitialState, allocateBlockId, allocateRunId, blockById, activeBl
5
5
  export { defaultConfig, validateConfig } from "./config.js";
6
6
  export * from "./compress-tools.js";
7
7
  export { assignRefs, highestUsedIndex, emptyRefMap, indexToRef, refToIndex, refForRaw, rawForRef, BLOCKED_REF, } from "./refs.js";
8
- export { prune, SUMMARY_HEADER, summaryMessageId, isSummaryMessageId, isRenderedSummaryMessage, } from "./prune.js";
8
+ export { prune, baseIdOf, isCovered, SUMMARY_HEADER, summaryMessageId, isSummaryMessageId, isRenderedSummaryMessage, } from "./prune.js";
9
9
  export { syncBlocks } from "./sync.js";
10
10
  export { resolveBoundaries, parseBoundary, BoundaryNotFoundError, visibleBlockAnchor, blockVisibleInRange, } from "./boundaries.js";
11
11
  export { defaultCountTokens, estimateTokensFast, createBpeTokenizer, } from "./tokenize.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,cAAc,qBAAqB,CAAC;AACpC,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK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,EACT,aAAa,EACb,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EACL,WAAW,EACX,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,cAAc,qBAAqB,CAAC;AACpC,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK,EACL,QAAQ,EACR,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EACL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AkB,EAClB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EACL,WAAW,EACX,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -107,33 +107,45 @@ function summaryMessageId(blockId) {
107
107
  function isSummaryMessageId(id) {
108
108
  return id.startsWith(SUMMARY_ID_PREFIX);
109
109
  }
110
+ function baseIdOf(id) {
111
+ const hash = id.indexOf("#");
112
+ return hash > 0 ? id.substring(0, hash) : id;
113
+ }
114
+ function isCovered(id, coveredBases) {
115
+ return coveredBases.has(baseIdOf(id));
116
+ }
110
117
  function isRenderedSummaryMessage(message) {
111
118
  return isSummaryMessageId(message.id) && message.role === "system" && message.contentType === "text";
112
119
  }
113
120
  function prune(messages, state, options = {}) {
114
121
  const covered = coveredMessageIds(state);
115
122
  if (covered.size === 0) return [...messages];
123
+ const coveredBases = /* @__PURE__ */ new Set();
124
+ for (const id of covered) coveredBases.add(baseIdOf(id));
116
125
  const inject = options.injectSummaries ?? true;
117
126
  const firstUserIndex = messages.findIndex(
118
127
  (message) => message.role === "user"
119
128
  );
120
- const indexById = /* @__PURE__ */ new Map();
129
+ const baseIndexById = /* @__PURE__ */ new Map();
121
130
  const summaryIndexById = /* @__PURE__ */ new Map();
122
131
  messages.forEach((message, index) => {
123
- indexById.set(message.id, index);
132
+ const base = baseIdOf(message.id);
133
+ const existing = baseIndexById.get(base);
134
+ if (existing === void 0 || index < existing)
135
+ baseIndexById.set(base, index);
124
136
  if (isRenderedSummaryMessage(message))
125
137
  summaryIndexById.set(message.id, index);
126
138
  });
127
- const anchors = inject ? collectSummaryAnchors(state, indexById, summaryIndexById) : [];
139
+ const anchors = inject ? collectSummaryAnchors(state, baseIndexById, summaryIndexById) : [];
128
140
  return stripOrphanedReasoning(
129
141
  stripOrphanedToolResults(
130
142
  stripOrphanedToolCalls(
131
- rebuildMessages(messages, covered, firstUserIndex, anchors)
143
+ rebuildMessages(messages, coveredBases, firstUserIndex, anchors)
132
144
  )
133
145
  )
134
146
  );
135
147
  }
136
- function collectSummaryAnchors(state, indexById, summaryIndexById) {
148
+ function collectSummaryAnchors(state, baseIndexById, summaryIndexById) {
137
149
  const anchors = [];
138
150
  for (const block of activeBlocks(state)) {
139
151
  const existingIndex = summaryIndexById.get(summaryMessageId(block.blockId));
@@ -148,7 +160,7 @@ function collectSummaryAnchors(state, indexById, summaryIndexById) {
148
160
  }
149
161
  let earliest = null;
150
162
  for (const id of block.effectiveMessageIds) {
151
- const index = indexById.get(id);
163
+ const index = baseIndexById.get(baseIdOf(id));
152
164
  if (index !== void 0 && (earliest === null || index < earliest)) {
153
165
  earliest = index;
154
166
  }
@@ -163,7 +175,7 @@ function collectSummaryAnchors(state, indexById, summaryIndexById) {
163
175
  anchors.sort((left, right) => left.insertAt - right.insertAt);
164
176
  return anchors;
165
177
  }
166
- function rebuildMessages(messages, covered, firstUserIndex, anchors) {
178
+ function rebuildMessages(messages, coveredBases, firstUserIndex, anchors) {
167
179
  const result = [];
168
180
  const pending = [...anchors];
169
181
  const anchoredSummaryIds = new Set(
@@ -177,7 +189,7 @@ function rebuildMessages(messages, covered, firstUserIndex, anchors) {
177
189
  result.push(messages[index]);
178
190
  continue;
179
191
  }
180
- if (covered.has(messages[index].id)) continue;
192
+ if (isCovered(messages[index].id, coveredBases)) continue;
181
193
  if (isRenderedSummaryMessage(messages[index]) && anchoredSummaryIds.has(messages[index].id))
182
194
  continue;
183
195
  result.push(messages[index]);
@@ -243,6 +255,8 @@ function stripOrphanedReasoning(messages) {
243
255
  // src/sync.ts
244
256
  function syncBlocks(messages, state) {
245
257
  const presentIds = new Set(messages.map((message) => message.id));
258
+ const presentBases = /* @__PURE__ */ new Set();
259
+ for (const message of messages) presentBases.add(baseIdOf(message.id));
246
260
  const deactivated = [];
247
261
  const result = {
248
262
  blocks: state.blocks.map((block) => ({
@@ -289,7 +303,7 @@ function syncBlocks(messages, state) {
289
303
  continue;
290
304
  }
291
305
  block.active = true;
292
- const stillPresent = block.effectiveMessageIds.some((id) => presentIds.has(id)) || presentIds.has(summaryMessageId(block.blockId));
306
+ const stillPresent = block.effectiveMessageIds.some((id) => presentBases.has(baseIdOf(id))) || presentIds.has(summaryMessageId(block.blockId));
293
307
  if (!stillPresent) {
294
308
  block.active = false;
295
309
  deactivated.push(block.blockId);
@@ -429,14 +443,20 @@ function resolveBoundaries(input) {
429
443
  );
430
444
  }
431
445
  const indexByMessageId = /* @__PURE__ */ new Map();
432
- input.messages.forEach(
433
- (message, index) => indexByMessageId.set(message.id, index)
434
- );
446
+ const baseIndexById = /* @__PURE__ */ new Map();
447
+ input.messages.forEach((message, index) => {
448
+ indexByMessageId.set(message.id, index);
449
+ const base = baseIdOf(message.id);
450
+ const existing = baseIndexById.get(base);
451
+ if (existing === void 0 || index < existing)
452
+ baseIndexById.set(base, index);
453
+ });
435
454
  let snappedBoundaries = [];
436
455
  const startAnchor = resolveAnchorIndex(
437
456
  start,
438
457
  input.state,
439
458
  indexByMessageId,
459
+ baseIndexById,
440
460
  "start"
441
461
  );
442
462
  if (startAnchor.snapped) snappedBoundaries.push(startAnchor.snapped);
@@ -444,6 +464,7 @@ function resolveBoundaries(input) {
444
464
  end,
445
465
  input.state,
446
466
  indexByMessageId,
467
+ baseIndexById,
447
468
  "end"
448
469
  );
449
470
  if (endAnchor.snapped) snappedBoundaries.push(endAnchor.snapped);
@@ -462,7 +483,13 @@ function resolveBoundaries(input) {
462
483
  const nestedBlockIds = [];
463
484
  const nestedSeen = /* @__PURE__ */ new Set();
464
485
  for (const block of activeBlocks(input.state)) {
465
- if (blockVisibleInRange(block, indexByMessageId, startIndex, endIndex)) {
486
+ if (blockVisibleInRange(
487
+ block,
488
+ indexByMessageId,
489
+ startIndex,
490
+ endIndex,
491
+ baseIndexById
492
+ )) {
466
493
  if (!nestedSeen.has(block.blockId)) {
467
494
  nestedSeen.add(block.blockId);
468
495
  nestedBlockIds.push(block.blockId);
@@ -480,7 +507,7 @@ function resolveBoundaries(input) {
480
507
  snappedBoundaries
481
508
  };
482
509
  }
483
- function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
510
+ function resolveAnchorIndex(boundary, state, indexByMessageId, baseIndexById, endpoint) {
484
511
  const label = endpoint === "start" ? "startId" : "endId";
485
512
  if (boundary.kind === "message") {
486
513
  const rawId = state.messageRefs.byRef[boundary.raw] ?? state.messageRefs.byRef[formatPaddedRef(boundary.numericId)];
@@ -491,11 +518,11 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
491
518
  `${label}="${boundary.raw}" does not exist in this session (typo or wrong session) \u2014 run acp_status for current refs.`
492
519
  );
493
520
  }
494
- const index = indexByMessageId.get(rawId);
521
+ const index = indexByMessageId.get(rawId) ?? baseIndexById.get(baseIdOf(rawId));
495
522
  if (index !== void 0) {
496
523
  return { index, snapped: null };
497
524
  }
498
- const owner2 = activeOwnerAnchor(state, [rawId], indexByMessageId);
525
+ const owner2 = activeOwnerAnchor(state, [rawId], indexByMessageId, baseIndexById);
499
526
  if (owner2 !== null) {
500
527
  return {
501
528
  index: owner2,
@@ -517,7 +544,7 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
517
544
  );
518
545
  }
519
546
  if (block.active) {
520
- const anchor = visibleBlockAnchor(block, indexByMessageId);
547
+ const anchor = visibleBlockAnchor(block, indexByMessageId, baseIndexById);
521
548
  if (anchor !== null) {
522
549
  return { index: anchor, snapped: null };
523
550
  }
@@ -525,7 +552,8 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
525
552
  const owner = activeOwnerAnchor(
526
553
  state,
527
554
  block.effectiveMessageIds,
528
- indexByMessageId
555
+ indexByMessageId,
556
+ baseIndexById
529
557
  );
530
558
  if (owner !== null) {
531
559
  return {
@@ -546,9 +574,10 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
546
574
  `${label}="b${boundary.numericId}" is an active block but none of its content (raw messages or rendered summary) is visible in the current context \u2014 run acp_status to verify.`
547
575
  );
548
576
  }
549
- function activeOwnerAnchor(state, ownedIds, indexByMessageId) {
577
+ function activeOwnerAnchor(state, ownedIds, indexByMessageId, baseIndexById) {
550
578
  if (ownedIds.length === 0) return null;
551
- const owned = new Set(ownedIds);
579
+ const owned = /* @__PURE__ */ new Set();
580
+ for (const id of ownedIds) owned.add(baseIdOf(id));
552
581
  let best = null;
553
582
  for (const block of state.blocks) {
554
583
  if (!block.active) continue;
@@ -561,7 +590,7 @@ function activeOwnerAnchor(state, ownedIds, indexByMessageId) {
561
590
  }
562
591
  }
563
592
  if (!ownsInherited) continue;
564
- const anchor = visibleBlockAnchor(block, indexByMessageId);
593
+ const anchor = visibleBlockAnchor(block, indexByMessageId, baseIndexById);
565
594
  if (anchor === null) continue;
566
595
  if (best === null || anchor < best) {
567
596
  best = anchor;
@@ -574,39 +603,54 @@ function inheritedContentIds(state, block) {
574
603
  for (const childId of block.directBlockIds) {
575
604
  const child = blockById(state, childId);
576
605
  if (!child) continue;
577
- for (const id of child.effectiveMessageIds) ids.add(id);
606
+ for (const id of child.effectiveMessageIds) ids.add(baseIdOf(id));
578
607
  }
579
608
  return ids;
580
609
  }
581
610
  function formatPaddedRef(index) {
582
611
  return `m${String(index).padStart(5, "0")}`;
583
612
  }
584
- function visibleBlockAnchor(block, indexByMessageId) {
613
+ function visibleBlockAnchor(block, indexByMessageId, baseIndexById) {
585
614
  const summaryIndex = indexByMessageId.get(summaryMessageId(block.blockId));
586
615
  if (summaryIndex !== void 0) return summaryIndex;
587
- return earliestIndexOfIds(block.effectiveMessageIds, indexByMessageId);
616
+ return earliestIndexOfIds(
617
+ block.effectiveMessageIds,
618
+ indexByMessageId,
619
+ baseIndexById
620
+ );
588
621
  }
589
- function blockVisibleInRange(block, indexByMessageId, startIndex, endIndex) {
622
+ function blockVisibleInRange(block, indexByMessageId, startIndex, endIndex, baseIndexById) {
590
623
  const summaryIndex = indexByMessageId.get(summaryMessageId(block.blockId));
591
624
  if (summaryIndex !== void 0 && summaryIndex >= startIndex && summaryIndex <= endIndex) {
592
625
  return true;
593
626
  }
594
627
  const rawIndex = earliestIndexOfIds(
595
628
  block.effectiveMessageIds,
596
- indexByMessageId
629
+ indexByMessageId,
630
+ baseIndexById
597
631
  );
598
632
  return rawIndex !== null && rawIndex >= startIndex && rawIndex <= endIndex;
599
633
  }
600
- function earliestIndexOfIds(ids, indexByMessageId) {
634
+ function earliestIndexOfIds(ids, indexByMessageId, baseIndexById) {
635
+ const baseIndex = baseIndexById ?? deriveBaseIndex(indexByMessageId);
601
636
  let earliest = null;
602
637
  for (const id of ids) {
603
- const index = indexByMessageId.get(id);
638
+ const index = baseIndex.get(baseIdOf(id));
604
639
  if (index !== void 0 && (earliest === null || index < earliest)) {
605
640
  earliest = index;
606
641
  }
607
642
  }
608
643
  return earliest;
609
644
  }
645
+ function deriveBaseIndex(indexByMessageId) {
646
+ const baseIndex = /* @__PURE__ */ new Map();
647
+ for (const [id, index] of indexByMessageId) {
648
+ const base = baseIdOf(id);
649
+ const existing = baseIndex.get(base);
650
+ if (existing === void 0 || index < existing) baseIndex.set(base, index);
651
+ }
652
+ return baseIndex;
653
+ }
610
654
 
611
655
  // src/truncate-tools.ts
612
656
  var TRUNCATION_MARKER = "[truncated for context space]";
@@ -666,57 +710,25 @@ var KEEP_LAST_ORPHANED = 2;
666
710
  function rangeKey(startRef, endRef) {
667
711
  return `${startRef}::${endRef}`;
668
712
  }
669
- function parseCallText(text) {
670
- const raw = text ?? "";
671
- const start = raw.indexOf("{");
672
- if (start < 0) return null;
713
+ function rewriteCompressText(text, liveKeys) {
673
714
  let parsed;
674
715
  try {
675
- parsed = JSON.parse(raw.slice(start));
716
+ parsed = JSON.parse(text ?? "");
676
717
  } catch {
677
718
  return null;
678
719
  }
679
720
  if (!parsed || typeof parsed !== "object") return null;
680
721
  const obj = parsed;
681
- if (!Array.isArray(obj.content) || obj.content.length === 0) return null;
682
- return { prefix: raw.slice(0, start), obj, content: obj.content };
683
- }
684
- function rewriteCompressText(text, liveKeys) {
685
- const parsed = parseCallText(text);
686
- if (!parsed) return null;
687
- const { prefix, obj, content } = parsed;
722
+ const content = obj.content;
723
+ if (!Array.isArray(content) || content.length === 0) return null;
688
724
  const kept = content.filter((entry) => {
689
725
  if (!entry || typeof entry !== "object") return false;
690
- const e = entry;
691
- const s = typeof e.startId === "string" ? e.startId : typeof e.messageId === "string" ? e.messageId : "";
692
- const end = typeof e.endId === "string" ? e.endId : typeof e.messageId === "string" ? e.messageId : "";
693
- return liveKeys.has(rangeKey(s, end));
694
- });
695
- if (kept.length === 0) return null;
696
- return prefix + serializeCompacted(obj, kept).text;
697
- }
698
- var SUMMARY_STUB_CHARS = 200;
699
- function compactEntry(entry) {
700
- if (!entry || typeof entry !== "object") return entry;
701
- const e = entry;
702
- if (typeof e.summary !== "string" || e.summary.length <= SUMMARY_STUB_CHARS) return entry;
703
- return { ...e, summary: `${e.summary.slice(0, SUMMARY_STUB_CHARS - 1)}\u2026` };
704
- }
705
- function serializeCompacted(obj, content) {
706
- let changed = false;
707
- const compacted = content.map((entry) => {
708
- const out = compactEntry(entry);
709
- if (out !== entry) changed = true;
710
- return out;
726
+ const s = typeof entry.startId === "string" ? entry.startId : typeof entry.messageId === "string" ? entry.messageId : "";
727
+ const e = typeof entry.endId === "string" ? entry.endId : typeof entry.messageId === "string" ? entry.messageId : "";
728
+ return liveKeys.has(rangeKey(s, e));
711
729
  });
712
- return { text: JSON.stringify({ ...obj, content: compacted }), changed };
713
- }
714
- function compactCompressText(text) {
715
- const parsed = parseCallText(text);
716
- if (!parsed) return null;
717
- const { prefix, obj, content } = parsed;
718
- const { text: out, changed } = serializeCompacted(obj, content);
719
- return changed ? prefix + out : null;
730
+ if (kept.length === content.length || kept.length === 0) return null;
731
+ return JSON.stringify({ ...obj, content: kept });
720
732
  }
721
733
  function hideConsumedCompressCalls(state, messages) {
722
734
  const allBlockCallIds = /* @__PURE__ */ new Set();
@@ -775,11 +787,6 @@ function hideConsumedCompressCalls(state, messages) {
775
787
  continue;
776
788
  }
777
789
  }
778
- const compacted = compactCompressText(message.text);
779
- if (compacted !== null) {
780
- result.push({ ...message, text: compacted });
781
- continue;
782
- }
783
790
  }
784
791
  result.push(message);
785
792
  }
@@ -1695,20 +1702,26 @@ function estimateTextTokens(text) {
1695
1702
  function isToolMessage(message) {
1696
1703
  return message.contentType === "tool-call" || message.contentType === "tool-result";
1697
1704
  }
1698
- function isSyntheticOrPruned(message, state) {
1699
- if (message.text?.startsWith("[Compressed conversation section]")) return true;
1705
+ function activeBlockCoveredBases(state) {
1706
+ const covered = /* @__PURE__ */ new Set();
1700
1707
  for (const block of state.blocks) {
1701
- if (block.active && block.effectiveMessageIds.includes(message.id)) return true;
1708
+ if (!block.active) continue;
1709
+ for (const id of block.effectiveMessageIds) covered.add(baseIdOf(id));
1702
1710
  }
1703
- return false;
1711
+ return covered;
1712
+ }
1713
+ function isSyntheticOrPruned(message, coveredBases) {
1714
+ if (message.text?.startsWith("[Compressed conversation section]")) return true;
1715
+ return coveredBases.has(baseIdOf(message.id));
1704
1716
  }
1705
1717
  function computeProtectedRefs(messages, state, config, countTokens = estimateTextTokens) {
1706
1718
  const preserveN = config.preserveRecentMessages;
1707
1719
  const preserveTokens = config.preserveRecentTokens;
1708
1720
  const result = /* @__PURE__ */ new Set();
1709
1721
  const visible = [];
1722
+ const coveredBases = activeBlockCoveredBases(state);
1710
1723
  for (const msg of messages) {
1711
- if (isSyntheticOrPruned(msg, state)) continue;
1724
+ if (isSyntheticOrPruned(msg, coveredBases)) continue;
1712
1725
  if (isNeverPreserveRecent(msg)) continue;
1713
1726
  const ref = state.messageRefs.byRaw[msg.id];
1714
1727
  if (!ref || ref === "BLOCKED") continue;
@@ -1729,7 +1742,7 @@ function computeProtectedRefs(messages, state, config, countTokens = estimateTex
1729
1742
  if (preserveN > 0) {
1730
1743
  for (let i = messages.length - 1; i >= 0; i--) {
1731
1744
  const msg = messages[i];
1732
- if (msg.role !== "user" || isSyntheticOrPruned(msg, state)) continue;
1745
+ if (msg.role !== "user" || isSyntheticOrPruned(msg, coveredBases)) continue;
1733
1746
  const ref = state.messageRefs.byRaw[msg.id];
1734
1747
  if (ref && ref !== "BLOCKED") result.add(ref);
1735
1748
  break;
@@ -1743,10 +1756,11 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
1743
1756
  const protectedCallIds = collectProtectedToolCallIds(messages, config);
1744
1757
  let skipSinceCompressible = false;
1745
1758
  let skipSinceProtected = false;
1759
+ const coveredBases = activeBlockCoveredBases(state);
1746
1760
  for (const msg of messages) {
1747
1761
  const ref = state.messageRefs.byRaw[msg.id];
1748
1762
  if (!ref || ref === "BLOCKED") continue;
1749
- if (isSyntheticOrPruned(msg, state)) {
1763
+ if (isSyntheticOrPruned(msg, coveredBases)) {
1750
1764
  skipSinceCompressible = true;
1751
1765
  skipSinceProtected = true;
1752
1766
  continue;
@@ -1913,16 +1927,22 @@ function refGateDiagnostics(state, requestedRanges, unknownCount) {
1913
1927
  }
1914
1928
  function danglingMessageRefs(state, messages, spec) {
1915
1929
  const visible = new Set(messages.map((m) => m.id));
1930
+ const visibleBases = /* @__PURE__ */ new Set();
1931
+ for (const id of visible) visibleBases.add(baseIdOf(id));
1932
+ const coveredBases = /* @__PURE__ */ new Set();
1933
+ for (const block of state.blocks) {
1934
+ if (!block.active) continue;
1935
+ for (const id of block.effectiveMessageIds) coveredBases.add(baseIdOf(id));
1936
+ }
1916
1937
  const dangling = [];
1917
1938
  for (const ref of [spec.startRef, spec.endRef]) {
1918
1939
  const parsed = parseBoundary(ref);
1919
1940
  if (!parsed || parsed.kind !== "message") continue;
1920
1941
  const rawId = state.messageRefs.byRef[parsed.raw] ?? state.messageRefs.byRef[indexToRef(parsed.numericId)];
1921
- if (!rawId || visible.has(rawId)) continue;
1922
- const covered = state.blocks.some(
1923
- (block) => block.active && block.effectiveMessageIds.includes(rawId)
1924
- );
1925
- if (!covered) dangling.push(parsed.raw);
1942
+ if (!rawId) continue;
1943
+ const base = baseIdOf(rawId);
1944
+ if (visible.has(rawId) || visibleBases.has(base)) continue;
1945
+ if (!coveredBases.has(base)) dangling.push(parsed.raw);
1926
1946
  }
1927
1947
  return dangling;
1928
1948
  }
@@ -2341,13 +2361,25 @@ function applySingleRange(input) {
2341
2361
  ).filter((id) => !isSummaryMessageId(id));
2342
2362
  if (rangeMessageIds.length > resolved.messageIds.length) {
2343
2363
  const indexByMessageId = /* @__PURE__ */ new Map();
2344
- input.messages.forEach((m, i) => indexByMessageId.set(m.id, i));
2364
+ const baseIndexById = /* @__PURE__ */ new Map();
2365
+ input.messages.forEach((m, i) => {
2366
+ indexByMessageId.set(m.id, i);
2367
+ const base = baseIdOf(m.id);
2368
+ const existing = baseIndexById.get(base);
2369
+ if (existing === void 0 || i < existing) baseIndexById.set(base, i);
2370
+ });
2345
2371
  const adjustedStart = rangeMessageIds.length > 0 ? indexByMessageId.get(rangeMessageIds[0]) ?? resolved.startIndex : resolved.startIndex;
2346
2372
  const adjustedEnd = rangeMessageIds.length > 0 ? indexByMessageId.get(rangeMessageIds[rangeMessageIds.length - 1]) ?? resolved.endIndex : resolved.endIndex;
2347
2373
  const nestedSeen = new Set(resolved.nestedBlockIds);
2348
2374
  for (const block2 of activeBlocks(input.state)) {
2349
2375
  if (nestedSeen.has(block2.blockId)) continue;
2350
- if (blockVisibleInRange(block2, indexByMessageId, adjustedStart, adjustedEnd)) {
2376
+ if (blockVisibleInRange(
2377
+ block2,
2378
+ indexByMessageId,
2379
+ adjustedStart,
2380
+ adjustedEnd,
2381
+ baseIndexById
2382
+ )) {
2351
2383
  nestedSeen.add(block2.blockId);
2352
2384
  resolved.nestedBlockIds.push(block2.blockId);
2353
2385
  }
@@ -2373,7 +2405,7 @@ function applySingleRange(input) {
2373
2405
  }
2374
2406
  }
2375
2407
  const directMessageIds = [...effectiveMessageIds].filter(
2376
- (id) => !input.preExistingCoverage.has(id)
2408
+ (id) => !input.preExistingCoverage.has(baseIdOf(id))
2377
2409
  );
2378
2410
  let filteredIds = filterProtectedToolMessages(
2379
2411
  directMessageIds,
@@ -2553,7 +2585,7 @@ function resolveTargetTier(state, nestedBlockIds, isBlockBoundary) {
2553
2585
  function collectCoverage(state) {
2554
2586
  const coverage = /* @__PURE__ */ new Set();
2555
2587
  for (const block of activeBlocks(state)) {
2556
- for (const id of block.effectiveMessageIds) coverage.add(id);
2588
+ for (const id of block.effectiveMessageIds) coverage.add(baseIdOf(id));
2557
2589
  }
2558
2590
  return coverage;
2559
2591
  }
@@ -2814,10 +2846,12 @@ function parseBlockIdArg(arg) {
2814
2846
  }
2815
2847
  function findBlocksOverlappingMessages(state, messageIds) {
2816
2848
  if (messageIds.size === 0) return [];
2849
+ const messageBases = /* @__PURE__ */ new Set();
2850
+ for (const id of messageIds) messageBases.add(baseIdOf(id));
2817
2851
  const matched = [];
2818
2852
  for (const block of state.blocks) {
2819
2853
  if (!block.active) continue;
2820
- if (block.effectiveMessageIds.some((id) => messageIds.has(id))) {
2854
+ if (block.effectiveMessageIds.some((id) => messageBases.has(baseIdOf(id)))) {
2821
2855
  matched.push(block);
2822
2856
  }
2823
2857
  }
@@ -2874,13 +2908,15 @@ function deactivateBlock(state, blockIds, options = {}) {
2874
2908
  return { ...state, blocks: final };
2875
2909
  }
2876
2910
  function buildRestoredContentPreview(messages, beforeActiveMessageIds, state) {
2911
+ const coveredBases = /* @__PURE__ */ new Set();
2912
+ for (const b of state.blocks) {
2913
+ if (!b.active) continue;
2914
+ for (const id of b.effectiveMessageIds) coveredBases.add(baseIdOf(id));
2915
+ }
2877
2916
  const restored = [];
2878
2917
  for (const message of messages) {
2879
2918
  if (!beforeActiveMessageIds.has(message.id)) continue;
2880
- const stillCovered = state.blocks.some(
2881
- (b) => b.active && b.effectiveMessageIds.includes(message.id)
2882
- );
2883
- if (!stillCovered) restored.push(message);
2919
+ if (!coveredBases.has(baseIdOf(message.id))) restored.push(message);
2884
2920
  }
2885
2921
  if (restored.length === 0) return { preview: "", restoredCount: 0 };
2886
2922
  const lines = [];
@@ -2899,9 +2935,10 @@ function buildRestoredContentPreview(messages, beforeActiveMessageIds, state) {
2899
2935
  }
2900
2936
  function collectBlockContent(state, block, messages, options = {}) {
2901
2937
  const full = options.full ?? false;
2902
- const targetIds = new Set(block.effectiveMessageIds);
2938
+ const targetBases = /* @__PURE__ */ new Set();
2939
+ for (const id of block.effectiveMessageIds) targetBases.add(baseIdOf(id));
2903
2940
  if (full) {
2904
- const msgs = messages.filter((m) => targetIds.has(m.id));
2941
+ const msgs = messages.filter((m) => targetBases.has(baseIdOf(m.id)));
2905
2942
  if (msgs.length === 0) return { text: "", count: 0 };
2906
2943
  return { text: msgs.map(formatMessage).join("\n\n"), count: msgs.length };
2907
2944
  }
@@ -2911,7 +2948,7 @@ function collectBlockContent(state, block, messages, options = {}) {
2911
2948
  const child = state.blocks.find((b) => b.blockId === childId);
2912
2949
  if (!child?.active) continue;
2913
2950
  nestedChildren.push(child);
2914
- for (const id of child.effectiveMessageIds) nestedCovered.add(id);
2951
+ for (const id of child.effectiveMessageIds) nestedCovered.add(baseIdOf(id));
2915
2952
  }
2916
2953
  const parts = [];
2917
2954
  for (const child of nestedChildren) {
@@ -2921,7 +2958,8 @@ ${child.summary}`);
2921
2958
  }
2922
2959
  let directCount = 0;
2923
2960
  for (const m of messages) {
2924
- if (targetIds.has(m.id) && !nestedCovered.has(m.id)) {
2961
+ const base = baseIdOf(m.id);
2962
+ if (targetBases.has(base) && !nestedCovered.has(base)) {
2925
2963
  parts.push(formatMessage(m));
2926
2964
  directCount++;
2927
2965
  }
@@ -2983,7 +3021,7 @@ function collectVisible(messages, state, countTokens) {
2983
3021
  const coveredIds = /* @__PURE__ */ new Set();
2984
3022
  for (const block of state.blocks) {
2985
3023
  if (!block.active) continue;
2986
- for (const id of block.effectiveMessageIds) coveredIds.add(id);
3024
+ for (const id of block.effectiveMessageIds) coveredIds.add(baseIdOf(id));
2987
3025
  }
2988
3026
  let summaryTokens = 0;
2989
3027
  for (const block of state.blocks) {
@@ -2997,7 +3035,7 @@ function collectVisible(messages, state, countTokens) {
2997
3035
  }
2998
3036
  }
2999
3037
  messages.forEach((message, index) => {
3000
- if (coveredIds.has(message.id)) return;
3038
+ if (coveredIds.has(baseIdOf(message.id))) return;
3001
3039
  const ref = refForRaw(state.messageRefs, message.id);
3002
3040
  if (!ref) return;
3003
3041
  const tokens = countTokens(message.text ?? "");
@@ -4097,6 +4135,7 @@ export {
4097
4135
  applyAbsorb,
4098
4136
  applyMessageFilters,
4099
4137
  assignRefs,
4138
+ baseIdOf,
4100
4139
  blockById,
4101
4140
  blockDocs,
4102
4141
  blockVisibleInRange,
@@ -4135,6 +4174,7 @@ export {
4135
4174
  highestUsedIndex,
4136
4175
  indexToRef,
4137
4176
  isAbsorbCandidate,
4177
+ isCovered,
4138
4178
  isMessageProtected,
4139
4179
  isRenderedSummaryMessage,
4140
4180
  isSummaryMessageId,