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 guards before importing code that can open outbound connections.
9 // Fast paths such as the Cursor SDK worker never reach runCli, so they need these here too.
10 const { extendConnectionAttemptTimeout, ignoreMacosTypeOfServiceEinval } =
11 await import("./outboundHttp.ts");
12 ignoreMacosTypeOfServiceEinval();
13 extendConnectionAttemptTimeout();
14 if (command === "__document-text") {
15 const { extractDocumentText } = await import("./provider/documentTextWorker.ts");
16 try {
17 process.stdout.write(await extractDocumentText(process.argv[3]!, process.argv[4]!));
18 } catch (error) {
19 if (error instanceof Error && "code" in error && /^E[A-Z0-9]+$/.test(String(error.code))) {
20 throw error;
21 }
22 // Exit 2 identifies document rejections; OS and process failures remain retryable.
23 process.exitCode = 2;
24 }
25 } else if (command === "__managed-chatgpt-token") {
26 const { runManagedChatGptTokenCli } = await import("./cli/managedChatGptToken.ts");
27 await runManagedChatGptTokenCli(process.argv.slice(3));
28 } else if (command === "acp-mcp-bridge" || command === "acp-mcp-call") {
29 const { runAcpMcpCliFastPath } = await import("./mcp/AcpMcpStdioBridge.ts");
30 await runAcpMcpCliFastPath(command, process.argv.slice(3));
31 } else if (command === "__speech-worker") {
32 const mode = process.argv[3];
33 if (mode !== "discover" && mode !== "model") throw new Error("Unknown speech worker mode.");
34 const { runNativeSpeechWorker } = await import("./speech/native.ts");
35 await runNativeSpeechWorker(mode, process.argv[4]);
36 } else if (command === "__cursor-sdk-worker") {
37 const [NodeServices, { runCursorSdkWorker }] = await Promise.all([
38 import("@effect/platform-node/NodeServices"),
39 import("@t3tools/provider-cursor/server/worker"),
40 ]);
41 await runCursorSdkWorker(NodeServices.layer);
42 } else {
43 enableCliCompileCache();
44 // Windows desktop launches without stdin; attach before reading, except on fast paths using pipes.
45 const { attachConsoleStdin } = await import("./cli/consoleStdin.ts");
46 attachConsoleStdin();
47 const importStart = performance.now();
48 const { runCli } = await import("./binCli.ts");
49 if (process.env.T3CODE_STARTUP_PROFILE_DIR) {
50 performance.measure("server.import.binCli", { start: importStart });
51 }
52 runCli();
53 }
54}