opencode

package
v1.0.0-alpha.21 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package opencode reads `opencode run --format json` runs.

OpenCode prints a step_finish line as each model request ends, with that request's tokens and OpenCode's own price for it. Each step is one set of rows, and the wrapper prices the run after every step, so a run is stopped at the cap between steps. OpenCode's price stays the agent's own figure; the rows are priced from the catalog.

Index

Constants

View Source
const (
	// Name is the costroid/agent tag.
	Name = "opencode"

	// StatedUnit is the unit of OpenCode's own price for a step, and of its
	// figure for the run, AgentStated.
	StatedUnit = "USD"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct{}

Agent is OpenCode.

func (Agent) Name

func (Agent) Name() string

Name returns the costroid/agent tag.

func (Agent) NewSession

func (Agent) NewSession(plan adapter.Plan) adapter.Session

NewSession starts reading a run of the planned command. It reads the version from the command's own opencode, and the basis from the key the provider runs on.

func (Agent) Plan

func (Agent) Plan(argv []string, _ decimal.Decimal) (adapter.Plan, error)

Plan adds --format json, and --title= when the command names no title. It refuses a command whose model the catalog cannot price, since a run that cannot be priced cannot be held to the budget.

type Session

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

Session reads one OpenCode run. Feed and Tail run on separate goroutines, so the lock covers everything below it.

func (*Session) Feed

func (s *Session) Feed(raw []byte, at time.Time) error

Feed reads one stdout line. A line whose shape this reader does not know is skipped and counted. A step_finish line that cannot be read stops the run's reading at Finish, because it holds the run's figures.

func (*Session) Finish

func (s *Session) Finish() (adapter.Report, error)

Finish returns the run's usage and the grade it earned.

func (*Session) Tail

func (s *Session) Tail(ctx context.Context, settled func([]adapter.Request))

Tail calls settled with the run's steps so far each time one settles, until ctx ends.

Jump to

Keyboard shortcuts

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