Open History to see the last commit
1import { doctorCommand } from "./cli/doctor.ts";
2import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
3import * as NodeServices from "@effect/platform-node/NodeServices";
4import * as Effect from "effect/Effect";
5import * as Layer from "effect/Layer";
6import { Argument, Command } from "effect/cli";
7import * as CliError from "effect/cli/CliError";
8
9import * as NetService from "@t3tools/shared/Net";
10import packageJson from "../package.json" with { type: "json" };
11import { acpMcpBridgeCommand, acpMcpCallCommand } from "./cli/acpMcpBridge.ts";
12import { authCommand } from "./cli/auth.ts";
13import { environmentCommand } from "./cli/environment.ts";
14import { appCommand } from "./cli/app.ts";
15import { browserCommand } from "./cli/browser.ts";
16import { pairCommand } from "./cli/pair.ts";
17import { hasCloudPublicConfig } from "./cloud/publicConfig.ts";
18import { extendConnectionAttemptTimeout, keepOutboundFetchOnHttp1 } from "./outboundHttp.ts";
19import { sharedServerCommandFlags } from "./cli/config.ts";
20import { projectCommand } from "./cli/project.ts";
21import { threadCommand } from "./cli/thread.ts";
22import { runDefaultServerCommand, serveCommand, startCommand } from "./cli/server.ts";
23import { updateCommand } from "./cli/update.ts";
24import { uninstallCommand } from "./cli/uninstall.ts";
25import { serviceLauncherCommand } from "./cli/serviceLauncher.ts";
26import { claudeHistoryCommand } from "./cli/claudeHistory.ts";
27import { sshHelperCommand } from "./cli/sshHelper.ts";
28import { serviceCommand } from "./cli/service.ts";
29import { servicePreflightCommand } from "./cli/servicePreflight.ts";
30import { themeCommand } from "./cli/theme.ts";
31import { traceCommand } from "./cli/trace.ts";
32import { triageCommand } from "./cli/triage.ts";
33import { connectCommand, statusCommand, upCommand } from "./cli/up.ts";
34
35const layerCliRuntime = Layer.mergeAll(NodeServices.layer, NetService.layer);
36
37const connectPublicConfigMissingMessage =
38 "T3 Connect commands are unavailable: this build is missing T3 Connect public configuration.";
39
40class ConnectPublicConfigMissingError extends CliError.UserError {
41 override get message() {
42 return connectPublicConfigMissingMessage;
43 }
44}
45
46const connectUnavailableCommand = Command.make("connect", {
47 command: Argument.String("command").pipe(Argument.variadic),
48}).pipe(
49 Command.withDescription("T3 Connect is unavailable in builds without public configuration."),
50 Command.unlisted,
51 Command.withHandler(() =>
52 Effect.fail(
53 new CliError.ShowHelp({
54 commandPath: ["t3", "connect"],
55 errors: [new ConnectPublicConfigMissingError({ cause: connectPublicConfigMissingMessage })],
56 }),
57 ),
58 ),
59);
60
61export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
62 Command.make("t3", { ...sharedServerCommandFlags }).pipe(
63 Command.withDescription(
64 "Run T3 Code in this terminal and open it in your browser. To use it from your other devices, run `t3 up`.",
65 ),
66 Command.withHandler(runDefaultServerCommand),
67 Command.withSubcommands([
68 Command.make("help").pipe(
69 Command.withDescription("Show command help."),
70 Command.withHandler(() =>
71 Effect.fail(new CliError.ShowHelp({ commandPath: ["t3"], errors: [] })),
72 ),
73 ),
74 acpMcpBridgeCommand,
75 acpMcpCallCommand,
76 startCommand,
77 serveCommand,
78 appCommand,
79 pairCommand,
80 authCommand,
81 environmentCommand,
82 browserCommand,
83 projectCommand,
84 threadCommand,
85 upCommand,
86 statusCommand,
87 serviceCommand,
88 updateCommand,
89 uninstallCommand,
90 serviceLauncherCommand,
91 claudeHistoryCommand,
92 sshHelperCommand,
93
94 servicePreflightCommand,
95 themeCommand,
96 traceCommand,
97 doctorCommand,
98 triageCommand,
99 cloudEnabled ? connectCommand : connectUnavailableCommand,
100 ]),
101 );
102
103export const cli = makeCli();
104
105export function runCli() {
106 extendConnectionAttemptTimeout();
107 keepOutboundFetchOnHttp1();
108 Command.run(cli, { version: packageJson.version }).pipe(
109 Effect.scoped,
110 Effect.provide(layerCliRuntime),
111 NodeRuntime.runMain,
112 );
113}