feat: add file persistence for large tool outputs #6234
+112
−45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements file persistence for large tool outputs instead of truncating and losing data. When tool outputs exceed 30,000 characters, the full output is saved to disk and the model receives a file path with instructions for exploring the data using Read, Grep, or jq tools.
This addresses the root cause of "prompt is too long" errors caused by large tool outputs overwhelming the context window.
Closes #4560
Related: #4826, #4845, #5360
Changes
tool-results.ts: Storage helper that saves large outputs to~/.local/share/opencode/storage/tool_results/{sessionID}/{toolName}-{ulid}.txtprompt.ts: MCP tools now save large outputs to file instead of passing directly to model contextbash.ts: Replace simple truncation with file persistence, preserving full output instead of losing data beyond 30k chars. Added 10MB hard limit to prevent memory issues.webfetch.ts: Add file persistence for large fetched contentwebsearch.ts: Add file persistence for large search resultscodesearch.ts: Add file persistence for large code search resultsbash.txt: Tool description reflects new behaviorsession/index.ts: Clean up tool_results directory when session is deletedOPENCODE_EXPERIMENTAL_MCP_MAX_OUTPUT_LENGTHfor configurabilityBenefits
Coverage
This PR covers file persistence for: