@@ -55,6 +55,8 @@ export interface ProviderMaintenanceCapabilityResolutionOptions {
5555 readonly env ?: NodeJS . ProcessEnv ;
5656 readonly resolvedCommandPath ?: string | null ;
5757 readonly realCommandPath ?: string | null ;
58+ /** Contents of the resolved command when it is a small script, so wrappers can be recognised. */
59+ readonly commandScript ?: string | null ;
5860}
5961
6062export interface ProviderMaintenanceCapabilitiesResolver {
@@ -188,6 +190,21 @@ function makeVitePlusGlobalProviderMaintenanceCapabilities(
188190 } ) ;
189191}
190192
193+ function makeMiseProviderMaintenanceCapabilities (
194+ definition : PackageManagedProviderMaintenanceDefinition ,
195+ tool : string ,
196+ ) : ProviderMaintenanceCapabilities {
197+ return makeProviderMaintenanceCapabilities ( {
198+ provider : definition . provider ,
199+ packageName : definition . npmPackageName ,
200+ updateExecutable : "mise" ,
201+ // `--bump` moves past an exact version pin in the user's config; the
202+ // usual `latest` pin stays `latest`.
203+ updateArgs : [ "upgrade" , "--bump" , tool ] ,
204+ updateLockKey : "mise" ,
205+ } ) ;
206+ }
207+
191208function makeHomebrewProviderMaintenanceCapabilities (
192209 definition : PackageManagedProviderMaintenanceDefinition ,
193210) : ProviderMaintenanceCapabilities {
@@ -259,6 +276,40 @@ function isNpmGlobalCommandPath(commandPath: string): boolean {
259276 ) ;
260277}
261278
279+ const MISE_INSTALL_PATH_PATTERN = / \/ m i s e \/ i n s t a l l s \/ ( [ ^ / ] + ) \/ / ;
280+ const MISE_SHIM_PATH_PATTERN = / \/ m i s e \/ s h i m s \/ ( [ ^ / ] + ) $ / ;
281+ // Wrapper scripts such as Omarchy's `exec mise x "codex" -- "codex" "$@"`.
282+ const MISE_EXEC_SCRIPT_PATTERN = / \b m i s e \s + (?: x | e x e c ) \s + " ? ( [ ^ \s " ] + ) " ? / ;
283+
284+ /**
285+ * Maps a mise-managed command to the tool spec `mise upgrade` expects, or
286+ * null when mise does not manage it. Recognises binaries under mise's install
287+ * tree, mise shims, and small wrapper scripts that `mise x` the tool. Binaries
288+ * under mise's `node` install are ordinary npm globals and are left to npm.
289+ * Install directories are kebab-cased tool specs, so only the npm backend can
290+ * be mapped back to a spec; shims and wrappers name the tool by its bin name.
291+ */
292+ function resolveMiseTool ( input : {
293+ readonly commandPaths : ReadonlyArray < string > ;
294+ readonly commandScript : string | null | undefined ;
295+ readonly npmPackageName : string ;
296+ } ) : string | null {
297+ for ( const commandPath of input . commandPaths ) {
298+ const normalized = normalizeCommandPath ( commandPath ) ;
299+ const installDir = MISE_INSTALL_PATH_PATTERN . exec ( normalized ) ?. [ 1 ] ;
300+ if ( installDir && installDir !== "node" ) {
301+ return installDir . startsWith ( "npm-" ) ? `npm:${ input . npmPackageName } ` : installDir ;
302+ }
303+ const shim = MISE_SHIM_PATH_PATTERN . exec ( normalized ) ?. [ 1 ] ;
304+ if ( shim ) {
305+ return shim . replace ( / \. ( e x e | c m d ) $ / , "" ) ;
306+ }
307+ }
308+ return input . commandScript
309+ ? ( MISE_EXEC_SCRIPT_PATTERN . exec ( input . commandScript ) ?. [ 1 ] ?? null )
310+ : null ;
311+ }
312+
262313function isHomebrewCommandPath ( commandPath : string ) : boolean {
263314 const normalized = normalizeCommandPath ( commandPath ) ;
264315 return (
@@ -291,6 +342,17 @@ export function resolvePackageManagedProviderMaintenance(
291342 ...( options ?. realCommandPath ? [ options . realCommandPath ] : [ ] ) ,
292343 ] ;
293344
345+ // Checked before native installers: a mise wrapper for claude lives at
346+ // `~/.local/bin/claude`, where the native check would otherwise send
347+ // `claude update` at a binary that mise owns.
348+ const miseTool = resolveMiseTool ( {
349+ commandPaths,
350+ commandScript : options ?. commandScript ,
351+ npmPackageName : definition . npmPackageName ,
352+ } ) ;
353+ if ( miseTool ) {
354+ return makeMiseProviderMaintenanceCapabilities ( definition , miseTool ) ;
355+ }
294356 const nativeUpdate = definition . nativeUpdate ;
295357 if (
296358 nativeUpdate &&
@@ -353,11 +415,28 @@ function makeManualProviderMaintenanceCapabilities(
353415 } ) ;
354416}
355417
418+ const COMMAND_SCRIPT_MAX_BYTES = 4_096n ;
419+
420+ /** Reads the resolved command when it is a small file; binaries and large launchers yield null. */
421+ const readCommandScript = Effect . fn ( "readCommandScript" ) ( function * (
422+ fileSystem : FileSystem . FileSystem ,
423+ commandPath : string ,
424+ ) {
425+ const info = yield * fileSystem . stat ( commandPath ) . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ;
426+ if ( ! info || info . type !== "File" || info . size > COMMAND_SCRIPT_MAX_BYTES ) {
427+ return null ;
428+ }
429+ return yield * fileSystem . readFileString ( commandPath ) . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ;
430+ } ) ;
431+
356432export const resolveProviderMaintenanceCapabilitiesEffect = Effect . fn (
357433 "resolveProviderMaintenanceCapabilitiesEffect" ,
358434) ( function * (
359435 resolver : ProviderMaintenanceCapabilitiesResolver ,
360- options ?: Omit < ProviderMaintenanceCapabilityResolutionOptions , "realCommandPath" > ,
436+ options ?: Omit <
437+ ProviderMaintenanceCapabilityResolutionOptions ,
438+ "realCommandPath" | "commandScript"
439+ > ,
361440) {
362441 const binaryPath = nonEmptyString ( options ?. binaryPath ) ;
363442 if ( ! binaryPath ) {
@@ -377,11 +456,13 @@ export const resolveProviderMaintenanceCapabilitiesEffect = Effect.fn(
377456 const realCommandPath = yield * fileSystem
378457 . realPath ( resolvedCommandPath )
379458 . pipe ( Effect . orElseSucceed ( ( ) => resolvedCommandPath ) ) ;
459+ const commandScript = yield * readCommandScript ( fileSystem , realCommandPath ) ;
380460 return resolver . resolve ( {
381461 ...options ,
382462 env,
383463 resolvedCommandPath,
384464 realCommandPath,
465+ commandScript,
385466 } ) ;
386467} ) ;
387468
0 commit comments