Skip to content

Add self-update: sleeperagent update + Codex-style startup offer - #19

Merged
amanjaiman merged 1 commit into
mainfrom
feat/self-update
Jul 11, 2026
Merged

Add self-update: sleeperagent update + Codex-style startup offer#19
amanjaiman merged 1 commit into
mainfrom
feat/self-update

Conversation

@amanjaiman

Copy link
Copy Markdown
Owner

Why

Updating currently means re-downloading a release and re-running install --force (or go install). Codex CLI's flow is better: check for a newer version at startup, ask, and self-update on Y. This brings that to sleeperagent, and adds an explicit sleeperagent update command that permanently answers "how do I update this machine?"

What

  • internal/update: resolves the latest release from the /releases/latest redirect (no API token, no rate limits), semver-compares against the goreleaser-stamped main.version, downloads the platform asset (sleeperagent_<ver>_<os>_<arch>.tar.gz|zip), verifies sha256 against the release's checksums.txt, and atomically replaces the executable. On Windows the running exe is parked as <exe>.old and cleaned up on the next start.
  • sleeperagent update [--check] — explicit update; --check only reports.
  • Startup offer: run/attach-existing from a real terminal check at most once a day (cached in the state dir), prompt Update now? [Y/n] before the session takes the terminal, and continue on the current version after updating. Never blocks startup: 3s timeout, silent on failure, skipped for dev builds and non-TTY runs.
  • Opt-outs: [update] check = false in config.toml, or SLEEPERAGENT_NO_UPDATE_CHECK=1.
  • Safety: checksum mismatch or any failure aborts without touching the installed binary.

CI

  • The workflow's hand-kept integration list had drifted (missing dead_session and both interactive tests); it now runs test/run_all.sh directly and stamps the test binary with a version so the update test can run.
  • Test scripts that give the binary a pty export SLEEPERAGENT_NO_UPDATE_CHECK so the startup prompt can never reach real GitHub from a test (this actually bit integration_pty.sh during development — it stalled on the prompt against the real v0.4.0 release).

Testing

  • Unit tests: version comparison (incl. dev, pre-release suffixes, git-describe strings), redirect resolution, tar.gz/zip extraction, checksum rejection, missing-checksum rejection, the Windows .old swap, cache throttling.
  • New test/integration_update.sh drives the real CLI against a fake release server: --check reports without installing, update swaps the executable (verified by executing the swapped-in payload), and a tampered asset is refused with the original binary untouched.
  • Full suite: all 12 integration tests green in WSL tmux; gofmt/vet/go test ./... green on Windows.

🤖 Generated with Claude Code

New internal/update package: resolves the latest release via the
/releases/latest redirect (no API rate limits), compares semver against
the ldflags-stamped version, downloads the platform asset, verifies it
against checksums.txt, and atomically swaps the executable (Windows
parks the running exe as .old, swept up on next start by CleanupOld).

`sleeperagent update [--check]` runs it explicitly. Release builds also
offer it at startup: run/attach-existing from a real terminal check at
most once a day (cached in the state dir), prompt [Y/n] before the
session launches, and never block startup on a slow or offline network.
Skipped for dev builds and non-TTY runs; opt out with [update]
check=false or SLEEPERAGENT_NO_UPDATE_CHECK=1. A declined or failed
update never touches the existing binary.

Tests: unit coverage for version compare, redirect resolution, archive
extraction, checksum rejection, the Windows .old dance, and cache
throttling; a new integration test drives the real CLI against a fake
release server end to end (report, install, swap, tamper rejection).
CI now runs the suite via test/run_all.sh (its hand-kept list had
drifted) and stamps the test binary so the update test can run; the
pty/interactive tests export SLEEPERAGENT_NO_UPDATE_CHECK so the
startup prompt can never reach real GitHub from a test pty.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@amanjaiman
amanjaiman merged commit 4247516 into main Jul 11, 2026
@amanjaiman
amanjaiman deleted the feat/self-update branch July 11, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant