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
- type Adapter
- func (a *Adapter) Command(job adapter.Job, workdir, resumeSessionID string) (*exec.Cmd, error)
- func (a *Adapter) Name() string
- func (a *Adapter) ParseErrEvent(line []byte) (adapter.Event, bool)
- func (a *Adapter) ParseEvent(line []byte) (adapter.Event, bool)
- func (a *Adapter) ProbeCommand(ctx context.Context) *exec.Cmd
- func (a *Adapter) ResultText(events []adapter.Event) string
Constants ¶
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
// contains filtered or unexported fields
}
Adapter drives the opencode CLI. Its zero value resolves opencode on PATH.
func (*Adapter) Command ¶
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) ParseErrEvent ¶
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 ¶
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 ¶
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 ¶
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.