adapter

package
v1.0.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 5 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 adapter holds what every agent adapter hands the wrapper.

Index

Constants

View Source
const (
	GradeGatewayPrecheck = "gateway-precheck"
	GradeAgentFlag       = "agent-flag"
	GradeWrapperWatchdog = "wrapper-watchdog"
	GradeNone            = "none"
)

Enforcement grades.

Variables

View Source
var ErrClaimed = errors.New("another costroid run holds the agent's state directory")

ErrClaimed means another run holds the directory an agent keeps its state in.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	// Name is the costroid/agent tag.
	Name() string
	// Plan rewrites a command to run under the budget, or refuses it.
	Plan(argv []string, budget decimal.Decimal) (Plan, error)
	// NewSession starts reading a run of the planned command.
	NewSession(plan Plan) Session
}

Agent is one supported agent.

type Count

type Count struct {
	Class  focus.TokenClass
	Tokens int64
}

Count is one class and its tokens.

type Enforcement

type Enforcement struct {
	Grade    string
	Note     string
	Watchdog bool
}

Enforcement is the grade a run was held at. Note states the limit of the grade in words and travels on every row.

type Exclusive

type Exclusive interface {
	// Claim holds the directory for one run, and release ends the hold. It
	// fails with ErrClaimed while another run holds it.
	Claim() (release func(), err error)
}

Exclusive is an Agent whose runs cannot share one state directory, because a run reads the directory and would count another run's spend as its own.

type Grain

type Grain string

Grain says what one Request covers.

const (
	// PerRequest is one model request.
	PerRequest Grain = "request"
	// PerTurn is one agent turn, which may hold many model requests.
	PerTurn Grain = "turn"
	// PerRun is one model's total across a run.
	PerRun Grain = "run"
)

The grains an agent can report at.

type Plan

type Plan struct {
	Argv        []string
	Enforcement Enforcement
}

Plan is how one agent command runs under a budget.

type Report

type Report struct {
	SessionID    string
	AgentVersion string
	CostBasis    focus.CostBasis
	CostSource   string
	Requests     []Request
	Warnings     []string
	// Enforcement is the grade the run earned, when it differs from what the
	// plan could promise. Empty means the plan's grade held.
	Enforcement Enforcement
	// Nested holds the sessions of other agent processes that started and
	// ended inside the run, each under its own session id. Their requests are
	// never in Requests.
	Nested []Report
	// Unrecorded counts the model requests the run sent whose usage no source
	// reported, so no row holds them. A warning says which.
	Unrecorded int
}

Report is what a run's usage came to.

type Request

type Request struct {
	// ID is the provider's request id, or the adapter's stated stand-in when
	// the source has none.
	ID          string
	Provider    string
	Model       string
	Start, End  time.Time
	ServiceTier string
	Region      string
	// ContextInputTokens is the request's whole input. At a coarser grain it
	// is the whole input of every request the entry sums, which no request in
	// it can pass, or zero when the adapter states none.
	ContextInputTokens int64
	Grain              Grain
	Tokens             Tokens
	// AssumedWrite is the cache write class that took tokens whose lifetime the
	// source did not report, by the adapter's rule. Empty when it reported all.
	AssumedWrite focus.TokenClass
	// CostSource names where this entry came from when it differs from the
	// report's. Empty means the report's.
	CostSource string
	// Note says in words how this entry was read, when the report's own
	// source does not.
	Note string
}

Request is one unit of usage at the finest grain the source reports.

type Session

type Session interface {
	// Feed reads one line of the agent's stdout, seen at the given time.
	Feed(line []byte, at time.Time) error
	// Finish reads whatever the agent left behind and returns the run's usage.
	Finish() (Report, error)
}

Session reads one run.

type Tailer

type Tailer interface {
	// Tail follows the file until ctx ends. It calls settled with the run's
	// requests so far each time a new one settles while the agent is working.
	Tail(ctx context.Context, settled func([]Request))
}

Tailer is a Session that watches a file the agent writes during a run.

type Tokens

type Tokens struct {
	InputUncached       int64
	CacheRead           int64
	CacheWrite5m        int64
	CacheWrite1h        int64
	CacheWrite30m       int64
	Output              int64
	ReasoningOutput     int64
	CachedInputReported int64
}

Tokens holds the canonical classes. Billed classes are disjoint; the two informational classes repeat tokens a billed class already counts.

func (Tokens) Add

func (t Tokens) Add(other Tokens) Tokens

Add returns the class-by-class sum.

func (Tokens) Counts

func (t Tokens) Counts() []Count

Counts lists the non-zero classes in a fixed order.

Directories

Path Synopsis
Package claudecode reads Claude Code runs.
Package claudecode reads Claude Code runs.
Package codex reads `codex exec --json` runs.
Package codex reads `codex exec --json` runs.

Jump to

Keyboard shortcuts

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