Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

bin.ts

46 lines2.0 KB

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 {
39 enableCliCompileCache();
40 // Windows desktop launches without stdin; attach before reading, except on fast paths using pipes.
41 const { attachConsoleStdin } = await import("./cli/consoleStdin.ts");
42 attachConsoleStdin();
43 const { runCli } = await import("./binCli.ts");
44 runCli();
45 }