Skip to content

feat(core): expose structured truncation counts and output file path in shell tool metadata #65018

Open

Description

@zsicheng0214

Problem

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:

  1. Shell.capture only returns { output, truncated: true }.
  2. 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.
  3. 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.

Activity

  1. opencodejr commented on Nov 19, 2026

    @opencodejr
    Contributor

    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:

  2. added
    area/core
    type/feature
    version/v2
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreplatform/linuxtype/featureversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions