acp-kernel 0.0.47 → 0.0.48-pr.181.34

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.
@@ -6,18 +6,23 @@ export interface ParsedBoundary {
6
6
  raw: string;
7
7
  }
8
8
  export declare function parseBoundary(ref: string): ParsedBoundary | null;
9
+ export type BoundaryFailureReason = "consumed" | "generation-replaced" | "edit-drift";
9
10
  /**
10
11
  * Thrown when a boundary ref parses but cannot be anchored in the visible
11
12
  * context. `kind` distinguishes a ref that never existed ("unknown", e.g. a
12
- * typo or a ref from another session) from one that was consumed by an
13
- * existing block ("consumed", messages hidden by prune). `endpoint` names the
14
- * failing side of the range so callers can attribute the error precisely.
13
+ * typo or a ref from another session) from one whose content is gone
14
+ * ("consumed"). `reason` classifies the consumed case: "consumed" (an active
15
+ * block covers it — retry with the block ref), "generation-replaced" (the
16
+ * covering block was itself distilled/consumed — content no longer
17
+ * available), "edit-drift" (the message was edited or removed, changing its
18
+ * content id). `endpoint` names the failing side of the range.
15
19
  */
16
20
  export declare class BoundaryNotFoundError extends Error {
17
21
  readonly code = "BOUNDARY_NOT_FOUND";
18
22
  readonly kind: "unknown" | "consumed";
19
23
  readonly endpoint: "start" | "end";
20
- constructor(kind: "unknown" | "consumed", endpoint: "start" | "end", message: string);
24
+ readonly reason: BoundaryFailureReason | null;
25
+ constructor(kind: "unknown" | "consumed", endpoint: "start" | "end", message: string, reason?: BoundaryFailureReason | null);
21
26
  }
