@logictan/dsh-verbatim-compaction 0.6.0 → 0.6.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 +1 -1
- package/lib/index.js +41 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
|
|
63
63
|
所以提取的材料是三段:用户请求(逐字)、助手正文(逐字)、工具轨迹(每条调用的 `description`,失败的调用另记一行首行错误)。模型输出固定的四节:`## Asked` / `## Did` / `## Concluded` / `## Overturned`。
|
|
64
64
|
|
|
65
|
-
空节直接删掉,不留 `(none)`
|
|
65
|
+
空节直接删掉,不留 `(none)` 占位。判据同时接受 `## Asked` 和裸写 `Asked`——实测模型有时不带 `##`,只认 `^#{1,6}` 会让 `Concluded\n- (none)` 原样留在摘要里。实测一份真实提取块里 `## Asked` 和 `## Overturned` 都是 `(none)`,删掉后 312 → 271 字符;按 130 轮算,这些占位合计约 900 token 只是在记录「什么都没发生」。清理在代码里做(`pruneEmptySections`),不只依赖提示词——模型仍写了 `(none)` 也不会白花 token。判据是整节每一行去掉项目符号后都只是 `(none)` / `none` / `n/a` / `无` 之类的占位;`none of the tests passed`、`无法连接,改用代理` 这类真内容照原样保留。
|
|
66
66
|
|
|
67
67
|
`## Asked` 记的是「**助手**向**用户**提了什么、给了哪些选项」。这一节最容易错成「把用户请求改写一遍」——真实一次压缩里,模型把用户那段中文请求翻成英文塞进了 `Asked`,而用户原话就在它上面逐字抄着,同一件事写了两遍。
|
|
68
68
|
|
package/lib/index.js
CHANGED
|
@@ -217,8 +217,13 @@ export function pruneEmptySections(body) {
|
|
|
217
217
|
pendingHeading = undefined;
|
|
218
218
|
pendingBody = [];
|
|
219
219
|
};
|
|
220
|
+
// A heading is either `## Name` or the bare name on its own line. Models
|
|
221
|
+
// sometimes answer without the `##`; a real run returned bare `Asked` / `Did` /
|
|
222
|
+
// `Concluded` lines, so a `^#{1,6}`-only test left `Concluded\n- (none)` in the
|
|
223
|
+
// digest as body text and the placeholder reached the reader.
|
|
224
|
+
const known = /^(Asked|Did|Concluded|Overturned)$/i;
|
|
220
225
|
for (const line of lines) {
|
|
221
|
-
if (/^#{1,6}\s/.test(line)) {
|
|
226
|
+
if (/^#{1,6}\s/.test(line) || known.test(line.trim())) {
|
|
222
227
|
flush();
|
|
223
228
|
pendingHeading = line;
|
|
224
229
|
continue;
|
|
@@ -937,34 +942,45 @@ export default class VerbatimCompactionEngine extends BasicCompactionEngine {
|
|
|
937
942
|
// Walk the same sections the renderer will use, so a key addresses the exact
|
|
938
943
|
// slot the block will be written into. Grouping by turn number instead lost
|
|
939
944
|
// blocks whenever the log reused a number.
|
|
945
|
+
// Partition the source into the same sections `buildSections` produced, then
|
|
946
|
+
// hand each section to its slot. A slot is a section, not a single message:
|
|
947
|
+
// the earlier version stopped at the first message, so a turn with 69
|
|
948
|
+
// assistant messages and 112 tool calls contributed 2 events out of 164 and
|
|
949
|
+
// the extractor reported "no work observed" for a turn that did plenty.
|
|
940
950
|
const sections = buildSections(source);
|
|
951
|
+
// Attribute events to sections by replaying the same walk `buildSections`
|
|
952
|
+
// does, so the two can never disagree about where a section starts. An
|
|
953
|
+
// independent scan drifted by one section on the fixture: `buildSections`
|
|
954
|
+
// opens a new section for an unclosed turn without consuming a user message.
|
|
955
|
+
const grouped = [];
|
|
956
|
+
let sectionIndex = -1;
|
|
957
|
+
const openedObjectives = new Set();
|
|
958
|
+
for (const event of source) {
|
|
959
|
+
const objective = goalObjective(event);
|
|
960
|
+
let startsSection = false;
|
|
961
|
+
if (objective !== undefined) {
|
|
962
|
+
if (!openedObjectives.has(objective)) {
|
|
963
|
+
openedObjectives.add(objective);
|
|
964
|
+
startsSection = true;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
else if (event.type === 'user/message' && !isInjection(event) && !isCheckpoint(event)) {
|
|
968
|
+
startsSection = true;
|
|
969
|
+
}
|
|
970
|
+
if (startsSection) {
|
|
971
|
+
sectionIndex += 1;
|
|
972
|
+
grouped[sectionIndex] = [];
|
|
973
|
+
}
|
|
974
|
+
if (sectionIndex >= 0)
|
|
975
|
+
grouped[sectionIndex]?.push(event);
|
|
976
|
+
}
|
|
941
977
|
const slots = [];
|
|
942
|
-
let lastTurn;
|
|
943
|
-
let cursor = 0;
|
|
944
978
|
for (const [sectionIndex, section] of sections.entries()) {
|
|
979
|
+
// A section may hold more than one turn; all of them see the section's
|
|
980
|
+
// events, because the material is about what the section did as a whole.
|
|
981
|
+
const events = grouped[sectionIndex] ?? [];
|
|
945
982
|
for (const [turnIndex, turn] of section.turns.entries()) {
|
|
946
|
-
|
|
947
|
-
// were built from the same array, so the cursor never rewinds.
|
|
948
|
-
const collected = [];
|
|
949
|
-
while (cursor < source.length) {
|
|
950
|
-
const event = source[cursor];
|
|
951
|
-
cursor += 1;
|
|
952
|
-
if (event === undefined)
|
|
953
|
-
break;
|
|
954
|
-
if (event.type === 'turn/start') {
|
|
955
|
-
const turnNumber = turnOf(event);
|
|
956
|
-
if (turnNumber !== undefined)
|
|
957
|
-
lastTurn = turnNumber;
|
|
958
|
-
collected.push(event);
|
|
959
|
-
continue;
|
|
960
|
-
}
|
|
961
|
-
collected.push(event);
|
|
962
|
-
if (event.type === 'user/message' || event.type === 'assistant/message') {
|
|
963
|
-
if (!isInjection(event) && !isCheckpoint(event))
|
|
964
|
-
break;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
slots.push({ key: turnKey(sectionIndex, turnIndex), turn: turn.turn, events: collected });
|
|
983
|
+
slots.push({ key: turnKey(sectionIndex, turnIndex), turn: turn.turn, events });
|
|
968
984
|
}
|
|
969
985
|
}
|
|
970
986
|
const extracted = new Map();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logictan/dsh-verbatim-compaction",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.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",
|