Skip to content

Commit cadf7d5

Browse files
t3dotggclaude
andauthored
feat(cli): t3 up asks how your other devices reach this machine (#27996)
t3 up asks one question (T3 Connect and/or the local network) or takes flags, then runs T3 Code as the background service, restarting only when a setting it reads at start changed. t3 status (and --json) shows the setup; t3 connect is t3 up --connect. A new background service listens on this machine only until you choose the local network (T3CODE_LAN); older installs keep their LAN access. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1aa46d0 commit cadf7d5

17 files changed

Lines changed: 1263 additions & 322 deletions

‎apps/server/src/binCli.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { authCommand } from "./cli/auth.ts";
1313
import { environmentCommand } from "./cli/environment.ts";
1414
import { appCommand } from "./cli/app.ts";
1515
import { browserCommand } from "./cli/browser.ts";
16-
import { connectCommand } from "./cli/connect.ts";
1716
import { pairCommand } from "./cli/pair.ts";
1817
import { hasCloudPublicConfig } from "./cloud/publicConfig.ts";
1918
import { extendConnectionAttemptTimeout, keepOutboundFetchOnHttp1 } from "./outboundHttp.ts";
@@ -31,6 +30,7 @@ import { servicePreflightCommand } from "./cli/servicePreflight.ts";
3130
import { themeCommand } from "./cli/theme.ts";
3231
import { traceCommand } from "./cli/trace.ts";
3332
import { triageCommand } from "./cli/triage.ts";
33+
import { connectCommand, statusCommand, upCommand } from "./cli/up.ts";
3434

3535
const layerCliRuntime = Layer.mergeAll(NodeServices.layer, NetService.layer);
3636

@@ -60,7 +60,9 @@ const connectUnavailableCommand = Command.make("connect", {
6060

6161
export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
6262
Command.make("t3", { ...sharedServerCommandFlags }).pipe(
63-
Command.withDescription("Run the T3 Code server."),
63+
Command.withDescription(
64+
"Run T3 Code in this terminal and open it in your browser. To use it from your other devices, run `t3 up`.",
65+
),
6466
Command.withHandler(runDefaultServerCommand),
6567
Command.withSubcommands([
6668
Command.make("help").pipe(
@@ -80,6 +82,8 @@ export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
8082
browserCommand,
8183
projectCommand,
8284
threadCommand,
85+
upCommand,
86+
statusCommand,
8387
serviceCommand,
8488
updateCommand,
8589
uninstallCommand,

‎apps/server/src/cli/config.test.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const minimalDesktopFlags = (baseDir: string) => ({
4949
logWebSocketEvents: Option.none<boolean>(),
5050
tailscaleServeEnabled: Option.none<boolean>(),
5151
tailscaleServePort: Option.none<number>(),
52+
lan: Option.none<boolean>(),
5253
});
5354

5455
const encodeDesktopBootstrap = Schema.encodeEffect(Schema.fromJsonString(DesktopBackendBootstrap));
@@ -231,6 +232,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
231232
logWebSocketEvents: Option.none<boolean>(),
232233
tailscaleServeEnabled: Option.none<boolean>(),
233234
tailscaleServePort: Option.none<number>(),
235+
lan: Option.none<boolean>(),
234236
};
235237
const layerConfig = ConfigProvider.layer(
236238
ConfigProvider.fromEnv({
@@ -275,6 +277,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
275277
logWebSocketEvents: Option.none<boolean>(),
276278
tailscaleServeEnabled: Option.none<boolean>(),
277279
tailscaleServePort: Option.none<number>(),
280+
lan: Option.none<boolean>(),
278281
};
279282
const layerConfig = ConfigProvider.layer(
280283
ConfigProvider.fromEnv({ env: { T3CODE_DEV_AUTH_TOKEN: secret } }),
@@ -330,6 +333,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
330333
logWebSocketEvents: Option.some(false),
331334
tailscaleServeEnabled: Option.none(),
332335
tailscaleServePort: Option.none(),
336+
lan: Option.none(),
333337
},
334338
Option.none(),
335339
).pipe(
@@ -406,6 +410,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
406410
logWebSocketEvents: Option.none(),
407411
tailscaleServeEnabled: Option.none(),
408412
tailscaleServePort: Option.none(),
413+
lan: Option.none(),
409414
},
410415
Option.some("Debug"),
411416
).pipe(
@@ -553,6 +558,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
553558
logWebSocketEvents: Option.none(),
554559
tailscaleServeEnabled: Option.none(),
555560
tailscaleServePort: Option.none(),
561+
lan: Option.none(),
556562
},
557563
Option.none(),
558564
).pipe(
@@ -601,6 +607,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
601607
logWebSocketEvents: Option.none(),
602608
tailscaleServeEnabled: Option.none(),
603609
tailscaleServePort: Option.none(),
610+
lan: Option.none(),
604611
},
605612
Option.none(),
606613
).pipe(
@@ -641,6 +648,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
641648
logWebSocketEvents: Option.none(),
642649
tailscaleServeEnabled: Option.none(),
643650
tailscaleServePort: Option.none(),
651+
lan: Option.none(),
644652
},
645653
Option.none(),
646654
{
@@ -703,6 +711,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
703711
logWebSocketEvents: Option.none(),
704712
tailscaleServeEnabled: Option.none(),
705713
tailscaleServePort: Option.none(),
714+
lan: Option.none(),
706715
},
707716
Option.none(),
708717
).pipe(
@@ -742,6 +751,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
742751
logWebSocketEvents: Option.none<boolean>(),
743752
tailscaleServeEnabled: Option.none<boolean>(),
744753
tailscaleServePort: Option.none<number>(),
754+
lan: Option.none<boolean>(),
745755
});
746756

747757
it.effect(
@@ -863,7 +873,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
863873
}),
864874
);
865875

