Skip to content

feat: add OpenCode CLI backend support#2

Merged
CCALITA merged 5 commits intomainfrom
feat/opencode-backend
Apr 15, 2026
Merged

feat: add OpenCode CLI backend support#2
CCALITA merged 5 commits intomainfrom
feat/opencode-backend

Conversation

@CCALITA
Copy link
Copy Markdown
Owner

@CCALITA CCALITA commented Apr 14, 2026

Summary

Add OpenCode (opencode) as a new backend for inline-cli, enabling users to route queries through the OpenCode CLI.

  • New internal/backend/opencode.go — implements the Backend interface by invoking opencode run --format json <message> and parsing the newline-delimited JSON event stream from stdout
  • Extracts text from type:"text" events and surfaces type:"error" events as Go errors
  • Lets opencode use its own configured model (does not pass --model since opencode uses a different provider/model format)
  • Conversation history is prepended to the prompt for multi-turn context
  • Config: opencode_path in TOML / INLINE_CLI_OPENCODE_PATH env var for custom binary path
  • Wired "opencode" case into createBackend() in internal/daemon/server.go

Files changed

File Change
internal/backend/opencode.go New backend implementation (JSON event stream parser)
internal/backend/opencode_test.go 11 tests covering happy path, streaming, history, error events, partial output
internal/config/config.go Added OpenCodePath field and env var override
internal/config/config_test.go Config and env var tests
internal/daemon/server.go Added "opencode" case to createBackend()
internal/daemon/server_test.go Backend wiring tests

Usage

# ~/.inline-cli/config.toml
backend = "opencode"
# opencode_path = "/custom/path/to/opencode"  # optional

Or via environment variable:

export INLINE_CLI_BACKEND=opencode

Test plan

  • go build ./... passes
  • go test ./... -race passes (11 backend tests + config + daemon tests)
  • E2E verified: inline-cli query -p "say hi" returns response via opencode
  • E2E verified: Shift+Enter shell integration works with opencode backend
  • Error handling verified: invalid model produces clear error message
  • Conversation history correctly prepended to prompt

fanxiyao.3 added 5 commits April 14, 2026 21:53
Add opencode as a new backend option alongside api, cli, and acp.
The OpenCode backend invokes `opencode -p <prompt> --output-format text --quiet`
and streams stdout using the same scanChunks splitter as the Claude CLI backend.

- New file: internal/backend/opencode.go
- Config: OpenCodePath field with INLINE_CLI_OPENCODE_PATH env var override
- Server: "opencode" case in createBackend() switch
…-p`)

The opencode CLI uses `opencode run <message>` for non-interactive mode,
not `-p` which maps to `--password`. Also pass `--model` when provided.
opencode's default format writes to stderr with ANSI codes (TUI).
Using `--format json` produces newline-delimited JSON events on stdout
with types: step_start, text, step_finish. Parse these and extract
text from "text" events.

Also passes --model flag when provided and updates all tests to emit
JSON events matching the real opencode output format.
Two issues caused empty responses:
1. The default model (claude-sonnet-4-20250514) was passed via --model
   to opencode, which uses a different provider/model format. opencode
   returned a JSON error event that was silently ignored.
2. Error events (type:"error") were not handled, so failures produced
   empty responses with no error message.

Fix: stop passing --model (let opencode use its own default) and parse
error events to surface meaningful error messages.
@CCALITA CCALITA merged commit 2083a3f into main Apr 15, 2026
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