Skip to content

Unify tool output views - #880

Open
anandh8x wants to merge 3 commits into
mainfrom
perf/unified-tool-outcomes
Open

Unify tool output views#880
anandh8x wants to merge 3 commits into
mainfrom
perf/unified-tool-outcomes

Conversation

@anandh8x

@anandh8x anandh8x commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • introduce a finalized ToolOutcome that separates model-facing output, human-facing detail, recoverable artifacts, and reduction diagnostics
  • finalize outcomes once at the registry boundary after redaction, command reduction, and output budgeting
  • route agent, TUI, and exec surfaces through the appropriate outcome view while preserving compatibility for direct tool callers and persisted results
  • preserve detailed command evidence for users, including reduced error output, without returning that full output to the model context
  • add regression coverage for view separation, redaction, artifacts, after-hook rebudgeting, reduced errors, and corpus-level token behavior

Why

Tool output previously relied on several loosely related fields and metadata conventions. This made it easy for model context, user-visible detail, and recoverable raw output to drift or accidentally use the wrong representation.

The unified boundary keeps model context compact while retaining useful detailed output for users and exact redacted artifacts for recovery and inspection.

Measured behavior

  • reduction corpus: 513 estimated model tokens before, 495 after
  • retained reduction: approximately 65% before and 67% after
  • manual interactive command: approximately 92 tokens reduced to 41 while retaining an expandable 22-line result

The corpus boundaries differ slightly, so the primary claim is preservation of the existing token reduction with improved human detail and recoverability, rather than a standalone 2-point performance gain.

Validation

  • make fmt-check
  • go vet ./...
  • focused internal/tools, internal/agent, internal/tui, and internal/cli tests
  • go run ./cmd/zero-release build
  • go run ./cmd/zero-release smoke
  • make lint-static
  • make vulncheck
  • git diff HEAD --check
  • manual interactive verification of compact model output and expandable detailed output

The full local suite also exercised all affected packages successfully. Existing environment/baseline failures remain in doctor connectivity, worktree-trust end-to-end, and daemon end-to-end tests; this change does not touch those paths.

Summary by CodeRabbit

  • New Features

    • Improved tool-result presentation with distinct model output, human-readable previews, and recoverable artifacts.
    • Added output diagnostics covering truncation, retained content size, and artifact details.
    • Added bounded, UTF-8-safe previews with references to complete output.
    • Preserved finalized tool-result views across saved and restored sessions.
  • Bug Fixes

    • Preserved useful execution details across CLI, streaming, transcript, and TUI views.
    • Improved error displays with relevant command evidence and fewer misleading success previews.
    • Applied consistent sensitive-content redaction across displayed and stored output.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Tool results now expose finalized model, human, artifact, and diagnostic views. Execution paths finalize outcomes after budgeting and rebudgeting. Agent, CLI, and TUI consumers use the appropriate derived view.

Changes

Tool outcome finalization

Layer / File(s) Summary
Outcome contract and finalization
internal/tools/types.go, internal/tools/tool_outcome.go
Adds structured outcome types and accessors. Finalization records model and human views, artifacts, redaction, truncation, and output diagnostics.
Execution and rebudget finalization
internal/tools/registry.go, internal/tools/output_boundary.go, internal/tools/tool_outcome_test.go
Registry execution and post-hook rebudgeting finalize processed results after output reduction and budget enforcement. Tests cover artifacts, redaction, fallbacks, diagnostics, corpus reduction, and errors.
Agent, CLI, and TUI consumption
internal/agent/..., internal/cli/exec_writer.go, internal/tui/...
Agent transcripts, CLI output, and TUI rendering use model-facing and human-facing accessors. Result conversion preserves structured outcomes. Regression coverage verifies human-readable error output.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ToolRegistry
  participant OutcomeFinalizer
  participant AgentLoop
  participant CLIWriter
  participant TUI
  ToolRegistry->>OutcomeFinalizer: processed output and boundary output
  OutcomeFinalizer-->>ToolRegistry: finalized ToolOutcome
  ToolRegistry->>AgentLoop: finalized tool result
  AgentLoop->>AgentLoop: select ModelOutput
  AgentLoop->>CLIWriter: model and human views
  AgentLoop->>TUI: finalized tool result
  TUI->>TUI: select HumanDisplay or ModelOutput
Loading

Possibly related PRs

  • Gitlawb/zero#838: Modifies tool-result output-budget handling in the same execution and rebudgeting paths.
  • Gitlawb/zero#846: Modifies tool-output reduction used by finalized ToolOutcome views.
  • Gitlawb/zero#873: Modifies tool-result propagation in internal/agent/loop.go.

Suggested reviewers: kevincodex1, gnam...

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: separating and unifying tool output views across the system.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/unified-tool-outcomes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/tools/types.go`:
- Around line 139-154: Persist the finalized state of ToolOutcome across JSON
serialization by exposing a serialized marker or implementing custom
marshaling/unmarshaling for finalized. Ensure restored outcomes make Finalized()
return true so HumanDisplay(), ModelOutput(), and toolResultDetail() retain
reduced error evidence; add a JSON round-trip regression covering a reduced
error outcome.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5ab240c0-d033-48f8-b39f-39a06d4a229c

📥 Commits

Reviewing files that changed from the base of the PR and between 7f39a63 and abc0b90.

📒 Files selected for processing (10)
  • internal/agent/loop.go
  • internal/agent/types.go
  • internal/cli/exec_writer.go
  • internal/tools/output_boundary.go
  • internal/tools/registry.go
  • internal/tools/tool_outcome.go
  • internal/tools/tool_outcome_test.go
  • internal/tools/types.go
  • internal/tui/model.go
  • internal/tui/tool_outcome_test.go

Comment thread internal/tools/types.go
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Tests: go test ./...
  • [pass] Build: go run ./cmd/zero-release build
  • [pass] Smoke build: go run ./cmd/zero-release smoke

Scope

Head: 22aac8b0a89d
Changed files (10): internal/agent/loop.go, internal/agent/types.go, internal/cli/exec_writer.go, internal/tools/output_boundary.go, internal/tools/registry.go, internal/tools/tool_outcome.go, internal/tools/tool_outcome_test.go, internal/tools/types.go, internal/tui/model.go, internal/tui/tool_outcome_test.go

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/tui/tool_outcome_test.go`:
- Around line 52-54: Update TestToolResultDetailSurvivesOutcomeJSONRoundTrip to
set TMP and TEMP to t.TempDir() in addition to TMPDIR, ensuring os.TempDir uses
the test-owned directory on Windows for exec_command output spills.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 887dc319-f869-40f9-81e8-f05b45d5f520

📥 Commits

Reviewing files that changed from the base of the PR and between abc0b90 and b405c0d.

📒 Files selected for processing (2)
  • internal/tools/tool_outcome.go
  • internal/tui/tool_outcome_test.go

Comment thread internal/tui/tool_outcome_test.go
@Gitlawb Gitlawb deleted a comment from coderabbitai Bot Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant