opencode

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package opencode discovers models exposed by a local OpenCode runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateServerURL

func ValidateServerURL(raw string) (string, error)

ValidateServerURL accepts only explicit local HTTP endpoints. It normalizes localhost to 127.0.0.1 to avoid name-resolution surprises.

Types

type Config

type Config struct {
	Mode   Mode   `json:"mode"`
	Server string `json:"server,omitempty"`
}

Config is safe to persist in ~/.veto/config.json. It never contains provider credentials or OpenCode's provider-auth state.

type Connection

type Connection struct {
	Discovery Discovery
	// contains filtered or unexported fields
}

Connection owns a managed OpenCode process when Mode is managed.

func Connect

func Connect(ctx context.Context, config Config, deps Dependencies) (*Connection, error)

Connect discovers OpenCode and retains a managed process until Close.

func (*Connection) Close

func (c *Connection) Close() error

Close releases a managed server. Attach and CLI connections are no-ops.

type Dependencies

type Dependencies struct {
	LookPath func(string) (string, error)
	Run      func(context.Context, string, ...string) ([]byte, error)
	Stream   func(context.Context, string, []string, []string, io.Writer, io.Writer) error
	Start    func(string, []string, []string) (Process, error)
	Do       func(*http.Request) (*http.Response, error)
	Getenv   func(string) string
}

Dependencies makes filesystem-free process and HTTP boundaries injectable.

func DefaultDependencies

func DefaultDependencies() Dependencies

DefaultDependencies returns bounded production process and HTTP boundaries.

type Discovery

type Discovery struct {
	Mode       Mode    `json:"mode"`
	Server     string  `json:"server,omitempty"`
	Executable string  `json:"executable,omitempty"`
	Version    string  `json:"version"`
	Models     []Model `json:"models"`
}

Discovery describes a reachable OpenCode runtime and its connected models.

func Discover

func Discover(ctx context.Context, config Config, deps Dependencies) (Discovery, error)

Discover connects, returns metadata, and closes any temporary managed server.

func ProbeCLI

func ProbeCLI(ctx context.Context, deps Dependencies) (Discovery, error)

ProbeCLI checks that the CLI exists and reports a compatible version without listing models or contacting providers. It is suitable for doctor checks of managed mode, where starting a server would be an unwanted side effect.

type IncompatibleError

type IncompatibleError struct {
	Version string
	Detail  string
}

IncompatibleError means OpenCode was reachable but did not satisfy the documented CLI or server contract.

func (*IncompatibleError) Error

func (e *IncompatibleError) Error() string

type Mode

type Mode string

Mode selects how Veto reaches OpenCode.

const (
	ModeAttach  Mode = "attach"
	ModeManaged Mode = "managed"
	ModeCLI     Mode = "cli"
)

type Model

type Model struct {
	Provider string `json:"provider"`
	ID       string `json:"id"`
}

Model is an OpenCode provider/model pair.

type Process

type Process interface {
	Wait() error
	Kill() error
}

Process is the minimal managed-server lifecycle used by discovery.

type Runtime added in v0.4.0

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime executes one specific OpenCode provider/model binding. Every call creates a fresh session; it never resumes a prior Veto or user session.

func NewRuntime added in v0.4.0

func NewRuntime(config Config, discovery Discovery, model Model, deps Dependencies) *Runtime

NewRuntime binds one discovered provider/model to an OpenCode transport.

func (*Runtime) EffectiveTools added in v0.4.0

func (r *Runtime) EffectiveTools() []string

EffectiveTools is deliberately unknown until OpenCode exposes the tools for the active project/session. Veto must not infer shell, file, or browser access from a model name.

func (*Runtime) EffectiveToolsKnown added in v0.4.0

func (r *Runtime) EffectiveToolsKnown() bool

func (*Runtime) Execute added in v0.4.0

func (r *Runtime) Execute(ctx context.Context, prompt string, options vetox.ExecutionOptions) vetox.Result

func (*Runtime) ExecuteWithEvents added in v0.4.0

func (r *Runtime) ExecuteWithEvents(
	ctx context.Context,
	prompt string,
	options vetox.ExecutionOptions,
	w io.Writer,
	emit func(vetox.RuntimeEvent),
) vetox.Result

func (*Runtime) Run added in v0.4.0

func (r *Runtime) Run(ctx context.Context, prompt string) vetox.Result

func (*Runtime) RuntimeID added in v0.4.0

func (r *Runtime) RuntimeID() string

Jump to

Keyboard shortcuts

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