acp-kernel 0.0.47-pr.176.29 → 0.0.47-pr.177.30
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/boundaries.d.ts +4 -9
- package/dist/boundaries.d.ts.map +1 -1
- package/dist/compress.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -100
- package/dist/index.js.map +1 -1
- package/dist/message-kind.d.ts +11 -0
- package/dist/message-kind.d.ts.map +1 -0
- package/dist/panel/index.js.map +1 -1
- package/dist/panel/panel.d.ts +7 -6
- package/dist/panel/panel.d.ts.map +1 -1
- package/dist/rebuild.d.ts.map +1 -1
- package/dist/recommend.d.ts.map +1 -1
- package/dist/refs.d.ts +0 -5
- package/dist/refs.d.ts.map +1 -1
- package/dist/report.d.ts.map +1 -1
- package/dist/sync.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/boundaries.d.ts
CHANGED
|
@@ -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
|
|
14
|
-
* ("consumed"). `
|
|
15
|
-
*
|
|
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
|
-
|
|
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;
|
package/dist/boundaries.d.ts.map
CHANGED
|
@@ -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
|
|
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,CA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MAAM,CAAC,GACpC,MAAM,GAAG,IAAI,CASf;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,GAAG,gBAAgB,CAMzE"}
|
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;AAchF,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;AAchF,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;AA2BD,wBAAgB,UAAU,CAAC,KAAK,GAAE,KAAU,GAAG,eAAe,CA+T7D;AAm5BD,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,
|
|
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";
|
|
@@ -22,6 +21,7 @@ export { parseBlockIdArg, findBlocksOverlappingMessages, findActiveAncestor, dea
|
|
|
22
21
|
export type { DeactivateOptions, CollectedContentResult, CollectContentOptions, } from "./decompress.js";
|
|
23
22
|
export { buildStatusReport, buildRecap } from "./report.js";
|
|
24
23
|
export type { StatusReportOptions } from "./report.js";
|
|
24
|
+
export { isToolMessage } from "./message-kind.js";
|
|
25
25
|
export { hideConsumedCompressCalls } from "./hide-consumed.js";
|
|
26
26
|
export type { HideConsumedResult } from "./hide-consumed.js";
|
|
27
27
|
export { ABSORB_TOOL_NAME, ABSORB_TOOL, ABSORB_TOOL_OPENAI, } from "./compress-tools.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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,EAAE,UAAU,EAAE,aAAa,EA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AY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,YAAY,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAClH,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,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,42 +77,18 @@ function assignRefs(messages, options) {
|
|
|
77
77
|
return { map, nextIndex: cursor, newlyAssigned };
|
|
78
78
|
}
|
|
79
79
|
function allocateFreeRef(map, start) {
|
|
80
|
-
|
|
81
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
|
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}"
|
|
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
|
-
|
|
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
|
|
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) {
|
|
@@ -1636,6 +1575,11 @@ function createRenderRefsNode(strategy) {
|
|
|
1636
1575
|
}
|
|
1637
1576
|
var renderRefsNode = createRenderRefsNode("all");
|
|
1638
1577
|
|
|
1578
|
+
// src/message-kind.ts
|
|
1579
|
+
function isToolMessage(message) {
|
|
1580
|
+
return message.contentType === "tool-call" || message.contentType === "tool-result";
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1639
1583
|
// src/tool-pairs.ts
|
|
1640
1584
|
function adjustBoundariesForToolPairs(startIndex, endIndex, messages, maxScan = 20) {
|
|
1641
1585
|
const callIdsInRange = /* @__PURE__ */ new Set();
|
|
@@ -1713,9 +1657,6 @@ function refNum(ref) {
|
|
|
1713
1657
|
function estimateTextTokens(text) {
|
|
1714
1658
|
return Math.ceil(text.length / 4);
|
|
1715
1659
|
}
|
|
1716
|
-
function isToolMessage(message) {
|
|
1717
|
-
return message.contentType === "tool-call" || message.contentType === "tool-result";
|
|
1718
|
-
}
|
|
1719
1660
|
function isSyntheticOrPruned(message, state) {
|
|
1720
1661
|
if (message.text?.startsWith("[Compressed conversation section]")) return true;
|
|
1721
1662
|
for (const block of state.blocks) {
|
|
@@ -1925,10 +1866,7 @@ function numericBlockId(id) {
|
|
|
1925
1866
|
function createCore(ports = {}) {
|
|
1926
1867
|
const countTokens = ports.countTokens ?? defaultCountTokens;
|
|
1927
1868
|
function applyCompression(input) {
|
|
1928
|
-
const state =
|
|
1929
|
-
input.messages,
|
|
1930
|
-
input.state
|
|
1931
|
-
).state;
|
|
1869
|
+
const state = cloneState(input.state);
|
|
1932
1870
|
const runId = allocateRunId(state);
|
|
1933
1871
|
let blocksCreated = 0;
|
|
1934
1872
|
let tokensCompressed = 0;
|
|
@@ -2168,15 +2106,9 @@ var assignRefsNode = {
|
|
|
2168
2106
|
run(io, ctx) {
|
|
2169
2107
|
const hasProtection = ctx.config.protectedTools.length > 0 || !!ctx.config.isToolProtected;
|
|
2170
2108
|
const protectedFn = hasProtection ? (m) => isMessageProtected(m, ctx.config) : void 0;
|
|
2171
|
-
const liveIds = new Set(io.messages.map((m) => m.id));
|
|
2172
|
-
for (const block of io.state.blocks) {
|
|
2173
|
-
if (!block.active) continue;
|
|
2174
|
-
for (const id of block.effectiveMessageIds) liveIds.add(id);
|
|
2175
|
-
}
|
|
2176
|
-
const pruned = pruneDeadRefs(io.state.messageRefs, liveIds);
|
|
2177
2109
|
const refResult = assignRefs(io.messages, {
|
|
2178
|
-
existing:
|
|
2179
|
-
nextIndex: highestUsedIndex(
|
|
2110
|
+
existing: io.state.messageRefs,
|
|
2111
|
+
nextIndex: highestUsedIndex(io.state.messageRefs) + 1,
|
|
2180
2112
|
isProtected: protectedFn
|
|
2181
2113
|
});
|
|
2182
2114
|
return { ...io, state: { ...io.state, messageRefs: refResult.map } };
|
|
@@ -2736,7 +2668,7 @@ function computeContextBreakdown(messages, total, growth, countTokens) {
|
|
|
2736
2668
|
const tokens = count(msg.text ?? "");
|
|
2737
2669
|
if (msg.text?.startsWith("[Compressed conversation section]")) {
|
|
2738
2670
|
summaries += tokens;
|
|
2739
|
-
} else if (msg
|
|
2671
|
+
} else if (isToolMessage(msg)) {
|
|
2740
2672
|
tool += tokens;
|
|
2741
2673
|
} else if (msg.role === "system") {
|
|
2742
2674
|
system += tokens;
|
|
@@ -2748,6 +2680,26 @@ function computeContextBreakdown(messages, total, growth, countTokens) {
|
|
|
2748
2680
|
}
|
|
2749
2681
|
return { system, tool, summaries, code, text, total, growth };
|
|
2750
2682
|
}
|
|
2683
|
+
function cloneState(state) {
|
|
2684
|
+
return {
|
|
2685
|
+
blocks: state.blocks.map((block) => ({
|
|
2686
|
+
...block,
|
|
2687
|
+
directMessageIds: [...block.directMessageIds],
|
|
2688
|
+
effectiveMessageIds: [...block.effectiveMessageIds],
|
|
2689
|
+
directBlockIds: [...block.directBlockIds]
|
|
2690
|
+
})),
|
|
2691
|
+
messageRefs: {
|
|
2692
|
+
byRaw: { ...state.messageRefs.byRaw },
|
|
2693
|
+
byRef: { ...state.messageRefs.byRef }
|
|
2694
|
+
},
|
|
2695
|
+
tokenSnapshot: { ...state.tokenSnapshot ?? {} },
|
|
2696
|
+
nudge: { ...state.nudge, anchors: { ...state.nudge.anchors } },
|
|
2697
|
+
stats: { ...state.stats },
|
|
2698
|
+
absorbed: (state.absorbed ?? []).map((record) => ({ ...record })),
|
|
2699
|
+
nextBlockId: state.nextBlockId,
|
|
2700
|
+
nextRunId: state.nextRunId
|
|
2701
|
+
};
|
|
2702
|
+
}
|
|
2751
2703
|
function scoreRelevance(block, terms) {
|
|
2752
2704
|
const topic = (block.topic ?? "").toLowerCase();
|
|
2753
2705
|
const summary = block.summary.toLowerCase();
|
|
@@ -2919,7 +2871,7 @@ function formatTokens2(n) {
|
|
|
2919
2871
|
}
|
|
2920
2872
|
function pct(n, total) {
|
|
2921
2873
|
if (n <= 0 || total <= 0) return 0;
|
|
2922
|
-
return Math.
|
|
2874
|
+
return Math.round(n / total * 100);
|
|
2923
2875
|
}
|
|
2924
2876
|
function numericPart2(blockId) {
|
|
2925
2877
|
const match = /^b(\d+)$/.exec(blockId);
|
|
@@ -2957,14 +2909,21 @@ function collectVisible(messages, state, countTokens) {
|
|
|
2957
2909
|
for (const block of state.blocks) {
|
|
2958
2910
|
if (block.active) summaryTokens += summaryTokensOf(block, countTokens);
|
|
2959
2911
|
}
|
|
2912
|
+
const nameByCallId = /* @__PURE__ */ new Map();
|
|
2913
|
+
for (const message of messages) {
|
|
2914
|
+
if (message.contentType === "tool-call" && message.toolCallId && message.toolName) {
|
|
2915
|
+
nameByCallId.set(message.toolCallId, message.toolName);
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2960
2918
|
const visible = [];
|
|
2961
2919
|
messages.forEach((message, index) => {
|
|
2962
2920
|
if (coveredIds.has(message.id)) return;
|
|
2963
2921
|
const ref = refForRaw(state.messageRefs, message.id);
|
|
2964
2922
|
if (!ref) return;
|
|
2965
2923
|
const tokens = countTokens(message.text ?? "");
|
|
2966
|
-
const
|
|
2967
|
-
|
|
2924
|
+
const isTool = isToolMessage(message);
|
|
2925
|
+
const tool = isTool ? message.toolName ?? (message.toolCallId ? nameByCallId.get(message.toolCallId) : void 0) ?? "tool" : "text";
|
|
2926
|
+
if (tokens > 0) visible.push({ ref, tokens, tool, isTool, index });
|
|
2968
2927
|
});
|
|
2969
2928
|
return { visible, summaryTokens };
|
|
2970
2929
|
}
|
|
@@ -2994,8 +2953,8 @@ function renderOverview(visible, summaryTokens, blocks, state, countTokens, limi
|
|
|
2994
2953
|
toolTypeMap.set(message.tool, (toolTypeMap.get(message.tool) ?? 0) + message.tokens);
|
|
2995
2954
|
}
|
|
2996
2955
|
const topTool = [...toolTypeMap.entries()].sort((a, b) => b[1] - a[1])[0]?.[0];
|
|
2997
|
-
const totalTool = visible.filter((m) => m.
|
|
2998
|
-
const totalText = visible.filter((m) => m.
|
|
2956
|
+
const totalTool = visible.filter((m) => m.isTool).reduce((sum, m) => sum + m.tokens, 0);
|
|
2957
|
+
const totalText = visible.filter((m) => !m.isTool).reduce((sum, m) => sum + m.tokens, 0);
|
|
2999
2958
|
const total = summaryTokens + totalTool + totalText;
|
|
3000
2959
|
lines.push("CONTEXT BREAKDOWN");
|
|
3001
2960
|
lines.push(
|
|
@@ -3461,15 +3420,9 @@ function salvageContentEntries(raw) {
|
|
|
3461
3420
|
// src/rebuild.ts
|
|
3462
3421
|
function rebuildCompressionState(state, messages, config, ports = {}) {
|
|
3463
3422
|
const core = createCore({ countTokens: ports.countTokens ?? defaultCountTokens });
|
|
3464
|
-
const liveIds = new Set(messages.map((message) => message.id));
|
|
3465
|
-
for (const block of state.blocks) {
|
|
3466
|
-
if (!block.active) continue;
|
|
3467
|
-
for (const id of block.effectiveMessageIds) liveIds.add(id);
|
|
3468
|
-
}
|
|
3469
|
-
const pruned = pruneDeadRefs(state.messageRefs, liveIds);
|
|
3470
3423
|
const refResult = assignRefs(messages, {
|
|
3471
|
-
existing:
|
|
3472
|
-
nextIndex: highestUsedIndex(
|
|
3424
|
+
existing: state.messageRefs,
|
|
3425
|
+
nextIndex: highestUsedIndex(state.messageRefs) + 1
|
|
3473
3426
|
});
|
|
3474
3427
|
let working = { ...state, messageRefs: refResult.map };
|
|
3475
3428
|
const invocations = collectCompressInvocations(messages);
|
|
@@ -3930,6 +3883,7 @@ export {
|
|
|
3930
3883
|
isMessageProtected,
|
|
3931
3884
|
isRenderedSummaryMessage,
|
|
3932
3885
|
isSummaryMessageId,
|
|
3886
|
+
isToolMessage,
|
|
3933
3887
|
listMessageFilters,
|
|
3934
3888
|
listSearchAlgorithms,
|
|
3935
3889
|
makeIO,
|
|
@@ -3941,7 +3895,6 @@ export {
|
|
|
3941
3895
|
parseCompressArgs,
|
|
3942
3896
|
parseCompressInput,
|
|
3943
3897
|
prune,
|
|
3944
|
-
pruneDeadRefs,
|
|
3945
3898
|
rawForRef,
|
|
3946
3899
|
rebuildCompressionState,
|
|
3947
3900
|
refForRaw,
|