Open History to see the last commit
1import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5import { Argument, Command } from "effect/unstable/cli";
6import * as CliError from "effect/unstable/cli/CliError";
7
8import * as NetService from "@t3tools/shared/Net";
9import packageJson from "../package.json" with { type: "json" };
10import { authCommand } from "./cli/auth.ts";
11import { appCommand } from "./cli/app.ts";
12import { connectCommand } from "./cli/connect.ts";
13import { pairCommand } from "./cli/pair.ts";
14import { hasCloudPublicConfig } from "./cloud/publicConfig.ts";
15import { sharedServerCommandFlags } from "./cli/config.ts";
16import { isEntrypoint } from "./entrypoint.ts";
17import { projectCommand } from "./cli/project.ts";
18import { runServerCommand, serveCommand, startCommand } from "./cli/server.ts";
19import { serviceCommand } from "./cli/service.ts";
20import { uninstallCommand } from "./cli/uninstall.ts";
21import { updateCommand } from "./cli/update.ts";
22import { claudeHistoryCommand } from "./cli/claudeHistory.ts";
23import { serviceLauncherCommand } from "./cli/serviceLauncher.ts";
24import { servicePreflightCommand } from "./cli/servicePreflight.ts";
25import { sshHelperCommand } from "./cli/sshHelper.ts";
26import { themeCommand } from "./cli/theme.ts";
27import { traceCommand } from "./cli/trace.ts";
28import { triageCommand } from "./cli/triage.ts";
29
30const CliRuntimeLayer = Layer.mergeAll(NodeServices.layer, NetService.layer);
31
32const connectPublicConfigMissingMessage =
33 "T3 Connect commands are unavailable: this build is missing T3 Connect public configuration.";
34
35class ConnectPublicConfigMissingError extends CliError.UserError {
36 override get message() {
37 return connectPublicConfigMissingMessage;
38 }
39}
40
41const connectUnavailableCommand = Command.make("connect", {
42 command: Argument.String("command").pipe(Argument.variadic),
43}).pipe(
44 Command.withDescription("T3 Connect is unavailable in builds without public configuration."),
45 Command.unlisted,
46 Command.withHandler(() =>
47 Effect.fail(
48 new CliError.ShowHelp({
49 commandPath: ["t3", "connect"],
50 errors: [new ConnectPublicConfigMissingError({ cause: connectPublicConfigMissingMessage })],
51 }),
52 ),
53 ),
54);
55
56export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
57 Command.make("t3", { ...sharedServerCommandFlags }).pipe(
58 Command.withDescription("Run the T3 Code server."),
59 Command.withHandler((flags) => runServerCommand(flags)),
60 Command.withSubcommands([
61 startCommand,
62 serveCommand,
63 appCommand,
64 pairCommand,
65 authCommand,
66 projectCommand,
67 serviceCommand,
68 updateCommand,
69 uninstallCommand,
70 serviceLauncherCommand,
71 claudeHistoryCommand,
72 servicePreflightCommand,
73 sshHelperCommand,
74 themeCommand,
75 traceCommand,
76 triageCommand,
77 cloudEnabled ? connectCommand : connectUnavailableCommand,
78 ]),
79 );
80
81export const cli = makeCli();
82
83if (
84 isEntrypoint({
85 moduleUrl: import.meta.url,
86 entryPath: process.argv[1],
87 runtimeMain: import.meta.main,
88 })
89) {
90 Command.run(cli, { version: packageJson.version }).pipe(
91 Effect.scoped,
92 Effect.provide(CliRuntimeLayer),
93 NodeRuntime.runMain,
94 );
95}