Help us shape the future of Go! Take the 2026 Go Developer Survey

harness

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package harness detects, installs, updates, and logs in to the vendor agent CLIs, and lists their models. The vendor facts come from agent-wire.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound    = errors.New("harness: not found")
	ErrInvalid     = errors.New("harness: invalid request")
	ErrState       = errors.New("harness: wrong state")
	ErrBusy        = errors.New("harness: busy")
	ErrUnsupported = errors.New("harness: not supported")
)

Errors.

Functions

This section is empty.

Types

type AuthMode

type AuthMode string

AuthMode tells which login a harness uses.

const (
	// AuthShared uses the login of the user, in the user home of the harness.
	AuthShared AuthMode = "shared"
	// AuthSeparate uses a login of the visor only, in <home>/harness/<name>.
	AuthSeparate AuthMode = "separate"
)

Auth modes.

type AuthState

type AuthState string

AuthState is the login state of a harness.

const (
	AuthUnknown AuthState = "unknown"
	AuthOK      AuthState = "ok"
	AuthMissing AuthState = "missing"
	AuthExpired AuthState = "expired"
)

Auth states.

type Facts

type Facts struct {
	Recipe          func(h agentwire.Harness) (agentwire.InstallRecipe, bool)
	LoginCommand    func(h agentwire.Harness) []string
	LogoutCommand   func(h agentwire.Harness) []string
	LoginEnv        func(h agentwire.Harness, home string) map[string]string
	CredentialFiles func(h agentwire.Harness) []string
	AuthStatus      func(ctx context.Context, h agentwire.Harness, home string) (agentwire.AuthState, error)
}

Facts are the vendor facts with no runtime. A nil field uses agent-wire. Tests replace them.

type Harness

type Harness struct {
	Name      string `json:"name"`
	Installed bool   `json:"installed"`
	Version   string `json:"version,omitempty"`
	// Latest is the newest vendor release, when known.
	Latest string `json:"latest,omitempty"`
	Path   string `json:"path,omitempty"`
	Source Source `json:"source,omitempty"`
	// Installs are the versions that the visor installed, oldest first.
	Installs []string `json:"installs,omitempty"`
	// Installable means that the visor can install its own copy.
	Installable bool `json:"installable"`
	// Supported means that the installed version meets the agent-wire floor.
	Supported bool `json:"supported"`
	// Detail tells why the harness is not usable.
	Detail   string    `json:"detail,omitempty"`
	AuthMode AuthMode  `json:"auth_mode"`
	Auth     AuthState `json:"auth"`
	// EnvKeys lists the harness env keys. The values never leave the visor.
	EnvKeys []string `json:"env_keys,omitempty"`
	Limits  *Limits  `json:"limits,omitempty"`
	// Models is the fixed model list. Manager.Models gives the live list.
	Models []Model `json:"models,omitempty"`
	// Login is the login that runs now, or nil.
	Login *Login `json:"login,omitempty"`
}

Harness is one vendor agent CLI on this machine.

type Launch

type Launch struct {
	// Binary is the visor copy. Empty searches PATH.
	Binary string
	// Home is the login home of a separate login. Empty uses the user login.
	Home string
	// Env is the harness env layer.
	Env map[string]string
	// Args are launch args that the harness needs, before the session args.
	Args []string
}

Launch is what a session start needs from the harness.

type LimitWindow

type LimitWindow struct {
	Key         string    `json:"key"`
	Scope       string    `json:"scope,omitempty"`
	Minutes     int       `json:"minutes,omitempty"`
	UsedPercent float64   `json:"used_percent"`
	ResetsAt    time.Time `json:"resets_at,omitzero"`
}

LimitWindow is the use of one plan limit window.

type Limits

type Limits struct {
	Plan     string        `json:"plan,omitempty"`
	Rejected bool          `json:"rejected,omitempty"`
	Windows  []LimitWindow `json:"windows,omitempty"`
}

Limits is the plan limit state of the account behind a harness.

type Login

type Login struct {
	Harness string `json:"harness"`
	// URL is the address that the user opens.
	URL string `json:"url,omitempty"`
	// Code is the device code that the user types on that page.
	Code string `json:"code,omitempty"`
	// AwaitCode means that the vendor asks for a pasted code. A pipe login
	// cannot send it; a terminal login can.
	AwaitCode bool `json:"await_code,omitempty"`
	// InApp means that the harness logs in only inside its own terminal
	// view. No login process runs.
	InApp bool   `json:"in_app,omitempty"`
	Error string `json:"error,omitempty"`
	Hint  string `json:"hint,omitempty"`
	// Done means that the login process ended.
	Done      bool      `json:"done,omitempty"`
	StartedAt time.Time `json:"started_at,omitzero"`
}

