fix(opencode): share tool response truncation
Merged
MA
2mo ago+88+88+01234567890123456789-15-15-01234567890123456789
Summary
- use the existing tool-response truncator for successful output, persisted tool errors, workflow-tool errors, and malformed tool-call repairs
- reduce the shared default limit from 50 KiB to 40 KiB while retaining the existing 2,000-line limit and configuration overrides
- save complete truncated content in the existing seven-day tool-output store and return the same head preview plus file path
- keep a bounded preview if the archive write fails, for both successful responses and errors
Why
A production malformed browser_execute call contained roughly 118,000 newline characters. AI SDK InvalidToolInputError copied the malformed tool input into its error, and JSON reserialization persisted a roughly 445,000-character assistant message. A later tiny user turn then exceeded model context. Normal tool-output truncation did not apply because the oversized content crossed the boundary as tool input and error rather than successful output.
Validation
- bun test test/tool/truncation.test.ts test/session/session.test.ts: 28 passed
- production-shaped 118,000-newline malformed-input regression: passed and full error archived
- shell truncation regressions: 4 passed
- packages/opencode bun typecheck: passed
- root filtered typecheck: 16 packages passed
- targeted oxlint: 0 errors
- Prettier and git diff --check: passed
- repository pre-push hook with Bun 1.3.14: passed
Scope
The final diff is four files. Three source integration points remain necessary: the shared truncator, the central persisted-tool-error boundary, and the AI SDK malformed-call repair boundary.