Repository navigation
fix(agent): pi 已截断的长输出不再切「假头」,摘录预算全给尾部 - #833
Merged
Merged
Conversation
pi 的 bash 超过 2000 行 / 50KB 时只留尾部,此时正文开头已是原输出的中段; 再按 20% 切「头」等于把中段当命令开头展示给模型。 改为按 result.details.truncation.truncated 条件化:已截断则传 head 为空(纯尾, 8192 名额全给尾巴,开头直接是 … [N bytes omitted] …);未截断(32–50KB 档, details 里没有 truncation)仍保留真头。excerptText 顺手去掉纯尾模式的前导空行。
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.
问题
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条件化:excerpt(..., { head: '' }):纯尾摘录,8192 名额全给尾巴,开头直接是… [N bytes omitted] …;details里没有truncation字段)→ 保持 20% 真头;excerptText顺手去掉纯尾模式下多出来的前导空行。实测
truncated=true(bytes)… [43130 bytes omitted] …开头LINE_ONE已丢(符合预期)SUMMARY_TAIL保留LINE_ONE保留(真头)SUMMARY_TAIL保留验证
tsc --noEmit通过;biome check通过;pnpm test:changed35 文件 / 430 测试通过;src/agent/toolOutputBudget.test.ts16 用例(新增「已截断不给假头」「未截断保留真头」两例)。本次不做
不在本层读
details.fullOutputPath把真开头拼回来:全量日志路径已经在 pi 的提示文本里(保留在尾巴中),模型需要时一次read就能拿到,没必要每轮都塞进窗口。