fix(compress): 出口同步内核瘦身的 compress 锚点 args (closes #340) - #342
Open
ranxianglei wants to merge 1 commit into
Open
Conversation
… request (closes #340)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题 (closes #340)
acp-kernel #230 修复(PR ranxianglei/acp-kernel#232)后,内核出口视图里的 compress 锚点调用文本会被瘦身(滤死范围 + >200 字符摘要存根化),但 pi 适配层
coreOutToAgentMessages(src/messages.ts)重建 assistant 消息时使用原始 entry 内容,不消费内核改写后的 tool-call text → 出口请求仍携带全量 args 复写本(风暴会话 01a07b3c 实测 16 条活锚点 args 合计 21.6K tokens,单条 924→278 chars)。方案
coreOutToAgentMessages新增coreTextByCallId映射 +syncToolCallArgs同步逻辑(取自已关 #338 的 m00462 实现,剥离全部 reasoning 相关部分,并补上其未覆盖的 no-#路径——单调用 compress 消息正是 22K 的主要形态):contentType: "tool-call"的 core——tool-result core 共享同一 toolCallId,其文本(如 "Compressed 3 messages into block b1")会覆盖调用文本导致indexOf("{")落空、同步静默失效(真实内核 E2E 抓到的回归,新增专项测试)syncToolCallArgs:仅对name === "compress"的 toolCall 动作(内核只改写 compress,可证守卫);取内核改写文本自首个{起的 JSON 部分(前缀与 content 形状由内核serializeCompacted保证保留),写回toolCall.argumentscontent数组/字符串的对象)回退原 args;字符串形式 args 保持字符串形状(镜像内核形状保留契约)#(patchRefTag)与#(reconstructToolCallMessage两分支)路径都生效;assistant 分支前移到 tag 检查之前(无 tag 的改写调用也要同步)纯文本同步,不动 thinking(#339 的 scope,正交)。
验证
npm run typecheck/npm test(630 pass / 0 fail / 3 skip,含 7 个新用例:单调用 no-# / # 路径 / 字节一致 no-op / 非 compress 花括号字符串 args / 字符串形状 / 不可解析回退 / tool-result 同 id 覆盖)/npm run build—— 在 pin 0.0.56 与 acp-kernel pr-232 overlay 下均通过coreOutToAgentMessages,出口 args 实测 478 → 278 chars,与内核改写逐字节一致<acp tokens="70" type="compress">m00013</acp>\n{...stubbed...}(tag 前缀 + 正文)依赖与后续