@@ -82,23 +82,37 @@ export async function getLatestCliVersion(fetchImpl: typeof fetch = fetch): Prom
8282 throw new Error ( "Invalid release response from GitHub." )
8383 }
8484
85+ let latestVersion : string | undefined
86+
8587 for ( const release of releases ) {
8688 if ( ! isRecord ( release ) ) {
8789 continue
8890 }
8991
9092 const tagName = release . tag_name
9193 if ( typeof tagName === "string" && tagName . startsWith ( "cli-v" ) ) {
92- return tagName . slice ( "cli-v" . length )
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+ }
93102 }
94103 }
95104
105+ if ( latestVersion ) {
106+ return latestVersion
107+ }
108+
96109 throw new Error ( "Could not determine the latest CLI release version." )
97110}
98111
99- export function runUpgradeInstaller ( spawnImpl : typeof spawn = spawn ) : Promise < void > {
112+ export function runUpgradeInstaller ( version ?: string , spawnImpl : typeof spawn = spawn ) : Promise < void > {
100113 return new Promise ( ( resolve , reject ) => {
101- const child = spawnImpl ( "sh" , [ "-c" , INSTALL_SCRIPT_COMMAND ] , { stdio : "inherit" } )
114+ const env = version ? { ...process . env , ROO_VERSION : version } : process . env
115+ const child = spawnImpl ( "sh" , [ "-c" , INSTALL_SCRIPT_COMMAND ] , { stdio : "inherit" , env } )
102116
103117 child . once ( "error" , ( error ) => {
104118 reject ( error )
@@ -119,7 +133,7 @@ export function runUpgradeInstaller(spawnImpl: typeof spawn = spawn): Promise<vo
119133export async function upgrade ( options : UpgradeOptions = { } ) : Promise < void > {
120134 const currentVersion = options . currentVersion ?? VERSION
121135 const fetchImpl = options . fetchImpl ?? fetch
122- const runInstaller = options . runInstaller ?? ( ( ) => runUpgradeInstaller ( ) )
136+ const runInstaller = options . runInstaller
123137
124138 console . log ( `Current version: ${ currentVersion } ` )
125139
@@ -132,6 +146,10 @@ export async function upgrade(options: UpgradeOptions = {}): Promise<void> {
132146 }
133147
134148 console . log ( `Upgrading Roo CLI from ${ currentVersion } to ${ latestVersion } ...` )
135- await runInstaller ( )
149+ if ( runInstaller ) {
150+ await runInstaller ( )
151+ } else {
152+ await runUpgradeInstaller ( latestVersion )
153+ }
136154 console . log ( "✓ Upgrade completed." )
137155}
0 commit comments