Skip to content

Add JSON stream parsing for the opencode provider#375

Open
asterixcapri wants to merge 2 commits intomattpocock:mainfrom
asterixcapri:opencode-json-stream-clean
Open

Add JSON stream parsing for the opencode provider#375
asterixcapri wants to merge 2 commits intomattpocock:mainfrom
asterixcapri:opencode-json-stream-clean

Conversation

@asterixcapri
Copy link
Copy Markdown

Summary

Switch the opencode provider to JSON stream parsing.

This replaces raw stdout passthrough with structured parsing so Sandcastle can surface streamed text,
supported tool calls, and a final result from step_finish.

Validation

  • npm run build
  • npm test -- src/AgentProvider.test.ts src/Orchestrator.test.ts
  • real opencode run --format json ... smoke test

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 18, 2026

@asterixcapri is attempting to deploy a commit to the Matt Pocock's projects Team on Vercel.

A member of the Team first needs to authorize it.

mattpocock added a commit that referenced this pull request Apr 24, 2026
…pty (#422)

When an agent exits non-zero and stderr is empty, the AgentError message
was blank after the exit code. This is the primary case for OpenCode,
whose parseStreamLine is a no-op (resultText always empty), but also
applies to structured parsers that capture error details via stream events.

The fallback chain in invokeAgent is now: stderr → resultText → tail of
raw stdout (last 20 non-empty lines).

Key decisions:
- Fix is in Orchestrator's invokeAgent, not in provider-specific parsers
- OpenCode's parseStreamLine remains unchanged (still returns [])
- Complements PR #375 (OpenCode JSON parsing) — works regardless of parser
- Same pattern as #420 (Pi) and #421 (Codex) but at the Orchestrator level

Files changed:
- src/Orchestrator.ts — stderr→resultText→stdout fallback in error path
- src/Orchestrator.test.ts — 3 tests: no-op parser stdout fallback,
  structured parser resultText fallback, stderr-present preserved
- .changeset/agent-error-stdout-fallback.md — patch changeset

Closes #422

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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