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

binCli.ts

104 lines3.7 KB

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