runner

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 25 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 runner runs a delegated role through a command-line harness the operator named, with the same brief, inputs and output contract the host's own sub-agent gets (itd-2609201916056194, spc-2609221533057881).

A role's route is roles.<role>.runner in the layered configuration (config.go): host, the default, or a runner this machine enabled under runner.<name>. The shipped runners are the claude CLI in print mode with the bare flag (claude.go) and opencode's run mode (opencode.go). Each is started as a process (proc.go): the argv is a vector and never a shell line, the binary is resolved on PATH and refused inside the repository, the environment is the parent's scrubbed of every git repository-selection and config-injection variable, stdin is the null device, output is bounded, and a run past its time is killed with the process group it leads.

The fallback is decided in one place (dispatch.go): an absent, refusing, failing or unparsable runner, or an answer the contract's validator refuses, hands the role to the host session, or with no host session to the host the operator configured (runner.fallback_host), and writes one receipt naming the role, the runner asked for, the reason and the route that ran. Tally counts those receipts per runner and per role for the run's summary.

The package never prints. It starts processes only through Dispatch and the adapters' Run, and never logs a harness in: a harness's credential is its own, read from its own environment or configuration, and abcd never puts one on a command line, in an error or in a receipt.

Index

Constants

View Source
const (
	Host     = "host"
	Claude   = "claude"
	OpenCode = "opencode"
)

The routes a role may name. Host is the default.

View Source
const ApproverTool = "mcp__abcd__approve"

ApproverTool is the permission prompt tool a shell launch names.

View Source
const DefaultTimeout = 60 * time.Minute

DefaultTimeout bounds one run when the request names no timeout.

Variables

View Source
var (
	ErrNotOnPath  = errors.New("not on PATH")
	ErrRefused    = errors.New("refused before it is run")
	ErrNotStarted = errors.New("could not be started")
)

The launch stages a Failure can name through errors.Is: the program was not found, it was found and refused, or it was admitted and could not start. Every other failure (a non-zero exit, a run past its time, an overrun bound) is none of them.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	// Text is the harness's final message.
	Text string
	// Model is the model the harness reports, "" when it reports none: the
	// model the runner asked for is Sides.ModelAsked, and never stands in for
	// the one that answered (itd-166, iss-2610161709506207).
	Model string
	// SessionID is the harness's own session id, "" when it reports none.
	SessionID string
	// Sides is both sides of the run: what the runner asked for, and the
	// token counts, cost and served models the harness's events report.
	Sides
	// contains filtered or unexported fields
}

Answer is the one answer shape every adapter parses its harness's events into. The contract's own answer is the receipt file; this is what the harness said about the run.

type ClaudeCLI

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

ClaudeCLI is the claude CLI runner.

func (*ClaudeCLI) Name

func (*ClaudeCLI) Name() string

Name is the route's name.

func (*ClaudeCLI) Run

func (c *ClaudeCLI) Run(ctx context.Context, req Request) (Answer, []byte, error)

Run runs the role through the claude CLI.

type Command added in v0.13.0

type Command struct {
	// Name is the program's fixed name, looked up on PATH; a name carrying a
	// path separator is refused, so no caller can point Exec at a file.
	Name string
	// Args is the argument vector, never a shell line.
	Args []string
	// Dir is the working directory the program runs in; empty runs it at the
	// file-system root, never in the caller's directory, which for abcd is
	// usually a project whose settings a vendor binary must not read.
	Dir string
	// Guards are the folders a program resolving inside is refused from,
	// lexically or through a link: repository content is never run. A caller
	// running in or for a project passes it here; Exec cannot know it.
	Guards []string
	// Timeout bounds the run; past it the program's group is killed. A
	// command without one is never run.
	Timeout time.Duration
	// MaxStdout and MaxStderr bound each stream; past either the run fails.
	MaxStdout, MaxStderr int
}

Command is one program found on PATH that another package runs under this file's discipline: the one launch primitive abcd has for a vendor binary, so a second copy of the admission, the group kill and the bounds is never written. Zero output bounds take a harness's own.

