acp-kernel 0.0.89-pr.399.259 → 0.0.89-pr.403.266
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/DESIGN.md +16 -0
- package/dist/boundaries.d.ts +1 -0
- package/dist/boundaries.d.ts.map +1 -1
- package/dist/compress.d.ts.map +1 -1
- package/dist/hide-consumed.d.ts +4 -0
- package/dist/hide-consumed.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +184 -38
- 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/persist/index.js +43 -4
- package/dist/persist/index.js.map +1 -1
- package/dist/persist/store.d.ts +13 -1
- package/dist/persist/store.d.ts.map +1 -1
- package/dist/protected.d.ts.map +1 -1
- package/dist/prune.d.ts +15 -0
- package/dist/prune.d.ts.map +1 -1
- package/dist/recommend.d.ts +0 -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 +34 -10
- package/dist/search/doc-cache.d.ts.map +1 -1
- package/dist/sync.d.ts.map +1 -1
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/wire/anthropic.d.ts +1 -1
- package/dist/wire/anthropic.d.ts.map +1 -1
- package/dist/wire/index.js +8 -2
- package/dist/wire/index.js.map +1 -1
- package/package.json +1 -1
package/DESIGN.md
CHANGED
|
@@ -232,3 +232,19 @@ A default `countTokens` ships with the core (word-level + unicode CJK tokenizer,
|
|
|
232
232
|
## 7. Why the algorithm, but not the DCP-derived code, comes here
|
|
233
233
|
|
|
234
234
|
Copyright protects *expression*, not ideas, methods, or algorithms (17 USC §102(b)). The compression *methods* (3-tier, growth cadence, protected filtering) are the author's. This core reimplements them in **fresh expression** — it is not a copy or refactor of DCP-derived files. See [PROVENANCE.md](./PROVENANCE.md) for the per-module origin classification (original-bring / DCP-derived-reimplement / adapter-only).
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## 8. Prune Semantics & Wire Invariants
|
|
239
|
+
|
|
240
|
+
`prune` rebuilds the visible view every turn: messages covered by active blocks are dropped, and each active block's rendered summary (`[Compressed conversation section]`, id `acp_summary_bN`) is inserted at the block's earliest covered position (pair-safe, per `pairSafeAnchorIndex`). One behavior of the rebuilt view is a load-bearing contract for downstream consumers:
|
|
241
|
+
|
|
242
|
+
### 8.1 First-user-message pin
|
|
243
|
+
|
|
244
|
+
The session's **first user message survives prune unconditionally** — even when it is covered by an active block. In `rebuildMessages` (`src/prune.ts`) the pin check runs *before* the covered-by-active-block check, so after compressing a range that includes the first user message, the rebuilt wire contains **both** the rendered summary **and** the first user message verbatim; all other covered messages drop as usual. Only the *first* user message is pinned — later covered user messages are pruned normally.
|
|
245
|
+
|
|
246
|
+
- **Why:** strict providers reject conversations with no user message (e.g., Anthropic requires the conversation to start from the user role). Pinning guarantees the rebuilt wire retains at least one user message whenever the input had one. Deliberate since prune's first implementation (v0.0.2) — the ordering of the two checks is part of the contract, not incidental. Regression-tested by `tests/state-prune.test.ts` ("prune preserves first user message even when covered") and `tests/orphan-fixes.test.ts` ("prune: first user message pruned when covered (no duplication)").
|
|
247
|
+
- **Consequences for consumers:**
|
|
248
|
+
- Consumers cannot assert byte-level disappearance of the first user message after compression; post-compress wire assertions must expect the rendered summary **plus** the pinned message verbatim.
|
|
249
|
+
- Token-size and prefix-cache stability estimates must account for the pinned message staying verbatim (it is often the task description and can be long).
|
|
250
|
+
- Boundary resolution compensates: `blockVisibleInRange` (`src/boundaries.ts`) treats a block as present in a range via its rendered summary **or** its earliest surviving raw — required precisely because the summary anchors *before* the pinned raw.
|
package/dist/boundaries.d.ts
CHANGED
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":"AAIA,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,EAAE,MAAM,EAAE,CAAC;IACxB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,sBAAsB,GAC5B,aAAa,CAiFf;AAsMD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,gBAAgB,EACvB,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,MAAM,GAAG,IAAI,CAIf;AAOD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,gBAAgB,EACvB,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACrC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAcT;AAED,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EAAE,EACb,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,MAAM,GAAG,IAAI,CASf;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,GAAG,gBAAgB,CAMzE"}
|
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;AAgBhF,OAAO,KAAK,EAAE,mBAAmB,EAAa,MAAM,UAAU,CAAC;AAE/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAI9D,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;AAgBhF,OAAO,KAAK,EAAE,mBAAmB,EAAa,MAAM,UAAU,CAAC;AAE/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAI9D,OAAO,KAAK,EAAE,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,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;AAqND,wBAAgB,UAAU,CAAC,KAAK,GAAE,KAAU,GAAG,eAAe,CA4d7D;AAwqCD,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/hide-consumed.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ import type { CompressionState, CoreMessage } from "./types.js";
|
|
|
2
2
|
export interface HideConsumedResult {
|
|
3
3
|
messages: CoreMessage[];
|
|
4
4
|
hidden: number;
|
|
5
|
+
/** Padded refs of the orphan compress call/result messages hidden by this
|
|
6
|
+
* pass (orphans beyond the keep window). Consumed by boundary resolution to
|
|
7
|
+
* snap a range endpoint onto a hidden-but-intact orphan (#396). */
|
|
8
|
+
hiddenOrphanRefs: string[];
|
|
5
9
|
}
|
|
6
10
|
export declare function hideConsumedCompressCalls(state: CompressionState, messages: CoreMessage[]): HideConsumedResult;
|
|
7
11
|
//# sourceMappingURL=hide-consumed.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hide-consumed.d.ts","sourceRoot":"","sources":["../src/hide-consumed.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hide-consumed.d.ts","sourceRoot":"","sources":["../src/hide-consumed.ts"],"names":[],"mappings":"AAEA,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;IACf;;wEAEoE;IACpE,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC9B;AA8FD,wBAAgB,yBAAyB,CACrC,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,WAAW,EAAE,GACxB,kBAAkB,CAoGpB"}
|
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";
|
|
@@ -30,6 +30,7 @@ export { buildCacheReport, computeFoldEconomics, decomposeSample, formatCacheRep
|
|
|
30
30
|
export type { CacheSample, FoldEvent, FoldEconomicsInput, PriceProfile, SampleDecomposition, CacheTotals, FoldEconomics, EconomicsSummary, CacheReportLine, CacheReportOptions, CacheReport, FormatCacheReportOptions, } from "./cache-report.js";
|
|
31
31
|
export { renderHandoff, renderMessage, matchSession } from "./handoff.js";
|
|
32
32
|
export type { HandoffInput, HandoffMeta, HandoffBlockFull } from "./handoff.js";
|
|
33
|
+
export { isToolMessage } from "./message-kind.js";
|
|
33
34
|
export { hideConsumedCompressCalls } from "./hide-consumed.js";
|
|
34
35
|
export type { HideConsumedResult } from "./hide-consumed.js";
|
|
35
36
|
export { ABSORB_TOOL_NAME, ABSORB_TOOL, ABSORB_TOOL_OPENAI, IMAGE_FULL_TOOL_NAME, IMAGE_FULL_TOOL, IMAGE_FULL_TOOL_OPENAI, IMAGE_FULL_TOOL_RESPONSES, } 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,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,EAClB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,YAAY,EAAE,MAAM,eA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O,EACL,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,wBAAwB,EACxB,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,eAAe,GACrB,MAAM,gBAAgB,CAAC;AACxB,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;AACpE,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,8BAA8B,EAC9B,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,GACZ,MAAM,sBAAsB,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,M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EAC9B,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,GACZ,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -111,33 +111,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);
|
|
@@ -1248,7 +1262,12 @@ function hasMediaPayload(msg) {
|
|
|
1248
1262
|
if (m.rawOpenaiContent != null) return true;
|
|
1249
1263
|
if (Array.isArray(m.rawOpenaiContentParts) && m.rawOpenaiContentParts.length > 0)
|
|
1250
1264
|
return true;
|
|
1251
|
-
|
|
1265
|
+
const ab = m.rawAnthropicBlock;
|
|
1266
|
+
if (isObjWith(ab, "type", "image")) return true;
|
|
1267
|
+
if (isObjWith(ab, "type", "tool_result")) {
|
|
1268
|
+
const content = ab.content;
|
|
1269
|
+
if (Array.isArray(content)) return content.some((p) => !isObjWith(p, "type", "text"));
|
|
1270
|
+
}
|
|
1252
1271
|
const item = m.rawResponsesItem;
|
|
1253
1272
|
if (isObjWith(item, "type", "input_image")) return true;
|
|
1254
1273
|
if (item && typeof item === "object") {
|
|
@@ -1612,8 +1631,10 @@ function resolveBoundaries(input) {
|
|
|
1612
1631
|
if (endAnchor.snapped) snappedBoundaries.push(endAnchor.snapped);
|
|
1613
1632
|
let startIndex = startAnchor.index;
|
|
1614
1633
|
let endIndex = endAnchor.index;
|
|
1634
|
+
let reversedNote;
|
|
1615
1635
|
if (startIndex > endIndex) {
|
|
1616
1636
|
[startIndex, endIndex] = [endIndex, startIndex];
|
|
1637
|
+
reversedNote = `note: refs were given reversed (${start.raw}\u2192${end.raw}), normalized to ${end.raw}..${start.raw}`;
|
|
1617
1638
|
}
|
|
1618
1639
|
const messageIds = [];
|
|
1619
1640
|
for (let index = startIndex; index <= endIndex; index++) {
|
|
@@ -1640,7 +1661,8 @@ function resolveBoundaries(input) {
|
|
|
1640
1661
|
nestedBlockIds,
|
|
1641
1662
|
boundaryKind,
|
|
1642
1663
|
protectedGaps,
|
|
1643
|
-
snappedBoundaries
|
|
1664
|
+
snappedBoundaries,
|
|
1665
|
+
reversedNote
|
|
1644
1666
|
};
|
|
1645
1667
|
}
|
|
1646
1668
|
function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
|
|
@@ -1665,6 +1687,27 @@ function resolveAnchorIndex(boundary, state, indexByMessageId, endpoint) {
|
|
|
1665
1687
|
snapped: `${label}="${boundary.raw}" refers to a message already compressed into an active block \u2014 anchored to the active block covering it instead.`
|
|
1666
1688
|
};
|
|
1667
1689
|
}
|
|
1690
|
+
const paddedRef = formatPaddedRef(boundary.numericId);
|
|
1691
|
+
if (state.hiddenOrphanRefs?.includes(paddedRef)) {
|
|
1692
|
+
const neighbor = snapToNeighborVisible(
|
|
1693
|
+
state,
|
|
1694
|
+
indexByMessageId,
|
|
1695
|
+
boundary.numericId,
|
|
1696
|
+
endpoint
|
|
1697
|
+
);
|
|
1698
|
+
if (neighbor !== null) {
|
|
1699
|
+
const dir = endpoint === "start" ? "the next visible message after it" : "the previous visible message before it";
|
|
1700
|
+
return {
|
|
1701
|
+
index: neighbor,
|
|
1702
|
+
snapped: `${label}="${boundary.raw}" is a hidden orphan compress call (no matching block) \u2014 snapped to ${dir} instead.`
|
|
1703
|
+
};
|
|
1704
|
+
}
|
|
1705
|
+
throw new BoundaryNotFoundError(
|
|
1706
|
+
"consumed",
|
|
1707
|
+
endpoint,
|
|
1708
|
+
`${label}="${boundary.raw}" is a hidden orphan compress call with no adjacent visible message to anchor to \u2014 run acp_status for current refs.`
|
|
1709
|
+
);
|
|
1710
|
+
}
|
|
1668
1711
|
throw new BoundaryNotFoundError(
|
|
1669
1712
|
"consumed",
|
|
1670
1713
|
endpoint,
|
|
@@ -1741,6 +1784,26 @@ function inheritedContentIds(state, block) {
|
|
|
1741
1784
|
}
|
|
1742
1785
|
return ids;
|
|
1743
1786
|
}
|
|
1787
|
+
function snapToNeighborVisible(state, indexByMessageId, refNumber, endpoint) {
|
|
1788
|
+
let bestIndex = null;
|
|
1789
|
+
let bestRef = null;
|
|
1790
|
+
for (const [rawId, index] of indexByMessageId) {
|
|
1791
|
+
const refText = state.messageRefs.byRaw[rawId];
|
|
1792
|
+
if (!refText || refText === BLOCKED_REF) continue;
|
|
1793
|
+
const ref = refToIndex(refText);
|
|
1794
|
+
if (ref === null) continue;
|
|
1795
|
+
if (endpoint === "start") {
|
|
1796
|
+
if (ref > refNumber && (bestRef === null || ref < bestRef)) {
|
|
1797
|
+
bestRef = ref;
|
|
1798
|
+
bestIndex = index;
|
|
1799
|
+
}
|
|
1800
|
+
} else if (ref < refNumber && (bestRef === null || ref > bestRef)) {
|
|
1801
|
+
bestRef = ref;
|
|
1802
|
+
bestIndex = index;
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
return bestIndex;
|
|
1806
|
+
}
|
|
1744
1807
|
function formatPaddedRef(index) {
|
|
1745
1808
|
return `m${String(index).padStart(5, "0")}`;
|
|
1746
1809
|
}
|
|
@@ -2163,14 +2226,26 @@ function hideConsumedCompressCalls(state, messages) {
|
|
|
2163
2226
|
}
|
|
2164
2227
|
}
|
|
2165
2228
|
let hidden = 0;
|
|
2229
|
+
const hiddenOrphanRefs = [];
|
|
2230
|
+
const rememberHiddenRef = (message) => {
|
|
2231
|
+
if (message.toolCallId && allBlockCallIds.has(message.toolCallId)) {
|
|
2232
|
+
return;
|
|
2233
|
+
}
|
|
2234
|
+
const ref = state.messageRefs.byRaw[message.id];
|
|
2235
|
+
if (ref && ref !== BLOCKED_REF && !hiddenOrphanRefs.includes(ref)) {
|
|
2236
|
+
hiddenOrphanRefs.push(ref);
|
|
2237
|
+
}
|
|
2238
|
+
};
|
|
2166
2239
|
const result = [];
|
|
2167
2240
|
for (const message of messages) {
|
|
2168
2241
|
if (message.toolName === "compress" && message.contentType === "tool-call" && (!message.toolCallId || !keepCallIds.has(message.toolCallId))) {
|
|
2169
2242
|
hidden++;
|
|
2243
|
+
rememberHiddenRef(message);
|
|
2170
2244
|
continue;
|
|
2171
2245
|
}
|
|
2172
2246
|
if (message.contentType === "tool-result" && message.toolCallId && hiddenCallIds.has(message.toolCallId)) {
|
|
2173
2247
|
hidden++;
|
|
2248
|
+
rememberHiddenRef(message);
|
|
2174
2249
|
continue;
|
|
2175
2250
|
}
|
|
2176
2251
|
if (message.toolName === "compress" && message.contentType === "tool-call" && message.toolCallId && keepCallIds.has(message.toolCallId)) {
|
|
@@ -2190,7 +2265,7 @@ function hideConsumedCompressCalls(state, messages) {
|
|
|
2190
2265
|
}
|
|
2191
2266
|
result.push(message);
|
|
2192
2267
|
}
|
|
2193
|
-
return { messages: result, hidden };
|
|
2268
|
+
return { messages: result, hidden, hiddenOrphanRefs };
|
|
2194
2269
|
}
|
|
2195
2270
|
|
|
2196
2271
|
// src/absorb.ts
|
|
@@ -3912,6 +3987,11 @@ function createRenderRefsNode(strategy) {
|
|
|
3912
3987
|
}
|
|
3913
3988
|
var renderRefsNode = createRenderRefsNode("all");
|
|
3914
3989
|
|
|
3990
|
+
// src/message-kind.ts
|
|
3991
|
+
function isToolMessage(message) {
|
|
3992
|
+
return message.contentType === "tool-call" || message.contentType === "tool-result";
|
|
3993
|
+
}
|
|
3994
|
+
|
|
3915
3995
|
// src/tool-pairs.ts
|
|
3916
3996
|
function adjustBoundariesForToolPairs(startIndex, endIndex, messages, maxScan = 20) {
|
|
3917
3997
|
const callIdsInRange = /* @__PURE__ */ new Set();
|
|
@@ -4116,9 +4196,6 @@ function computeIntegrityWithdrawals(messages, foldedIds) {
|
|
|
4116
4196
|
function estimateTextTokens(text) {
|
|
4117
4197
|
return Math.ceil(text.length / 4);
|
|
4118
4198
|
}
|
|
4119
|
-
function isToolMessage(message) {
|
|
4120
|
-
return message.contentType === "tool-call" || message.contentType === "tool-result";
|
|
4121
|
-
}
|
|
4122
4199
|
function isSyntheticOrPruned(message, state) {
|
|
4123
4200
|
if (message.text?.startsWith("[Compressed conversation section]")) return true;
|
|
4124
4201
|
for (const block of state.blocks) {
|
|
@@ -4520,6 +4597,7 @@ function createCore(ports = {}) {
|
|
|
4520
4597
|
let tokensCompressed = 0;
|
|
4521
4598
|
const errors = [];
|
|
4522
4599
|
const warnings = [];
|
|
4600
|
+
const notes = [];
|
|
4523
4601
|
const protectedMessageIds = input.protectedMessageIds ?? computeProtectedRefs(
|
|
4524
4602
|
input.messages,
|
|
4525
4603
|
input.state,
|
|
@@ -4571,11 +4649,16 @@ function createCore(ports = {}) {
|
|
|
4571
4649
|
else if (resolution.status === "unknown") unknownCount++;
|
|
4572
4650
|
}
|
|
4573
4651
|
const refoldDecisions = /* @__PURE__ */ new Map();
|
|
4574
|
-
|
|
4575
|
-
|
|
4652
|
+
const isRefoldCandidate = (resolution) => resolution.status === "consumed" || resolution.status === "ok" && resolution.resolved.boundaryKind !== "block" && resolution.resolved.messageIds.every(
|
|
4653
|
+
(id) => preExistingCoverage.has(id)
|
|
4654
|
+
);
|
|
4655
|
+
for (const [spec, resolution] of classifications) {
|
|
4656
|
+
if (isRefoldCandidate(resolution)) {
|
|
4657
|
+
refoldDecisions.set(spec, evaluateRefold(state, spec));
|
|
4658
|
+
}
|
|
4576
4659
|
}
|
|
4577
|
-
const allRefold = input.ranges.length > 0 &&
|
|
4578
|
-
(
|
|
4660
|
+
const allRefold = input.ranges.length > 0 && unknownCount === 0 && [...classifications.entries()].every(
|
|
4661
|
+
([spec, resolution]) => isRefoldCandidate(resolution) && refoldDecisions.get(spec)?.kind === "refold"
|
|
4579
4662
|
);
|
|
4580
4663
|
const rangeSpans = [];
|
|
4581
4664
|
for (const [spec, resolution] of classifications) {
|
|
@@ -4632,11 +4715,42 @@ function createCore(ports = {}) {
|
|
|
4632
4715
|
})
|
|
4633
4716
|
)
|
|
4634
4717
|
];
|
|
4635
|
-
const
|
|
4718
|
+
const refoldSuffix = (reasons) => reasons.length > 0 ? ` Refold blocked: ${reasons.join("; ")}. Restore the affected block(s) inline (decompress with inline:true), then recompressing the same range updates them in place` : "";
|
|
4719
|
+
const refoldDetail = refoldSuffix(refoldReasons);
|
|
4720
|
+
const okBlockedReasons = [
|
|
4721
|
+
...new Set(
|
|
4722
|
+
[...classifications.entries()].flatMap(([spec, resolution]) => {
|
|
4723
|
+
if (skipSpecs.has(spec) || resolution.status !== "ok") return [];
|
|
4724
|
+
const decision = refoldDecisions.get(spec);
|
|
4725
|
+
return decision?.kind === "blocked" ? decision.reasons : [];
|
|
4726
|
+
})
|
|
4727
|
+
)
|
|
4728
|
+
];
|
|
4636
4729
|
const danglingRefs = consumedRanges.flatMap(
|
|
4637
4730
|
(spec) => danglingMessageRefs(state, input.messages, spec)
|
|
4638
4731
|
);
|
|
4639
|
-
|
|
4732
|
+
let gateMessage = resolvableCount === 0 && consumedRanges.length === 0 && unknownCount > 0 ? `None of the ${input.ranges.length} requested range(s) resolved \u2014 every ref is unknown to this session. Refs are per-session snapshots, assigned once when a message is first rendered; no compress reassigns them, so unknown refs cannot come from an earlier compress in this session. They come from a different generation: a previous session instance (switching model or upstream mid-conversation starts a fresh session whose refs restart at m00001), the generation before a native-compaction rebase (which also resets refs to m00001), or a typo. ${diagnostics} Run acp_status, then call the compress tool again using only the refs it reports.` : consumedRanges.length > 0 ? danglingRefs.length > 0 ? `Requested range(s) cannot be anchored (e.g. ${firstConsumed.startRef}..${firstConsumed.endRef}) \u2014 the refs exist in this session's ref map, but the messages they point to are no longer in the visible context and no active block covers them: the message content changed (or the message was filtered out of the view) and now carries a new ref, leaving your old refs dangling. ${diagnostics} Run acp_status, then call the compress tool again using only the refs it reports.` : `Requested range(s) already compressed (e.g. ${firstConsumed.startRef}..${firstConsumed.endRef}) \u2014 ${coverDetail}${refoldDetail}. Nothing new to compress in that window. ${diagnostics} Continue the task, or run acp_status and target one of the CURRENT compressible ranges it reports.${tierActionHint(input.config, state)}` : countedRanges > 0 ? `Total compressible content too small (${totalRangeChars} chars across ${countedRanges} range(s), min ${input.config.compress.minCompressRange}). Combine more messages into your range(s) to meet the threshold.${refoldSuffix(okBlockedReasons)}` : null;
|
|
4733
|
+
if (gateMessage === null) {
|
|
4734
|
+
return {
|
|
4735
|
+
state: input.state,
|
|
4736
|
+
result: {
|
|
4737
|
+
blocksCreated: 0,
|
|
4738
|
+
tokensCompressed: 0,
|
|
4739
|
+
errors: [...classificationErrors],
|
|
4740
|
+
warnings: []
|
|
4741
|
+
}
|
|
4742
|
+
};
|
|
4743
|
+
}
|
|
4744
|
+
const reversalNotes = [];
|
|
4745
|
+
for (const [spec, resolution] of classifications) {
|
|
4746
|
+
if (resolution.status === "ok" && !skipSpecs.has(spec)) {
|
|
4747
|
+
const note = resolution.resolved.reversedNote;
|
|
4748
|
+
if (note) reversalNotes.push(note);
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
if (reversalNotes.length > 0) {
|
|
4752
|
+
gateMessage += ` ${reversalNotes.join(" ")}`;
|
|
4753
|
+
}
|
|
4640
4754
|
return {
|
|
4641
4755
|
state: input.state,
|
|
4642
4756
|
result: {
|
|
@@ -4685,6 +4799,8 @@ function createCore(ports = {}) {
|
|
|
4685
4799
|
continue;
|
|
4686
4800
|
}
|
|
4687
4801
|
warnings.push(...resolution.resolved.snappedBoundaries);
|
|
4802
|
+
const note = resolution.resolved.reversedNote;
|
|
4803
|
+
if (note) notes.push(note);
|
|
4688
4804
|
try {
|
|
4689
4805
|
const outcome = applySingleRange({
|
|
4690
4806
|
spec,
|
|
@@ -4696,7 +4812,7 @@ function createCore(ports = {}) {
|
|
|
4696
4812
|
countTokens,
|
|
4697
4813
|
preExistingCoverage
|
|
4698
4814
|
});
|
|
4699
|
-
blocksCreated += outcome.
|
|
4815
|
+
blocksCreated += outcome.refolded ? outcome.refolded.length : 1;
|
|
4700
4816
|
tokensCompressed += outcome.tokens;
|
|
4701
4817
|
warnings.push(...outcome.warnings);
|
|
4702
4818
|
} catch (error) {
|
|
@@ -4718,7 +4834,13 @@ function createCore(ports = {}) {
|
|
|
4718
4834
|
}
|
|
4719
4835
|
return {
|
|
4720
4836
|
state,
|
|
4721
|
-
result: {
|
|
4837
|
+
result: {
|
|
4838
|
+
blocksCreated,
|
|
4839
|
+
tokensCompressed,
|
|
4840
|
+
errors,
|
|
4841
|
+
warnings,
|
|
4842
|
+
...notes.length > 0 ? { notes } : {}
|
|
4843
|
+
}
|
|
4722
4844
|
};
|
|
4723
4845
|
}
|
|
4724
4846
|
function processTurn(input) {
|
|
@@ -4902,7 +5024,11 @@ var hideCompressCallsNode = {
|
|
|
4902
5024
|
name: "hide-compress-calls",
|
|
4903
5025
|
run(io) {
|
|
4904
5026
|
const hidden = hideConsumedCompressCalls(io.state, io.messages);
|
|
4905
|
-
return {
|
|
5027
|
+
return {
|
|
5028
|
+
...io,
|
|
5029
|
+
messages: hidden.messages,
|
|
5030
|
+
state: { ...io.state, hiddenOrphanRefs: hidden.hiddenOrphanRefs }
|
|
5031
|
+
};
|
|
4906
5032
|
}
|
|
4907
5033
|
};
|
|
4908
5034
|
var recommendNode = {
|
|
@@ -5160,16 +5286,20 @@ function applySingleRange(input) {
|
|
|
5160
5286
|
}
|
|
5161
5287
|
}
|
|
5162
5288
|
if (!isBlockBoundary && filteredIds.length === 0 && consumedBlockIds.length > 0) {
|
|
5163
|
-
const
|
|
5164
|
-
if (
|
|
5289
|
+
const decision = evaluateRefold(input.state, input.spec);
|
|
5290
|
+
if (decision.kind === "refold") {
|
|
5165
5291
|
applyRefolds({
|
|
5166
5292
|
spec: input.spec,
|
|
5167
5293
|
state: input.state,
|
|
5168
5294
|
runId: input.runId,
|
|
5169
5295
|
config: input.config,
|
|
5170
|
-
blockIds:
|
|
5296
|
+
blockIds: decision.blocks.map((block2) => block2.blockId)
|
|
5171
5297
|
});
|
|
5172
|
-
return {
|
|
5298
|
+
return {
|
|
5299
|
+
tokens: 0,
|
|
5300
|
+
warnings,
|
|
5301
|
+
refolded: decision.blocks.map((block2) => block2.blockId)
|
|
5302
|
+
};
|
|
5173
5303
|
}
|
|
5174
5304
|
const first = consumedBlockIds[0];
|
|
5175
5305
|
const last = consumedBlockIds[consumedBlockIds.length - 1];
|
|
@@ -5516,7 +5646,7 @@ function computeContextBreakdown(messages, total, growth, countTokens) {
|
|
|
5516
5646
|
const tokens = countMessageTokens(msg, count);
|
|
5517
5647
|
if (msg.text?.startsWith("[Compressed conversation section]")) {
|
|
5518
5648
|
summaries += tokens;
|
|
5519
|
-
} else if (msg
|
|
5649
|
+
} else if (isToolMessage(msg)) {
|
|
5520
5650
|
tool += tokens;
|
|
5521
5651
|
} else if (msg.role === "system") {
|
|
5522
5652
|
system += tokens;
|
|
@@ -5548,7 +5678,8 @@ function cloneState(state) {
|
|
|
5548
5678
|
nextRuleId: state.nextRuleId,
|
|
5549
5679
|
terminalStreak: state.terminalStreak,
|
|
5550
5680
|
nextBlockId: state.nextBlockId,
|
|
5551
|
-
nextRunId: state.nextRunId
|
|
5681
|
+
nextRunId: state.nextRunId,
|
|
5682
|
+
hiddenOrphanRefs: state.hiddenOrphanRefs ? [...state.hiddenOrphanRefs] : void 0
|
|
5552
5683
|
};
|
|
5553
5684
|
}
|
|
5554
5685
|
function scoreRelevance(block, terms) {
|
|
@@ -5842,14 +5973,16 @@ function tierLabel(block) {
|
|
|
5842
5973
|
}
|
|
5843
5974
|
function tierBreakdown(blocks, countTokens) {
|
|
5844
5975
|
const tierTokens = {};
|
|
5976
|
+
const tierCounts = {};
|
|
5845
5977
|
for (const block of blocks) {
|
|
5846
5978
|
tierTokens[block.tier] = (tierTokens[block.tier] ?? 0) + summaryTokensOf(block, countTokens);
|
|
5979
|
+
tierCounts[block.tier] = (tierCounts[block.tier] ?? 0) + 1;
|
|
5847
5980
|
}
|
|
5848
5981
|
const tiers = Object.keys(tierTokens).map(Number);
|
|
5849
5982
|
if (tiers.length <= 1) return null;
|
|
5850
5983
|
const parts = [];
|
|
5851
5984
|
for (const tier of [1, 2, 3]) {
|
|
5852
|
-
if (tierTokens[tier]) parts.push(`T${tier}: ${formatTokens2(tierTokens[tier])}`);
|
|
5985
|
+
if (tierTokens[tier]) parts.push(`T${tier}: ${formatTokens2(tierTokens[tier])} (${tierCounts[tier]} blocks)`);
|
|
5853
5986
|
}
|
|
5854
5987
|
return parts.join(" | ");
|
|
5855
5988
|
}
|
|
@@ -5875,8 +6008,9 @@ function collectVisible(messages, state, countTokens) {
|
|
|
5875
6008
|
const ref = refForRaw(state.messageRefs, message.id);
|
|
5876
6009
|
if (!ref) return;
|
|
5877
6010
|
const tokens = countMessageTokens(message, countTokens);
|
|
5878
|
-
const
|
|
5879
|
-
|
|
6011
|
+
const isTool = isToolMessage(message);
|
|
6012
|
+
const tool = isTool ? message.toolName ?? (message.toolCallId ? toolCallNames.get(message.toolCallId) : void 0) ?? "tool" : "text";
|
|
6013
|
+
if (tokens > 0) visible.push({ ref, tokens, tool, isTool, index });
|
|
5880
6014
|
});
|
|
5881
6015
|
return { visible, summaryTokens };
|
|
5882
6016
|
}
|
|
@@ -5919,8 +6053,8 @@ function renderOverview(visible, summaryTokens, blocks, state, countTokens, limi
|
|
|
5919
6053
|
toolTypeMap.set(message.tool, (toolTypeMap.get(message.tool) ?? 0) + message.tokens);
|
|
5920
6054
|
}
|
|
5921
6055
|
const topTool = [...toolTypeMap.entries()].sort((a, b) => b[1] - a[1])[0]?.[0];
|
|
5922
|
-
const totalTool = visible.filter((m) => m.
|
|
5923
|
-
const totalText = visible.filter((m) => m.
|
|
6056
|
+
const totalTool = visible.filter((m) => m.isTool).reduce((sum, m) => sum + m.tokens, 0);
|
|
6057
|
+
const totalText = visible.filter((m) => !m.isTool).reduce((sum, m) => sum + m.tokens, 0);
|
|
5924
6058
|
const total = summaryTokens + totalTool + totalText;
|
|
5925
6059
|
lines.push("CONTEXT BREAKDOWN");
|
|
5926
6060
|
lines.push(
|
|
@@ -5956,6 +6090,11 @@ function renderOverview(visible, summaryTokens, blocks, state, countTokens, limi
|
|
|
5956
6090
|
` ${block.blockId} (${tierLabel(block)}) ${formatTokens2(eff)}\u2192${formatTokens2(summaryTokensOf(block, countTokens))} ${block.effectiveMessageIds.length} msgs "${topic}"`
|
|
5957
6091
|
);
|
|
5958
6092
|
}
|
|
6093
|
+
if (blocks.length > limit) {
|
|
6094
|
+
lines.push(
|
|
6095
|
+
` ... and ${blocks.length - limit} more blocks not shown (scope:"compressed", limit:${blocks.length} for full list)`
|
|
6096
|
+
);
|
|
6097
|
+
}
|
|
5959
6098
|
}
|
|
5960
6099
|
lines.push("");
|
|
5961
6100
|
lines.push(
|
|
@@ -7638,7 +7777,11 @@ function build(text) {
|
|
|
7638
7777
|
}
|
|
7639
7778
|
function docFeatures(text) {
|
|
7640
7779
|
const hit = cache.get(text);
|
|
7641
|
-
if (hit)
|
|
7780
|
+
if (hit) {
|
|
7781
|
+
cache.delete(text);
|
|
7782
|
+
cache.set(text, hit);
|
|
7783
|
+
return hit;
|
|
7784
|
+
}
|
|
7642
7785
|
const f = build(text);
|
|
7643
7786
|
if (text.length > 0 && text.length <= capChars) {
|
|
7644
7787
|
while (cachedChars + text.length > capChars && cache.size > 0) {
|
|
@@ -7749,8 +7892,8 @@ var hybridAlgorithm = {
|
|
|
7749
7892
|
score(docs, query) {
|
|
7750
7893
|
const bm = bm25Algorithm.score(docs, query);
|
|
7751
7894
|
const fz = fuzzyAlgorithm.score(docs, query);
|
|
7752
|
-
const maxBm =
|
|
7753
|
-
const maxFz =
|
|
7895
|
+
const maxBm = bm.reduce((m, r) => r.score > m ? r.score : m, 1e-9);
|
|
7896
|
+
const maxFz = fz.reduce((m, r) => r.score > m ? r.score : m, 1e-9);
|
|
7754
7897
|
const bmMap = new Map(bm.map((r) => [r.ref, r.score / maxBm]));
|
|
7755
7898
|
const fzMap = new Map(fz.map((r) => [r.ref, r.score / maxFz]));
|
|
7756
7899
|
return docs.map((d) => ({
|
|
@@ -8115,6 +8258,7 @@ export {
|
|
|
8115
8258
|
applySectionOverrides,
|
|
8116
8259
|
applySteeringToPrompt,
|
|
8117
8260
|
assignRefs,
|
|
8261
|
+
baseIdOf,
|
|
8118
8262
|
blockById,
|
|
8119
8263
|
blockDocs,
|
|
8120
8264
|
blockVisibleInRange,
|
|
@@ -8191,6 +8335,7 @@ export {
|
|
|
8191
8335
|
imageShrinksForRef,
|
|
8192
8336
|
indexToRef,
|
|
8193
8337
|
isAbsorbCandidate,
|
|
8338
|
+
isCovered,
|
|
8194
8339
|
isImageFullRestored,
|
|
8195
8340
|
isMessageLatestProtected,
|
|
8196
8341
|
isMessageProtected,
|
|
@@ -8198,6 +8343,7 @@ export {
|
|
|
8198
8343
|
isRetrievedMessage,
|
|
8199
8344
|
isStoredPlaceholderText,
|
|
8200
8345
|
isSummaryMessageId,
|
|
8346
|
+
isToolMessage,
|
|
8201
8347
|
isValidPackName,
|
|
8202
8348
|
jsonFoldPlugin,
|
|
8203
8349
|
leanPack,
|