22
27
  export interface ResolveBoundariesInput {
23
28
  startRef: string;
@@ -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,IA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;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,CA+U7D;AA04BD,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -4,10 +4,11 @@ export type { Ports, CompressionCore, ProcessTurnInput, ApplyCompressionInput, }
4
4
  export { createInitialState, allocateBlockId, allocateRunId, blockById, activeBlocks, coveredMessageIds, highestActiveTier, advanceSurvival, } from "./state.js";
5
5
  export { defaultConfig, validateConfig } from "./config.js";
6
6
  export * from "./compress-tools.js";
7
- export { assignRefs, highestUsedIndex, emptyRefMap, indexToRef, refToIndex, refForRaw, rawForRef, BLOCKED_REF, } from "./refs.js";
7
+ export { assignRefs, highestUsedIndex, emptyRefMap, indexToRef, refToIndex, refForRaw, rawForRef, pruneDeadRefs, BLOCKED_REF, } from "./refs.js";
8
8
  export { prune, 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
+ export type { BoundaryFailureReason } from "./boundaries.js";
11
12
  export { defaultCountTokens, estimateTokensFast, createBpeTokenizer, } from "./tokenize.js";
12
13
  export type { TokenCountFn } from "./tokenize.js";
13
14
  export { renderNudgeText, formatRanges } from "./nudge-text.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,EACL,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChE,YAAY,EAA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Y,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,SAAS,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"}
package/dist/index.js CHANGED
@@ -77,18 +77,42 @@ function assignRefs(messages, options) {
77
77
  return { map, nextIndex: cursor, newlyAssigned };
78
78
  }
79
79
  function allocateFreeRef(map, start) {
80
- let candidate = Math.max(start, MIN_INDEX);
81
- while (candidate <= MAX_INDEX) {
80
+ const from = Math.max(start, MIN_INDEX);
81
+ for (let candidate = from; candidate <= MAX_INDEX; candidate++) {
82
+ const text = indexToRef(candidate);
83
+ if (!map.byRef[text]) {
84
+ return { text, index: candidate };
85
+ }
86
+ }
87
+ for (let candidate = MIN_INDEX; candidate < from; candidate++) {
82
88
  const text = indexToRef(candidate);
83
89
  if (!map.byRef[text]) {
84
90
  return { text, index: candidate };
85
91
  }
86
- candidate++;
87
92
  }
88
93
  throw new Error(
89
- `ref capacity exhausted: cannot allocate beyond ${indexToRef(MAX_INDEX)}`
94
+ `ref capacity exhausted: all ${MAX_INDEX} ref slots are occupied by live messages \u2014 nothing left to reclaim`
90
95
  );
91
96
  }
97
+ function pruneDeadRefs(map, liveIds) {
98
+ let pruned = 0;
99
+ const byRaw = {};
100
+ for (const [rawId, ref] of Object.entries(map.byRaw)) {
101
+ if (liveIds.has(rawId)) {
102
+ byRaw[rawId] = ref;
103
+ continue;
104
+ }
105
+ pruned++;
106
+ }
107
+ return { map: rebuildRefIndex({ byRaw, byRef: {} }), pruned };
108
+ }
109
+ function rebuildRefIndex(map) {
110
+ const byRef = {};
111
+ for (const [rawId, ref] of Object.entries(map.byRaw)) {
112
+ if (ref !== BLOCKED_REF) byRef[ref] = rawId;
113
+ }
114
+ return { byRaw: { ...map.byRaw }, byRef };
115
+ }
92
116
  function highestUsedIndex(map) {
93
117
  let highest = 0;
94
118
  for (const ref of Object.values(map.byRaw)) {
@@ -284,6 +308,10 @@ function syncBlocks(messages, state) {
284
308
  block.active = false;
285
309
  continue;
286
310
  }
311
+ if (block.expanded) {
312
+ block.active = false;
313
+ continue;
314
+ }
287
315
  block.active = true;
288
316
  const stillPresent = block.effectiveMessageIds.some((id) => presentIds.has(id)) || presentIds.has(summaryMessageId(block.blockId));
289
317
  if (!stillPresent) {
@@ -291,6 +319,13 @@ function syncBlocks(messages, state) {
291
319
  deactivated.push(block.blockId);
292
320
  }
293
321
  }
322
+ const liveIds = new Set(presentIds);
323
+ for (const block of result.blocks) {
324
+ if (!block.active) continue;
325
+ for (const id of block.effectiveMessageIds) liveIds.add(id);
326
+ }
327
+ const prunedRefs = pruneDeadRefs(result.messageRefs, liveIds);
328
+ result.messageRefs = prunedRefs.map;
294
329
  return { state: result, deactivated };
295
330
  }
296
331
 
@@ -405,12 +440,14 @@ var BoundaryNotFoundError = class extends Error {
405
440
  code = "BOUNDARY_NOT_FOUND";
406
441
  kind;
407
442
  endpoint;
408
- constructor(kind, endpoint, message) {
443
+ reason;
444
+ constructor(kind, endpoint, message, reason = null) {
409
445
  super(message);
410
446
  this.name = "BoundaryNotFoundError";
411
447
  this.code = "BOUNDARY_NOT_FOUND";
412
448
  this.kind = kind;
413
449
  this.endpoint = endpoint;
450
+ this.reason = reason;
414
451
  }
415
452
  };
416
453
  function resolveBoundaries(input) {
@@ -481,7 +518,7 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
481
518
  throw new BoundaryNotFoundError(
482
519
  "unknown",
483
520
  endpoint,
484
- `${label}="${boundary.raw}" does not exist in this session (typo or wrong session) \u2014 run acp_status for current refs.`
521
+ `${label}="${boundary.raw}" does not exist in this session (typo, wrong session, or the message was edited/removed and its ref released) \u2014 run acp_status for current refs.`
485
522
  );
486
523
  }
487
524
  const index = indexByMessageId.get(rawId);
@@ -495,10 +532,33 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
495
532
  snapped: `${label}="${boundary.raw}" refers to a message already compressed into an active block \u2014 anchored to the active block covering it instead.`
496
533
  };
497
534
  }
535
+ const coveringActive = state.blocks.filter(
536
+ (block2) => block2.active && block2.effectiveMessageIds.includes(rawId)
537
+ );
538
+ if (coveringActive.length > 0) {
539
+ throw new BoundaryNotFoundError(
540
+ "consumed",
541
+ endpoint,
542
+ `${label}="${boundary.raw}" is already compressed into active block(s) ${coveringActive.map((block2) => block2.blockId).join(", ")} \u2014 retry with the block ref(s) instead of the message ref.`,
543
+ "consumed"
544
+ );
545
+ }
546
+ const generationReplaced = state.blocks.some(
547
+ (block2) => !block2.active && block2.effectiveMessageIds.includes(rawId)
548
+ );
549
+ if (generationReplaced) {
550
+ throw new BoundaryNotFoundError(
551
+ "consumed",
552
+ endpoint,
553
+ `${label}="${boundary.raw}" was compressed into a block that has since been distilled or consumed \u2014 its content is no longer available in this session; run acp_status for current refs.`,
554
+ "generation-replaced"
555
+ );
556
+ }
498
557
  throw new BoundaryNotFoundError(
499
558
  "consumed",
500
559
  endpoint,
501
- `${label}="${boundary.raw}" not found in visible context (likely consumed by an existing block).`
560
+ `${label}="${boundary.raw}" no longer exists \u2014 the message was edited or removed (its content id changed); run acp_status for current refs.`,
561
+ "edit-drift"
502
562
  );
503
563
  }
504
564
  const block = blockById(state, `b${boundary.numericId}`);
@@ -527,16 +587,21 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
527
587
  };
