acp-kernel 0.0.59-pr.232.81 → 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.
- package/dist/boundaries.d.ts +3 -3
- package/dist/boundaries.d.ts.map +1 -1
- package/dist/compress.d.ts.map +1 -1
- package/dist/decompress.d.ts.map +1 -1
- package/dist/hide-consumed.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +141 -115
- package/dist/index.js.map +1 -1
- package/dist/prune.d.ts +15 -0
- package/dist/prune.d.ts.map +1 -1
- package/dist/recommend.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
|
@@ -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
|
package/dist/boundaries.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundaries.d.ts","sourceRoot":"","sources":["../src/boundaries.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"boundaries.d.ts","sourceRoot":"","sources":["../src/boundaries.ts"],"names":[],"mappings":"AAMA,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,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,wBAAwB;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,KAAK,CAAC;gBAGjC,IAAI,EAAE,SAAS,GAAG,UAAU,EAC5B,QAAQ,EAAE,OAAO,GAAG,KAAK,EACzB,OAAO,EAAE,MAAM;CAQlB;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,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,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ACN,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;AAmED,wBAAgB,UAAU,CAAC,KAAK,GAAE,KAAU,GAAG,eAAe,CAyU7D;AAm9BD,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/decompress.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAElF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO1D;AAED,wBAAgB,6BAA6B,CACzC,KAAK,EAAE,gBAAgB,EACvB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,GACxB,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAElF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO1D;AAED,wBAAgB,6BAA6B,CACzC,KAAK,EAAE,gBAAgB,EACvB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,GACxB,gBAAgB,EAAE,CAYpB;A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ide-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";
|
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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,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"}
|
|
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,EAA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Y,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
|
@@ -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
|
|
129
|
+
const baseIndexById = /* @__PURE__ */ new Map();
|
|
121
130
|
const summaryIndexById = /* @__PURE__ */ new Map();
|
|
122
131
|
messages.forEach((message, index) => {
|
|
123
|
-
|
|
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,
|
|
139
|
+
const anchors = inject ? collectSummaryAnchors(state, baseIndexById, summaryIndexById) : [];
|
|
128
140
|
return stripOrphanedReasoning(
|
|
129
141
|
stripOrphanedToolResults(
|
|
130
142
|
stripOrphanedToolCalls(
|
|
131
|
-
rebuildMessages(messages,
|
|
143
|
+
rebuildMessages(messages, coveredBases, firstUserIndex, anchors)
|
|
132
144
|
)
|
|
133
145
|
)
|
|
134
146
|
);
|
|
135
147
|
}
|
|
136
|
-
function collectSummaryAnchors(state,
|
|
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 =
|
|
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,
|
|
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 (
|
|
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) =>
|
|
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
|
-
|
|
433
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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 =
|
|
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,71 +710,25 @@ var KEEP_LAST_ORPHANED = 2;
|
|
|
666
710
|
function rangeKey(startRef, endRef) {
|
|
667
711
|
return `${startRef}::${endRef}`;
|
|
668
712
|
}
|
|
669
|
-
function
|
|
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(
|
|
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
|
-
|
|
682
|
-
|
|
683
|
-
if (Array.isArray(obj.content)) {
|
|
684
|
-
content = obj.content;
|
|
685
|
-
} else if (typeof obj.content === "string") {
|
|
686
|
-
contentWasString = true;
|
|
687
|
-
try {
|
|
688
|
-
const inner = JSON.parse(obj.content);
|
|
689
|
-
if (Array.isArray(inner)) content = inner;
|
|
690
|
-
} catch {
|
|
691
|
-
content = null;
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
if (!content || content.length === 0) return null;
|
|
695
|
-
return { prefix: raw.slice(0, start), obj, content, contentWasString };
|
|
696
|
-
}
|
|
697
|
-
function rewriteCompressText(text, liveKeys) {
|
|
698
|
-
const parsed = parseCallText(text);
|
|
699
|
-
if (!parsed) return null;
|
|
700
|
-
const { prefix, obj, content, contentWasString } = parsed;
|
|
722
|
+
const content = obj.content;
|
|
723
|
+
if (!Array.isArray(content) || content.length === 0) return null;
|
|
701
724
|
const kept = content.filter((entry) => {
|
|
702
725
|
if (!entry || typeof entry !== "object") return false;
|
|
703
|
-
const
|
|
704
|
-
const
|
|
705
|
-
|
|
706
|
-
return liveKeys.has(rangeKey(s, end));
|
|
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));
|
|
707
729
|
});
|
|
708
|
-
if (kept.length === 0) return null;
|
|
709
|
-
return
|
|
710
|
-
}
|
|
711
|
-
var SUMMARY_STUB_CHARS = 200;
|
|
712
|
-
function compactEntry(entry) {
|
|
713
|
-
if (!entry || typeof entry !== "object") return entry;
|
|
714
|
-
const e = entry;
|
|
715
|
-
if (typeof e.summary !== "string" || e.summary.length <= SUMMARY_STUB_CHARS) return entry;
|
|
716
|
-
return { ...e, summary: `${e.summary.slice(0, SUMMARY_STUB_CHARS - 1)}\u2026` };
|
|
717
|
-
}
|
|
718
|
-
function serializeCompacted(obj, content, contentWasString) {
|
|
719
|
-
let changed = false;
|
|
720
|
-
const compacted = content.map((entry) => {
|
|
721
|
-
const out = compactEntry(entry);
|
|
722
|
-
if (out !== entry) changed = true;
|
|
723
|
-
return out;
|
|
724
|
-
});
|
|
725
|
-
const outContent = contentWasString ? JSON.stringify(compacted) : compacted;
|
|
726
|
-
return { text: JSON.stringify({ ...obj, content: outContent }), changed };
|
|
727
|
-
}
|
|
728
|
-
function compactCompressText(text) {
|
|
729
|
-
const parsed = parseCallText(text);
|
|
730
|
-
if (!parsed) return null;
|
|
731
|
-
const { prefix, obj, content, contentWasString } = parsed;
|
|
732
|
-
const { text: out, changed } = serializeCompacted(obj, content, contentWasString);
|
|
733
|
-
return changed ? prefix + out : null;
|
|
730
|
+
if (kept.length === content.length || kept.length === 0) return null;
|
|
731
|
+
return JSON.stringify({ ...obj, content: kept });
|
|
734
732
|
}
|
|
735
733
|
function hideConsumedCompressCalls(state, messages) {
|
|
736
734
|
const allBlockCallIds = /* @__PURE__ */ new Set();
|
|
@@ -789,11 +787,6 @@ function hideConsumedCompressCalls(state, messages) {
|
|
|
789
787
|
continue;
|
|
790
788
|
}
|
|
791
789
|
}
|
|
792
|
-
const compacted = compactCompressText(message.text);
|
|
793
|
-
if (compacted !== null) {
|
|
794
|
-
result.push({ ...message, text: compacted });
|
|
795
|
-
continue;
|
|
796
|
-
}
|
|
797
790
|
}
|
|
798
791
|
result.push(message);
|
|
799
792
|
}
|
|
@@ -1709,20 +1702,26 @@ function estimateTextTokens(text) {
|
|
|
1709
1702
|
function isToolMessage(message) {
|
|
1710
1703
|
return message.contentType === "tool-call" || message.contentType === "tool-result";
|
|
1711
1704
|
}
|
|
1712
|
-
function
|
|
1713
|
-
|
|
1705
|
+
function activeBlockCoveredBases(state) {
|
|
1706
|
+
const covered = /* @__PURE__ */ new Set();
|
|
1714
1707
|
for (const block of state.blocks) {
|
|
1715
|
-
if (block.active
|
|
1708
|
+
if (!block.active) continue;
|
|
1709
|
+
for (const id of block.effectiveMessageIds) covered.add(baseIdOf(id));
|
|
1716
1710
|
}
|
|
1717
|
-
return
|
|
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));
|
|
1718
1716
|
}
|
|
1719
1717
|
function computeProtectedRefs(messages, state, config, countTokens = estimateTextTokens) {
|
|
1720
1718
|
const preserveN = config.preserveRecentMessages;
|
|
1721
1719
|
const preserveTokens = config.preserveRecentTokens;
|
|
1722
1720
|
const result = /* @__PURE__ */ new Set();
|
|
1723
1721
|
const visible = [];
|
|
1722
|
+
const coveredBases = activeBlockCoveredBases(state);
|
|
1724
1723
|
for (const msg of messages) {
|
|
1725
|
-
if (isSyntheticOrPruned(msg,
|
|
1724
|
+
if (isSyntheticOrPruned(msg, coveredBases)) continue;
|
|
1726
1725
|
if (isNeverPreserveRecent(msg)) continue;
|
|
1727
1726
|
const ref = state.messageRefs.byRaw[msg.id];
|
|
1728
1727
|
if (!ref || ref === "BLOCKED") continue;
|
|
@@ -1743,7 +1742,7 @@ function computeProtectedRefs(messages, state, config, countTokens = estimateTex
|
|
|
1743
1742
|
if (preserveN > 0) {
|
|
1744
1743
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1745
1744
|
const msg = messages[i];
|
|
1746
|
-
if (msg.role !== "user" || isSyntheticOrPruned(msg,
|
|
1745
|
+
if (msg.role !== "user" || isSyntheticOrPruned(msg, coveredBases)) continue;
|
|
1747
1746
|
const ref = state.messageRefs.byRaw[msg.id];
|
|
1748
1747
|
if (ref && ref !== "BLOCKED") result.add(ref);
|
|
1749
1748
|
break;
|
|
@@ -1757,10 +1756,11 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
1757
1756
|
const protectedCallIds = collectProtectedToolCallIds(messages, config);
|
|
1758
1757
|
let skipSinceCompressible = false;
|
|
1759
1758
|
let skipSinceProtected = false;
|
|
1759
|
+
const coveredBases = activeBlockCoveredBases(state);
|
|
1760
1760
|
for (const msg of messages) {
|
|
1761
1761
|
const ref = state.messageRefs.byRaw[msg.id];
|
|
1762
1762
|
if (!ref || ref === "BLOCKED") continue;
|
|
1763
|
-
if (isSyntheticOrPruned(msg,
|
|
1763
|
+
if (isSyntheticOrPruned(msg, coveredBases)) {
|
|
1764
1764
|
skipSinceCompressible = true;
|
|
1765
1765
|
skipSinceProtected = true;
|
|
1766
1766
|
continue;
|
|
@@ -1927,16 +1927,22 @@ function refGateDiagnostics(state, requestedRanges, unknownCount) {
|
|
|
1927
1927
|
}
|
|
1928
1928
|
function danglingMessageRefs(state, messages, spec) {
|
|
1929
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
|
+
}
|
|
1930
1937
|
const dangling = [];
|
|
1931
1938
|
for (const ref of [spec.startRef, spec.endRef]) {
|
|
1932
1939
|
const parsed = parseBoundary(ref);
|
|
1933
1940
|
if (!parsed || parsed.kind !== "message") continue;
|
|
1934
1941
|
const rawId = state.messageRefs.byRef[parsed.raw] ?? state.messageRefs.byRef[indexToRef(parsed.numericId)];
|
|
1935
|
-
if (!rawId
|
|
1936
|
-
const
|
|
1937
|
-
|
|
1938
|
-
);
|
|
1939
|
-
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);
|
|
1940
1946
|
}
|
|
1941
1947
|
return dangling;
|
|
1942
1948
|
}
|
|
@@ -2355,13 +2361,25 @@ function applySingleRange(input) {
|
|
|
2355
2361
|
).filter((id) => !isSummaryMessageId(id));
|
|
2356
2362
|
if (rangeMessageIds.length > resolved.messageIds.length) {
|
|
2357
2363
|
const indexByMessageId = /* @__PURE__ */ new Map();
|
|
2358
|
-
|
|
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
|
+
});
|
|
2359
2371
|
const adjustedStart = rangeMessageIds.length > 0 ? indexByMessageId.get(rangeMessageIds[0]) ?? resolved.startIndex : resolved.startIndex;
|
|
2360
2372
|
const adjustedEnd = rangeMessageIds.length > 0 ? indexByMessageId.get(rangeMessageIds[rangeMessageIds.length - 1]) ?? resolved.endIndex : resolved.endIndex;
|
|
2361
2373
|
const nestedSeen = new Set(resolved.nestedBlockIds);
|
|
2362
2374
|
for (const block2 of activeBlocks(input.state)) {
|
|
2363
2375
|
if (nestedSeen.has(block2.blockId)) continue;
|
|
2364
|
-
if (blockVisibleInRange(
|
|
2376
|
+
if (blockVisibleInRange(
|
|
2377
|
+
block2,
|
|
2378
|
+
indexByMessageId,
|
|
2379
|
+
adjustedStart,
|
|
2380
|
+
adjustedEnd,
|
|
2381
|
+
baseIndexById
|
|
2382
|
+
)) {
|
|
2365
2383
|
nestedSeen.add(block2.blockId);
|
|
2366
2384
|
resolved.nestedBlockIds.push(block2.blockId);
|
|
2367
2385
|
}
|
|
@@ -2387,7 +2405,7 @@ function applySingleRange(input) {
|
|
|
2387
2405
|
}
|
|
2388
2406
|
}
|
|
2389
2407
|
const directMessageIds = [...effectiveMessageIds].filter(
|
|
2390
|
-
(id) => !input.preExistingCoverage.has(id)
|
|
2408
|
+
(id) => !input.preExistingCoverage.has(baseIdOf(id))
|
|
2391
2409
|
);
|
|
2392
2410
|
let filteredIds = filterProtectedToolMessages(
|
|
2393
2411
|
directMessageIds,
|
|
@@ -2567,7 +2585,7 @@ function resolveTargetTier(state, nestedBlockIds, isBlockBoundary) {
|
|
|
2567
2585
|
function collectCoverage(state) {
|
|
2568
2586
|
const coverage = /* @__PURE__ */ new Set();
|
|
2569
2587
|
for (const block of activeBlocks(state)) {
|
|
2570
|
-
for (const id of block.effectiveMessageIds) coverage.add(id);
|
|
2588
|
+
for (const id of block.effectiveMessageIds) coverage.add(baseIdOf(id));
|
|
2571
2589
|
}
|
|
2572
2590
|
return coverage;
|
|
2573
2591
|
}
|
|
@@ -2828,10 +2846,12 @@ function parseBlockIdArg(arg) {
|
|
|
2828
2846
|
}
|
|
2829
2847
|
function findBlocksOverlappingMessages(state, messageIds) {
|
|
2830
2848
|
if (messageIds.size === 0) return [];
|
|
2849
|
+
const messageBases = /* @__PURE__ */ new Set();
|
|
2850
|
+
for (const id of messageIds) messageBases.add(baseIdOf(id));
|
|
2831
2851
|
const matched = [];
|
|
2832
2852
|
for (const block of state.blocks) {
|
|
2833
2853
|
if (!block.active) continue;
|
|
2834
|
-
if (block.effectiveMessageIds.some((id) =>
|
|
2854
|
+
if (block.effectiveMessageIds.some((id) => messageBases.has(baseIdOf(id)))) {
|
|
2835
2855
|
matched.push(block);
|
|
2836
2856
|
}
|
|
2837
2857
|
}
|
|
@@ -2888,13 +2908,15 @@ function deactivateBlock(state, blockIds, options = {}) {
|
|
|
2888
2908
|
return { ...state, blocks: final };
|
|
2889
2909
|
}
|
|
2890
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
|
+
}
|
|
2891
2916
|
const restored = [];
|
|
2892
2917
|
for (const message of messages) {
|
|
2893
2918
|
if (!beforeActiveMessageIds.has(message.id)) continue;
|
|
2894
|
-
|
|
2895
|
-
(b) => b.active && b.effectiveMessageIds.includes(message.id)
|
|
2896
|
-
);
|
|
2897
|
-
if (!stillCovered) restored.push(message);
|
|
2919
|
+
if (!coveredBases.has(baseIdOf(message.id))) restored.push(message);
|
|
2898
2920
|
}
|
|
2899
2921
|
if (restored.length === 0) return { preview: "", restoredCount: 0 };
|
|
2900
2922
|
const lines = [];
|
|
@@ -2913,9 +2935,10 @@ function buildRestoredContentPreview(messages, beforeActiveMessageIds, state) {
|
|
|
2913
2935
|
}
|
|
2914
2936
|
function collectBlockContent(state, block, messages, options = {}) {
|
|
2915
2937
|
const full = options.full ?? false;
|
|
2916
|
-
const
|
|
2938
|
+
const targetBases = /* @__PURE__ */ new Set();
|
|
2939
|
+
for (const id of block.effectiveMessageIds) targetBases.add(baseIdOf(id));
|
|
2917
2940
|
if (full) {
|
|
2918
|
-
const msgs = messages.filter((m) =>
|
|
2941
|
+
const msgs = messages.filter((m) => targetBases.has(baseIdOf(m.id)));
|
|
2919
2942
|
if (msgs.length === 0) return { text: "", count: 0 };
|
|
2920
2943
|
return { text: msgs.map(formatMessage).join("\n\n"), count: msgs.length };
|
|
2921
2944
|
}
|
|
@@ -2925,7 +2948,7 @@ function collectBlockContent(state, block, messages, options = {}) {
|
|
|
2925
2948
|
const child = state.blocks.find((b) => b.blockId === childId);
|
|
2926
2949
|
if (!child?.active) continue;
|
|
2927
2950
|
nestedChildren.push(child);
|
|
2928
|
-
for (const id of child.effectiveMessageIds) nestedCovered.add(id);
|
|
2951
|
+
for (const id of child.effectiveMessageIds) nestedCovered.add(baseIdOf(id));
|
|
2929
2952
|
}
|
|
2930
2953
|
const parts = [];
|
|
2931
2954
|
for (const child of nestedChildren) {
|
|
@@ -2935,7 +2958,8 @@ ${child.summary}`);
|
|
|
2935
2958
|
}
|
|
2936
2959
|
let directCount = 0;
|
|
2937
2960
|
for (const m of messages) {
|
|
2938
|
-
|
|
2961
|
+
const base = baseIdOf(m.id);
|
|
2962
|
+
if (targetBases.has(base) && !nestedCovered.has(base)) {
|
|
2939
2963
|
parts.push(formatMessage(m));
|
|
2940
2964
|
directCount++;
|
|
2941
2965
|
}
|
|
@@ -2997,7 +3021,7 @@ function collectVisible(messages, state, countTokens) {
|
|
|
2997
3021
|
const coveredIds = /* @__PURE__ */ new Set();
|
|
2998
3022
|
for (const block of state.blocks) {
|
|
2999
3023
|
if (!block.active) continue;
|
|
3000
|
-
for (const id of block.effectiveMessageIds) coveredIds.add(id);
|
|
3024
|
+
for (const id of block.effectiveMessageIds) coveredIds.add(baseIdOf(id));
|
|
3001
3025
|
}
|
|
3002
3026
|
let summaryTokens = 0;
|
|
3003
3027
|
for (const block of state.blocks) {
|
|
@@ -3011,7 +3035,7 @@ function collectVisible(messages, state, countTokens) {
|
|
|
3011
3035
|
}
|
|
3012
3036
|
}
|
|
3013
3037
|
messages.forEach((message, index) => {
|
|
3014
|
-
if (coveredIds.has(message.id)) return;
|
|
3038
|
+
if (coveredIds.has(baseIdOf(message.id))) return;
|
|
3015
3039
|
const ref = refForRaw(state.messageRefs, message.id);
|
|
3016
3040
|
if (!ref) return;
|
|
3017
3041
|
const tokens = countTokens(message.text ?? "");
|
|
@@ -4111,6 +4135,7 @@ export {
|
|
|
4111
4135
|
applyAbsorb,
|
|
4112
4136
|
applyMessageFilters,
|
|
4113
4137
|
assignRefs,
|
|
4138
|
+
baseIdOf,
|
|
4114
4139
|
blockById,
|
|
4115
4140
|
blockDocs,
|
|
4116
4141
|
blockVisibleInRange,
|
|
@@ -4149,6 +4174,7 @@ export {
|
|
|
4149
4174
|
highestUsedIndex,
|
|
4150
4175
|
indexToRef,
|
|
4151
4176
|
isAbsorbCandidate,
|
|
4177
|
+
isCovered,
|
|
4152
4178
|
isMessageProtected,
|
|
4153
4179
|
isRenderedSummaryMessage,
|
|
4154
4180
|
isSummaryMessageId,
|