Open History to see the last commit
1import { 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.
6export 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 {
34 enableCliCompileCache();
35 // Windows desktop launches without stdin; attach before reading, except on fast paths using pipes.
36 const { attachConsoleStdin } = await import("./cli/consoleStdin.ts");
37 attachConsoleStdin();
38 const importStart = performance.now();
39 const { runCli } = await import("./binCli.ts");
40 if (process.env.T3CODE_STARTUP_PROFILE_DIR) {
41 performance.measure("server.import.binCli", { start: importStart });
42 }
43 runCli();
44 }
45}