opencode

package
v1.0.0-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package opencode drives OpenCode 1.19.0 headless: one `opencode run` per worker job, resumed by session id. Credentials remain in the CLI's own store (`opencode auth login`); the adapter supplies none.

Index

Constants

View Source
const DefaultModel = "default"

DefaultModel names the CLI's own default, without passing a model flag.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	Binary string // empty means "opencode"
	Agent  string // optional --agent preset
}

Adapter drives the opencode CLI. Its zero value resolves opencode on PATH.

func (*Adapter) Command

func (a *Adapter) Command(job adapter.Job, workdir, resumeSessionID string) (*exec.Cmd, error)

Command passes the prompt as one positional argument after --. OpenCode permits edits headless by default, matching worker policy, and workerPermissions limits bash to the job's mapped tool scope (none for a review) and denies paths outside the worktree. Never pass --auto (or its permission-bypass aliases); permission rules ride the environment, not the CLI's project config.

OpenCode picks its directory as options.root ?? process.env.PWD ?? process.cwd() and chdirs there (packages/cli/src/run/run.ts:74, run/v1.ts:29, mini.ts localDirectory), so cmd.Dir alone is not enough: the runner sets PWD to the worktree on every command it starts.

func (*Adapter) Name

func (a *Adapter) Name() string

func (*Adapter) ParseErrEvent

func (a *Adapter) ParseErrEvent(line []byte) (adapter.Event, bool)

ParseErrEvent recognizes the same JSON shapes on stderr, plus the one fixed-format line the headless run path prints when it auto-rejects a permission ask — never arbitrary prose containing words such as "quota" or "key".

func (*Adapter) ParseEvent

func (a *Adapter) ParseEvent(line []byte) (adapter.Event, bool)

ParseEvent maps completed assistant text, tool states and provider errors. step_start supplies the session id without stealing a message/tool event. The CLI currently emits tool_use only for completed/error states, so real runs have tool ends without starts; do not invent starts from step_start (a model step is not a tool). If a running ToolPart is emitted, its schema maps directly to a start. Unknown tool states and event types stay ignored.

func (*Adapter) ProbeCommand

func (a *Adapter) ProbeCommand(ctx context.Context) *exec.Cmd

ProbeCommand implements adapter.Adapter: `opencode --version`, a cheap command that answers when the CLI is well (§8 "Health"), bound to ctx so a hung CLI is killed and reads as a failing probe.

func (*Adapter) ResultText

func (a *Adapter) ResultText(events []adapter.Event) string

ResultText is the run's last assistant message, which the worker/review contract reads (§5.4). Tool, session, reasoning and usage events cannot replace it, and earlier assistant messages are never concatenated into it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL