@logictan/dsh-verbatim-compaction 0.8.0 → 0.9.0

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 CHANGED
@@ -62,7 +62,7 @@
62
62
 
63
63
  所以提取的材料是三段:用户请求(逐字)、助手正文(逐字)、工具轨迹(每条调用的 `description`,失败的调用另记一行首行错误)。模型输出固定的四节:`## Asked` / `## Did` / `## Concluded` / `## Overturned`。
64
64
 
65
- 空节直接删掉,不留占位。占位符既包括 `(none)`/`n/a`/`无`,也包括模型爱写的 `未提问。`;判据同时覆盖标题行(`## Asked`、裸写 `Asked`)和行内形式(`- Did: …`、`**Asked**:…`)——两种形式会混在同一个块里。判据同时接受 `## 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`、`无法连接,改用代理` 这类真内容照原样保留。
65
+ 空节直接删掉,不留占位。占位符既包括 `(none)`/`n/a`/`无`,也包括模型爱写的 `未提问。`;判据同时覆盖标题行(`## Asked`、裸写 `Asked`)和行内形式(`- Did: …`、`**Asked**:…`)——两种形式会混在同一个块里。中文标签(`问:`/`做:`/`结论:`/`推翻:`)同样识别:模型对中文会话会直接改用中文标签,只认英文时 `Asked` 不会被移到最后、空节也不会被清。判据同时接受 `## 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
 
@@ -86,6 +86,8 @@
86
86
 
87
87
  `## Asked` 由代码移到最后(`moveAskedLast`),因为用户的回复常常只有「8399」「继续」,只有紧接在提问后面才读得懂。模型用过三种写法——`## Asked`、`**Asked**:`、`- Asked:`——三种都认。
88
88
 
89
+ `ask_user_question` 不计入工具调用上限(120 条)。它是「问了什么」的唯一记录,而答案按调用 id 匹配、不受上限约束;提问被截断时答案会变成孤立一行——实测一轮 292 次调用,提问排在后面被切掉,用户的选择就此丢失。
90
+
89
91
  `ask_user_question` 的问题与用户选择都会进材料。它没有 `description` 参数,载荷在 `questions[]`,原来只留下 `TOOL ask_user_question` 五个字——问题是什么、用户选了什么全丢。答案在工具结果里(`answers[].selected`,或用户自己打字时的 `answers[].custom`),实测 31 次提问里 10 次是打字回答。
90
92
 
91
93
  一个 section 就是一次请求、一个 turn。日志会在同一次请求里推进 turn 号(实测一个请求的 7 条助手消息记作 turn 2、另 9 条记作 turn 3),按号码切分会把一个请求拆成「空请求 turn + 无用户消息的回复 turn」,摘要里就出现两个 `### assistant`。用户消息本身不带 turn 字段,这条也曾让两者永远对不上。
package/lib/index.js CHANGED
@@ -256,10 +256,10 @@ export function pruneEmptySections(block) {
256
256
  const headingOf = (line) => {
257
257
  if (/^#{1,6}\s/.test(line))
258
258
  return { own: '' };
259
- if (/^\s*(?:[-*]\s+)?(?:\*\*)?(Asked|Did|Concluded|Overturned)(?:\*\*)?\s*[::]?\s*$/i.test(line)) {
259
+ if (/^\s*(?:[-*]\s+)?(?:\*\*)?(Asked|Did|Concluded|Overturned|问|做|结论|推翻)(?:\*\*)?\s*[::]?\s*$/i.test(line)) {
260
260
  return { own: '' };
261
261
  }
262
- const inline = /^\s*(?:[-*]\s+)?(?:\*\*)?(Asked|Did|Concluded|Overturned)(?:\*\*)?\s*[::]\s*(.*)$/i.exec(line);
262
+ const inline = /^\s*(?:[-*]\s+)?(?:\*\*)?(Asked|Did|Concluded|Overturned|问|做|结论|推翻)(?:\*\*)?\s*[::]\s*(.*)$/i.exec(line);
263
263
  if (inline !== null)
264
264
  return { own: inline[2] ?? '' };
265
265
  return undefined;
@@ -422,12 +422,20 @@ export function collectHints(events) {
422
422
  // matched nothing and a 342-call turn produced a single hint line.
423
423
  if (event.type === 'assistant/message') {
424
424
  for (const call of toolCallsOf(event)) {
425
- if (calls >= MAX_HINTS_PER_TURN)
426
- break;
427
- calls += 1;
425
+ // A question is never dropped by the cap. It is the only record of what was
426
+ // asked, and its answer is matched by call id rather than by the cap, so
427
+ // dropping the question left an orphan ANSWER line with nothing beside it —
428
+ // a real turn made 292 calls, the question came late, and the user's choice
429
+ // never reached the digest.
430
+ const isQuestion = call.name === 'ask_user_question';
431
+ if (!isQuestion) {
432
+ if (calls >= MAX_HINTS_PER_TURN)
433
+ break;
434
+ calls += 1;
435
+ }
428
436
  const hint = hintOf(call.arguments);
429
437
  lines.push(hint.length > 0 ? `TOOL ${call.name}: ${hint}` : `TOOL ${call.name}`);
430
- if (call.name === 'ask_user_question')
438
+ if (isQuestion)
431
439
  askedIds.add(call.id);
432
440
  }
433
441
  continue;
@@ -677,9 +685,9 @@ export function moveAskedLast(block) {
677
685
  // Three heading forms observed from the same model: `## Asked`, `**Asked**:` and
678
686
  // `- Asked:`. Recognising only the first left Asked at the top whenever the model
679
687
  // changed style.
680
- const isAsked = (line) => /^\s*(?:#{0,6}\s*|[-*]\s+)?(?:\*\*)?Asked(?:\*\*)?\s*[::]?\s*$/i.test(line);
681
- const isAskedInline = (line) => /^\s*(?:[-*]\s+)?(?:\*\*)?Asked(?:\*\*)?\s*[::]/i.test(line);
682
- const isOther = (line) => /^\s*(?:#{0,6}\s*|[-*]\s+)?(?:\*\*)?(Did|Concluded|Overturned)(?:\*\*)?\s*[::]?/i.test(line);
688
+ const isAsked = (line) => /^\s*(?:#{0,6}\s*|[-*]\s+)?(?:\*\*)?(?:Asked|问)(?:\*\*)?\s*[::]?\s*$/i.test(line);
689
+ const isAskedInline = (line) => /^\s*(?:[-*]\s+)?(?:\*\*)?(?:Asked|问)(?:\*\*)?\s*[::]/i.test(line);
690
+ const isOther = (line) => /^\s*(?:#{0,6}\s*|[-*]\s+)?(?:\*\*)?(Did|Concluded|Overturned|做|结论|推翻)(?:\*\*)?\s*[::]?/i.test(line);
683
691
  const start = lines.findIndex((line) => isAsked(line) || isAskedInline(line));
684
692
  if (start < 0)
685
693
  return block;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logictan/dsh-verbatim-compaction",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
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",