866-
it.effect("listens on private networks only under the service launcher with no host set", () =>
876+
it.effect("listens on private networks per T3CODE_LAN, else under the service launcher", () =>
867877
Effect.gen(function* () {
868878
const { join } = yield* Path.Path;
869879
const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-service-host");
@@ -893,6 +903,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
893903
}),
894904
);
895905

906+
// A service installed before T3CODE_LAN existed.
896907
expect(yield* resolveHost({ connected: true })).toEqual({
897908
host: "0.0.0.0",
898909
privateNetworkOnly: true,
@@ -902,6 +913,14 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
902913
host: "127.0.0.1",
903914
privateNetworkOnly: undefined,
904915
});
916+
expect(yield* resolveHost({ connected: true, env: { T3CODE_LAN: "false" } })).toEqual({
917+
host: undefined,
918+
privateNetworkOnly: undefined,
919+
});
920+
expect(yield* resolveHost({ connected: false, env: { T3CODE_LAN: "true" } })).toEqual({
921+
host: "0.0.0.0",
922+
privateNetworkOnly: true,
923+
});
905924
// Without the launcher's IPC channel the context was inherited, e.g. by
906925
// `t3 serve` started from an agent inside the service.
907926
expect(yield* resolveHost({ connected: false })).toEqual({

‎apps/server/src/cli/config.ts‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ const tailscaleServePortFlag = Flag.Int("tailscale-serve-port").pipe(
8585
Flag.withDescription("HTTPS port for Tailscale Serve when --tailscale-serve is enabled."),
8686
Flag.optional,
8787
);
88+
const lanFlag = Flag.Boolean("lan").pipe(
89+
Flag.withDescription(
90+
"Accept connections from your local network and tailnet, not only this machine (equivalent to T3CODE_LAN).",
91+
),
92+
Flag.optional,
93+
);
8894

8995
export const traceFileConfig = Config.String("T3CODE_TRACE_FILE").pipe(
9096
Config.option,
@@ -165,6 +171,7 @@ const EnvServerConfig = Config.all({
165171
Config.option,
166172
Config.map(Option.getOrUndefined),
167173
),
174+
lan: Config.Boolean("T3CODE_LAN").pipe(Config.option, Config.map(Option.getOrUndefined)),
168175
});
169176

170177
const DevAuthTokenConfig = Config.Redacted("T3CODE_DEV_AUTH_TOKEN").pipe(
@@ -200,6 +207,7 @@ export interface CliServerFlags {
200207
readonly logWebSocketEvents: Option.Option<boolean>;
201208
readonly tailscaleServeEnabled: Option.Option<boolean>;
202209
readonly tailscaleServePort: Option.Option<number>;
210+
readonly lan: Option.Option<boolean>;
203211
}
204212

205213
export interface CliAuthLocationFlags {
@@ -234,6 +242,7 @@ export const sharedServerCommandFlags = {
234242
logWebSocketEvents: logWebSocketEventsFlag,
235243
tailscaleServeEnabled: tailscaleServeFlag,
236244
tailscaleServePort: tailscaleServePortFlag,
245+
lan: lanFlag,
237246
} as const;
238247

239248
const resolveOptionPrecedence = <Value>(
@@ -277,6 +286,7 @@ export const resolveServerConfig = Effect.fn("config.resolveServerConfig")(funct
277286
logWebSocketEvents: flags.logWebSocketEvents ?? Option.none(),
278287
tailscaleServeEnabled: flags.tailscaleServeEnabled ?? Option.none(),
279288
tailscaleServePort: flags.tailscaleServePort ?? Option.none(),
289+
lan: flags.lan ?? Option.none(),
280290
} satisfies CliServerFlags;
281291
const bootstrapFd = Option.getOrUndefined(normalizedFlags.bootstrapFd) ?? env.bootstrapFd;
282292
const bootstrapEnvelope =
@@ -410,16 +420,19 @@ export const resolveServerConfig = Effect.fn("config.resolveServerConfig")(funct
410420
Option.fromUndefinedOr(env.host),
411421
Option.fromUndefinedOr(bootstrap?.host),
412422
);
413-
// A background service exists to be reached from other devices, so it
414-
// listens on private networks unless `service.env` sets `T3CODE_HOST`.
415-
// Clients then learn its LAN address and prefer it over T3 Connect.
423+
// Private networks only, so clients learn a LAN address and prefer it over
424+
// T3 Connect. `t3 service install` writes T3CODE_LAN=false for a new
425+
// service; one installed before T3CODE_LAN existed keeps listening.
426+
const lan = resolveOptionPrecedence(normalizedFlags.lan, Option.fromUndefinedOr(env.lan));
416427
const privateNetworkOnly =
417428
Option.isNone(explicitHost) &&
418429
mode === "web" &&
419-
(yield* resolveServiceLauncherMode().pipe(
420-
Effect.map((launcher) => launcher.managed),
421-
Effect.orElseSucceed(() => false),
422-
));
430+
(Option.isSome(lan)
431+
? lan.value
432+
: yield* resolveServiceLauncherMode().pipe(
433+
Effect.map((launcher) => launcher.managed),
434+
Effect.orElseSucceed(() => false),
435+
));
423436
const host = Option.getOrElse(explicitHost, () =>
424437
privateNetworkOnly ? "0.0.0.0" : mode === "desktop" ? "127.0.0.1" : undefined,
425438
);
@@ -530,6 +543,7 @@ export const resolveCliAuthConfig = (
530543
logWebSocketEvents: Option.none(),
531544
tailscaleServeEnabled: Option.none(),
532545
tailscaleServePort: Option.none(),
546+
lan: Option.none(),
533547
},
534548
cliLogLevel,
535549
);

0 commit comments

Comments
 (0)