feat(cli): add self-update service

Check the npm registry (at most once per 24h, file-locked) for newer
@opencode-ai/cli releases and act on a host-level autoupdate policy read
from config. Apply patch updates automatically, confirm minor updates
interactively, and never auto-update across majors. Skip local installs
and honor the disable flag. Wired into the default TUI command
(interactive) and serve (background).
This commit is contained in:
Dax Raad 2026-06-27 00:51:45 -04:00
commit 5df049d081
8 changed files with 256 additions and 3 deletions

View file

@ -0,0 +1,25 @@
import { describe, expect, test } from "bun:test"
import { action, decodePolicy } from "./updater"
describe("updater", () => {
test("reads autoupdate from JSONC", () => {
expect(decodePolicy('{ // preference\n "autoupdate": "notify",\n}')).toBe("notify")
expect(decodePolicy('{ "autoupdate": false }')).toBe(false)
expect(decodePolicy('{ "autoupdate": "invalid" }')).toBeUndefined()
})
test("automatically updates patches", () => {
expect(action("1.2.3", "1.2.4", true, false)).toBe("upgrade")
expect(action("1.2.3", "1.2.4", "notify", true)).toBe("confirm")
expect(action("1.2.3", "1.2.4", false, true)).toBe("none")
})
test("requires an interactive confirmation for minors", () => {
expect(action("1.2.3", "1.3.0", true, true)).toBe("confirm")
expect(action("1.2.3", "1.3.0", true, false)).toBe("none")
})
test("never automatically updates majors", () => {
expect(action("1.2.3", "2.0.0", true, true)).toBe("none")
})
})