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 ¶
- Variables
- type AuthMode
- type AuthState
- type Facts
- type Harness
- type Launch
- type LimitWindow
- type Limits
- type Login
- type Manager
- func (m *Manager) Busy() bool
- func (m *Manager) Close(ctx context.Context) error
- func (m *Manager) Harness(ctx context.Context, name string) (Harness, error)
- func (m *Manager) Install(ctx context.Context, name, version string) (Harness, error)
- func (m *Manager) Launch(ctx context.Context, name string) (Launch, error)
- func (m *Manager) List(ctx context.Context) ([]Harness, error)
- func (m *Manager) Login(ctx context.Context, name string) (Login, error)
- func (m *Manager) Logout(ctx context.Context, name string) error
- func (m *Manager) Models(ctx context.Context, name string) ([]Model, error)
- func (m *Manager) SetAuthMode(ctx context.Context, name string, mode AuthMode) (Harness, error)
- func (m *Manager) SetEnv(_ context.Context, name string, env map[string]string) error
- func (m *Manager) SetLimits(ctx context.Context, name string, l Limits)
- func (m *Manager) Update(ctx context.Context, name, version string) (Harness, error)
- type Model
- type Options
- type Source
- type Wire
Constants ¶
This section is empty.
Variables ¶
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 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 (*Manager) Install ¶
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 ¶
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) Login ¶
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 ¶
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 ¶
Models lists the models of a harness: the live list when the harness gives one, else the fixed list.
func (*Manager) SetAuthMode ¶
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 ¶
SetEnv replaces the env of a harness. An empty env removes it. The file has mode 0600.
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 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.