528
588
  }
529
589
  if (!block.active) {
590
+ const consumer = state.blocks.find(
591
+ (candidate) => candidate.active && candidate.directBlockIds.includes(block.blockId) && visibleBlockAnchor(candidate, indexByMessageId) !== null
592
+ );
530
593
  throw new BoundaryNotFoundError(
531
594
  "consumed",
532
595
  endpoint,
533
- `${label}="b${boundary.numericId}" not found in visible context (block distilled/consumed by a higher-tier block).`
596
+ consumer ? `${label}="b${boundary.numericId}" was consumed by ${consumer.blockId} (higher-tier block) \u2014 retry with ${consumer.blockId} instead.` : `${label}="b${boundary.numericId}" is inactive (distilled or garbage-collected) and none of its content is visible in the current context \u2014 run acp_status for current refs.`,
597
+ "generation-replaced"
534
598
  );
535
599
  }
536
600
  throw new BoundaryNotFoundError(
537
601
  "consumed",
538
602
  endpoint,
539
- `${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.`
603
+ `${label}="b${boundary.numericId}" is an active block but none of its content (raw messages or rendered summary) is present in the current view \u2014 its messages were likely edited or removed (id drift); it will be deactivated on the next state sync. Run acp_status to verify.`,
604
+ "edit-drift"
540
605
  );
541
606
  }
