Documentation
¶
Overview ¶
Package cliupdate keeps the agent CLIs of the machine (Claude Code, Codex) up to date in the background. OpenAI's backend gives Codex the model list of its client version, so a stale CLI hides new models everywhere; a copy left early on PATH (an old `npm i -g` into ~/.local) shadows a newer one the machine has.
A run, for each CLI: it finds every copy along the login shell's PATH, points the first one at the newest when a newer copy stands later (only a link of the person's own folder is changed), asks npm for the latest version, and when the person's own copy is older it installs the new one beside the old (Codex into ~/.local/share/harnessly/agent-cli/codex/<version>, Claude Code through its own `claude update`, which does the same) and switches the link. Running chats keep the files they started with. A copy the machine's admin keeps (a folder the account cannot write) is left to the admin and reported.
Index ¶
Constants ¶
const ( // Every is how often a run starts by itself. Every = 6 * time.Hour // PokeAfter is how old the last run must be for a page open to start another. PokeAfter = 30 * time.Minute // FirstAfter is how long after the start the first run waits, so it does not slow the start. FirstAfter = 2 * time.Minute )
Timing of the runs.
const ( StateOK = "ok" // the newest known version runs StateUpdating = "updating" // a new version is being installed StateUpdated = "updated" // the last run installed a new version or pointed PATH at the newer copy StateManaged = "managed" // a newer version exists, the copy is the admin's StateShadowed = "shadowed" // an older copy shadows a newer one and its entry cannot be changed here StateFailed = "failed" // the last update failed (Detail says why); the old version keeps running StateMissing = "missing" // not installed )
States of a CLI (Status.State).
Variables ¶
var CLIs = []CLI{
{Name: "claude", Package: "@anthropic-ai/claude-code", Label: "Claude Code"},
{Name: "codex", Package: "@openai/codex", Label: "Codex"},
}
CLIs the updater keeps.
Functions ¶
func LiveModels ¶
LiveModels are the «gpt-live» models of the Codex at real (the path PATH's codex resolves to). The first call for a version starts the read in the background and answers nil; the next ones answer what it found.
func Newer ¶
Newer: version a is newer than b. A version that does not parse is never newer, and anything is newer than none.
func ScanLiveModels ¶
ScanLiveModels finds the «gpt-live-…-codex» names in r, each once.
Types ¶
type CLI ¶
CLI is an agent CLI the updater keeps: its command and its npm package (where its latest version is read).
type Copy ¶
type Copy struct {
Path string `json:"path"`
Real string `json:"real"`
Version string `json:"version"`
}
Copy is one copy of a CLI along PATH: the PATH entry, where it really is, the version it prints.
func Newest ¶
Newest is the copy with the highest version, the earliest on PATH among equals; false with no copy that has one.
func ParseCopies ¶
ParseCopies reads the lines of the listing script: PATH entry, real path and the first line of `--version`, by tabs. A real path seen before is the same copy and is left out.
type Deps ¶
type Deps struct {
// Shell runs scripts in the person's login shell (preflight.Checker).
Shell agents.LoginRunner
// EnvDir holds the env files (the proxy) the CLIs' scripts source first.
EnvDir string
Home string
// Changed is told after a CLI changed (a new version, a repointed link): the runtime drops what it cached of the
// CLIs and refreshes the model lists.
Changed func(cli string)
// Log hears what the updater did.
Log func(format string, a ...any)
// Now is the clock; nil is time.Now.
Now func() time.Time
}
Deps are what the updater needs of the runtime.
type Status ¶
type Status struct {
CLI string `json:"cli"`
Label string `json:"label"`
Path string `json:"path,omitempty"`
Real string `json:"real,omitempty"`
Version string `json:"version,omitempty"`
Latest string `json:"latest,omitempty"`
State string `json:"state"`
Detail string `json:"detail,omitempty"`
// From is the version before the last update, To the one after it, At when it happened.
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitzero"`
CheckedAt time.Time `json:"checkedAt,omitzero"`
// Fixable: a run now would change something (an update of the person's copy, a link to repoint).
Fixable bool `json:"fixable,omitempty"`
}
Status of a CLI as the machine checks show it.
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater runs the checks, one at a time.
func (*Updater) Poke ¶
Poke starts a run in the background when the last one is older than PokeAfter (a page was opened); it never waits.