type Config

type Config struct {

	// Diagnostics are the non-fatal reports the read produced, one line each,
	// for a front door to print on stderr.
	Diagnostics []string
	// contains filtered or unexported fields
}

Config is the runner configuration one invocation read.

func Load

func Load(r layered.Roots) (*Config, error)

Load reads and validates the runner configuration. A fault is an error naming the file and the key; none falls through to a default.

func (*Config) FallbackHost

func (c *Config) FallbackHost() string

FallbackHost is the runner that runs a role when there is no host session, "" when none is configured.

func (*Config) FlagRoutes added in v0.16.0

func (c *Config) FlagRoutes() map[string]string

FlagRoutes are the roles the person's --route routed for this invocation (Override), each with the --route text verbatim; nil when none did.

func (*Config) Override added in v0.16.0

func (c *Config) Override(routes []oracle.FlagRoute) error

Override places the person's --route runner routes (oracle.ParseRunnerRoutes) in the flag layer, for this invocation alone (iss-2610161801358637): each hands its role to the runner it names, asking for the model it names in place of the runner's machine model, which stays every other role's. The flag is the person's own, so it may hand a role to a runner as the machine file may (personal), but only to a runner this machine enabled, and only for a model the runner's provider lists: the allowlist check a machine model route passes (adr-2609221009491186). A refusal routes nothing and names the fix.

func (*Config) Quota added in v0.14.0

func (c *Config) Quota(ctx context.Context, name string) (Quota, bool, error)

Quota asks the runner the machine enabled under name for its remaining quota. The host, and a name the machine has not enabled, report none.

func (*Config) RouteFor

func (c *Config) RouteFor(role string) Route

RouteFor returns where role runs: its configured route, or the host from the bundled default.

func (*Config) Runner

func (c *Config) Runner(name string) (RunnerConfig, bool)

Runner returns the runner this machine enabled under name.

type Counts

type Counts struct {
	Total    int            `json:"total"`
	ByRunner map[string]int `json:"by_runner"`
	ByRole   map[string]int `json:"by_role"`
}

Counts is the fallback intel a run's summary reports.

func Tally

func Tally(rs []FallbackReceipt) Counts

Tally counts fallback receipts per runner asked for and per role. A run with none reports zero, with empty maps rather than none.

type Dispatcher

type Dispatcher struct {
	// Config is the runner configuration read at the lane's start.
	Config *Config
	// HostSession is true when a host session drives the loop and can take a
	// role handed back to it.
	HostSession bool
	// Attended is true when the person is at the terminal with no host session
	// (the plain-Terminal interviews, spc-2610030911534855): a role routed to a
	// runner runs there although no runner.fallback_host is configured, and a
	// runner that does not answer stops the run, its fallback receipt naming
	// none as the route that ran, rather than leaving the role nowhere to land.
	// A role on the host still needs a host session or a configured host.
	Attended bool
	// Validate is the contract's validator: the same check the host sub-agent's
	// answer passes. It is handed the runner that ran the role, so a caller
	// whose validator also records the answer (the loop's receipt verifier)
	// can name the route that ran.
	Validate func(runner string, req Request, ans Answer) error
	// Transcripts is where every runner's transcript lands.
	Transcripts TranscriptStore
	// Record appends one fallback receipt to the run's state.
	Record func(FallbackReceipt) error
	// Prepare, when set, readies req's files for the runner about to run it,
	// before each runner starts: the routed one and a fallback host alike. A
	// *Failure it returns is that runner's failure, recorded and fallen back
	// on as a launch's would be, with nothing launched; any other error ends
	// the dispatch.
	Prepare func(runner string, req Request) error
	// Now is the clock the receipts are stamped with; time.Now when nil.
	Now func() time.Time
}

Dispatcher runs roles by their routes.

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(ctx context.Context, req Request) (Outcome, error)

Dispatch runs req by its role's route.

type Failure

type Failure struct {
	Runner string
	Reason Reason
	Detail string
	// contains filtered or unexported fields
}

