cliupdate

package
v0.16.397 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 17 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 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

View Source
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.

View Source
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

View Source
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 Dir

func Dir(home string) string

Dir is where Codex's side-by-side installs go.

func LiveModels

func LiveModels(real string) []string

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

func Newer(a, b string) bool

Newer: version a is newer than b. A version that does not parse is never newer, and anything is newer than none.

func ScanLiveModels

func ScanLiveModels(r io.Reader) []string

ScanLiveModels finds the «gpt-live-…-codex» names in r, each once.

Types

type CLI

type CLI struct {
	Name    string
	Package string
	Label   string
}

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

func Newest(copies []Copy) (Copy, bool)

Newest is the copy with the highest version, the earliest on PATH among equals; false with no copy that has one.

func ParseCopies

func ParseCopies(out string) []Copy

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.

func Shadowing

func Shadowing(copies []Copy) (Copy, bool)

Shadowing is the newer copy that the first copy on PATH shadows; false when the first one is the newest.

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 New

func New(d Deps) *Updater

New is an updater; nothing runs until Loop, Poke or Run.

func (*Updater) Loop

func (u *Updater) Loop(ctx context.Context)

Loop runs a check FirstAfter the start and then Every, until ctx ends.

func (*Updater) Poke

func (u *Updater) Poke(ctx context.Context) bool

Poke starts a run in the background when the last one is older than PokeAfter (a page was opened); it never waits.

func (*Updater) Run

func (u *Updater) Run(ctx context.Context)

Run checks and updates every CLI now; a run already going is waited for instead of starting another.

func (*Updater) Status

func (u *Updater) Status() []Status

Status is what the last run saw, in the order of CLIs; a CLI never looked at is left out.

Jump to

Keyboard shortcuts

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