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 | import { enableCliCompileCache } from "./cliCompileCache.ts"; |
| 2 | |
| 3 | // Packaged builds load this graph with require(esm): top-level await anywhere in it breaks them. |
| 4 | // ACP agents spawn `acp-mcp-bridge` per session and `acp-mcp-call` per tool call, so those fast |
| 5 | // paths dispatch before the full CLI module graph (seconds of evaluation) loads. |
| 6 | export async function runCliCommand() { |
| 7 | const command = process.argv[2]; |
| 8 | // Install the socket guard before importing code that can open outbound connections. |
| 9 | const { ignoreMacosTypeOfServiceEinval } = await import("./outboundHttp.ts"); |
| 10 | ignoreMacosTypeOfServiceEinval(); |
| 11 | if (command === "__document-text") { |
| 12 | const { extractDocumentText } = await import("./provider/documentTextWorker.ts"); |
| 13 | try { |
| 14 | process.stdout.write(await extractDocumentText(process.argv[3]!, process.argv[4]!)); |
| 15 | } catch (error) { |
| 16 | if (error instanceof Error && "code" in error && /^E[A-Z0-9]+$/.test(String(error.code))) { |
| 17 | throw error; |
| 18 | } |
| 19 | // Exit 2 identifies document rejections; OS and process failures remain retryable. |
| 20 | process.exitCode = 2; |
| 21 | } |
| 22 | } else if (command === "__managed-chatgpt-token") { |
| 23 | const { runManagedChatGptTokenCli } = await import("./cli/managedChatGptToken.ts"); |
| 24 | await runManagedChatGptTokenCli(process.argv.slice(3)); |
| 25 | } else if (command === "acp-mcp-bridge" || command === "acp-mcp-call") { |
| 26 | const { runAcpMcpCliFastPath } = await import("./mcp/AcpMcpStdioBridge.ts"); |
| 27 | await runAcpMcpCliFastPath(command, process.argv.slice(3)); |
| 28 | } else if (command === "__speech-worker") { |
| 29 | const mode = process.argv[3]; |
| 30 | if (mode !== "discover" && mode !== "model") throw new Error("Unknown speech worker mode."); |
| 31 | const { runNativeSpeechWorker } = await import("./speech/native.ts"); |
| 32 | await runNativeSpeechWorker(mode, process.argv[4]); |
| 33 | } else if (command === "__cursor-sdk-worker") { |
| 34 | const [NodeServices, { runCursorSdkWorker }] = await Promise.all([ |
| 35 | import("@effect/platform-node/NodeServices"), |
| 36 | import("@t3tools/provider-cursor/server/worker"), |
| 37 | ]); |
| 38 | await runCursorSdkWorker(NodeServices.layer); |
| 39 | } else { |
| 40 | enableCliCompileCache(); |
| 41 | // Windows desktop launches without stdin; attach before reading, except on fast paths using pipes. |
| 42 | const { attachConsoleStdin } = await import("./cli/consoleStdin.ts"); |
| 43 | attachConsoleStdin(); |
| 44 | const importStart = performance.now(); |
| 45 | const { runCli } = await import("./binCli.ts"); |
| 46 | if (process.env.T3CODE_STARTUP_PROFILE_DIR) { |
| 47 | performance.measure("server.import.binCli", { start: importStart }); |
| 48 | } |
| 49 | runCli(); |
| 50 | } |
| 51 | } |