Failure is a runner's failure. Detail is written by abcd, never copied from the harness's output, so it cannot carry anything the harness printed, a credential it echoed included.

func (*Failure) Error

func (f *Failure) Error() string

func (*Failure) Unwrap added in v0.13.0

func (f *Failure) Unwrap() error

Unwrap is the launch stage that failed, nil when the failure is not one.

type FallbackReceipt

type FallbackReceipt struct {
	At     time.Time `json:"at"`
	Role   string    `json:"role"`
	Asked  string    `json:"asked"`
	Reason Reason    `json:"reason"`
	// Detail is abcd's own account of the reason; it never carries the
	// harness's output.
	Detail string `json:"detail"`
	Ran    string `json:"ran"`
}

FallbackReceipt is one fallback: the role, the runner asked for, the reason, and the route that ran instead.

type HistoryStore

type HistoryStore struct {
	RepoRoot string
	RootSHA  string
}

HistoryStore is the production store: the repository's lane of the user-level transcript store, keyed on its root commit.

func (HistoryStore) Store

func (h HistoryStore) Store(runner string, req Request, ans Answer, raw []byte) error

Store captures raw as a native transcript produced by the runner, recorded under the harness's own session id when it reported one and the request's otherwise, with the role as its agent type.

type OpenCodeCLI

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

OpenCodeCLI is the opencode runner.

func (*OpenCodeCLI) Name

func (*OpenCodeCLI) Name() string

Name is the route's name.

func (*OpenCodeCLI) Run

func (o *OpenCodeCLI) Run(ctx context.Context, req Request) (Answer, []byte, error)

Run runs the role through opencode.

type Outcome

type Outcome struct {
	// Handoff is true when the host session runs the role, exactly as it does
	// with no runner configured: the caller hands the host the brief and
	// awaits its receipt.
	Handoff bool
	// Answer is the runner's parsed answer when a runner ran the role.
	Answer *Answer
	// Fallback is the receipt this dispatch recorded, nil when none.
	Fallback *FallbackReceipt
	// Receipt is the role's receipt block.
	Receipt RoleReceipt
}

Outcome is one dispatch's result.

type Output added in v0.13.0

type Output struct {
	Stdout, Stderr []byte
}

Output is what an Exec run wrote, each stream up to its bound.

func Exec added in v0.13.0

func Exec(ctx context.Context, c Command) (Output, error)

Exec admits c.Name exactly as a harness is admitted (admit) and runs it exactly as a harness is run (run): the scrubbed environment, the null device on stdin, the bounds, and the process group killed through this handle at the timeout or when ctx ends. A failure is a *Failure, whose errors.Is names the stage for ErrNotOnPath, ErrRefused and ErrNotStarted; the output is returned whenever the program produced some.

type Quota added in v0.14.0

type Quota struct {
	Remaining int `json:"remaining"`
}

Quota is what a runner reports of its budget before a run starts (itd-2609201925079472 criterion 7): the agent runs it can still start in its current window. A runner whose harness counts its budget in another unit converts it, or reports none.

type QuotaReporter added in v0.14.0

type QuotaReporter interface {
	Quota(ctx context.Context) (Quota, error)
}

QuotaReporter is a Runner that reports its remaining quota. Neither shipped runner is one: the claude CLI and opencode expose no remaining quota a launch can read before it starts, so a run routed to either names it and skips the budget check out loud.

type Reason

type Reason string

Reason is why a runner did not answer: the kinds the fallback records.

const (
	// ReasonAbsent: the runner is not enabled on this machine, or its binary
	// is not on PATH or is refused.
	ReasonAbsent Reason = "absent"
	// ReasonRefused: the harness ran and reported that it refused or erred.
	ReasonRefused Reason = "refused"
	// ReasonFailed: the harness could not start, exited non-zero, ran out of
	// time or overran its output bound.
	ReasonFailed Reason = "failed"
	// ReasonUnparsable: the harness's output is not its structured events.
	ReasonUnparsable Reason = "unparsable"
	// ReasonInvalid: the answer failed the contract's validator.
	ReasonInvalid Reason = "invalid"
	// ReasonRateLimited: the harness reported a rate-limit response and did
	// not finish. It is never fallen back on (dispatch.go): every route spends
	// the budget the run's window paces, so the caller ends the window
	// (itd-2609201925079472 criterion 8).
	ReasonRateLimited Reason = "rate-limited"
)

