You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(core): expose structured truncation counts and output file path in shell tool metadata #65018
When a foreground or background shell command produces output exceeding ToolOutput limits, Shell.result (packages/core/src/shell.ts:860-885) already computes the exact byte size (size), line count (total), retained line window (kept.length, total - kept.length + 1..total), and full spillover file path (info.file) in order to format the inline prose footer:
[showing lines 501-1000 of 1000; full output saved to /path/to/output]
However, those structured values are discarded immediately afterward:
Shell.capture only returns { output, truncated: true }.
ShellResult.metadata (packages/core/src/shell/result.ts:62-70) — used for both direct tool metadata and background <shell> synthetic completion notices — exposes only { truncated: true } without outputPath, totalBytes, shownBytes, totalLines, startLine, or endLine.
ShellTool's StructuredOutput (packages/core/src/tool/plugin/shell.ts:121) omits truncated (Struct.omit(output, ["exit", "status", "truncated", ...])) as well as the line/byte window counts, so Code Mode callers (tools.opencode.shell(...)), SDK consumers, and opencode run --format json streams have to regex-parse the human footer string to know whether output was clipped, where the spillover file lives, or which line range to read next.
We surfaced this while evaluating OpenCode 2.3.0 in containerized TraceTrial-Bench (C1-escalation-export-001), where large diagnostic exports require machine-readable truncation accounting and deterministic range continuation.
Proposed Approach
Surface the already-computed truncation fields additively without extra file I/O:
Include optional totalBytes, shownBytes, totalLines, startLine, and endLine on Shell.capture when truncated: true (alongside outputPath: info.file).
Propagate truncated and those optional counts + outputPath into ShellResult.metadata (covering both foreground tool_use metadata and background <shell> synthetic notifications) and ShellTool's StructuredOutput.
Happy to submit a focused PR with tool-shell.test.ts coverage if this direction looks good to the team.
Thanks for the detailed write-up! The request: when shell output is truncated, the shell tool should return the truncation details as structured fields (truncated, total and shown bytes, total lines, the start and end of the kept line range, and the output file path). That way Code Mode, SDK and opencode run --format json consumers wouldn't need to parse the [showing lines …] footer.
One detail from reading the current code on dev:
The shell tool's structured output already has an optional outputPath. It is set to the output file when a completed command's output was truncated.
The tool metadata already carries truncated, but the structured output leaves truncated out.
The line and byte counts appear only in the footer text.
So the gap is mainly the counts, and truncated in the structured output.
Maintainers will look at the request and the approach you describe. Related work on the shell result shape that may be useful context for a PR:
Activity
opencodejr commentedon Nov 19, 2026
Thanks for the detailed write-up! The request: when shell output is truncated, the shell tool should return the truncation details as structured fields (
truncated, total and shown bytes, total lines, the start and end of the kept line range, and the output file path). That way Code Mode, SDK andopencode run --format jsonconsumers wouldn't need to parse the[showing lines …]footer.One detail from reading the current code on
dev:outputPath. It is set to the output file when a completed command's output was truncated.truncated, but the structured output leavestruncatedout.So the gap is mainly the counts, and
truncatedin the structured output.Maintainers will look at the request and the approach you describe. Related work on the shell result shape that may be useful context for a PR: