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 { appCommand } from "./cli/app.ts";
14import { browserCommand } from "./cli/browser.ts";
15import { connectCommand } from "./cli/connect.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";
33
34const layerCliRuntime = Layer.mergeAll(NodeServices.layer, NetService.layer);
35
36const connectPublicConfigMissingMessage =
37 "T3 Connect commands are unavailable: this build is missing T3 Connect public configuration.";
38
39class ConnectPublicConfigMissingError extends CliError.UserError {
40 override get message() {
41 return connectPublicConfigMissingMessage;
42 }
43}
44
45const connectUnavailableCommand = Command.make("connect", {
46 command: Argument.String("command").pipe(Argument.variadic),
47}).pipe(
48 Command.withDescription("T3 Connect is unavailable in builds without public configuration."),
49 Command.unlisted,
50 Command.withHandler(() =>
51 Effect.fail(
52 new CliError.ShowHelp({
53 commandPath: ["t3", "connect"],
54 errors: [new ConnectPublicConfigMissingError({ cause: connectPublicConfigMissingMessage })],
55 }),
56 ),
57 ),
58);
59
60export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
61 Command.make("t3", { ...sharedServerCommandFlags }).pipe(
62 Command.withDescription("Run the T3 Code server."),
63 Command.withHandler(runDefaultServerCommand),
64 Command.withSubcommands([
65 Command.make("help").pipe(
66 Command.withDescription("Show command help."),
67 Command.withHandler(() =>
68 Effect.fail(new CliError.ShowHelp({ commandPath: ["t3"], errors: [] })),
69 ),
70 ),
71 acpMcpBridgeCommand,
72 acpMcpCallCommand,
73 startCommand,
74 serveCommand,
75 appCommand,
76 pairCommand,
77 authCommand,
78 browserCommand,
79 projectCommand,
80 threadCommand,
81 serviceCommand,
82 updateCommand,
83 uninstallCommand,
84 serviceLauncherCommand,
85 claudeHistoryCommand,
86 sshHelperCommand,
87
88 servicePreflightCommand,
89 themeCommand,
90 traceCommand,
91 doctorCommand,
92 triageCommand,
93 cloudEnabled ? connectCommand : connectUnavailableCommand,
94 ]),
95 );
96
97export const cli = makeCli();
98
99export function runCli() {
100 extendConnectionAttemptTimeout();
101 keepOutboundFetchOnHttp1();
102 Command.run(cli, { version: packageJson.version }).pipe(
103 Effect.scoped,
104 Effect.provide(layerCliRuntime),
105 NodeRuntime.runMain,
106 );
107}