fix: add output truncation to ls_tool to prevent context window overflow (#1896)

ls_tool was the only sandbox tool without output size limits, allowing
multi-MB results from large directories to blow up the model context
window. Add head-truncation (configurable via ls_output_max_chars,
default 20000) consistent with existing bash and read_file truncation.

Closes #1887

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
yangzheli
2026-04-06 15:09:57 +08:00
committed by GitHub
parent d7a3eff23e
commit 5fd2c581f6
4 changed files with 109 additions and 3 deletions
+2 -1
View File
@@ -392,10 +392,11 @@ sandbox:
# Tool output truncation limits (characters).
# bash uses middle-truncation (head + tail) since errors can appear anywhere in the output.
# read_file uses head-truncation since source code context is front-loaded.
# read_file and ls use head-truncation since their content is front-loaded.
# Set to 0 to disable truncation.
bash_output_max_chars: 20000
read_file_output_max_chars: 50000
ls_output_max_chars: 20000
# Option 2: Container-based AIO Sandbox
# Executes commands in isolated containers (Docker or Apple Container)