feat(config): make tool output truncation limits configurable - #14824
Closed
teknium1 wants to merge 1 commit into
Closed
feat(config): make tool output truncation limits configurable#14824teknium1 wants to merge 1 commit into
teknium1 wants to merge 1 commit into
Conversation
Port from anomalyco/opencode#23770: expose a new `tool_output` config section so users can tune the hardcoded truncation caps that apply to terminal output and read_file pagination. Three knobs under `tool_output`: - max_bytes (default 50_000) — terminal stdout/stderr cap - max_lines (default 2000) — read_file pagination cap - max_line_length (default 2000) — per-line cap in line-numbered view All three keep their existing hardcoded values as defaults, so behaviour is unchanged when the section is absent. Power users on big-context models can raise them; small-context local models can lower them. Implementation: - New `tools/tool_output_limits.py` reads the section with defensive fallback (missing/invalid values → defaults, never raises). - `tools/terminal_tool.py` MAX_OUTPUT_CHARS now comes from get_max_bytes(). - `tools/file_operations.py` normalize_read_pagination() and _add_line_numbers() now pull the limits at call time. - `hermes_cli/config.py` DEFAULT_CONFIG gains the `tool_output` section so `hermes setup` writes defaults into fresh configs. - Docs page `user-guide/configuration.md` gains a "Tool Output Truncation Limits" section with large-context and small-context example configs. Tests (18 new in tests/tools/test_tool_output_limits.py): - Default resolution with missing / malformed / non-dict config. - Full and partial user overrides. - Coercion of bad values (None, negative, wrong type, str int). - Shortcut accessors delegate correctly. - DEFAULT_CONFIG exposes the section with the right defaults. - Integration: normalize_read_pagination clamps to the configured max_lines.
Contributor
Author
|
Closing as already on main. Credit to your OpenCode#23770 scout — the landed implementation matches the approach. |
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.
Summary
Port anomalyco/opencode#23770 — expose a new
tool_outputconfig section so users can tune the hardcoded truncation caps that apply to terminal output andread_filepagination.Motivation (from the upstream PR)
OpenCode had
MAX_LINES = 2000andMAX_BYTES = 50 * 1024hardcoded inpackages/opencode/src/tool/truncate.ts. Hermes-agent had the same constants hardcoded in two places:tools/terminal_tool.py—MAX_OUTPUT_CHARS = 50000(terminal stdout cap)tools/file_operations.py—MAX_LINES = 2000/MAX_LINE_LENGTH = 2000Users on big-context models (opus-4.6, sonnet-4.6, MiniMax M2.7) wanted to let tools return more raw output before truncation. Users on small local models wanted the opposite.
Changes
tools/tool_output_limits.py— defensive reader. Missing/invalid values fall back to the pre-existing hardcoded defaults. Never raises.tools/terminal_tool.py—MAX_OUTPUT_CHARSnow pulled viaget_max_bytes()at call time.tools/file_operations.py—normalize_read_pagination()and_add_line_numbers()pull limits at call time.hermes_cli/config.py—DEFAULT_CONFIGgains thetool_outputsection so fresh installs write these keys.website/docs/user-guide/configuration.md— new section with large-context and small-context example configs.Architectural differences from OpenCode
OpenCode's version routes all tool output through a
Truncate.Servicethat also writes the full text to a scratch directory and returns a preview + hint. Hermes-agent's truncation lives at two separate call sites (terminal head/tail split,read_filepagination) so the port is a straight s/hardcoded/configurable swap rather than a service introduction. The config surface matches:tool_output.max_bytes/tool_output.max_linesuse the same names as upstream.max_line_lengthis a Hermes-specific addition (OpenCode doesn't have an equivalent per-line cap).Default-preserving by design: users who don't set the section get the identical behaviour they had before this PR.
Validation
tool_output.max_bytes(default 50000)tool_output.max_lines(default 2000)tool_output.max_line_length(default 2000)scripts/run_tests.sh tests/tools/test_tool_output_limits.py— 18/18 passing.scripts/run_tests.sh tests/tools/ -k 'file_op or read_file or pagination or terminal'— 237/237 passing.HERMES_HOMEwith a config settingmax_bytes: 200 / max_lines: 10, verifiedget_tool_output_limits()returns the overrides andnormalize_read_pagination(limit=500)clamps to 10. Also verified the no-config path returns the defaults.Credit
Ported from @anomaly's OpenCode (PR #23770 upstream).