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

bin.ts

44 lines1.9 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";
8​
9if (
10 isEntrypoint({
11 moduleUrl: import.meta.url,
12 entryPath: process.argv[1],
13 runtimeMain: import.meta.main,
14 })
15) {
16 const command = process.argv[2];
17 // Guard sockets before either dispatch path can load outbound-capable modules.
18 const { ignoreMacosTypeOfServiceEinval } = await import("./outboundHttp.ts");
19 ignoreMacosTypeOfServiceEinval();
20 if (command === "__document-text") {
21 const { extractDocumentText } = await import("./provider/documentTextWorker.ts");
22 try {
23 process.stdout.write(await extractDocumentText(process.argv[3]!, process.argv[4]!));
24 } catch (error) {
25 if (error instanceof Error && "code" in error && /^E[A-Z0-9]+$/.test(String(error.code))) {
26 throw error;
27 }
28 // Exit 2 identifies document rejections; OS and process failures remain retryable.
29 process.exitCode = 2;
30 }
31 } else if (command === "__managed-chatgpt-token") {
32 const { runManagedChatGptTokenCli } = await import("./cli/managedChatGptToken.ts");
33 await runManagedChatGptTokenCli(process.argv.slice(3));
34 } else if (command === "acp-mcp-bridge" || command === "acp-mcp-call") {
35 const { runAcpMcpCliFastPath } = await import("./mcp/AcpMcpStdioBridge.ts");
36 await runAcpMcpCliFastPath(command, process.argv.slice(3));
37 } else {
38 // Windows desktop launches without stdin; attach before reading, except on fast paths using pipes.
39 const { attachConsoleStdin } = await import("./cli/consoleStdin.ts");
40 attachConsoleStdin();
41 const { runCli } = await import("./binCli.ts");
42 runCli();
43 }