type Request

type Request struct {
	// Role is the agent the run plays: an agent in the roster, or the
	// implementer.
	Role string
	// Brief is the absolute path of the brief the role follows; it states the
	// task and the output contract.
	Brief string
	// Receipt is the absolute path the contract says the answer is written to.
	Receipt string
	// Dir is the absolute path of the working tree the role runs in.
	Dir string
	// Checkout is the absolute path of the checkout the run belongs to when
	// Dir is a worktree of it (a lane's worktree lives outside it); a program
	// inside it is repository content and is never run, as one inside Dir is
	// not. Empty when Dir is the checkout itself.
	Checkout string
	// Tools are the tools the role's contract grants, granted without a
	// prompt; none granted when empty.
	Tools []string
	// Base is the full object name of the commit the run's working tree was
	// cut from: a lane's base, or the HEAD an interview launched on. A launch
	// that grants the shell needs it, since the approver judges every
	// command against the hazard registry at that commit.
	Base string
	// Denied are the tools the role is refused outright, whatever else would
	// grant them: a harness that keeps a deny list takes them there, ahead of
	// every grant.
	Denied []string
	// Model is the <provider>/<model> route this request runs at, over the
	// model the runner's own route names, so one runner serves two reviewers
	// at two classes (itd-2610240922461281 decision 4); "" keeps the route's.
	// It is admitted against the provider's allowlist when the request is
	// dispatched, as a configured route is when it is read, never trusted
	// because a caller stored it.
	Model string
	// SessionID names the run's transcript record when the harness reports no
	// session of its own.
	SessionID string
	// Timeout bounds the run; DefaultTimeout when zero.
	Timeout time.Duration
}

Request is what a role is handed: the same the host sub-agent is handed.

func (Request) Check added in v0.15.1

func (r Request) Check() error

Check refuses a request no runner may be started with, as every launch does before it starts anything: a caller that must know whether a runner was started asks it first.

type RoleReceipt

type RoleReceipt struct {
	Role  string `json:"role"`
	Brief string `json:"brief"`
	// Contract is the receipt path the contract names.
	Contract string      `json:"contract"`
	Route    RouteRecord `json:"route"`
}

RoleReceipt is a role run's receipt block. Everything but Route is the request's, so two runs of one request differ in their route alone.

type Route

type Route struct {
	Runner string
	Layer  layered.Layer
	Origin string
}

Route is where a role runs and the layer that said so.

func (Route) Override added in v0.16.0

func (r Route) Override() string

Override is the --route text verbatim when the person's flag routed the role for this invocation (Config.Override), "" otherwise.

type RouteRecord

type RouteRecord struct {
	// Asked is the route the configuration named: host or a runner.
	Asked string `json:"asked"`
	// Ran is the route that ran the role: host, a runner, or none.
	Ran string `json:"ran"`
	// Model is the model the runner that ran it reported, the canonical
	// served model; "" on the host, whose own receipt reports it, and when
	// the runner reported none.
	Model string `json:"model"`
	// Override is the --route text verbatim when the person's flag routed the
	// role for this invocation, so a run on a chosen model is never mistaken
	// for the configured route; "" otherwise.
	Override string `json:"override,omitempty"`
	// Sides is both sides of the run, present when a runner ran it; its
	// fields are omitted when empty, so a host's or an older record reads as
	// it always has.
	Sides
}

RouteRecord is the route a role asked for and the one that ran it, and, when a runner ran it, both sides of the run (itd-166).

func RecordOf added in v0.16.0

func RecordOf(asked, ran string, ans Answer) RouteRecord

RecordOf is the route record of a role ran ran, routed to asked, whose harness answered ans: the served model as the canonical one, and both sides beside it.

type Runner

