@devries-cameron20 / t3code Mirror · read-only / commits / 6dad2adc72
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 22, 02:00 UTC

feat(cli): npx t3 offers to install the t3 command (#33150)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Nov 8, 2026 at 18:01 UTC 6dad2adc720cb4945530c9e4cf8e10d9a8c92d88
23 files changed +1389 -58
AGENTS.md
+2 -2
@@ -18,13 +18,13 @@ Lots of apps have gotten bogged down with bad tech decisions and "slop". We have
18
19 ### 3. Remote ready
20
21 -The architecture of T3 Code's websocket layer (npx t3) enables a lot of awesome remote features. These have become core to the product. Whether users are connecting directly over their local network, using Tailscale, or leaning in fully with T3 Connect (our tunnel solution, also in this repo), we need to make sure new features are properly supported.
21 +The architecture of T3 Code's websocket layer (`t3`) enables a lot of awesome remote features. These have become core to the product. Whether users are connecting directly over their local network, using Tailscale, or leaning in fully with T3 Connect (our tunnel solution, also in this repo), we need to make sure new features are properly supported.
22
23 ### 4. Multi-surface
24
25 T3 Code has 3 key app surfaces: **web**, **desktop**, and **mobile**.
26
27 -**Web** is kind of two surfaces, as we have the public facing "app.t3.codes" as well as locally hosting the web app through the `npx t3` command. Both need to be supported by all new features where reasonable.
27 +**Web** is kind of two surfaces, as we have the public facing "app.t3.codes" as well as locally hosting the web app through the `t3` command. Both need to be supported by all new features where reasonable.
28
29 **Desktop** is the main surface most users install first. It's a full Electron app that bundles the server runner as well. The desktop app can also be used as the host server, allowing remote connections from app.t3.codes or the mobile app.
30
README.md
+1 -1
@@ -37,7 +37,7 @@ irm https://t3.codes/install.ps1 | iex
37
38 Then run `t3` to start the server and open the local web app. `t3 service install` keeps it running in the background, `t3 update` moves to a newer release, and `t3 --help` has the full reference.
39
40 -To try it once without installing, run `npx t3@latest` instead.
40 +To try it once without installing, run `npx t3@latest`. It offers to install the `t3` command for you.
41
42 ### Desktop app
43
apps/server/src/binCli.ts
+23 -1
@@ -23,6 +23,12 @@ import { projectCommand } from "./cli/project.ts";
23 import { threadCommand } from "./cli/thread.ts";
24 import { runDefaultServerCommand, serveCommand, startCommand } from "./cli/server.ts";
25 import { updateCommand } from "./cli/update.ts";
26 +import {
27 + confirmCliInstall,
28 + inTerminalForeground,
29 + installCommand,
30 + offerCliInstall,
31 +} from "./cli/install.ts";
32 import { uninstallCommand } from "./cli/uninstall.ts";
33 import { runServiceLauncherCli } from "./cli/serviceLauncher.ts";
34 import { speechWorkerCommand } from "./cli/speechWorker.ts";
@@ -89,6 +95,7 @@ export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
95 statusCommand,
96 serviceCommand,
97 updateCommand,
98 + installCommand,
99 uninstallCommand,
100 // bin.ts runs the bare service invocation; this keeps flags and help working like other commands.
101 Command.make("__service-launcher").pipe(
@@ -115,7 +122,22 @@ export const cli = makeCli();
122 export function runCli() {
123 extendConnectionAttemptTimeout();
124 keepOutboundFetchOnHttp1();
118 - Command.run(cli, { version: packageJson.version }).pipe(
125 + offerCliInstall({
126 + args: process.argv.slice(2),
127 + // A child started over IPC (a service launcher) has no one to answer.
128 + interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY) && process.send === undefined,
129 + foreground: inTerminalForeground,
130 + confirm: confirmCliInstall,
131 + }).pipe(
132 + // The offer handles its own errors; even an unexpected defect must not stop the command.
133 + Effect.catchDefect(() => Effect.succeed(true)),
134 + Effect.flatMap((proceed) =>
135 + proceed
136 + ? Command.run(cli, { version: packageJson.version })
137 + : Effect.sync(() => {
138 + process.exitCode = 130;
139 + }),
140 + ),
141 Effect.scoped,
142 Effect.provide(layerCliRuntime),
143 NodeRuntime.runMain,
apps/server/src/cli/install.test.ts new
+288
@@ -0,0 +1,288 @@
1 +import * as NodeServices from "@effect/platform-node/NodeServices";
2 +import { assert, it } from "@effect/vitest";
3 +import * as HostProcess from "@t3tools/shared/HostProcess";
4 +import * as Deferred from "effect/Deferred";
5 +import * as Effect from "effect/Effect";
6 +import * as Fiber from "effect/Fiber";
7 +import * as FileSystem from "effect/FileSystem";
8 +import * as Path from "effect/Path";
9 +import * as TestClock from "effect/testing/TestClock";
10 +
11 +import packageJson from "../../package.json" with { type: "json" };
12 +import { installCli, isForegroundProcStat, isForegroundPs, offerCliInstall } from "./install.ts";
13 +
14 +const VERSION = packageJson.version;
15 +
16 +/** A standalone runtime in a temp T3 home, started by the npm launcher from an npx cache. */
17 +const setup = Effect.gen(function* () {
18 + const fs = yield* FileSystem.FileSystem;
19 + const path = yield* Path.Path;
20 + const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-install-" });
21 + const runtimeDir = path.join(root, ".t3/runtime");
22 + const executable = path.join(runtimeDir, "versions", VERSION, "t3");
23 + yield* fs.makeDirectory(path.dirname(executable), { recursive: true });
24 + yield* fs.writeFileString(executable, "");
25 + const npmPackage = path.join(root, ".npm/_npx/abc/node_modules/t3");
26 + yield* fs.makeDirectory(path.join(npmPackage, "bin"), { recursive: true });
27 + yield* fs.writeFileString(
28 + path.join(npmPackage, "package.json"),
29 + JSON.stringify({ name: "t3", version: VERSION }),
30 + );
31 + const binDir = path.join(root, "bin");
32 + const provide = <A, E, R>(effect: Effect.Effect<A, E, R>, env: NodeJS.ProcessEnv = {}) =>
33 + effect.pipe(
34 + Effect.provideService(HostProcess.Platform, "linux"),
35 + Effect.provideService(HostProcess.HomeDirectory, root),
36 + Effect.provideService(HostProcess.IsExecutable, true),
37 + Effect.provideService(HostProcess.ExecutablePath, executable),
38 + Effect.provideService(HostProcess.Environment, {
39 + PATH: "/usr/bin",
40 + SHELL: "/bin/zsh",
41 + T3CODE_INSTALL_BIN_DIR: binDir,
42 + T3CODE_NPM_LAUNCHER_PATH: path.join(npmPackage, "bin/t3.mjs"),
43 + ...env,
44 + }),
45 + );
46 + return { root, npmPackage, runtimeDir, executable, link: path.join(binDir, "t3"), provide };
47 +});
48 +
49 +it.layer(NodeServices.layer)("t3 install", (it) => {
50 + it.effect("links the running runtime, records it, and never replaces another t3", () =>
51 + Effect.gen(function* () {
52 + const fs = yield* FileSystem.FileSystem;
53 + const path = yield* Path.Path;
54 + const { root, runtimeDir, executable, link, provide } = yield* setup;
55 +
56 + const older = path.join(runtimeDir, "versions/0.0.1/t3");
57 + yield* fs.makeDirectory(path.dirname(link), { recursive: true });
58 + yield* fs.symlink(older, link);
59 + const installed = yield* provide(installCli());
60 + assert.equal(yield* fs.readLink(link), executable);
61 + assert.isFalse(installed.onPath);
62 + assert.include(installed.pathCommand, "$HOME/bin");
63 +
64 + // A link written through a symlinked T3 home is still ours.
65 + const alias = path.join(root, "alias");
66 + yield* fs.symlink(path.join(root, ".t3"), alias);
67 + yield* fs.remove(link);
68 + yield* fs.symlink(path.join(alias, "runtime/versions", VERSION, "t3"), link);
69 + const onPath = yield* provide(installCli(), { PATH: `/usr/bin:${path.join(root, "bin")}/` });
70 + assert.isTrue(onPath.onPath);
71 + // Another t3 earlier on PATH still runs first, so `t3` would not run this one.
72 + const otherBin = path.join(root, "other-bin");
73 + yield* fs.makeDirectory(otherBin);
74 + yield* fs.writeFileString(path.join(otherBin, "t3"), "");
75 + const shadowed = yield* provide(installCli(), {
76 + PATH: `${otherBin}:${path.join(root, "bin")}`,
77 + });
78 + assert.isFalse(shadowed.onPath);
79 + assert.equal(shadowed.shadowedBy, path.join(otherBin, "t3"));
80 + assert.isUndefined(shadowed.pathCommand);
81 + const recorded = yield* fs.readFileString(path.join(runtimeDir, "launchers"));
82 + assert.equal(recorded, `\n${yield* fs.realPath(path.join(root, "bin"))}/t3\n`);
83 +
84 + yield* fs.remove(link);
85 + yield* fs.writeFileString(link, "#!/bin/sh\n");
86 + const error = yield* provide(installCli()).pipe(Effect.flip);
87 + assert.include(error.message, "Another t3 is already at");
88 + assert.equal(yield* fs.readFileString(link), "#!/bin/sh\n");
89 +
90 + // Only `<version>/t3` is ours, not another program inside a version.
91 + yield* fs.remove(link);
92 + yield* fs.symlink(path.join(runtimeDir, "versions/0.0.1/node"), link);
93 + const sibling = yield* provide(installCli()).pipe(Effect.flip);
94 + assert.include(sibling.message, "Another t3 is already at");
95 + // This home's desktop launcher is replaced, as install.sh does.
96 + yield* fs.remove(link);
97 + yield* fs.symlink(path.join(root, ".t3/bin/t3"), link);
98 + yield* provide(installCli());
99 + assert.equal(yield* fs.readLink(link), executable);
100 +
101 + // A failed swap over our own link leaves a staging path it did not create alone.
102 + yield* fs.remove(link);
103 + yield* fs.symlink(older, link);
104 + const staging = `${link}.${process.pid}.tmp`;
105 + yield* fs.writeFileString(staging, "someone else's\n");
106 + const linkFailed = yield* provide(installCli()).pipe(Effect.flip);
107 + assert.include(linkFailed.message, "Could not link");
108 + assert.equal(yield* fs.readFileString(staging), "someone else's\n");
109 + yield* fs.remove(staging);
110 +
111 + // An empty spot is created exclusively: a file that appears first is kept.
112 + yield* fs.remove(link);
113 + const racing = installCli().pipe(
114 + Effect.provideService(FileSystem.FileSystem, {
115 + ...fs,
116 + symlink: (target, path) =>
117 + fs
118 + .writeFileString(path, "#!/bin/sh\necho raced\n")
119 + .pipe(Effect.andThen(fs.symlink(target, path))),
120 + }),
121 + );
122 + assert.include((yield* provide(racing).pipe(Effect.flip)).message, "Could not link");
123 + assert.equal(yield* fs.readFileString(link), "#!/bin/sh\necho raced\n");
124 + yield* fs.remove(link);
125 +
126 + // Windows writes a t3.cmd: only over its own, and only for paths cmd can run.
127 + const shim = path.join(root, "bin", "t3.cmd");
128 + const windows = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
129 + provide(effect.pipe(Effect.provideService(HostProcess.Platform, "win32")));
130 + const desktopShim =
131 + '@echo off\r\nrem Written by T3 Code\r\n"C:\\T3 Code\\T3 Code.exe" "x" %*\r\n';
132 + yield* fs.writeFileString(shim, desktopShim);
133 + const foreignShim = yield* windows(installCli()).pipe(Effect.flip);
134 + assert.include(foreignShim.message, "Another t3 is already at");
135 + assert.equal(yield* fs.readFileString(shim), desktopShim);
136 + // A user's wrapper that also runs a managed t3.exe is still theirs.
137 + const wrapper = `@echo off\r\nset FOO=1\r\n"${path.join(runtimeDir, "versions/0.0.1/t3.exe")}" %*`;
138 + yield* fs.writeFileString(shim, wrapper);
139 + yield* windows(installCli()).pipe(Effect.flip);
140 + assert.equal(yield* fs.readFileString(shim), wrapper);
141 + // A dangling symlink is not free; writing through it would land outside the bin folder.
142 + const elsewhere = path.join(root, "elsewhere.cmd");
143 + yield* fs.remove(shim);
144 + yield* fs.symlink(elsewhere, shim);
145 + yield* windows(installCli()).pipe(Effect.flip);
146 + assert.isFalse(yield* fs.exists(elsewhere));
147 + yield* fs.remove(shim);
148 + yield* fs.writeFileString(
149 + shim,
150 + `@echo off\r\n"${path.join(runtimeDir, "versions/0.0.1/t3.exe")}" %*`,
151 + );
152 + const windowsInstalled = yield* windows(installCli());
153 + assert.equal(yield* fs.readFileString(shim), `@echo off\r\n"${executable}" %*`);
154 + // A PowerShell command for this window; the saved PATH is left to the user.
155 + assert.equal(windowsInstalled.pathCommand, `$env:Path += ';${path.join(root, "bin")}'`);
156 + const unrunnable = yield* windows(
157 + installCli().pipe(
158 + Effect.provideService(
159 + HostProcess.ExecutablePath,
160 + path.join(runtimeDir, "versions/100%/t3"),
161 + ),
162 + ),
163 + ).pipe(Effect.flip);
164 + assert.include(unrunnable.message, "has % or non-ASCII characters");
165 + }).pipe(Effect.scoped),
166 + );
167 +
168 + it.effect("asks npx users without a t3 command once per minor release and installs on yes", () =>
169 + Effect.gen(function* () {
170 + const fs = yield* FileSystem.FileSystem;
171 + const path = yield* Path.Path;
172 + const { root, npmPackage, runtimeDir, executable, link, provide } = yield* setup;
173 + let asked = 0;
174 + const offer = (
175 + answer: boolean | undefined | Effect.Effect<boolean>,
176 + options: {
177 + readonly args?: ReadonlyArray<string>;
178 + readonly env?: NodeJS.ProcessEnv;
179 + readonly interactive?: boolean;
180 + readonly foreground?: boolean;
181 + } = {},
182 + ) =>
183 + provide(
184 + offerCliInstall({
185 + args: options.args ?? ["connect"],
186 + interactive: options.interactive ?? true,
187 + foreground: Effect.succeed(options.foreground ?? true),
188 + confirm: Effect.andThen(
189 + Effect.sync(() => (asked += 1)),
190 + Effect.isEffect(answer) ? answer : Effect.succeed(answer),
191 + ),
192 + }),
193 + options.env,
194 + );
195 +
196 + // Scripts, CI, sudo, dumb terminals, background jobs, and help never ask.
197 + yield* offer(false, { interactive: false });
198 + yield* offer(false, { env: { CI: "true" } });
199 + yield* offer(false, { env: { SUDO_USER: "theo" } });
200 + yield* offer(false, { env: { TERM: "dumb" } });
201 + yield* offer(false, { env: { npm_config_yes: "true" } });
202 + yield* offer(false, { args: ["--completions", "zsh"] });
203 + yield* offer(false, { foreground: false });
204 + yield* offer(false, { args: ["connect", "--help"] });
205 + yield* offer(false, { args: ["--log-level", "debug", "install"] });
206 + yield* offer(false, { args: ["status", "--json"] });
207 + yield* offer(false, { args: ["up", "--yes"] });
208 + yield* offer(false, { args: ["status", "--json=true"] });
209 + const globalBin = path.join(root, "global-bin");
210 + yield* fs.makeDirectory(globalBin);
211 + yield* fs.writeFileString(path.join(globalBin, "t3"), "");
212 + yield* offer(false, { env: { PATH: globalBin } });
213 + assert.equal(asked, 0);
214 + assert.isFalse(yield* fs.exists(link));
215 +
216 + // A runner's own .bin on PATH is not an installed t3.
217 + const npxBin = path.join(npmPackage, "../.bin");
218 + const pnpmBin = path.join(root, ".cache/pnpm/dlx/abc/node_modules/.bin");
219 + for (const bin of [npxBin, pnpmBin]) {
220 + yield* fs.makeDirectory(bin, { recursive: true });
221 + yield* fs.writeFileString(path.join(bin, "t3"), "");
222 + }
223 + assert.isFalse(yield* offer(undefined, { env: { PATH: `${npxBin}:${pnpmBin}` } }));
224 + assert.equal(asked, 1);
225 + assert.isFalse(yield* fs.exists(path.join(runtimeDir, "install-prompt-declined")));
226 + asked = 0;
227 +
228 + // `service install` is not `t3 install`; it still leaves the command unlinked.
229 + yield* offer(false, { args: ["service", "install"] });
230 + assert.equal(asked, 1);
231 + yield* offer(false);
232 + assert.equal(asked, 1);
233 + assert.isFalse(yield* fs.exists(link));
234 +
235 + yield* fs.writeFileString(path.join(runtimeDir, "install-prompt-declined"), "0.0\n");
236 + yield* offer(true);
237 + assert.equal(asked, 2);
238 + assert.equal(yield* fs.readLink(link), executable);
239 +
240 + yield* fs.remove(path.join(runtimeDir, "install-prompt-declined"));
241 + yield* offer(true);
242 + assert.equal(asked, 2);
243 +
244 + // A yes that cannot install, and no answer at all, also wait for the next minor release.
245 + const declined = path.join(runtimeDir, "install-prompt-declined");
246 + yield* fs.remove(link);
247 + yield* fs.remove(path.join(runtimeDir, "launchers"));
248 + yield* fs.writeFileString(link, "#!/bin/sh\necho mine\n");
249 + asked = 0;
250 + assert.isTrue(yield* offer(true));
251 + assert.equal(yield* fs.readFileString(link), "#!/bin/sh\necho mine\n");
252 + assert.equal(
253 + (yield* fs.readFileString(declined)).trim(),
254 + VERSION.split(".").slice(0, 2).join("."),
255 + );
256 + yield* offer(true);
257 + assert.equal(asked, 1);
258 +
259 + yield* fs.remove(declined);
260 + yield* fs.remove(link);
261 + const waiting = yield* Deferred.make<void>();
262 + const unanswered = yield* offer(
263 + Effect.andThen(Deferred.succeed(waiting, undefined), Effect.never),
264 + ).pipe(Effect.forkChild);
265 + yield* Deferred.await(waiting);
266 + yield* TestClock.adjust("30 seconds");
267 + assert.isTrue(yield* Fiber.join(unanswered));
268 + assert.isTrue(yield* fs.exists(declined));
269 + assert.isFalse(yield* fs.exists(link));
270 + }).pipe(Effect.scoped),
271 + );
272 +
273 + it.effect("reads the terminal's foreground group from /proc and ps", () =>
274 + Effect.sync(() => {
275 + // The command name can hold spaces and parentheses.
276 + const stat = (pgrp: number, tpgid: number) =>
277 + `4242 (t3 (serve) x) S 100 ${pgrp} 100 34816 ${tpgid} 4194560 0 0`;
278 + assert.isTrue(isForegroundProcStat(stat(4242, 4242)));
279 + assert.isFalse(isForegroundProcStat(stat(4242, 4300)));
280 + assert.isFalse(isForegroundProcStat(stat(4242, -1)));
281 + assert.isFalse(isForegroundProcStat(""));
282 + assert.isTrue(isForegroundPs(" 4242 4242\n"));
283 + assert.isFalse(isForegroundPs(" 4300 4242\n"));
284 + assert.isFalse(isForegroundPs(" -1 4242\n"));
285 + assert.isFalse(isForegroundPs(""));
286 + }),
287 + );
288 +});
apps/server/src/cli/install.ts new
+380
@@ -0,0 +1,380 @@
1 +import * as HostProcess from "@t3tools/shared/HostProcess";
2 +import { pathSetupCommand } from "@t3tools/shared/shell";
3 +import * as Console from "effect/Console";
4 +import * as Duration from "effect/Duration";
5 +import * as Effect from "effect/Effect";
6 +import * as FileSystem from "effect/FileSystem";
7 +import * as Option from "effect/Option";
8 +import * as Path from "effect/Path";
9 +import * as Schema from "effect/Schema";
10 +import { Command, Prompt } from "effect/cli";
11 +import * as ChildProcess from "effect/process/ChildProcess";
12 +import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
13 +
14 +import packageJson from "../../package.json" with { type: "json" };
15 +import {
16 + generatedWindowsShimTarget,
17 + isVersionExecutable,
18 + recordPinnedRuntimeLauncher,
19 +} from "../cloud/pinnedRuntime.ts";
20 +import { detectCliRunner, resolveCliCommand, resolveEntryPath } from "./invocation.ts";
21 +
22 +export class CliInstallError extends Schema.TaggedError<CliInstallError>()("CliInstallError", {
23 + reason: Schema.String,
24 + cause: Schema.optional(Schema.Defect()),
25 +}) {
26 + override get message(): string {
27 + return this.reason;
28 + }
29 +}
30 +
31 +/** `<T3 home>/runtime/versions/<version>/t3`: the layout the install scripts and npm launcher share. */
32 +const standaloneRuntime = Effect.gen(function* () {
33 + const path = yield* Path.Path;
34 + if (!(yield* HostProcess.IsExecutable)) return Option.none();
35 + const executable = yield* HostProcess.ExecutablePath;
36 + const versionsDir = path.dirname(path.dirname(executable));
37 + const runtimeDir = path.dirname(versionsDir);
38 + if (path.basename(versionsDir) !== "versions" || path.basename(runtimeDir) !== "runtime") {
39 + return Option.none();
40 + }
41 + return Option.some({ executable, versionsDir, runtimeDir });
42 +});
43 +
44 +/** Links this runtime as the `t3` command the way the install scripts do, replacing only our own link. */
45 +export const installCli = Effect.fn("cli.install.install")(function* () {
46 + const fs = yield* FileSystem.FileSystem;
47 + const path = yield* Path.Path;
48 + const platform = yield* HostProcess.Platform;
49 + const environment = yield* HostProcess.Environment;
50 + const home = yield* HostProcess.HomeDirectory;
51 + const runtime = yield* standaloneRuntime;
52 + const windows = platform === "win32";
53 + if (Option.isNone(runtime)) {
54 + const script = windows
55 + ? "irm https://t3.codes/install.ps1 | iex"
56 + : "curl -fsSL https://t3.codes/install.sh | sh";
57 + return yield* new CliInstallError({
58 + reason: `Only the standalone t3 can install itself. Use \`${script}\`, or Settings in the desktop app.`,
59 + });
60 + }
61 + const { executable, versionsDir, runtimeDir } = runtime.value;
62 + // cmd.exe expands `%` and reads the shim in the OEM code page, so such a path would not run.
63 + if (windows && /[%\u0080-\uffff]/.test(executable)) {
64 + return yield* new CliInstallError({
65 + reason: `A t3.cmd cannot run ${executable}, because the path has % or non-ASCII characters. Keep using npx t3.`,
66 + });
67 + }
68 + // Absolute, so the PATH hint never adds a folder that changes with the working directory.
69 + const binDir = path.resolve(
70 + environment.T3CODE_INSTALL_BIN_DIR?.trim() || path.join(home, ".local", "bin"),
71 + );
72 + const name = windows ? "t3.cmd" : "t3";
73 + const link = path.join(binDir, name);
74 + const failed = (reason: string) => (cause: unknown) => new CliInstallError({ reason, cause });
75 +
76 + // Resolve fully so a link through a symlinked T3 home still counts as ours; a dangling one
77 + // (a pruned version) falls back to its own text.
78 + const realVersionsDir = yield* fs
79 + .realPath(versionsDir)
80 + .pipe(Effect.orElseSucceed(() => versionsDir));
81 + const current = windows
82 + ? yield* fs.readFileString(link).pipe(Effect.map(generatedWindowsShimTarget), Effect.option)
83 + : yield* fs.readLink(link).pipe(
84 + Effect.flatMap((target) =>
85 + fs.realPath(link).pipe(Effect.orElseSucceed(() => path.resolve(binDir, target))),
86 + ),
87 + Effect.option,
88 + );
89 + // A dangling symlink is occupied too: writing the shim would follow it.
90 + const occupied =
91 + Option.isSome(current) ||
92 + (yield* fs.exists(link)) ||
93 + Option.isSome(yield* fs.readLink(link).pipe(Effect.option));
94 + if (
95 + occupied &&
96 + !(
97 + Option.isSome(current) &&
98 + current.value !== undefined &&
99 + (isVersionExecutable(path, versionsDir, current.value) ||
100 + isVersionExecutable(path, realVersionsDir, current.value) ||
101 + // This home's desktop launcher, which install.sh also replaces.
102 + current.value === path.join(path.dirname(runtimeDir), "bin", name))
103 + )
104 + ) {
105 + return yield* new CliInstallError({
106 + reason: `Another t3 is already at ${link}. Remove it, then run this again.`,
107 + });
108 + }
109 +
110 + yield* fs
111 + .makeDirectory(binDir, { recursive: true })
112 + .pipe(Effect.mapError(failed(`Could not create ${binDir}.`)));
113 + // An empty spot is created exclusively, so a file that appears after the check above is kept.
114 + if (windows) {
115 + yield* fs
116 + .writeFileString(link, `@echo off\r\n"${executable}" %*`, occupied ? {} : { flag: "wx" })
117 + .pipe(Effect.mapError(failed(`Could not write ${link}.`)));
118 + } else if (!occupied) {
119 + yield* fs.symlink(executable, link).pipe(Effect.mapError(failed(`Could not link ${link}.`)));
120 + } else {
121 + // Swap a temporary link into place so a running `t3` never sees the command missing.
122 + const staging = `${link}.${process.pid}.tmp`;
123 + // Clean up only a staging link this call made, never a file that was already there.
124 + yield* fs
125 + .symlink(executable, staging)
126 + .pipe(
127 + Effect.andThen(
128 + fs
129 + .rename(staging, link)
130 + .pipe(Effect.tapError(() => fs.remove(staging, { force: true }).pipe(Effect.ignore))),
131 + ),
132 + Effect.mapError(failed(`Could not link ${link}.`)),
133 + );
134 + }
135 +
136 + // Pruning keeps what recorded launchers point at; a background service cannot see binDir otherwise.
137 + const recorded = path.join(
138 + yield* fs.realPath(binDir).pipe(Effect.orElseSucceed(() => binDir)),
139 + name,
140 + );
141 + yield* recordPinnedRuntimeLauncher({
142 + baseDir: path.dirname(runtimeDir),
143 + launcher: recorded,
144 + }).pipe(
145 + Effect.catch(() =>
146 + Console.error(
147 + `Warning: could not record ${recorded} in ${path.join(runtimeDir, "launchers")}. Cleanup may remove the version it runs.`,
148 + ),
149 + ),
150 + );
151 +
152 + // resolve() drops trailing separators, so `~/.local/bin/` on PATH still matches.
153 + const normalize = (value: string) =>
154 + windows ? path.resolve(value).toLowerCase() : path.resolve(value);
155 + const same = (entry: string) => entry !== "" && normalize(entry) === normalize(binDir);
156 + const entries = (environment.PATH ?? environment.Path ?? "").split(windows ? ";" : ":");
157 + const onPath = entries.some(same);
158 + // A t3 earlier on PATH runs instead, and an added folder goes last. Runner caches (npx's own
159 + // .bin) are not installs.
160 + const firstOther = Effect.gen(function* () {
161 + for (const entry of entries) {
162 + if (same(entry)) return undefined;
163 + if (!path.isAbsolute(entry) || detectCliRunner(`${entry}/`) !== null) continue;
164 + for (const name of windows ? ["t3.cmd", "t3.exe"] : ["t3"]) {
165 + const candidate = path.join(entry, name);
166 + if (yield* fs.exists(candidate).pipe(Effect.orElseSucceed(() => false))) return candidate;
167 + }
168 + }
169 + return undefined;
170 + });
171 + const shadowedBy = yield* firstOther;
172 + return {
173 + link,
174 + onPath: onPath && shadowedBy === undefined,
175 + shadowedBy,
176 + pathCommand:
177 + onPath || shadowedBy !== undefined
178 + ? undefined
179 + : windows
180 + ? // PowerShell; it covers this window only, since changing the saved PATH would flatten
181 + // its %VAR% entries. A `;` would split the folder.
182 + binDir.includes(";")
183 + ? undefined
184 + : `$env:Path += ';${binDir.replaceAll("'", "''")}'`
185 + : pathSetupCommand({
186 + directory: binDir,
187 + home,
188 + shell: environment.SHELL,
189 + platform,
190 + configHome: environment.XDG_CONFIG_HOME,
191 + zdotdir: environment.ZDOTDIR,
192 + }),
193 + binDir,
194 + };
195 +});
196 +
197 +const reportInstalled = Effect.fn("cli.install.report")(function* (
198 + installed: Effect.Success<ReturnType<typeof installCli>>,
199 +) {
200 + yield* Console.log(`Installed t3 ${packageJson.version} at ${installed.link}.`);
201 + if (installed.shadowedBy !== undefined) {
202 + return yield* Console.log(
203 + `Another t3 at ${installed.shadowedBy} runs first, so run ${installed.link} to use this one.`,
204 + );
205 + }
206 + if (installed.onPath) return yield* Console.log("Run `t3` to get started.");
207 + if (installed.pathCommand === undefined) {
208 + return yield* Console.log(`Add ${installed.binDir} to your PATH, then run \`t3\`.`);
209 + }
210 + if ((yield* HostProcess.Platform) === "win32") {
211 + yield* Console.log(
212 + `${installed.binDir} is not on your PATH yet. In this PowerShell window, run:`,
213 + );
214 + yield* Console.log(` ${installed.pathCommand}`);
215 + return yield* Console.log("Then run `t3`. For new windows, add the folder to your PATH.");
216 + }
217 + yield* Console.log(`${installed.binDir} is not on your PATH yet. Add it with:`);
218 + yield* Console.log(` ${installed.pathCommand}`);
219 + yield* Console.log("Then open a new terminal and run `t3`.");
220 +});
221 +
222 +export const installCommand = Command.make("install").pipe(
223 + Command.withDescription("Install this version as the `t3` command."),
224 + Command.withHandler(() => installCli().pipe(Effect.flatMap(reportInstalled))),
225 +);
226 +
227 +/** Saying no lasts until the next minor release: `0.2` covers `0.2.5` and `0.2.6-nightly.…`. */
228 +const minorRelease = (version: string) => version.split(".").slice(0, 2).join(".");
229 +
230 +const SKIPPED_ARGUMENTS = new Set([
231 + "help",
232 + "--help",
233 + "-h",
234 + "--version",
235 + "-v",
236 + "--completions",
237 + // Scripts and machine-readable output; a prompt would stall them or corrupt their output.
238 + "--json",
239 + "--yes",
240 + "-y",
241 +]);
242 +
243 +/** The subcommand, past global flags that may come first (two take a value). */
244 +const topLevelCommand = (args: ReadonlyArray<string>) => {
245 + for (let index = 0; index < args.length; index++) {
246 + const arg = args[index]!;
247 + if (arg === "--log-level" || arg === "--completions") index++;
248 + else if (!arg.startsWith("-")) return arg;
249 + }
250 + return undefined;
251 +};
252 +
253 +/** Agents can run commands in a terminal that nobody answers; no answer counts as no. */
254 +const PROMPT_TIMEOUT = Duration.seconds(30);
255 +
256 +/** `/proc/<pid>/stat` fields after the parenthesized command name: state ppid pgrp session tty_nr tpgid. */
257 +export const isForegroundProcStat = (stat: string) => {
258 + const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
259 + return fields[2] !== undefined && fields[2] !== "" && fields[2] === fields[5];
260 +};
261 +
262 +/** Output of `ps -o tpgid=,pgid=`; tpgid is -1 without a controlling terminal. */
263 +export const isForegroundPs = (output: string) => {
264 + const [tpgid, pgid] = output.trim().split(/\s+/);
265 + return tpgid !== undefined && tpgid !== "" && tpgid === pgid;
266 +};
267 +
268 +/**
269 + * A background job (`npx t3 serve &`) that reads the terminal is stopped by the shell, so only
270 + * the terminal's foreground process group may prompt. Unknown counts as background.
271 + */
272 +export const inTerminalForeground = Effect.gen(function* () {
273 + const fs = yield* FileSystem.FileSystem;
274 + const platform = yield* HostProcess.Platform;
275 + if (platform === "win32") return true;
276 + if (platform === "linux") {
277 + return isForegroundProcStat(
278 + yield* fs.readFileString("/proc/self/stat").pipe(Effect.orElseSucceed(() => "")),
279 + );
280 + }
281 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
282 + return isForegroundPs(
283 + yield* spawner
284 + .string(
285 + // Absolute: under npx, PATH starts with a project's node_modules/.bin.
286 + ChildProcess.make("/bin/ps", ["-o", "tpgid=,pgid=", "-p", String(process.pid)], {
287 + stdin: "ignore",
288 + stderr: "ignore",
289 + }),
290 + )
291 + .pipe(Effect.orElseSucceed(() => "")),
292 + );
293 +});
294 +
295 +/**
296 + * Before a command run through npx, pnpm dlx, or bunx at a terminal, asks to install the `t3`
297 + * command. Yes is the default. No, no answer, or a failed install is saved in the T3 home until
298 + * the next minor release. Returns false when the user quits the prompt, so the command does not run.
299 + */
300 +export const offerCliInstall = Effect.fn("cli.install.offer")(function* <E, R, E2, R2>(input: {
301 + readonly args: ReadonlyArray<string>;
302 + readonly interactive: boolean;
303 + readonly foreground: Effect.Effect<boolean, E2, R2>;
304 + /** Undefined when the user quits the prompt. */
305 + readonly confirm: Effect.Effect<boolean | void, E, R>;
306 +}) {
307 + const fs = yield* FileSystem.FileSystem;
308 + const path = yield* Path.Path;
309 + const platform = yield* HostProcess.Platform;
310 + const environment = yield* HostProcess.Environment;
311 + if (!input.interactive || environment.CI || environment.SUDO_USER) return true;
312 + if (environment.TERM === "dumb") return true;
313 + // `npx --yes` asks for no prompts; npm passes it on to the command as npm_config_yes.
314 + if (environment.npm_config_yes === "true") return true;
315 + // `--json=true` and `-y=true` are the same flags.
316 + if (input.args.some((arg) => SKIPPED_ARGUMENTS.has(arg.split("=")[0]!))) return true;
317 + const command = topLevelCommand(input.args);
318 + if (command === "install" || command === "uninstall") return true;
319 + if (detectCliRunner(yield* resolveEntryPath) === null) return true;
320 + const runtime = yield* standaloneRuntime;
321 + if (Option.isNone(runtime)) return true;
322 + const { runtimeDir } = runtime.value;
323 +
324 + // Any t3 already installed means no prompt: ours (even when off PATH) or another on PATH.
325 + // Runners put their own cache's node_modules/.bin on PATH, so skip those.
326 + const windows = platform === "win32";
327 + const names = windows ? ["t3.cmd", "t3.exe"] : ["t3"];
328 + const launchers = yield* fs
329 + .readFileString(path.join(runtimeDir, "launchers"))
330 + .pipe(Effect.orElseSucceed(() => ""));
331 + const candidates = [
332 + ...launchers.split(/\r?\n/).filter(Boolean),
333 + path.join(path.dirname(runtimeDir), "bin", windows ? "t3.cmd" : "t3"),
334 + ...(environment.PATH ?? environment.Path ?? "")
335 + .split(windows ? ";" : ":")
336 + .filter(
337 + (directory) => path.isAbsolute(directory) && detectCliRunner(`${directory}/`) === null,
338 + )
339 + .flatMap((directory) => names.map((name) => path.join(directory, name))),
340 + ];
341 + for (const candidate of candidates) {
342 + if (yield* fs.exists(candidate).pipe(Effect.orElseSucceed(() => false))) return true;
343 + }
344 +
345 + const declinedFile = path.join(runtimeDir, "install-prompt-declined");
346 + const declined = yield* fs.readFileString(declinedFile).pipe(Effect.orElseSucceed(() => ""));
347 + const minor = minorRelease(packageJson.version);
348 + if (declined.trim() === minor) return true;
349 + if (!(yield* input.foreground)) return true;
350 +
351 + const installHint = `Run \`${yield* resolveCliCommand("install")}\` any time.`;
352 + const saveDecline = fs.writeFileString(declinedFile, `${minor}\n`).pipe(Effect.ignore);
353 + const answer = yield* input.confirm.pipe(Effect.timeoutOption(PROMPT_TIMEOUT));
354 + if (Option.isNone(answer)) {
355 + yield* saveDecline;
356 + yield* Console.log(`\nNo answer, so t3 was not installed. ${installHint}\n`);
357 + return true;
358 + }
359 + if (answer.value === undefined) return false;
360 + if (!answer.value) {
361 + yield* saveDecline;
362 + yield* Console.log(`Skipped. ${installHint}\n`);
363 + return true;
364 + }
365 + yield* installCli().pipe(
366 + Effect.flatMap(reportInstalled),
367 + Effect.catch((error) =>
368 + Effect.andThen(saveDecline, Console.error(`Could not install t3: ${error.message}`)),
369 + ),
370 + );
371 + yield* Console.log("");
372 + return true;
373 +});
374 +
375 +export const confirmCliInstall = Prompt.run(
376 + Prompt.Confirm({
377 + message: "Install the t3 command? Then you can run `t3` directly.",
378 + initial: true,
379 + }),
380 +).pipe(Effect.catchTags({ QuitError: () => Effect.void }));
apps/server/src/cli/invocation.ts
+1 -1
@@ -13,7 +13,7 @@ import packageJson from "../../package.json" with { type: "json" };
13 export type CliRunner = "npx" | "pnpm dlx" | "bunx";
14
15 /** Detection is best-effort; callers must fail closed to a plain `t3` command. */
16 -function detectCliRunner(entryPath: string): CliRunner | null {
16 +export function detectCliRunner(entryPath: string): CliRunner | null {
17 const path = entryPath.replaceAll("\\", "/");
18 if (path.includes("/_npx/")) {
19 return "npx";
apps/server/src/cli/uninstall.test.ts
+52 -2
@@ -6,14 +6,17 @@ import * as FileSystem from "effect/FileSystem";
6 import * as Path from "effect/Path";
7 import * as HostProcess from "@t3tools/shared/HostProcess";
8
9 -import { findOwnedLauncher, spawnWindowsRemoval } from "./uninstall.ts";
9 +import { findOwnedLauncher, findRecordedLaunchers, spawnWindowsRemoval } from "./uninstall.ts";
10
11 it.layer(NodeServices.layer)("t3 uninstall launcher", (it) => {
12 it.effect("claims only a launcher that points into this home's runtime tree", () =>
13 Effect.gen(function* () {
14 const fs = yield* FileSystem.FileSystem;
15 const path = yield* Path.Path;
16 - const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-uninstall-" });
16 + // macOS spells the temp folder /var but resolves it to /private/var.
17 + const root = yield* fs
18 + .makeTempDirectoryScoped({ prefix: "t3-uninstall-" })
19 + .pipe(Effect.flatMap(fs.realPath));
20 const versionsDir = path.join(root, "runtime/versions");
21 const exe = path.join(versionsDir, "1.0.0/t3");
22 const otherExe = path.join(root, "other/runtime/versions/1.0.0/t3");
@@ -33,6 +36,53 @@ it.layer(NodeServices.layer)("t3 uninstall launcher", (it) => {
36 assert.isUndefined(yield* findOwnedLauncher({ launchedAs: theirs, versionsDir }));
37 assert.isUndefined(yield* findOwnedLauncher({ launchedAs: copy, versionsDir }));
38 assert.isUndefined(yield* findOwnedLauncher({ launchedAs: undefined, versionsDir }));
39 +
40 + // On Windows, only the shim exactly as written is ours; a user's wrapper stays.
41 + const shimDir = path.join(root, "win-bin");
42 + const shim = path.join(shimDir, "t3.cmd");
43 + yield* fs.makeDirectory(shimDir);
44 + const windowsOwner = (contents: string) =>
45 + fs
46 + .writeFileString(shim, contents)
47 + .pipe(
48 + Effect.andThen(findOwnedLauncher({ launchedAs: exe, versionsDir })),
49 + Effect.provideService(HostProcess.Platform, "win32"),
50 + Effect.provideService(HostProcess.Environment, { PATH: shimDir }),
51 + );
52 + assert.equal(yield* windowsOwner(`@echo off\r\n"${exe}" %*`), shim);
53 + assert.isUndefined(yield* windowsOwner(`@echo off\r\nset FOO=1\r\n"${exe}" %*`));
54 +
55 + // npx can run another version than the installed one, so uninstall also reads the
56 + // recorded launchers: through a symlinked home, and dangling after a prune.
57 + const throughAlias = path.join(root, "bin/t3-alias");
58 + const pruned = path.join(root, "bin/t3-pruned");
59 + yield* fs.symlink(root, path.join(root, "alias"));
60 + yield* fs.symlink(path.join(root, "alias/runtime/versions/1.0.0/t3"), throughAlias);
61 + yield* fs.symlink(path.join(versionsDir, "0.9.0/t3"), pruned);
62 + // Another program inside a version is not a launcher.
63 + const sibling = path.join(root, "bin/t3-sibling");
64 + yield* fs.symlink(path.join(versionsDir, "1.0.0/node"), sibling);
65 + yield* fs.writeFileString(
66 + path.join(root, "runtime/launchers"),
67 + [ours, theirs, copy, throughAlias, pruned, sibling, path.join(root, "missing")].join("\n") +
68 + "\n",
69 + );
70 + for (const dir of [versionsDir, path.join(root, "alias/runtime/versions")]) {
71 + assert.deepStrictEqual(yield* findRecordedLaunchers(dir), [ours, throughAlias, pruned]);
72 + }
73 +
74 + // On Windows only an unedited t3.cmd is ours; a hand-edited wrapper belongs to the user.
75 + const cmd = path.join(root, "bin/t3.cmd");
76 + const edited = path.join(root, "bin/edited.cmd");
77 + yield* fs.writeFileString(cmd, `@echo off\r\n"${exe}" %*`);
78 + yield* fs.writeFileString(edited, `@echo off\r\nset "T3CODE_HOME=D:\\other"\r\n"${exe}" %*`);
79 + yield* fs.writeFileString(path.join(root, "runtime/launchers"), `${cmd}\r\n${edited}\r\n`);
80 + assert.deepStrictEqual(
81 + yield* findRecordedLaunchers(versionsDir).pipe(
82 + Effect.provideService(HostProcess.Platform, "win32"),
83 + ),
84 + [cmd],
85 + );
86 }).pipe(Effect.scoped, Effect.provideService(HostProcess.Platform, "linux")),
87 );
88 });
apps/server/src/cli/uninstall.ts
+82 -14
@@ -13,9 +13,9 @@ import { Command, Flag, GlobalFlag, Prompt } from "effect/cli";
13
14 import * as BootService from "../cloud/bootService.ts";
15 import {
16 - launcherOwnsVersionsDir,
16 + generatedWindowsShimTarget,
17 + isVersionExecutable,
18 pinnedRuntimeVersionsDir,
18 - windowsShimTarget,
19 } from "../cloud/pinnedRuntime.ts";
20 import { projectLocationFlags, resolveCliAuthConfig } from "./config.ts";
21 import * as CliService from "./service.ts";
@@ -32,7 +32,8 @@ export class CliUninstallError extends Schema.TaggedError<CliUninstallError>()(
32
33 export interface UninstallPlan {
34 readonly service: boolean;
35 - readonly launcher: string | undefined;
35 + readonly versionsDir: string;
36 + readonly launchers: ReadonlyArray<string>;
37 readonly runtimeDir: string | undefined;
38 readonly userdataDir: string;
39 }
@@ -50,15 +51,71 @@ export const findOwnedLauncher = Effect.fn("cli.uninstall.find_launcher")(functi
51 const shimPath = yield* findWindowsShim(input.launchedAs);
52 if (shimPath === undefined) return undefined;
53 const contents = yield* fs.readFileString(shimPath).pipe(Effect.option);
53 - const target = Option.isSome(contents) ? windowsShimTarget(contents.value) : undefined;
54 - return target !== undefined && launcherOwnsVersionsDir(path, input.versionsDir, target)
54 + const target = Option.isSome(contents) ? generatedWindowsShimTarget(contents.value) : undefined;
55 + return target !== undefined && isVersionExecutable(path, input.versionsDir, target)
56 ? shimPath
57 : undefined;
58 }
59 const linkTarget = yield* fs.readLink(input.launchedAs).pipe(Effect.option);
60 if (Option.isNone(linkTarget)) return undefined;
61 const resolved = path.resolve(path.dirname(input.launchedAs), linkTarget.value);
61 - return launcherOwnsVersionsDir(path, input.versionsDir, resolved) ? input.launchedAs : undefined;
62 + return isVersionExecutable(path, input.versionsDir, resolved) ? input.launchedAs : undefined;
63 +});
64 +
65 +/** Whether `launcher` is a link or unedited `t3.cmd` into this home's runtime/versions. */
66 +const ownsLauncher = Effect.fn("cli.uninstall.owns_launcher")(function* (
67 + launcher: string,
68 + versionsDir: string,
69 +) {
70 + const fs = yield* FileSystem.FileSystem;
71 + const path = yield* Path.Path;
72 + const platform = yield* HostProcess.Platform;
73 + const realVersionsDir = yield* fs
74 + .realPath(versionsDir)
75 + .pipe(Effect.orElseSucceed(() => versionsDir));
76 + // The link's own text keeps a pruned (dangling) target; the real path sees through a
77 + // symlinked T3 home.
78 + const targets =
79 + platform === "win32"
80 + ? [
81 + yield* fs.readFileString(launcher).pipe(
82 + Effect.map(generatedWindowsShimTarget),
83 + Effect.orElseSucceed(() => undefined),
84 + ),
85 + ]
86 + : [
87 + yield* fs.readLink(launcher).pipe(
88 + Effect.map((link) => path.resolve(path.dirname(launcher), link)),
89 + Effect.orElseSucceed(() => undefined),
90 + ),
91 + yield* fs.realPath(launcher).pipe(Effect.orElseSucceed(() => undefined)),
92 + ];
93 + return targets.some(
94 + (target) =>
95 + target !== undefined &&
96 + (isVersionExecutable(path, versionsDir, target) ||
97 + isVersionExecutable(path, realVersionsDir, target)),
98 + );
99 +});
100 +
101 +/**
102 + * Launchers recorded in `runtime/launchers` by the install scripts and `t3 install` that still
103 + * point into this home's runtime/versions. npx can run a different version than the installed
104 + * one, so the launcher this process started from does not always name them.
105 + */
106 +export const findRecordedLaunchers = Effect.fn("cli.uninstall.find_recorded_launchers")(function* (
107 + versionsDir: string,
108 +) {
109 + const fs = yield* FileSystem.FileSystem;
110 + const path = yield* Path.Path;
111 + const recorded = yield* fs
112 + .readFileString(path.join(path.dirname(versionsDir), "launchers"))
113 + .pipe(Effect.orElseSucceed(() => ""));
114 + const owned: Array<string> = [];
115 + for (const launcher of recorded.split(/\r?\n/).filter(Boolean)) {
116 + if (yield* ownsLauncher(launcher, versionsDir)) owned.push(launcher);
117 + }
118 + return owned;
119 });
120
121 // cmd.exe needs verbatim quoting and a literal path, with delayed expansion disabled.
@@ -95,9 +152,16 @@ const planUninstall = Effect.fn("cli.uninstall.plan")(function* (input: {
152 const versionsDir = pinnedRuntimeVersionsDir(path, input.baseDir);
153 const runtimeDir = path.dirname(versionsDir);
154 const launchedAs = (yield* HostProcess.IsExecutable) ? yield* resolveLauncherPath : undefined;
155 + const launchedFrom = yield* findOwnedLauncher({ launchedAs, versionsDir });
156 const plan: UninstallPlan = {
157 service: status.supported && status.installed && servesThisHome,
100 - launcher: yield* findOwnedLauncher({ launchedAs, versionsDir }),
158 + versionsDir,
159 + launchers: [
160 + ...new Set([
161 + ...(launchedFrom === undefined ? [] : [launchedFrom]),
162 + ...(yield* findRecordedLaunchers(versionsDir)),
163 + ]),
164 + ],
165 runtimeDir: (yield* fs.exists(runtimeDir).pipe(Effect.orElseSucceed(() => false)))
166 ? runtimeDir
167 : undefined,
@@ -140,7 +204,7 @@ const runUninstall = Effect.fn("cli.uninstall.run")(function* (input: {
204 const service = yield* BootService.BootService;
205 const plan = yield* planUninstall({ baseDir: input.baseDir });
206
143 - if (!plan.service && plan.launcher === undefined && plan.runtimeDir === undefined) {
207 + if (!plan.service && plan.launchers.length === 0 && plan.runtimeDir === undefined) {
208 yield* Console.log(`Nothing to remove: t3 is not installed for ${input.baseDir}.`);
209 if (!(yield* HostProcess.IsExecutable)) {
210 yield* Console.log(
@@ -152,7 +216,7 @@ const runUninstall = Effect.fn("cli.uninstall.run")(function* (input: {
216
217 yield* Console.log("This will remove:");
218 if (plan.service) yield* Console.log(" the background service (stopping it first)");
155 - if (plan.launcher !== undefined) yield* Console.log(` the launcher at ${plan.launcher}`);
219 + for (const launcher of plan.launchers) yield* Console.log(` the launcher at ${launcher}`);
220 if (plan.runtimeDir !== undefined) {
221 yield* Console.log(` every downloaded version under ${plan.runtimeDir}`);
222 }
@@ -180,16 +244,20 @@ const runUninstall = Effect.fn("cli.uninstall.run")(function* (input: {
244 yield* service.uninstall;
245 yield* Console.log("Removed the background service.");
246 }
183 - if (plan.launcher !== undefined) {
247 + for (const launcher of plan.launchers) {
248 + // The prompt can wait a long time; never delete a file that replaced the launcher meanwhile.
249 + if (!(yield* ownsLauncher(launcher, plan.versionsDir))) {
250 + yield* Console.log(`Left ${launcher}: it no longer runs this t3.`);
251 + continue;
252 + }
253 yield* fs
185 - .remove(plan.launcher, { force: true })
254 + .remove(launcher, { force: true })
255 .pipe(
256 Effect.mapError(
188 - () =>
189 - new CliUninstallError({ reason: `Could not remove the launcher at ${plan.launcher}.` }),
257 + () => new CliUninstallError({ reason: `Could not remove the launcher at ${launcher}.` }),
258 ),
259 );
192 - yield* Console.log(`Removed ${plan.launcher}.`);
260 + yield* Console.log(`Removed ${launcher}.`);
261 }
262 if (plan.runtimeDir !== undefined) {
263 // Windows refuses to unlink this running executable; a detached shell removes it after exit.
apps/server/src/cloud/pinnedRuntime.test.ts
+12
@@ -1,3 +1,4 @@
1 +// @effect-diagnostics nodeBuiltinImport:off - node:path.win32 stands in for a Windows host in one test.
2 import * as NodeServices from "@effect/platform-node/NodeServices";
3 import { assert, it } from "@effect/vitest";
4 import * as Deferred from "effect/Deferred";
@@ -6,6 +7,7 @@ import * as Effect from "effect/Effect";
7 import * as FileSystem from "effect/FileSystem";
8 import * as Fiber from "effect/Fiber";
9 import * as Path from "effect/Path";
10 +import * as NodePath from "node:path";
11 import * as TestClock from "effect/testing/TestClock";
12 import { HttpClient, HttpClientResponse } from "effect/http";
13 import * as ChildProcess from "effect/process/ChildProcess";
@@ -15,6 +17,7 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
17
18 import * as ProcessRunner from "../processRunner.ts";
19 import {
20 + isVersionExecutable,
21 ensurePinnedRuntimeInstalled,
22 isUnpublishedRelease,
23 pinnedRuntimeCommand,
@@ -376,6 +379,15 @@ it.layer(NodeServices.layer)("ensurePinnedRuntimeInstalled", (it) => {
379 );
380 });
381
382 +it("isVersionExecutable accepts only <version>/t3, never another drive or program", () => {
383 + const win32 = NodePath.win32 as unknown as Path.Path;
384 + assert.isTrue(isVersionExecutable(win32, "C:\\t3\\versions", "C:\\t3\\versions\\1.0.0\\t3.exe"));
385 + assert.isFalse(isVersionExecutable(win32, "C:\\t3\\versions", "D:\\t3.exe"));
386 + assert.isFalse(
387 + isVersionExecutable(win32, "C:\\t3\\versions", "C:\\t3\\versions\\1.0.0\\node.exe"),
388 + );
389 +});
390 +
391 it.layer(NodeServices.layer)("prunePinnedRuntimes", (it) => {
392 const lsofRunner = (stdout: string) =>
393 ProcessRunner.ProcessRunner.of({
apps/server/src/cloud/pinnedRuntime.ts
+15
@@ -443,9 +443,24 @@ export const recordPinnedRuntimeLauncher = Effect.fn("cloud.pinned_runtime.recor
443 },
444 );
445
446 +/** Whether `candidate` is a version's own executable, `<versionsDir>/<version>/t3[.exe]`. */
447 +export function isVersionExecutable(
448 + path: Path.Path,
449 + versionsDir: string,
450 + candidate: string,
451 +): boolean {
452 + const relative = path.relative(versionsDir, path.resolve(candidate));
453 + // On another Windows drive, relative() returns the absolute path, like `D:\t3.exe`.
454 + return !path.isAbsolute(relative) && /^(?!\.\.)[^\\/]+[\\/]t3(?:\.exe)?$/i.test(relative);
455 +}
456 +
457 /** The executable a `t3.cmd` shim written by the install script or `t3 update` runs. */
458 export const windowsShimTarget = (contents: string) => /^"([^"]+)"/m.exec(contents)?.[1];
459
460 +/** Like {@link windowsShimTarget}, but only for a shim exactly as written; never a user's wrapper. */
461 +export const generatedWindowsShimTarget = (contents: string) =>
462 + /^@echo off\r?\n"([^"]+)" %\*\s*$/.exec(contents)?.[1];
463 +
464 /** Where the `t3` launchers written by the install scripts and `t3 update` point. */
465 const shellLauncherTargets = Effect.fn("cloud.pinned_runtime.shell_launcher_targets")(function* (
466 baseDir: string,
apps/web/src/components/HostedEmptyState.tsx
+4 -4
@@ -9,7 +9,7 @@ import { hasCloudPublicConfig } from "~/cloud/publicConfig";
9 import { isElectron } from "../env";
10 import { isLocalEnvironmentDisabled } from "../localEnvironment";
11 import { useRelayEnvironmentDiscovery } from "../state/environments";
12 -import { CommandBlock } from "./CommandBlock";
12 +import { InstallT3Commands } from "./InstallT3Commands";
13 import { useT3ConnectAuthPrompt } from "./clerk/useT3ConnectAuthPrompt";
14 import { CloudEnvironmentConnectRows } from "./cloud/CloudEnvironmentConnectList";
15 import { Button } from "./ui/button";
@@ -88,7 +88,7 @@ function T3ConnectSteps() {
88 )}
89 </SetupStep>
90 <SetupStep number={2}>
91 - <RunOnComputer command="npx t3 connect" />
91 + <RunOnComputer command="t3 connect" />
92 {isSignedIn ? (
93 <div className="mt-4 space-y-1.5">
94 <CloudEnvironmentConnectRows
@@ -119,7 +119,7 @@ function PairingSteps() {
119 return (
120 <>
121 <SetupStep number={1}>
122 - <RunOnComputer command="npx t3 pair" />
122 + <RunOnComputer command="t3 pair" />
123 </SetupStep>
124 <SetupStep number={2}>
125 <Button render={<Link to="/settings/connections" />} size="sm">
@@ -149,7 +149,7 @@ function RunOnComputer({ command }: { readonly command: string }) {
149 return (
150 <>
151 <p>Run on your computer:</p>
152 - <CommandBlock command={command} className="mt-2" />
152 + <InstallT3Commands command={command} className="mt-2" />
153 <a
154 className="mt-2 inline-block text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground"
155 href={DESKTOP_DOWNLOAD_URL}
apps/web/src/components/InstallT3Commands.tsx new
+31
@@ -0,0 +1,31 @@
1 +import { cn } from "~/lib/utils";
2 +
3 +import { CommandBlock } from "./CommandBlock";
4 +
5 +/**
6 + * Setup steps for another computer: install `t3`, then run `command`. Both installers are shown
7 + * because the browser showing this is often not the computer being set up.
8 + */
9 +export function InstallT3Commands({
10 + command,
11 + className,
12 +}: {
13 + readonly command: string;
14 + readonly className?: string;
15 +}) {
16 + return (
17 + <div className={cn("space-y-2", className)}>
18 + <p className="text-xs text-muted-foreground">macOS, Linux</p>
19 + <CommandBlock command="curl -fsSL https://t3.codes/install.sh | sh" />
20 + <p className="text-xs text-muted-foreground">Windows (PowerShell)</p>
21 + <CommandBlock command="irm https://t3.codes/install.ps1 | iex" />
22 + <p className="text-xs text-muted-foreground">Then</p>
23 + <CommandBlock command={command} />
24 + <p className="text-xs text-muted-foreground">
25 + Skip the install if you already have <code className="font-mono">t3</code>. If{" "}
26 + <code className="font-mono">t3</code> is not found after installing, add the folder the
27 + installer names to your PATH.
28 + </p>
29 + </div>
30 + );
31 +}
apps/web/src/components/onboarding/WelcomeWizard.tsx
+7 -8
@@ -94,7 +94,7 @@ import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon";
94 import { T3Wordmark } from "../T3Wordmark";
95 import { Alert, AlertDescription } from "../ui/alert";
96 import { Button } from "../ui/button";
97 -import { CommandBlock } from "../CommandBlock";
97 +import { InstallT3Commands } from "../InstallT3Commands";
98 import { Checkbox } from "../ui/checkbox";
99 import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
100 import { Input } from "../ui/input";
@@ -541,7 +541,7 @@ function ConnectAccountOption({
541 <p className="text-sm text-muted-foreground">
542 Run this on each computer you want to connect.
543 </p>
544 - <CommandBlock command="npx t3 connect" className="mt-3" />
544 + <InstallT3Commands command="t3 connect" className="mt-3" />
545 <p className="mt-3 text-xs text-muted-foreground">
546 Keep T3 Code running. Select the computers you want to set up above.
547 </p>
@@ -648,13 +648,12 @@ function PairingForm({
648 </Button>
649 </div>
650 <CollapsiblePanel>
651 - <p className="pt-3 text-sm text-muted-foreground">
652 - On the computer with your code, start T3 Code or run{" "}
653 - <code className="font-mono">npx t3 serve</code>, then run:
654 - </p>
655 - <CommandBlock command="npx t3 pair" className="mt-2" />
651 + <p className="pt-3 text-sm text-muted-foreground">On the computer with your code:</p>
652 + <InstallT3Commands command="t3 pair" className="mt-2" />
653 <p className="mt-2 text-xs leading-relaxed text-muted-foreground">
657 - On a tailnet, run <code className="font-mono">npx t3 pair --tailscale</code> instead.
654 + Start T3 Code or run <code className="font-mono">t3 serve</code> there before{" "}
655 + <code className="font-mono">t3 pair</code>. On a tailnet, run{" "}
656 + <code className="font-mono">t3 pair --tailscale</code> instead.
657 </p>
658 </CollapsiblePanel>
659 </Collapsible>
docs/operations/observability.md
+3 -3
@@ -156,7 +156,7 @@ You do not need any extra env vars. Just run the app normally and inspect `serve
156 Examples:
157
158 ```bash
159 -npx t3
159 +t3
160 ```
161
162 ```bash
@@ -191,7 +191,7 @@ Default Grafana login:
191
192 For endpoint settings and startup precedence, see the
193 [user telemetry guide](../user/telemetry.md#export-diagnostics-to-your-own-receiver).
194 -In a worktree, use `vp run dev` instead of `npx t3` to keep state isolated.
194 +In a worktree, use `vp run dev` instead of `t3` to keep state isolated.
195
196 ```bash
197 export T3CODE_OTLP_TRACES_URL=http://localhost:4318/v1/traces
@@ -212,7 +212,7 @@ export T3CODE_TRACE_TIMING_ENABLED=true
212 CLI:
213
214 ```bash
215 -npx t3
215 +t3
216 ```
217
218 Monorepo web/server dev:
docs/user/faq.md
+2 -2
@@ -13,7 +13,7 @@ Bring your own: Claude Code, Codex, Cursor, Grok Build, OpenCode, Google Antigra
13 We were inspired by the Codex desktop app, Conductor, Claude Desktop, and Cursor Glass, but none met our bar. What you get:
14
15 - Bring your own sub. Claude, Codex, and whatever else you already have installed.
16 -- Best in class remote. Run `npx t3 up` on any box and drive it from anywhere.
16 +- Best in class remote. Run `t3 up` on any box and drive it from anywhere.
17 - Best in class mobile app.
18 - Truly 100% open source. If we go the wrong direction, fork it.
19
@@ -37,7 +37,7 @@ T3 Code drives Claude through Anthropic's Agent SDK. I confirmed it's a real bug
37
38 ## How do I use T3 Code remotely?
39
40 -Your agents run wherever T3 Code runs: your desktop, a server, a VPS. You connect to it from anywhere. I do this constantly. Less than 5% of my prompts run on my laptop. Run `npx t3 up` on that machine and you get really good remote support. T3 Connect is the easy path. LAN pairing and Tailscale work too, and [app.t3.codes](https://app.t3.codes) is the web client. [Remote access](./remote-access.md)
40 +Your agents run wherever T3 Code runs: your desktop, a server, a VPS. You connect to it from anywhere. I do this constantly. Less than 5% of my prompts run on my laptop. Run `t3 up` on that machine and you get really good remote support. T3 Connect is the easy path. LAN pairing and Tailscale work too, and [app.t3.codes](https://app.t3.codes) is the web client. [Remote access](./remote-access.md)
41
42 ## How do I use T3 Code on my phone?
43
docs/user/install.md
+11 -4
@@ -20,9 +20,12 @@ On Windows, in PowerShell:
20 irm https://t3.codes/install.ps1 | iex
21 ```
22
23 -This installs the `t3` binary to `~/.local/bin`. If your shell reports `command not found`
24 -afterwards, that directory is not on your `PATH` yet; the installer prints the
25 -line to add. Set `T3CODE_CHANNEL=nightly` to install the nightly train, or
23 +This installs the `t3` binary to `~/.local/bin`. If that folder is not on your
24 +`PATH` yet, the installer says so and, for zsh, bash on Linux, and fish, prints
25 +a command to add it. On Windows, `t3` works in the same PowerShell window right
26 +away; add the folder to your `PATH` for new windows. If a `t3` that the
27 +installer or the desktop app did not create is already there, it leaves that
28 +one alone and stops. Set `T3CODE_CHANNEL=nightly` to install the nightly train, or
29 `T3CODE_VERSION` to pin an exact version.
30
31 | Task | Command |
@@ -44,7 +47,11 @@ instead. Stop it before starting a replacement, or use a different `--base-dir`
47 for an independent server.
48
49 To try T3 Code once without installing it, run `npx t3@latest` instead (needs
47 -Node.js for `npx`).
50 +Node.js for `npx`). It offers to install the `t3` command first. If you say no,
51 +it asks again at the next minor release, and `npx t3 install` installs it later.
52 +`npx t3` always runs the version npm picked, even when a `t3` is installed. On
53 +the nightly train, run your installed `t3` (for example `t3 connect`), not
54 +`npx t3`, which runs the latest stable release.
55
56 ### Intel Macs
57
docs/user/remote-access.md
+4 -5
@@ -288,9 +288,8 @@ command to run on the host:
288 sudo t3 browser setup
289 ```
290
291 -The server shows the exact line for how you started it, such as
292 -`sudo npx t3 browser setup`, and keeps your `PATH` when Node is installed only
293 -for your user. Where `t3` is not on your `PATH`, such as with only the
291 +The server shows the exact line for how you started it, and keeps your `PATH`
292 +when you started it with `npx` and Node is installed only for your user. Where `t3` is not on your `PATH`, such as with only the
293 desktop app installed, it names the full path of the app's own `t3` instead. It allows Chrome's sandbox with an AppArmor profile and installs
294 any missing libraries and system fonts with apt; pages that load without text
295 can mean the host has no fonts. It is safe to run again. Without `sudo`, it only
@@ -379,11 +378,11 @@ expires.
378 To choose a token's permissions, pass `--scope` once for each scope you want:
379
380 ```sh
382 -npx t3 pair --scope orchestration:read --scope relay:read
381 +t3 pair --scope orchestration:read --scope relay:read
382 ```
383
384 The selected scopes replace the default permissions. The same option works with
386 -`npx t3 auth pairing create` and `npx t3 auth session issue`; each command's
385 +`t3 auth pairing create` and `t3 auth session issue`; each command's
386 `--help` lists the available scopes. Without `--scope`, pairing tokens and issued
387 bearer sessions get every permission, including managing access and T3 Connect.
388 A terminal or a full-access agent on the host can reach those as well, so a
docs/user/welcome-wizard.md
+2 -2
@@ -4,8 +4,8 @@ T3 Code shows a setup flow when you open a new installation. Existing
4 workspaces skip this flow.
5
6 The hosted app at app.t3.codes does not open setup. With no computer connected,
7 -it asks you to sign in to T3 Connect, then to run `npx t3 connect` on your
8 -computer. From home, it adds compatible computers linked to your account and
7 +it asks you to sign in to T3 Connect, then to install T3 Code and run
8 +`t3 connect` on your computer. From home, it adds compatible computers linked to your account and
9 opens the app.
10
11 Close setup while no import is running to go straight to the app. You can connect
packages/shared/src/shell.test.ts
+56
@@ -18,6 +18,8 @@ import { describe, expect, it, vi } from "vite-plus/test";
18
19 import {
20 applyShellEnvironment,
21 + pathSetup,
22 + pathSetupCommand,
23 CommandAvailability,
24 CommandResolutionCache,
25 type CommandAvailabilityChecker,
@@ -1160,3 +1162,57 @@ describe("desktop shell environment updates", () => {
1162 },
1163 );
1164 });
1165 +
1166 +describe("pathSetupCommand", () => {
1167 + // Undefined where a pasted line could break things: Windows (it would flatten %VAR% entries in
1168 + // the registry PATH), macOS bash (several startup files), other shells, and unsafe paths.
1169 + it.each([
1170 + [
1171 + "/home/theo/.local/bin",
1172 + "/bin/bash",
1173 + "linux",
1174 + `printf '\\n%s\\n' 'export PATH="$PATH:/home/theo/.local/bin"' >> ~/.bashrc`,
1175 + ],
1176 + [
1177 + "/Users/theo/.local/bin",
1178 + "/usr/bin/fish",
1179 + "linux",
1180 + `mkdir -p ~/.config/fish && printf '\\n%s\\n' 'fish_add_path --append --path $HOME/.local/bin' >> ~/.config/fish/config.fish`,
1181 + ],
1182 + [
1183 + "/opt/t3/bin",
1184 + "/bin/zsh",
1185 + "linux",
1186 + `printf '\\n%s\\n' 'export PATH="$PATH:/opt/t3/bin"' >> ~/.zshrc`,
1187 + ],
1188 + ["/Users/theo/.local/bin", "/bin/tcsh", "darwin", undefined],
1189 + ["/Users/theo/.local/bin", "/bin/bash", "darwin", undefined],
1190 + ["C:\\Users\\theo\\.local\\bin", "pwsh", "win32", undefined],
1191 + ["/Users/theo/it's here", "/bin/zsh", "darwin", undefined],
1192 + ["/opt/a$PWD/bin", "/bin/zsh", "linux", undefined],
1193 + // Relative: PATH would follow the working directory into any checkout's `bin`.
1194 + ["bin", "/bin/zsh", "linux", undefined],
1195 + ] as const)("%s with %s on %s", (directory, shell, platform, expected) => {
1196 + expect(pathSetupCommand({ directory, home: "/Users/theo", shell, platform })).toBe(expected);
1197 + });
1198 +
1199 + it("writes the startup file fish and zsh read, under XDG_CONFIG_HOME or ZDOTDIR", () => {
1200 + const setup = { directory: "/opt/t3/bin", home: "/home/theo", shell: "/usr/bin/fish" } as const;
1201 + expect(pathSetup({ ...setup, platform: "linux", configHome: "/home/theo/cfg" })?.file).toBe(
1202 + "/home/theo/cfg/fish/config.fish",
1203 + );
1204 + expect(pathSetup({ ...setup, platform: "linux" })?.file).toBe("~/.config/fish/config.fish");
1205 + // zsh reads .zshrc from ZDOTDIR when it is set.
1206 + expect(
1207 + pathSetup({ ...setup, shell: "/bin/zsh", platform: "darwin", zdotdir: "/Users/theo/.zsh" })
1208 + ?.file,
1209 + ).toBe("/Users/theo/.zsh/.zshrc");
1210 + // A set folder that cannot be written safely means no setup, never the unread default.
1211 + expect(
1212 + pathSetup({ ...setup, shell: "/bin/zsh", platform: "darwin", zdotdir: "/Users/theo/my zsh" }),
1213 + ).toBeUndefined();
1214 + expect(
1215 + pathSetup({ ...setup, platform: "linux", configHome: "/home/theo/my cfg" }),
1216 + ).toBeUndefined();
1217 + });
1218 +});
packages/shared/src/shell.ts
+62
@@ -1030,3 +1030,65 @@ export function applyShellEnvironment(
1030 else env[key] = value;
1031 }
1032 }
1033 +
1034 +interface PathSetupInput {
1035 + readonly directory: string;
1036 + readonly home: string;
1037 + readonly shell: string | undefined;
1038 + readonly platform: NodeJS.Platform;
1039 + /** `XDG_CONFIG_HOME`, where fish reads its startup file when set. */
1040 + readonly configHome?: string | undefined;
1041 + /** `ZDOTDIR`, where zsh reads `.zshrc` when set. */
1042 + readonly zdotdir?: string | undefined;
1043 +}
1044 +
1045 +/**
1046 + * The startup file (`~/...`, or absolute under `configHome`) and line that put `directory` last on
1047 + * PATH for new zsh, bash, or fish terminals, so it never shadows another `t3`. Undefined on Windows (writing PATH there would flatten the registry's
1048 + * `%VAR%` entries), for other shells, macOS bash, or unsafe paths.
1049 + */
1050 +export function pathSetup(
1051 + input: PathSetupInput,
1052 +): { readonly file: string; readonly line: string } | undefined {
1053 + // A relative folder on PATH would follow the working directory into any checkout.
1054 + if (input.platform === "win32" || !input.directory.startsWith("/")) return undefined;
1055 + const underHome = input.directory.startsWith(`${input.home}/`);
1056 + const rest = underHome ? input.directory.slice(input.home.length) : input.directory;
1057 + if (!/^[\w./-]+$/.test(rest)) return undefined;
1058 + const directory = underHome ? `$HOME${rest}` : rest;
1059 + const shell = input.shell?.split("/").pop();
1060 + // A set folder the shell reads from replaces the default; one unsafe to write means no setup,
1061 + // since the default file would never be read.
1062 + const readFrom = (value: string | undefined, fallback: string) =>
1063 + !value ? fallback : value.startsWith("/") && /^[\w./-]+$/.test(value) ? value : undefined;
1064 + if (shell === "fish") {
1065 + const configHome = readFrom(input.configHome, "~/.config");
1066 + if (configHome === undefined) return undefined;
1067 + // --path changes $PATH itself; fish_user_paths would go ahead of the system folders.
1068 + return {
1069 + file: `${configHome}/fish/config.fish`,
1070 + line: `fish_add_path --append --path ${directory}`,
1071 + };
1072 + }
1073 + // macOS bash reads only the first of .bash_profile, .bash_login, and .profile; no file is safe.
1074 + const zdotdir = readFrom(input.zdotdir, "~");
1075 + const file =
1076 + shell === "zsh"
1077 + ? zdotdir && `${zdotdir}/.zshrc`
1078 + : shell === "bash" && input.platform !== "darwin"
1079 + ? "~/.bashrc"
1080 + : undefined;
1081 + return file === undefined ? undefined : { file, line: `export PATH="$PATH:${directory}"` };
1082 +}
1083 +
1084 +/** A command to paste that does what {@link pathSetup} describes. */
1085 +export function pathSetupCommand(input: PathSetupInput): string | undefined {
1086 + const setup = pathSetup(input);
1087 + if (!setup) return undefined;
1088 + // The leading newline keeps the line out of a final comment with no newline after it.
1089 + const append = `printf '\\n%s\\n' '${setup.line}' >> ${setup.file}`;
1090 + // fish's config folder may not exist yet; `&&` works in fish 3 too.
1091 + return setup.file.endsWith(".fish")
1092 + ? `mkdir -p ${setup.file.slice(0, setup.file.lastIndexOf("/"))} && ${append}`
1093 + : append;
1094 +}
scripts/install.ps1
+37 -4
@@ -20,6 +20,8 @@ $repo = "pingdotgg/t3code"
20 $baseUrl = if ($env:T3CODE_RELEASE_BASE_URL) { $env:T3CODE_RELEASE_BASE_URL.TrimEnd("/") } else { "https://github.com/$repo/releases/download" }
21 $t3Home = if ($env:T3CODE_HOME) { $env:T3CODE_HOME } else { Join-Path $HOME ".t3" }
22 $binDir = if ($env:T3CODE_INSTALL_BIN_DIR) { $env:T3CODE_INSTALL_BIN_DIR } else { Join-Path $HOME ".local\bin" }
23 +# Absolute, so PATH never gets a folder that changes with the working directory.
24 +$binDir = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($binDir)
25
26 function Fail([string] $message) {
27 Write-Error "t3 install: $message"
@@ -216,19 +218,50 @@ if ((Test-Path $marker) -and ((Get-Content $marker -Raw).Trim() -eq $version)) {
218 Step "Setting up the t3 command..."
219 New-Item -ItemType Directory -Force -Path $binDir | Out-Null
220 $shim = Join-Path $binDir "t3.cmd"
221 +# Replace only a shim that runs a version in this home; never the desktop app's or another t3.
222 +if (Test-Path -LiteralPath $shim) {
223 + $existingTarget = ""
224 + # The shim is UTF-8 without a BOM; Windows PowerShell 5.1 reads files as ANSI by default.
225 + # Only a shim exactly as written here counts; a user's wrapper that also runs t3.exe does not.
226 + $existing = [System.IO.File]::ReadAllText($shim, [System.Text.Encoding]::UTF8)
227 + if ($existing -match '^@echo off\r?\n"([^"]+)" %\*\s*$') { $existingTarget = $Matches[1] }
228 + # Full paths, so a target like versions\..\other cannot pass as ours.
229 + $ownedPrefix = [System.IO.Path]::GetFullPath($versionsDir).TrimEnd('\', '/') + [System.IO.Path]::DirectorySeparatorChar
230 + if ($existingTarget) { $existingTarget = [System.IO.Path]::GetFullPath($existingTarget) }
231 + # Exactly <version>\t3.exe, never another program inside a version.
232 + $owned = $existingTarget.StartsWith($ownedPrefix, [System.StringComparison]::OrdinalIgnoreCase) -and
233 + ($existingTarget.Substring($ownedPrefix.Length) -match '^[^\\/]+\\t3\.exe$')
234 + if (-not $owned) {
235 + Fail "another t3 is already at $shim. Remove it and run this again, or run $(Join-Path $targetDir 't3.exe') directly."
236 + }
237 +}
238 # UTF-8 without a BOM: cmd.exe reads the shim as-is, and ASCII would corrupt
239 # non-ASCII characters in the user's home path.
240 [System.IO.File]::WriteAllText($shim, "@echo off`r`n`"$(Join-Path $targetDir 't3.exe')`" %*", (New-Object System.Text.UTF8Encoding $false))
241 # Pruning keeps what this shim points at; a background service cannot see $binDir otherwise.
242 $launchers = Join-Path $t3Home "runtime\launchers"
224 -$shimPath = (Resolve-Path $shim).Path
243 +$shimPath = (Resolve-Path -LiteralPath $shim).Path
244 if (-not ((Test-Path $launchers) -and ((Get-Content $launchers) -contains $shimPath))) {
245 [System.IO.File]::AppendAllText($launchers, "$shimPath`r`n", (New-Object System.Text.UTF8Encoding $false))
246 }
247 if ($interactive) { [Console]::Error.Write("`r$esc[2K") }
248 [Console]::Error.WriteLine(" ${green}Installed T3 Code $version$reset`n")
230 -if (($env:PATH -split ";") -notcontains $binDir) {
231 - Write-Host " Add $binDir to your PATH, then run ${bold}t3$reset.`n"
249 +if ($binDir.Contains(";")) {
250 + # PATH would split the folder at the `;`, so name the command in full instead.
251 + Write-Host " Run ${bold}& '$($shim.Replace("'", "''"))'$reset to get started.`n"
252 } else {
233 - Write-Host " Run ${bold}t3$reset to use T3 Code here, or ${bold}t3 up$reset to use it from your other devices.`n"
253 + # Either side may end in a separator. Trim only here: a drive root keeps its `\` for Join-Path.
254 + $added = ($env:PATH -split ";" | ForEach-Object { $_.TrimEnd('\', '/') }) -notcontains $binDir.TrimEnd('\', '/')
255 + # `irm | iex` runs in the user's own session, so t3 works in this window right away.
256 + # Last, so it never shadows another t3.
257 + if ($added) { $env:Path = "$env:Path;$binDir" }
258 + # A t3 earlier on PATH runs instead, so name this one in full.
259 + $first = Get-Command t3 -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
260 + if ($first -and [System.IO.Path]::GetFullPath($first.Source) -ne [System.IO.Path]::GetFullPath($shimPath)) {
261 + Write-Host " Another t3 at $($first.Source) runs first, so run ${bold}& '$($shim.Replace("'", "''"))'$reset to use this one.`n"
262 + } elseif ($added) {
263 + Write-Host " Run ${bold}t3$reset to get started. For new windows, add $binDir to your PATH.`n"
264 + } else {
265 + Write-Host " Run ${bold}t3$reset to use T3 Code here, or ${bold}t3 up$reset to use it from your other devices.`n"
266 + }
267 }
scripts/install.sh
+93 -5
@@ -29,6 +29,11 @@ case "$t3_home" in
29 ;;
30 esac
31 bin_dir="${T3CODE_INSTALL_BIN_DIR:-$HOME/.local/bin}"
32 +# Trailing slashes would put `//` in the paths the t3 command guard compares.
33 +while [ "${t3_home%/}" != "$t3_home" ] && [ "$t3_home" != / ]; do t3_home="${t3_home%/}"; done
34 +while [ "${bin_dir%/}" != "$bin_dir" ] && [ "$bin_dir" != / ]; do bin_dir="${bin_dir%/}"; done
35 +# Absolute, so the PATH hint never adds a folder that changes with the working directory.
36 +case "$bin_dir" in /*) ;; *) bin_dir="$PWD/$bin_dir" ;; esac
37
38 fail() {
39 printf '\nt3 install: %s\n' "$1" >&2
@@ -238,14 +243,97 @@ fi
243
244 step "Setting up the t3 command..."
245 mkdir -p "$bin_dir"
241 -ln -sfn "${target_dir}/t3" "${bin_dir}/t3"
246 +# Replace only this home's own t3 links: into its versions, or the desktop app's launcher.
247 +# Anything that is not a symlink (a script, a copied binary) belongs to someone else.
248 +# Exactly <versions>/<version>/t3 ($1 under $2), never another program inside a version.
249 +version_t3() {
250 + case "$1" in "$2"/*) ;; *) return 1 ;; esac
251 + case "${1#"$2"/}" in */*/*) return 1 ;; */t3) return 0 ;; *) return 1 ;; esac
252 +}
253 +slot_empty=true
254 +if [ -e "${bin_dir}/t3" ] || [ -L "${bin_dir}/t3" ]; then
255 + slot_empty=false
256 + owned=false
257 + if [ -L "${bin_dir}/t3" ]; then
258 + existing="$(readlink "${bin_dir}/t3" 2>/dev/null || true)"
259 + case "$existing" in /*) ;; *) existing="${bin_dir}/${existing}" ;; esac
260 + real_versions_dir="$(CDPATH='' cd -P -- "$versions_dir" && pwd)"
261 + # Through a symlinked T3 home the link text names the alias; resolve its folder to compare.
262 + existing_dir="$(CDPATH='' cd -P -- "$(dirname -- "$existing")" 2>/dev/null && pwd || true)"
263 + # The text alone counts only without . or .. segments (a pruned version leaves a dangling link).
264 + case "$existing" in
265 + */./* | */../* | */. | */..) ;;
266 + *)
267 + if version_t3 "$existing" "$versions_dir" || version_t3 "$existing" "$real_versions_dir" ||
268 + [ "$existing" = "${t3_home}/bin/t3" ]; then owned=true; fi
269 + ;;
270 + esac
271 + if [ -n "$existing_dir" ] && version_t3 "${existing_dir}/${existing##*/}" "$real_versions_dir"; then
272 + owned=true
273 + fi
274 + fi
275 + "$owned" || fail "another t3 is already at ${bin_dir}/t3. Remove it and run this again, or run ${target_dir}/t3 directly."
276 +fi
277 +# An empty spot is linked without -f, so a file that appears after the check above is kept.
278 +if "$slot_empty"; then
279 + ln -s "${target_dir}/t3" "${bin_dir}/t3" || fail "could not link ${bin_dir}/t3; something else was created there."
280 +else
281 + # Known race, accepted: a file written here after the ownership check above is overwritten.
282 + ln -sfn "${target_dir}/t3" "${bin_dir}/t3"
283 +fi
284 # Pruning keeps what this launcher points at; a background service cannot see bin_dir otherwise.
285 launcher="$(CDPATH='' cd -P -- "$bin_dir" && pwd)/t3"
286 launchers="${t3_home}/runtime/launchers"
287 grep -qxF "$launcher" "$launchers" 2>/dev/null || printf '%s\n' "$launcher" >> "$launchers"
288 if "$interactive"; then printf '\r\033[2K' >&2; fi
289 printf ' %sInstalled T3 Code %s%s\n\n' "$green" "$version" "$reset" >&2
248 -case ":${PATH}:" in
249 - *":${bin_dir}:"*) printf ' Run %st3%s to use T3 Code here, or %st3 up%s to use it from your other devices.\n\n' "$bold" "$reset" "$bold" "$reset" ;;
250 - *) printf ' Add %s to your PATH, then run %st3%s.\n\n' "$bin_dir" "$bold" "$reset" ;;
251 -esac
290 +# The folder a shell reads its startup file from: $1 when set and safe to paste, else $2 when
291 +# unset. A set but unsafe folder prints nothing, since the default would never be read.
292 +read_from() {
293 + case "$1" in
294 + "") printf '%s' "$2" ;;
295 + /*) case "$1" in *[!A-Za-z0-9_./-]*) ;; *) printf '%s' "$1" ;; esac ;;
296 + esac
297 +}
298 +# A command to paste for zsh, Linux bash, or fish, like `t3 install` prints. macOS bash reads only
299 +# one of several startup files, so no single file is safe to change there.
300 +path_command=
301 +path_rest="$bin_dir"
302 +path_prefix=
303 +case "$bin_dir" in "$HOME"/*) path_rest="${bin_dir#"$HOME"}" path_prefix='$HOME' ;; esac
304 +case "$path_rest" in *[!A-Za-z0-9_./-]*) path_rest= ;; esac
305 +if [ -n "$path_rest" ]; then
306 + # Last on PATH, so it never shadows another t3.
307 + path_line="export PATH=\"\$PATH:${path_prefix}${path_rest}\""
308 + shell_name="${SHELL:-}"
309 + case "${shell_name##*/}" in
310 + zsh)
311 + # zsh reads .zshrc from ZDOTDIR when it is set; ~/.zshrc would never be read then.
312 + zsh_dir="$(read_from "${ZDOTDIR:-}" '~')"
313 + [ -z "$zsh_dir" ] || path_command="printf '\\n%s\\n' '${path_line}' >> ${zsh_dir}/.zshrc" ;;
314 + bash) [ "$platform" = darwin ] || path_command="printf '\\n%s\\n' '${path_line}' >> ~/.bashrc" ;;
315 + fish)
316 + # --path changes $PATH itself; fish_user_paths would go ahead of the system folders.
317 + config_dir="$(read_from "${XDG_CONFIG_HOME:-}" '~/.config')"
318 + fish_dir="${config_dir}/fish"
319 + [ -z "$config_dir" ] || path_command="mkdir -p ${fish_dir} && printf '\\n%s\\n' 'fish_add_path --append --path ${path_prefix}${path_rest}' >> ${fish_dir}/config.fish" ;;
320 + esac
321 +fi
322 +# A t3 earlier on PATH runs instead; the PATH command adds this folder last.
323 +# A PATH entry with a trailing slash gives `dir//t3`.
324 +first_t3="$(command -v t3 2>/dev/null | tr -s / || true)"
325 +case "$first_t3" in "" | "${bin_dir}/t3") first_t3= ;; esac
326 +if [ -n "$first_t3" ]; then
327 + printf ' Another t3 at %s runs first, so run %s%s/t3%s to use this one.\n\n' "$first_t3" "$bold" "$bin_dir" "$reset"
328 +else
329 + case ":${PATH}:" in
330 + *":${bin_dir}:"* | *":${bin_dir}/:"*) printf ' Run %st3%s to use T3 Code here, or %st3 up%s to use it from your other devices.\n\n' "$bold" "$reset" "$bold" "$reset" ;;
331 + *)
332 + if [ -n "$path_command" ]; then
333 + printf ' %s is not on your PATH yet. Add it with:\n\n %s\n\n Then open a new terminal and run %st3%s.\n\n' "$bin_dir" "$path_command" "$bold" "$reset"
334 + else
335 + printf ' Add %s to your PATH, then run %st3%s.\n\n' "$bin_dir" "$bold" "$reset"
336 + fi
337 + ;;
338 + esac
339 +fi
scripts/install.test.ts
+221
@@ -128,6 +128,227 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer chan
128 });
129 });
130
131 +/** Runs an installer for a version that is already unpacked, so only the t3 command step runs. */
132 +async function installOver(input: {
133 + readonly script: "install.sh" | "install.ps1";
134 + readonly home: string;
135 + readonly binDir: string;
136 + readonly env?: NodeJS.ProcessEnv;
137 + readonly cwd?: string;
138 +}) {
139 + const target = NodePath.join(input.home, "runtime", "versions", "1.2.3");
140 + await NodeFSP.mkdir(target, { recursive: true });
141 + await NodeFSP.writeFile(NodePath.join(target, ".install-complete"), "1.2.3\n");
142 + const installer = NodePath.resolve(import.meta.dirname, input.script);
143 + const [command, args] =
144 + input.script === "install.sh"
145 + ? ["sh", [installer]]
146 + : ["powershell.exe", ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", installer]];
147 + const result = NodeChildProcess.spawnSync(command, args, {
148 + encoding: "utf8",
149 + ...(input.cwd === undefined ? {} : { cwd: input.cwd }),
150 + env: {
151 + ...process.env,
152 + T3CODE_CHANNEL: "",
153 + T3CODE_VERSION: "1.2.3",
154 + T3CODE_HOME: input.home,
155 + T3CODE_INSTALL_BIN_DIR: input.binDir,
156 + T3CODE_RELEASE_BASE_URL: "http://127.0.0.1:9",
157 + ...input.env,
158 + },
159 + });
160 + return { code: result.status, output: `${result.stdout}${result.stderr}`, target };
161 +}
162 +
163 +describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("install.sh t3 command", () => {
164 + it("replaces only this home's own links and prints a PATH command", async () => {
165 + const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-link-"));
166 + try {
167 + const home = NodePath.join(root, "home");
168 + const binDir = NodePath.join(root, "bin");
169 + const link = NodePath.join(binDir, "t3");
170 + await NodeFSP.mkdir(binDir, { recursive: true });
171 +
172 + await NodeFSP.writeFile(link, "#!/bin/sh\necho mine\n");
173 + const foreign = await installOver({ script: "install.sh", home, binDir });
174 + expect(foreign.code).not.toBe(0);
175 + expect(foreign.output).toContain(`another t3 is already at ${link}`);
176 + expect(await NodeFSP.readFile(link, "utf8")).toBe("#!/bin/sh\necho mine\n");
177 + // Not even from inside the versions folder, where `.` would resolve into it.
178 + const fromVersions = await installOver({
179 + script: "install.sh",
180 + home,
181 + binDir,
182 + cwd: foreign.target,
183 + });
184 + expect(fromVersions.code).not.toBe(0);
185 + expect(await NodeFSP.readFile(link, "utf8")).toBe("#!/bin/sh\necho mine\n");
186 +
187 + // A link that only looks like it points into versions (join() would normalize the ..).
188 + await NodeFSP.rm(link);
189 + await NodeFSP.mkdir(NodePath.join(home, "other"), { recursive: true });
190 + await NodeFSP.writeFile(NodePath.join(home, "other/t3"), "#!/bin/sh\n");
191 + await NodeFSP.symlink(`${home}/runtime/versions/../../other/t3`, link);
192 + const climbing = await installOver({ script: "install.sh", home, binDir });
193 + expect(climbing.code).not.toBe(0);
194 + expect(await NodeFSP.readlink(link)).toBe(`${home}/runtime/versions/../../other/t3`);
195 +
196 + // Only `<version>/t3` counts, not another program inside a version.
197 + await NodeFSP.rm(link);
198 + await NodeFSP.symlink(NodePath.join(home, "runtime/versions/1.0.0/helper"), link);
199 + const sibling = await installOver({ script: "install.sh", home, binDir });
200 + expect(sibling.code).not.toBe(0);
201 + expect(await NodeFSP.readlink(link)).toBe(
202 + NodePath.join(home, "runtime/versions/1.0.0/helper"),
203 + );
204 +
205 + // An upgrade over an older version's link, written through a symlinked T3 home.
206 + await NodeFSP.rm(link);
207 + await NodeFSP.symlink(NodePath.join(home, "runtime/versions/1.0.0/t3"), link);
208 + await NodeFSP.symlink(home, NodePath.join(root, "alias"));
209 + const upgrade = await installOver({
210 + script: "install.sh",
211 + home: NodePath.join(root, "alias"),
212 + binDir,
213 + env: { HOME: root, SHELL: "/bin/zsh", PATH: "/usr/bin:/bin" },
214 + });
215 + expect(upgrade.code, upgrade.output).toBe(0);
216 + expect(await NodeFSP.readlink(link)).toBe(
217 + NodePath.join(root, "alias/runtime/versions/1.2.3/t3"),
218 + );
219 + expect(upgrade.output).toContain(
220 + `printf '\\n%s\\n' 'export PATH="$PATH:$HOME/bin"' >> ~/.zshrc`,
221 + );
222 +
223 + // Containers and CI often have no SHELL; `set -u` must not stop the installer there.
224 + const noShell = await installOver({
225 + script: "install.sh",
226 + home,
227 + binDir,
228 + env: { HOME: root, SHELL: undefined, PATH: "/usr/bin:/bin" },
229 + });
230 + expect(noShell.code, noShell.output).toBe(0);
231 + expect(noShell.output).toContain(`Add ${binDir} to your PATH`);
232 +
233 + // Its folder on PATH with a trailing slash is still this t3, not another one.
234 + const slashed = await installOver({
235 + script: "install.sh",
236 + home,
237 + binDir,
238 + env: { HOME: root, PATH: `${binDir}/:/usr/bin:/bin` },
239 + });
240 + expect(slashed.code, slashed.output).toBe(0);
241 + expect(slashed.output).toContain("Run t3 to use T3 Code here");
242 +
243 + // A relative folder is made absolute, so the PATH command never follows the working directory.
244 + const relative = await installOver({
245 + script: "install.sh",
246 + home,
247 + binDir: "bin",
248 + cwd: root,
249 + env: { HOME: root, SHELL: "/bin/zsh", PATH: "/usr/bin:/bin" },
250 + });
251 + expect(relative.code, relative.output).toBe(0);
252 + expect(relative.output).toContain(`'export PATH="$PATH:$HOME/bin"'`);
253 +
254 + await NodeFSP.rm(link);
255 + await NodeFSP.symlink(NodePath.join(home, "bin/t3"), link);
256 + const overDesktop = await installOver({
257 + script: "install.sh",
258 + home: `${home}//`,
259 + binDir: `${binDir}/`,
260 + });
261 + expect(overDesktop.code, overDesktop.output).toBe(0);
262 + expect(await NodeFSP.readlink(link)).toBe(NodePath.join(home, "runtime/versions/1.2.3/t3"));
263 + } finally {
264 + await NodeFSP.rm(root, { recursive: true, force: true });
265 + }
266 + });
267 +});
268 +
269 +describe.skipIf(HostProcess.Platform.defaultValue() !== "win32")("install.ps1 t3 command", () => {
270 + it("replaces only its own t3.cmd, also in non-ASCII and bracketed paths", async () => {
271 + const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-ps1-"));
272 + try {
273 + // Windows PowerShell 5.1 reads files as ANSI by default and expands wildcards in paths.
274 + const home = NodePath.join(root, "José", ".t3");
275 + const binDir = NodePath.join(root, "bin[t3]");
276 + const shim = NodePath.join(binDir, "t3.cmd");
277 + await NodeFSP.mkdir(binDir, { recursive: true });
278 +
279 + const desktopShim = '@echo off\r\n"C:\\Program Files\\T3 Code\\T3 Code.exe" "x" %*\r\n';
280 + await NodeFSP.writeFile(shim, desktopShim);
281 + const foreign = await installOver({ script: "install.ps1", home, binDir });
282 + expect(foreign.code).not.toBe(0);
283 + expect(foreign.output).toContain("another t3 is already at");
284 + expect(await NodeFSP.readFile(shim, "utf8")).toBe(desktopShim);
285 +
286 + // A hand-edited wrapper may set its own environment; replacing it would drop that.
287 + const edited = `@echo off\r\nset "T3CODE_HOME=D:\\other"\r\n"${NodePath.join(home, "runtime", "versions", "1.0.0", "t3.exe")}" %*`;
288 + await NodeFSP.writeFile(shim, edited, "utf8");
289 + const wrapper = await installOver({ script: "install.ps1", home, binDir });
290 + expect(wrapper.code).not.toBe(0);
291 + expect(await NodeFSP.readFile(shim, "utf8")).toBe(edited);
292 +
293 + const climbing = `@echo off\r\n"${NodePath.join(home, "runtime", "versions")}\\..\\other\\t3.exe" %*`;
294 + await NodeFSP.writeFile(shim, climbing, "utf8");
295 + const outside = await installOver({ script: "install.ps1", home, binDir });
296 + expect(outside.code).not.toBe(0);
297 + expect(await NodeFSP.readFile(shim, "utf8")).toBe(climbing);
298 +
299 + const older = NodePath.join(home, "runtime", "versions", "1.0.0", "t3.exe");
300 + await NodeFSP.writeFile(shim, `@echo off\r\n"${older}" %*`, "utf8");
301 + const upgrade = await installOver({ script: "install.ps1", home, binDir });
302 + expect(upgrade.code, upgrade.output).toBe(0);
303 + expect(await NodeFSP.readFile(shim, "utf8")).toContain(
304 + NodePath.join(upgrade.target, "t3.exe"),
305 + );
306 +
307 + const again = await installOver({ script: "install.ps1", home, binDir });
308 + expect(again.code, again.output).toBe(0);
309 +
310 + // Another t3 first on PATH still runs, so the installer names this one in full.
311 + const otherBin = NodePath.join(root, "other");
312 + await NodeFSP.mkdir(otherBin);
313 + await NodeFSP.writeFile(NodePath.join(otherBin, "t3.cmd"), "@echo off\r\n");
314 + // Windows spells it Path; a second PATH key would be ambiguous.
315 + const pathKey =
316 + Object.keys(process.env).find((key) => key.toUpperCase() === "PATH") ?? "PATH";
317 + const shadowed = await installOver({
318 + script: "install.ps1",
319 + home,
320 + binDir,
321 + env: { [pathKey]: `${otherBin};${process.env[pathKey] ?? ""}` },
322 + });
323 + expect(shadowed.code, shadowed.output).toBe(0);
324 + expect(shadowed.output).toContain(
325 + `Another t3 at ${NodePath.join(otherBin, "t3.cmd")} runs first`,
326 + );
327 +
328 + // Its own folder on PATH with a trailing separator is already on PATH.
329 + const slashed = await installOver({
330 + script: "install.ps1",
331 + home,
332 + binDir,
333 + env: { [pathKey]: `${binDir}\\;${process.env[pathKey] ?? ""}` },
334 + });
335 + expect(slashed.code, slashed.output).toBe(0);
336 + expect(slashed.output).toContain("to use T3 Code here");
337 + // The same when the install folder itself is given with a trailing separator.
338 + const bothSlashed = await installOver({
339 + script: "install.ps1",
340 + home,
341 + binDir: `${binDir}\\`,
342 + env: { [pathKey]: `${binDir}\\;${process.env[pathKey] ?? ""}` },
343 + });
344 + expect(bothSlashed.code, bothSlashed.output).toBe(0);
345 + expect(bothSlashed.output).toContain("to use T3 Code here");
346 + } finally {
347 + await NodeFSP.rm(root, { recursive: true, force: true });
348 + }
349 + });
350 +});
351 +
352 describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer checksum", () => {
353 it.each(
354 ["home\\data", "home\ndata"].flatMap((homeName) =>