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

binCli.ts

115 lines4.1 KB

1import { doctorCommand } from "./cli/doctor.ts";
2import { policyCommand } from "./cli/policy.ts";
3import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
4import * as NodeServices from "@effect/platform-node/NodeServices";
5import * as Effect from "effect/Effect";
6import * as Layer from "effect/Layer";
7import { Argument, Command } from "effect/cli";
8import * as CliError from "effect/cli/CliError";
9​
10import * as NetService from "@t3tools/shared/Net";
11import packageJson from "../package.json" with { type: "json" };
12import { acpMcpBridgeCommand, acpMcpCallCommand } from "./cli/acpMcpBridge.ts";
13import { authCommand } from "./cli/auth.ts";
14import { environmentCommand } from "./cli/environment.ts";
15import { appCommand } from "./cli/app.ts";
16import { browserCommand } from "./cli/browser.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";
34import { connectCommand, statusCommand, upCommand } from "./cli/up.ts";
35​
36const layerCliRuntime = Layer.mergeAll(NodeServices.layer, NetService.layer);
37​
38const connectPublicConfigMissingMessage =
39 "T3 Connect commands are unavailable: this build is missing T3 Connect public configuration.";
40​
41class ConnectPublicConfigMissingError extends CliError.UserError {
42 override get message() {
43 return connectPublicConfigMissingMessage;
44 }
46​
47const connectUnavailableCommand = Command.make("connect", {
48 command: Argument.String("command").pipe(Argument.variadic),
49}).pipe(
50 Command.withDescription("T3 Connect is unavailable in builds without public configuration."),
51 Command.unlisted,
52 Command.withHandler(() =>
53 Effect.fail(
54 new CliError.ShowHelp({
55 commandPath: ["t3", "connect"],
56 errors: [new ConnectPublicConfigMissingError({ cause: connectPublicConfigMissingMessage })],
57 }),
58 ),
59 ),
60);
61​
62export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
63 Command.make("t3", { ...sharedServerCommandFlags }).pipe(
64 Command.withDescription(
65 "Run T3 Code in this terminal and open it in your browser. To use it from your other devices, run `t3 up`.",
66 ),
67 Command.withHandler(runDefaultServerCommand),
68 Command.withSubcommands([
69 Command.make("help").pipe(
70 Command.withDescription("Show command help."),
71 Command.withHandler(() =>
72 Effect.fail(new CliError.ShowHelp({ commandPath: ["t3"], errors: [] })),
73 ),
74 ),
75 acpMcpBridgeCommand,
76 acpMcpCallCommand,
77 startCommand,
78 serveCommand,
79 appCommand,
80 pairCommand,
81 authCommand,
82 environmentCommand,
83 browserCommand,
84 projectCommand,
85 threadCommand,
86 upCommand,
87 statusCommand,
88 serviceCommand,
89 updateCommand,
90 uninstallCommand,
91 serviceLauncherCommand,
92 claudeHistoryCommand,
93 sshHelperCommand,
94​
95 servicePreflightCommand,
96 themeCommand,
97 traceCommand,
98 doctorCommand,
99 policyCommand,
100 triageCommand,
101 cloudEnabled ? connectCommand : connectUnavailableCommand,
102 ]),
103 );
104​
105export const cli = makeCli();
106​
107export function runCli() {
108 extendConnectionAttemptTimeout();
109 keepOutboundFetchOnHttp1();
110 Command.run(cli, { version: packageJson.version }).pipe(
111 Effect.scoped,
112 Effect.provide(layerCliRuntime),
113 NodeRuntime.runMain,
114 );