Documentation
¶
Overview ¶
Package opencode provides an Executor implementation for the opencode CLI.
opencode CLI emits NDJSON via `opencode run --format json` — a different schema from Claude, Gemini, and Codex. See opencode_compat_test.go for the full schema documentation with fixture assertions.
Key differences from Codex:
- Per-step token deltas: sum step_finish.part.tokens.input/output across events (Codex emits cumulative running totals; opencode emits per-step deltas)
- Session resume: --session <sessionID> (not built into the directive)
- Model string: "provider/model" format (e.g. "anthropic/claude-haiku-4-5", "ollama/gemma4:latest")
- Ollama local models: configure ~/.config/opencode/opencode.jsonc with custom provider block; see testdata/opencode_ollama_config.jsonc
Index ¶
- func Register()
- type OpenCodeExecutor
- func (e *OpenCodeExecutor) Capabilities() []executor.Capability
- func (e *OpenCodeExecutor) Close() error
- func (e *OpenCodeExecutor) CostModel() *executor.CostModel
- func (e *OpenCodeExecutor) Execute(ctx context.Context, task *executor.Task) (*executor.Result, error)
- func (e *OpenCodeExecutor) ExecuteStreaming(ctx context.Context, task *executor.Task, handler executor.EventHandler) (*executor.Result, error)
- func (e *OpenCodeExecutor) HealthCheck(ctx context.Context) error
- func (e *OpenCodeExecutor) Name() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type OpenCodeExecutor ¶
type OpenCodeExecutor struct {
// contains filtered or unexported fields
}
OpenCodeExecutor executes tasks using the opencode CLI.
func New ¶
func New(cfg *executor.Config) (*OpenCodeExecutor, error)
New creates a new OpenCodeExecutor.
func (*OpenCodeExecutor) Capabilities ¶
func (e *OpenCodeExecutor) Capabilities() []executor.Capability
Capabilities returns the list of features this executor supports.
func (*OpenCodeExecutor) Close ¶
func (e *OpenCodeExecutor) Close() error
Close releases any resources held by the executor.
func (*OpenCodeExecutor) CostModel ¶
func (e *OpenCodeExecutor) CostModel() *executor.CostModel
CostModel returns a generic default cost model for opencode. Actual cost depends on the provider/model string used; opencode reports per-step cost in step_finish events which the executor sums into CostUSD. The CostModel here is used only for pre-flight estimates when no live data is available; the real cost comes from summing step_finish.part.cost.
func (*OpenCodeExecutor) Execute ¶
func (e *OpenCodeExecutor) Execute(ctx context.Context, task *executor.Task) (*executor.Result, error)
Execute runs a task and returns the result.
func (*OpenCodeExecutor) ExecuteStreaming ¶
func (e *OpenCodeExecutor) ExecuteStreaming(ctx context.Context, task *executor.Task, handler executor.EventHandler) (*executor.Result, error)
ExecuteStreaming runs a task with real-time event callbacks, parsing the opencode NDJSON stream into normalized executor events.
func (*OpenCodeExecutor) HealthCheck ¶
func (e *OpenCodeExecutor) HealthCheck(ctx context.Context) error
HealthCheck verifies the opencode binary exists on PATH and responds.
func (*OpenCodeExecutor) Name ¶
func (e *OpenCodeExecutor) Name() string
Name returns the executor identifier.