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
@@ -74,5 +74,10 @@ class SandboxConfig(BaseModel):
ge=0,
description="Maximum characters to keep from read_file tool output. Output exceeding this limit is head-truncated. Set to 0 to disable truncation.",
)
ls_output_max_chars: int = Field(
default=20000,
ge=0,
description="Maximum characters to keep from ls tool output. Output exceeding this limit is head-truncated. Set to 0 to disable truncation.",
)
model_config = ConfigDict(extra="allow")