harness

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 22 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 harness configures coding harnesses (Claude, which is Claude Code and Claude Desktop together, 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.

A harness that supports it runs `baseten grid token` for its credential instead of storing a key; setup then removes any key it stored before.

Index

Constants

View Source
const (
	// Claude configures Claude Code and, when the app is installed, Claude Desktop.
	Claude   = "claude"
	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 (
	ProviderAnthropic = "ANTHROPIC"
	ProviderOpenAI    = "OPENAI"
	ProviderBaseten   = "BASETEN_MODEL_API"
	ProviderBedrock   = "BEDROCK"
	ProviderVertex    = "VERTEX"
)

Route providers, as the routes API names them on connections and targets.

View Source
const (
	InstallCLI     = "CLI"
	InstallDesktop = "Desktop"
)

Install kinds.

View Source
const ClaudeCode = "claude-code"

ClaudeCode is the client name Claude Code and Claude Desktop send on the wire, which Baseten keys their catalog, team defaults and usage on. It was also the name of the claude harness before Claude Desktop joined it, so configurations written then still pass it to 'grid token'.

View Source
const CredentialSourceHelper = "helper"

CredentialSourceHelper marks a setup that installed `baseten grid token` as the credential command instead of a key.

View Source
const CredentialSourceSession = "session"

CredentialSourceSession marks a record whose setup installed the session's API key with --use-session-credential instead of creating a routes API key.

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 ClaudeDesktopLocations added in v1.8.0

func ClaudeDesktopLocations() string

ClaudeDesktopLocations names where Detect looks for the app, for error messages.

func ClaudeServedModel added in v1.7.0

func ClaudeServedModel(transcript, message, prompt string) (requested, served string)

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 HasClaudeDesktop added in v1.8.0

func HasClaudeDesktop(installs []Install) bool

HasClaudeDesktop reports whether Detect found the Claude Desktop app.

func HasOpenCode2 added in v1.8.0

func HasOpenCode2(d Detection) bool

func Normalize added in v1.8.0

func Normalize(name string) string

Normalize maps a harness name that has since changed to its current one.

func OpenCodeDesktopLocations added in v1.4.0

func OpenCodeDesktopLocations() string

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

func RestartCodexDaemon

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

func SaveRecords added in v1.4.0

func SaveRecords(dir string, file RecordFile) error

SaveRecords writes the setup records to dir, replacing the file.

func StageCredentials added in v1.4.0

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

StageCredentials puts the proposed token into configuration files, to aid with diff detection.

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
	// Installs lists every copy of the harness found, the one on PATH first.
	// They all read the settings file at Path.
	Installs []Install
}

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. With opts.Helper, the
	// harness runs it for its credential. Without it, ApplyPlans inserts a
	// static one.
	Prepare(path string, routes []Route, opts PrepareOptions) ([]*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
	// SupportsSubagent reports whether --subagent-route-id applies to this harness.
	SupportsSubagent() bool
	// SupportsHelper reports whether the harness can run a [Helper] for its
	// credential instead of storing a key.
	SupportsHelper() bool
	// 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 Helper added in v1.7.0

type Helper struct {
	Path    string
	Profile string
}

Helper is the credential command a harness runs instead of storing a key: this CLI, with the profile setup used pinned so the harness resolves the same one regardless of its environment.

type Install added in v1.4.0

type Install struct {
	// Kind is how the harness was installed: InstallCLI or InstallDesktop.
	Kind   string
	Binary string
	// Version is the executable's --version output, which is informational only.
	Version string
}

Install is one copy of a harness executable.

type Plan

type Plan struct {
	Harness  string
	Path     string
	Keys     []string
	Replaced []string
	Notes    []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 PrepareOptions added in v1.7.0

type PrepareOptions struct {
	Selection Selection
	Endpoint  string
	Helper    *Helper
	CLI       string
	// Installs are the copies of the harness Detect found, for a harness that
	// configures each kind of install in its own files.
	Installs              []Install
	NoClaudeServedModel   bool
	NoPiServedModel       bool
	NoOpenCodeServedModel bool
	GitContext            bool
}

type Providers added in v1.4.0

type Providers map[string]string

Providers lists a team's route connections by ID, as the provider each one authenticates with.

func NewProviders added in v1.4.0

func NewProviders(connections []managementapi.GridConnection) Providers

NewProviders indexes a team's connections by ID.

type Record added in v1.4.0

type Record struct {
	// Config is the settings file path setup wrote, which sync must match.
	Config           string `json:"config"`
	Profile          string `json:"profile"`
	ManagementURL    string `json:"management_url"`
	TeamID           string `json:"team_id"`
	KeyName          string `json:"key_name,omitempty"`
	CredentialSource string `json:"credential_source,omitempty"`
	Route            string `json:"route,omitempty"`
	BackgroundRoute  string `json:"background_route,omitempty"`
	SubagentRoute    string `json:"subagent_route,omitempty"`
	FallbackRoute    string `json:"fallback_route,omitempty"`
	// CodexRestartPending records that the codex app-server daemon still needs
	// a restart, because the last one was declined or failed. Retried on the
	// next sync.
	CodexRestartPending   bool `json:"codex_restart_pending,omitempty"`
	NoClaudeServedModel   bool `json:"no_claude_served_model,omitempty"`
	NoPiServedModel       bool `json:"no_pi_served_model,omitempty"`
	NoOpenCodeServedModel bool `json:"no_opencode_served_model,omitempty"`
	GitContext            bool `json:"git_context,omitempty"`
}

Record remembers the options of the last successful setup for one harness, so sync can replay them. Explicit route selections are stored as route names; an empty route follows the current default, never the default resolved at setup time. Profile and ManagementURL scope the record the same way saved routes API keys are scoped.

type RecordFile added in v1.4.0

type RecordFile struct {
	Version   int               `json:"version"`
	Harnesses map[string]Record `json:"harnesses"`
}

RecordFile is the on-disk harness.json structure. Unrecognized keys are ignored on read and dropped on the next write, like auth.json.

func LoadRecords added in v1.4.0

func LoadRecords(dir string) (RecordFile, error)

LoadRecords reads the setup records in dir. A missing file is an empty record file.

type Route

type Route struct {
	// ID is the route's stable ID, which Claude Desktop's model IDs carry.
	ID          string
	Name        string
	DisplayName string
	// Provider is the route's upstream provider, such as ProviderAnthropic.
	// It is "" when unknown, as for an intelligent route that picks a model per request.
	Provider         string
	UpstreamModel    string
	IntelligentRoute bool
	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
	TargetAPI TargetAPI
	// 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.GridRoute, providers Providers) (Route, error)

NewRoute converts a route from the routes API, resolving the provider of a route that reaches one through a team connection. 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.

func (Selection) Resolve added in v1.4.0

func (s Selection) Resolve(routes []Route) (Selection, error)

Resolve defaults the primary route to the first route and the subagent and fallback routes to the primary, then checks that every selected route exists.

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.

type TargetAPI added in v1.8.0

type TargetAPI string

TargetAPI is the wire protocol a harness calls a route with.

const (
	TargetAPIMessages        TargetAPI = "messages"
	TargetAPIResponses       TargetAPI = "responses"
	TargetAPIChatCompletions TargetAPI = "chat-completions"
)

Jump to

Keyboard shortcuts

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