Skip to content

refactor(tools): 精简高频命令与文件工具返回载荷中的冗余字段 - #269

Merged
uvwt merged 1 commit into
mainfrom
refactor/trim-tool-response-noise
Nov 26, 2026
Merged

uvwt merged 1 commit into
mainfrom
refactor/trim-tool-response-noise

Conversation

@uvwt

@uvwt uvwt commented Nov 26, 2026

Copy link
Copy Markdown
Owner

变更说明

精简 exec_command / session_observe / session_act、search_text、read_file 等高频工具返回载荷中的冗余零值与常量字段,降低日常工具调用的上下文 Token 消耗:

  1. 命令工具按需输出(internal/tool/command):
    • stdout_truncated / stderr_truncated 及对应的 *_output_bytes、*_total_bytes、*_dropped_bytes、*_omitted_bytes 仅在该流发生截断/丢弃/省略时输出;
    • 空且未截断的 stderr、timed_out: false、默认 terminal: pipes 省略,仅在有值/触发时返回;
    • 移除无价值的 stdout_output_lines / stderr_output_lines 及其底层计算,并同步补齐 OutputSchema。
  2. search_text 按需输出上下文(internal/tool/file/search.go、internal/wslfilehelper):
    • 统一 rg、go_fallback 与 WSL go_wsl 三条路径:无前后上下文行时省略 before、after、context_start_line、context_end_line,存在上下文行时按需输出;
    • 顺带修正 go_fallback 末尾换行符拆分产生幽灵空行导致尾部上下文与 rg / go_wsl 不一致的问题。
  3. 移除 read_file 硬编码常量 encoding: utf-8(internal/tool/file):
    • 从 Host 返回体、WSL 返回体及 OutputSchema 中移除 encoding,非 UTF-8 仍保持返回 ENCODING_UNSUPPORTED。

验证

  • 本地通过 gofmt、go vet ./...、受影响全套 7 个测试包及 Linux 交叉编译(CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... + wslfilehelper 测试编译),全量跨平台测试交由本次 PR CI 验证。

@uvwt
uvwt merged commit d60ae9f into main Nov 26, 2026
14 of 15 checks passed
@uvwt
uvwt deleted the refactor/trim-tool-response-noise branch November 26, 2026 17:27
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