Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

binCli.ts

100 lines3.5 KB

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/cli";
6import * as CliError from "effect/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 { browserCommand } from "./cli/browser.ts";
14import { connectCommand } from "./cli/connect.ts";
15import { pairCommand } from "./cli/pair.ts";
16import { hasCloudPublicConfig } from "./cloud/publicConfig.ts";
17import { sharedServerCommandFlags } from "./cli/config.ts";
18import { projectCommand } from "./cli/project.ts";
19import { runDefaultServerCommand, serveCommand, startCommand } from "./cli/server.ts";
20import { updateCommand } from "./cli/update.ts";
21import { uninstallCommand } from "./cli/uninstall.ts";
22import { serviceLauncherCommand } from "./cli/serviceLauncher.ts";
23import { claudeHistoryCommand } from "./cli/claudeHistory.ts";
24import { sshHelperCommand } from "./cli/sshHelper.ts";
25import { serviceCommand } from "./cli/service.ts";
26import { servicePreflightCommand } from "./cli/servicePreflight.ts";
27import { themeCommand } from "./cli/theme.ts";
28import { traceCommand } from "./cli/trace.ts";
29import { triageCommand } from "./cli/triage.ts";
30​
31const layerCliRuntime = Layer.mergeAll(NodeServices.layer, NetService.layer);
32​
33const connectPublicConfigMissingMessage =
34 "T3 Connect commands are unavailable: this build is missing T3 Connect public configuration.";
35​
36class ConnectPublicConfigMissingError extends CliError.UserError {
37 override get message() {
38 return connectPublicConfigMissingMessage;
39 }
41​
42const connectUnavailableCommand = Command.make("connect", {
43 command: Argument.String("command").pipe(Argument.variadic),
44}).pipe(
45 Command.withDescription("T3 Connect is unavailable in builds without public configuration."),
46 Command.unlisted,
47 Command.withHandler(() =>
48 Effect.fail(
49 new CliError.ShowHelp({
50 commandPath: ["t3", "connect"],
51 errors: [new ConnectPublicConfigMissingError({ cause: connectPublicConfigMissingMessage })],
52 }),
53 ),
54 ),
55);
56​
57export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
58 Command.make("t3", { ...sharedServerCommandFlags }).pipe(
59 Command.withDescription("Run the T3 Code server."),
60 Command.withHandler(runDefaultServerCommand),
61 Command.withSubcommands([
62 Command.make("help").pipe(
63 Command.withDescription("Show command help."),
64 Command.withHandler(() =>
65 Effect.fail(new CliError.ShowHelp({ commandPath: ["t3"], errors: [] })),
66 ),
67 ),
68 acpMcpBridgeCommand,
69 acpMcpCallCommand,
70 startCommand,
71 serveCommand,
72 appCommand,
73 pairCommand,
74 authCommand,
75 browserCommand,
76 projectCommand,
77 serviceCommand,
78 updateCommand,
79 uninstallCommand,
80 serviceLauncherCommand,
81 claudeHistoryCommand,
82 sshHelperCommand,
83​
84 servicePreflightCommand,
85 themeCommand,
86 traceCommand,
87 triageCommand,
88 cloudEnabled ? connectCommand : connectUnavailableCommand,
89 ]),
90 );
91​
92export const cli = makeCli();
93​
94export function runCli() {
95 Command.run(cli, { version: packageJson.version }).pipe(
96 Effect.scoped,
97 Effect.provide(layerCliRuntime),
98 NodeRuntime.runMain,
99 );