harness

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package harness configures coding harnesses (Claude Code, Codex, OpenCode, and Pi) to use Baseten routes, and removes that configuration again.

Setup overwrites a fixed set of integration settings in each harness's native settings file. There are no backups: repeating setup refreshes the same settings, and teardown deletes them so the harness's native defaults apply. Unrelated settings are left alone, and previous values of overwritten settings are not restored. Setup and teardown are idempotent.

Index

Constants

View Source
const (
	ClaudeCode = "claude-code"
	Codex      = "codex"
	OpenCode   = "opencode"
	Pi         = "pi"
)

Harness names, as accepted by --harness.

View Source
const (
	StateNotConfigured = "not-configured"
	StateConfigured    = "configured"
	// StateInactive means Baseten settings exist but another provider is selected.
	StateInactive = "inactive"
	// StateIncomplete means some Baseten settings are missing; rerun setup or teardown.
	StateIncomplete = "incomplete"
)

Integration states reported by Harness.Inspect.

View Source
const (
	TargetAnthropic = "ANTHROPIC"
	TargetOpenAI    = "OPENAI"
)

Route target types, as the routes API reports them.

Variables

This section is empty.

Functions

func ApplyPlans

func ApplyPlans(plans []*Plan, token string) error

ApplyPlans writes plans in order, inserting token into setup plans first. Concurrent invocations are not supported, and a multi-file operation is not a transaction: rerun an interrupted setup or teardown to finish it.

func CodexClearCloudConfig

func CodexClearCloudConfig(dir string) error

func CodexCloudConfigPath

func CodexCloudConfigPath(dir string) string

func CodexDaemonClients

func CodexDaemonClients(ctx context.Context, execer Execer, socket string) (int, error)

func CodexDaemonSocket

func CodexDaemonSocket(ctx context.Context, execer Execer, dir string) string

func CodexDesktopLocations

func CodexDesktopLocations() string

CodexDesktopLocations describes where Detect looks for a desktop-bundled Codex on this platform, or "" if it looks only on PATH.

func CodexLoggedIn

func CodexLoggedIn(ctx context.Context, execer Execer, dir string) bool

func CodexLogout

func CodexLogout(ctx context.Context, execer Execer, dir string) error

func RestartCodexDaemon

func RestartCodexDaemon(ctx context.Context, execer Execer, dir string) (int, error)

func Supported

func Supported() bool

Supported reports whether harness settings locations are verified on this platform.

Types

type Cost

type Cost struct {
	Input, Output         float64
	CacheRead, CacheWrite *float64
	// LongContext prices long-context requests, when the provider tiers them.
	LongContext *Cost
}

Cost holds prices in USD per 1M tokens. Optional prices are nil when unknown.

type Detection

type Detection struct {
	Name      string
	Path      string
	Installed bool
	Version   string
}

Detection describes a harness installation and its settings file.

type Execer

type Execer interface {
	LookPath(file string) (string, error)
	Exec(cmd *exec.Cmd) error
}

Execer runs subprocesses. The CLI's shared executor satisfies it.

type Harness

type Harness interface {
	// Name is the --harness value.
	Name() string
	// Detect finds the harness executable and its settings file in configDir,
	// or in the harness's native configuration directory when configDir is empty.
	Detect(ctx context.Context, execer Execer, configDir string) (Detection, error)
	// Prepare plans setup of the settings file at path. The plan keeps the
	// file's current credential; ApplyPlans inserts the real one.
	Prepare(path string, routes []Route, selection Selection, endpoint string) ([]*Plan, error)
	// Inspect reports the integration state of the detected settings file.
	Inspect(d Detection) (Status, error)
	// Teardown plans removal of the integration settings at path.
	Teardown(path string) ([]*Plan, error)
	// BackgroundRoute is the route for lightweight background tasks, or "" if
	// the harness has no such setting.
	BackgroundRoute(selection Selection) string
	// Credential returns the routes API key setup wrote to the settings file at
	// path, or "" if there is none.
	Credential(path string) (string, error)
	// Routes returns the routes the harness can call, in order.
	Routes(routes []Route) []Route
}

Harness configures one coding harness. API access, user interaction, and output belong to the calling command.

func All

func All() []Harness

All returns every supported harness.

type Plan

type Plan struct {
	Harness  string
	Path     string
	Keys     []string
	Replaced []string
	Managed  bool
	Changed  bool
	// contains filtered or unexported fields
}

Plan is a pending change to one file. It exposes paths and setting names only, never credential values.

type Route

type Route struct {
	Name        string
	DisplayName string
	// Target is the route's upstream provider, such as TargetAnthropic, which
	// decides the API a harness calls the route with.
	Target          string
	ContextWindow   int
	OutputLimit     int
	InputModalities []string
	Tools           bool
	ReasoningLevels []string
	ParallelTools   bool
	// Messages and Responses report whether the route serves the Anthropic
	// Messages API and the OpenAI Responses API.
	Messages  bool
	Responses bool
	// Cost is the provider's list price, or nil if unknown.
	Cost *Cost
}

Route is a Baseten route as shown in a harness's model picker, with the model capabilities supplied by the route's own metadata.

func NewRoute

func NewRoute(api managementapi.Route) (Route, error)

NewRoute converts a route from the routes API. It fails if the route's model metadata is missing or is not enough to configure a harness.

type Selection

type Selection struct {
	Primary    string
	Background string
	Subagent   string
	Fallback   string
}

Selection holds the requested routes. Empty fields use each harness's default.

type ServerDefaults added in v1.3.0

type ServerDefaults struct {
	Primary    string
	Background string
}

func (ServerDefaults) Selectable added in v1.3.0

func (d ServerDefaults) Selectable(routes []Route) ServerDefaults

type Status

type Status struct {
	Detection
	State           string
	DefaultRoute    string
	BackgroundRoute string
	Routes          []Route
	// Managed lists the integration settings present in the file.
	Managed []string
}

Status describes the current integration settings of one harness.

Jump to

Keyboard shortcuts

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