feat(truncate): allow configuring tool output truncation limits#23770
Merged
rekram1-node merged 4 commits intoanomalyco:devfrom Apr 23, 2026
Merged
feat(truncate): allow configuring tool output truncation limits#23770rekram1-node merged 4 commits intoanomalyco:devfrom
rekram1-node merged 4 commits intoanomalyco:devfrom
Conversation
Add an optional `tool_output` section to opencode config so users can override the default 2000-line / 50 KB thresholds that apply before tool output is truncated and saved to the truncation directory. - config: new `tool_output.max_lines` and `tool_output.max_bytes` - Truncate service: new `limits()` method that resolves from config, falling back to `MAX_LINES` / `MAX_BYTES` when config is absent (kept for backward compatibility and for contexts where the Config service is not provided, e.g. tests) - bash tool: reads limits from the service so the description presented to the model and the internal streaming cap both reflect the user's configuration
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
teknium1
added a commit
to NousResearch/hermes-agent
that referenced
this pull request
Apr 24, 2026
* feat(config): make tool output truncation limits configurable 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. * feat(skills): add design-md skill for Google's DESIGN.md spec Built-in skill under skills/creative/ that teaches the agent to author, lint, diff, and export DESIGN.md files — Google's open-source (Apache-2.0) format for describing a visual identity to coding agents. Covers: - YAML front matter + markdown body anatomy - Full token schema (colors, typography, rounded, spacing, components) - Canonical section order + duplicate-heading rejection - Component property whitelist + variants-as-siblings pattern - CLI workflow via 'npx @google/design.md' (lint/diff/export/spec) - Lint rule reference including WCAG contrast checks - Common YAML pitfalls (quoted hex, negative dimensions, dotted refs) - Starter template at templates/starter.md Package verified live on npm (@google/design.md@0.1.1).
xywsxp
pushed a commit
to xywsxp/opencode
that referenced
this pull request
Apr 24, 2026
…alyco#23770) Co-authored-by: rgs_ramp <rgs@ramp.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
nekorytaylor666
pushed a commit
to nekorytaylor666/hermes-agent
that referenced
this pull request
Apr 24, 2026
…search#14876) * feat(config): make tool output truncation limits configurable 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. * feat(skills): add design-md skill for Google's DESIGN.md spec Built-in skill under skills/creative/ that teaches the agent to author, lint, diff, and export DESIGN.md files — Google's open-source (Apache-2.0) format for describing a visual identity to coding agents. Covers: - YAML front matter + markdown body anatomy - Full token schema (colors, typography, rounded, spacing, components) - Canonical section order + duplicate-heading rejection - Component property whitelist + variants-as-siblings pattern - CLI workflow via 'npx @google/design.md' (lint/diff/export/spec) - Lint rule reference including WCAG contrast checks - Common YAML pitfalls (quoted hex, negative dimensions, dotted refs) - Starter template at templates/starter.md Package verified live on npm (@google/design.md@0.1.1).
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.
Issue for this PR
Closes #22565
Type of change
What does this PR do?
Moves the tool-output truncation thresholds (
MAX_LINES = 2000,MAX_BYTES = 50 * 1024inpackages/opencode/src/tool/truncate.ts) from hardcoded constants into optional opencode config.New config:
{ "tool_output": { "max_lines": 5000, "max_bytes": 204800 } }Truncate.Servicegains alimits()method that reads those values fromConfig.Serviceand falls back to the existing constants.output()uses it as the default, so callers that pass{}(e.g.Tool.wrap) pick up the config without any change at the call site.Config.Serviceis read withEffect.serviceOption, so tests and any other caller ofTruncate.defaultLayerthat doesn't provide Config keep working and get the original defaults.bash.tsalso readTruncate.MAX_LINES/Truncate.MAX_BYTESdirectly in two spots (its internal streaming cap, and the${maxLines}/${maxBytes}placeholders it substitutes into the tool description shown to the model) — switched both totrunc.limits()so the advertised and enforced limits track config.How did you verify your code works?
Tests from
packages/opencode:The new truncation tests mock
Config.ServiceviaLayer.mockand assert:limits()returns{ maxLines: 123, maxBytes: 456 }when config sets thoseoutput()with a 100-line input truncates to "...90 lines truncated..." whenmax_lines: 10, max_bytes: 1 MB(isolates the line path)output()with a 1000-byte input shows "bytes truncated..." whenmax_lines: 1_000_000, max_bytes: 100(isolates the byte path)options.maxLines/options.maxBytesstill override configlimits()returns the existingMAX_LINES/MAX_BYTES— the test file's default layer is unchanged, so the other 15 tests also prove the no-config pathAlso passing:
bun run typecheckinpackages/opencode(tsgo --noEmit)typecheckover all 13 workspace packagesReproducing manually: drop
{"tool_output":{"max_lines":10,"max_bytes":1048576}}into your opencode config and run a bash command whose output exceeds 10 lines — it truncates at 10 instead of 2000.Screenshots / recordings
N/A — no UI changes.
Checklist