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

binCli.ts

116 lines4.2 KB

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