From c7a0efb5aa2b5b46c6b05d191265c63c958d4d25 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Sun, 18 Oct 2026 16:09:44 -0400 Subject: [PATCH 01/12] feat(server): update mise-installed providers through mise The provider Update button ran a provider's own updater, such as `claude update`, on installs that mise owns, which fails or installs a copy mise does not track. Omarchy now installs its agent CLIs this way by default. Mise is now checked first, and only mise proves ownership: `mise which` resolves shims and `mise x` wrappers, and `mise ls --json --installed` must list an active install holding the binary. A tool requested as `latest` updates with `mise upgrade `; a pinned tool stays manual so T3 Code never edits a mise config. The latest version comes from `mise latest`, which applies mise's own settings such as `minimum_release_age`, and is asked only while update checks are on. OpenCode 1.x stays manual because mise's `opencode` follows releases into 2.x. Grok and Muse use the same path, and npm globals under mise's Node stay npm's. Co-authored-by: Claude Opus 5.5 --- .../src/provider/Drivers/CodexDriver.test.ts | 168 ++++++++-- docs/internals/providers.md | 26 +- docs/user/install.md | 11 +- .../src/server/maintenanceResolver.test.ts | 286 ++++++++++++++++++ .../src/server/maintenanceResolver.ts | 181 +++++++++-- .../provider-grok/src/server/driver.test.ts | 59 ++++ packages/provider-grok/src/server/driver.ts | 32 +- packages/provider-muse/src/server/driver.ts | 13 +- .../src/server/maintenance.test.ts | 57 ++++ .../provider-muse/src/server/maintenance.ts | 22 +- .../src/server/driver.test.ts | 59 ++++ .../provider-opencode/src/server/driver.ts | 2 + 12 files changed, 826 insertions(+), 90 deletions(-) diff --git a/apps/server/src/provider/Drivers/CodexDriver.test.ts b/apps/server/src/provider/Drivers/CodexDriver.test.ts index 2ccc555256f5b..53346d049abc6 100644 --- a/apps/server/src/provider/Drivers/CodexDriver.test.ts +++ b/apps/server/src/provider/Drivers/CodexDriver.test.ts @@ -93,6 +93,39 @@ const windowsHost = HostProcess.Platform.defaultValue() === "win32"; const noSpawn = ChildProcessSpawner.make(() => Effect.die("Disabled Codex must not spawn a process"), ); + +/** A finished probe that prints `stdout`, or exits 1 when it has nothing to print. */ +const probeHandle = (stdout: string | null) => + ChildProcessSpawner.makeHandle({ + pid: ChildProcessSpawner.ProcessId(1), + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(stdout === null ? 1 : 0)), + isRunning: Effect.succeed(false), + kill: () => Effect.void, + unref: Effect.succeed(Effect.void), + stdin: Sink.drain, + stdout: Stream.encodeText(Stream.make(stdout ?? "")), + stderr: Stream.empty, + all: Stream.empty, + getInputFd: () => Sink.drain, + getOutputFd: () => Stream.empty, + }); + +/** Lets resolution query only this `mise`, answering `which` and `ls --json --installed`. */ +const miseProbeSpawner = ( + misePath: string, + answers: { readonly which?: string; readonly installed: unknown }, +) => + ChildProcessSpawner.make((command) => + ChildProcess.isStandardCommand(command) && command.command === misePath + ? Effect.succeed( + probeHandle( + command.args[0] === "which" + ? (answers.which ?? null) + : JSON.stringify(answers.installed), + ), + ) + : Effect.die("Codex resolution may only query mise"), + ); const encodeCredentials = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown)); it.layer(layerTest)("CodexDriver", (it) => { @@ -337,24 +370,24 @@ it.layer(layerTest)("CodexDriver", (it) => { for (const fixture of [ { - name: "leaves mise npm-backend installations manual-only", + name: "updates mise npm-backend installations through mise", installSegments: ["mise", "installs", "npm-openai-codex", "0.110.0"], - npmOwned: false, + miseTool: "npm:@openai/codex", }, { - name: "leaves mise tool aliases backed by npm manual-only", + name: "updates mise tool aliases backed by npm through mise", installSegments: ["mise", "installs", "codex", "0.110.0"], - npmOwned: false, + miseTool: "codex", }, { name: "keeps npm updates for globals in a mise Node installation", installSegments: ["mise", "installs", "node", "24.0.0"], - npmOwned: true, + miseTool: null, }, { name: "keeps npm updates for ordinary global installations", installSegments: ["npm-global"], - npmOwned: true, + miseTool: null, }, ] as const) { it.effect.skipIf(windowsHost)(fixture.name, () => @@ -374,26 +407,48 @@ it.layer(layerTest)("CodexDriver", (it) => { "codex.js", ); const binaryPath = NodePath.join(tempDir, "bin", "codex"); - yield* fs.makeDirectory(NodePath.dirname(realBinaryPath), { recursive: true }); + const misePath = NodePath.join(tempDir, "mise-bin", "mise"); + for (const file of [realBinaryPath, misePath]) { + yield* fs.makeDirectory(NodePath.dirname(file), { recursive: true }); + yield* fs.writeFileString(file, "#!/bin/sh\n"); + yield* fs.chmod(file, 0o755); + } yield* fs.makeDirectory(NodePath.dirname(binaryPath), { recursive: true }); - yield* fs.writeFileString(realBinaryPath, "#!/bin/sh\n"); - yield* fs.chmod(realBinaryPath, 0o755); yield* fs.symlink(realBinaryPath, binaryPath); const instance = yield* CodexDriver.create({ instanceId: ProviderInstanceId.make("codex-installer"), displayName: "Codex installer test", enabled: false, - environment: [], + environment: [{ name: "PATH", value: NodePath.dirname(misePath), sensitive: false }], config: { ...CodexDriver.defaultConfig(), binaryPath, homePath: NodePath.join(tempDir, "codex-home"), }, - }); + }).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseProbeSpawner(misePath, { + installed: fixture.miseTool + ? { + [fixture.miseTool]: [ + { install_path: installPath, requested_version: "latest", active: true }, + ], + } + : {}, + }), + ), + ); const update = (yield* instance.snapshot.resolveMaintenance()).update; - if (fixture.npmOwned) { + if (fixture.miseTool) { + expect(update).toMatchObject({ + executable: misePath, + args: ["upgrade", fixture.miseTool], + lockKey: "mise", + }); + } else { expect(update).toMatchObject({ executable: "npm", args: [ @@ -405,8 +460,6 @@ it.layer(layerTest)("CodexDriver", (it) => { "@openai/codex@latest", ], }); - } else { - expect(update).toBeNull(); } }).pipe( Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn), @@ -415,7 +468,61 @@ it.layer(layerTest)("CodexDriver", (it) => { ); } - for (const {} of ["direct", "wrapper"] as const) { + for (const layout of ["direct", "wrapper"] as const) { + it.effect.skipIf(windowsHost)(`updates a mise ${layout} installation through mise`, () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const tempDir = yield* fs + .makeTempDirectoryScoped({ prefix: `t3-codex-mise-${layout}-` }) + .pipe(Effect.flatMap((directory) => fs.realPath(directory))); + const installPath = NodePath.join(tempDir, "mise", "installs", "codex", "0.110.0"); + const installedPath = NodePath.join(installPath, "codex"); + const misePath = NodePath.join(tempDir, "mise-bin", "mise"); + const binaryPath = + layout === "direct" ? installedPath : NodePath.join(tempDir, "omarchy", "bin", "codex"); + for (const file of [installedPath, misePath, binaryPath]) { + yield* fs.makeDirectory(NodePath.dirname(file), { recursive: true }); + yield* fs.writeFileString( + file, + file === binaryPath && layout === "wrapper" + ? '#!/bin/sh\nmise use -g --quiet "codex" || exit 1\nexec mise x "codex" -- "codex" "$@"\n' + : "#!/bin/sh\n", + ); + yield* fs.chmod(file, 0o755); + } + + const instance = yield* CodexDriver.create({ + instanceId: ProviderInstanceId.make(`codex-mise-${layout}`), + displayName: "Codex mise test", + enabled: false, + environment: [{ name: "PATH", value: NodePath.dirname(misePath), sensitive: false }], + config: { + ...CodexDriver.defaultConfig(), + binaryPath, + homePath: NodePath.join(tempDir, "codex-home"), + }, + }).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseProbeSpawner(misePath, { + which: installedPath, + installed: { + codex: [{ install_path: installPath, requested_version: "latest", active: true }], + }, + }), + ), + ); + + expect((yield* instance.snapshot.resolveMaintenance()).update).toMatchObject({ + command: "mise upgrade codex", + executable: misePath, + lockKey: "mise", + }); + }).pipe( + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn), + Effect.scoped, + ), + ); } it.effect.each([ @@ -492,28 +599,23 @@ it.layer(layerTest)("CodexDriver", (it) => { ].join(NodePath.delimiter); const probes: Array> = []; const metadataSpawner = ChildProcessSpawner.make((command) => { - if (!ChildProcess.isStandardCommand(command) || command.command !== brewPath) { + if (!ChildProcess.isStandardCommand(command)) { + return Effect.die("Provider resolution must not execute a provider or updater"); + } + // The shim asks its own mise, which has no Codex, so ownership stays unproven. + if (command.command === misePath) { + return Effect.succeed(probeHandle(null)); + } + if (command.command !== brewPath) { return Effect.die("Provider resolution must not execute a provider or updater"); } probes.push(command.args); - const stdout = - command.args[0] === "--prefix" - ? brewPrefix - : JSON.stringify({ formulae: [{ versions: { stable: "2026.9.1" } }] }); return Effect.succeed( - ChildProcessSpawner.makeHandle({ - pid: ChildProcessSpawner.ProcessId(1), - exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)), - isRunning: Effect.succeed(false), - kill: () => Effect.void, - unref: Effect.succeed(Effect.void), - stdin: Sink.drain, - stdout: Stream.encodeText(Stream.make(stdout)), - stderr: Stream.empty, - all: Stream.empty, - getInputFd: () => Sink.drain, - getOutputFd: () => Stream.empty, - }), + probeHandle( + command.args[0] === "--prefix" + ? brewPrefix + : JSON.stringify({ formulae: [{ versions: { stable: "2026.9.1" } }] }), + ), ); }); const instance = yield* CodexDriver.create({ diff --git a/docs/internals/providers.md b/docs/internals/providers.md index 4121a349dcbf8..64ddd6be69ff6 100644 --- a/docs/internals/providers.md +++ b/docs/internals/providers.md @@ -88,13 +88,25 @@ either the resolved path or its real target, since those installers place real f symlinks there. Volta is proven by its `volta-shim` link plus the package's image directory. When nothing is proven, the provider's own updater (`claude update`, `codex update`, `opencode upgrade`, `pi update --self`, `grok update`) runs instead, because each one detects its installer itself; -the runner's version check catches an updater that exits 0 without updating. Mise installs stay -manual-only because their version is pinned in mise's config. A Grok cask whose Homebrew prefix -cannot be verified also stays manual-only: `grok update` would install a second copy. npm updates pin `--prefix` because the -`npm` on `PATH` can belong to a different Node than the one that owns the provider. Homebrew -compares against `brew info` since casks trail npm by hours; native installs share npm's version -train, so the registry stays authoritative for them. -See the [resolver](../../apps/server/src/provider/providerMaintenance.ts). +the runner's version check catches an updater that exits 0 without updating. A Grok cask whose +Homebrew prefix cannot be verified stays manual-only: `grok update` would install a second copy. +npm updates pin `--prefix` because the `npm` on `PATH` can belong to a different Node than the one +that owns the provider. Homebrew compares against `brew info` since casks trail npm by hours; native +installs share npm's version train, so the registry stays authoritative for them. + +Mise is checked before everything else, because Omarchy's `mise x` wrappers sit at native installer +paths such as `~/.local/bin/claude`. A binary under `mise/installs/`, a shim (a link to mise itself, +under any data directory), or a `mise x` wrapper is only a hint. Mise proves ownership: `mise which` +resolves shims and wrappers, and `mise ls --json --installed` must list an active install that +contains the binary. That listing also names the tool, which install paths cannot (`npm:@scope/pkg` +lives in `npm-scope-pkg`). Only a tool requested as `latest` gets `mise upgrade `, run with +the instance environment the probe used. Like Homebrew, its latest version comes from the installer: +`mise latest ` applies mise's settings, such as `minimum_release_age`, which npm's registry +cannot. Mise may go to the network for that answer, so it is asked lazily through +`lookupLatestVersion` and never while update checks are off. A pinned tool stays manual-only, so T3 +Code never edits a mise config. OpenCode 1.x stays manual too, since mise's `opencode` follows +releases into 2.x. npm globals under mise's own Node remain npm's. See the +[resolver](../../packages/provider-core/src/server/maintenanceResolver.ts). Ownership is cached per instance and re-read immediately before an update runs. The [runner](../../apps/server/src/provider/providerMaintenanceRunner.ts) refuses when the lock key diff --git a/docs/user/install.md b/docs/user/install.md index 59c8648934ca4..a7da207d18e83 100644 --- a/docs/user/install.md +++ b/docs/user/install.md @@ -159,9 +159,14 @@ on the environment's machine. An unlisted version is unverified. When a provider CLI is behind its latest release, its provider card shows the available version. **Update now** runs the installer that owns the CLI -(Homebrew, or a global npm, pnpm, Yarn, Bun, Volta, or Vite+ install), or the -CLI's own update command when T3 Code cannot tell. Update a CLI installed with -mise through mise. Cursor and Antigravity update with T3 Code. Homebrew installs +(Homebrew, mise, or a global npm, pnpm, Yarn, Bun, Volta, or Vite+ install), or +the CLI's own update command when T3 Code cannot tell. For mise, T3 Code runs +`mise upgrade` only for a tool your mise config requests as `latest`. It never +edits your mise config, so update a pinned version, or OpenCode 1.x, through +mise yourself. T3 Code offers the version mise would install, so a release that +mise holds back, such as one newer than your `minimum_release_age`, appears once +mise allows it. +Cursor and Antigravity update with T3 Code. Homebrew installs compare against the version Homebrew offers, which can trail the npm release by a few hours. diff --git a/packages/provider-core/src/server/maintenanceResolver.test.ts b/packages/provider-core/src/server/maintenanceResolver.test.ts index cbb24818eb550..5a64030f7ae73 100644 --- a/packages/provider-core/src/server/maintenanceResolver.test.ts +++ b/packages/provider-core/src/server/maintenanceResolver.test.ts @@ -24,6 +24,7 @@ import { makeCachedProviderMaintenanceResolution, makePackageManagedProviderMaintenanceResolver, makeProviderMaintenanceCapabilities, + miseOwnerFromInstalledTools, normalizeCommandPath, npmGlobalPrefixFromCommandPath, parseHomebrewLatestVersion, @@ -99,6 +100,19 @@ const noSpawn = ChildProcessSpawner.make(() => Effect.die("maintenance resolution should not spawn a process here"), ); +/** A `mise` that answers `which`, `latest`, and `ls --json --installed`, recording each call. */ +function miseSpawner( + answers: { readonly which?: string; readonly latest?: string; readonly installed: unknown }, + spawned: Array>, +) { + return stdoutSpawner((command, args) => { + spawned.push([command, ...args]); + if (args[0] === "which") return `${answers.which ?? ""}\n`; + if (args[0] === "latest") return `${answers.latest ?? ""}\n`; + return JSON.stringify(answers.installed); + }); +} + function stdoutSpawner( onSpawn: (command: string, args: ReadonlyArray) => string, exitCodeOf: (args: ReadonlyArray) => number = () => 0, @@ -1065,6 +1079,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { lockKey: "packageTool-native", }); + // A mise install belongs to mise, so the provider's updater never runs on it. const misePath = NodePath.join(tempDir, "mise", "installs", "package-tool", "1.0.0", "bin"); writeExecutable(NodePath.join(misePath, "package-tool")); const mise = yield* resolveProviderMaintenanceCapabilitiesEffect(selfUpdating, { @@ -1075,6 +1090,277 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { }), ); + it("names the active mise tool whose install holds the binary", () => { + const installed = JSON.stringify({ + codex: [ + { install_path: "/m/installs/codex/0.9.0", requested_version: null, active: false }, + { install_path: "/m/installs/codex/0.1", requested_version: "latest", active: true }, + ], + "npm:@example/package-tool": [ + { + install_path: "/m/installs/npm-example-package-tool/1.0.0", + requested_version: "1.0.0", + active: true, + }, + ], + }); + expect(miseOwnerFromInstalledTools(installed, "/m/installs/codex/0.1/bin/codex")).toEqual({ + tool: "codex", + requestedVersion: "latest", + }); + expect( + miseOwnerFromInstalledTools( + installed, + "/m/installs/npm-example-package-tool/1.0.0/node_modules/.bin/package-tool", + ), + ).toEqual({ tool: "npm:@example/package-tool", requestedVersion: "1.0.0" }); + // `mise upgrade` moves only the active install, and `0.1` does not own `0.10`. + expect(miseOwnerFromInstalledTools(installed, "/m/installs/codex/0.9.0/codex")).toBeNull(); + expect(miseOwnerFromInstalledTools(installed, "/m/installs/codex/0.10/codex")).toBeNull(); + expect(miseOwnerFromInstalledTools("not json", "/m/installs/codex/0.1/codex")).toBeNull(); + }); + + it.effect.skipIf(windowsHost)("upgrades a mise tool requested as latest through mise", () => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-install"); + const miseBinDir = NodePath.join(tempDir, "mise-bin"); + const misePath = NodePath.join(miseBinDir, "mise"); + writeExecutable(misePath); + const installPath = NodePath.join( + tempDir, + "mise", + "installs", + "npm-example-package-tool", + "1.0.0", + ); + const binaryPath = NodePath.join(installPath, "node_modules", ".bin", "package-tool"); + writeExecutable(binaryPath); + const env = { PATH: miseBinDir }; + const spawned: Array> = []; + + const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, { + binaryPath, + env, + }).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner( + { + // `minimum_release_age` holds mise at 1.0.0 while npm has 1.2.0. + latest: "1.0.0", + installed: { + "npm:@example/package-tool": [ + { install_path: installPath, requested_version: "latest", active: true }, + ], + }, + }, + spawned, + ), + ), + ); + + expect(spawned).toEqual([[misePath, "ls", "--json", "--installed"]]); + expect(capabilities.update).toEqual({ + command: "mise upgrade npm:@example/package-tool", + executable: misePath, + args: ["upgrade", "npm:@example/package-tool"], + lockKey: "mise", + env, + }); + expect(makeTargetedProviderUpdateAction(capabilities, "2.0.0")).toBeNull(); + + const advise = (enableProviderUpdateChecks: boolean) => + enrichProviderSnapshotWithVersionAdvisory(installedPackageToolProvider, capabilities, { + enableProviderUpdateChecks, + }).pipe( + Effect.provideServiceEffect( + ProviderLatestVersions.ProviderLatestVersions, + ProviderLatestVersions.make([["@example/package-tool", "1.2.0"]]), + ), + Effect.provideService( + HttpClient.HttpClient, + HttpClient.make(() => Effect.die("mise answers for its own installs")), + ), + ); + // Disabled update checks never ask mise, which may go to the network. + expect((yield* advise(false)).versionAdvisory?.latestVersion).toBeNull(); + expect(spawned).toHaveLength(1); + // The advisory offers what `mise upgrade` installs, not npm's newer release. + expect((yield* advise(true)).versionAdvisory).toMatchObject({ + status: "current", + latestVersion: "1.0.0", + }); + expect(spawned.at(-1)).toEqual([misePath, "latest", "npm:@example/package-tool"]); + }), + ); + + it.effect.each([ + { name: "a pinned version", requestedVersion: "1.0.0", active: true, misePresent: true }, + { name: "an inactive install", requestedVersion: "latest", active: false, misePresent: true }, + { + name: "an install mise cannot vouch for", + requestedVersion: "latest", + active: true, + misePresent: false, + }, + ])( + "leaves $name manual-only", + (fixture) => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-manual"); + const miseBinDir = NodePath.join(tempDir, "mise-bin"); + if (fixture.misePresent) { + writeExecutable(NodePath.join(miseBinDir, "mise")); + } + const installPath = NodePath.join(tempDir, "mise", "installs", "package-tool", "1.0.0"); + const binaryPath = NodePath.join(installPath, "bin", "package-tool"); + writeExecutable(binaryPath); + + const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect( + packageToolUpdate, + { binaryPath, env: { PATH: miseBinDir } }, + ).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner( + { + installed: { + "package-tool": [ + { + install_path: installPath, + requested_version: fixture.requestedVersion, + active: fixture.active, + }, + ], + }, + }, + [], + ), + ), + ); + + // The manual advisory names the executable to update. + expect(capabilities).toEqual({ ...manualPackageTool, installPath: binaryPath }); + }), + { skip: windowsHost }, + ); + + it.effect.skipIf(!symlinksSupported || windowsHost)( + "upgrades a mise wrapper at the native installer's path through mise", + () => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-wrapper"); + const miseBinDir = NodePath.join(tempDir, "mise-bin"); + const misePath = NodePath.join(miseBinDir, "mise"); + writeExecutable(misePath); + const toolDir = NodePath.join(tempDir, "mise", "installs", "native-package-tool"); + const installPath = NodePath.join(toolDir, "2.0.0"); + writeExecutable(NodePath.join(installPath, "native-package-tool")); + NodeFS.symlinkSync(installPath, NodePath.join(toolDir, "latest")); + // Omarchy's lazy installer, written where the native installer links its binary. + const wrapperPath = NodePath.join(tempDir, ".local", "bin", "native-package-tool"); + NodeFS.mkdirSync(NodePath.dirname(wrapperPath), { recursive: true }); + NodeFS.writeFileSync( + wrapperPath, + '#!/bin/sh\nmise use -g --quiet "native-package-tool" || exit 1\nexec mise x "native-package-tool" -- "native-package-tool" "$@"\n', + ); + NodeFS.chmodSync(wrapperPath, 0o755); + const resolve = resolveProviderMaintenanceCapabilitiesEffect(nativePackageToolUpdate, { + binaryPath: wrapperPath, + env: { PATH: miseBinDir }, + }); + const spawned: Array> = []; + + const capabilities = yield* resolve.pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner( + { + which: NodePath.join(toolDir, "latest", "native-package-tool"), + installed: { + "native-package-tool": [ + { install_path: installPath, requested_version: "latest", active: true }, + ], + }, + }, + spawned, + ), + ), + ); + + expect(spawned).toEqual([ + [misePath, "which", "native-package-tool"], + [misePath, "ls", "--json", "--installed"], + ]); + expect(capabilities.update).toMatchObject({ + command: "mise upgrade native-package-tool", + executable: misePath, + lockKey: "mise", + }); + + // A comment that mentions mise does not hand a native launcher to mise. + NodeFS.writeFileSync( + wrapperPath, + '#!/bin/sh\n# Alternative: mise exec other-tool -- tool\nexec /opt/native-package-tool "$@"\n', + ); + const native = yield* resolve.pipe( + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn), + ); + expect(native.update).toMatchObject({ lockKey: "nativePackageTool-native" }); + }), + ); + + it.effect.skipIf(!symlinksSupported || windowsHost)( + "upgrades a shim through the mise it links to, whatever mise's data directory", + () => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-shim"); + const misePath = NodePath.join(tempDir, "opt", "bin", "mise"); + writeExecutable(misePath); + const shimPath = NodePath.join(tempDir, "tool-data", "shims", "package-tool"); + NodeFS.mkdirSync(NodePath.dirname(shimPath), { recursive: true }); + NodeFS.symlinkSync(misePath, shimPath); + const installPath = NodePath.join( + tempDir, + "tool-data", + "installs", + "package-tool", + "1.2.0", + ); + const binaryPath = NodePath.join(installPath, "bin", "package-tool"); + writeExecutable(binaryPath); + const spawned: Array> = []; + + // mise is not on PATH; the shim's own target is the mise to run. + const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect( + packageToolUpdate, + { binaryPath: shimPath, env: { PATH: "" } }, + ).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner( + { + which: binaryPath, + installed: { + "package-tool": [ + { install_path: installPath, requested_version: "latest", active: true }, + ], + }, + }, + spawned, + ), + ), + ); + + expect(spawned[0]).toEqual([misePath, "which", "package-tool"]); + expect(capabilities.update).toMatchObject({ + executable: misePath, + args: ["upgrade", "package-tool"], + lockKey: "mise", + }); + }), + ); + it.effect.skipIf(!symlinksSupported)("updates Yarn global installs with yarn", () => Effect.gen(function* () { const tempDir = yield* makeTempDir("t3-yarn-capabilities"); diff --git a/packages/provider-core/src/server/maintenanceResolver.ts b/packages/provider-core/src/server/maintenanceResolver.ts index ed3967ebb4654..9eaf86b2bc971 100644 --- a/packages/provider-core/src/server/maintenanceResolver.ts +++ b/packages/provider-core/src/server/maintenanceResolver.ts @@ -87,6 +87,12 @@ export interface PackageManagedProviderMaintenanceDefinition { readonly isCommandPath?: (commandPath: string) => boolean; readonly env?: NodeJS.ProcessEnv; } | null; + /** + * `mise upgrade` installs the newest release mise knows, which can cross a + * line T3 Code must not: mise's OpenCode tool carries 1.x and 2.x. False keeps + * mise installs manual-only. + */ + readonly miseUpgrade?: boolean; } const NpmLatestVersionResponse = Schema.Struct({ @@ -230,12 +236,6 @@ function isYarnGlobalCommandPath(commandPath: string): boolean { return /\/yarn\/(?:data\/)?global\/node_modules\//.test(normalizeCommandPath(commandPath)); } -/** Version-manager installs are pinned in its config, so updating them means editing that. */ -function isMiseCommandPath(commandPath: string): boolean { - const normalized = normalizeCommandPath(commandPath); - return normalized.includes("/mise/installs/") || normalized.includes("/mise/shims/"); -} - /** * WinGet's Claude Code install under its user root (`:\Users\\AppData\Local\Microsoft\WinGet`) * or machine root (`:\Program Files\WinGet`): the `Links\claude.exe` link or the binary in the @@ -422,6 +422,142 @@ const resolvePnpmGlobalLatestVersion = Effect.fn("resolvePnpmGlobalLatestVersion return nonEmptyString(listedEntries?.[0]?.dependencies?.[packageName]?.version); }); +const MiseInstalledTools = Schema.Record( + Schema.String, + Schema.Array( + Schema.Struct({ + install_path: Schema.String, + requested_version: Schema.optional(Schema.NullOr(Schema.String)), + active: Schema.optional(Schema.Boolean), + }), + ), +); + +const decodeMiseInstalledTools = Schema.decodeUnknownOption( + Schema.fromJsonString(MiseInstalledTools), +); + +/** + * The active mise tool whose install directory holds `binaryPath`, read from + * `mise ls --json --installed`. Mise's tool names are not recoverable from + * install paths (`npm:@scope/pkg` lives in `npm-scope-pkg`), so mise names it. + */ +export function miseOwnerFromInstalledTools( + listing: string, + binaryPath: string, +): { readonly tool: string; readonly requestedVersion: string | null } | null { + const decoded = decodeMiseInstalledTools(listing); + if (Option.isNone(decoded)) { + return null; + } + const binary = normalizeCommandPath(binaryPath); + for (const [tool, installs] of Object.entries(decoded.value)) { + const owner = installs.find( + (install) => + install.active === true && + binary.startsWith(`${normalizeCommandPath(install.install_path).replace(/\/+$/, "")}/`), + ); + if (owner) { + return { tool, requestedVersion: owner.requested_version ?? null }; + } + } + return null; +} + +/** + * Mise owns an executable in its install tree, one of its shims (a link to + * mise itself), or a wrapper that runs the tool through `mise x`. Ownership is + * proven by mise: the binary must sit in the install of a tool active in mise's + * config. Only a tool requested as `latest` gets `mise upgrade`; a pinned + * version is the user's choice, so T3 Code never edits a mise config and the + * install stays manual. Returns null when mise does not manage the executable, + * including npm globals under mise's Node, which npm owns. + */ +export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMaintenance")( + function* ( + owner: { readonly provider: ProviderDriverKind; readonly packageName: string | null }, + context: ProviderMaintenanceResolutionContext, + ) { + const path = yield* Path.Path; + const resolvedPath = normalizeCommandPath(context.resolvedCommandPath); + const realPath = normalizeCommandPath(context.realCommandPath); + if ( + resolvedPath.includes("/mise/installs/node/") || + realPath.includes("/mise/installs/node/") + ) { + return null; + } + const isInstall = realPath.includes("/mise/installs/"); + // A shim is a link to mise itself, wherever mise keeps its data. + const isShim = path.basename(realPath).replace(/\.exe$/, "") === "mise"; + if ( + !isInstall && + !isShim && + !resolvedPath.includes("/mise/shims/") && + !(yield* isMiseWrapperScript(context)) + ) { + return null; + } + + const misePath = isShim + ? context.realCommandPath + : yield* resolveCommandPath("mise", { env: context.env }); + if (!misePath) { + return makeManualOnlyProviderMaintenanceCapabilities({ + ...owner, + installPath: context.realCommandPath, + }); + } + // A shim or wrapper runs whatever mise resolves for the command's name. + const commandName = path + .basename(context.resolvedCommandPath) + .replace(/\.(?:exe|cmd|bat|ps1)$/i, ""); + const which = isInstall + ? null + : nonEmptyString(yield* runProbe(misePath, ["which", commandName], context.env)); + const fileSystem = yield* FileSystem.FileSystem; + const binaryPath = isInstall + ? context.realCommandPath + : which + ? yield* fileSystem.realPath(which).pipe(Effect.orElseSucceed(() => null)) + : null; + const listing = binaryPath + ? yield* runProbe(misePath, ["ls", "--json", "--installed"], context.env) + : null; + const tool = listing && binaryPath ? miseOwnerFromInstalledTools(listing, binaryPath) : null; + // A shim can also lead to an npm global under mise's Node, whose prefix it does not prove. + if (!tool || tool.tool === "node" || tool.requestedVersion !== "latest") { + // A shim's own path is mise; name the binary it runs. + return makeManualOnlyProviderMaintenanceCapabilities({ + ...owner, + installPath: binaryPath ?? context.realCommandPath, + }); + } + const args = ["upgrade", tool.tool]; + const services = yield* Effect.context(); + return makeProviderMaintenanceCapabilities({ + provider: owner.provider, + packageName: owner.packageName, + updateExecutable: misePath, + updateArgs: args, + updateLockKey: "mise", + updateCommand: ["mise", ...args.map((arg) => quoteShellWord(arg, context.platform))].join( + " ", + ), + platform: context.platform, + // `mise ls` answered for this environment, so the upgrade runs in it too. + env: context.env, + // Mise settings such as `minimum_release_age` can hold `mise upgrade` + // behind the npm registry, so only mise can say what it installs. + latestVersion: null, + lookupLatestVersion: runProbe(misePath, ["latest", tool.tool], context.env).pipe( + Effect.map(nonEmptyString), + Effect.provideContext(services), + ), + }); + }, +); + export const resolvePackageManagedProviderMaintenance = Effect.fn( "resolvePackageManagedProviderMaintenance", )(function* ( @@ -451,6 +587,16 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn( return manual; } + // Mise goes first: Omarchy's `mise x` wrapper for claude sits at + // `~/.local/bin/claude`, the native installer's path. + const mise = yield* resolveMiseProviderMaintenance( + { provider: definition.provider, packageName }, + context, + ); + if (mise) { + return definition.miseUpgrade === false ? manual : mise; + } + const nativeUpdate = definition.nativeUpdate; const native = nativeUpdate ? makeProviderMaintenanceCapabilities({ @@ -463,13 +609,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn( ...(nativeUpdate.env ? { env: nativeUpdate.env } : {}), }) : manual; - // A native-looking launcher can still delegate to a mise-owned install. - if ( - nativeUpdate?.isCommandPath && - commandPaths.some(nativeUpdate.isCommandPath) && - !commandPaths.some(isMiseCommandPath) && - !(yield* isMiseWrapperScript(context)) - ) { + if (nativeUpdate?.isCommandPath && commandPaths.some(nativeUpdate.isCommandPath)) { return native; } // A `node_modules` path not proven below belongs to another package or a @@ -566,14 +706,6 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn( } const homebrew = homebrewOwnershipFromCommandPath(context.realCommandPath); - if ( - commandPaths.some(isMiseCommandPath) || - // Mise shims resolve to the version manager's keg, not the provider's. - (homebrew?.kind === "formula" && homebrew.name.toLowerCase() === "mise") || - (yield* isMiseWrapperScript(context)) - ) { - return manual; - } if (homebrew) { return ( (yield* resolveHomebrewProviderMaintenance( @@ -657,7 +789,12 @@ const isMiseWrapperScript = Effect.fn("isMiseWrapperScript")(function* ( const script = yield* fileSystem .readFileString(context.realCommandPath) .pipe(Effect.orElseSucceed(() => "")); - return script.startsWith("#!") && /\bmise\s+(?:x|exec)\b/.test(script); + return ( + script.startsWith("#!") && + script + .split("\n") + .some((line) => !line.trimStart().startsWith("#") && /\bmise\s+(?:x|exec)\b/.test(line)) + ); }); /** diff --git a/packages/provider-grok/src/server/driver.test.ts b/packages/provider-grok/src/server/driver.test.ts index 958dcdfa545b0..77963ea2212fa 100644 --- a/packages/provider-grok/src/server/driver.test.ts +++ b/packages/provider-grok/src/server/driver.test.ts @@ -9,6 +9,7 @@ import * as Path from "effect/Path"; import * as Sink from "effect/Sink"; import * as Stream from "effect/Stream"; import * as HttpClient from "effect/http/HttpClient"; +import * as ChildProcess from "effect/process/ChildProcess"; import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions"; @@ -170,6 +171,64 @@ it.layer(layerTest)("GrokDriver", (it) => { }); } + it.effect.skipIf(windowsHost)("updates a mise install through mise, not grok update", () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const tempDir = yield* fs + .makeTempDirectoryScoped({ prefix: "t3-grok-mise-" }) + .pipe(Effect.flatMap((directory) => fs.realPath(directory))); + const installPath = path.join(tempDir, "mise", "installs", "grok", "1.0.50"); + const binaryPath = path.join(installPath, "grok"); + const misePath = path.join(tempDir, "mise-bin", "mise"); + for (const file of [binaryPath, misePath]) { + yield* fs.makeDirectory(path.dirname(file), { recursive: true }); + yield* fs.writeFileString(file, "#!/bin/sh\n"); + yield* fs.chmod(file, 0o755); + } + const installed = JSON.stringify({ + grok: [{ install_path: installPath, requested_version: "latest", active: true }], + }); + const miseSpawner = ChildProcessSpawner.make((command) => + ChildProcess.isStandardCommand(command) && command.command === misePath + ? Effect.succeed( + ChildProcessSpawner.makeHandle({ + pid: ChildProcessSpawner.ProcessId(1), + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)), + isRunning: Effect.succeed(false), + kill: () => Effect.void, + unref: Effect.succeed(Effect.void), + stdin: Sink.drain, + stdout: Stream.encodeText(Stream.make(installed)), + stderr: Stream.empty, + all: Stream.empty, + getInputFd: () => Sink.drain, + getOutputFd: () => Stream.empty, + }), + ) + : Effect.die("Grok resolution may only query mise"), + ); + + const instance = yield* GrokDriver.create({ + instanceId: ProviderInstanceId.make("grok-mise"), + displayName: "Grok test", + enabled: false, + environment: [{ name: "PATH", value: path.dirname(misePath), sensitive: false }], + config: { ...GrokDriver.defaultConfig(), binaryPath }, + }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, miseSpawner)); + + expect((yield* instance.snapshot.resolveMaintenance()).update).toMatchObject({ + command: "mise upgrade grok", + executable: misePath, + args: ["upgrade", "grok"], + lockKey: "mise", + }); + }).pipe( + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawner), + Effect.scoped, + ), + ); + it.effect("stays manual-only when the configured executable does not exist", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; diff --git a/packages/provider-grok/src/server/driver.ts b/packages/provider-grok/src/server/driver.ts index 0c9cfe62f18ca..7192880fcb7cb 100644 --- a/packages/provider-grok/src/server/driver.ts +++ b/packages/provider-grok/src/server/driver.ts @@ -37,6 +37,7 @@ import { makeProviderMaintenanceCapabilities, type ProviderMaintenanceCapabilitiesResolver, resolveHomebrewProviderMaintenance, + resolveMiseProviderMaintenance, resolveProviderMaintenanceCapabilitiesEffect, } from "@t3tools/provider-core/server/maintenanceResolver"; import { @@ -51,37 +52,34 @@ const DRIVER_KIND = ProviderDriverKind.make("grok"); // by default, so the registry stays the source for "latest". const GROK_NPM_PACKAGE = "@xai-official/grok"; // `grok update` finds the installer that owns the binary itself, so the -// resolved executable is its own updater. It installs under `GROK_HOME`, so it -// runs with the instance's environment. The exception is a Homebrew cask -// (normally `grok-build`), which brew upgrades and versions: `grok update` would install -// a second copy beside it, so a cask its brew cannot vouch for stays manual. +// resolved executable is its own updater, unless mise owns it. It installs +// under `GROK_HOME`, so it runs with the instance's environment. A Homebrew cask +// (normally `grok-build`) is the other exception, which brew upgrades and +// versions: `grok update` would install a second copy beside it, so a cask its +// brew cannot vouch for stays manual. const UPDATE: ProviderMaintenanceCapabilitiesResolver = { resolve: Effect.fn("resolveGrokMaintenance")(function* (context) { + const owner = { provider: DRIVER_KIND, packageName: GROK_NPM_PACKAGE }; if (!context) { - return makeManualOnlyProviderMaintenanceCapabilities({ - provider: DRIVER_KIND, - packageName: GROK_NPM_PACKAGE, - }); + return makeManualOnlyProviderMaintenanceCapabilities(owner); + } + const mise = yield* resolveMiseProviderMaintenance(owner, context); + if (mise) { + return mise; } const homebrew = homebrewOwnershipFromCommandPath(context.realCommandPath); // Only a cask is Grok's: a formula keg such as `node` holding an npm global is not. if (homebrew?.kind === "cask") { return ( - (yield* resolveHomebrewProviderMaintenance( - { provider: DRIVER_KIND, packageName: GROK_NPM_PACKAGE }, - homebrew, - context, - )) ?? + (yield* resolveHomebrewProviderMaintenance(owner, homebrew, context)) ?? makeManualOnlyProviderMaintenanceCapabilities({ - provider: DRIVER_KIND, - packageName: GROK_NPM_PACKAGE, + ...owner, installPath: context.realCommandPath, }) ); } return makeProviderMaintenanceCapabilities({ - provider: DRIVER_KIND, - packageName: GROK_NPM_PACKAGE, + ...owner, updateExecutable: context.resolvedCommandPath, updateArgs: ["update"], updateLockKey: "grok", diff --git a/packages/provider-muse/src/server/driver.ts b/packages/provider-muse/src/server/driver.ts index 9a39487a5a2f6..8ece743d425cf 100644 --- a/packages/provider-muse/src/server/driver.ts +++ b/packages/provider-muse/src/server/driver.ts @@ -114,12 +114,13 @@ export const MuseDriver: ProviderDriver = { const capabilities = yield* resolveInstallation(options); // The maintenance runner requests fresh capabilities around an explicit update // and needs the native target version to verify that the command actually upgraded. - const latestVersion = options?.fresh - ? yield* latestMuseVersion(processEnvironment, { fresh: true }).pipe( - Effect.provideService(HttpClient.HttpClient, httpClient), - Effect.provideService(ProviderLatestVersions.ProviderLatestVersions, latestVersions), - ) - : undefined; + const latestVersion = + options?.fresh && !capabilities.lookupLatestVersion + ? yield* latestMuseVersion(processEnvironment, { fresh: true }).pipe( + Effect.provideService(HttpClient.HttpClient, httpClient), + Effect.provideService(ProviderLatestVersions.ProviderLatestVersions, latestVersions), + ) + : undefined; return latestVersion !== undefined ? { ...capabilities, latestVersion } : capabilities; }); const snapshot = yield* makeManagedServerProvider>({ diff --git a/packages/provider-muse/src/server/maintenance.test.ts b/packages/provider-muse/src/server/maintenance.test.ts index 61b1a9fc32f28..6b2fd52615f91 100644 --- a/packages/provider-muse/src/server/maintenance.test.ts +++ b/packages/provider-muse/src/server/maintenance.test.ts @@ -1,6 +1,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices"; import { expect, it } from "@effect/vitest"; import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts"; +import * as HostProcess from "@t3tools/shared/HostProcess"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as HttpClient from "effect/http/HttpClient"; @@ -116,4 +117,60 @@ it.layer(NodeServices.layer)("Muse maintenance", (it) => { }), ), ); + + it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")( + "updates a mise install through mise and offers the version mise would install", + () => + Effect.scoped( + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const directory = yield* fs.makeTempDirectoryScoped({ prefix: "muse-mise-" }); + const installPath = `${directory}/mise/installs/muse/1.4.9-R6000.1`; + const binaryPath = `${installPath}/muse`; + const misePath = `${directory}/bin/mise`; + yield* fs.makeDirectory(installPath, { recursive: true }); + yield* fs.makeDirectory(`${directory}/bin`); + yield* fs.writeFileString(binaryPath, "standalone binary"); + const installed = JSON.stringify({ + muse: [{ install_path: installPath, requested_version: "latest", active: true }], + }); + yield* fs.writeFileString( + misePath, + `#!/bin/sh\ncase "$1" in\n ls) echo '${installed}' ;;\n latest) echo 1.4.10-R6427.1 ;;\n *) exit 1 ;;\nesac\n`, + ); + yield* fs.chmod(misePath, 0o755); + const capabilities = yield* museMaintenance.resolve({ + binaryPath, + resolvedCommandPath: binaryPath, + realCommandPath: binaryPath, + platform: "linux", + env: { PATH: `${directory}/bin` }, + }); + expect(capabilities.update).toMatchObject({ + command: "mise upgrade muse", + executable: misePath, + args: ["upgrade", "muse"], + }); + expect(capabilities.compareVersions).toBe(compareMuseVersions); + + const result = yield* enrichMuseSnapshot({ + snapshot: { ...snapshot, version: "1.4.9-R6000.1" }, + maintenanceCapabilities: capabilities, + enableProviderUpdateChecks: true, + environment: {}, + }).pipe( + Effect.provide(ProviderLatestVersions.layer), + Effect.provideService( + HttpClient.HttpClient, + HttpClient.make(() => Effect.die("Unexpected channel request")), + ), + ); + expect(result.versionAdvisory).toMatchObject({ + status: "behind_latest", + latestVersion: "1.4.10-R6427.1", + canUpdate: true, + }); + }), + ), + ); }); diff --git a/packages/provider-muse/src/server/maintenance.ts b/packages/provider-muse/src/server/maintenance.ts index 0a3a59de128e8..653d1e173a028 100644 --- a/packages/provider-muse/src/server/maintenance.ts +++ b/packages/provider-muse/src/server/maintenance.ts @@ -12,6 +12,7 @@ import { makeProviderMaintenanceCapabilities, type ProviderMaintenanceCapabilities, type ProviderMaintenanceCapabilitiesResolver, + resolveMiseProviderMaintenance, } from "@t3tools/provider-core/server/maintenanceResolver"; import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions"; import { parseGenericCliVersion } from "@t3tools/provider-core/server/snapshotProbe"; @@ -37,7 +38,10 @@ export const compareMuseVersions = (current: string, latest: string) => ? compareSemverVersions(comparableMuseVersion(current), comparableMuseVersion(latest)) : compareSemverVersions(current.replace(MUSE_REVISION, ""), latest.replace(MUSE_REVISION, "")); -/** Only the official launcher owns an update channel; a standalone binary cannot update itself. */ +/** + * Mise updates a binary it installed. Otherwise only the official launcher owns + * an update channel; a standalone binary cannot update itself. + */ export const museMaintenance: ProviderMaintenanceCapabilitiesResolver = { resolve: Effect.fn("MuseMaintenance.resolve")(function* (context) { const manual = { @@ -45,6 +49,11 @@ export const museMaintenance: ProviderMaintenanceCapabilitiesResolver = { compareVersions: compareMuseVersions, }; if (!context || context.platform === "win32") return manual; + const mise = yield* resolveMiseProviderMaintenance( + { provider: DRIVER, packageName: null }, + context, + ); + if (mise) return { ...mise, compareVersions: compareMuseVersions }; const fs = yield* FileSystem.FileSystem; const isLauncher = yield* Effect.gen(function* () { const stat = yield* fs.stat(context.realCommandPath); @@ -119,6 +128,15 @@ export const enrichMuseSnapshot = Effect.fn("enrichMuseSnapshot")(function* (inp readonly environment: NodeJS.ProcessEnv; }) { const { snapshot } = input; + const options = { enableProviderUpdateChecks: input.enableProviderUpdateChecks }; + // Mise names the version it would install itself. + if (input.maintenanceCapabilities.lookupLatestVersion) { + return yield* enrichProviderSnapshotWithVersionAdvisory( + snapshot, + input.maintenanceCapabilities, + options, + ); + } const latestVersion = input.enableProviderUpdateChecks && snapshot.enabled && snapshot.installed && snapshot.version ? yield* latestMuseVersion(input.environment) @@ -126,6 +144,6 @@ export const enrichMuseSnapshot = Effect.fn("enrichMuseSnapshot")(function* (inp return yield* enrichProviderSnapshotWithVersionAdvisory( snapshot, { ...input.maintenanceCapabilities, latestVersion }, - { enableProviderUpdateChecks: input.enableProviderUpdateChecks }, + options, ); }); diff --git a/packages/provider-opencode/src/server/driver.test.ts b/packages/provider-opencode/src/server/driver.test.ts index 20afe88d81045..11f639dc09e2b 100644 --- a/packages/provider-opencode/src/server/driver.test.ts +++ b/packages/provider-opencode/src/server/driver.test.ts @@ -11,6 +11,8 @@ import * as HostProcess from "@t3tools/shared/HostProcess"; import * as Effect from "effect/Effect"; import * as Fiber from "effect/Fiber"; import * as Layer from "effect/Layer"; +import * as Sink from "effect/Sink"; +import * as Stream from "effect/Stream"; import * as TestClock from "effect/testing/TestClock"; import * as HttpClient from "effect/http/HttpClient"; import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; @@ -155,6 +157,63 @@ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")( }), ); +it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")( + "updates a mise OpenCode 2 install through mise but never moves 1.x onto 2.x", + () => + Effect.gen(function* () { + const root = NodeFS.realpathSync( + NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-opencode-mise-")), + ); + const installPath = NodePath.join(root, "mise", "installs", "opencode", "1.19.0"); + const misePath = NodePath.join(root, "mise-bin", "mise"); + for (const file of [NodePath.join(installPath, "opencode"), misePath]) { + NodeFS.mkdirSync(NodePath.dirname(file), { recursive: true }); + NodeFS.writeFileSync(file, "#!/bin/sh\n"); + NodeFS.chmodSync(file, 0o755); + } + const installed = JSON.stringify({ + opencode: [{ install_path: installPath, requested_version: "latest", active: true }], + }); + const resolveMiseUpdate = (generation: "v1" | "v2") => + ProviderMaintenance.resolveProviderMaintenanceCapabilitiesEffect( + openCodeUpdateFor(generation), + { + binaryPath: NodePath.join(installPath, "opencode"), + env: { PATH: NodePath.dirname(misePath) }, + }, + ).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + ChildProcessSpawner.make(() => + Effect.succeed( + ChildProcessSpawner.makeHandle({ + pid: ChildProcessSpawner.ProcessId(1), + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)), + isRunning: Effect.succeed(false), + kill: () => Effect.void, + unref: Effect.succeed(Effect.void), + stdin: Sink.drain, + stdout: Stream.encodeText(Stream.make(installed)), + stderr: Stream.empty, + all: Stream.empty, + getInputFd: () => Sink.drain, + getOutputFd: () => Stream.empty, + }), + ), + ), + ), + Effect.provide(NodeServices.layer), + ); + + // 2.x converts the shared database in place, so a 1.x install never takes mise's latest. + assert.isNull((yield* resolveMiseUpdate("v1")).update); + assert.deepStrictEqual((yield* resolveMiseUpdate("v2")).update?.args, [ + "upgrade", + "opencode", + ]); + }), +); + const versionOutput: { current: string | undefined } = { current: undefined }; const versionProbes: Array = []; const changingRuntime = { diff --git a/packages/provider-opencode/src/server/driver.ts b/packages/provider-opencode/src/server/driver.ts index 5348e66ddda0c..31a3ec1d62ddc 100644 --- a/packages/provider-opencode/src/server/driver.ts +++ b/packages/provider-opencode/src/server/driver.ts @@ -88,6 +88,8 @@ export const openCodeUpdateFor = (generation: ProbedOpenCode["generation"]) => args: ["upgrade"], isCommandPath: isOpenCodeNativeCommandPath, }, + // mise's `opencode` follows releases into 2.x, so it would upgrade 1.x onto it. + miseUpgrade: generation === "v2", }); type OpenCodeRuntimeProbe = Effect.Success< From 0280ec2fe36e9401225ab88ac398ecaf89b16a87 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Mon, 19 Oct 2026 01:41:02 -0400 Subject: [PATCH 02/12] fix(server): a mise wrapper that picks its own version stays manual `mise which` answers for mise's config, so a wrapper running `mise x claude@2 -- claude` got `mise upgrade claude` while it kept running 2.x. A wrapper whose `mise x` line names a version, or builds its tool list at run time, now stays manual and names the wrapper. `@latest` and scoped npm names such as `npm:@scope/pkg` still follow mise's config. Comments and docs describe a `mise x` wrapper at a native installer's path in general rather than as Omarchy's. Co-authored-by: Claude Opus 5.5 --- docs/internals/providers.md | 11 ++-- .../src/server/maintenanceResolver.test.ts | 55 ++++++++++++++++- .../src/server/maintenanceResolver.ts | 59 ++++++++++++++----- 3 files changed, 103 insertions(+), 22 deletions(-) diff --git a/docs/internals/providers.md b/docs/internals/providers.md index 64ddd6be69ff6..1039de48ea00b 100644 --- a/docs/internals/providers.md +++ b/docs/internals/providers.md @@ -94,8 +94,8 @@ npm updates pin `--prefix` because the `npm` on `PATH` can belong to a different that owns the provider. Homebrew compares against `brew info` since casks trail npm by hours; native installs share npm's version train, so the registry stays authoritative for them. -Mise is checked before everything else, because Omarchy's `mise x` wrappers sit at native installer -paths such as `~/.local/bin/claude`. A binary under `mise/installs/`, a shim (a link to mise itself, +Mise is checked before everything else, because a `mise x` wrapper can sit at a native installer's +path, such as `~/.local/bin/claude`. A binary under `mise/installs/`, a shim (a link to mise itself, under any data directory), or a `mise x` wrapper is only a hint. Mise proves ownership: `mise which` resolves shims and wrappers, and `mise ls --json --installed` must list an active install that contains the binary. That listing also names the tool, which install paths cannot (`npm:@scope/pkg` @@ -104,9 +104,10 @@ the instance environment the probe used. Like Homebrew, its latest version comes `mise latest ` applies mise's settings, such as `minimum_release_age`, which npm's registry cannot. Mise may go to the network for that answer, so it is asked lazily through `lookupLatestVersion` and never while update checks are off. A pinned tool stays manual-only, so T3 -Code never edits a mise config. OpenCode 1.x stays manual too, since mise's `opencode` follows -releases into 2.x. npm globals under mise's own Node remain npm's. See the -[resolver](../../packages/provider-core/src/server/maintenanceResolver.ts). +Code never edits a mise config, and so does a wrapper that picks its own version +(`mise x claude@2`), since `mise which` answers for mise's config. OpenCode 1.x stays manual too, +since mise's `opencode` follows releases into 2.x. npm globals under mise's own Node remain npm's. +See the [resolver](../../packages/provider-core/src/server/maintenanceResolver.ts). Ownership is cached per instance and re-read immediately before an update runs. The [runner](../../apps/server/src/provider/providerMaintenanceRunner.ts) refuses when the lock key diff --git a/packages/provider-core/src/server/maintenanceResolver.test.ts b/packages/provider-core/src/server/maintenanceResolver.test.ts index 5a64030f7ae73..e7c5c5b57f97c 100644 --- a/packages/provider-core/src/server/maintenanceResolver.test.ts +++ b/packages/provider-core/src/server/maintenanceResolver.test.ts @@ -1257,7 +1257,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { const installPath = NodePath.join(toolDir, "2.0.0"); writeExecutable(NodePath.join(installPath, "native-package-tool")); NodeFS.symlinkSync(installPath, NodePath.join(toolDir, "latest")); - // Omarchy's lazy installer, written where the native installer links its binary. + // A `mise x` wrapper, written where the native installer links its binary. const wrapperPath = NodePath.join(tempDir, ".local", "bin", "native-package-tool"); NodeFS.mkdirSync(NodePath.dirname(wrapperPath), { recursive: true }); NodeFS.writeFileSync( @@ -1307,6 +1307,59 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn), ); expect(native.update).toMatchObject({ lockKey: "nativePackageTool-native" }); + + // A wrapper that picks its own version runs an install `mise upgrade` never touches. + for (const tool of ['"native-package-tool@1.9.0"', '"$TOOL"']) { + NodeFS.writeFileSync( + wrapperPath, + `#!/bin/sh\nexec mise x ${tool} -- "native-package-tool" "$@"\n`, + ); + const asked: Array> = []; + const pinned = yield* resolve.pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner( + { + which: NodePath.join(toolDir, "latest", "native-package-tool"), + installed: { + "native-package-tool": [ + { install_path: installPath, requested_version: "latest", active: true }, + ], + }, + }, + asked, + ), + ), + ); + expect(pinned.update).toBeNull(); + expect(pinned.installPath).toBe(NodeFS.realpathSync(wrapperPath)); + expect(asked).toEqual([]); + } + + // `@latest` and a scoped npm name still follow mise's config. + for (const tool of ['"native-package-tool@latest"', "npm:@example/native-package-tool"]) { + NodeFS.writeFileSync( + wrapperPath, + `#!/bin/sh\nexec mise x ${tool} -- native-package-tool "$@"\n`, + ); + const followed = yield* resolve.pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner( + { + which: NodePath.join(toolDir, "latest", "native-package-tool"), + installed: { + "native-package-tool": [ + { install_path: installPath, requested_version: "latest", active: true }, + ], + }, + }, + [], + ), + ), + ); + expect(followed.update).toMatchObject({ command: "mise upgrade native-package-tool" }); + } }), ); diff --git a/packages/provider-core/src/server/maintenanceResolver.ts b/packages/provider-core/src/server/maintenanceResolver.ts index 9eaf86b2bc971..09f8d52c5f4df 100644 --- a/packages/provider-core/src/server/maintenanceResolver.ts +++ b/packages/provider-core/src/server/maintenanceResolver.ts @@ -490,14 +490,21 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain const isInstall = realPath.includes("/mise/installs/"); // A shim is a link to mise itself, wherever mise keeps its data. const isShim = path.basename(realPath).replace(/\.exe$/, "") === "mise"; - if ( - !isInstall && - !isShim && - !resolvedPath.includes("/mise/shims/") && - !(yield* isMiseWrapperScript(context)) - ) { + const wrapper = + isInstall || isShim || resolvedPath.includes("/mise/shims/") + ? null + : yield* readMiseWrapper(context); + if (!isInstall && !isShim && !resolvedPath.includes("/mise/shims/") && wrapper === null) { return null; } + // `mise which` answers for mise's config, so a wrapper that picks its own + // version may run an install `mise upgrade` never touches. + if (wrapper === "chooses-version") { + return makeManualOnlyProviderMaintenanceCapabilities({ + ...owner, + installPath: context.realCommandPath, + }); + } const misePath = isShim ? context.realCommandPath @@ -587,8 +594,8 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn( return manual; } - // Mise goes first: Omarchy's `mise x` wrapper for claude sits at - // `~/.local/bin/claude`, the native installer's path. + // Mise goes first: a `mise x` wrapper can sit at the native installer's + // path, such as `~/.local/bin/claude`. const mise = yield* resolveMiseProviderMaintenance( { provider: definition.provider, packageName }, context, @@ -775,7 +782,23 @@ export const resolveHomebrewProviderMaintenance = Effect.fn("resolveHomebrewProv }, ); -const isMiseWrapperScript = Effect.fn("isMiseWrapperScript")(function* ( +const MISE_EXEC = /\bmise\s+(?:x|exec)\b/; + +/** + * Whether a `mise x` line picks the tool's version itself (`claude@2`) or + * builds its tool list at run time. Scoped npm names (`npm:@scope/pkg`) and + * `@latest` follow mise's config like a bare name. + */ +function miseExecChoosesVersion(line: string): boolean { + const tools = line.slice(line.search(MISE_EXEC)).split(/\s--(?:\s|$)/, 1)[0] ?? ""; + return /[$`]/.test(tools) || /[\w./-]@(?!latest\b)/.test(tools); +} + +/** + * A small script that runs its tool through `mise x`, or null for anything + * else. Comment lines never count. + */ +const readMiseWrapper = Effect.fn("readMiseWrapper")(function* ( context: ProviderMaintenanceResolutionContext, ) { const fileSystem = yield* FileSystem.FileSystem; @@ -784,17 +807,21 @@ const isMiseWrapperScript = Effect.fn("isMiseWrapperScript")(function* ( Effect.orElseSucceed(() => Infinity), ); if (size > MISE_WRAPPER_MAX_BYTES) { - return false; + return null; } const script = yield* fileSystem .readFileString(context.realCommandPath) .pipe(Effect.orElseSucceed(() => "")); - return ( - script.startsWith("#!") && - script - .split("\n") - .some((line) => !line.trimStart().startsWith("#") && /\bmise\s+(?:x|exec)\b/.test(line)) - ); + if (!script.startsWith("#!")) { + return null; + } + const lines = script + .split("\n") + .filter((line) => !line.trimStart().startsWith("#") && MISE_EXEC.test(line)); + if (lines.length === 0) { + return null; + } + return lines.some(miseExecChoosesVersion) ? "chooses-version" : "follows-config"; }); /** From dea6f86b31157027d7b191c14089a41ecee80ff0 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Mon, 19 Oct 2026 01:49:04 -0400 Subject: [PATCH 03/12] fix(server): a mise wrapper that sets MISE__VERSION stays manual mise documents `MISE__VERSION` as overriding the config's version, so a wrapper that exports one before `mise x` runs a version `mise which` does not report. Such a wrapper now stays manual like one that names a version in its `mise x` line. Co-authored-by: Claude Opus 5.5 --- .../src/server/maintenanceResolver.test.ts | 11 ++++++----- .../provider-core/src/server/maintenanceResolver.ts | 11 +++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/provider-core/src/server/maintenanceResolver.test.ts b/packages/provider-core/src/server/maintenanceResolver.test.ts index e7c5c5b57f97c..fedcd25606264 100644 --- a/packages/provider-core/src/server/maintenanceResolver.test.ts +++ b/packages/provider-core/src/server/maintenanceResolver.test.ts @@ -1309,11 +1309,12 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { expect(native.update).toMatchObject({ lockKey: "nativePackageTool-native" }); // A wrapper that picks its own version runs an install `mise upgrade` never touches. - for (const tool of ['"native-package-tool@1.9.0"', '"$TOOL"']) { - NodeFS.writeFileSync( - wrapperPath, - `#!/bin/sh\nexec mise x ${tool} -- "native-package-tool" "$@"\n`, - ); + for (const script of [ + 'exec mise x "native-package-tool@1.9.0" -- "native-package-tool" "$@"', + 'exec mise x "$TOOL" -- "native-package-tool" "$@"', + 'export MISE_NATIVE_PACKAGE_TOOL_VERSION=1.9.0\nexec mise x native-package-tool -- native-package-tool "$@"', + ]) { + NodeFS.writeFileSync(wrapperPath, `#!/bin/sh\n${script}\n`); const asked: Array> = []; const pinned = yield* resolve.pipe( Effect.provideService( diff --git a/packages/provider-core/src/server/maintenanceResolver.ts b/packages/provider-core/src/server/maintenanceResolver.ts index 09f8d52c5f4df..9e5f31256b7f9 100644 --- a/packages/provider-core/src/server/maintenanceResolver.ts +++ b/packages/provider-core/src/server/maintenanceResolver.ts @@ -783,6 +783,8 @@ export const resolveHomebrewProviderMaintenance = Effect.fn("resolveHomebrewProv ); const MISE_EXEC = /\bmise\s+(?:x|exec)\b/; +// Overrides the config's version for whatever mise runs next. +const MISE_TOOL_VERSION = /\bMISE_[A-Z0-9_]+_VERSION=/; /** * Whether a `mise x` line picks the tool's version itself (`claude@2`) or @@ -815,13 +817,14 @@ const readMiseWrapper = Effect.fn("readMiseWrapper")(function* ( if (!script.startsWith("#!")) { return null; } - const lines = script - .split("\n") - .filter((line) => !line.trimStart().startsWith("#") && MISE_EXEC.test(line)); + const code = script.split("\n").filter((line) => !line.trimStart().startsWith("#")); + const lines = code.filter((line) => MISE_EXEC.test(line)); if (lines.length === 0) { return null; } - return lines.some(miseExecChoosesVersion) ? "chooses-version" : "follows-config"; + return code.some((line) => MISE_TOOL_VERSION.test(line)) || lines.some(miseExecChoosesVersion) + ? "chooses-version" + : "follows-config"; }); /** From c1b18125128909eb701e2d4e89e75689da5b81af Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Mon, 19 Oct 2026 02:01:38 -0400 Subject: [PATCH 04/12] fix(server): a mise wrapper that sources a file stays manual A sourced file can export `MISE__VERSION`, which the probe cannot see, so a wrapper that sources one now stays manual too. Anything else a wrapper does to mise's environment is still caught after the update: the runner rechecks the version the provider reports. Co-authored-by: Claude Opus 5.5 --- .../provider-core/src/server/maintenanceResolver.test.ts | 1 + packages/provider-core/src/server/maintenanceResolver.ts | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/provider-core/src/server/maintenanceResolver.test.ts b/packages/provider-core/src/server/maintenanceResolver.test.ts index fedcd25606264..86a76bf197a75 100644 --- a/packages/provider-core/src/server/maintenanceResolver.test.ts +++ b/packages/provider-core/src/server/maintenanceResolver.test.ts @@ -1313,6 +1313,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { 'exec mise x "native-package-tool@1.9.0" -- "native-package-tool" "$@"', 'exec mise x "$TOOL" -- "native-package-tool" "$@"', 'export MISE_NATIVE_PACKAGE_TOOL_VERSION=1.9.0\nexec mise x native-package-tool -- native-package-tool "$@"', + '. "$HOME/.native-package-tool-env"\nexec mise x native-package-tool -- native-package-tool "$@"', ]) { NodeFS.writeFileSync(wrapperPath, `#!/bin/sh\n${script}\n`); const asked: Array> = []; diff --git a/packages/provider-core/src/server/maintenanceResolver.ts b/packages/provider-core/src/server/maintenanceResolver.ts index 9e5f31256b7f9..fe32cd48ef461 100644 --- a/packages/provider-core/src/server/maintenanceResolver.ts +++ b/packages/provider-core/src/server/maintenanceResolver.ts @@ -783,8 +783,9 @@ export const resolveHomebrewProviderMaintenance = Effect.fn("resolveHomebrewProv ); const MISE_EXEC = /\bmise\s+(?:x|exec)\b/; -// Overrides the config's version for whatever mise runs next. -const MISE_TOOL_VERSION = /\bMISE_[A-Z0-9_]+_VERSION=/; +// The probe cannot see either: `MISE__VERSION` overrides the config's +// version, and a sourced file can export it. +const WRAPPER_PICKS_VERSION = /\bMISE_[A-Z0-9_]+_VERSION=|^\s*(?:source|\.)\s+\S/; /** * Whether a `mise x` line picks the tool's version itself (`claude@2`) or @@ -822,7 +823,7 @@ const readMiseWrapper = Effect.fn("readMiseWrapper")(function* ( if (lines.length === 0) { return null; } - return code.some((line) => MISE_TOOL_VERSION.test(line)) || lines.some(miseExecChoosesVersion) + return code.some((line) => WRAPPER_PICKS_VERSION.test(line)) || lines.some(miseExecChoosesVersion) ? "chooses-version" : "follows-config"; }); From 0959252274844768032fe79d3c6fd91d7a9164a2 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Mon, 19 Oct 2026 02:15:55 -0400 Subject: [PATCH 05/12] fix(server): a mise wrapper counts only when its one command is mise x The probe asks mise with the server's environment, and a script can change what mise runs in more ways than a pattern list can name: a pinned tool, a `MISE_*` variable, a sourced file (conditional or not), a `cd`. A wrapper now counts as mise-owned only when its single command is `[VAR=value ...] [exec] mise x -- ...` with no version, `MISE_*` assignment, or shell expansion in the tool list. Any other wrapper that runs `mise x` stays manual, as mise installs were before this change. Co-authored-by: Claude Opus 5.5 --- .../src/provider/Drivers/CodexDriver.test.ts | 2 +- docs/internals/providers.md | 7 +-- .../src/server/maintenanceResolver.test.ts | 8 +++- .../src/server/maintenanceResolver.ts | 43 +++++++++++-------- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/apps/server/src/provider/Drivers/CodexDriver.test.ts b/apps/server/src/provider/Drivers/CodexDriver.test.ts index 53346d049abc6..3c92d526be124 100644 --- a/apps/server/src/provider/Drivers/CodexDriver.test.ts +++ b/apps/server/src/provider/Drivers/CodexDriver.test.ts @@ -485,7 +485,7 @@ it.layer(layerTest)("CodexDriver", (it) => { yield* fs.writeFileString( file, file === binaryPath && layout === "wrapper" - ? '#!/bin/sh\nmise use -g --quiet "codex" || exit 1\nexec mise x "codex" -- "codex" "$@"\n' + ? '#!/bin/sh\nexec mise x "codex" -- "codex" "$@"\n' : "#!/bin/sh\n", ); yield* fs.chmod(file, 0o755); diff --git a/docs/internals/providers.md b/docs/internals/providers.md index 1039de48ea00b..10f7efa73e32e 100644 --- a/docs/internals/providers.md +++ b/docs/internals/providers.md @@ -104,9 +104,10 @@ the instance environment the probe used. Like Homebrew, its latest version comes `mise latest ` applies mise's settings, such as `minimum_release_age`, which npm's registry cannot. Mise may go to the network for that answer, so it is asked lazily through `lookupLatestVersion` and never while update checks are off. A pinned tool stays manual-only, so T3 -Code never edits a mise config, and so does a wrapper that picks its own version -(`mise x claude@2`), since `mise which` answers for mise's config. OpenCode 1.x stays manual too, -since mise's `opencode` follows releases into 2.x. npm globals under mise's own Node remain npm's. +Code never edits a mise config. A wrapper counts only when its one command is a `mise x` that names +no version: `mise which` answers for mise's config, and anything else in the script could change +what mise runs. OpenCode 1.x stays manual too, since mise's `opencode` follows releases into 2.x. +npm globals under mise's own Node remain npm's. See the [resolver](../../packages/provider-core/src/server/maintenanceResolver.ts). Ownership is cached per instance and re-read immediately before an update runs. The diff --git a/packages/provider-core/src/server/maintenanceResolver.test.ts b/packages/provider-core/src/server/maintenanceResolver.test.ts index 86a76bf197a75..5b6d67e7cf3ca 100644 --- a/packages/provider-core/src/server/maintenanceResolver.test.ts +++ b/packages/provider-core/src/server/maintenanceResolver.test.ts @@ -1262,7 +1262,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { NodeFS.mkdirSync(NodePath.dirname(wrapperPath), { recursive: true }); NodeFS.writeFileSync( wrapperPath, - '#!/bin/sh\nmise use -g --quiet "native-package-tool" || exit 1\nexec mise x "native-package-tool" -- "native-package-tool" "$@"\n', + '#!/bin/sh\nexec mise x "native-package-tool" -- "native-package-tool" "$@"\n', ); NodeFS.chmodSync(wrapperPath, 0o755); const resolve = resolveProviderMaintenanceCapabilitiesEffect(nativePackageToolUpdate, { @@ -1308,12 +1308,16 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { ); expect(native.update).toMatchObject({ lockKey: "nativePackageTool-native" }); - // A wrapper that picks its own version runs an install `mise upgrade` never touches. + // A wrapper that may not follow mise's config could run an install + // `mise upgrade` never touches, so only a lone `mise x` counts. for (const script of [ 'exec mise x "native-package-tool@1.9.0" -- "native-package-tool" "$@"', 'exec mise x "$TOOL" -- "native-package-tool" "$@"', 'export MISE_NATIVE_PACKAGE_TOOL_VERSION=1.9.0\nexec mise x native-package-tool -- native-package-tool "$@"', '. "$HOME/.native-package-tool-env"\nexec mise x native-package-tool -- native-package-tool "$@"', + 'if [ -f "$HOME/.env" ]; then . "$HOME/.env"; fi\nexec mise x native-package-tool -- native-package-tool "$@"', + 'MISE_NATIVE_PACKAGE_TOOL_VERSION=1.9.0 exec mise x native-package-tool -- native-package-tool "$@"', + 'mise use -g --quiet "native-package-tool" || exit 1\nexec mise x "native-package-tool" -- "native-package-tool" "$@"', ]) { NodeFS.writeFileSync(wrapperPath, `#!/bin/sh\n${script}\n`); const asked: Array> = []; diff --git a/packages/provider-core/src/server/maintenanceResolver.ts b/packages/provider-core/src/server/maintenanceResolver.ts index fe32cd48ef461..8d8ec3ed05a78 100644 --- a/packages/provider-core/src/server/maintenanceResolver.ts +++ b/packages/provider-core/src/server/maintenanceResolver.ts @@ -497,9 +497,9 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain if (!isInstall && !isShim && !resolvedPath.includes("/mise/shims/") && wrapper === null) { return null; } - // `mise which` answers for mise's config, so a wrapper that picks its own - // version may run an install `mise upgrade` never touches. - if (wrapper === "chooses-version") { + // `mise which` answers for mise's config, so a wrapper that may not follow + // it could run an install `mise upgrade` never touches. + if (wrapper === "unproven") { return makeManualOnlyProviderMaintenanceCapabilities({ ...owner, installPath: context.realCommandPath, @@ -783,18 +783,25 @@ export const resolveHomebrewProviderMaintenance = Effect.fn("resolveHomebrewProv ); const MISE_EXEC = /\bmise\s+(?:x|exec)\b/; -// The probe cannot see either: `MISE__VERSION` overrides the config's -// version, and a sourced file can export it. -const WRAPPER_PICKS_VERSION = /\bMISE_[A-Z0-9_]+_VERSION=|^\s*(?:source|\.)\s+\S/; +// `[VAR=value ...] [exec] mise x -- `, capturing the +// assignments and the tool list. +const MISE_EXEC_COMMAND = + /^((?:[A-Za-z_]\w*=\S*\s+)*)(?:exec\s+)?mise\s+(?:x|exec)\s(.*?)(?:\s--(?:\s|$)|$)/; /** - * Whether a `mise x` line picks the tool's version itself (`claude@2`) or - * builds its tool list at run time. Scoped npm names (`npm:@scope/pkg`) and - * `@latest` follow mise's config like a bare name. + * Whether a wrapper's commands are just one `mise x` that follows mise's + * config. The probe asks mise with the server's environment, so anything else + * the script does (a pinned `claude@2`, a `MISE_*` variable, a sourced file, + * a `cd`) could change what mise runs. Scoped npm names (`npm:@scope/pkg`) and + * `@latest` follow the config like a bare name. */ -function miseExecChoosesVersion(line: string): boolean { - const tools = line.slice(line.search(MISE_EXEC)).split(/\s--(?:\s|$)/, 1)[0] ?? ""; - return /[$`]/.test(tools) || /[\w./-]@(?!latest\b)/.test(tools); +function miseWrapperFollowsConfig(commands: ReadonlyArray): boolean { + const match = commands.length === 1 ? MISE_EXEC_COMMAND.exec(commands[0] ?? "") : null; + return ( + match !== null && + !/\bMISE_/.test(match[1] ?? "") && + !/[$`;&|]|[\w./-]@(?!latest\b)/.test(match[2] ?? "") + ); } /** @@ -818,14 +825,14 @@ const readMiseWrapper = Effect.fn("readMiseWrapper")(function* ( if (!script.startsWith("#!")) { return null; } - const code = script.split("\n").filter((line) => !line.trimStart().startsWith("#")); - const lines = code.filter((line) => MISE_EXEC.test(line)); - if (lines.length === 0) { + const commands = script + .split("\n") + .map((line) => line.trim()) + .filter((line) => line !== "" && !line.startsWith("#")); + if (!commands.some((line) => MISE_EXEC.test(line))) { return null; } - return code.some((line) => WRAPPER_PICKS_VERSION.test(line)) || lines.some(miseExecChoosesVersion) - ? "chooses-version" - : "follows-config"; + return miseWrapperFollowsConfig(commands) ? "follows-config" : "unproven"; }); /** From dbf1b8bb25d4aee3eaa42933ef46b941ed0e60f7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 25 Oct 2026 21:36:58 +0000 Subject: [PATCH 06/12] test(server): mise-installed providers update through their mapped mise tool Co-Authored-By: Claude Opus 5.5 --- .../src/server/maintenanceResolver.test.ts | 304 ++++++++++++++++++ 1 file changed, 304 insertions(+) diff --git a/packages/provider-core/src/server/maintenanceResolver.test.ts b/packages/provider-core/src/server/maintenanceResolver.test.ts index 60522e0c29f48..a3d93a000ec44 100644 --- a/packages/provider-core/src/server/maintenanceResolver.test.ts +++ b/packages/provider-core/src/server/maintenanceResolver.test.ts @@ -12,6 +12,7 @@ import * as Effect from "effect/Effect"; import * as Fiber from "effect/Fiber"; import * as Sink from "effect/Sink"; import * as Stream from "effect/Stream"; +import * as TestClock from "effect/testing/TestClock"; import * as HttpClient from "effect/http/HttpClient"; import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; import * as ProviderLatestVersions from "./ProviderLatestVersions.ts"; @@ -60,6 +61,12 @@ const nativePackageToolUpdate = makePackageManagedProviderMaintenanceResolver({ isCommandPath: isNativeTestCommandPath("/.local/bin/native-package-tool"), }, }); +const miseToolUpdate = makePackageManagedProviderMaintenanceResolver({ + provider: driver("packageTool"), + npmPackageName: "@example/package-tool", + miseTool: "package-tool", + nativeUpdate: null, +}); const installedPackageToolProvider: ServerProvider = { instanceId: ProviderInstanceId.make("packageTool"), driver: driver("packageTool"), @@ -125,6 +132,88 @@ function stdoutSpawner( }); } +type MiseLatestAnswer = string | { readonly stdout?: string; readonly exitCode?: number } | "hang"; + +/** A `mise` answering `which`, `ls --json --installed [tool]`, and `latest`, recording each call. */ +function miseSpawner( + answers: { + readonly which: string; + readonly latest?: MiseLatestAnswer; + readonly installed: Record>; + }, + spawned: Array>, +) { + return ChildProcessSpawner.make((command) => { + const { command: executable, args } = command as unknown as { + readonly command: string; + readonly args: ReadonlyArray; + }; + spawned.push([executable, ...args]); + const latest = answers.latest ?? ""; + const hang = args[0] === "latest" && latest === "hang"; + let stdout = ""; + let exitCode = 0; + if (args[0] === "which") { + stdout = `${answers.which}\n`; + } else if (args[0] === "latest" && typeof latest === "string") { + stdout = latest === "hang" ? "" : `${latest}\n`; + } else if (args[0] === "latest") { + stdout = latest.stdout ?? ""; + exitCode = latest.exitCode ?? 0; + } else if (args[0] === "ls") { + // `mise ls --json ` lists one tool's installs; without a tool, every tool's. + const tool = args.slice(1).find((arg) => !arg.startsWith("-")); + stdout = JSON.stringify(tool ? (answers.installed[tool] ?? []) : answers.installed); + } else { + exitCode = 1; + } + return Effect.succeed( + ChildProcessSpawner.makeHandle({ + pid: ChildProcessSpawner.ProcessId(1), + exitCode: hang ? Effect.never : Effect.succeed(ChildProcessSpawner.ExitCode(exitCode)), + isRunning: Effect.succeed(hang), + kill: () => Effect.void, + unref: Effect.succeed(Effect.void), + stdin: Sink.drain, + stdout: hang ? Stream.never : Stream.encodeText(Stream.make(stdout)), + stderr: Stream.empty, + all: Stream.empty, + getInputFd: () => Sink.drain, + getOutputFd: () => Stream.empty, + }), + ); + }); +} + +/** A mise binary on its own PATH dir and an install of `package-tool` 1.0.0 in its data dir. */ +function miseFixture( + tempDir: string, + options: { readonly misePresent?: boolean; readonly tool?: string } = {}, +) { + const miseBinDir = NodePath.join(tempDir, "mise-bin"); + const misePath = NodePath.join(miseBinDir, "mise"); + if (options.misePresent !== false) writeExecutable(misePath); + const installPath = NodePath.join(tempDir, "mise", "installs", "package-tool", "1.0.0"); + const binaryPath = NodePath.join(installPath, "bin", "package-tool"); + writeExecutable(binaryPath); + const installed = ( + install: { readonly requested_version?: string; readonly active?: boolean } = {}, + ) => ({ + [options.tool ?? "package-tool"]: [ + { install_path: installPath, requested_version: "latest", active: true, ...install }, + ], + }); + return { miseBinDir, misePath, binaryPath, installed }; +} + +/** A mise shim: a link named for the tool that points at mise itself. */ +function linkShim(tempDir: string, misePath: string, name: string) { + const shimPath = NodePath.join(tempDir, "mise", "shims", name); + NodeFS.mkdirSync(NodePath.dirname(shimPath), { recursive: true }); + NodeFS.symlinkSync(misePath, shimPath); + return shimPath; +} + it.layer(NodeServices.layer)("providerMaintenance", (it) => { it.effect("prefers the installer's own latest version over the npm registry", () => resolveLatestProviderVersion({ ...manualPackageTool, latestVersion: "1.2.0" }).pipe( @@ -1101,6 +1190,221 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { }), ); + it.effect.each([ + { name: "an install", via: "install" }, + { name: "a shim", via: "shim" }, + ])( + "upgrades the mapped mise tool for $name requested as latest", + (fixture) => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-upgrade"); + const mise = miseFixture(tempDir); + const binaryPath = + fixture.via === "install" + ? mise.binaryPath + : linkShim(tempDir, mise.misePath, "package-tool"); + const spawned: Array> = []; + + const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(miseToolUpdate, { + binaryPath, + env: { PATH: mise.miseBinDir }, + }).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner({ which: mise.binaryPath, installed: mise.installed() }, spawned), + ), + ); + + expect(capabilities.update).toMatchObject({ + command: "mise upgrade package-tool", + executable: mise.misePath, + args: ["upgrade", "package-tool"], + }); + expect(spawned).toContainEqual([mise.misePath, "which", "package-tool"]); + // Resolution proves ownership but never asks mise for releases. + expect(spawned.some((args) => args[1] === "latest")).toBe(false); + }), + { skip: !symlinksSupported || windowsHost }, + ); + + it.effect.each([ + { name: "a pinned version", installed: { requested_version: "1.0.0" } }, + { name: "an inactive install", installed: { active: false } }, + { name: "an install of another mise tool", tool: "other-tool" }, + { name: "an install mise which does not run", which: "elsewhere" }, + { name: "an install without mise on PATH", misePresent: false }, + { name: "a provider with no mise tool", definition: "unmapped" }, + { name: "a mise x wrapper", via: "wrapper" }, + ] as const)( + "leaves $name manual-only", + (fixture) => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-manual"); + const mise = miseFixture(tempDir, { + misePresent: !("misePresent" in fixture), + tool: "tool" in fixture ? fixture.tool : "package-tool", + }); + let binaryPath = mise.binaryPath; + if ("via" in fixture) { + binaryPath = NodePath.join(tempDir, "bin", "package-tool"); + NodeFS.mkdirSync(NodePath.dirname(binaryPath), { recursive: true }); + NodeFS.writeFileSync( + binaryPath, + '#!/bin/sh\nexec mise x package-tool -- package-tool "$@"\n', + ); + NodeFS.chmodSync(binaryPath, 0o755); + } + const which = + "which" in fixture + ? NodePath.join(tempDir, "elsewhere", "package-tool") + : mise.binaryPath; + + const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect( + "definition" in fixture ? packageToolUpdate : miseToolUpdate, + { binaryPath, env: { PATH: mise.miseBinDir } }, + ).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner( + { + which, + installed: mise.installed("installed" in fixture ? fixture.installed : {}), + }, + [], + ), + ), + ); + + expect(capabilities.update).toBeNull(); + expect(capabilities.lookupLatestVersion).toBeUndefined(); + }), + { skip: windowsHost }, + ); + + it.effect.skipIf(windowsHost)( + "keeps the provider's own updater for an install mise does not own", + () => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-native"); + const nativePath = NodePath.join(tempDir, ".local", "bin", "native-package-tool"); + writeExecutable(nativePath); + const miseMappedNative = makePackageManagedProviderMaintenanceResolver({ + provider: driver("nativePackageTool"), + npmPackageName: "@example/native-package-tool", + miseTool: "native-package-tool", + nativeUpdate: { + args: ["update"], + isCommandPath: isNativeTestCommandPath("/.local/bin/native-package-tool"), + }, + }); + + const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(miseMappedNative, { + binaryPath: nativePath, + env: { PATH: "" }, + }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, noSpawn)); + + expect(capabilities.update).toEqual({ + command: `${nativePath} update`, + executable: nativePath, + args: ["update"], + lockKey: "nativePackageTool-native", + }); + }), + ); + + it.effect.skipIf(windowsHost)( + "asks mise for its latest release only while update checks are enabled", + () => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-latest"); + const mise = miseFixture(tempDir); + const spawned: Array> = []; + const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(miseToolUpdate, { + binaryPath: mise.binaryPath, + env: { PATH: mise.miseBinDir }, + }).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner( + // mise's `minimum_release_age` can hold it behind npm's 1.2.0. + { which: mise.binaryPath, latest: "1.1.0", installed: mise.installed() }, + spawned, + ), + ), + ); + const advise = (enableProviderUpdateChecks: boolean) => + enrichProviderSnapshotWithVersionAdvisory(installedPackageToolProvider, capabilities, { + enableProviderUpdateChecks, + }); + + expect((yield* advise(false)).versionAdvisory).toMatchObject({ + status: "unknown", + latestVersion: null, + }); + expect(spawned.filter((args) => args[1] === "latest")).toEqual([]); + + expect((yield* advise(true)).versionAdvisory).toMatchObject({ + status: "behind_latest", + latestVersion: "1.1.0", + }); + expect((yield* advise(true)).versionAdvisory?.latestVersion).toBe("1.1.0"); + expect(spawned.filter((args) => args[1] === "latest")).toEqual([ + [mise.misePath, "latest", "package-tool"], + ]); + }).pipe( + Effect.provide(ProviderLatestVersions.layer), + Effect.provideService( + HttpClient.HttpClient, + HttpClient.make(() => Effect.die("mise answers for its own installs")), + ), + ), + ); + + it.effect.each([ + { name: "fails", latest: { exitCode: 1 } }, + { name: "prints nothing", latest: { stdout: "" } }, + { name: "never answers", latest: "hang" }, + ] as const)( + "reports an unknown latest version when mise latest $name", + (fixture) => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-latest-unknown"); + const mise = miseFixture(tempDir); + const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(miseToolUpdate, { + binaryPath: mise.binaryPath, + env: { PATH: mise.miseBinDir }, + }).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner( + { which: mise.binaryPath, latest: fixture.latest, installed: mise.installed() }, + [], + ), + ), + ); + expect(capabilities.update).toMatchObject({ args: ["upgrade", "package-tool"] }); + + const advisory = yield* enrichProviderSnapshotWithVersionAdvisory( + installedPackageToolProvider, + capabilities, + { enableProviderUpdateChecks: true }, + ).pipe(Effect.forkChild); + yield* TestClock.adjust("1 minute"); + + expect((yield* Fiber.join(advisory)).versionAdvisory).toMatchObject({ + status: "unknown", + latestVersion: null, + }); + }).pipe( + Effect.provide(ProviderLatestVersions.layer), + Effect.provideService( + HttpClient.HttpClient, + HttpClient.make(() => Effect.die("an offline mise must not fall back to npm")), + ), + ), + { skip: windowsHost }, + ); + it.effect.skipIf(!symlinksSupported)("updates Yarn global installs with yarn", () => Effect.gen(function* () { const tempDir = yield* makeTempDir("t3-yarn-capabilities"); From 5ba9be45f2db83244af9aacfba5100fb3a363487 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 25 Oct 2026 21:46:21 +0000 Subject: [PATCH 07/12] fix(server): mise-installed providers update through mise When mise installed a provider, Update either ran the provider's own updater, producing a copy mise does not track, or offered nothing. Each driver now declares its fixed mise tool (Claude, Codex, Grok, Muse, OpenCode 2, Pi; OpenCode 1.x stays manual since mise's opencode crosses into 2.x). One shared resolver proves ownership with `mise which` and an active `mise ls --json --installed` entry requested as `latest`, then offers `mise upgrade `, versioned by a lazy `mise latest`. Pinned, inactive, wrapper, and unproven installs stay manual. Co-Authored-By: Claude Opus 5.5 --- .../src/provider/Drivers/ClaudeDriver.ts | 1 + .../src/provider/Drivers/CodexDriver.ts | 1 + docs/internals/providers.md | 9 +- docs/user/install.md | 7 +- .../src/server/maintenanceResolver.test.ts | 2 +- .../src/server/maintenanceResolver.ts | 151 ++++++++++++++++-- packages/provider-grok/src/server/driver.ts | 8 + packages/provider-muse/src/server/driver.ts | 13 +- .../provider-muse/src/server/maintenance.ts | 23 ++- .../provider-opencode/src/server/driver.ts | 2 + packages/provider-pi/src/server/driver.ts | 1 + 11 files changed, 187 insertions(+), 31 deletions(-) diff --git a/apps/server/src/provider/Drivers/ClaudeDriver.ts b/apps/server/src/provider/Drivers/ClaudeDriver.ts index 86832d53d3119..f2ff273d6816c 100644 --- a/apps/server/src/provider/Drivers/ClaudeDriver.ts +++ b/apps/server/src/provider/Drivers/ClaudeDriver.ts @@ -84,6 +84,7 @@ function isClaudeNativeCommandPath(commandPath: string): boolean { const UPDATE = makePackageManagedProviderMaintenanceResolver({ provider: DRIVER_KIND, npmPackageName: "@anthropic-ai/claude-code", + miseTool: "claude", nativeUpdate: { args: ["update"], isCommandPath: isClaudeNativeCommandPath, diff --git a/apps/server/src/provider/Drivers/CodexDriver.ts b/apps/server/src/provider/Drivers/CodexDriver.ts index 2d078cf32594f..6db17c4e9278c 100644 --- a/apps/server/src/provider/Drivers/CodexDriver.ts +++ b/apps/server/src/provider/Drivers/CodexDriver.ts @@ -69,6 +69,7 @@ function makeCodexMaintenanceResolver(sharedHomePath: string) { return makePackageManagedProviderMaintenanceResolver({ provider: DRIVER_KIND, npmPackageName: "@openai/codex", + miseTool: "codex", nativeUpdate: { args: ["update"], isCommandPath: isCodexStandaloneCommandPath, diff --git a/docs/internals/providers.md b/docs/internals/providers.md index 4121a349dcbf8..dfff6a88fda5f 100644 --- a/docs/internals/providers.md +++ b/docs/internals/providers.md @@ -88,8 +88,13 @@ either the resolved path or its real target, since those installers place real f symlinks there. Volta is proven by its `volta-shim` link plus the package's image directory. When nothing is proven, the provider's own updater (`claude update`, `codex update`, `opencode upgrade`, `pi update --self`, `grok update`) runs instead, because each one detects its installer itself; -the runner's version check catches an updater that exits 0 without updating. Mise installs stay -manual-only because their version is pinned in mise's config. A Grok cask whose Homebrew prefix +the runner's version check catches an updater that exits 0 without updating. Mise is checked +first, since a `mise x` wrapper can sit at a native installer's path. Each driver names its fixed +mise tool; mise must resolve the binary with `mise which` and list it in an active install of that +tool requested as `latest`, which gets `mise upgrade `. Everything else mise touches (pinned +tools, wrappers, OpenCode 1.x, whose mise tool crosses into 2.x) stays manual-only, so T3 Code never +edits mise config. `mise latest` supplies the version, because settings such as +`minimum_release_age` can hold mise behind npm. A Grok cask whose Homebrew prefix cannot be verified also stays manual-only: `grok update` would install a second copy. npm updates pin `--prefix` because the `npm` on `PATH` can belong to a different Node than the one that owns the provider. Homebrew compares against `brew info` since casks trail npm by hours; native installs share npm's version diff --git a/docs/user/install.md b/docs/user/install.md index 64b1f19fac54b..d14f5c7d3f09d 100644 --- a/docs/user/install.md +++ b/docs/user/install.md @@ -159,9 +159,10 @@ on the environment's machine. An unlisted version is unverified. When a provider CLI is behind its latest release, its provider card shows the available version. **Update now** runs the installer that owns the CLI -(Homebrew, or a global npm, pnpm, Yarn, Bun, Volta, or Vite+ install), or the -CLI's own update command when T3 Code cannot tell. Update a CLI installed with -mise through mise. Cursor and Antigravity update with T3 Code. Homebrew installs +(Homebrew, mise, or a global npm, pnpm, Yarn, Bun, Volta, or Vite+ install), or +the CLI's own update command when T3 Code cannot tell. T3 Code runs `mise upgrade` +only for a tool your mise config requests as `latest`; update a pinned version +through mise yourself. Cursor and Antigravity update with T3 Code. Homebrew installs compare against the version Homebrew offers, which can trail the npm release by a few hours. diff --git a/packages/provider-core/src/server/maintenanceResolver.test.ts b/packages/provider-core/src/server/maintenanceResolver.test.ts index a3d93a000ec44..5047607a21025 100644 --- a/packages/provider-core/src/server/maintenanceResolver.test.ts +++ b/packages/provider-core/src/server/maintenanceResolver.test.ts @@ -157,7 +157,7 @@ function miseSpawner( stdout = `${answers.which}\n`; } else if (args[0] === "latest" && typeof latest === "string") { stdout = latest === "hang" ? "" : `${latest}\n`; - } else if (args[0] === "latest") { + } else if (args[0] === "latest" && typeof latest !== "string") { stdout = latest.stdout ?? ""; exitCode = latest.exitCode ?? 0; } else if (args[0] === "ls") { diff --git a/packages/provider-core/src/server/maintenanceResolver.ts b/packages/provider-core/src/server/maintenanceResolver.ts index 2e3aad166c58e..bf169c84ecd39 100644 --- a/packages/provider-core/src/server/maintenanceResolver.ts +++ b/packages/provider-core/src/server/maintenanceResolver.ts @@ -89,6 +89,8 @@ export interface PackageManagedProviderMaintenanceDefinition { readonly requiresCommandPath?: boolean; readonly env?: NodeJS.ProcessEnv; } | null; + /** The mise registry tool that installs this provider; unset keeps mise installs manual-only. */ + readonly miseTool?: string; } const NpmLatestVersionResponse = Schema.Struct({ @@ -232,10 +234,18 @@ function isYarnGlobalCommandPath(commandPath: string): boolean { return /\/yarn\/(?:data\/)?global\/node_modules\//.test(normalizeCommandPath(commandPath)); } -/** Version-manager installs are pinned in its config, so updating them means editing that. */ +/** npm globals under mise's own Node belong to npm, which proves their prefix. */ function isMiseCommandPath(commandPath: string): boolean { const normalized = normalizeCommandPath(commandPath); - return normalized.includes("/mise/installs/") || normalized.includes("/mise/shims/"); + return ( + (normalized.includes("/mise/installs/") && !normalized.includes("/mise/installs/node/")) || + normalized.includes("/mise/shims/") + ); +} + +/** A mise shim is a link to mise itself, wherever mise keeps its data. */ +function isMiseExecutablePath(commandPath: string): boolean { + return /(?:^|\/)mise(?:\.exe)?$/.test(normalizeCommandPath(commandPath)); } const winGetClaudeCommandPath = @@ -417,6 +427,120 @@ const resolvePnpmGlobalLatestVersion = Effect.fn("resolvePnpmGlobalLatestVersion return nonEmptyString(listedEntries?.[0]?.dependencies?.[packageName]?.version); }); +const MiseInstall = Schema.Struct({ + install_path: Schema.String, + requested_version: Schema.optional(Schema.NullOr(Schema.String)), + active: Schema.optional(Schema.Boolean), +}); +const decodeMiseToolInstalls = Schema.decodeUnknownOption( + Schema.fromJsonString(Schema.Array(MiseInstall)), +); +const decodeMiseInstalls = Schema.decodeUnknownOption( + Schema.fromJsonString(Schema.Record(Schema.String, Schema.Array(MiseInstall))), +); + +/** The installs `mise ls --json --installed ` lists, refusing any other tool's. */ +function miseToolInstalls( + listing: string, + miseTool: string, +): ReadonlyArray { + const installs = decodeMiseToolInstalls(listing); + if (Option.isSome(installs)) return installs.value; + const byTool = Option.getOrUndefined(decodeMiseInstalls(listing)); + return byTool && Object.keys(byTool).every((tool) => tool === miseTool) + ? (byTool[miseTool] ?? []) + : []; +} + +/** + * Null when mise does not own the executable. Mise must prove the rest: `mise which` runs it from + * an active install of `miseTool` requested as `latest`; anything else stays manual-only, so T3 + * Code never edits mise config. `miseTool` is the driver's fixed name, never mise's own output. + */ +export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMaintenance")( + function* ( + owner: { readonly provider: ProviderDriverKind; readonly packageName: string | null }, + miseTool: string | undefined, + context: ProviderMaintenanceResolutionContext, + ) { + const commandPaths = [context.resolvedCommandPath, context.realCommandPath]; + const isShim = isMiseExecutablePath(context.realCommandPath); + const isMise = isShim || commandPaths.some(isMiseCommandPath); + if (!isMise && !(yield* isMiseWrapperScript(context))) return null; + const manual = (installPath: string) => + makeManualOnlyProviderMaintenanceCapabilities({ ...owner, installPath }); + const commandName = normalizeCommandPath(context.resolvedCommandPath) + .split("/") + .at(-1) + ?.replace(/\.(?:exe|cmd|bat|ps1)$/, ""); + // A shim runs whatever mise resolves for its own name, which must be the mapped tool's. + if (!isMise || !miseTool || (isShim && commandName !== miseTool)) { + return manual(context.realCommandPath); + } + + const fileSystem = yield* FileSystem.FileSystem; + const realPath = (target: string) => + fileSystem.realPath(target).pipe(Effect.orElseSucceed(() => target)); + const misePath = + (yield* resolveCommandPath("mise", { env: context.env })) ?? + (isShim ? context.realCommandPath : null); + if (!misePath) return manual(context.realCommandPath); + const which = nonEmptyString(yield* runProbe(misePath, ["which", miseTool], context.env)); + const binaryPath = which ? yield* realPath(which) : null; + // Through a shim T3 Code runs whatever mise resolves; otherwise mise must resolve this binary. + if ( + !binaryPath || + (!isShim && + normalizeCommandPath(binaryPath) !== normalizeCommandPath(context.realCommandPath)) + ) { + return manual(binaryPath ?? context.realCommandPath); + } + const listing = yield* runProbe( + misePath, + ["ls", "--json", "--installed", miseTool], + context.env, + ); + const candidates = listing + ? miseToolInstalls(listing, miseTool).filter( + (install) => install.active === true && install.requested_version === "latest", + ) + : []; + const installPaths = yield* Effect.forEach(candidates, (install) => + realPath(install.install_path), + ); + const binary = normalizeCommandPath(binaryPath); + if ( + !installPaths.some((installPath) => + binary.startsWith(`${normalizeCommandPath(installPath).replace(/\/+$/, "")}/`), + ) + ) { + return manual(binaryPath); + } + const args = ["upgrade", miseTool]; + const services = yield* Effect.context(); + return makeProviderMaintenanceCapabilities({ + ...owner, + updateExecutable: misePath, + updateArgs: args, + updateLockKey: "mise", + updateCommand: ["mise", ...args].join(" "), + platform: context.platform, + // Mise read its config from this environment, so the upgrade runs in it too. + env: context.env, + // Settings such as `minimum_release_age` can hold mise behind the registry, + // so only mise can say what it installs. It may go to the network, so ask lazily. + latestVersion: null, + lookupLatestVersion: runProbe(misePath, ["latest", miseTool], context.env).pipe( + Effect.map((latest) => { + const version = nonEmptyString(latest); + return version && /^\S+$/.test(version) ? version : null; + }), + Effect.provideContext(services), + ), + }); + }, +); + export const resolvePackageManagedProviderMaintenance = Effect.fn( "resolvePackageManagedProviderMaintenance", )(function* ( @@ -445,6 +569,13 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn( return manual; } + const mise = yield* resolveMiseProviderMaintenance( + { provider: definition.provider, packageName }, + definition.miseTool, + context, + ); + if (mise) return mise; + const nativeUpdate = definition.nativeUpdate; const native = nativeUpdate ? makeProviderMaintenanceCapabilities({ @@ -457,13 +588,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn( ...(nativeUpdate.env ? { env: nativeUpdate.env } : {}), }) : manual; - // A native-looking launcher can still delegate to a mise-owned install. - if ( - nativeUpdate?.isCommandPath && - commandPaths.some(nativeUpdate.isCommandPath) && - !commandPaths.some(isMiseCommandPath) && - !(yield* isMiseWrapperScript(context)) - ) { + if (nativeUpdate?.isCommandPath && commandPaths.some(nativeUpdate.isCommandPath)) { return native; } // A `node_modules` path not proven below belongs to another package or a @@ -551,14 +676,6 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn( } const homebrew = homebrewOwnershipFromCommandPath(context.realCommandPath); - if ( - commandPaths.some(isMiseCommandPath) || - // Mise shims resolve to the version manager's keg, not the provider's. - (homebrew?.kind === "formula" && homebrew.name.toLowerCase() === "mise") || - (yield* isMiseWrapperScript(context)) - ) { - return manual; - } if (homebrew) { return ( (yield* resolveHomebrewProviderMaintenance( diff --git a/packages/provider-grok/src/server/driver.ts b/packages/provider-grok/src/server/driver.ts index 23ecf58158533..955b9cb932961 100644 --- a/packages/provider-grok/src/server/driver.ts +++ b/packages/provider-grok/src/server/driver.ts @@ -37,6 +37,7 @@ import { makeProviderMaintenanceCapabilities, type ProviderMaintenanceCapabilitiesResolver, resolveHomebrewProviderMaintenance, + resolveMiseProviderMaintenance, resolveProviderMaintenanceCapabilitiesEffect, } from "@t3tools/provider-core/server/maintenanceResolver"; import { @@ -50,6 +51,7 @@ const DRIVER_KIND = ProviderDriverKind.make("grok"); // npm latest matches the stable channel installed by grok update. const GROK_NPM_PACKAGE = "@xai-official/grok"; // `grok update` installs under `GROK_HOME`; use the resolved executable and instance environment. +// A mise install upgrades through mise instead. // Homebrew casks need brew upgrades; `grok update` would install a second copy. // Keep casks manual when their brew cannot vouch for them. const UPDATE: ProviderMaintenanceCapabilitiesResolver = { @@ -60,6 +62,12 @@ const UPDATE: ProviderMaintenanceCapabilitiesResolver = { packageName: GROK_NPM_PACKAGE, }); } + const mise = yield* resolveMiseProviderMaintenance( + { provider: DRIVER_KIND, packageName: GROK_NPM_PACKAGE }, + "grok", + context, + ); + if (mise) return mise; const homebrew = homebrewOwnershipFromCommandPath(context.realCommandPath); // Only a cask is Grok's: a formula keg such as `node` holding an npm global is not. if (homebrew?.kind === "cask") { diff --git a/packages/provider-muse/src/server/driver.ts b/packages/provider-muse/src/server/driver.ts index 390764c20bcd0..c24111f07d155 100644 --- a/packages/provider-muse/src/server/driver.ts +++ b/packages/provider-muse/src/server/driver.ts @@ -121,12 +121,13 @@ export const MuseDriver: ProviderDriver< const capabilities = yield* resolveInstallation(options); // The maintenance runner requests fresh capabilities around an explicit update // and needs the native target version to verify that the command actually upgraded. - const latestVersion = options?.fresh - ? yield* latestMuseVersion(processEnvironment, { fresh: true }).pipe( - Effect.provideService(HttpClient.HttpClient, httpClient), - Effect.provideService(ProviderLatestVersions.ProviderLatestVersions, latestVersions), - ) - : undefined; + const latestVersion = + options?.fresh && !capabilities.lookupLatestVersion + ? yield* latestMuseVersion(processEnvironment, { fresh: true }).pipe( + Effect.provideService(HttpClient.HttpClient, httpClient), + Effect.provideService(ProviderLatestVersions.ProviderLatestVersions, latestVersions), + ) + : undefined; return latestVersion !== undefined ? { ...capabilities, latestVersion } : capabilities; }); const snapshot = yield* makeManagedServerProvider>({ diff --git a/packages/provider-muse/src/server/maintenance.ts b/packages/provider-muse/src/server/maintenance.ts index 0a3a59de128e8..46ffee6b993d4 100644 --- a/packages/provider-muse/src/server/maintenance.ts +++ b/packages/provider-muse/src/server/maintenance.ts @@ -12,6 +12,7 @@ import { makeProviderMaintenanceCapabilities, type ProviderMaintenanceCapabilities, type ProviderMaintenanceCapabilitiesResolver, + resolveMiseProviderMaintenance, } from "@t3tools/provider-core/server/maintenanceResolver"; import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions"; import { parseGenericCliVersion } from "@t3tools/provider-core/server/snapshotProbe"; @@ -37,7 +38,10 @@ export const compareMuseVersions = (current: string, latest: string) => ? compareSemverVersions(comparableMuseVersion(current), comparableMuseVersion(latest)) : compareSemverVersions(current.replace(MUSE_REVISION, ""), latest.replace(MUSE_REVISION, "")); -/** Only the official launcher owns an update channel; a standalone binary cannot update itself. */ +/** + * Mise upgrades a binary it installed. Otherwise only the official launcher owns + * an update channel; a standalone binary cannot update itself. + */ export const museMaintenance: ProviderMaintenanceCapabilitiesResolver = { resolve: Effect.fn("MuseMaintenance.resolve")(function* (context) { const manual = { @@ -45,6 +49,12 @@ export const museMaintenance: ProviderMaintenanceCapabilitiesResolver = { compareVersions: compareMuseVersions, }; if (!context || context.platform === "win32") return manual; + const mise = yield* resolveMiseProviderMaintenance( + { provider: DRIVER, packageName: null }, + "muse", + context, + ); + if (mise) return { ...mise, compareVersions: compareMuseVersions }; const fs = yield* FileSystem.FileSystem; const isLauncher = yield* Effect.gen(function* () { const stat = yield* fs.stat(context.realCommandPath); @@ -119,6 +129,15 @@ export const enrichMuseSnapshot = Effect.fn("enrichMuseSnapshot")(function* (inp readonly environment: NodeJS.ProcessEnv; }) { const { snapshot } = input; + const options = { enableProviderUpdateChecks: input.enableProviderUpdateChecks }; + // Mise names the version it would install, so its answer alone counts. + if (input.maintenanceCapabilities.lookupLatestVersion) { + return yield* enrichProviderSnapshotWithVersionAdvisory( + snapshot, + input.maintenanceCapabilities, + options, + ); + } const latestVersion = input.enableProviderUpdateChecks && snapshot.enabled && snapshot.installed && snapshot.version ? yield* latestMuseVersion(input.environment) @@ -126,6 +145,6 @@ export const enrichMuseSnapshot = Effect.fn("enrichMuseSnapshot")(function* (inp return yield* enrichProviderSnapshotWithVersionAdvisory( snapshot, { ...input.maintenanceCapabilities, latestVersion }, - { enableProviderUpdateChecks: input.enableProviderUpdateChecks }, + options, ); }); diff --git a/packages/provider-opencode/src/server/driver.ts b/packages/provider-opencode/src/server/driver.ts index 713bc3f05ad27..2b11c2b7425e1 100644 --- a/packages/provider-opencode/src/server/driver.ts +++ b/packages/provider-opencode/src/server/driver.ts @@ -84,6 +84,8 @@ export const openCodeUpdateFor = (generation: ProbedOpenCode["generation"]) => args: ["upgrade"], isCommandPath: isOpenCodeNativeCommandPath, }, + // mise's `opencode` follows releases into 2.x, so it would upgrade 1.x across that line. + ...(generation === "v2" ? { miseTool: "opencode" } : {}), }); type OpenCodeRuntimeProbe = Effect.Success< diff --git a/packages/provider-pi/src/server/driver.ts b/packages/provider-pi/src/server/driver.ts index c37e5d757f382..7a533614b6999 100644 --- a/packages/provider-pi/src/server/driver.ts +++ b/packages/provider-pi/src/server/driver.ts @@ -45,6 +45,7 @@ const DRIVER_KIND = ProviderDriverKind.make("pi"); const UPDATE = makePackageManagedProviderMaintenanceResolver({ provider: DRIVER_KIND, npmPackageName: "@earendil-works/pi-coding-agent", + miseTool: "pi", nativeUpdate: { args: ["update", "--self"] }, }); From f52352aeef147e9f4357022e9ec9d3a33cec48df Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 25 Oct 2026 21:56:25 +0000 Subject: [PATCH 08/12] fix(server): mise updates only follow paths the upgrade moves A provider launched from a fixed mise version directory kept running the old binary after `mise upgrade`, and fails once mise prunes it. Only mise shims and the tool's `latest` link now get `mise upgrade`; version directories, including one `mise activate` put on PATH, stay manual-only. Mapped tools now ask `mise which` whenever mise is on PATH, so installs under a custom MISE_DATA_DIR are recognized instead of reaching the native updater. Installer latest-version cache keys include a hash of the update environment, so instances with different mise settings keep their own answers. Co-Authored-By: Claude Opus 5.5 --- docs/internals/providers.md | 13 +- docs/user/install.md | 5 +- .../src/server/maintenanceResolver.test.ts | 148 +++++++++++++++--- .../src/server/maintenanceResolver.ts | 57 ++++--- 4 files changed, 177 insertions(+), 46 deletions(-) diff --git a/docs/internals/providers.md b/docs/internals/providers.md index dfff6a88fda5f..5f1dc92157dc6 100644 --- a/docs/internals/providers.md +++ b/docs/internals/providers.md @@ -89,11 +89,14 @@ symlinks there. Volta is proven by its `volta-shim` link plus the package's imag nothing is proven, the provider's own updater (`claude update`, `codex update`, `opencode upgrade`, `pi update --self`, `grok update`) runs instead, because each one detects its installer itself; the runner's version check catches an updater that exits 0 without updating. Mise is checked -first, since a `mise x` wrapper can sit at a native installer's path. Each driver names its fixed -mise tool; mise must resolve the binary with `mise which` and list it in an active install of that -tool requested as `latest`, which gets `mise upgrade `. Everything else mise touches (pinned -tools, wrappers, OpenCode 1.x, whose mise tool crosses into 2.x) stays manual-only, so T3 Code never -edits mise config. `mise latest` supplies the version, because settings such as +first, since a `mise x` wrapper can sit at a native installer's path, and `MISE_DATA_DIR` can put +installs anywhere, so `mise which` is asked whenever mise is on `PATH`. Each driver names its fixed +mise tool; mise must resolve the binary and list it in an active install of that tool requested as +`latest`, which gets `mise upgrade `. T3 Code keeps launching the configured path, so that +path must be a shim or under the tool's `latest` link, which the upgrade repoints: a version +directory (including one `mise activate` put on `PATH`) would keep running the old binary until mise +prunes it. Everything else mise touches (fixed version paths, pinned tools, wrappers, OpenCode 1.x, +whose mise tool crosses into 2.x) stays manual-only, so T3 Code never edits mise config. `mise latest` supplies the version, because settings such as `minimum_release_age` can hold mise behind npm. A Grok cask whose Homebrew prefix cannot be verified also stays manual-only: `grok update` would install a second copy. npm updates pin `--prefix` because the `npm` on `PATH` can belong to a different Node than the one that owns the provider. Homebrew diff --git a/docs/user/install.md b/docs/user/install.md index d14f5c7d3f09d..a5fa42008a8b3 100644 --- a/docs/user/install.md +++ b/docs/user/install.md @@ -161,8 +161,9 @@ When a provider CLI is behind its latest release, its provider card shows the available version. **Update now** runs the installer that owns the CLI (Homebrew, mise, or a global npm, pnpm, Yarn, Bun, Volta, or Vite+ install), or the CLI's own update command when T3 Code cannot tell. T3 Code runs `mise upgrade` -only for a tool your mise config requests as `latest`; update a pinned version -through mise yourself. Cursor and Antigravity update with T3 Code. Homebrew installs +only for a tool your mise config requests as `latest` when the provider's binary +path is a mise shim or under the tool's `installs//latest` link; update a +pinned version, or a path into one version's directory, through mise yourself. Cursor and Antigravity update with T3 Code. Homebrew installs compare against the version Homebrew offers, which can trail the npm release by a few hours. diff --git a/packages/provider-core/src/server/maintenanceResolver.test.ts b/packages/provider-core/src/server/maintenanceResolver.test.ts index 5047607a21025..7cfee05408430 100644 --- a/packages/provider-core/src/server/maintenanceResolver.test.ts +++ b/packages/provider-core/src/server/maintenanceResolver.test.ts @@ -185,17 +185,41 @@ function miseSpawner( }); } -/** A mise binary on its own PATH dir and an install of `package-tool` 1.0.0 in its data dir. */ +/** + * A mise binary on its own PATH dir and an install of `package-tool` 1.0.0 in its data dir, + * with the `latest` link mise keeps pointing at the newest install. + */ function miseFixture( tempDir: string, - options: { readonly misePresent?: boolean; readonly tool?: string } = {}, + options: { + readonly misePresent?: boolean; + readonly tool?: string; + readonly dataDir?: string; + } = {}, ) { const miseBinDir = NodePath.join(tempDir, "mise-bin"); const misePath = NodePath.join(miseBinDir, "mise"); if (options.misePresent !== false) writeExecutable(misePath); - const installPath = NodePath.join(tempDir, "mise", "installs", "package-tool", "1.0.0"); - const binaryPath = NodePath.join(installPath, "bin", "package-tool"); - writeExecutable(binaryPath); + const toolDir = NodePath.join( + options.dataDir ?? NodePath.join(tempDir, "mise"), + "installs", + "package-tool", + ); + const latestDir = NodePath.join(toolDir, "latest"); + let installPath = ""; + let binaryPath = ""; + /** Installs `version` and points `latest` at it, as `mise upgrade` does. */ + const install = (version: string) => { + installPath = NodePath.join(toolDir, version); + binaryPath = NodePath.join(installPath, "bin", "package-tool"); + writeExecutable(binaryPath); + if (symlinksSupported) { + NodeFS.rmSync(latestDir, { force: true }); + NodeFS.symlinkSync(installPath, latestDir); + } + return binaryPath; + }; + install("1.0.0"); const installed = ( install: { readonly requested_version?: string; readonly active?: boolean } = {}, ) => ({ @@ -203,7 +227,16 @@ function miseFixture( { install_path: installPath, requested_version: "latest", active: true, ...install }, ], }); - return { miseBinDir, misePath, binaryPath, installed }; + return { + miseBinDir, + misePath, + get binaryPath() { + return binaryPath; + }, + latestBinaryPath: NodePath.join(latestDir, "bin", "package-tool"), + install, + installed, + }; } /** A mise shim: a link named for the tool that points at mise itself. */ @@ -1191,17 +1224,21 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { ); it.effect.each([ - { name: "an install", via: "install" }, + { name: "its latest link", via: "latest" }, + { name: "a latest link in a custom data dir", via: "latest", dataDir: "data" }, { name: "a shim", via: "shim" }, ])( - "upgrades the mapped mise tool for $name requested as latest", + "upgrades the mapped mise tool through $name requested as latest", (fixture) => Effect.gen(function* () { const tempDir = yield* makeTempDir("t3-mise-upgrade"); - const mise = miseFixture(tempDir); + const mise = miseFixture( + tempDir, + fixture.dataDir ? { dataDir: NodePath.join(tempDir, fixture.dataDir) } : {}, + ); const binaryPath = - fixture.via === "install" - ? mise.binaryPath + fixture.via === "latest" + ? mise.latestBinaryPath : linkShim(tempDir, mise.misePath, "package-tool"); const spawned: Array> = []; @@ -1227,6 +1264,34 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { { skip: !symlinksSupported || windowsHost }, ); + it.effect.skipIf(!symlinksSupported || windowsHost)( + "launches the upgraded version through mise's latest link", + () => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-upgraded"); + const mise = miseFixture(tempDir); + const resolve = () => + resolveProviderMaintenanceCapabilitiesEffect(miseToolUpdate, { + binaryPath: mise.latestBinaryPath, + env: { PATH: mise.miseBinDir }, + }).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner({ which: mise.binaryPath, installed: mise.installed() }, []), + ), + ); + expect((yield* resolve()).update).toMatchObject({ args: ["upgrade", "package-tool"] }); + + const upgraded = mise.install("1.1.0"); + NodeFS.rmSync(NodePath.join(tempDir, "mise", "installs", "package-tool", "1.0.0"), { + recursive: true, + }); + + expect(NodeFS.realpathSync(mise.latestBinaryPath)).toBe(NodeFS.realpathSync(upgraded)); + expect((yield* resolve()).update).toMatchObject({ args: ["upgrade", "package-tool"] }); + }), + ); + it.effect.each([ { name: "a pinned version", installed: { requested_version: "1.0.0" } }, { name: "an inactive install", installed: { active: false } }, @@ -1235,6 +1300,8 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { { name: "an install without mise on PATH", misePresent: false }, { name: "a provider with no mise tool", definition: "unmapped" }, { name: "a mise x wrapper", via: "wrapper" }, + { name: "a fixed version path", via: "versioned" }, + { name: "a version mise activate put on PATH", via: "activated" }, ] as const)( "leaves $name manual-only", (fixture) => @@ -1244,8 +1311,14 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { misePresent: !("misePresent" in fixture), tool: "tool" in fixture ? fixture.tool : "package-tool", }); - let binaryPath = mise.binaryPath; - if ("via" in fixture) { + let binaryPath = symlinksSupported ? mise.latestBinaryPath : mise.binaryPath; + let path = mise.miseBinDir; + if ("via" in fixture && fixture.via === "versioned") { + binaryPath = mise.binaryPath; + } else if ("via" in fixture && fixture.via === "activated") { + binaryPath = "package-tool"; + path = [NodePath.dirname(mise.binaryPath), mise.miseBinDir].join(NodePath.delimiter); + } else if ("via" in fixture) { binaryPath = NodePath.join(tempDir, "bin", "package-tool"); NodeFS.mkdirSync(NodePath.dirname(binaryPath), { recursive: true }); NodeFS.writeFileSync( @@ -1261,7 +1334,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect( "definition" in fixture ? packageToolUpdate : miseToolUpdate, - { binaryPath, env: { PATH: mise.miseBinDir } }, + { binaryPath, env: { PATH: path } }, ).pipe( Effect.provideService( ChildProcessSpawner.ChildProcessSpawner, @@ -1312,7 +1385,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { }), ); - it.effect.skipIf(windowsHost)( + it.effect.skipIf(!symlinksSupported || windowsHost)( "asks mise for its latest release only while update checks are enabled", () => Effect.gen(function* () { @@ -1320,7 +1393,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { const mise = miseFixture(tempDir); const spawned: Array> = []; const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(miseToolUpdate, { - binaryPath: mise.binaryPath, + binaryPath: mise.latestBinaryPath, env: { PATH: mise.miseBinDir }, }).pipe( Effect.provideService( @@ -1360,6 +1433,45 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { ), ); + it.effect.skipIf(!symlinksSupported || windowsHost)( + "keeps each mise environment's latest release apart", + () => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-latest-env"); + const mise = miseFixture(tempDir); + const advise = (env: NodeJS.ProcessEnv, latest: string) => + resolveProviderMaintenanceCapabilitiesEffect(miseToolUpdate, { + binaryPath: mise.latestBinaryPath, + env: { PATH: mise.miseBinDir, ...env }, + }).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner({ which: mise.binaryPath, latest, installed: mise.installed() }, []), + ), + Effect.flatMap((capabilities) => + enrichProviderSnapshotWithVersionAdvisory( + installedPackageToolProvider, + capabilities, + { + enableProviderUpdateChecks: true, + }, + ), + ), + Effect.map((snapshot) => snapshot.versionAdvisory?.latestVersion), + ); + + expect(yield* advise({ MISE_MINIMUM_RELEASE_AGE: "7d" }, "1.1.0")).toBe("1.1.0"); + expect(yield* advise({}, "1.2.0")).toBe("1.2.0"); + expect(yield* advise({ MISE_MINIMUM_RELEASE_AGE: "7d" }, "1.2.0")).toBe("1.1.0"); + }).pipe( + Effect.provide(ProviderLatestVersions.layer), + Effect.provideService( + HttpClient.HttpClient, + HttpClient.make(() => Effect.die("mise answers for its own installs")), + ), + ), + ); + it.effect.each([ { name: "fails", latest: { exitCode: 1 } }, { name: "prints nothing", latest: { stdout: "" } }, @@ -1371,7 +1483,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { const tempDir = yield* makeTempDir("t3-mise-latest-unknown"); const mise = miseFixture(tempDir); const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(miseToolUpdate, { - binaryPath: mise.binaryPath, + binaryPath: mise.latestBinaryPath, env: { PATH: mise.miseBinDir }, }).pipe( Effect.provideService( @@ -1402,7 +1514,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { HttpClient.make(() => Effect.die("an offline mise must not fall back to npm")), ), ), - { skip: windowsHost }, + { skip: !symlinksSupported || windowsHost }, ); it.effect.skipIf(!symlinksSupported)("updates Yarn global installs with yarn", () => diff --git a/packages/provider-core/src/server/maintenanceResolver.ts b/packages/provider-core/src/server/maintenanceResolver.ts index bf169c84ecd39..7ea65b583c714 100644 --- a/packages/provider-core/src/server/maintenanceResolver.ts +++ b/packages/provider-core/src/server/maintenanceResolver.ts @@ -1,3 +1,5 @@ +// @effect-diagnostics nodeBuiltinImport:off -- Synchronous hashing keeps env values out of cache keys. +import * as NodeCrypto from "node:crypto"; export type { ProviderMaintenanceCapabilities, ProviderMaintenanceCommandAction, @@ -453,9 +455,9 @@ function miseToolInstalls( } /** - * Null when mise does not own the executable. Mise must prove the rest: `mise which` runs it from - * an active install of `miseTool` requested as `latest`; anything else stays manual-only, so T3 - * Code never edits mise config. `miseTool` is the driver's fixed name, never mise's own output. + * Null when mise does not own the executable. Upgrades need an active `latest` install of the + * driver's fixed `miseTool`, launched through a shim or the `latest` link `mise upgrade` moves; + * a fixed version's path would keep running the pruned binary, so it stays manual-only. */ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMaintenance")( function* ( @@ -465,18 +467,18 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain ) { const commandPaths = [context.resolvedCommandPath, context.realCommandPath]; const isShim = isMiseExecutablePath(context.realCommandPath); - const isMise = isShim || commandPaths.some(isMiseCommandPath); - if (!isMise && !(yield* isMiseWrapperScript(context))) return null; + const looksMise = + isShim || commandPaths.some(isMiseCommandPath) || (yield* isMiseWrapperScript(context)); const manual = (installPath: string) => makeManualOnlyProviderMaintenanceCapabilities({ ...owner, installPath }); + const notOwned = (installPath: string) => (looksMise ? manual(installPath) : null); const commandName = normalizeCommandPath(context.resolvedCommandPath) .split("/") .at(-1) ?.replace(/\.(?:exe|cmd|bat|ps1)$/, ""); + if (!miseTool) return notOwned(context.realCommandPath); // A shim runs whatever mise resolves for its own name, which must be the mapped tool's. - if (!isMise || !miseTool || (isShim && commandName !== miseTool)) { - return manual(context.realCommandPath); - } + if (isShim && commandName !== miseTool) return manual(context.realCommandPath); const fileSystem = yield* FileSystem.FileSystem; const realPath = (target: string) => @@ -484,7 +486,8 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain const misePath = (yield* resolveCommandPath("mise", { env: context.env })) ?? (isShim ? context.realCommandPath : null); - if (!misePath) return manual(context.realCommandPath); + if (!misePath) return notOwned(context.realCommandPath); + // Asked even off mise's usual paths, since `MISE_DATA_DIR` can put installs anywhere. const which = nonEmptyString(yield* runProbe(misePath, ["which", miseTool], context.env)); const binaryPath = which ? yield* realPath(which) : null; // Through a shim T3 Code runs whatever mise resolves; otherwise mise must resolve this binary. @@ -493,7 +496,7 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain (!isShim && normalizeCommandPath(binaryPath) !== normalizeCommandPath(context.realCommandPath)) ) { - return manual(binaryPath ?? context.realCommandPath); + return notOwned(binaryPath ?? context.realCommandPath); } const listing = yield* runProbe( misePath, @@ -505,16 +508,23 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain (install) => install.active === true && install.requested_version === "latest", ) : []; - const installPaths = yield* Effect.forEach(candidates, (install) => - realPath(install.install_path), - ); const binary = normalizeCommandPath(binaryPath); - if ( - !installPaths.some((installPath) => - binary.startsWith(`${normalizeCommandPath(installPath).replace(/\/+$/, "")}/`), - ) - ) { - return manual(binaryPath); + const isUnder = (path: string, dir: string) => + path.startsWith(`${normalizeCommandPath(dir).replace(/\/+$/, "")}/`); + const owning = yield* Effect.filter(candidates, (install) => + realPath(install.install_path).pipe( + Effect.map((installPath) => isUnder(binary, installPath)), + ), + ); + const install = owning[0]; + if (!install) return manual(binaryPath); + if (!isShim) { + const toolDir = normalizeCommandPath(install.install_path) + .replace(/\/+$/, "") + .replace(/\/[^/]+$/, ""); + const latestDirs = [toolDir, yield* realPath(toolDir)].map((dir) => `${dir}/latest`); + const resolved = normalizeCommandPath(context.resolvedCommandPath); + if (!latestDirs.some((dir) => isUnder(resolved, dir))) return manual(binaryPath); } const args = ["upgrade", miseTool]; const services = yield* Effect.context(); @@ -960,9 +970,14 @@ const fetchNpmLatestVersion = Effect.fn("fetchNpmLatestVersion")(function* (pack /** The installer's own answer is cached apart from the npm registry entry. */ function installerLatestVersionKey(capabilities: ProviderMaintenanceCapabilities) { const update = capabilities.update; - return capabilities.lookupLatestVersion && update - ? [update.lockKey, update.executable, ...update.args].join("\0") + if (!capabilities.lookupLatestVersion || !update) return null; + // The installer reads its settings from this environment, so each one gets its own answer. + const env = update.env + ? NodeCrypto.createHash("sha256") + .update(JSON.stringify(Object.entries(update.env).toSorted(([a], [b]) => (a < b ? -1 : 1)))) + .digest("hex") : null; + return [update.lockKey, update.executable, ...update.args, ...(env ? [env] : [])].join("\0"); } export function latestProviderVersionCacheKeys( From bc19123f86864001238e8462de57faa1b22ef2f1 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 25 Oct 2026 22:04:18 +0000 Subject: [PATCH 09/12] fix(server): mise ownership no longer depends on upgrade eligibility OpenCode 1.x dropped its mise mapping to avoid upgrading across 2.x, so an install in a custom MISE_DATA_DIR fell through to `opencode upgrade`. Drivers now always name their mise tool and opt out of the upgrade separately. An npm global under mise's Node is resolved by `mise which` without being an install of the mapped tool; that no longer counts as mise ownership, so npm keeps updating it with its own --prefix. Co-Authored-By: Claude Opus 5.5 --- .../src/provider/Drivers/ClaudeDriver.ts | 2 +- .../src/provider/Drivers/CodexDriver.ts | 2 +- .../src/server/maintenanceResolver.test.ts | 87 ++++++++++++++++++- .../src/server/maintenanceResolver.ts | 33 ++++--- packages/provider-grok/src/server/driver.ts | 2 +- .../provider-muse/src/server/maintenance.ts | 2 +- .../provider-opencode/src/server/driver.ts | 2 +- packages/provider-pi/src/server/driver.ts | 2 +- 8 files changed, 111 insertions(+), 21 deletions(-) diff --git a/apps/server/src/provider/Drivers/ClaudeDriver.ts b/apps/server/src/provider/Drivers/ClaudeDriver.ts index f2ff273d6816c..d732b3e9be6e5 100644 --- a/apps/server/src/provider/Drivers/ClaudeDriver.ts +++ b/apps/server/src/provider/Drivers/ClaudeDriver.ts @@ -84,7 +84,7 @@ function isClaudeNativeCommandPath(commandPath: string): boolean { const UPDATE = makePackageManagedProviderMaintenanceResolver({ provider: DRIVER_KIND, npmPackageName: "@anthropic-ai/claude-code", - miseTool: "claude", + mise: { tool: "claude" }, nativeUpdate: { args: ["update"], isCommandPath: isClaudeNativeCommandPath, diff --git a/apps/server/src/provider/Drivers/CodexDriver.ts b/apps/server/src/provider/Drivers/CodexDriver.ts index 6db17c4e9278c..f154b41e464bc 100644 --- a/apps/server/src/provider/Drivers/CodexDriver.ts +++ b/apps/server/src/provider/Drivers/CodexDriver.ts @@ -69,7 +69,7 @@ function makeCodexMaintenanceResolver(sharedHomePath: string) { return makePackageManagedProviderMaintenanceResolver({ provider: DRIVER_KIND, npmPackageName: "@openai/codex", - miseTool: "codex", + mise: { tool: "codex" }, nativeUpdate: { args: ["update"], isCommandPath: isCodexStandaloneCommandPath, diff --git a/packages/provider-core/src/server/maintenanceResolver.test.ts b/packages/provider-core/src/server/maintenanceResolver.test.ts index 7cfee05408430..82e0f515337f1 100644 --- a/packages/provider-core/src/server/maintenanceResolver.test.ts +++ b/packages/provider-core/src/server/maintenanceResolver.test.ts @@ -64,7 +64,7 @@ const nativePackageToolUpdate = makePackageManagedProviderMaintenanceResolver({ const miseToolUpdate = makePackageManagedProviderMaintenanceResolver({ provider: driver("packageTool"), npmPackageName: "@example/package-tool", - miseTool: "package-tool", + mise: { tool: "package-tool" }, nativeUpdate: null, }); const installedPackageToolProvider: ServerProvider = { @@ -1364,7 +1364,7 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { const miseMappedNative = makePackageManagedProviderMaintenanceResolver({ provider: driver("nativePackageTool"), npmPackageName: "@example/native-package-tool", - miseTool: "native-package-tool", + mise: { tool: "native-package-tool" }, nativeUpdate: { args: ["update"], isCommandPath: isNativeTestCommandPath("/.local/bin/native-package-tool"), @@ -1385,6 +1385,89 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { }), ); + it.effect.each([ + { + name: "a mise tool whose upgrades are disabled", + mise: { tool: "package-tool", upgrade: false }, + }, + { name: "a pinned mise tool", mise: { tool: "package-tool" }, pinned: true }, + ] as const)( + "keeps $name in a custom data dir manual-only instead of running its own updater", + (fixture) => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-custom-manual"); + const mise = miseFixture(tempDir, { dataDir: NodePath.join(tempDir, "data") }); + const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect( + makePackageManagedProviderMaintenanceResolver({ + provider: driver("packageTool"), + npmPackageName: "@example/package-tool", + mise: fixture.mise, + nativeUpdate: { args: ["upgrade"] }, + }), + { binaryPath: mise.latestBinaryPath, env: { PATH: mise.miseBinDir } }, + ).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + miseSpawner( + { + which: mise.binaryPath, + installed: mise.installed( + "pinned" in fixture ? { requested_version: "1.0.0" } : {}, + ), + }, + [], + ), + ), + ); + + expect(capabilities.update).toBeNull(); + }), + { skip: !symlinksSupported || windowsHost }, + ); + + it.effect.skipIf(!symlinksSupported || windowsHost)( + "updates an npm global under mise's Node with npm even when mise runs it", + () => + Effect.gen(function* () { + const tempDir = yield* makeTempDir("t3-mise-node-npm"); + const mise = miseFixture(tempDir); + const nodePrefix = NodePath.join(tempDir, "mise", "installs", "node", "22.0.0"); + const binaryPath = NodePath.join(nodePrefix, "bin", "package-tool"); + const target = NodePath.join( + nodePrefix, + "lib", + "node_modules", + "@example", + "package-tool", + "bin", + "package-tool.js", + ); + writeExecutable(target); + NodeFS.mkdirSync(NodePath.dirname(binaryPath), { recursive: true }); + NodeFS.symlinkSync(target, binaryPath); + + const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(miseToolUpdate, { + binaryPath, + env: { PATH: mise.miseBinDir }, + }).pipe( + Effect.provideService( + ChildProcessSpawner.ChildProcessSpawner, + // mise resolves the npm global through its Node; no `package-tool` tool is installed. + miseSpawner({ which: binaryPath, installed: {} }, []), + ), + ); + + expect(capabilities.update?.args).toEqual([ + "install", + "-g", + "--prefix", + NodeFS.realpathSync(nodePrefix), + "--allow-scripts=@example/package-tool", + "@example/package-tool@latest", + ]); + }), + ); + it.effect.skipIf(!symlinksSupported || windowsHost)( "asks mise for its latest release only while update checks are enabled", () => diff --git a/packages/provider-core/src/server/maintenanceResolver.ts b/packages/provider-core/src/server/maintenanceResolver.ts index 7ea65b583c714..5c911a3f7ad85 100644 --- a/packages/provider-core/src/server/maintenanceResolver.ts +++ b/packages/provider-core/src/server/maintenanceResolver.ts @@ -92,7 +92,13 @@ export interface PackageManagedProviderMaintenanceDefinition { readonly env?: NodeJS.ProcessEnv; } | null; /** The mise registry tool that installs this provider; unset keeps mise installs manual-only. */ - readonly miseTool?: string; + readonly mise?: MiseProviderTool; +} + +export interface MiseProviderTool { + readonly tool: string; + /** False still claims the tool's installs, but keeps them manual-only. */ + readonly upgrade?: boolean; } const NpmLatestVersionResponse = Schema.Struct({ @@ -456,13 +462,13 @@ function miseToolInstalls( /** * Null when mise does not own the executable. Upgrades need an active `latest` install of the - * driver's fixed `miseTool`, launched through a shim or the `latest` link `mise upgrade` moves; + * driver's fixed mise tool, launched through a shim or the `latest` link `mise upgrade` moves; * a fixed version's path would keep running the pruned binary, so it stays manual-only. */ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMaintenance")( function* ( owner: { readonly provider: ProviderDriverKind; readonly packageName: string | null }, - miseTool: string | undefined, + mise: MiseProviderTool | undefined, context: ProviderMaintenanceResolutionContext, ) { const commandPaths = [context.resolvedCommandPath, context.realCommandPath]; @@ -476,7 +482,8 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain .split("/") .at(-1) ?.replace(/\.(?:exe|cmd|bat|ps1)$/, ""); - if (!miseTool) return notOwned(context.realCommandPath); + if (!mise) return notOwned(context.realCommandPath); + const miseTool = mise.tool; // A shim runs whatever mise resolves for its own name, which must be the mapped tool's. if (isShim && commandName !== miseTool) return manual(context.realCommandPath); @@ -503,21 +510,21 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain ["ls", "--json", "--installed", miseTool], context.env, ); - const candidates = listing - ? miseToolInstalls(listing, miseTool).filter( - (install) => install.active === true && install.requested_version === "latest", - ) - : []; + if (!listing) return manual(binaryPath); const binary = normalizeCommandPath(binaryPath); const isUnder = (path: string, dir: string) => path.startsWith(`${normalizeCommandPath(dir).replace(/\/+$/, "")}/`); - const owning = yield* Effect.filter(candidates, (install) => + const owning = yield* Effect.filter(miseToolInstalls(listing, miseTool), (install) => realPath(install.install_path).pipe( Effect.map((installPath) => isUnder(binary, installPath)), ), ); - const install = owning[0]; - if (!install) return manual(binaryPath); + // `mise which` also resolves binaries from other tools, such as npm globals under mise's Node. + if (owning.length === 0) return notOwned(binaryPath); + const install = owning.find( + (candidate) => candidate.active === true && candidate.requested_version === "latest", + ); + if (!install || mise.upgrade === false) return manual(binaryPath); if (!isShim) { const toolDir = normalizeCommandPath(install.install_path) .replace(/\/+$/, "") @@ -581,7 +588,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn( const mise = yield* resolveMiseProviderMaintenance( { provider: definition.provider, packageName }, - definition.miseTool, + definition.mise, context, ); if (mise) return mise; diff --git a/packages/provider-grok/src/server/driver.ts b/packages/provider-grok/src/server/driver.ts index 955b9cb932961..11fea7c49a627 100644 --- a/packages/provider-grok/src/server/driver.ts +++ b/packages/provider-grok/src/server/driver.ts @@ -64,7 +64,7 @@ const UPDATE: ProviderMaintenanceCapabilitiesResolver = { } const mise = yield* resolveMiseProviderMaintenance( { provider: DRIVER_KIND, packageName: GROK_NPM_PACKAGE }, - "grok", + { tool: "grok" }, context, ); if (mise) return mise; diff --git a/packages/provider-muse/src/server/maintenance.ts b/packages/provider-muse/src/server/maintenance.ts index 46ffee6b993d4..342e91638b830 100644 --- a/packages/provider-muse/src/server/maintenance.ts +++ b/packages/provider-muse/src/server/maintenance.ts @@ -51,7 +51,7 @@ export const museMaintenance: ProviderMaintenanceCapabilitiesResolver = { if (!context || context.platform === "win32") return manual; const mise = yield* resolveMiseProviderMaintenance( { provider: DRIVER, packageName: null }, - "muse", + { tool: "muse" }, context, ); if (mise) return { ...mise, compareVersions: compareMuseVersions }; diff --git a/packages/provider-opencode/src/server/driver.ts b/packages/provider-opencode/src/server/driver.ts index 2b11c2b7425e1..d4e0ddc0da747 100644 --- a/packages/provider-opencode/src/server/driver.ts +++ b/packages/provider-opencode/src/server/driver.ts @@ -85,7 +85,7 @@ export const openCodeUpdateFor = (generation: ProbedOpenCode["generation"]) => isCommandPath: isOpenCodeNativeCommandPath, }, // mise's `opencode` follows releases into 2.x, so it would upgrade 1.x across that line. - ...(generation === "v2" ? { miseTool: "opencode" } : {}), + mise: { tool: "opencode", upgrade: generation === "v2" }, }); type OpenCodeRuntimeProbe = Effect.Success< diff --git a/packages/provider-pi/src/server/driver.ts b/packages/provider-pi/src/server/driver.ts index 7a533614b6999..9f32de9d29c4d 100644 --- a/packages/provider-pi/src/server/driver.ts +++ b/packages/provider-pi/src/server/driver.ts @@ -45,7 +45,7 @@ const DRIVER_KIND = ProviderDriverKind.make("pi"); const UPDATE = makePackageManagedProviderMaintenanceResolver({ provider: DRIVER_KIND, npmPackageName: "@earendil-works/pi-coding-agent", - miseTool: "pi", + mise: { tool: "pi" }, nativeUpdate: { args: ["update", "--self"] }, }); From e077d39f9de498a56b80ac42b0bac2b9eb517c97 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 25 Oct 2026 22:10:41 +0000 Subject: [PATCH 10/12] fix(server): inactive mise installs of a configured binary stay manual-only A custom binary path pointing at an inactive mise install was treated as not owned whenever `mise which` resolved a different active version, so the provider's own updater was offered. Ownership now checks the configured binary against `mise ls` before anything else; an owned binary mise does not currently run stays manual-only. Co-Authored-By: Claude Opus 5.5 --- .../src/server/maintenanceResolver.test.ts | 31 +++++++++++++------ .../src/server/maintenanceResolver.ts | 20 ++++++------ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/packages/provider-core/src/server/maintenanceResolver.test.ts b/packages/provider-core/src/server/maintenanceResolver.test.ts index 82e0f515337f1..a4d7a3eac008d 100644 --- a/packages/provider-core/src/server/maintenanceResolver.test.ts +++ b/packages/provider-core/src/server/maintenanceResolver.test.ts @@ -1391,12 +1391,31 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { mise: { tool: "package-tool", upgrade: false }, }, { name: "a pinned mise tool", mise: { tool: "package-tool" }, pinned: true }, + { + name: "an inactive version of a mise tool", + mise: { tool: "package-tool" }, + inactive: true, + }, + { + name: "an inactive version of a mise tool whose upgrades are disabled", + mise: { tool: "package-tool", upgrade: false }, + inactive: true, + }, ] as const)( "keeps $name in a custom data dir manual-only instead of running its own updater", (fixture) => Effect.gen(function* () { const tempDir = yield* makeTempDir("t3-mise-custom-manual"); const mise = miseFixture(tempDir, { dataDir: NodePath.join(tempDir, "data") }); + let binaryPath = mise.latestBinaryPath; + let installed = mise.installed("pinned" in fixture ? { requested_version: "1.0.0" } : {}); + if ("inactive" in fixture) { + // Configured to 1.0.0 while mise resolves its active 2.0.0 instead. + binaryPath = mise.binaryPath; + const inactive = { ...installed["package-tool"]![0]!, active: false }; + mise.install("2.0.0"); + installed = { "package-tool": [inactive, ...mise.installed()["package-tool"]!] }; + } const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect( makePackageManagedProviderMaintenanceResolver({ provider: driver("packageTool"), @@ -1404,19 +1423,11 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => { mise: fixture.mise, nativeUpdate: { args: ["upgrade"] }, }), - { binaryPath: mise.latestBinaryPath, env: { PATH: mise.miseBinDir } }, + { binaryPath, env: { PATH: mise.miseBinDir } }, ).pipe( Effect.provideService( ChildProcessSpawner.ChildProcessSpawner, - miseSpawner( - { - which: mise.binaryPath, - installed: mise.installed( - "pinned" in fixture ? { requested_version: "1.0.0" } : {}, - ), - }, - [], - ), + miseSpawner({ which: mise.binaryPath, installed }, []), ), ); diff --git a/packages/provider-core/src/server/maintenanceResolver.ts b/packages/provider-core/src/server/maintenanceResolver.ts index 5c911a3f7ad85..0907d562ebb46 100644 --- a/packages/provider-core/src/server/maintenanceResolver.ts +++ b/packages/provider-core/src/server/maintenanceResolver.ts @@ -496,24 +496,21 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain if (!misePath) return notOwned(context.realCommandPath); // Asked even off mise's usual paths, since `MISE_DATA_DIR` can put installs anywhere. const which = nonEmptyString(yield* runProbe(misePath, ["which", miseTool], context.env)); - const binaryPath = which ? yield* realPath(which) : null; - // Through a shim T3 Code runs whatever mise resolves; otherwise mise must resolve this binary. - if ( - !binaryPath || - (!isShim && - normalizeCommandPath(binaryPath) !== normalizeCommandPath(context.realCommandPath)) - ) { - return notOwned(binaryPath ?? context.realCommandPath); - } + const resolvedPath = which ? yield* realPath(which) : null; + // Through a shim T3 Code runs whatever mise resolves; otherwise the configured binary. + const binaryPath = isShim ? resolvedPath : context.realCommandPath; + if (!binaryPath) return manual(context.realCommandPath); + const binary = normalizeCommandPath(binaryPath); + const runsBinary = resolvedPath !== null && normalizeCommandPath(resolvedPath) === binary; const listing = yield* runProbe( misePath, ["ls", "--json", "--installed", miseTool], context.env, ); - if (!listing) return manual(binaryPath); - const binary = normalizeCommandPath(binaryPath); + if (!listing) return runsBinary ? manual(binaryPath) : notOwned(binaryPath); const isUnder = (path: string, dir: string) => path.startsWith(`${normalizeCommandPath(dir).replace(/\/+$/, "")}/`); + // An inactive or shadowed install is still mise's, even when `mise which` resolves another. const owning = yield* Effect.filter(miseToolInstalls(listing, miseTool), (install) => realPath(install.install_path).pipe( Effect.map((installPath) => isUnder(binary, installPath)), @@ -521,6 +518,7 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain ); // `mise which` also resolves binaries from other tools, such as npm globals under mise's Node. if (owning.length === 0) return notOwned(binaryPath); + if (!runsBinary) return manual(binaryPath); const install = owning.find( (candidate) => candidate.active === true && candidate.requested_version === "latest", ); From 80b1280b4e3ac6abefbeb5d836429db154ea23f1 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Sun, 8 Nov 2026 05:13:34 -0800 Subject: [PATCH 11/12] fix(server): key mise latest-version lookups on the instance environment Main now caches installer lookups by latestVersionCacheKey, so the mise path sets its own key instead of changing the shared key function. Co-Authored-By: Ryan Hughes Co-Authored-By: Claude Opus 5.5 --- .../provider-core/src/server/maintenanceResolver.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/provider-core/src/server/maintenanceResolver.ts b/packages/provider-core/src/server/maintenanceResolver.ts index 329dbecc9844a..1f75dbe27ef3e 100644 --- a/packages/provider-core/src/server/maintenanceResolver.ts +++ b/packages/provider-core/src/server/maintenanceResolver.ts @@ -576,9 +576,13 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain const args = ["upgrade", miseTool]; const services = yield* Effect.context(); // Mise reads its settings from this environment, so each one gets its own cached answer. - const envKey = NodeCrypto.createHash("sha256") - .update(JSON.stringify(Object.entries(context.env).toSorted(([a], [b]) => (a < b ? -1 : 1)))) - .digest("hex"); + const envHash = NodeCrypto.createHash("sha256"); + for (const [name, value] of Object.entries(context.env).toSorted(([a], [b]) => + a < b ? -1 : 1, + )) { + envHash.update(`${name}\0${value ?? ""}\0`); + } + const envKey = envHash.digest("hex"); const capabilities = makeProviderMaintenanceCapabilities({ ...owner, updateExecutable: misePath, From abf5e5dbe771911ccecd623fe7b9dbc32b288049 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Sun, 8 Nov 2026 05:17:54 -0800 Subject: [PATCH 12/12] fix(server): mise latest-link check keeps the install path's case Also drop a test that only re-checked its fixture's own symlink move. Co-Authored-By: Ryan Hughes Co-Authored-By: Claude Opus 5.5 --- .../src/server/maintenanceResolver.test.ts | 28 ------------------- .../src/server/maintenanceResolver.ts | 4 ++- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/packages/provider-core/src/server/maintenanceResolver.test.ts b/packages/provider-core/src/server/maintenanceResolver.test.ts index 83b3176f309bd..e5298def7f0da 100644 --- a/packages/provider-core/src/server/maintenanceResolver.test.ts +++ b/packages/provider-core/src/server/maintenanceResolver.test.ts @@ -1649,34 +1649,6 @@ it.layer( { skip: !symlinksSupported || windowsHost }, ); - it.effect.skipIf(!symlinksSupported || windowsHost)( - "launches the upgraded version through mise's latest link", - () => - Effect.gen(function* () { - const tempDir = yield* makeTempDir("t3-mise-upgraded"); - const mise = miseFixture(tempDir); - const resolve = () => - resolveProviderMaintenanceCapabilitiesEffect(miseToolUpdate, { - binaryPath: mise.latestBinaryPath, - env: { PATH: mise.miseBinDir }, - }).pipe( - Effect.provideService( - ChildProcessSpawner.ChildProcessSpawner, - miseSpawner({ which: mise.binaryPath, installed: mise.installed() }, []), - ), - ); - expect((yield* resolve()).update).toMatchObject({ args: ["upgrade", "package-tool"] }); - - const upgraded = mise.install("1.1.0"); - NodeFS.rmSync(NodePath.join(tempDir, "mise", "installs", "package-tool", "1.0.0"), { - recursive: true, - }); - - expect(NodeFS.realpathSync(mise.latestBinaryPath)).toBe(NodeFS.realpathSync(upgraded)); - expect((yield* resolve()).update).toMatchObject({ args: ["upgrade", "package-tool"] }); - }), - ); - it.effect.each([ { name: "a pinned version", installed: { requested_version: "1.0.0" } }, { name: "an inactive install", installed: { active: false } }, diff --git a/packages/provider-core/src/server/maintenanceResolver.ts b/packages/provider-core/src/server/maintenanceResolver.ts index 1f75dbe27ef3e..bb60e8e865714 100644 --- a/packages/provider-core/src/server/maintenanceResolver.ts +++ b/packages/provider-core/src/server/maintenanceResolver.ts @@ -566,7 +566,9 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain ); if (!install || mise.upgrade === false) return manual(binaryPath); if (!isShim) { - const toolDir = normalizeCommandPath(install.install_path) + // Keep the path's case: `realPath` needs it on case-sensitive filesystems. + const toolDir = install.install_path + .replaceAll("\\", "/") .replace(/\/+$/, "") .replace(/\/[^/]+$/, ""); const latestDirs = [toolDir, yield* realPath(toolDir)].map((dir) => `${dir}/latest`);