The best way to control Claude Code, Codex and more from any computer or phone

main
ts 28 lines 1.08 KB
Raw
1 import { compareSemverVersions, parseSemver } from "@t3tools/shared/semver";
2
3 // A non-semver installed version counts any other release as an update.
4 const isNewer = (candidate: string, current: string) =>
5 parseSemver(candidate) && parseSemver(current)
6 ? compareSemverVersions(candidate, current) > 0
7 : candidate !== current;
8
9 /**
10 * Picks the release a managed installation's `start` downloads. A fresh install
11 * gets T3 Code's pinned release; an existing one moves to the newest known
12 * release above it. Null means nothing newer is known, so `start` re-checks the
13 * installed runtime instead of downgrading it.
14 */
15 export function selectManagedRelease<Release extends { readonly version: string }>(
16 installedVersion: string | null,
17 pinned: Release | null,
18 upstream: Release | null,
19 ): Release | null {
20 if (installedVersion === null) return pinned;
21 let selected: Release | null = null;
22 for (const candidate of [pinned, upstream]) {
23 if (candidate && isNewer(candidate.version, selected?.version ?? installedVersion)) {
24 selected = candidate;
25 }
26 }
27 return selected;
28 }