@devries-cameron20 / t3code Mirror · read-only / commits / 393a9f8950
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 03:00 UTC

fix(grok): a Homebrew-installed Grok updates through brew and is compared against the cask (#18772)

Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

Igor Makowski committed Oct 19, 2026 at 06:53 UTC 393a9f8950f4a2fe5685c5702d43b1539cf09650
4 files changed +198 -34
docs/internals/providers.md
+2 -1
@@ -89,7 +89,8 @@ symlinks there. Volta is proven by its `volta-shim` link plus the package's imag
89 nothing is proven, the provider's own updater (`claude update`, `codex update`, `opencode upgrade`,
90 `pi update --self`, `grok update`) runs instead, because each one detects its installer itself;
91 the runner's version check catches an updater that exits 0 without updating. Mise installs stay
92 -manual-only because their version is pinned in mise's config. npm updates pin `--prefix` because the
92 +manual-only because their version is pinned in mise's config. A Grok cask whose Homebrew prefix
93 +cannot be verified also stays manual-only: `grok update` would install a second copy. npm updates pin `--prefix` because the
94 `npm` on `PATH` can belong to a different Node than the one that owns the provider. Homebrew
95 compares against `brew info` since casks trail npm by hours; native installs share npm's version
96 train, so the registry stays authoritative for them.
packages/provider-core/src/server/maintenanceResolver.ts
+36 -15
@@ -485,16 +485,39 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
485 });
486 }
487
488 - if (commandPaths.some(isMiseCommandPath) || (yield* isMiseWrapperScript(context))) {
488 + const homebrew = homebrewOwnershipFromCommandPath(context.realCommandPath);
489 + if (
490 + commandPaths.some(isMiseCommandPath) ||
491 + // Mise shims resolve to the version manager's keg, not the provider's.
492 + (homebrew?.kind === "formula" && homebrew.name.toLowerCase() === "mise") ||
493 + (yield* isMiseWrapperScript(context))
494 + ) {
495 return manual;
496 }
491 -
492 - const homebrew = homebrewOwnershipFromCommandPath(context.realCommandPath);
497 if (homebrew) {
494 - // Mise shims resolve to the version manager, not the provider.
495 - if (homebrew.kind === "formula" && homebrew.name.toLowerCase() === "mise") {
496 - return manual;
497 - }
498 + return (
499 + (yield* resolveHomebrewProviderMaintenance(
500 + { provider: definition.provider, packageName },
501 + homebrew,
502 + context,
503 + )) ?? fallback
504 + );
505 + }
506 +
507 + return fallback;
508 +});
509 +
510 +/**
511 + * `brew upgrade` capabilities once the keg's prefix is confirmed by a `brew`
512 + * that reports it as its own, with `latestVersion` from `brew info`. Null when
513 + * no `brew` is found or it owns another prefix.
514 + */
515 +export const resolveHomebrewProviderMaintenance = Effect.fn("resolveHomebrewProviderMaintenance")(
516 + function* (
517 + input: { readonly provider: ProviderDriverKind; readonly packageName: string | null },
518 + homebrew: HomebrewOwnership,
519 + context: ProviderMaintenanceResolutionContext,
520 + ) {
521 const fileSystem = yield* FileSystem.FileSystem;
522 const path = yield* Path.Path;
523 // The keg's own brew works even when a GUI-launched server has no
@@ -504,7 +527,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
527 ? kegBrewPath
528 : yield* resolveCommandPath("brew", { env: context.env });
529 if (!brewPath) {
507 - return fallback;
530 + return null;
531 }
532 const brewPrefix = nonEmptyString(yield* runProbe(brewPath, ["--prefix"], context.env));
533 const realBrewPrefix = brewPrefix
@@ -514,7 +537,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
537 !realBrewPrefix ||
538 normalizeCommandPath(realBrewPrefix) !== normalizeCommandPath(homebrew.prefix)
539 ) {
517 - return fallback;
540 + return null;
541 }
542 const args =
543 homebrew.kind === "cask" ? ["upgrade", "--cask", homebrew.name] : ["upgrade", homebrew.name];
@@ -522,18 +545,16 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
545 // `brew upgrade` can actually deliver.
546 const info = yield* runProbe(brewPath, ["info", "--json=v2", homebrew.name], context.env);
547 return makeProviderMaintenanceCapabilities({
525 - provider: definition.provider,
526 - packageName,
548 + provider: input.provider,
549 + packageName: input.packageName,
550 updateExecutable: brewPath,
551 updateArgs: args,
552 updateLockKey: "homebrew",
553 updateCommand: ["brew", ...args].join(" "),
554 latestVersion: info ? parseHomebrewLatestVersion(info, homebrew) : null,
555 });
533 - }
534 -
535 - return fallback;
536 -});
556 + },
557 +);
558
559 const isMiseWrapperScript = Effect.fn("isMiseWrapperScript")(function* (
560 context: ProviderMaintenanceResolutionContext,
packages/provider-grok/src/server/driver.test.ts
+122
@@ -6,6 +6,8 @@ import * as Effect from "effect/Effect";
6 import * as FileSystem from "effect/FileSystem";
7 import * as Layer from "effect/Layer";
8 import * as Path from "effect/Path";
9 +import * as Sink from "effect/Sink";
10 +import * as Stream from "effect/Stream";
11 import * as HttpClient from "effect/http/HttpClient";
12 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
13
@@ -40,6 +42,31 @@ const noSpawner = ChildProcessSpawner.make(() =>
42 Effect.die("Disabled Grok must not spawn a process"),
43 );
44
45 +/** Answers every spawn with `onSpawn(command, args)` on stdout, like a stub `brew`. */
46 +function stdoutSpawner(onSpawn: (command: string, args: ReadonlyArray<string>) => string) {
47 + return ChildProcessSpawner.make((command) => {
48 + const { command: executable, args } = command as unknown as {
49 + readonly command: string;
50 + readonly args: ReadonlyArray<string>;
51 + };
52 + return Effect.succeed(
53 + ChildProcessSpawner.makeHandle({
54 + pid: ChildProcessSpawner.ProcessId(1),
55 + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
56 + isRunning: Effect.succeed(false),
57 + kill: () => Effect.void,
58 + unref: Effect.succeed(Effect.void),
59 + stdin: Sink.drain,
60 + stdout: Stream.encodeText(Stream.make(onSpawn(executable, args))),
61 + stderr: Stream.empty,
62 + all: Stream.empty,
63 + getInputFd: () => Sink.drain,
64 + getOutputFd: () => Stream.empty,
65 + }),
66 + );
67 + });
68 +}
69 +
70 // The `#!/bin/sh` stub below cannot be resolved as an executable on Windows.
71 const windowsHost = HostProcess.Platform.defaultValue() === "win32";
72
@@ -77,6 +104,101 @@ it.layer(layerTest)("GrokDriver", (it) => {
104 ),
105 );
106
107 + // Each case puts a stub `brew` at `<prefix>/bin/brew` beside the Grok binary.
108 + const homebrewCases = [
109 + {
110 + name: "upgrades a Homebrew grok-build cask through brew",
111 + binary: ["Caskroom", "grok-build", "1.2.3,456", "grok"],
112 + reportedPrefix: "own",
113 + brewArgs: [["--prefix"], ["info", "--json=v2", "grok-build"]],
114 + latestVersion: "1.2.4",
115 + update: (brewPath: string, _binaryPath: string) => ({
116 + command: "brew upgrade --cask grok-build",
117 + executable: brewPath,
118 + args: ["upgrade", "--cask", "grok-build"],
119 + lockKey: "homebrew",
120 + }),
121 + },
122 + {
123 + // `grok update` would install a second copy beside the cask.
124 + name: "stays manual-only for a cask another brew prefix owns",
125 + binary: ["Caskroom", "grok-build", "1.2.3", "grok"],
126 + reportedPrefix: "/opt/homebrew",
127 + brewArgs: [["--prefix"]],
128 + latestVersion: undefined,
129 + update: () => null,
130 + },
131 + {
132 + // A formula keg such as `node` holding an npm global is not Grok's owner.
133 + name: "keeps grok update for an npm global inside a Homebrew node keg",
134 + binary: [
135 + "Cellar",
136 + "node",
137 + "22",
138 + "lib",
139 + "node_modules",
140 + "@xai-official",
141 + "grok",
142 + "bin",
143 + "grok",
144 + ],
145 + reportedPrefix: "own",
146 + brewArgs: [],
147 + latestVersion: undefined,
148 + update: (_brewPath: string, binaryPath: string) => ({
149 + executable: binaryPath,
150 + args: ["update"],
151 + lockKey: "grok",
152 + }),
153 + },
154 + ] as const;
155 +
156 + for (const testCase of homebrewCases) {
157 + it.effect.skipIf(windowsHost)(testCase.name, () => {
158 + const brewArgs: Array<ReadonlyArray<string>> = [];
159 + let prefix = "";
160 + return Effect.gen(function* () {
161 + const fs = yield* FileSystem.FileSystem;
162 + const path = yield* Path.Path;
163 + prefix = yield* fs.realPath(yield* fs.makeTempDirectoryScoped({ prefix: "t3-grok-brew-" }));
164 + const brewPath = path.join(prefix, "bin", "brew");
165 + const binaryPath = path.join(prefix, ...testCase.binary);
166 + for (const executable of [brewPath, binaryPath]) {
167 + yield* fs.makeDirectory(path.dirname(executable), { recursive: true });
168 + yield* fs.writeFileString(executable, "#!/bin/sh\n");
169 + yield* fs.chmod(executable, 0o755);
170 + }
171 +
172 + const instance = yield* GrokDriver.create({
173 + instanceId: ProviderInstanceId.make("grok-homebrew"),
174 + displayName: "Grok test",
175 + enabled: false,
176 + environment: [],
177 + config: { ...GrokDriver.defaultConfig(), binaryPath },
178 + });
179 + const capabilities = yield* instance.snapshot.resolveMaintenance();
180 +
181 + const update = testCase.update(brewPath, binaryPath);
182 + expect(brewArgs).toEqual(testCase.brewArgs);
183 + expect(capabilities.latestVersion).toBe(testCase.latestVersion);
184 + expect(capabilities.update).toEqual(update && expect.objectContaining(update));
185 + }).pipe(
186 + Effect.provideService(
187 + ChildProcessSpawner.ChildProcessSpawner,
188 + stdoutSpawner((command, args) => {
189 + expect(command).toBe(`${prefix}/bin/brew`);
190 + brewArgs.push(args);
191 + if (args[0] === "--prefix") {
192 + return `${testCase.reportedPrefix === "own" ? prefix : testCase.reportedPrefix}\n`;
193 + }
194 + return JSON.stringify({ casks: [{ version: "1.2.4,789" }] });
195 + }),
196 + ),
197 + Effect.scoped,
198 + );
199 + });
200 + }
201 +
202 it.effect("stays manual-only when the configured executable does not exist", () =>
203 Effect.gen(function* () {
204 const fs = yield* FileSystem.FileSystem;
packages/provider-grok/src/server/driver.ts
+38 -18
@@ -31,10 +31,12 @@ import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIden
31 import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
32 import { discoverGrokSkills } from "./skills.ts";
33 import {
34 + homebrewOwnershipFromCommandPath,
35 makeCachedProviderMaintenanceResolution,
36 makeManualOnlyProviderMaintenanceCapabilities,
37 makeProviderMaintenanceCapabilities,
38 type ProviderMaintenanceCapabilitiesResolver,
39 + resolveHomebrewProviderMaintenance,
40 resolveProviderMaintenanceCapabilitiesEffect,
41 } from "@t3tools/provider-core/server/maintenanceResolver";
42 import {
@@ -50,25 +52,43 @@ const DRIVER_KIND = ProviderDriverKind.make("grok");
52 const GROK_NPM_PACKAGE = "@xai-official/grok";
53 // `grok update` finds the installer that owns the binary itself, so the
54 // resolved executable is its own updater. It installs under `GROK_HOME`, so it
53 -// runs with the instance's environment.
55 +// runs with the instance's environment. The exception is a Homebrew cask
56 +// (normally `grok-build`), which brew upgrades and versions: `grok update` would install
57 +// a second copy beside it, so a cask its brew cannot vouch for stays manual.
58 const UPDATE: ProviderMaintenanceCapabilitiesResolver = {
55 - resolve: (context) =>
56 - Effect.succeed(
57 - context
58 - ? makeProviderMaintenanceCapabilities({
59 - provider: DRIVER_KIND,
60 - packageName: GROK_NPM_PACKAGE,
61 - updateExecutable: context.resolvedCommandPath,
62 - updateArgs: ["update"],
63 - updateLockKey: "grok",
64 - platform: context.platform,
65 - env: context.env,
66 - })
67 - : makeManualOnlyProviderMaintenanceCapabilities({
68 - provider: DRIVER_KIND,
69 - packageName: GROK_NPM_PACKAGE,
70 - }),
71 - ),
59 + resolve: Effect.fn("resolveGrokMaintenance")(function* (context) {
60 + if (!context) {
61 + return makeManualOnlyProviderMaintenanceCapabilities({
62 + provider: DRIVER_KIND,
63 + packageName: GROK_NPM_PACKAGE,
64 + });
65 + }
66 + const homebrew = homebrewOwnershipFromCommandPath(context.realCommandPath);
67 + // Only a cask is Grok's: a formula keg such as `node` holding an npm global is not.
68 + if (homebrew?.kind === "cask") {
69 + return (
70 + (yield* resolveHomebrewProviderMaintenance(
71 + { provider: DRIVER_KIND, packageName: GROK_NPM_PACKAGE },
72 + homebrew,
73 + context,
74 + )) ??
75 + makeManualOnlyProviderMaintenanceCapabilities({
76 + provider: DRIVER_KIND,
77 + packageName: GROK_NPM_PACKAGE,
78 + installPath: context.realCommandPath,
79 + })
80 + );
81 + }
82 + return makeProviderMaintenanceCapabilities({
83 + provider: DRIVER_KIND,
84 + packageName: GROK_NPM_PACKAGE,
85 + updateExecutable: context.resolvedCommandPath,
86 + updateArgs: ["update"],
87 + updateLockKey: "grok",
88 + platform: context.platform,
89 + env: context.env,
90 + });
91 + }),
92 };
93
94 export type GrokDriverEnv =