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 { acpMcpBridgeCommand, acpMcpCallCommand } from "./cli/acpMcpBridge.ts";
11import { authCommand } from "./cli/auth.ts";
12import { appCommand } from "./cli/app.ts";
13import { connectCommand } from "./cli/connect.ts";
14import { pairCommand } from "./cli/pair.ts";
15import { hasCloudPublicConfig } from "./cloud/publicConfig.ts";
16import { sharedServerCommandFlags } from "./cli/config.ts";
17import { projectCommand } from "./cli/project.ts";
18import { runServerCommand, serveCommand, startCommand } from "./cli/server.ts";
19import { serviceCommand } from "./cli/service.ts";
20import { servicePreflightCommand } from "./cli/servicePreflight.ts";
21import { themeCommand } from "./cli/theme.ts";
22import { triageCommand } from "./cli/triage.ts";
23
24const CliRuntimeLayer = Layer.mergeAll(NodeServices.layer, NetService.layer);
25
26const connectPublicConfigMissingMessage =
27 "T3 Connect commands are unavailable: this build is missing T3 Connect public configuration.";
28
29class ConnectPublicConfigMissingError extends CliError.UserError {
30 override get message() {
31 return connectPublicConfigMissingMessage;
32 }
33}
34
35const connectUnavailableCommand = Command.make("connect", {
36 command: Argument.string("command").pipe(Argument.variadic),
37}).pipe(
38 Command.withDescription("T3 Connect is unavailable in builds without public configuration."),
39 Command.unlisted,
40 Command.withHandler(() =>
41 Effect.fail(
42 new CliError.ShowHelp({
43 commandPath: ["t3", "connect"],
44 errors: [new ConnectPublicConfigMissingError({ cause: connectPublicConfigMissingMessage })],
45 }),
46 ),
47 ),
48);
49
50export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
51 Command.make("t3", { ...sharedServerCommandFlags }).pipe(
52 Command.withDescription("Run the T3 Code server."),
53 Command.withHandler((flags) => runServerCommand(flags)),
54 Command.withSubcommands([
55 acpMcpBridgeCommand,
56 acpMcpCallCommand,
57 startCommand,
58 serveCommand,
59 appCommand,
60 pairCommand,
61 authCommand,
62 projectCommand,
63 serviceCommand,
64 servicePreflightCommand,
65 themeCommand,
66 triageCommand,
67 cloudEnabled ? connectCommand : connectUnavailableCommand,
68 ]),
69 );
70
71export const cli = makeCli();
72
73export function runCli() {
74 Command.run(cli, { version: packageJson.version }).pipe(
75 Effect.scoped,
76 Effect.provide(CliRuntimeLayer),
77 NodeRuntime.runMain,
78 );
79}