type Runner interface {
	// Name is the route's name, as roles.<role>.runner spells it.
	Name() string
	// Run runs the role and returns the parsed answer and the transcript, the
	// harness's raw event stream. A failure is a *Failure; the transcript is
	// returned whenever the harness produced one, failure or not.
	Run(ctx context.Context, req Request) (Answer, []byte, error)
}

Runner is one route a role can run through.

type RunnerConfig

type RunnerConfig struct {
	Name string
	// Model is the admitted <provider>/<model> route, "" for the harness's own
	// default.
	Model string
	// Pin is the machine's pin for that model on that provider
	// (oracle.Pin), nil when it sets none; the opencode runner holds a run
	// to it.
	Pin *oracle.Pin
	// Local says the model's provider is a block on this machine, and
	// LocalPin is the machine's local pin for the model, nil when it sets
	// none (oracle.LocalPin): opencode is held to it after a probe.
	Local    bool
	LocalPin *oracle.LocalPin
	Origin   string
}

RunnerConfig is one runner this machine enabled.

type Sides added in v0.16.0

type Sides struct {
	// ModelAsked is the model the runner passed the harness, "" when it
	// passed none and the harness chose.
	ModelAsked string `json:"model_asked,omitempty"`
	// ServedModels is every model the harness says served the run (claude's
	// per-model usage), sorted; empty when it names none.
	ServedModels []string `json:"served_models,omitempty"`
	// ServedProvider is the provider the harness names as serving the
	// canonical model, "" when it names none.
	ServedProvider string `json:"served_provider,omitempty"`
	// FinishReason is why the run's last turn stopped, as the harness says.
	FinishReason string `json:"finish_reason,omitempty"`
	// HarnessVersion is the harness's own version, as it reports it.
	HarnessVersion string `json:"harness_version,omitempty"`
	// PromptSHA256 is the SHA-256 of the prompt the runner handed the harness
	// (prompt), never its text; the brief it names is the run's own file.
	PromptSHA256 string `json:"prompt_sha256,omitempty"`
	// Usage and Cost are the run's token counts and cost, nil when the
	// harness reported none. Each count is the harness's own: claude's
	// input_tokens and opencode's input exclude the cached prompt tokens,
	// which are counted apart.
	Usage *oracle.Usage `json:"usage,omitempty"`
	Cost  *oracle.Cost  `json:"cost,omitempty"`
	// Unpinned lists every field of the fixed lists the run could not pin.
	Unpinned []oracle.Unpinned `json:"unpinned,omitempty"`
	// ProviderPin is the pin the run's opencode was pointed at, and
	// PinConfigSHA256 the SHA-256 of the sealed configuration that carried it
	// (pin.go); empty when the run was not pinned. It is what was configured,
	// not what reached OpenRouter, so Unpinned lists it as not verified.
	ProviderPin     *oracle.Pin `json:"provider_pin,omitempty"`
	PinConfigSHA256 string      `json:"pin_config_sha256,omitempty"`
	// LocalPin is the local pin of a run routed to a model on this machine
	// (oracle.LocalPin, iss-2610161734428291), and LocalServed what the
	// server reported when it was probed before the run; both absent on any
	// other route. LocalServed describes the probe, not the run: opencode
	// can still be pointed at another server (askedUnpinned), so the local
	// fields stay not verified. PinConfigSHA256 is then the sealed
	// configuration that pointed opencode at the probed server.
	LocalPin    *oracle.LocalPin    `json:"local_pin,omitempty"`
	LocalServed *oracle.LocalServed `json:"local_served,omitempty"`
	// Local says the route's provider is a block on this machine, so the
	// record lists the local fields (iss-2610171545099084). A harness's
	// output cannot say so; the configuration does.
	Local bool `json:"local,omitempty"`
}

Sides is both sides of a run as a runner records them. Every string the harness supplied is cleaned and bounded (cleanHarness) before it is set.

type TranscriptStore

type TranscriptStore interface {
	Store(runner string, req Request, ans Answer, raw []byte) error
}

TranscriptStore keeps one runner's transcript of one role's run.

Jump to

Keyboard shortcuts

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