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 21, 03:37 UTC
| 1 | // @effect-diagnostics nodeBuiltinImport:off |
| 2 | import * as NodeChildProcess from "node:child_process"; |
| 3 | |
| 4 | const ENV = "/usr/bin/env"; |
| 5 | |
| 6 | let chdirSupport: Promise<boolean> | undefined; |
| 7 | |
| 8 | /** Whether `/usr/bin/env` takes `-C` (GNU coreutils 8.28 and later; BusyBox does not). */ |
| 9 | export const supportsEnvChdir = (): Promise<boolean> => |
| 10 | (chdirSupport ??= new Promise((resolve) => |
| 11 | // Run against `/` and absolute paths, so the check itself cannot wait on a mount. |
| 12 | NodeChildProcess.execFile(ENV, ["-C", "/", "--", "/bin/sh", "-c", ":"], (error) => |
| 13 | resolve(error === null), |
| 14 | ), |
| 15 | )); |
| 16 | |
| 17 | /** |
| 18 | * libuv's spawn blocks until the child has run chdir(cwd) and the PATH search, which a hung |
| 19 | * mount stalls. Through `env` both run after exec, with argv and environment untouched. |
| 20 | * Undefined when `env` would read the command as `NAME=value` or `-`, which `--` does not stop. |
| 21 | */ |
| 22 | export function envTrampoline<Arg>( |
| 23 | command: string, |
| 24 | args: ReadonlyArray<Arg>, |
| 25 | cwd: string | undefined, |
| 26 | ): { readonly command: string; readonly args: Array<Arg | string> } | undefined { |
| 27 | if (command === "" || command === "-" || command.includes("=")) return undefined; |
| 28 | return { |
| 29 | command: ENV, |
| 30 | args: [...(cwd === undefined ? [] : ["-C", cwd]), "--", command, ...args], |
| 31 | }; |
| 32 | } |