opencode_webresearch
opencode_webresearch is a Rust library for automated web research workflows through OpenCode and MCP tools.
It is designed to:
- Probe a configured OpenCode server.
- Start a managed server when one is not available.
- Run a research prompt in a fresh session.
- Auto-approve permission requests to keep tool execution unblocked.
- Collect streamed assistant output.
- Validate and write the final result to
response.json. - Retry from the beginning when failures or empty responses occur.
Installation
[]
= "0.1.0"
Required Runtime Dependencies
- Unix-like OS (Linux/macOS), matching
opencode-sdksupport. opencodebinary available inPATHif managed server startup is needed.- Configured OpenCode/MCP environment for tools like
searxngandwebfetch.
API
ResearchRequest
Notes:
opencode_server_portaccepts either number (7777) or string ("7777").working_directory,timeout_secs,max_attempts, and other operational controls are also available.
run_research
use ;
use PathBuf;
async
Output Format
The library writes response.json in the provided output directory.
It includes:
- Original prompt.
- Assistant answer text.
- Session ID.
- Attempt number.
- Provider/model metadata.
- Requested tool names.
- Message count.
- Generation timestamp.
Retry Behavior
Each attempt executes the full sequence:
- Check server health.
- Start server if needed.
- Create session.
- Send prompt.
- Stream response and handle permissions.
- Save validated
response.json. - Delete session.
If any step fails, or if the answer is empty, the workflow retries from step 1 until max_attempts is exhausted.
Testing
Run unit and integration test targets:
Integration tests that require real OpenCode + network are present but marked #[ignore]:
- Research
"brosnan yuen"and writeresponse.json. - Research RP2040 and verify datasheet PDF downloads in
/home/brosnan/opencode_webresearch/output.
Run ignored integration tests explicitly: