mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:28:26 +00:00
feat: show update availability in status
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user