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

main
ts 57 lines 2.03 KB
Raw
1 import * as HostProcess from "@t3tools/shared/HostProcess";
2 import * as Config from "effect/Config";
3 import * as Effect from "effect/Effect";
4 import * as Option from "effect/Option";
5
6 export type BuildArch = "arm64" | "x64" | "universal";
7 export type BuildPlatform = "mac" | "linux" | "win";
8
9 interface PlatformConfig {
10 readonly archChoices: ReadonlyArray<BuildArch>;
11 }
12
13 const WindowsProcessorArchitectureConfig = Config.all({
14 processorArchitecture: Config.String("PROCESSOR_ARCHITECTURE").pipe(Config.option),
15 processorArchitectureW6432: Config.String("PROCESSOR_ARCHITEW6432").pipe(Config.option),
16 });
17
18 function normalizeWindowsArch(value: string | undefined): BuildArch | undefined {
19 const normalized = value?.trim().toLowerCase();
20 if (!normalized) return undefined;
21 if (normalized.includes("arm64") || normalized === "aarch64") return "arm64";
22 if (normalized.includes("amd64") || normalized.includes("x64")) return "x64";
23 return undefined;
24 }
25
26 const optionToUndefined = <A>(value: Option.Option<A>): A | undefined =>
27 Option.getOrUndefined(value);
28
29 const resolveHostProcessArch = Effect.fn("resolveHostProcessArch")(function* () {
30 const platform = yield* HostProcess.Platform;
31 const processArch = yield* HostProcess.Architecture;
32 if (processArch === "arm64") return "arm64";
33 if (processArch === "x64") {
34 if (platform !== "win32") return "x64";
35
36 // Emulated x64 Node/Bun can run on Windows ARM64; use host processor variables.
37 const env = yield* WindowsProcessorArchitectureConfig;
38 return (
39 normalizeWindowsArch(optionToUndefined(env.processorArchitectureW6432)) ??
40 normalizeWindowsArch(optionToUndefined(env.processorArchitecture)) ??
41 "x64"
42 );
43 }
44 return undefined;
45 });
46
47 export const getDefaultBuildArch = Effect.fn("getDefaultBuildArch")(function* (
48 platform: BuildPlatform,
49 platformConfig: PlatformConfig,
50 ) {
51 const hostArch = yield* resolveHostProcessArch();
52 if (hostArch && platformConfig.archChoices.includes(hostArch)) {
53 return hostArch;
54 }
55
56 return platformConfig.archChoices[0] ?? "x64";
57 });