acp-kernel 0.0.82-pr.229.213 → 0.0.82-pr.235.211
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +135 -62
- 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/search/algorithms/hybrid.d.ts.map +1 -1
- package/dist/search/doc-cache.d.ts +10 -34
- package/dist/search/doc-cache.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,E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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;AAmHD,wBAAgB,UAAU,CAAC,KAAK,GAAE,KAAU,GAAG,eAAe,CAgV7D;AAknCD,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":"AAEA,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":"AAEA,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;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiB1F;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,eAAe,CAC3B,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,GAAE,iBAAsB,GAChC,gBAAgB,CAkClB;AAED,MAAM,WAAW,qBAAqB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,2BAA2B,CACvC,QAAQ,EAAE,WAAW,EAAE,EACvB,sBAAsB,EAAE,GAAG,CAAC,MAAM,CAAC,EACnC,KAAK,EAAE,gBAAgB,GACxB,qBAAqB,CAgCvB;AAED,MAAM,WAAW,sBAAsB;IACnC,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,6GAA6G;IAC7G,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IAClC,kKAAkK;IAClK,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,WAAW,EAAE,EACvB,OAAO,GAAE,qBAA0B,GACpC,sBAAsB,CA0CxB"}
|
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, countMessageTokens, } 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,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,kBA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,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,cAAc,qBAAqB,CAAC;AACpC,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK,EACL,QAAQ,EACR,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE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,45 @@ function summaryMessageId(blockId) {
|
|
|
111
111
|
function isSummaryMessageId(id) {
|
|
112
112
|
return id.startsWith(SUMMARY_ID_PREFIX);
|
|
113
113
|
}
|
|
114
|
+
function baseIdOf(id) {
|
|
115
|
+
const hash = id.indexOf("#");
|
|
116
|
+
return hash > 0 ? id.substring(0, hash) : id;
|
|
117
|
+
}
|
|
118
|
+
function isCovered(id, coveredBases) {
|
|
119
|
+
return coveredBases.has(baseIdOf(id));
|
|
120
|
+
}
|
|
114
121
|
function isRenderedSummaryMessage(message) {
|
|
115
122
|
return isSummaryMessageId(message.id) && message.role === "system" && message.contentType === "text";
|
|
116
123
|
}
|
|
117
124
|
function prune(messages, state, options = {}) {
|
|
118
125
|
const covered = coveredMessageIds(state);
|
|
119
126
|
if (covered.size === 0) return [...messages];
|
|
127
|
+
const coveredBases = /* @__PURE__ */ new Set();
|
|
128
|
+
for (const id of covered) coveredBases.add(baseIdOf(id));
|
|
120
129
|
const inject = options.injectSummaries ?? true;
|
|
121
130
|
const firstUserIndex = messages.findIndex(
|
|
122
131
|
(message) => message.role === "user"
|
|
123
132
|
);
|
|
124
|
-
const
|
|
133
|
+
const baseIndexById = /* @__PURE__ */ new Map();
|
|
125
134
|
const summaryIndexById = /* @__PURE__ */ new Map();
|
|
126
135
|
messages.forEach((message, index) => {
|
|
127
|
-
|
|
136
|
+
const base = baseIdOf(message.id);
|
|
137
|
+
const existing = baseIndexById.get(base);
|
|
138
|
+
if (existing === void 0 || index < existing)
|
|
139
|
+
baseIndexById.set(base, index);
|
|
128
140
|
if (isRenderedSummaryMessage(message))
|
|
129
141
|
summaryIndexById.set(message.id, index);
|
|
130
142
|
});
|
|
131
|
-
const anchors = inject ? collectSummaryAnchors(state,
|
|
143
|
+
const anchors = inject ? collectSummaryAnchors(state, baseIndexById, summaryIndexById) : [];
|
|
132
144
|
return stripOrphanedReasoning(
|
|
133
145
|
stripOrphanedToolResults(
|
|
134
146
|
stripOrphanedToolCalls(
|
|
135
|
-
rebuildMessages(messages,
|
|
147
|
+
rebuildMessages(messages, coveredBases, firstUserIndex, anchors)
|
|
136
148
|
)
|
|
137
149
|
)
|
|
138
150
|
);
|
|
139
151
|
}
|
|
140
|
-
function collectSummaryAnchors(state,
|
|
152
|
+
function collectSummaryAnchors(state, baseIndexById, summaryIndexById) {
|
|
141
153
|
const anchors = [];
|
|
142
154
|
for (const block of activeBlocks(state)) {
|
|
143
155
|
const existingIndex = summaryIndexById.get(summaryMessageId(block.blockId));
|
|
@@ -152,7 +164,7 @@ function collectSummaryAnchors(state, indexById, summaryIndexById) {
|
|
|
152
164
|
}
|
|
153
165
|
let earliest = null;
|
|
154
166
|
for (const id of block.effectiveMessageIds) {
|
|
155
|
-
const index =
|
|
167
|
+
const index = baseIndexById.get(baseIdOf(id));
|
|
156
168
|
if (index !== void 0 && (earliest === null || index < earliest)) {
|
|
157
169
|
earliest = index;
|
|
158
170
|
}
|
|
@@ -197,7 +209,7 @@ function pairSafeAnchorIndex(messages, index) {
|
|
|
197
209
|
}
|
|
198
210
|
return safe;
|
|
199
211
|
}
|
|
200
|
-
function rebuildMessages(messages,
|
|
212
|
+
function rebuildMessages(messages, coveredBases, firstUserIndex, anchors) {
|
|
201
213
|
const safeAnchors = anchors.map((anchor) => ({
|
|
202
214
|
...anchor,
|
|
203
215
|
insertAt: pairSafeAnchorIndex(messages, anchor.insertAt)
|
|
@@ -215,7 +227,7 @@ function rebuildMessages(messages, covered, firstUserIndex, anchors) {
|
|
|
215
227
|
result.push(messages[index]);
|
|
216
228
|
continue;
|
|
217
229
|
}
|
|
218
|
-
if (
|
|
230
|
+
if (isCovered(messages[index].id, coveredBases)) continue;
|
|
219
231
|
if (isRenderedSummaryMessage(messages[index]) && anchoredSummaryIds.has(messages[index].id))
|
|
220
232
|
continue;
|
|
221
233
|
result.push(messages[index]);
|
|
@@ -281,6 +293,8 @@ function stripOrphanedReasoning(messages) {
|
|
|
281
293
|
// src/sync.ts
|
|
282
294
|
function syncBlocks(messages, state) {
|
|
283
295
|
const presentIds = new Set(messages.map((message) => message.id));
|
|
296
|
+
const presentBases = /* @__PURE__ */ new Set();
|
|
297
|
+
for (const message of messages) presentBases.add(baseIdOf(message.id));
|
|
284
298
|
const deactivated = [];
|
|
285
299
|
const result = {
|
|
286
300
|
blocks: state.blocks.map((block) => ({
|
|
@@ -330,7 +344,7 @@ function syncBlocks(messages, state) {
|
|
|
330
344
|
continue;
|
|
331
345
|
}
|
|
332
346
|
block.active = true;
|
|
333
|
-
const stillPresent = block.effectiveMessageIds.some((id) =>
|
|
347
|
+
const stillPresent = block.effectiveMessageIds.some((id) => presentBases.has(baseIdOf(id))) || presentIds.has(summaryMessageId(block.blockId));
|
|
334
348
|
if (!stillPresent) {
|
|
335
349
|
block.active = false;
|
|
336
350
|
deactivated.push(block.blockId);
|
|
@@ -482,14 +496,20 @@ function resolveBoundaries(input) {
|
|
|
482
496
|
);
|
|
483
497
|
}
|
|
484
498
|
const indexByMessageId = /* @__PURE__ */ new Map();
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
499
|
+
const baseIndexById = /* @__PURE__ */ new Map();
|
|
500
|
+
input.messages.forEach((message, index) => {
|
|
501
|
+
indexByMessageId.set(message.id, index);
|
|
502
|
+
const base = baseIdOf(message.id);
|
|
503
|
+
const existing = baseIndexById.get(base);
|
|
504
|
+
if (existing === void 0 || index < existing)
|
|
505
|
+
baseIndexById.set(base, index);
|
|
506
|
+
});
|
|
488
507
|
let snappedBoundaries = [];
|
|
489
508
|
const startAnchor = resolveAnchorIndex(
|
|
490
509
|
start,
|
|
491
510
|
input.state,
|
|
492
511
|
indexByMessageId,
|
|
512
|
+
baseIndexById,
|
|
493
513
|
"start"
|
|
494
514
|
);
|
|
495
515
|
if (startAnchor.snapped) snappedBoundaries.push(startAnchor.snapped);
|
|
@@ -497,6 +517,7 @@ function resolveBoundaries(input) {
|
|
|
497
517
|
end,
|
|
498
518
|
input.state,
|
|
499
519
|
indexByMessageId,
|
|
520
|
+
baseIndexById,
|
|
500
521
|
"end"
|
|
501
522
|
);
|
|
502
523
|
if (endAnchor.snapped) snappedBoundaries.push(endAnchor.snapped);
|
|
@@ -515,7 +536,13 @@ function resolveBoundaries(input) {
|
|
|
515
536
|
const nestedBlockIds = [];
|
|
516
537
|
const nestedSeen = /* @__PURE__ */ new Set();
|
|
517
538
|
for (const block of activeBlocks(input.state)) {
|
|
518
|
-
if (blockVisibleInRange(
|
|
539
|
+
if (blockVisibleInRange(
|
|
540
|
+
block,
|
|
541
|
+
indexByMessageId,
|
|
542
|
+
startIndex,
|
|
543
|
+
endIndex,
|
|
544
|
+
baseIndexById
|
|
545
|
+
)) {
|
|
519
546
|
if (!nestedSeen.has(block.blockId)) {
|
|
520
547
|
nestedSeen.add(block.blockId);
|
|
521
548
|
nestedBlockIds.push(block.blockId);
|
|
@@ -533,7 +560,7 @@ function resolveBoundaries(input) {
|
|
|
533
560
|
snappedBoundaries
|
|
534
561
|
};
|
|
535
562
|
}
|
|
536
|
-
function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
|
|
563
|
+
function resolveAnchorIndex(boundary, state, indexByMessageId, baseIndexById, endpoint) {
|
|
537
564
|
const label = endpoint === "start" ? "startId" : "endId";
|
|
538
565
|
if (boundary.kind === "message") {
|
|
539
566
|
const rawId = state.messageRefs.byRef[boundary.raw] ?? state.messageRefs.byRef[formatPaddedRef(boundary.numericId)];
|
|
@@ -544,11 +571,11 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
|
|
|
544
571
|
`${label}="${boundary.raw}" does not exist in this session (typo or wrong session) \u2014 run acp_status for current refs.`
|
|
545
572
|
);
|
|
546
573
|
}
|
|
547
|
-
const index = indexByMessageId.get(rawId);
|
|
574
|
+
const index = indexByMessageId.get(rawId) ?? baseIndexById.get(baseIdOf(rawId));
|
|
548
575
|
if (index !== void 0) {
|
|
549
576
|
return { index, snapped: null };
|
|
550
577
|
}
|
|
551
|
-
const owner2 = activeOwnerAnchor(state, [rawId], indexByMessageId);
|
|
578
|
+
const owner2 = activeOwnerAnchor(state, [rawId], indexByMessageId, baseIndexById);
|
|
552
579
|
if (owner2 !== null) {
|
|
553
580
|
return {
|
|
554
581
|
index: owner2,
|
|
@@ -570,7 +597,7 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
|
|
|
570
597
|
);
|
|
571
598
|
}
|
|
572
599
|
if (block.active) {
|
|
573
|
-
const anchor = visibleBlockAnchor(block, indexByMessageId);
|
|
600
|
+
const anchor = visibleBlockAnchor(block, indexByMessageId, baseIndexById);
|
|
574
601
|
if (anchor !== null) {
|
|
575
602
|
return { index: anchor, snapped: null };
|
|
576
603
|
}
|
|
@@ -578,7 +605,8 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
|
|
|
578
605
|
const owner = activeOwnerAnchor(
|
|
579
606
|
state,
|
|
580
607
|
block.effectiveMessageIds,
|
|
581
|
-
indexByMessageId
|
|
608
|
+
indexByMessageId,
|
|
609
|
+
baseIndexById
|
|
582
610
|
);
|
|
583
611
|
if (owner !== null) {
|
|
584
612
|
return {
|
|
@@ -599,9 +627,10 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
|
|
|
599
627
|
`${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.`
|
|
600
628
|
);
|
|
601
629
|
}
|
|
602
|
-
function activeOwnerAnchor(state, ownedIds, indexByMessageId) {
|
|
630
|
+
function activeOwnerAnchor(state, ownedIds, indexByMessageId, baseIndexById) {
|
|
603
631
|
if (ownedIds.length === 0) return null;
|
|
604
|
-
const owned = new Set(
|
|
632
|
+
const owned = /* @__PURE__ */ new Set();
|
|
633
|
+
for (const id of ownedIds) owned.add(baseIdOf(id));
|
|
605
634
|
let best = null;
|
|
606
635
|
for (const block of state.blocks) {
|
|
607
636
|
if (!block.active) continue;
|
|
@@ -614,7 +643,7 @@ function activeOwnerAnchor(state, ownedIds, indexByMessageId) {
|
|
|
614
643
|
}
|
|
615
644
|
}
|
|
616
645
|
if (!ownsInherited) continue;
|
|
617
|
-
const anchor = visibleBlockAnchor(block, indexByMessageId);
|
|
646
|
+
const anchor = visibleBlockAnchor(block, indexByMessageId, baseIndexById);
|
|
618
647
|
if (anchor === null) continue;
|
|
619
648
|
if (best === null || anchor < best) {
|
|
620
649
|
best = anchor;
|
|
@@ -627,39 +656,54 @@ function inheritedContentIds(state, block) {
|
|
|
627
656
|
for (const childId of block.directBlockIds) {
|
|
628
657
|
const child = blockById(state, childId);
|
|
629
658
|
if (!child) continue;
|
|
630
|
-
for (const id of child.effectiveMessageIds) ids.add(id);
|
|
659
|
+
for (const id of child.effectiveMessageIds) ids.add(baseIdOf(id));
|
|
631
660
|
}
|
|
632
661
|
return ids;
|
|
633
662
|
}
|
|
634
663
|
function formatPaddedRef(index) {
|
|
635
664
|
return `m${String(index).padStart(5, "0")}`;
|
|
636
665
|
}
|
|
637
|
-
function visibleBlockAnchor(block, indexByMessageId) {
|
|
666
|
+
function visibleBlockAnchor(block, indexByMessageId, baseIndexById) {
|
|
638
667
|
const summaryIndex = indexByMessageId.get(summaryMessageId(block.blockId));
|
|
639
668
|
if (summaryIndex !== void 0) return summaryIndex;
|
|
640
|
-
return earliestIndexOfIds(
|
|
669
|
+
return earliestIndexOfIds(
|
|
670
|
+
block.effectiveMessageIds,
|
|
671
|
+
indexByMessageId,
|
|
672
|
+
baseIndexById
|
|
673
|
+
);
|
|
641
674
|
}
|
|
642
|
-
function blockVisibleInRange(block, indexByMessageId, startIndex, endIndex) {
|
|
675
|
+
function blockVisibleInRange(block, indexByMessageId, startIndex, endIndex, baseIndexById) {
|
|
643
676
|
const summaryIndex = indexByMessageId.get(summaryMessageId(block.blockId));
|
|
644
677
|
if (summaryIndex !== void 0 && summaryIndex >= startIndex && summaryIndex <= endIndex) {
|
|
645
678
|
return true;
|
|
646
679
|
}
|
|
647
680
|
const rawIndex = earliestIndexOfIds(
|
|
648
681
|
block.effectiveMessageIds,
|
|
649
|
-
indexByMessageId
|
|
682
|
+
indexByMessageId,
|
|
683
|
+
baseIndexById
|
|
650
684
|
);
|
|
651
685
|
return rawIndex !== null && rawIndex >= startIndex && rawIndex <= endIndex;
|
|
652
686
|
}
|
|
653
|
-
function earliestIndexOfIds(ids, indexByMessageId) {
|
|
687
|
+
function earliestIndexOfIds(ids, indexByMessageId, baseIndexById) {
|
|
688
|
+
const baseIndex = baseIndexById ?? deriveBaseIndex(indexByMessageId);
|
|
654
689
|
let earliest = null;
|
|
655
690
|
for (const id of ids) {
|
|
656
|
-
const index =
|
|
691
|
+
const index = baseIndex.get(baseIdOf(id));
|
|
657
692
|
if (index !== void 0 && (earliest === null || index < earliest)) {
|
|
658
693
|
earliest = index;
|
|
659
694
|
}
|
|
660
695
|
}
|
|
661
696
|
return earliest;
|
|
662
697
|
}
|
|
698
|
+
function deriveBaseIndex(indexByMessageId) {
|
|
699
|
+
const baseIndex = /* @__PURE__ */ new Map();
|
|
700
|
+
for (const [id, index] of indexByMessageId) {
|
|
701
|
+
const base = baseIdOf(id);
|
|
702
|
+
const existing = baseIndex.get(base);
|
|
703
|
+
if (existing === void 0 || index < existing) baseIndex.set(base, index);
|
|
704
|
+
}
|
|
705
|
+
return baseIndex;
|
|
706
|
+
}
|
|
663
707
|
|
|
664
708
|
// src/truncate-tools.ts
|
|
665
709
|
var TRUNCATION_MARKER = "[truncated for context space]";
|
|
@@ -2191,20 +2235,26 @@ function estimateTextTokens(text) {
|
|
|
2191
2235
|
function isToolMessage(message) {
|
|
2192
2236
|
return message.contentType === "tool-call" || message.contentType === "tool-result";
|
|
2193
2237
|
}
|
|
2194
|
-
function
|
|
2195
|
-
|
|
2238
|
+
function activeBlockCoveredBases(state) {
|
|
2239
|
+
const covered = /* @__PURE__ */ new Set();
|
|
2196
2240
|
for (const block of state.blocks) {
|
|
2197
|
-
if (block.active
|
|
2241
|
+
if (!block.active) continue;
|
|
2242
|
+
for (const id of block.effectiveMessageIds) covered.add(baseIdOf(id));
|
|
2198
2243
|
}
|
|
2199
|
-
return
|
|
2244
|
+
return covered;
|
|
2245
|
+
}
|
|
2246
|
+
function isSyntheticOrPruned(message, coveredBases) {
|
|
2247
|
+
if (message.text?.startsWith("[Compressed conversation section]")) return true;
|
|
2248
|
+
return coveredBases.has(baseIdOf(message.id));
|
|
2200
2249
|
}
|
|
2201
2250
|
function computeProtectedRefs(messages, state, config, countTokens = estimateTextTokens) {
|
|
2202
2251
|
const preserveN = config.preserveRecentMessages;
|
|
2203
2252
|
const preserveTokens = config.preserveRecentTokens;
|
|
2204
2253
|
const result = /* @__PURE__ */ new Set();
|
|
2205
2254
|
const visible = [];
|
|
2255
|
+
const coveredBases = activeBlockCoveredBases(state);
|
|
2206
2256
|
for (const msg of messages) {
|
|
2207
|
-
if (isSyntheticOrPruned(msg,
|
|
2257
|
+
if (isSyntheticOrPruned(msg, coveredBases)) continue;
|
|
2208
2258
|
if (isNeverPreserveRecent(msg)) continue;
|
|
2209
2259
|
const ref = state.messageRefs.byRaw[msg.id];
|
|
2210
2260
|
if (!ref || ref === "BLOCKED") continue;
|
|
@@ -2225,7 +2275,7 @@ function computeProtectedRefs(messages, state, config, countTokens = estimateTex
|
|
|
2225
2275
|
if (preserveN > 0) {
|
|
2226
2276
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
2227
2277
|
const msg = messages[i];
|
|
2228
|
-
if (msg.role !== "user" || isSyntheticOrPruned(msg,
|
|
2278
|
+
if (msg.role !== "user" || isSyntheticOrPruned(msg, coveredBases)) continue;
|
|
2229
2279
|
const ref = state.messageRefs.byRaw[msg.id];
|
|
2230
2280
|
if (ref && ref !== "BLOCKED") result.add(ref);
|
|
2231
2281
|
break;
|
|
@@ -2242,11 +2292,12 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
2242
2292
|
let skipSinceCompressible = false;
|
|
2243
2293
|
let skipSinceProtected = false;
|
|
2244
2294
|
let msgIndex = -1;
|
|
2295
|
+
const coveredBases = activeBlockCoveredBases(state);
|
|
2245
2296
|
for (const msg of messages) {
|
|
2246
2297
|
msgIndex++;
|
|
2247
2298
|
const ref = state.messageRefs.byRaw[msg.id];
|
|
2248
2299
|
if (!ref || ref === "BLOCKED") continue;
|
|
2249
|
-
if (isSyntheticOrPruned(msg,
|
|
2300
|
+
if (isSyntheticOrPruned(msg, coveredBases)) {
|
|
2250
2301
|
skipSinceCompressible = true;
|
|
2251
2302
|
skipSinceProtected = true;
|
|
2252
2303
|
continue;
|
|
@@ -2447,16 +2498,22 @@ function refGateDiagnostics(state, requestedRanges, unknownCount) {
|
|
|
2447
2498
|
}
|
|
2448
2499
|
function danglingMessageRefs(state, messages, spec) {
|
|
2449
2500
|
const visible = new Set(messages.map((m) => m.id));
|
|
2501
|
+
const visibleBases = /* @__PURE__ */ new Set();
|
|
2502
|
+
for (const id of visible) visibleBases.add(baseIdOf(id));
|
|
2503
|
+
const coveredBases = /* @__PURE__ */ new Set();
|
|
2504
|
+
for (const block of state.blocks) {
|
|
2505
|
+
if (!block.active) continue;
|
|
2506
|
+
for (const id of block.effectiveMessageIds) coveredBases.add(baseIdOf(id));
|
|
2507
|
+
}
|
|
2450
2508
|
const dangling = [];
|
|
2451
2509
|
for (const ref of [spec.startRef, spec.endRef]) {
|
|
2452
2510
|
const parsed = parseBoundary(ref);
|
|
2453
2511
|
if (!parsed || parsed.kind !== "message") continue;
|
|
2454
2512
|
const rawId = state.messageRefs.byRef[parsed.raw] ?? state.messageRefs.byRef[indexToRef(parsed.numericId)];
|
|
2455
|
-
if (!rawId
|
|
2456
|
-
const
|
|
2457
|
-
|
|
2458
|
-
);
|
|
2459
|
-
if (!covered) dangling.push(parsed.raw);
|
|
2513
|
+
if (!rawId) continue;
|
|
2514
|
+
const base = baseIdOf(rawId);
|
|
2515
|
+
if (visible.has(rawId) || visibleBases.has(base)) continue;
|
|
2516
|
+
if (!coveredBases.has(base)) dangling.push(parsed.raw);
|
|
2460
2517
|
}
|
|
2461
2518
|
return dangling;
|
|
2462
2519
|
}
|
|
@@ -2963,13 +3020,25 @@ function applySingleRange(input) {
|
|
|
2963
3020
|
);
|
|
2964
3021
|
if (rangeMessageIds.length > resolved.messageIds.length) {
|
|
2965
3022
|
const indexByMessageId = /* @__PURE__ */ new Map();
|
|
2966
|
-
|
|
3023
|
+
const baseIndexById = /* @__PURE__ */ new Map();
|
|
3024
|
+
input.messages.forEach((m, i) => {
|
|
3025
|
+
indexByMessageId.set(m.id, i);
|
|
3026
|
+
const base = baseIdOf(m.id);
|
|
3027
|
+
const existing = baseIndexById.get(base);
|
|
3028
|
+
if (existing === void 0 || i < existing) baseIndexById.set(base, i);
|
|
3029
|
+
});
|
|
2967
3030
|
const adjustedStart = rangeMessageIds.length > 0 ? indexByMessageId.get(rangeMessageIds[0]) ?? resolved.startIndex : resolved.startIndex;
|
|
2968
3031
|
const adjustedEnd = rangeMessageIds.length > 0 ? indexByMessageId.get(rangeMessageIds[rangeMessageIds.length - 1]) ?? resolved.endIndex : resolved.endIndex;
|
|
2969
3032
|
const nestedSeen = new Set(resolved.nestedBlockIds);
|
|
2970
3033
|
for (const block2 of activeBlocks(input.state)) {
|
|
2971
3034
|
if (nestedSeen.has(block2.blockId)) continue;
|
|
2972
|
-
if (blockVisibleInRange(
|
|
3035
|
+
if (blockVisibleInRange(
|
|
3036
|
+
block2,
|
|
3037
|
+
indexByMessageId,
|
|
3038
|
+
adjustedStart,
|
|
3039
|
+
adjustedEnd,
|
|
3040
|
+
baseIndexById
|
|
3041
|
+
)) {
|
|
2973
3042
|
nestedSeen.add(block2.blockId);
|
|
2974
3043
|
resolved.nestedBlockIds.push(block2.blockId);
|
|
2975
3044
|
}
|
|
@@ -2995,7 +3064,7 @@ function applySingleRange(input) {
|
|
|
2995
3064
|
}
|
|
2996
3065
|
}
|
|
2997
3066
|
const directMessageIds = [...effectiveMessageIds].filter(
|
|
2998
|
-
(id) => !input.preExistingCoverage.has(id)
|
|
3067
|
+
(id) => !input.preExistingCoverage.has(baseIdOf(id))
|
|
2999
3068
|
);
|
|
3000
3069
|
let filteredIds = filterProtectedToolMessages(
|
|
3001
3070
|
directMessageIds,
|
|
@@ -3201,7 +3270,7 @@ function resolveTargetTier(state, nestedBlockIds, isBlockBoundary) {
|
|
|
3201
3270
|
function collectCoverage(state) {
|
|
3202
3271
|
const coverage = /* @__PURE__ */ new Set();
|
|
3203
3272
|
for (const block of activeBlocks(state)) {
|
|
3204
|
-
for (const id of block.effectiveMessageIds) coverage.add(id);
|
|
3273
|
+
for (const id of block.effectiveMessageIds) coverage.add(baseIdOf(id));
|
|
3205
3274
|
}
|
|
3206
3275
|
return coverage;
|
|
3207
3276
|
}
|
|
@@ -3716,10 +3785,12 @@ function parseBlockIdArg(arg) {
|
|
|
3716
3785
|
}
|
|
3717
3786
|
function findBlocksOverlappingMessages(state, messageIds) {
|
|
3718
3787
|
if (messageIds.size === 0) return [];
|
|
3788
|
+
const messageBases = /* @__PURE__ */ new Set();
|
|
3789
|
+
for (const id of messageIds) messageBases.add(baseIdOf(id));
|
|
3719
3790
|
const matched = [];
|
|
3720
3791
|
for (const block of state.blocks) {
|
|
3721
3792
|
if (!block.active) continue;
|
|
3722
|
-
if (block.effectiveMessageIds.some((id) =>
|
|
3793
|
+
if (block.effectiveMessageIds.some((id) => messageBases.has(baseIdOf(id)))) {
|
|
3723
3794
|
matched.push(block);
|
|
3724
3795
|
}
|
|
3725
3796
|
}
|
|
@@ -3776,13 +3847,15 @@ function deactivateBlock(state, blockIds, options = {}) {
|
|
|
3776
3847
|
return { ...state, blocks: final };
|
|
3777
3848
|
}
|
|
3778
3849
|
function buildRestoredContentPreview(messages, beforeActiveMessageIds, state) {
|
|
3850
|
+
const coveredBases = /* @__PURE__ */ new Set();
|
|
3851
|
+
for (const b of state.blocks) {
|
|
3852
|
+
if (!b.active) continue;
|
|
3853
|
+
for (const id of b.effectiveMessageIds) coveredBases.add(baseIdOf(id));
|
|
3854
|
+
}
|
|
3779
3855
|
const restored = [];
|
|
3780
3856
|
for (const message of messages) {
|
|
3781
3857
|
if (!beforeActiveMessageIds.has(message.id)) continue;
|
|
3782
|
-
|
|
3783
|
-
(b) => b.active && b.effectiveMessageIds.includes(message.id)
|
|
3784
|
-
);
|
|
3785
|
-
if (!stillCovered) restored.push(message);
|
|
3858
|
+
if (!coveredBases.has(baseIdOf(message.id))) restored.push(message);
|
|
3786
3859
|
}
|
|
3787
3860
|
if (restored.length === 0) return { preview: "", restoredCount: 0 };
|
|
3788
3861
|
const lines = [];
|
|
@@ -3801,9 +3874,10 @@ function buildRestoredContentPreview(messages, beforeActiveMessageIds, state) {
|
|
|
3801
3874
|
}
|
|
3802
3875
|
function collectBlockContent(state, block, messages, options = {}) {
|
|
3803
3876
|
const full = options.full ?? false;
|
|
3804
|
-
const
|
|
3877
|
+
const targetBases = /* @__PURE__ */ new Set();
|
|
3878
|
+
for (const id of block.effectiveMessageIds) targetBases.add(baseIdOf(id));
|
|
3805
3879
|
if (full) {
|
|
3806
|
-
const msgs = messages.filter((m) =>
|
|
3880
|
+
const msgs = messages.filter((m) => targetBases.has(baseIdOf(m.id)));
|
|
3807
3881
|
if (msgs.length === 0) return { text: "", count: 0 };
|
|
3808
3882
|
return { text: msgs.map(formatMessage).join("\n\n"), count: msgs.length };
|
|
3809
3883
|
}
|
|
@@ -3813,7 +3887,7 @@ function collectBlockContent(state, block, messages, options = {}) {
|
|
|
3813
3887
|
const child = state.blocks.find((b) => b.blockId === childId);
|
|
3814
3888
|
if (!child?.active) continue;
|
|
3815
3889
|
nestedChildren.push(child);
|
|
3816
|
-
for (const id of child.effectiveMessageIds) nestedCovered.add(id);
|
|
3890
|
+
for (const id of child.effectiveMessageIds) nestedCovered.add(baseIdOf(id));
|
|
3817
3891
|
}
|
|
3818
3892
|
const parts = [];
|
|
3819
3893
|
for (const child of nestedChildren) {
|
|
@@ -3823,7 +3897,8 @@ ${child.summary}`);
|
|
|
3823
3897
|
}
|
|
3824
3898
|
let directCount = 0;
|
|
3825
3899
|
for (const m of messages) {
|
|
3826
|
-
|
|
3900
|
+
const base = baseIdOf(m.id);
|
|
3901
|
+
if (targetBases.has(base) && !nestedCovered.has(base)) {
|
|
3827
3902
|
parts.push(formatMessage(m));
|
|
3828
3903
|
directCount++;
|
|
3829
3904
|
}
|
|
@@ -3885,7 +3960,7 @@ function collectVisible(messages, state, countTokens) {
|
|
|
3885
3960
|
const coveredIds = /* @__PURE__ */ new Set();
|
|
3886
3961
|
for (const block of state.blocks) {
|
|
3887
3962
|
if (!block.active) continue;
|
|
3888
|
-
for (const id of block.effectiveMessageIds) coveredIds.add(id);
|
|
3963
|
+
for (const id of block.effectiveMessageIds) coveredIds.add(baseIdOf(id));
|
|
3889
3964
|
}
|
|
3890
3965
|
let summaryTokens = 0;
|
|
3891
3966
|
for (const block of state.blocks) {
|
|
@@ -3899,7 +3974,7 @@ function collectVisible(messages, state, countTokens) {
|
|
|
3899
3974
|
}
|
|
3900
3975
|
}
|
|
3901
3976
|
messages.forEach((message, index) => {
|
|
3902
|
-
if (coveredIds.has(message.id)) return;
|
|
3977
|
+
if (coveredIds.has(baseIdOf(message.id))) return;
|
|
3903
3978
|
const ref = refForRaw(state.messageRefs, message.id);
|
|
3904
3979
|
if (!ref) return;
|
|
3905
3980
|
const tokens = countMessageTokens(message, countTokens);
|
|
@@ -5377,11 +5452,7 @@ function build(text) {
|
|
|
5377
5452
|
}
|
|
5378
5453
|
function docFeatures(text) {
|
|
5379
5454
|
const hit = cache.get(text);
|
|
5380
|
-
if (hit)
|
|
5381
|
-
cache.delete(text);
|
|
5382
|
-
cache.set(text, hit);
|
|
5383
|
-
return hit;
|
|
5384
|
-
}
|
|
5455
|
+
if (hit) return hit;
|
|
5385
5456
|
const f = build(text);
|
|
5386
5457
|
if (text.length > 0 && text.length <= capChars) {
|
|
5387
5458
|
while (cachedChars + text.length > capChars && cache.size > 0) {
|
|
@@ -5492,8 +5563,8 @@ var hybridAlgorithm = {
|
|
|
5492
5563
|
score(docs, query) {
|
|
5493
5564
|
const bm = bm25Algorithm.score(docs, query);
|
|
5494
5565
|
const fz = fuzzyAlgorithm.score(docs, query);
|
|
5495
|
-
const maxBm = bm.
|
|
5496
|
-
const maxFz = fz.
|
|
5566
|
+
const maxBm = Math.max(...bm.map((r) => r.score), 1e-9);
|
|
5567
|
+
const maxFz = Math.max(...fz.map((r) => r.score), 1e-9);
|
|
5497
5568
|
const bmMap = new Map(bm.map((r) => [r.ref, r.score / maxBm]));
|
|
5498
5569
|
const fzMap = new Map(fz.map((r) => [r.ref, r.score / maxFz]));
|
|
5499
5570
|
return docs.map((d) => ({
|
|
@@ -5704,6 +5775,7 @@ export {
|
|
|
5704
5775
|
applyMessageFilters,
|
|
5705
5776
|
applySectionOverrides,
|
|
5706
5777
|
assignRefs,
|
|
5778
|
+
baseIdOf,
|
|
5707
5779
|
blockById,
|
|
5708
5780
|
blockDocs,
|
|
5709
5781
|
blockVisibleInRange,
|
|
@@ -5758,6 +5830,7 @@ export {
|
|
|
5758
5830
|
highestUsedIndex,
|
|
5759
5831
|
indexToRef,
|
|
5760
5832
|
isAbsorbCandidate,
|
|
5833
|
+
isCovered,
|
|
5761
5834
|
isMessageLatestProtected,
|
|
5762
5835
|
isMessageProtected,
|
|
5763
5836
|
isRenderedSummaryMessage,
|