Open History to see the last commit
1/**
2 * Every ACP agent spawns `t3 acp-mcp-bridge` while opening its session, and terminal-fallback
3 * agents run `t3 acp-mcp-call` per tool call, so their startup sits on first-message latency.
4 * They and Codex's managed-token helper dispatch before the full CLI module graph (seconds
5 * of evaluation) loads; everything else defers to the real CLI in ./binCli.ts.
6 */
7import { isEntrypoint } from "./entrypoint.ts";
8import { enableCliCompileCache } from "./cliCompileCache.ts";
9
10if (
11 isEntrypoint({
12 moduleUrl: import.meta.url,
13 entryPath: process.argv[1],
14 runtimeMain: import.meta.main,
15 })
16) {
17 const command = process.argv[2];
18 // Guard sockets before either dispatch path can load outbound-capable modules.
19 const { ignoreMacosTypeOfServiceEinval } = await import("./outboundHttp.ts");
20 ignoreMacosTypeOfServiceEinval();
21 if (command === "__document-text") {
22 const { extractDocumentText } = await import("./provider/documentTextWorker.ts");
23 try {
24 process.stdout.write(await extractDocumentText(process.argv[3]!, process.argv[4]!));
25 } catch (error) {
26 if (error instanceof Error && "code" in error && /^E[A-Z0-9]+$/.test(String(error.code))) {
27 throw error;
28 }
29 // Exit 2 identifies document rejections; OS and process failures remain retryable.
30 process.exitCode = 2;
31 }
32 } else if (command === "__managed-chatgpt-token") {
33 const { runManagedChatGptTokenCli } = await import("./cli/managedChatGptToken.ts");
34 await runManagedChatGptTokenCli(process.argv.slice(3));
35 } else if (command === "acp-mcp-bridge" || command === "acp-mcp-call") {
36 const { runAcpMcpCliFastPath } = await import("./mcp/AcpMcpStdioBridge.ts");
37 await runAcpMcpCliFastPath(command, process.argv.slice(3));
38 } else if (command === "__speech-worker") {
39 const mode = process.argv[3];
40 if (mode !== "discover" && mode !== "model") throw new Error("Unknown speech worker mode.");
41 const { runNativeSpeechWorker } = await import("./speech/native.ts");
42 await runNativeSpeechWorker(mode, process.argv[4]);
43 } else {
44 enableCliCompileCache();
45 // Windows desktop launches without stdin; attach before reading, except on fast paths using pipes.
46 const { attachConsoleStdin } = await import("./cli/consoleStdin.ts");
47 attachConsoleStdin();
48 const importStart = performance.now();
49 const { runCli } = await import("./binCli.ts");
50 if (process.env.T3CODE_STARTUP_PROFILE_DIR) {
51 performance.measure("server.import.binCli", { start: importStart });
52 }
53 runCli();
54 }
55}