feat: show update availability in status

This commit is contained in:
Peter Steinberger
2026-01-17 18:23:27 +00:00
parent 8a67d29748
commit 7a3fa9ce03
4 changed files with 58 additions and 2 deletions

View File

@@ -24,6 +24,48 @@ export async function getUpdateCheckResult(params: {
});
}
export type UpdateAvailability = {
available: boolean;
hasGitUpdate: boolean;
hasRegistryUpdate: boolean;
latestVersion: string | null;
gitBehind: number | null;
};
export function resolveUpdateAvailability(update: UpdateCheckResult): UpdateAvailability {
const latestVersion = update.registry?.latestVersion ?? null;
const registryCmp = latestVersion ? compareSemverStrings(VERSION, latestVersion) : null;
const hasRegistryUpdate = registryCmp != null && registryCmp < 0;
const gitBehind =
update.installKind === "git" && typeof update.git?.behind === "number"
? update.git.behind
: null;
const hasGitUpdate = gitBehind != null && gitBehind > 0;
return {
available: hasGitUpdate || hasRegistryUpdate,
hasGitUpdate,
hasRegistryUpdate,
latestVersion: hasRegistryUpdate ? latestVersion : null,
gitBehind,
};
}
export function formatUpdateAvailableHint(update: UpdateCheckResult): string | null {
const availability = resolveUpdateAvailability(update);
if (!availability.available) return null;
const details: string[] = [];
if (availability.hasGitUpdate && availability.gitBehind != null) {
details.push(`git behind ${availability.gitBehind}`);
}
if (availability.hasRegistryUpdate && availability.latestVersion) {
details.push(`npm ${availability.latestVersion}`);
}
const suffix = details.length > 0 ? ` (${details.join(" · ")})` : "";
return `Update available${suffix}. Run: clawdbot update`;
}
export function formatUpdateOneLiner(update: UpdateCheckResult): string {
const parts: string[] = [];
if (update.installKind === "git" && update.git) {