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

binCli.ts

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