feat(cli): make MAX_CODE_BLOCK_LINES configurable via env vars - #9301
Conversation
Adds three environment variables to control code block truncation in streaming output: - GOOSE_MAX_CODE_BLOCK_LINES: threshold before truncation (default: 50) - GOOSE_TRUNCATED_SHOW_LINES: lines shown before the cut (default: 20) - GOOSE_NO_CODE_TRUNCATION: set to "1" or "true" to disable entirely Closes aaif-goose#9300. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Pendleton <spendleton@bluecatnetworks.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fef648529d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…length If GOOSE_TRUNCATED_SHOW_LINES exceeds the actual code block line count, the subtraction would underflow. Clamp to lines.len() before subtracting. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Pendleton <spendleton@bluecatnetworks.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0c89f67d4f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
When GOOSE_TRUNCATED_SHOW_LINES exceeds GOOSE_MAX_CODE_BLOCK_LINES, blocks just over the threshold would render all lines then show "... (0 more lines)" with a temp file. Clamp to both max_lines and lines.len() so truncation always omits at least one line. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Pendleton <spendleton@bluecatnetworks.com>
…SE_NO_CODE_TRUNCATION to env vars guide Signed-off-by: Douwe Osinga <douwe@squareup.com>
DOsinga
left a comment
There was a problem hiding this comment.
Code is clean and well-scoped. Merged main and added a commit to document the three new env vars (GOOSE_MAX_CODE_BLOCK_LINES, GOOSE_TRUNCATED_SHOW_LINES, GOOSE_NO_CODE_TRUNCATION) in the environment variables guide.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d5669251a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The previous truncation matched the closing fence with `find("\n```")`
or `find("\n~~~")`. Two issues:
1. A block opened with a longer outer fence (e.g. ` ```` `) would be
prematurely closed by a shorter inner fence (e.g. ` ``` `), leaving
the inner-fence run as a stray closer in the output.
2. A code line that merely *begins* with backticks (` ``` not a fence`)
was misread as the closing fence.
Track the actual opening fence run length and require closing fences
to occupy the whole line (only fence chars + optional trailing
whitespace), matching CommonMark fence semantics.
Extracted `truncate_code_blocks_with(content, max_lines, show_lines)`
so the behaviour is testable without setting env vars, and added tests
for longer outer backtick/tilde fences and non-fence backtick lines.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Stephen Pendleton <spendleton@bluecatnetworks.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 75bbb0210a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
GOOSE_MAX_CODE_BLOCK_LINES and GOOSE_TRUNCATED_SHOW_LINES are documented as positive integers, but the previous parser accepted 0. With max=0, every non-empty fenced block was treated as over-limit and rendered with zero visible lines plus a temp-file pointer, effectively hiding all inline code output for users who supplied an invalid value. Validate the parsed value with `> 0` so zero (and other invalid input like negatives or non-numerics, which were already rejected by parse failure) falls back to the documented default. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stephen Pendleton <spendleton@bluecatnetworks.com>
…goose#9301) Signed-off-by: Stephen Pendleton <spendleton@bluecatnetworks.com> Signed-off-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Stephen Pendleton <spendleton@bluecatnetworks.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Douwe Osinga <douwe@squareup.com>
Closes #9300.
Summary
Makes the hard-coded
MAX_CODE_BLOCK_LINES(50) andTRUNCATED_SHOW_LINES(20) configurable via environment variables incrates/goose-cli/src/session/streaming_buffer.rs. Also adds an option to disable code block truncation entirely.Motivation
The streaming buffer truncates code blocks longer than 50 lines, saving full content to a temp file. This forces users who want to see complete code output to locate and parse the temp file — painful for workflows that pipe output or need inline visibility. Users had no way to adjust or bypass this behavior.
Design
Three new environment variables, read once via
LazyLock(zero per-call overhead):GOOSE_MAX_CODE_BLOCK_LINES50GOOSE_TRUNCATED_SHOW_LINES20GOOSE_NO_CODE_TRUNCATION1ortrueto disable truncation entirelyWhen
GOOSE_NO_CODE_TRUNCATIONis active,truncate_code_blocksreturns content unchanged — no temp file is created.Tests
cargo fmt -p goose-cli --checkandcargo clippy -p goose-cli -- -D warningsboth clean.Backwards compatibility
No behavior change when env vars are unset. Existing defaults (50/20) are preserved. No new dependencies. No public API change.
Checklist
cargo buildcargo test-D warningscargo fmt --checkclean