Skip to content

feat(compat): plain-text tool-result rendering via toModelOutput (#127)#171

Merged
OGtwelve merged 1 commit into
mainfrom
feat/plain-text-tool-output-127
Jul 13, 2026
Merged

feat(compat): plain-text tool-result rendering via toModelOutput (#127)#171
OGtwelve merged 1 commit into
mainfrom
feat/plain-text-tool-output-127

Conversation

@OGtwelve

Copy link
Copy Markdown
Contributor

Closes #127.

Problem

The eight fs/edit/search/bash tools mounted into every subagent tool set returned typed objects from execute and defined no toModelOutput, so AI SDK v6 rendered each result as a JSON part — which the OpenRouter mapper serializes with JSON.stringify. The model saw every Read as {"content":"…"}: file contents with every newline and quote escaped. Two costs: it taught the model to reproduce literal \n/\t in editFile's oldString (breaking the exact-match contract → wasted retries), and it added ~5–15% token overhead on precisely the results that dominate context volume. Claude Code presents these as raw text; this is trained-format parity at the model-visible layer only.

Fix

Define toModelOutput on each tool, returning a single { type: 'text', value } part:

Tool Model-visible text
readFile content verbatim (the #104 cat -n window rides inside it)
writeFile Wrote <path>
editFile / multiEdit Applied N replacement(s) to <path>. + the #104 numbered snippet (shared renderer)
grep / glob entries newline-joined + a truncation-notice line only when capped (shared renderer)
bash stdout; a stderr: section only when non-empty; an exit code: N line only when non-zero; (no output) when clean + empty
multiBash labeled per-command sections (same rules) + a [command #k failed: …] callout from failedAt (shared renderer)

Typed execute outputs are unchanged bit-for-bittoModelOutput only changes the model-visible layer, so programmatic callers (commitOnBranch/commitFix reading exitCode) and submittedOutput observe identical values, and the tool<BashInput, BashOutput> fakes in worker.test.ts/reviewer.test.ts keep compiling. Renderers apply no caps (bounding is #103's job at the typed layer, compaction is #102's).

Composition with #106: withReminders uses the wrapped tool's own toModelOutput as its base, so these plain-text renderers become the base its reminder envelope appends to — covered by an integration test (base text first, then <system-reminder> envelope).

Tests

Per-tool toModelOutput assertions across all four files (raw-content read with no escape sequences; write/edit confirmations; grep/glob join + truncation notice; bash conditional stderr/exit/(no output); multiBash sections + failing-command callout) + the #106 composition test.

Scope

compat-only — localEditTools/localReadTools already mount these objects and rendering travels with them; an MCP-filled slot's rendering is the server's concern. background-process.ts tools are out of scope (not mounted in any production set; #111 owns them).

Green gate

bun run typecheck (both) + typecheck:tests (compat) + bun run lint + bun run test:node — all green (compat 232, aitm 882).

The eight fs/edit/search/bash tools returned typed objects and defined no
toModelOutput, so the model saw every result as a JSON-escaped envelope
(e.g. a Read as {"content":"…"} with literal \n/\t). That taught the
model to reproduce escape sequences in editFile's oldString (breaking the
exact-match contract) and taxed context by ~5-15% on the results that
dominate volume. Claude Code presents these as raw text; this is
trained-format parity at the model-visible layer only.

Define toModelOutput on each tool, returning { type: 'text', value }:
- readFile → content verbatim (the #104 cat -n window rides inside it);
  writeFile → a confirmation naming the path.
- editFile/multiEdit → a confirmation with the replacement count + the #104
  numbered snippet (shared renderer).
- grep/glob → entries newline-joined + a truncation notice only when capped
  (shared renderer).
- bash → stdout, a stderr: section only when non-empty, an exit-code line only
  when non-zero, (no output) when clean+empty; multiBash → labeled per-command
  sections + a failing-command callout (shared renderer).

Typed execute outputs are unchanged bit-for-bit — programmatic callers
(commitOnBranch/commitFix reading exitCode) and submittedOutput are untouched,
and the tool<BashInput,BashOutput> fakes keep compiling. Composes with #106:
withReminders appends its envelope to this plain-text base (integration test).

Green: compat 232, aitm 882; typecheck + typecheck:tests + biome all clean.
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 24 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 78e3bf3c-8583-4367-967a-2111a9444167

📥 Commits

Reviewing files that changed from the base of the PR and between 6d0dc5f and a804439.

📒 Files selected for processing (8)
  • packages/ai-claude-compat/src/bash-tool.test.ts
  • packages/ai-claude-compat/src/bash-tool.ts
  • packages/ai-claude-compat/src/edit-tools.test.ts
  • packages/ai-claude-compat/src/edit-tools.ts
  • packages/ai-claude-compat/src/fs-tools.test.ts
  • packages/ai-claude-compat/src/fs-tools.ts
  • packages/ai-claude-compat/src/search-tools.test.ts
  • packages/ai-claude-compat/src/search-tools.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/plain-text-tool-output-127

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

@OGtwelve

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


You're currently rate limited under our Fair Usage Limits Policy. Your recent PR review activity is in the 95th percentile or higher among CodeRabbit users, so adaptive limits apply. Your next review will be available in 13 minutes.

@OGtwelve

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@OGtwelve

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


You're currently rate limited under our Fair Usage Limits Policy. Your recent PR review activity is in the 95th percentile or higher among CodeRabbit users, so adaptive limits apply. Your next review will be available in 5 seconds.

@OGtwelve

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


You're currently rate limited under our Fair Usage Limits Policy. Your recent PR review activity is in the 95th percentile or higher among CodeRabbit users, so adaptive limits apply. Your next review will be available in 24 minutes.

@OGtwelve OGtwelve merged commit 3ddbf27 into main Jul 13, 2026
4 checks passed
@OGtwelve OGtwelve deleted the feat/plain-text-tool-output-127 branch July 13, 2026 09:27
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.

feat(compat): plain-text tool-result rendering — toModelOutput on the file/search/bash tools so the model stops seeing JSON-escaped file contents

1 participant