fix(llm): 压缩回合回滚为「与常规请求字节同构+仅追加尾指令」

- 撤销上轮 inject 行过滤:裁历史中间行从首个被删行起前缀缓存全断,等于全价重读
  (memory_note 坐会话开头附近,伤害≈整段)
- 一并修同类更隐蔽病灶:withProfile=false 会把第 1 条画像快照抽掉,缓存从 index 1
  就断——画像快照与占位裁剪全部照常(与常规请求同一拼法),压缩只换尾巴
- 摘要看不到距尾≥2轮的已省原料可接受:那些多已被后续 assistant 正文复述/已落盘
- 教训入码:文件内写明「压缩要同构、标题可狠筛,两套逻辑不可串用」+冒烟改断言
  字节同构
This commit is contained in:
2026-10-02 10:25:46 +08:00
parent abe5673926
commit 3eed51a07b
2 changed files with 12 additions and 13 deletions
+5 -2
View File
@@ -34,9 +34,12 @@ msgs = llm.buildMessages({ history: rows.slice(0, 5), profile_snapshot: '', bloc
assert(msgs.find(m => m.role === 'tool' && m.tool_call_id === 'c1').content.length > 7000, 'fetch 距尾 1 轮应保留');
assert.strictEqual(JSON.parse(msgs.filter(m => m.tool_calls).pop().tool_calls[0].function.arguments).content.length, 12000, 'write 参数距尾 0 轮应保留');
// C) 压缩回合不裁
// C) 压缩回合与常规拼装字节同构,仅尾部多一条指令(前缀缓存铁律)
const normal = llm.buildMessages(session(), 'Simplified Chinese', null, null);
const cm = llm.compressMessages(session(), 'Simplified Chinese', null, null);
assert(cm.find(m => m.role === 'tool' && m.tool_call_id === 'c1').content.length > 7000, '压缩回合保留原文');
assert(cm.length === normal.length + 1, '压缩=常规+尾指令');
assert(JSON.stringify(cm.slice(0, -1)) === JSON.stringify(normal), '前缀字节同构');
assert(/compact|concise/.test(cm.at(-1).content), '尾指令在位');
// D) read_file 回执同款
const r3orig = rows[2];