Login is the state of a vendor login. A token that the vendor prints never goes in it.

type Manager

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

Manager keeps the harness inventory of one visor.

func New

func New(home string, st *store.Store, wire Wire, o Options) *Manager

New makes the manager of the harnesses under home.

func (*Manager) Busy

func (m *Manager) Busy() bool

Busy reports that a login, an install, or an update runs.

func (*Manager) Close

func (m *Manager) Close(ctx context.Context) error

Close stops the logins and the release lookups.

func (*Manager) Harness

func (m *Manager) Harness(ctx context.Context, name string) (Harness, error)

Harness gives one harness.

func (*Manager) Install

func (m *Manager) Install(ctx context.Context, name, version string) (Harness, error)

Install installs a visor copy of the harness in bin/<name>/<version>/ and moves the current link to it. An empty version is the latest release. A failed install leaves the current link as it was. It returns ErrBusy when a live session uses the harness, because the switch must not change the binary under a running session.

func (*Manager) Launch

func (m *Manager) Launch(ctx context.Context, name string) (Launch, error)

Launch gives what a session of the harness needs. An unknown harness gives the zero Launch, so a session with no inventory entry still starts.

func (*Manager) List

func (m *Manager) List(ctx context.Context) ([]Harness, error)

List gives each known harness.

func (*Manager) Login

func (m *Manager) Login(ctx context.Context, name string) (Login, error)

Login starts the vendor login of the harness, in the login home of its auth mode. It returns when the vendor shows a URL or a code, when the process ends, or after Options.LoginWait. The process runs on until the user ends the login, or until Options.LoginTimeout. A second call while a login runs gives the same login.

func (*Manager) Logout

func (m *Manager) Logout(ctx context.Context, name string) error

Logout runs the vendor logout in the login home of the auth mode. With no vendor logout, a separate login removes its credential files.

func (*Manager) Models

func (m *Manager) Models(ctx context.Context, name string) ([]Model, error)

Models lists the models of a harness: the live list when the harness gives one, else the fixed list.

func (*Manager) SetAuthMode

func (m *Manager) SetAuthMode(ctx context.Context, name string, mode AuthMode) (Harness, error)

SetAuthMode moves the harness to a shared or a separate login. A live session keeps its login; the next session gets the new one.

func (*Manager) SetEnv

func (m *Manager) SetEnv(_ context.Context, name string, env map[string]string) error

SetEnv replaces the env of a harness. An empty env removes it. The file has mode 0600.

func (*Manager) SetLimits

func (m *Manager) SetLimits(ctx context.Context, name string, l Limits)

SetLimits keeps the last plan limits that a session of the harness saw.

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, name, version string) (Harness, error)

Update updates the harness. A visor copy gets a new visor copy. A system install runs the vendor update. Both return ErrBusy when a live session uses the harness.

type Model

type Model struct {
	ID          string `json:"id"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Default     bool   `json:"default,omitempty"`
	// Efforts are the effort levels, from low to high.
	Efforts []string `json:"efforts,omitempty"`
}

Model is one model that a harness offers.

type Options

type Options struct {
	// Names are the harnesses that the manager knows. Empty means each
	// agent-wire harness with an install recipe.
	Names []string
	// Path is the search path for the install tools, such as npm. Empty
	// uses PATH.
	Path  string
	Facts Facts
	// LoginWait is how long Login waits for a URL or a code. Zero is 20 s.
	LoginWait time.Duration
	// LoginTimeout stops a login that does not end. Zero is 10 min.
	LoginTimeout time.Duration
	// InUse reports that a live session uses the harness. The visor sets it.
	InUse func(name string) bool
	// OnChange gets the name of a harness that changed. The visor sets it.
	OnChange func(name string)
	Logger   *slog.Logger
}

Options configures a Manager.

type Source

type Source string

Source tells where the harness binary comes from.

const (
	SourceVisor  Source = "visor"
	SourceSystem Source = "system"
)

Sources.

type Wire

type Wire interface {
	Detect(ctx context.Context, h agentwire.Harness) (agentwire.Detection, error)
	Version(ctx context.Context, bin string) string
	Models(ctx context.Context, h agentwire.Harness, q agentwire.ModelQuery) ([]agentwire.ModelInfo, error)
	LatestVersion(ctx context.Context, h agentwire.Harness) (string, error)
	InvalidateModels(h agentwire.Harness)
}

Wire is what the manager needs from the agent-wire runtime.

Jump to

Keyboard shortcuts

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