opencode

package
v0.6.121 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package opencode drives the opencode CLI as a subprocess and parses its JSON-lines output into a plain text reply, session ID, and token usage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoginReport

type LoginReport struct {
	Command string
	Version string
	Ready   bool
	Error   string
}

func CheckLogin

func CheckLogin(command string, timeout time.Duration) (LoginReport, error)

type Runner

type Runner struct {
	shared.RunnerBase
	DefaultModel   string
	DefaultVariant string
}

Runner executes the opencode CLI for a single request.

func (Runner) Run

func (r Runner) Run(ctx context.Context, userText string) (string, error)

Run is a convenience wrapper that runs without thread resumption or progress callbacks. It uses the runner's DefaultModel and DefaultVariant when set.

func (Runner) RunWithThreadAndProgress

func (r Runner) RunWithThreadAndProgress(
	ctx context.Context,
	threadID string,
	userText string,
	model string,
	variant string,
	env map[string]string,
	onProgress func(step string),
	onRawEvent func(kind, line, detail string),
) (string, string, int64, int64, int64, error)

RunWithThreadAndProgress runs the opencode CLI and returns the final reply, next session ID, and token usage.

  • threadID: resume an existing session when non-empty.
  • userText: the fully assembled prompt.
  • model: the provider/model string (e.g. "deepseek/deepseek-v4-pro").
  • variant: the model variant (e.g. "max", "high", "minimal").
  • env: merged over the process environment.
  • onProgress: called with each text event as an independent agent message; may be nil.
  • onRawEvent: optional callback for raw stdout events (kind, line, detail); nil disables raw event delivery.

Jump to

Keyboard shortcuts

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