542
607
  function activeOwnerAnchor(state, ownedIds, indexByMessageId) {
@@ -1861,10 +1926,33 @@ function numericBlockId(id) {
1861
1926
  const parsed = /^b(\d+)$/.exec(id);
1862
1927
  return parsed ? Number(parsed[1]) : 0;
1863
1928
  }
1929
+ function refGateDiagnostics(state, requestedRanges, unknownCount) {
1930
+ const highest = highestUsedIndex(state.messageRefs);
1931
+ const highestRef = highest > 0 ? indexToRef(highest) : "none";
1932
+ return `[diagnostics: session highest ref=${highestRef}, unknown ranges in request=${unknownCount}/${requestedRanges}, session history=${state.stats.compressionCount} compression(s), ${state.blocks.length} block(s)]`;
1933
+ }
1934
+ function danglingMessageRefs(state, messages, spec) {
1935
+ const visible = new Set(messages.map((m) => m.id));
1936
+ const dangling = [];
1937
+ for (const ref of [spec.startRef, spec.endRef]) {
1938
+ const parsed = parseBoundary(ref);
1939
+ if (!parsed || parsed.kind !== "message") continue;
1940
+ const rawId = state.messageRefs.byRef[parsed.raw] ?? state.messageRefs.byRef[indexToRef(parsed.numericId)];
1941
+ if (!rawId || visible.has(rawId)) continue;
1942
+ const covered = state.blocks.some(
1943
+ (block) => block.active && block.effectiveMessageIds.includes(rawId)
1944
+ );
1945
+ if (!covered) dangling.push(parsed.raw);
1946
+ }
1947
+ return dangling;
1948
+ }
1864
1949
  function createCore(ports = {}) {
1865
1950
  const countTokens = ports.countTokens ?? defaultCountTokens;
1866
1951
  function applyCompression(input) {
1867
- const state = cloneState(input.state);
1952
+ const state = syncBlocks(
1953
+ input.messages,
1954
+ input.state
1955
+ ).state;
1868
1956
  const runId = allocateRunId(state);
1869
1957
  let blocksCreated = 0;
1870
1958
  let tokensCompressed = 0;
@@ -1961,7 +2049,15 @@ function createCore(ports = {}) {
1961
2049
  if (!hasBlockBoundaryRange && totalRangeChars < input.config.compress.minCompressRange) {
1962
2050
  const live = activeBlocks(state).map((b) => b.blockId).sort((x, y) => numericBlockId(x) - numericBlockId(y));
1963
2051
  const liveHint = live.length > 0 ? ` Current active blocks span ${live[0]}..${live[live.length - 1]} \u2014 retry with startId/endId set to active block IDs in that span.` : "";
1964
- const gateMessage = resolvableCount === 0 && consumedRanges.length === 0 && unknownCount > 0 ? `None of the ${input.ranges.length} requested range(s) resolved \u2014 every ref failed with "does not exist in this session". Refs recorded before an earlier compress are stale: each successful compress renumbers the remaining refs. Run acp_status, then call the compress tool again using only the refs it reports.` : consumedRanges.length > 0 ? `Requested range(s) already compressed (e.g. ${consumedRanges[0].startRef}..${consumedRanges[0].endRef}) \u2014 your refs are stale: a prior compress renumbered the remaining refs, so this range now falls inside an active block. Run acp_status, then call the compress tool again using only the CURRENT compressible ranges it reports.${liveHint}` : `Total compressible content too small (${totalRangeChars} chars across ${countedRanges} range(s), min ${input.config.compress.minCompressRange}). Combine more messages into your range(s) to meet the threshold.`;
2052
+ const diagnostics = refGateDiagnostics(
2053
+ state,
2054
+ input.ranges.length,
2055
+ unknownCount
2056
+ );
2057
+ const danglingRefs = consumedRanges.flatMap(
2058
+ (spec) => danglingMessageRefs(state, input.messages, spec)
2059
+ );
2060
+ const gateMessage = resolvableCount === 0 && consumedRanges.length === 0 && unknownCount > 0 ? `None of the ${input.ranges.length} requested range(s) resolved \u2014 every ref is unknown to this session. Refs are per-session snapshots, assigned once when a message is first rendered; no compress reassigns them, so unknown refs cannot come from an earlier compress in this session. They come from a different generation: a previous session instance (switching model or upstream mid-conversation starts a fresh session whose refs restart at m00001), the generation before a native-compaction rebase (which also resets refs to m00001), a typo, or a message that was edited or removed (its old ref was released when the content id changed). ${diagnostics} Run acp_status, then call the compress tool again using only the refs it reports.` : consumedRanges.length > 0 ? danglingRefs.length > 0 ? `Requested range(s) cannot be anchored (e.g. ${consumedRanges[0].startRef}..${consumedRanges[0].endRef}) \u2014 the refs exist in this session's ref map, but the messages they point to are no longer in the visible context and no active block covers them: the message content changed (or the message was filtered out of the view) and now carries a new ref, leaving your old refs dangling. ${diagnostics} Run acp_status, then call the compress tool again using only the refs it reports.` : `Requested range(s) already compressed (e.g. ${consumedRanges[0].startRef}..${consumedRanges[0].endRef}) \u2014 those refs no longer point to directly compressible content: the range is covered by active block(s) or the block ref(s) are stale (distilled or consumed). ${diagnostics} Run acp_status, then call the compress tool again using only the CURRENT compressible ranges it reports.${liveHint}` : `Total compressible content too small (${totalRangeChars} chars across ${countedRanges} range(s), min ${input.config.compress.minCompressRange}). Combine more messages into your range(s) to meet the threshold.`;
1965
2061
  return {
1966
2062
  state: input.state,
1967
2063
  result: {
@@ -2104,9 +2200,15 @@ var assignRefsNode = {
2104
2200
  run(io, ctx) {
2105
2201
  const hasProtection = ctx.config.protectedTools.length > 0 || !!ctx.config.isToolProtected;
2106
2202
  const protectedFn = hasProtection ? (m) => isMessageProtected(m, ctx.config) : void 0;
2203
+ const liveIds = new Set(io.messages.map((m) => m.id));
2204
+ for (const block of io.state.blocks) {
2205
+ if (!block.active) continue;
2206
+ for (const id of block.effectiveMessageIds) liveIds.add(id);
2207
+ }
2208
+ const pruned = pruneDeadRefs(io.state.messageRefs, liveIds);
2107
2209
  const refResult = assignRefs(io.messages, {
2108
- existing: io.state.messageRefs,
2109
- nextIndex: highestUsedIndex(io.state.messageRefs) + 1,
2210
+ existing: pruned.map,
2211
+ nextIndex: highestUsedIndex(pruned.map) + 1,
2110
2212
  isProtected: protectedFn
2111
2213
  });
2112
2214
  return { ...io, state: { ...io.state, messageRefs: refResult.map } };
@@ -2678,26 +2780,6 @@ function computeContextBreakdown(messages, total, growth, countTokens) {
2678
2780
  }
2679
2781
  return { system, tool, summaries, code, text, total, growth };
2680
2782
  }
2681
- function cloneState(state) {
2682
- return {
2683
- blocks: state.blocks.map((block) => ({
2684
- ...block,
2685
- directMessageIds: [...block.directMessageIds],
2686
- effectiveMessageIds: [...block.effectiveMessageIds],
2687
- directBlockIds: [...block.directBlockIds]
2688
- })),
2689
- messageRefs: {
2690
- byRaw: { ...state.messageRefs.byRaw },
2691
- byRef: { ...state.messageRefs.byRef }
2692
- },
2693
- tokenSnapshot: { ...state.tokenSnapshot ?? {} },
2694
- nudge: { ...state.nudge, anchors: { ...state.nudge.anchors } },
2695
- stats: { ...state.stats },
2696
- absorbed: (state.absorbed ?? []).map((record) => ({ ...record })),
2697
- nextBlockId: state.nextBlockId,
2698
- nextRunId: state.nextRunId
2699
- };
2700
- }
2701
2783
  function scoreRelevance(block, terms) {
2702
2784
  const topic = (block.topic ?? "").toLowerCase();
2703
2785
  const summary = block.summary.toLowerCase();
@@ -3411,9 +3493,15 @@ function salvageContentEntries(raw) {
3411
3493
  // src/rebuild.ts
3412
3494
  function rebuildCompressionState(state, messages, config, ports = {}) {
3413
3495
  const core = createCore({ countTokens: ports.countTokens ?? defaultCountTokens });
3496
+ const liveIds = new Set(messages.map((message) => message.id));
3497
+ for (const block of state.blocks) {
3498
+ if (!block.active) continue;
3499
+ for (const id of block.effectiveMessageIds) liveIds.add(id);
3500
+ }
3501
+ const pruned = pruneDeadRefs(state.messageRefs, liveIds);
3414
3502
  const refResult = assignRefs(messages, {
3415
- existing: state.messageRefs,
3416
- nextIndex: highestUsedIndex(state.messageRefs) + 1
3503
+ existing: pruned.map,
3504
+ nextIndex: highestUsedIndex(pruned.map) + 1
3417
3505
  });
3418
3506
  let working = { ...state, messageRefs: refResult.map };
3419
3507
  const invocations = collectCompressInvocations(messages);
@@ -3885,6 +3973,7 @@ export {
3885
3973
  parseCompressArgs,
3886
3974
  parseCompressInput,
3887
3975
  prune,
3976
+ pruneDeadRefs,
3888
3977
  rawForRef,
3889
3978
  rebuildCompressionState,
3890
3979
  refForRaw,