fix(server): resolve Node for standalone helper scripts #12033
Mergedjuliusmarmingemerged 4 commits into
main fromrefs/pull/12033/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- packages/shared/src/nodeRuntime.ts line 59Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +24,21 @@24+ feature: string,25+ environment?: NodeJS.ProcessEnv,26+) {27+ const executablePath = yield* HostProcessExecutablePath;28+ if (!(yield* HostProcessIsExecutable)) return executablePath;29+30+ const fs = yield* FileSystem.FileSystem;31+ const path = yield* Path.Path;32+ const nodePath = yield* resolveCommandPath("node", {33+ env: environment ?? (yield* HostProcessEnvironment),34+ }).pipe(35+ // Refresh immediately after the user installs Node and retries setup.36+ Effect.provideService(CommandResolutionCache, new Map()),37+ Effect.map((commandPath) => path.resolve(commandPath)),38+ Effect.mapError((cause) => new NodeRuntimeUnavailableError({ feature, cause })),39+ );40+ // A launcher or symlink named node must not point back at the standalone app.41+ const resolvedPath = yield* fs42+ .realPath(nodePath)43+ .pipe(Effect.mapError((cause) => new NodeRuntimeUnavailableError({ feature, cause })));44+ if (resolvedPath === executablePath) return yield* new NodeRuntimeUnavailableError({ feature });
- apps/server/src/provider/AntigravityInstallation.ts lines 525 to 525OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -517,3 +518,8 @@517518518519 const install = Effect.fn("AntigravityInstallation.install")(519520 function* (asset: AntigravityReleaseAsset) {521+ yield* resolveNodeExecutable("Antigravity", environment).pipe(522+ Effect.provideService(FileSystem.FileSystem, fs),523+ Effect.provideService(Path.Path, path),524+ Effect.provideService(HostProcessPlatform, platform),525+ Effect.mapError((cause) => installationError("verify", cause.message, cause)),apps/server/src/device/LocalDeviceHost.ts lines 550 to 550OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -532,3 +538,13 @@532538 if (alive) return running;533539 yield* Ref.set(runningRef, null);534540 }541+ const nodePath = yield* resolveNodeExecutable("Local device support", hostEnvironment).pipe(542+ Effect.provideService(FileSystem.FileSystem, fs),543+ Effect.provideService(Path.Path, path),544+ Effect.provideService(HostProcessPlatform, hostPlatform),545+ Effect.mapError(546+ (cause) =>547+ new DeviceHost.DeviceHostError({548+ hostId,549+ step: "finding Node.js",550+ detail: cause.message,apps/server/src/provider/antigravityAuthSupport.ts lines 314 to 314OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -307,4 +308,7 @@307308 const platform = input.platform ?? (yield* HostProcessPlatform);308309 const userHome =309310 input.userHome ?? resolveAntigravityUserHome(platform, input.baseEnv ?? process.env);310- const runtimeExecutablePath = input.runtimeExecutablePath ?? (yield* HostProcessExecutablePath);311+ const runtimeExecutablePath =312+ input.runtimeExecutablePath ??313+ (yield* resolveNodeExecutable("Antigravity sign-in", input.baseEnv).pipe(314+ Effect.mapError((error) => authSupportError(error.message)),apps/server/src/mcp/toolkits/device/handlers.ts lines 187 to 189OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -182,6 +182,8 @@182182 stateDir: config.stateDir,183183 }).pipe(184184 Effect.mapError(185- () =>185+ (error) =>186186 new DeviceToolUnavailableError({187- reason: "Could not prepare the agent-device launcher.",187+ reason:188+ error._tag === "NodeRuntimeUnavailableError"189+ ? error.messageapps/server/src/device/DeviceHost.ts lines 26 to 29OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -23,6 +23,7 @@2323 hostId: Schema.String,2424 step: Schema.String,2525 cause: Schema.Defect(),26+ detail: Schema.optional(Schema.String),2627 }) {2728 override get message(): string {28- return `Device host ${this.hostId} failed while ${this.step}.`;29+ return this.detail ?? `Device host ${this.hostId} failed while ${this.step}.`;apps/server/src/device/DeviceService.ts lines 1015 to 1015OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1003,15 +1004,12 @@10031004 );10041005 return {10051006 ...service,1006- agentCli: ensureAgentDevice(config.baseDir).pipe(1007+ agentCli: resolveNodeExecutable("Device automation").pipe(1008+ Effect.flatMap(() => ensureAgentDevice(config.baseDir)),10071009 Effect.provideService(FileSystem.FileSystem, fs),10081010 Effect.provideService(Path.Path, path),10091011 Effect.provideService(ProcessRunner.ProcessRunner, runner),10101012 Effect.map((tool) => tool.entryPath),1011- Effect.mapError(1012- (error) =>1013- new DeviceOperationError({1014- operation: "install agent CLI",1015- reason: "command_failed",1016- cause: error,1017- }),1013+ Effect.mapError((error) =>1014+ error._tag === "NodeRuntimeUnavailableError"1015+ ? new DeviceHostUnavailableError({ hostId: LOCAL_DEVICE_HOST_ID, reason: error.message })apps/server/src/provider/Drivers/AntigravityDriver.ts lines 172 to 172OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -164,3 +164,9 @@164164 Effect.provideService(FileSystem.FileSystem, fileSystem),165165 Effect.provideService(Path.Path, path),166166 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),167+ Effect.mapError(168+ (cause) =>169+ new ProviderSetupError({170+ instanceId,171+ operation: "start",172+ detail: cause.detail ?? cause.message,
- packages/shared/src/nodeRuntime.ts line 36OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +16,21 @@16+17+export class NodeRuntimeUnavailableError extends Schema.TaggedError<NodeRuntimeUnavailableError>()(18+ "NodeRuntimeUnavailableError",19+ { feature: Schema.String, cause: Schema.optional(Schema.Defect()) },20+) {21+ override get message(): string {22+ return nodeRuntimeUnavailableMessage(this.feature);23+ }24+}25+26+/** A standalone T3 binary runs its embedded CLI, regardless of script arguments. */27+export const resolveNodeExecutable = Effect.fn("nodeRuntime.resolveNodeExecutable")(function* (28+ feature: string,29+ environment?: NodeJS.ProcessEnv,30+) {31+ const executablePath = yield* HostProcessExecutablePath;32+ if (!(yield* HostProcessIsExecutable)) return executablePath;33+34+ const fs = yield* FileSystem.FileSystem;35+ const path = yield* Path.Path;36+ const nodePath = yield* resolveCommandPath("node", {
- packages/shared/src/nodeRuntime.ts lines 20 to 20OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,20 @@1+import * as Effect from "effect/Effect";2+import * as FileSystem from "effect/FileSystem";3+import * as Path from "effect/Path";4+import * as Option from "effect/Option";5+import * as Schema from "effect/Schema";6+7+import {8+ HostProcessEnvironment,9+ HostProcessExecutablePath,10+ HostProcessIsExecutable,11+ HostProcessPlatform,12+} from "./hostProcess.ts";13+import { CommandResolutionCache, resolveCommandPath } from "./shell.ts";14+15+export const nodeRuntimeUnavailableMessage = (feature: string): string =>16+ `${feature} requires Node.js. Install Node.js and make sure node is on PATH, then retry.`;17+18+export class NodeRuntimeUnavailableError extends Schema.TaggedError<NodeRuntimeUnavailableError>()(19+ "NodeRuntimeUnavailableError",20+ { feature: Schema.String, cause: Schema.optional(Schema.Defect()) },
juliusmarminge merged thisbf55408
juliusmarminge closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed