(fetchImpl: typeof fetch = fetch)
| 66 | } |
| 67 | |
| 68 | export async function getLatestCliVersion(fetchImpl: typeof fetch = fetch): Promise<string> { |
| 69 | const response = await fetchImpl(RELEASES_URL, { |
| 70 | headers: { |
| 71 | Accept: "application/vnd.github+json", |
| 72 | "User-Agent": "roo-cli", |
| 73 | }, |
| 74 | }) |
| 75 | |
| 76 | if (!response.ok) { |
| 77 | throw new Error(`Failed to check latest version (HTTP ${response.status})`) |
| 78 | } |
| 79 | |
| 80 | const releases = await response.json() |
| 81 | if (!Array.isArray(releases)) { |
| 82 | throw new Error("Invalid release response from GitHub.") |
| 83 | } |
| 84 | |
| 85 | let latestVersion: string | undefined |
| 86 | |
| 87 | for (const release of releases) { |
| 88 | if (!isRecord(release)) { |
| 89 | continue |
| 90 | } |
| 91 | |
| 92 | const tagName = release.tag_name |
| 93 | if (typeof tagName === "string" && tagName.startsWith("cli-v")) { |
| 94 | const candidate = tagName.slice("cli-v".length) |
| 95 | try { |
| 96 | if (!latestVersion || compareVersions(candidate, latestVersion) > 0) { |
| 97 | latestVersion = candidate |
| 98 | } |
| 99 | } catch { |
| 100 | // Ignore malformed CLI tags and keep scanning other releases. |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | if (latestVersion) { |
| 106 | return latestVersion |
| 107 | } |
| 108 | |
| 109 | throw new Error("Could not determine the latest CLI release version.") |
| 110 | } |
| 111 | |
| 112 | export function runUpgradeInstaller(version?: string, spawnImpl: typeof spawn = spawn): Promise<void> { |
| 113 | return new Promise((resolve, reject) => { |
no test coverage detected