@logictan/dsh-verbatim-compaction 0.11.0 → 0.11.1
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/README.md +11 -3
- package/lib/index.js +122 -85
- package/lib/types/index.d.ts +0 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
|
|
63
63
|
所以提取的材料是三段:用户请求(逐字)、助手正文(逐字)、工具轨迹(每条调用的 `description`,失败的调用另记一行首行错误)。模型输出固定的四节:`## Asked` / `## Did` / `## Concluded` / `## Overturned`。
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
空节直接不出现:「没有内容」是一个空数组,不是需要事后识别的占位符。字段化之前是自由 markdown,模型写 `## Overturned\n- (none)` 就得在代码里再认一遍占位符,实测一份真实提取块里 `## Asked` 和 `## Overturned` 都是 `(none)`,删掉后 312 → 271 字符;按 130 轮算,这些占位合计约 900 token 只是在记录「什么都没发生」。现在这类占位在解析阶段就被滤掉,不再有一个专门的清理函数。`none of the tests passed`、`无法连接,改用代理` 这类真内容照原样保留。
|
|
66
66
|
|
|
67
67
|
`## Asked` 记的是「**助手**向**用户**提了什么、给了哪些选项」。这一节最容易错成「把用户请求改写一遍」——真实一次压缩里,模型把用户那段中文请求翻成英文塞进了 `Asked`,而用户原话就在它上面逐字抄着,同一件事写了两遍。
|
|
68
68
|
|
|
69
69
|
原因之一在材料标签:原来写 `USER REQUEST:`,模型有理由读成「这一轮问了什么」,现在改成 `USER INSTRUCTION (already in the digest verbatim; never copy it into Asked)`。另一部分靠指令本身——`## Asked` 的定义写明「助手问、用户答」,并注明照抄用户请求是这一节最常见的出错方式。
|
|
70
70
|
|
|
71
|
-
正文为空的轮次(那个真实案例有 96 条助手消息、150 次工具调用却只有 156 字符正文)本来就没有提问可记,`## Asked` 和 `## Did`
|
|
71
|
+
正文为空的轮次(那个真实案例有 96 条助手消息、150 次工具调用却只有 156 字符正文)本来就没有提问可记,`## Asked` 和 `## Did` 一样整节省略,不需要单独规则。实测 123 条真人消息里 43 条(35%)不超过 12 个字符——`3`、`1`、`同意`、`做`、`继续`——而 46% 是在回答上一轮助手的提问。只逐字保留「3」而不保留它在回答什么问题,等于记下一个决定却没记下决定的是什么。
|
|
72
72
|
|
|
73
73
|
模型用的是会话自己的路由(`session.requestHeader()?.config`),和宿主原生压缩同一个取法,不需要单独配置凭据。
|
|
74
74
|
|
|
@@ -76,7 +76,15 @@
|
|
|
76
76
|
|
|
77
77
|
- **失败信号只认 `data.isError`**。曾用 `/error/i` 匹配序列化文本,347 条成功结果全部命中(工具输出里常有 "error" 字样),模型据此报告「整轮失败」。测试里有一条专门钉住这个坑。
|
|
78
78
|
- **工具调用从 `assistant/message` 的 block 里取**。日志里没有独立的 `tool/call` 事件类型,按它过滤会一条都取不到。
|
|
79
|
-
-
|
|
79
|
+
- **提取失败就退回逐字正文**。模型不可达、超时、输出为空时,该轮保留原来的助手正文;压缩本身不能因此失败,否则会话死于上下文溢出,比丢细节更糟。降级是逐轮的:一批里某一轮没答,只有那一轮退回正文。**但降级不再无声**:整批拿不到可用 JSON、或单槽位在令牌上限被截断,都会打一条 `verbatim-compaction:` 开头的 warn,写明受影响的 slot key。没有这条日志时,插件退化成纯逐字摘要这件事在运行期完全不可观测——这正是「JSON 经常不生效却查不到」的成因。
|
|
80
|
+
|
|
81
|
+
提取调用的 `maxTokens` **在每槽位预算之外另加一笔固定的思考余量**(`EXTRACT_TOKENS_PER_TURN × 槽位数 + EXTRACT_THINKING_RESERVE_TOKENS`)。`maxTokens` 把思考与正文算在一起,而思考是**每次调用的固定开销,不随批次变小而变小**——这正是「按槽位线性给上限」必然失败的原因。对真实路由(deepseek-flash,真实量级材料)实测:单槽位按旧公式 `220 × 1` 给上限,**4 次全部解析出 0 个槽位**(思考块吃光了整个配额);改成 `220 × 1 + 1000` 后 **4 次全部成功**,1/2/4/8 槽位各 4 次同样全通过。
|
|
82
|
+
|
|
83
|
+
同时把 effort **钉在路由声明的最便宜档**,而不是沿用路由默认档。思考与正文共用同一笔 `maxTokens`,默认档通常是最贵那档,会挤占正文预算。实测 2 槽位、带余量:`low` 花 375 个思考 token、3/3 解析成功;`high` 花 931、只有 2/3。
|
|
84
|
+
|
|
85
|
+
**`off` 走不通,这一点是实测而非推断。** 用本地回显服务抓 pi-ai 1.3.0 对 `thinkingFormat: deepseek` 真正发出的 body:`off` 档被映射成 `reasoning_effort: "minimal"` 且 `thinking: {"type":"enabled"}` 固定不变,而该端点直接拒绝 `minimal`(`valid levels: low, medium, high`)。真正能关掉思考的是 provider 自己的 `thinking: {"type":"disabled"}`(实测 0 个思考 token),但 `GenerateOptions` 没有承载它的字段,这条接缝上的任何插件都发不出去。所以 effort 只在路由**声明了**非 `off` 档时才发——宿主会拒绝未声明的档位。
|
|
86
|
+
|
|
87
|
+
被令牌上限截断的那一批会**对半拆开重发**:截断的答案解析为空,一个超预算的轮次会连带丢掉同批其余七轮;对半拆把损失限制在仍然装不下的那一半,单槽位无法再拆时放弃并留 warn。注意这两条是一组:没有思考余量时,对半拆只会让每半的每槽位预算更紧、必然全败,所以余量是拆分重试成立的前提。判据钉在 `extractive.spec.mjs` 的「carries a thinking reserve」「pins the cheapest advertised effort」「never sent an effort it did not advertise」「split and retried, not dropped whole」「leaves a warning, not silence」。
|
|
80
88
|
|
|
81
89
|
提取结果按内容哈希缓存,同一次会话内复用。`digestSource` 每次压缩都从原始日志重建,而原始事件永远留在日志里,所以同一轮会被反复读到。实测那个压缩了 33 次的会话:共提取 142 轮,其中 **129 轮(91%)在更早的压缩里已经提取过**;全机 370 个会话、456 次压缩里,**81% 的压缩工作量是这种重复**(有压缩的 88 个会话中 70 个压缩过 2 次以上)。
|
|
82
90
|
|
package/lib/index.js
CHANGED
|
@@ -231,76 +231,6 @@ export function isErrorResult(event) {
|
|
|
231
231
|
const message = messageOf(event);
|
|
232
232
|
return message?.isError === true;
|
|
233
233
|
}
|
|
234
|
-
/**
|
|
235
|
-
* Drop headings whose body says nothing.
|
|
236
|
-
*
|
|
237
|
-
* The instruction asks the model to omit empty sections, but a model that writes
|
|
238
|
-
* `## Overturned\n- (none)` anyway must not cost tokens on every turn: 130 turns
|
|
239
|
-
* of that placeholder is ~900 tokens recording that nothing was overturned. So
|
|
240
|
-
* the shape is enforced here as well, not only requested in the prompt.
|
|
241
|
-
*
|
|
242
|
-
* A heading is dropped when every non-blank line under it, once its bullet is
|
|
243
|
-
* stripped, is a placeholder — `(none)`, `none`, `n/a`, `-`, `无`. A heading with
|
|
244
|
-
* any real content is kept verbatim.
|
|
245
|
-
*
|
|
246
|
-
* @param body - one slot's extracted text.
|
|
247
|
-
* @returns the same text with empty sections removed, or an empty string when
|
|
248
|
-
* nothing substantive remains.
|
|
249
|
-
*/
|
|
250
|
-
export function pruneEmptySections(block) {
|
|
251
|
-
const lines = block.split('\n');
|
|
252
|
-
const kept = [];
|
|
253
|
-
// A section is one heading plus the lines under it. The heading may be a line of
|
|
254
|
-
// its own (`## Asked`, bare `Asked`) or carry its body inline (`- Did: …`,
|
|
255
|
-
// `**Asked**:…`). Both forms occur in real output, sometimes in the same block.
|
|
256
|
-
const headingOf = (line) => {
|
|
257
|
-
if (/^#{1,6}\s/.test(line))
|
|
258
|
-
return { own: '' };
|
|
259
|
-
if (/^\s*(?:[-*]\s+)?(?:\*\*)?(Asked|Did|Concluded|Overturned|问|做|结论|推翻)(?:\*\*)?\s*[::]?\s*$/i.test(line)) {
|
|
260
|
-
return { own: '' };
|
|
261
|
-
}
|
|
262
|
-
const inline = /^\s*(?:[-*]\s+)?(?:\*\*)?(Asked|Did|Concluded|Overturned|问|做|结论|推翻)(?:\*\*)?\s*[::]\s*(.*)$/i.exec(line);
|
|
263
|
-
if (inline !== null)
|
|
264
|
-
return { own: inline[2] ?? '' };
|
|
265
|
-
return undefined;
|
|
266
|
-
};
|
|
267
|
-
// Placeholders for "nothing here" that models actually write. `未提问` came from a
|
|
268
|
-
// real run and cost a line on every turn that asked no question.
|
|
269
|
-
const placeholder = (text) => {
|
|
270
|
-
const trimmed = text.trim();
|
|
271
|
-
if (trimmed.length === 0)
|
|
272
|
-
return true;
|
|
273
|
-
if (/^(?:\(?none\)?|n\/a|na|-{1,2}|无|沒有|没有)$/i.test(trimmed))
|
|
274
|
-
return true;
|
|
275
|
-
return /^(?:未提问|无提问|没有提问|未提出|no questions? (?:were |was )?asked|none asked|no question)[。.!!]*$/i.test(trimmed);
|
|
276
|
-
};
|
|
277
|
-
let heading;
|
|
278
|
-
let under = [];
|
|
279
|
-
const flush = () => {
|
|
280
|
-
if (heading !== undefined) {
|
|
281
|
-
const own = headingOf(heading)?.own ?? '';
|
|
282
|
-
const substantive = (own.length > 0 && !placeholder(own))
|
|
283
|
-
|| under.some((line) => !placeholder(line.replace(/^\s*(?:[-*]|\d+\.)\s*/, '')));
|
|
284
|
-
if (substantive)
|
|
285
|
-
kept.push(heading, ...under);
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
kept.push(...under);
|
|
289
|
-
}
|
|
290
|
-
heading = undefined;
|
|
291
|
-
under = [];
|
|
292
|
-
};
|
|
293
|
-
for (const line of lines) {
|
|
294
|
-
if (headingOf(line) !== undefined) {
|
|
295
|
-
flush();
|
|
296
|
-
heading = line;
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
under.push(line);
|
|
300
|
-
}
|
|
301
|
-
flush();
|
|
302
|
-
return kept.join('\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
303
|
-
}
|
|
304
234
|
/** Directive appended as the final user message of the extraction call. */
|
|
305
235
|
const EXTRACT_INSTRUCTION = [
|
|
306
236
|
'You are summarizing a batch of turns from a coding session for a compaction checkpoint.',
|
|
@@ -406,6 +336,17 @@ export function renderExtractionBlock(extraction) {
|
|
|
406
336
|
const TURNS_PER_CALL = 8;
|
|
407
337
|
/** Output tokens allowed per turn in an extraction call. */
|
|
408
338
|
const EXTRACT_TOKENS_PER_TURN = 220;
|
|
339
|
+
/**
|
|
340
|
+
* Fixed thinking reserve added to every extraction call's `maxTokens`.
|
|
341
|
+
*
|
|
342
|
+
* `maxTokens` covers thinking and the answer together, and thinking is a
|
|
343
|
+
* per-call cost that does not shrink with the batch. Measured on the live route
|
|
344
|
+
* with real-length material: one slot at `220 x 1` with no reserve returned zero
|
|
345
|
+
* parseable slots in 4 of 4 runs, while `220 x 1 + 1000` parsed in 4 of 4. See
|
|
346
|
+
* `extractOnce` for the effort half of the same problem, and for why the reserve
|
|
347
|
+
* is the fix rather than an `off` effort.
|
|
348
|
+
*/
|
|
349
|
+
const EXTRACT_THINKING_RESERVE_TOKENS = 1000;
|
|
409
350
|
/** Most tool calls one turn may contribute to the hint block. */
|
|
410
351
|
const MAX_HINTS_PER_TURN = 120;
|
|
411
352
|
/** Characters kept from one call's description or command head. */
|
|
@@ -1133,27 +1074,114 @@ export function buildExtractionMaterial(turn, prose) {
|
|
|
1133
1074
|
* compaction does (`ctx.llm.stream` with the session's provider/model), so no
|
|
1134
1075
|
* separate credential or configuration is involved.
|
|
1135
1076
|
*
|
|
1136
|
-
* Every failure path
|
|
1137
|
-
* a compaction that cannot reach the model must still compact, or the
|
|
1138
|
-
* dies of context overflow instead of losing detail.
|
|
1077
|
+
* Every failure path yields no blocks and the caller falls back to the plain
|
|
1078
|
+
* digest: a compaction that cannot reach the model must still compact, or the
|
|
1079
|
+
* session dies of context overflow instead of losing detail. The degradation is
|
|
1080
|
+
* per turn, but it is never silent — a batch that comes back unusable is
|
|
1081
|
+
* reported, because the whole point of that fallback is invisible otherwise.
|
|
1139
1082
|
*
|
|
1140
|
-
* @param ctx - plugin context carrying the `llm` service.
|
|
1083
|
+
* @param ctx - plugin context carrying the `llm` service and a logger.
|
|
1141
1084
|
* @param agent - owner of the session being compacted; supplies the routed model.
|
|
1142
|
-
* @param
|
|
1143
|
-
* @param prose - that turn's assistant prose, already extracted.
|
|
1085
|
+
* @param batch - slots to extract, in one call unless the answer is truncated.
|
|
1144
1086
|
* @param signal - cancellation forwarded to the adapter.
|
|
1145
|
-
* @returns the extracted
|
|
1087
|
+
* @returns the extracted blocks by slot key; empty when extraction is unavailable.
|
|
1146
1088
|
*/
|
|
1147
1089
|
async function extractBatch(ctx, agent, batch, signal) {
|
|
1090
|
+
const out = new Map();
|
|
1091
|
+
if (batch.length === 0)
|
|
1092
|
+
return out;
|
|
1093
|
+
const attempt = await extractOnce(ctx, agent, batch, signal);
|
|
1094
|
+
if (!attempt.truncated) {
|
|
1095
|
+
if (attempt.blocks.size === 0) {
|
|
1096
|
+
ctx.logger?.warn(`verbatim-compaction: extraction returned no usable JSON for ${batch.length} slot(s) `
|
|
1097
|
+
+ `(${batch.map((slot) => slot.key).join(', ')}); those turns keep their verbatim prose`);
|
|
1098
|
+
}
|
|
1099
|
+
return attempt.blocks;
|
|
1100
|
+
}
|
|
1101
|
+
// A truncated answer parses to nothing, so one over-budget turn would cost
|
|
1102
|
+
// every turn in its batch. Measured on 191 real compactions, failures arrived
|
|
1103
|
+
// in runs of exactly `TURNS_PER_CALL`, which is this batching, not the model
|
|
1104
|
+
// failing per turn. Halving bounds the loss to the half that still does not
|
|
1105
|
+
// fit, and a single slot cannot be split further.
|
|
1106
|
+
if (batch.length === 1) {
|
|
1107
|
+
ctx.logger?.warn(`verbatim-compaction: extraction truncated at the token cap for slot ${batch[0]?.key ?? '?'}; `
|
|
1108
|
+
+ 'that turn keeps its verbatim prose');
|
|
1109
|
+
return attempt.blocks;
|
|
1110
|
+
}
|
|
1111
|
+
for (const [key, block] of attempt.blocks)
|
|
1112
|
+
out.set(key, block);
|
|
1113
|
+
const middle = Math.ceil(batch.length / 2);
|
|
1114
|
+
for (const half of [batch.slice(0, middle), batch.slice(middle)]) {
|
|
1115
|
+
for (const [key, block] of await extractBatch(ctx, agent, half, signal))
|
|
1116
|
+
out.set(key, block);
|
|
1117
|
+
}
|
|
1118
|
+
return out;
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* The cheapest effort a route advertises, or undefined when it advertises none.
|
|
1122
|
+
*
|
|
1123
|
+
* The route's own default is not used: it is typically the highest level, and
|
|
1124
|
+
* thinking is paid out of the answer's token budget. The list is ordered from
|
|
1125
|
+
* least to greatest effort by the host's own contract, so the first entry is the
|
|
1126
|
+
* cheapest. `off` is skipped even when present — pi-ai maps it to a wire value
|
|
1127
|
+
* the route may reject, and a level that cannot be sent is worse than a cheap
|
|
1128
|
+
* one that can.
|
|
1129
|
+
*
|
|
1130
|
+
* @param efforts - the route's advertised efforts, in escalation order.
|
|
1131
|
+
* @returns the cheapest usable effort id, or undefined to leave the choice alone.
|
|
1132
|
+
*/
|
|
1133
|
+
function cheapestEffort(efforts) {
|
|
1134
|
+
return efforts?.find((entry) => entry.id !== 'off')?.id;
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* One extraction request, no retry.
|
|
1138
|
+
*
|
|
1139
|
+
* The cap must carry a fixed thinking reserve on top of the per-slot output
|
|
1140
|
+
* budget. `maxTokens` covers thinking and the answer together, and thinking is
|
|
1141
|
+
* a per-call cost that does not shrink when the batch does. Measured against the
|
|
1142
|
+
* live route (deepseek-flash, `reasoning_effort` unset, real-length material):
|
|
1143
|
+
* a single slot at the old `220 x 1` cap returned zero parseable slots in 4 of 4
|
|
1144
|
+
* runs, the thinking block having consumed the entire cap; the same single slot
|
|
1145
|
+
* at `220 x 1 + 1000` parsed in 4 of 4. The reserve is what makes the cap work
|
|
1146
|
+
* for a batch of any size, including the batches the caller splits down to.
|
|
1147
|
+
*
|
|
1148
|
+
* The effort is pinned to the route's cheapest advertised level rather than left
|
|
1149
|
+
* to the route default. Thinking is paid out of the same `maxTokens` as the
|
|
1150
|
+
* answer, so a default that thinks hard shrinks the answer budget even with the
|
|
1151
|
+
* reserve in place. Measured on the live route at a 2-slot cap with the reserve:
|
|
1152
|
+
* `low` spent 375 thinking tokens and parsed 3 of 3; `high` spent 931 and parsed
|
|
1153
|
+
* 2 of 3.
|
|
1154
|
+
*
|
|
1155
|
+
* Two things that look like fixes and are not:
|
|
1156
|
+
*
|
|
1157
|
+
* - `off` cannot be reached through pi-ai. Its `deepseek` thinking format maps
|
|
1158
|
+
* the `off` level to `reasoning_effort: "minimal"`, which the route rejects
|
|
1159
|
+
* outright (`valid levels: low, medium, high`), and its `thinking` field is
|
|
1160
|
+
* pinned to `{type: "enabled"}` for every level. Captured from pi-ai 1.3.0
|
|
1161
|
+
* against a local echo server, not inferred.
|
|
1162
|
+
* - Only the provider's own `thinking: {type: "disabled"}` actually stops
|
|
1163
|
+
* thinking (0 thinking tokens, measured), but `GenerateOptions` has no field
|
|
1164
|
+
* that carries it, so no plugin on this seam can send it.
|
|
1165
|
+
*
|
|
1166
|
+
* An effort is requested only when the route advertises it, because the host
|
|
1167
|
+
* rejects one it does not.
|
|
1168
|
+
*
|
|
1169
|
+
* @param ctx - plugin context carrying the `llm` service and a logger.
|
|
1170
|
+
* @param agent - owner of the session being compacted.
|
|
1171
|
+
* @param batch - slots to ask about in this one call.
|
|
1172
|
+
* @param signal - cancellation forwarded to the adapter.
|
|
1173
|
+
* @returns the parsed blocks and whether the model stopped at the token cap.
|
|
1174
|
+
*/
|
|
1175
|
+
async function extractOnce(ctx, agent, batch, signal) {
|
|
1148
1176
|
const out = new Map();
|
|
1149
1177
|
const llm = ctx.llm;
|
|
1150
1178
|
if (llm === undefined)
|
|
1151
|
-
return out;
|
|
1179
|
+
return { blocks: out, truncated: false };
|
|
1152
1180
|
const route = agent.session.requestHeader()?.config;
|
|
1153
1181
|
const provider = route?.provider ?? agent.options.provider;
|
|
1154
1182
|
const model = route?.model ?? agent.options.model;
|
|
1155
1183
|
if (provider === undefined || model === undefined)
|
|
1156
|
-
return out;
|
|
1184
|
+
return { blocks: out, truncated: false };
|
|
1157
1185
|
// The label the model echoes back is the slot key, not the turn number: two
|
|
1158
1186
|
// requests can share a number, and a duplicate label would collapse two blocks
|
|
1159
1187
|
// into one entry.
|
|
@@ -1170,8 +1198,13 @@ async function extractBatch(ctx, agent, batch, signal) {
|
|
|
1170
1198
|
parts.push(`=== SLOT ${slot.key} (turn ${slot.turn ?? '?'}) ===\n${material}`);
|
|
1171
1199
|
}
|
|
1172
1200
|
if (parts.length === 0)
|
|
1173
|
-
return out;
|
|
1201
|
+
return { blocks: out, truncated: false };
|
|
1202
|
+
const info = await Promise.resolve()
|
|
1203
|
+
.then(() => llm.resolveModelInfo?.(provider, model, signal))
|
|
1204
|
+
.catch(() => undefined);
|
|
1205
|
+
const cheapest = cheapestEffort(info?.reasoning?.efforts);
|
|
1174
1206
|
const chunks = [];
|
|
1207
|
+
let truncated = false;
|
|
1175
1208
|
try {
|
|
1176
1209
|
const stream = llm.stream({
|
|
1177
1210
|
provider,
|
|
@@ -1179,24 +1212,28 @@ async function extractBatch(ctx, agent, batch, signal) {
|
|
|
1179
1212
|
messages: [
|
|
1180
1213
|
{ role: 'user', content: [{ type: 'text', text: `${parts.join('\n\n')}\n\n${EXTRACT_INSTRUCTION}` }] },
|
|
1181
1214
|
],
|
|
1182
|
-
maxTokens: EXTRACT_TOKENS_PER_TURN * parts.length,
|
|
1215
|
+
maxTokens: EXTRACT_TOKENS_PER_TURN * parts.length + EXTRACT_THINKING_RESERVE_TOKENS,
|
|
1183
1216
|
sessionId: agent.session.id,
|
|
1184
1217
|
purpose: 'compaction',
|
|
1218
|
+
...(cheapest === undefined ? {} : { reasoningEffort: cheapest }),
|
|
1185
1219
|
...(signal === undefined ? {} : { signal }),
|
|
1186
1220
|
});
|
|
1187
1221
|
for await (const chunk of stream) {
|
|
1188
1222
|
const delta = chunk;
|
|
1189
1223
|
if (delta.type === 'text-delta' && typeof delta.text === 'string')
|
|
1190
1224
|
chunks.push(delta.text);
|
|
1225
|
+
else if (delta.type === 'finish' && delta.reason?.kind === 'max-tokens')
|
|
1226
|
+
truncated = true;
|
|
1191
1227
|
}
|
|
1192
1228
|
}
|
|
1193
|
-
catch {
|
|
1194
|
-
|
|
1229
|
+
catch (error) {
|
|
1230
|
+
ctx.logger?.warn(`verbatim-compaction: extraction call failed for ${parts.length} slot(s): ${String(error)}`);
|
|
1231
|
+
return { blocks: out, truncated: false };
|
|
1195
1232
|
}
|
|
1196
1233
|
const answer = chunks.join('').trim();
|
|
1197
1234
|
if (answer.length === 0)
|
|
1198
|
-
return out;
|
|
1199
|
-
return parseExtraction(answer);
|
|
1235
|
+
return { blocks: out, truncated };
|
|
1236
|
+
return { blocks: parseExtraction(answer), truncated };
|
|
1200
1237
|
}
|
|
1201
1238
|
/**
|
|
1202
1239
|
* Deterministic compaction backend: verbatim prose, pointerized tools, no model
|
package/lib/types/index.d.ts
CHANGED
|
@@ -80,23 +80,6 @@ export interface SummaryResult {
|
|
|
80
80
|
* @returns true only when the log itself marks the result as an error.
|
|
81
81
|
*/
|
|
82
82
|
export declare function isErrorResult(event: SessionEvent): boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Drop headings whose body says nothing.
|
|
85
|
-
*
|
|
86
|
-
* The instruction asks the model to omit empty sections, but a model that writes
|
|
87
|
-
* `## Overturned\n- (none)` anyway must not cost tokens on every turn: 130 turns
|
|
88
|
-
* of that placeholder is ~900 tokens recording that nothing was overturned. So
|
|
89
|
-
* the shape is enforced here as well, not only requested in the prompt.
|
|
90
|
-
*
|
|
91
|
-
* A heading is dropped when every non-blank line under it, once its bullet is
|
|
92
|
-
* stripped, is a placeholder — `(none)`, `none`, `n/a`, `-`, `无`. A heading with
|
|
93
|
-
* any real content is kept verbatim.
|
|
94
|
-
*
|
|
95
|
-
* @param body - one slot's extracted text.
|
|
96
|
-
* @returns the same text with empty sections removed, or an empty string when
|
|
97
|
-
* nothing substantive remains.
|
|
98
|
-
*/
|
|
99
|
-
export declare function pruneEmptySections(block: string): string;
|
|
100
83
|
/** One slot's extraction, as the model returns it. */
|
|
101
84
|
export interface Extraction {
|
|
102
85
|
did: string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logictan/dsh-verbatim-compaction",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Deterministic compaction backend that keeps conversation prose verbatim in the checkpoint instead of re-summarizing it: user and assistant text survive word for word, tool results collapse to one-line pointers, reasoning is never read, and no model call is made.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|