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 { triageCommand } from "./cli/triage.ts";
28
29const CliRuntimeLayer = Layer.mergeAll(NodeServices.layer, NetService.layer);
30
31const connectPublicConfigMissingMessage =
32 "T3 Connect commands are unavailable: this build is missing T3 Connect public configuration.";
33
34class ConnectPublicConfigMissingError extends CliError.UserError {
35 override get message() {
36 return connectPublicConfigMissingMessage;
37 }
38}
39
40const connectUnavailableCommand = Command.make("connect", {
41 command: Argument.string("command").pipe(Argument.variadic),
42}).pipe(
43 Command.withDescription("T3 Connect is unavailable in builds without public configuration."),
44 Command.unlisted,
45 Command.withHandler(() =>
46 Effect.fail(
47 new CliError.ShowHelp({
48 commandPath: ["t3", "connect"],
49 errors: [new ConnectPublicConfigMissingError({ cause: connectPublicConfigMissingMessage })],
50 }),
51 ),
52 ),
53);
54
55export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
56 Command.make("t3", { ...sharedServerCommandFlags }).pipe(
57 Command.withDescription("Run the T3 Code server."),
58 Command.withHandler((flags) => runServerCommand(flags)),
59 Command.withSubcommands([
60 startCommand,
61 serveCommand,
62 appCommand,
63 pairCommand,
64 authCommand,
65 projectCommand,
66 serviceCommand,
67 updateCommand,
68 uninstallCommand,
69 serviceLauncherCommand,
70 claudeHistoryCommand,
71 servicePreflightCommand,
72 sshHelperCommand,
73 themeCommand,
74 triageCommand,
75 cloudEnabled ? connectCommand : connectUnavailableCommand,
76 ]),
77 );
78
79export const cli = makeCli();
80
81if (
82 isEntrypoint({
83 moduleUrl: import.meta.url,
84 entryPath: process.argv[1],
85 runtimeMain: import.meta.main,
86 })
87) {
88 Command.run(cli, { version: packageJson.version }).pipe(
89 Effect.scoped,
90 Effect.provide(CliRuntimeLayer),
91 NodeRuntime.runMain,
92 );
93}