Near-silent auto-update. Mimics Claude Code's UX:
- On launch, fork a fully detached worker (<exe> --self-update-check) that polls the GitHub releases API, downloads the matching tarball, and atomically swaps the running binary's path. The current process keeps using the old inode; the next launch picks up the new one.
- Throttled so we hit the API at most once per 4h.
- On the first launch after a swap, print one dim line on stderr.
The build-time default is off — source-installed binaries (nimble install) shouldn't quietly self-replace what the user just built. CI passes -d:autoUpdate for prebuilt release binaries, which flips the default on. Either way, an explicit auto-update = "true"/"false" under [settings] in ~/.config/3code/config wins.
Procs
proc autoUpdateEnabled(): bool {....raises: [], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, WriteIOEffect, RootEffect], forbids: [].}
- Resolution: explicit config value wins; otherwise fall back to the build-time default. Read parsecfg directly so the update path doesn't drag in the rest of the config machinery.
proc cleanupStaleBinaries() {....raises: [], tags: [], forbids: [].}
- Windows-only: delete <name>.old files left behind by swapInstall from a prior auto-update. They couldn't be deleted at swap time because the previous process still held them mapped; the new process doesn't, so the delete now succeeds.
proc parseSemver(s: string): seq[int] {....raises: [ValueError], tags: [], forbids: [].}
proc selfUpdateCheck(curVersion = Version; targetPath = ""; force = false) {. ...raises: [Exception, ValueError, OSError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, WriteIOEffect, RootEffect, TimeEffect, WriteDirEffect, ExecIOEffect], forbids: [].}
-
Worker entry point. Runs in the detached background process. Strictly silent — never writes to stdout/stderr.
curVersion / targetPath exist for tests: they spoof the "running version" and the binary path so the live pipeline can be exercised without affecting the installed binary. force skips the config gate (tests + manual invocation override).
proc semverGt(a, b: string): bool {....raises: [ValueError], tags: [], forbids: [].}
proc showUpdateNoticeMaybe() {....raises: [], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, WriteIOEffect, WriteDirEffect], forbids: [].}
- If the recorded last-seen version differs from the running version, emit one dim line on stderr and update the marker. First launch (no marker) is silent — only writes the marker.
proc spawnBackgroundUpdateMaybe() {....raises: [], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, WriteIOEffect, RootEffect, TimeEffect, WriteDirEffect], forbids: [].}
- Double-fork + setsid so the worker survives the parent exiting and SIGHUP from the controlling terminal. Throttle is claimed before the fork so concurrent launches don't pile up.