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 * Both dispatch here before the full CLI module graph (seconds of evaluation) loads; everything
5 * else defers to the real CLI in ./binCli.ts.
6 */
7import packageJson from "../package.json" with { type: "json" };
8import * as NodeSea from "node:sea";
9import { enableCliCompileCache } from "./cliCompileCache.ts";
10import { isEntrypoint } from "./entrypoint.ts";
11
12if (
13 isEntrypoint({
14 moduleUrl: import.meta.url,
15 entryPath: process.argv[1],
16 runtimeMain: import.meta.main,
17 })
18) {
19 const command = process.argv[2];
20 // Helpers omit --base-dir; browser setup may run as root. Avoid caching in the wrong home.
21 const uncached =
22 command === "__spawn-host" ||
23 command === "__load-bundle" ||
24 command === "__claude-history" ||
25 command === "acp-mcp-bridge" ||
26 command === "acp-mcp-call" ||
27 command === "browser";
28 if (!(process.argv.length === 3 && command === "--version") && !uncached) {
29 enableCliCompileCache({
30 bundled: NodeSea.isSea() || import.meta.url.endsWith(".mjs"),
31 argv: process.argv.slice(2),
32 environment: process.env,
33 version: packageJson.version,
34 });
35 }
36 if (process.argv.length === 3 && command === "--version") {
37 process.stdout.write(`t3 v${packageJson.version}\n`);
38 } else if (
39 command === "pair" ||
40 command === "auth" ||
41 command === "service" ||
42 command === "project" ||
43 command === "serve" ||
44 command === "start"
45 ) {
46 const { runLightCli } = await import("./binLightCli.ts");
47 await runLightCli(command);
48 } else if (command === "acp-mcp-bridge" || command === "acp-mcp-call") {
49 const { runAcpMcpCliFastPath } = await import("./mcp/AcpMcpStdioBridge.ts");
50 await runAcpMcpCliFastPath(command, process.argv.slice(3));
51 } else if (command === "__spawn-host") {
52 const { runSpawnHost } = await import("./process/spawnHostProcess.ts");
53 runSpawnHost();
54 } else if (command === "__load-bundle") {
55 const { loadBundle } = await import("./loadBundle.ts");
56 const chunks = await loadBundle(import.meta.url);
57 process.stdout.write(`t3 v${packageJson.version}: loaded ${chunks} bundle chunks\n`);
58 // A chunk may start timers or handles at load, as it would in the server.
59 process.exit(0);
60 } else {
61 // Before anything reads stdin: the desktop app's Windows launcher starts
62 // the CLI without one. Never for the fast paths, whose stdin is a pipe.
63 const { attachConsoleStdin } = await import("./cli/consoleStdin.ts");
64 attachConsoleStdin();
65 const { runCli } = await import("./binCli.ts");
66 runCli();
67 }
68}