Skip to content

fix(agent): pi 已截断的长输出不再切「假头」,摘录预算全给尾部 - #833

Merged
J3n5en merged 1 commit into
mainfrom
fix/bash-excerpt-true-head
Dec 3, 2026
Merged

J3n5en merged 1 commit into
mainfrom
fix/bash-excerpt-true-head

Conversation

@J3n5en

@J3n5en J3n5en commented Dec 3, 2026

Copy link
Copy Markdown
Owner

问题

pi 的 bash 超过 2000 行 / 50KB 时只留尾部。上一层 toolOutputBudget 再用 excerpt() 切「头 20% / 尾 80%」时,那个「头」已经是原输出的中段,不是命令第一行 —— 等于拿假开头骗模型。

真实链路实测(createBashToolDefinition + withToolOutputBudget,2500 行输出):details.truncation.truncated=true、truncatedBy=bytes、totalBytes=96415、outputBytes=51180,而当时摘录的第一段是 ok Case2295... 这种中段行。

改动

按 result.details.truncation.truncated 条件化:

  • pi 已截断 → excerpt(..., { head: '' }):纯尾摘录,8192 名额全给尾巴,开头直接是 … [N bytes omitted] …;
  • pi 未截断(32–50KB 档,details 里没有 truncation 字段)→ 保持 20% 真头;
  • excerptText 顺手去掉纯尾模式下多出来的前导空行。

实测

输入 details.truncation 模型可见 首行 结论行
2500 行 / 96KB truncated=true (bytes) 8605 字节,以 … [43130 bytes omitted] … 开头 LINE_ONE 已丢(符合预期) SUMMARY_TAIL 保留
700 行 / ~40KB 无该字段 8609 字节 LINE_ONE 保留(真头) SUMMARY_TAIL 保留

验证

tsc --noEmit 通过;biome check 通过;pnpm test:changed 35 文件 / 430 测试通过;src/agent/toolOutputBudget.test.ts 16 用例(新增「已截断不给假头」「未截断保留真头」两例)。

本次不做

不在本层读 details.fullOutputPath 把真开头拼回来:全量日志路径已经在 pi 的提示文本里(保留在尾巴中),模型需要时一次 read 就能拿到,没必要每轮都塞进窗口。

pi 的 bash 超过 2000 行 / 50KB 时只留尾部,此时正文开头已是原输出的中段;
再按 20% 切「头」等于把中段当命令开头展示给模型。

改为按 result.details.truncation.truncated 条件化:已截断则传 head 为空(纯尾,
8192 名额全给尾巴,开头直接是 … [N bytes omitted] …);未截断(32–50KB 档,
details 里没有 truncation)仍保留真头。excerptText 顺手去掉纯尾模式的前导空行。
@J3n5en
J3n5en merged commit 7607aaa into main Dec 3, 2026
5 checks passed
@J3n5en
J3n5en deleted the fix/bash-excerpt-true-head branch December 3, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant