@devries-cameron20 / t3code Mirror · read-only / commits / c910b1bbe9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 12:15 UTC

fix(cli): t3 connect and t3 service hints keep --base-dir (#31906)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

spoukyii committed Nov 14, 2026 at 20:17 UTC c910b1bbe957858da61fe889781ffd0b9ebf0e85
6 files changed +148 -21
apps/server/src/cli/connect.test.ts
+36
@@ -3,6 +3,7 @@ import * as NodeHttp from "node:http";
3
4 import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
5 import * as NodeServices from "@effect/platform-node/NodeServices";
6 +import * as HostProcess from "@t3tools/shared/HostProcess";
7 import * as NetService from "@t3tools/shared/Net";
8 import * as RelayClient from "@t3tools/shared/relayClient";
9 import { assert, it } from "@effect/vitest";
@@ -22,6 +23,7 @@ import {
23 persistServerRuntimeState,
24 } from "../serverRuntimeState.ts";
25 import { acquireRelayClientForLink } from "./connect.ts";
26 +import { resolveHostCliCommand } from "./invocation.ts";
27
28 const managedExecutable = {
29 status: "available",
@@ -59,6 +61,40 @@ it.effect("does not install the relay client when the user declines the managed
61 }),
62 );
63
64 +it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer))(
65 + "t3 connect next steps",
66 + (it) => {
67 + it.effect.each([
68 + { subcommand: "status", hint: "connect link" },
69 + { subcommand: "publish", hint: "connect login" },
70 + ])("t3 connect $subcommand names `t3 $hint` with --base-dir", ({ subcommand, hint }) =>
71 + Effect.gen(function* () {
72 + const fs = yield* FileSystem.FileSystem;
73 + const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-connect-hint-test-" });
74 +
75 + yield* Command.runWith(makeCli({ cloudEnabled: true }), { version: "0.0.0" })([
76 + "connect",
77 + subcommand,
78 + "--base-dir",
79 + baseDir,
80 + ]);
81 +
82 + const { command } = yield* resolveHostCliCommand(hint, ["--base-dir", baseDir]);
83 + assert.include((yield* TestConsole.logLines).join("\n"), `\`${command}\``);
84 + }).pipe(
85 + Effect.scoped,
86 + Effect.provideService(HostProcess.Environment, {}),
87 + Effect.provide(
88 + Layer.mergeAll(
89 + ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
90 + Layer.fresh(TestConsole.layer),
91 + ),
92 + ),
93 + ),
94 + );
95 + },
96 +);
97 +
98 it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer))(
99 "t3 connect unlink and status",
100 (it) => {
apps/server/src/cli/connect.ts
+18 -9
@@ -56,7 +56,7 @@ import {
56 readPersistedServerRuntimeState,
57 } from "../serverRuntimeState.ts";
58 import { projectLocationFlags, resolveCliAuthConfig } from "./config.ts";
59 -import { resolveCliCommand } from "./invocation.ts";
59 +import { resolveHostCliHint } from "./invocation.ts";
60 import * as CliService from "./service.ts";
61
62 const jsonFlag = Flag.Boolean("json").pipe(
@@ -184,7 +184,11 @@ function formatRelayClientStatus(executable: RelayClient.RelayClientStatus): Rea
184 }
185 }
186
187 -function formatCloudStatus(status: CloudCliStatus, options?: { readonly json?: boolean }): string {
187 +function formatCloudStatus(
188 + status: CloudCliStatus,
189 + commands: { readonly link: string; readonly serviceStatus: string },
190 + options?: { readonly json?: boolean },
191 +): string {
192 if (options?.json) {
193 return JSON.stringify(status, null, 2);
194 }
@@ -198,11 +202,11 @@ function formatCloudStatus(status: CloudCliStatus, options?: { readonly json?: b
202 : "not provisioned";
203 const publishOnly = status.desired && status.linkMode === "publish_only";
204 const nextStep = !status.authenticated
201 - ? "Run `t3 connect link` to authorize and enable T3 Connect."
205 + ? `Run \`${commands.link}\` to authorize and enable T3 Connect.`
206 : status.revoked
203 - ? "Run `t3 connect link` to link this environment again."
207 + ? `Run \`${commands.link}\` to link this environment again.`
208 : !status.desired
205 - ? "Run `t3 connect link` to enable T3 Connect."
209 + ? `Run \`${commands.link}\` to enable T3 Connect.`
210 : !status.linked
211 ? publishOnly
212 ? "Start T3 to provision the environment link."
@@ -227,7 +231,7 @@ function formatCloudStatus(status: CloudCliStatus, options?: { readonly json?: b
231 : status.reachability === null
232 ? [
233 "",
230 - "No running server answered, so reachability was not checked. Check the background service with `t3 service status`.",
234 + `No running server answered, so reachability was not checked. Check the background service with \`${commands.serviceStatus}\`.`,
235 ]
236 : status.reachability.status === "reachable"
237 ? [
@@ -667,7 +671,7 @@ const connectLinkCommand = Command.make("link", {
671 yield* Console.log("T3 Connect\n");
672 const linked = yield* linkEnvironmentForConnect(flags);
673 if (linked) {
670 - const serveCommand = yield* resolveCliCommand("serve");
674 + const serveCommand = yield* resolveHostCliHint("serve", flags.baseDir);
675 yield* Console.log(
676 flags.publishOnly
677 ? `✓ Authorized${connectedAs(linked.identity)}\n\nNext\n Start T3 to publish agent activity (no managed tunnel).`
@@ -732,7 +736,11 @@ const connectStatusCommand = Command.make("status", {
736 linkMode,
737 reachability,
738 };
735 - yield* Console.log(formatCloudStatus(status, { json: flags.json }));
739 + const commands = {
740 + link: yield* resolveHostCliHint("connect link", flags.baseDir),
741 + serviceStatus: yield* resolveHostCliHint("service status", flags.baseDir),
742 + };
743 + yield* Console.log(formatCloudStatus(status, commands, { json: flags.json }));
744 }),
745 {
746 quietLogs: flags.json,
@@ -782,8 +790,9 @@ const connectPublishCommand = Command.make("publish", {
790 }
791
792 if (!(yield* tokens.hasCredential)) {
793 + const loginCommand = yield* resolveHostCliHint("connect login", flags.baseDir);
794 yield* Console.log(
786 - "Run `t3 connect login` first so this environment can be authorized to publish.",
795 + `Run \`${loginCommand}\` first so this environment can be authorized to publish.`,
796 );
797 return;
798 }
apps/server/src/cli/invocation.ts
+11
@@ -215,6 +215,17 @@ export const resolveHostCliCommand = Effect.fn("invocation.resolveHostCliCommand
215 return { command: withArgs(`${call} ${subcommand}`), launcher: true };
216 });
217
218 +/** A hint's command, run against the caller's `--base-dir` when one was given. */
219 +export const resolveHostCliHint = (
220 + subcommand: string,
221 + baseDir: Option.Option<string>,
222 + args: ReadonlyArray<string> = [],
223 +) =>
224 + resolveHostCliCommand(subcommand, [
225 + ...Option.match(baseDir, { onNone: () => [], onSome: (dir) => ["--base-dir", dir] }),
226 + ...args,
227 + ]).pipe(Effect.map(({ command }) => command));
228 +
229 /**
230 * `sudo` resets PATH on most distributions, which drops a user-installed Node
231 * (nvm, fnm, a tarball) and with it `npx` or a global `t3`, so the command
apps/server/src/cli/service.test.ts
+57 -1
@@ -12,6 +12,7 @@ import { afterEach, vi } from "vite-plus/test";
12
13 import packageJson from "../../package.json" with { type: "json" };
14 import * as BootService from "../cloud/bootService.ts";
15 +import { resolveHostCliCommand } from "./invocation.ts";
16 import { serviceCommand } from "./service.ts";
17
18 afterEach(() => vi.restoreAllMocks());
@@ -135,11 +136,14 @@ it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands
136 Layer.succeed(BootService.BootService, service),
137 );
138
138 - yield* Command.runWith(serviceCommand, { version: packageJson.version })([
139 + const [lines, up] = yield* Command.runWith(serviceCommand, { version: packageJson.version })([
140 "install",
141 "--base-dir",
142 baseDir,
143 ]).pipe(
144 + Effect.andThen(
145 + Effect.all([TestConsole.logLines, resolveHostCliCommand("up", ["--base-dir", baseDir])]),
146 + ),
147 Effect.provideService(HostProcess.Environment, {}),
148 Effect.provide(
149 Layer.mergeAll(
@@ -149,6 +153,9 @@ it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands
153 ),
154 );
155 expect(yield* fs.readFileString(`${baseDir}/service.env`)).toBe(input.expected);
156 + expect(lines.map(String).filter((line) => line.includes("other devices"))).toEqual(
157 + input.installed ? [] : [`Run \`${up.command}\` to choose how your other devices reach it.`],
158 + );
159 }),
160 );
161
@@ -221,6 +228,55 @@ it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands
228 }),
229 );
230
231 + it.effect.each([
232 + {
233 + label: "a missing service",
234 + status: { ...status, installed: false },
235 + hint: "service install",
236 + args: [],
237 + },
238 + { label: "a newer service", status: newerServiceStatus, hint: "update", args: ["999.0.0"] },
239 + {
240 + label: "a stopped service",
241 + status: { ...status, problems: ["service-stopped"] as const },
242 + hint: "service install",
243 + args: [],
244 + },
245 + {
246 + label: "a restart-pending service",
247 + status: { ...status, problems: ["restart-pending"] as const },
248 + hint: "service restart",
249 + args: [],
250 + },
251 + ])("status of $label names its next step with --base-dir", (input) =>
252 + Effect.gen(function* () {
253 + const fs = yield* FileSystem.FileSystem;
254 + const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-service-cli-test-" });
255 + vi.spyOn(BootService, "layer").mockReturnValue(
256 + Layer.succeed(BootService.BootService, makeTestService(input.status).service),
257 + );
258 +
259 + const [lines, next] = yield* Command.runWith(serviceCommand, {
260 + version: packageJson.version,
261 + })(["status", "--base-dir", baseDir]).pipe(
262 + Effect.andThen(
263 + Effect.all([
264 + TestConsole.logLines,
265 + resolveHostCliCommand(input.hint, ["--base-dir", baseDir, ...input.args]),
266 + ]),
267 + ),
268 + Effect.provideService(HostProcess.Environment, {}),
269 + Effect.provide(
270 + Layer.mergeAll(
271 + ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
272 + Layer.fresh(TestConsole.layer),
273 + ),
274 + ),
275 + );
276 + expect(lines.join("\n")).toContain(`\`${next.command}\``);
277 + }),
278 + );
279 +
280 it.effect.each([
281 { label: "this home's service", otherHome: false, unreadable: false, removed: [true] },
282 { label: "another home's service", otherHome: true, unreadable: false, removed: [] },
apps/server/src/cli/service.ts
+16 -7
@@ -16,7 +16,7 @@ import { compareExactServiceVersions, SERVICE_ENV_FILE } from "../cloud/serviceP
16 import * as ServerConfig from "../config.ts";
17 import * as ProcessRunner from "../processRunner.ts";
18 import { projectLocationFlags, resolveCliAuthConfig } from "./config.ts";
19 -import { resolveEntryPath } from "./invocation.ts";
19 +import { resolveEntryPath, resolveHostCliHint } from "./invocation.ts";
20
21 export const layer = (config: ServerConfig.ServerConfig["Service"]) =>
22 BootService.layer({
@@ -174,13 +174,14 @@ function formatProtection(
174 function formatServiceStatus(
175 status: BootService.BootServiceStatus,
176 cliVersion: string,
177 + commands: { readonly install: string; readonly restart: string; readonly update: string },
178 protection?: ServiceProtection.ServiceProtectionState,
179 ): string {
180 if (!status.supported) {
181 return "T3 Code service\n Status: unavailable on this machine\n Supported on: Linux with systemd, macOS with launchd, Windows with Task Scheduler";
182 }
183 if (!status.installed) {
183 - return "T3 Code service\n Status: not installed\n Next: Run `t3 service install`.";
184 + return `T3 Code service\n Status: not installed\n Next: Run \`${commands.install}\`.`;
185 }
186 if (status.otherBaseDir !== undefined) {
187 return [
@@ -192,7 +193,7 @@ function formatServiceStatus(
193 }
194 const installedVersion = status.installedVersion ?? cliVersion;
195 const problems = (status.problems ?? []).map(
195 - (problem) => ` [${problem}] ${BootService.formatBootServiceProblem(problem)}`,
196 + (problem) => ` [${problem}] ${BootService.formatBootServiceProblem(problem, commands)}`,
197 );
198 if (
199 !status.current &&
@@ -206,7 +207,7 @@ function formatServiceStatus(
207 ` Logs: ${status.logPath}`,
208 ...formatProtection(protection),
209 ...problems,
209 - ` Next: Run \`t3 update ${installedVersion}\` to match it, or pass \`--allow-downgrade\` to \`t3 service install\` explicitly.`,
210 + ` Next: Run \`${commands.update}\` to match it, or pass \`--allow-downgrade\` to \`${commands.install}\` explicitly.`,
211 ].join("\n");
212 }
213 return [
@@ -216,7 +217,7 @@ function formatServiceStatus(
217 ` Logs: ${status.logPath}`,
218 ...formatProtection(protection),
219 ...problems,
219 - ...(status.current ? [] : [" Next: Run `t3 service install` to repair it."]),
220 + ...(status.current ? [] : [` Next: Run \`${commands.install}\` to repair it.`]),
221 ].join("\n");
222 }
223
@@ -254,7 +255,8 @@ const serviceInstallCommand = Command.make("install", serviceReconcileFlags).pip
255 }
256 yield* Console.log(formatServiceChange(result));
257 if (!result.previouslyInstalled) {
257 - yield* Console.log("Run `t3 up` to choose how your other devices reach it.");
258 + const upCommand = yield* resolveHostCliHint("up", flags.baseDir);
259 + yield* Console.log(`Run \`${upCommand}\` to choose how your other devices reach it.`);
260 }
261 }),
262 ),
@@ -358,7 +360,14 @@ const serviceStatusCommand = Command.make("status", projectLocationFlags).pipe(
360 Effect.provide(ProcessRunner.layer),
361 )
362 : undefined;
361 - yield* Console.log(formatServiceStatus(status, packageJson.version, protection));
363 + const commands = {
364 + install: yield* resolveHostCliHint("service install", flags.baseDir),
365 + restart: yield* resolveHostCliHint("service restart", flags.baseDir),
366 + update: yield* resolveHostCliHint("update", flags.baseDir, [
367 + status.installedVersion ?? packageJson.version,
368 + ]),
369 + };
370 + yield* Console.log(formatServiceStatus(status, packageJson.version, commands, protection));
371 }),
372 ),
373 ),
apps/server/src/cloud/bootService.ts
+10 -4
@@ -652,7 +652,13 @@ const BootServiceProblem = Schema.Literals([
652 ]);
653 type BootServiceProblem = typeof BootServiceProblem.Type;
654
655 -export function formatBootServiceProblem(problem: BootServiceProblem): string {
655 +export function formatBootServiceProblem(
656 + problem: BootServiceProblem,
657 + commands: { readonly install: string; readonly restart: string } = {
658 + install: "t3 service install",
659 + restart: "t3 service restart",
660 + },
661 +): string {
662 switch (problem) {
663 case "user-manager-unavailable":
664 return "Cannot reach the systemd user manager. Run `systemctl --user status` in a login session for the service user. Install your distribution's systemd user-session support if it is missing; do not run T3 with sudo.";
@@ -661,11 +667,11 @@ export function formatBootServiceProblem(problem: BootServiceProblem): string {
667 case "linger-disabled":
668 return 'Lingering is disabled. T3 Code will stop when your last login session ends and will not start at boot. Run `sudo loginctl enable-linger "$(id -un)"` on this machine, then retry the service command as your normal user.';
669 case "service-disabled":
664 - return "The service is not enabled to start automatically. Run `t3 service install` to repair it.";
670 + return `The service is not enabled to start automatically. Run \`${commands.install}\` to repair it.`;
671 case "service-stopped":
666 - return "The service is not running. Check the service log (on Linux, also `systemctl --user status t3code.service`), then run `t3 service install`.";
672 + return `The service is not running. Check the service log (on Linux, also \`systemctl --user status t3code.service\`), then run \`${commands.install}\`.`;
673 case "restart-pending":
668 - return "A newer version is installed but the service is still running the previous one. Run `t3 service restart` to switch.";
674 + return `A newer version is installed but the service is still running the previous one. Run \`${commands.restart}\` to switch.`;
675 }
676 }
677