Skip to content

feat(config): make tool output truncation limits configurable - #14824

Closed
teknium1 wants to merge 1 commit into
mainfrom
opencode-port/configurable-tool-output-limits
Closed

feat(config): make tool output truncation limits configurable#14824
teknium1 wants to merge 1 commit into
mainfrom
opencode-port/configurable-tool-output-limits

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Port 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.

Motivation (from the upstream PR)

OpenCode had MAX_LINES = 2000 and MAX_BYTES = 50 * 1024 hardcoded in packages/opencode/src/tool/truncate.ts. Hermes-agent had the same constants hardcoded in two places:

  • tools/terminal_tool.pyMAX_OUTPUT_CHARS = 50000 (terminal stdout cap)
  • tools/file_operations.pyMAX_LINES = 2000 / MAX_LINE_LENGTH = 2000

Users 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

tool_output:
  max_bytes: 50000        # terminal output cap (chars)
  max_lines: 2000         # read_file pagination cap
  max_line_length: 2000   # per-line cap in read_file's line-numbered view
  • New tools/tool_output_limits.py — defensive reader. Missing/invalid values fall back to the pre-existing hardcoded defaults. Never raises.
  • tools/terminal_tool.pyMAX_OUTPUT_CHARS now pulled via get_max_bytes() at call time.
  • tools/file_operations.pynormalize_read_pagination() and _add_line_numbers() pull limits at call time.
  • hermes_cli/config.pyDEFAULT_CONFIG gains the tool_output section 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.Service that 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_file pagination) 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_lines use the same names as upstream. max_line_length is 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

Before After
Terminal cap hardcoded 50000 tool_output.max_bytes (default 50000)
read_file cap hardcoded 2000 tool_output.max_lines (default 2000)
Per-line cap hardcoded 2000 tool_output.max_line_length (default 2000)
Behaviour w/o config n/a identical to before
  • 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.
  • E2E: built a tmp HERMES_HOME with a config setting max_bytes: 200 / max_lines: 10, verified get_tool_output_limits() returns the overrides and normalize_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).

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.
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/tools Tool registry, model_tools, toolsets tool/terminal Terminal execution and process management tool/file File tools (read, write, patch, search) area/config Config system, migrations, profiles labels Apr 24, 2026
@teknium1

Copy link
Copy Markdown
Contributor Author

Closing as already on main. tools/tool_output_limits.py ships with get_max_bytes() / get_max_lines() / get_max_line_length(), wired into tools/terminal_tool.py (L2099-2103) and tools/file_operations.py (L487, L610). tool_output: section is in DEFAULT_CONFIG. All 18 tests in tests/tools/test_tool_output_limits.py pass on current main.

Credit to your OpenCode#23770 scout — the landed implementation matches the approach.

@teknium1 teknium1 closed this May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/tools Tool registry, model_tools, toolsets P3 Low — cosmetic, nice to have tool/file File tools (read, write, patch, search) tool/terminal Terminal execution and process management type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants