+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
118 lines
4.7 KiB
TypeScript
118 lines
4.7 KiB
TypeScript
import * as Effect from "effect/Effect";
|
|
import * as FileSystem from "effect/FileSystem";
|
|
import * as Path from "effect/Path";
|
|
import * as Option from "effect/Option";
|
|
import * as Schema from "effect/Schema";
|
|
|
|
import {
|
|
HostProcessArguments,
|
|
HostProcessEnvironment,
|
|
HostProcessExecutablePath,
|
|
HostProcessIsExecutable,
|
|
HostProcessPlatform,
|
|
} from "./hostProcess.ts";
|
|
import { CommandResolutionCache, resolveCommandPath } from "./shell.ts";
|
|
|
|
const NodeRuntimeFeature = Schema.Literals([
|
|
"Local device support",
|
|
"Device automation",
|
|
"Antigravity",
|
|
"Antigravity sign-in",
|
|
]);
|
|
|
|
export const nodeRuntimeUnavailableMessage = (feature: typeof NodeRuntimeFeature.Type): string =>
|
|
`${feature} requires Node.js. Install Node.js and make sure node is on PATH, then retry.`;
|
|
|
|
export class NodeRuntimeUnavailableError extends Schema.TaggedError<NodeRuntimeUnavailableError>()(
|
|
"NodeRuntimeUnavailableError",
|
|
{ feature: NodeRuntimeFeature, cause: Schema.optional(Schema.Defect()) },
|
|
) {
|
|
override get message(): string {
|
|
return nodeRuntimeUnavailableMessage(this.feature);
|
|
}
|
|
}
|
|
|
|
export interface SelfInvocation {
|
|
/** The binary to spawn: Node, Electron (with `ELECTRON_RUN_AS_NODE`), or the packaged T3. */
|
|
readonly command: string;
|
|
/**
|
|
* The absolute entrypoint script to place before the subcommand, or
|
|
* undefined for the packaged binary, which dispatches subcommands from
|
|
* argv[2] and treats a leading path as the subcommand itself.
|
|
*/
|
|
readonly entrypoint: string | undefined;
|
|
}
|
|
|
|
/**
|
|
* How another process runs this T3 install's CLI, for hidden subcommands the
|
|
* server hands to children such as `acp-mcp-bridge`. `process.execPath` plus
|
|
* `argv[1]` only works for a script run by Node; the single-executable has no
|
|
* entrypoint script (Node repeats the binary at argv[1]), so callers must not
|
|
* assemble the pair themselves.
|
|
*/
|
|
export const resolveSelfInvocation = Effect.fn("nodeRuntime.resolveSelfInvocation")(function* () {
|
|
const command = yield* HostProcessExecutablePath;
|
|
if (yield* HostProcessIsExecutable)
|
|
return { command, entrypoint: undefined } satisfies SelfInvocation;
|
|
const path = yield* Path.Path;
|
|
const entry = (yield* HostProcessArguments)[1];
|
|
// Children spawn from their own working directory, so the script path must be absolute.
|
|
return {
|
|
command,
|
|
entrypoint: entry === undefined ? undefined : path.resolve(entry),
|
|
} satisfies SelfInvocation;
|
|
});
|
|
|
|
/** `[entrypoint?, ...args]`: the argv that runs `args` against this T3 install. */
|
|
export const selfInvocationArgs = (
|
|
invocation: SelfInvocation,
|
|
args: ReadonlyArray<string>,
|
|
): ReadonlyArray<string> =>
|
|
invocation.entrypoint === undefined ? args : [invocation.entrypoint, ...args];
|
|
|
|
/** A standalone T3 binary runs its embedded CLI, regardless of script arguments. */
|
|
export const resolveNodeExecutable = Effect.fn("nodeRuntime.resolveNodeExecutable")(function* (
|
|
feature: typeof NodeRuntimeFeature.Type,
|
|
environment?: NodeJS.ProcessEnv,
|
|
) {
|
|
const executablePath = yield* HostProcessExecutablePath;
|
|
if (!(yield* HostProcessIsExecutable)) return executablePath;
|
|
|
|
const fs = yield* FileSystem.FileSystem;
|
|
const path = yield* Path.Path;
|
|
const platform = yield* HostProcessPlatform;
|
|
const env = environment ?? (yield* HostProcessEnvironment);
|
|
const nodePath = yield* resolveCommandPath(platform === "win32" ? "node.exe" : "node", {
|
|
// Batch wrappers require a shell; helper callers launch the runtime directly.
|
|
env: platform === "win32" ? { ...env, PATHEXT: ".EXE" } : env,
|
|
}).pipe(
|
|
// Refresh immediately after the user installs Node and retries setup.
|
|
Effect.provideService(CommandResolutionCache, new Map()),
|
|
Effect.map((commandPath) => path.resolve(commandPath)),
|
|
Effect.mapError((cause) => new NodeRuntimeUnavailableError({ feature, cause })),
|
|
);
|
|
// A launcher or symlink named node must not point back at the standalone app.
|
|
const resolvedPath = yield* fs
|
|
.realPath(nodePath)
|
|
.pipe(Effect.mapError((cause) => new NodeRuntimeUnavailableError({ feature, cause })));
|
|
if (resolvedPath === executablePath) return yield* new NodeRuntimeUnavailableError({ feature });
|
|
const [hostInfo, nodeInfo] = yield* Effect.all([
|
|
fs.stat(executablePath).pipe(Effect.option),
|
|
fs.stat(nodePath).pipe(Effect.option),
|
|
]);
|
|
if (
|
|
Option.isSome(hostInfo) &&
|
|
Option.isSome(nodeInfo) &&
|
|
hostInfo.value.dev === nodeInfo.value.dev &&
|
|
Option.isSome(hostInfo.value.ino) &&
|
|
Option.isSome(nodeInfo.value.ino) &&
|
|
Number.isSafeInteger(hostInfo.value.ino.value) &&
|
|
hostInfo.value.ino.value > 0 &&
|
|
hostInfo.value.ino.value === nodeInfo.value.ino.value
|
|
) {
|
|
return yield* new NodeRuntimeUnavailableError({ feature });
|
|
}
|
|
// Launchers such as Vite+ dispatch by argv[0]; keep the node name intact.
|
|
return nodePath;
|
|
});
|