acp-kernel 0.0.49 → 0.0.50-pr.195.46

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,23 +6,18 @@ 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";
10
9
  /**
11
10
  * Thrown when a boundary ref parses but cannot be anchored in the visible
12
11
  * context. `kind` distinguishes a ref that never existed ("unknown", e.g. a
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.
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.
19
15
  */
20
16
  export declare class BoundaryNotFoundError extends Error {
21
17
  readonly code = "BOUNDARY_NOT_FOUND";
22
18
  readonly kind: "unknown" | "consumed";
23
19
  readonly endpoint: "start" | "end";
24
- readonly reason: BoundaryFailureReason | null;
25
- constructor(kind: "unknown" | "consumed", endpoint: "start" | "end", message: string, reason?: BoundaryFailureReason | null);
20
+ constructor(kind: "unknown" | "consumed", endpoint: "start" | "end", message: string);
26
21
  }
27
22
  export interface ResolveBoundariesInput {
28
23
  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,IAAI,EA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MAAM,CAAC;IACf,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,sBAAsB,GAC5B,aAAa,CAuEf;AAgJD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,gBAAgB,EACvB,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,MAAM,GAAG,IAAI,CAIf;AAOD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,gBAAgB,EACvB,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACrC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAcT;AAED,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EAAE,EACb,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,MAAM,GAAG,IAAI,CASf;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,GAAG,gBAAgB,CAMzE"}
@@ -9,7 +9,8 @@ function createInitialState() {
9
9
  lastNudgeShownTokens: 0,
10
10
  baselineTokens: 0,
11
11
  anchors: {},
12
- lastShownByTier: {}
12
+ lastShownByTier: {},
13
+ everInjected: false
13
14
  },
14
15
  stats: { tokensCompressed: 0, compressionCount: 0, absorbedTokens: 0 },
15
16
  absorbed: [],
@@ -68,4 +69,4 @@ export {
68
69
  highestActiveTier,
69
70
  advanceSurvival
70
71
  };
71
- //# sourceMappingURL=chunk-UX4LINT7.js.map
72
+ //# sourceMappingURL=chunk-562X5HLA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state.ts"],"sourcesContent":["import type { CompressionBlock, CompressionState } from \"./types.js\";\n\nexport function createInitialState(): CompressionState {\n return {\n blocks: [],\n messageRefs: { byRaw: {}, byRef: {} },\n tokenSnapshot: {},\n nudge: {\n lastPerMessageNudgeTokens: 0,\n lastNudgeShownTokens: 0,\n baselineTokens: 0,\n anchors: {},\n lastShownByTier: {},\n everInjected: false,\n },\n stats: { tokensCompressed: 0, compressionCount: 0, absorbedTokens: 0 },\n absorbed: [],\n nextBlockId: 1,\n nextRunId: 1,\n };\n}\n\nexport function allocateBlockId(state: CompressionState): string {\n const id = state.nextBlockId;\n state.nextBlockId = Math.max(1, id) + 1;\n return `b${id}`;\n}\n\nexport function allocateRunId(state: CompressionState): string {\n const id = state.nextRunId;\n state.nextRunId = Math.max(1, id) + 1;\n return `r${id}`;\n}\n\nexport function blockById(\n state: CompressionState,\n blockId: string,\n): CompressionBlock | undefined {\n return state.blocks.find((block) => block.blockId === blockId);\n}\n\nexport function activeBlocks(state: CompressionState): CompressionBlock[] {\n return state.blocks.filter((block) => block.active);\n}\n\nexport function coveredMessageIds(state: CompressionState): Set<string> {\n const covered = new Set<string>();\n for (const block of state.blocks) {\n if (!block.active) continue;\n for (const id of block.effectiveMessageIds) covered.add(id);\n }\n return covered;\n}\n\nexport function highestActiveTier(state: CompressionState): 0 | 1 | 2 | 3 {\n let highest: 0 | 1 | 2 | 3 = 0;\n for (const block of state.blocks) {\n if (block.active && block.tier > highest) highest = block.tier;\n }\n return highest;\n}\n\nexport function advanceSurvival(\n state: CompressionState,\n promotionThreshold: number,\n): void {\n for (const block of state.blocks) {\n if (!block.active) continue;\n block.survivedCount += 1;\n if (block.survivedCount >= promotionThreshold) {\n block.generation = \"old\";\n }\n }\n}\n"],"mappings":";AAEO,SAAS,qBAAuC;AACrD,SAAO;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,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;AAm6BD,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -4,11 +4,10 @@ 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, pruneDeadRefs, BLOCKED_REF, } from "./refs.js";
7
+ export { assignRefs, highestUsedIndex, emptyRefMap, indexToRef, refToIndex, refForRaw, rawForRef, 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";
12
11
  export { defaultCountTokens, estimateTokensFast, createBpeTokenizer, } from "./tokenize.js";
13
12
  export type { TokenCountFn } from "./tokenize.js";
14
13
  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,aAAa,EACb,WAAW,GACZ,MAAM,WAAW,CAAC;AAC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ACZ,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"}
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,EA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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
@@ -1,3 +1,13 @@
1
+ import {
2
+ activeBlocks,
3
+ advanceSurvival,
4
+ allocateBlockId,
5
+ allocateRunId,
6
+ blockById,
7
+ coveredMessageIds,
8
+ createInitialState,
9
+ highestActiveTier
10
+ } from "./chunk-562X5HLA.js";
1
11
  import {
2
12
  COMPRESS_PHILOSOPHY,
3
13
  HOW_TO_COMPRESS_RULES,
@@ -13,16 +23,6 @@ import {
13
23
  resolvePrompts,
14
24
  viableRanges
15
25
  } from "./chunk-MWXUJVMN.js";
16
- import {
17
- activeBlocks,
18
- advanceSurvival,
19
- allocateBlockId,
20
- allocateRunId,
21
- blockById,
22
- coveredMessageIds,
23
- createInitialState,
24
- highestActiveTier
25
- } from "./chunk-UX4LINT7.js";
26
26
 
27
27
  // src/refs.ts
28
28
  var REF_WIDTH = 5;
@@ -77,42 +77,18 @@ function assignRefs(messages, options) {
77
77
  return { map, nextIndex: cursor, newlyAssigned };
78
78
  }
79
79
  function allocateFreeRef(map, start) {
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++) {
80
+ let candidate = Math.max(start, MIN_INDEX);
81
+ while (candidate <= MAX_INDEX) {
88
82
  const text = indexToRef(candidate);
89
83
  if (!map.byRef[text]) {
90
84
  return { text, index: candidate };
91
85
  }
86
+ candidate++;
92
87
  }
93
88
  throw new Error(
94
- `ref capacity exhausted: all ${MAX_INDEX} ref slots are occupied by live messages \u2014 nothing left to reclaim`
89
+ `ref capacity exhausted: cannot allocate beyond ${indexToRef(MAX_INDEX)}`
95
90
  );
96
91
  }
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
- }
116
92
  function highestUsedIndex(map) {
117
93
  let highest = 0;
118
94
  for (const ref of Object.values(map.byRaw)) {
@@ -315,13 +291,6 @@ function syncBlocks(messages, state) {
315
291
  deactivated.push(block.blockId);
316
292
  }
317
293
  }
318
- const liveIds = new Set(presentIds);
319
- for (const block of result.blocks) {
320
- if (!block.active) continue;
321
- for (const id of block.effectiveMessageIds) liveIds.add(id);
322
- }
323
- const prunedRefs = pruneDeadRefs(result.messageRefs, liveIds);
324
- result.messageRefs = prunedRefs.map;
325
294
  return { state: result, deactivated };
326
295
  }
327
296
 
@@ -436,14 +405,12 @@ var BoundaryNotFoundError = class extends Error {
436
405
  code = "BOUNDARY_NOT_FOUND";
437
406
  kind;
438
407
  endpoint;
439
- reason;
440
- constructor(kind, endpoint, message, reason = null) {
408
+ constructor(kind, endpoint, message) {
441
409
  super(message);
442
410
  this.name = "BoundaryNotFoundError";
443
411
  this.code = "BOUNDARY_NOT_FOUND";
444
412
  this.kind = kind;
445
413
  this.endpoint = endpoint;
446
- this.reason = reason;
447
414
  }
448
415
  };
449
416
  function resolveBoundaries(input) {
@@ -514,7 +481,7 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
514
481
  throw new BoundaryNotFoundError(
515
482
  "unknown",
516
483
  endpoint,
517
- `${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.`
484
+ `${label}="${boundary.raw}" does not exist in this session (typo or wrong session) \u2014 run acp_status for current refs.`
518
485
  );
519
486
  }
520
487
  const index = indexByMessageId.get(rawId);
@@ -528,33 +495,10 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
528
495
  snapped: `${label}="${boundary.raw}" refers to a message already compressed into an active block \u2014 anchored to the active block covering it instead.`
529
496
  };
530
497
  }
531
- const coveringActive = state.blocks.filter(
532
- (block2) => block2.active && block2.effectiveMessageIds.includes(rawId)
533
- );
534
- if (coveringActive.length > 0) {
535
- throw new BoundaryNotFoundError(
536
- "consumed",
537
- endpoint,
538
- `${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.`,
539
- "consumed"
540
- );
541
- }
542
- const generationReplaced = state.blocks.some(
543
- (block2) => !block2.active && block2.effectiveMessageIds.includes(rawId)
544
- );
545
- if (generationReplaced) {
546
- throw new BoundaryNotFoundError(
547
- "consumed",
548
- endpoint,
549
- `${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.`,
550
- "generation-replaced"
551
- );
552
- }
553
498
  throw new BoundaryNotFoundError(
554
499
  "consumed",
555
500
  endpoint,
556
- `${label}="${boundary.raw}" no longer exists \u2014 the message was edited or removed (its content id changed); run acp_status for current refs.`,
557
- "edit-drift"
501
+ `${label}="${boundary.raw}" not found in visible context (likely consumed by an existing block).`
558
502
  );
559
503
  }
560
504
  const block = blockById(state, `b${boundary.numericId}`);
@@ -583,21 +527,16 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
583
527
  };
584
528
  }
585
529
  if (!block.active) {
586
- const consumer = state.blocks.find(
587
- (candidate) => candidate.active && candidate.directBlockIds.includes(block.blockId) && visibleBlockAnchor(candidate, indexByMessageId) !== null
588
- );
589
530
  throw new BoundaryNotFoundError(
590
531
  "consumed",
591
532
  endpoint,
592
- 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.`,
593
- "generation-replaced"
533
+ `${label}="b${boundary.numericId}" not found in visible context (block distilled/consumed by a higher-tier block).`
594
534
  );
595
535
  }
596
536
  throw new BoundaryNotFoundError(
597
537
  "consumed",
598
538
  endpoint,
599
- `${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.`,
600
- "edit-drift"
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.`
601
540
  );
602
541
  }
603
542
  function activeOwnerAnchor(state, ownedIds, indexByMessageId) {
@@ -1945,10 +1884,7 @@ function danglingMessageRefs(state, messages, spec) {
1945
1884
  function createCore(ports = {}) {
1946
1885
  const countTokens = ports.countTokens ?? defaultCountTokens;
1947
1886
  function applyCompression(input) {
1948
- const state = syncBlocks(
1949
- input.messages,
1950
- input.state
1951
- ).state;
1887
+ const state = cloneState(input.state);
1952
1888
  const runId = allocateRunId(state);
1953
1889
  let blocksCreated = 0;
1954
1890
  let tokensCompressed = 0;
@@ -2053,7 +1989,7 @@ function createCore(ports = {}) {
2053
1989
  const danglingRefs = consumedRanges.flatMap(
2054
1990
  (spec) => danglingMessageRefs(state, input.messages, spec)
2055
1991
  );
2056
- 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.`;
1992
+ 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), or a typo. ${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.`;
2057
1993
  return {
2058
1994
  state: input.state,
2059
1995
  result: {
@@ -2196,15 +2132,9 @@ var assignRefsNode = {
2196
2132
  run(io, ctx) {
2197
2133
  const hasProtection = ctx.config.protectedTools.length > 0 || !!ctx.config.isToolProtected;
2198
2134
  const protectedFn = hasProtection ? (m) => isMessageProtected(m, ctx.config) : void 0;
2199
- const liveIds = new Set(io.messages.map((m) => m.id));
2200
- for (const block of io.state.blocks) {
2201
- if (!block.active) continue;
2202
- for (const id of block.effectiveMessageIds) liveIds.add(id);
2203
- }
2204
- const pruned = pruneDeadRefs(io.state.messageRefs, liveIds);
2205
2135
  const refResult = assignRefs(io.messages, {
2206
- existing: pruned.map,
2207
- nextIndex: highestUsedIndex(pruned.map) + 1,
2136
+ existing: io.state.messageRefs,
2137
+ nextIndex: highestUsedIndex(io.state.messageRefs) + 1,
2208
2138
  isProtected: protectedFn
2209
2139
  });
2210
2140
  return { ...io, state: { ...io.state, messageRefs: refResult.map } };
@@ -2319,6 +2249,7 @@ var nudgeNode = {
2319
2249
  }
2320
2250
  if (nudge.shouldInject) {
2321
2251
  stamped.lastNudgeShownTokens = ctx.tokenCount;
2252
+ stamped.everInjected = true;
2322
2253
  if (nudge.tier !== null) {
2323
2254
  stamped.lastShownByTier = {
2324
2255
  ...stamped.lastShownByTier,
@@ -2649,6 +2580,7 @@ function decideNudge(input) {
2649
2580
  const t3Pen = tiers[3]?.pending ?? 0;
2650
2581
  const t2Count = tiers[2]?.targetBlocks.length ?? 0;
2651
2582
  const t3Count = tiers[3]?.targetBlocks.length ?? 0;
2583
+ const inheritedReady = !state.nudge.everInjected && !hasPendingNudge && t1Eff >= nudgeGrowthTokens;
2652
2584
  if (pressure) {
2653
2585
  const candidates = [1];
2654
2586
  if (config.tiers.enabled) {
@@ -2668,10 +2600,11 @@ function decideNudge(input) {
2668
2600
  const label = emergencyOverride ? "EMERGENCY" : "OVER-LIMIT";
2669
2601
  injectedReason = best === 1 ? `${label} T1: max effective pending ${bestPending}, usage ${Math.round(usage * 100)}%` : `${label} T${best} distill: max pending ${bestPending} (T1 effective ${t1Eff}, T2 ${t2Pen}, T3 ${t3Pen}), usage ${Math.round(usage * 100)}%`;
2670
2602
  }
2671
- } else if (growthReady) {
2603
+ } else if (growthReady || inheritedReady) {
2672
2604
  if (t1Eff >= nudgeGrowthTokens) {
2673
2605
  injectedTier = 1;
2674
- injectedReason = `T1 effective ${t1Eff} >= ${nudgeGrowthTokens}, growth ${growthSinceReference}, usage ${Math.round(usage * 100)}%`;
2606
+ const waived = !growthReady;
2607
+ injectedReason = `T1 effective ${t1Eff} >= ${nudgeGrowthTokens}, growth ${growthSinceReference}, usage ${Math.round(usage * 100)}%${waived ? " (growth gate waived: inherited ready mass)" : ""}`;
2675
2608
  } else if (config.tiers.enabled && (t2Count >= config.tiers.tier2Trigger || t2Pen >= tier2Threshold && t2Pen > t1Eff)) {
2676
2609
  const lastShown = state.nudge.lastShownByTier[2] ?? 0;
2677
2610
  const cadenceMet = lastShown === 0 || tokenCount - lastShown >= growthFloor;
@@ -2750,6 +2683,7 @@ function decideNudge(input) {
2750
2683
  hasPendingNudge: hasPendingNudge ? 1 : 0,
2751
2684
  overLimit: overLimit ? 1 : 0,
2752
2685
  emergencyOverride: emergencyOverride ? 1 : 0,
2686
+ inheritedReady: inheritedReady ? 1 : 0,
2753
2687
  pendingT1: tiers[1].pending,
2754
2688
  pendingT2: tiers[2].pending,
2755
2689
  pendingT3: tiers[3].pending
@@ -2776,6 +2710,26 @@ function computeContextBreakdown(messages, total, growth, countTokens) {
2776
2710
  }
2777
2711
  return { system, tool, summaries, code, text, total, growth };
2778
2712
  }
2713
+ function cloneState(state) {
2714
+ return {
2715
+ blocks: state.blocks.map((block) => ({
2716
+ ...block,
2717
+ directMessageIds: [...block.directMessageIds],
2718
+ effectiveMessageIds: [...block.effectiveMessageIds],
2719
+ directBlockIds: [...block.directBlockIds]
2720
+ })),
2721
+ messageRefs: {
2722
+ byRaw: { ...state.messageRefs.byRaw },
2723
+ byRef: { ...state.messageRefs.byRef }
2724
+ },
2725
+ tokenSnapshot: { ...state.tokenSnapshot ?? {} },
2726
+ nudge: { ...state.nudge, anchors: { ...state.nudge.anchors } },
2727
+ stats: { ...state.stats },
2728
+ absorbed: (state.absorbed ?? []).map((record) => ({ ...record })),
2729
+ nextBlockId: state.nextBlockId,
2730
+ nextRunId: state.nextRunId
2731
+ };
2732
+ }
2779
2733
  function scoreRelevance(block, terms) {
2780
2734
  const topic = (block.topic ?? "").toLowerCase();
2781
2735
  const summary = block.summary.toLowerCase();
@@ -3548,15 +3502,9 @@ function salvageContentEntries(raw) {
3548
3502
  // src/rebuild.ts
3549
3503
  function rebuildCompressionState(state, messages, config, ports = {}) {
3550
3504
  const core = createCore({ countTokens: ports.countTokens ?? defaultCountTokens });
3551
- const liveIds = new Set(messages.map((message) => message.id));
3552
- for (const block of state.blocks) {
3553
- if (!block.active) continue;
3554
- for (const id of block.effectiveMessageIds) liveIds.add(id);
3555
- }
3556
- const pruned = pruneDeadRefs(state.messageRefs, liveIds);
3557
3505
  const refResult = assignRefs(messages, {
3558
- existing: pruned.map,
3559
- nextIndex: highestUsedIndex(pruned.map) + 1
3506
+ existing: state.messageRefs,
3507
+ nextIndex: highestUsedIndex(state.messageRefs) + 1
3560
3508
  });
3561
3509
  let working = { ...state, messageRefs: refResult.map };
3562
3510
  const invocations = collectCompressInvocations(messages);
@@ -4029,7 +3977,6 @@ export {
4029
3977
  parseCompressArgs,
4030
3978
  parseCompressInput,
4031
3979
  prune,
4032
- pruneDeadRefs,
4033
3980
  rawForRef,
4034
3981
  rebuildCompressionState,
4035
3982
  refForRaw,