Skip to content

fix(verbose): 修复 thinking 多行阶梯错乱与中文截断乱码 - #1

Merged
holihur merged 1 commit into
holihur:mainfrom
dolphinZzv:fix/verbose-thinking-display
Sep 2, 2026
Merged

holihur merged 1 commit into
holihur:mainfrom
dolphinZzv:fix/verbose-thinking-display

Conversation

@dolphinZzv

Copy link
Copy Markdown

问题

用户反馈 -display-thinking 默认开启时,[thinking] 在终端出现阶梯状缩进:

[thinking] 用户现在在郑州金水东路...
                                                                                             我需要考虑:
        1. 用户的位置:郑州金水东路
                                   2. 时间:今天中午

且中文长思考被截断时出现 �。

根因

  1. 内部 \n 未转 \r\n: cli 在 term.MakeRaw 后清 OPOST,裸 \n 不回车。2028fc3 只修了行尾 \r\n,verbose.go:72 的 text 内部多行仍是裸 \n,每行起始列=上一行结束列,形成阶梯。preview 同理。
  2. 按字节截断:len(text)>500 按字节,中文 1字3字节,text[:500] 易切在字符中间。

修复

  • thinking:统一 \r\n/\r -> \n,按 []rune 截断 500,再 \n -> \r\n 后打印,保持与 cli.write 一致的 raw 兼容
  • preview:归一化后压成单行(\n -> 空格),按 []rune 截断 300,避免多行工具输入同样阶梯

验证

  • go test ./internal/hook/verbose -v 通过,原有 ASCII 截断行为不变(rune len 对 ASCII 等价)
  • go test ./... 全绿
  • 手动验证中文 郑州金水东路 多行 thinking 与 中 重复截断不再出现乱码,换行正常回首列

备注

新增注释为必要说明,解释非显而易见的 raw/UTF-8 处理意图,避免被回退。

Fixes: thinking 显示错乱

- thinking 内部 \n 统一转 \r\n,避免 raw 模式(OPOST 已清)下裸 \n 不回车导致的阶梯缩进
- preview 压成单行后再打印,避免工具输入中的换行同样阶梯错位
- 截断从字节 len 改为 rune len,避免中文(3字节)被切半出现 �,与 ci 中文用例一致
- 归一化 \r\n/\r -> \n 再转 \r\n,兼容不同模型返回
@holihur
holihur merged commit 066458f into holihur:main Sep 2, 2026
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.

2 participants