@devries-cameron20 / t3code Mirror · read-only / commits / ba1193273a
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, 09:45 UTC

fix(desktop): SSH environments download the remote runtime from T3CODE_RELEASE_BASE_URL (#31396)

Julius Marminge committed Nov 16, 2026 at 17:26 UTC ba1193273ad02c4a758b8b1fe9149361b7905170
5 files changed +78 -17
apps/desktop/src/main.ts
+5 -17
@@ -16,14 +16,11 @@ import * as SecureRandom from "effect/crypto/SecureRandom";
16 import * as Effect from "effect/Effect";
17 import * as FileSystem from "effect/FileSystem";
18 import * as Layer from "effect/Layer";
19 -import * as Option from "effect/Option";
19
20 import * as Electron from "electron";
21
22 import * as NetService from "@t3tools/shared/Net";
23 import * as HostProcess from "@t3tools/shared/HostProcess";
25 -import type { RemoteT3RunnerOptions } from "@t3tools/ssh/tunnel";
26 -import serverPackageJson from "../../server/package.json" with { type: "json" };
24
25 import * as DesktopIpc from "./ipc/DesktopIpc.ts";
26 import * as ElectronApp from "./electron/ElectronApp.ts";
@@ -109,24 +106,15 @@ const layerDesktopEnvironment = Layer.unwrap(
106 }),
107 );
108
112 -const resolveDesktopSshCliRunner = (
113 - environment: DesktopEnvironment.DesktopEnvironment["Service"],
114 -): RemoteT3RunnerOptions => {
115 - const devRemoteEntryPath = Option.getOrUndefined(environment.devRemoteT3ServerEntryPath);
116 - if (environment.isDevelopment && devRemoteEntryPath !== undefined) {
117 - return {
118 - nodeScriptPath: devRemoteEntryPath,
119 - nodeEngineRange: serverPackageJson.engines.node,
120 - };
121 - }
122 - return { archiveVersion: environment.appVersion };
123 -};
124 -
109 const layerDesktopSshEnvironment = Layer.unwrap(
110 Effect.gen(function* () {
111 const environment = yield* DesktopEnvironment.DesktopEnvironment;
112 + const env = yield* HostProcess.Environment;
113 return DesktopSshEnvironment.layer({
129 - resolveCliRunner: Effect.succeed(resolveDesktopSshCliRunner(environment)),
114 + // Per connect: the login shell's environment is installed after this layer is built.
115 + resolveCliRunner: Effect.sync(() =>
116 + DesktopSshEnvironment.resolveDesktopSshCliRunner(environment, env),
117 + ),
118 resolveLauncherId: yield* Effect.cached(
119 DesktopSshEnvironment.readOrCreateLauncherId(
120 environment.path.join(environment.stateDir, "ssh-launcher-id"),
apps/desktop/src/shell/DesktopShellEnvironment.ts
+2
@@ -124,6 +124,7 @@ const LOGIN_SHELL_ENV_NAMES = [
124 "NODE_EXTRA_CA_CERTS",
125 "T3CODE_TELEMETRY_ENABLED",
126 "T3CODE_GITHUB_APP_CLIENT_ID",
127 + "T3CODE_RELEASE_BASE_URL",
128 "__MISE_DIFF",
129 "JAVA_HOME",
130 ] as const;
@@ -550,6 +551,7 @@ const installPosixEnvironment = Effect.fn("desktop.shellEnvironment.installPosix
551 "JAVA_HOME",
552 "T3CODE_TELEMETRY_ENABLED",
553 "T3CODE_GITHUB_APP_CLIENT_ID",
554 + "T3CODE_RELEASE_BASE_URL",
555 ] as const) {
556 if (!config.env[name] && shellEnvironment[name]) {
557 config.env[name] = shellEnvironment[name];
apps/desktop/src/ssh/DesktopSshEnvironment.test.ts new
+47
@@ -0,0 +1,47 @@
1 +import * as NodePath from "@effect/platform-node/NodePath";
2 +import * as NodeServices from "@effect/platform-node/NodeServices";
3 +import { assert, describe, it } from "@effect/vitest";
4 +import { CLI_RELEASE_BASE_URL_ENV } from "@t3tools/shared/cliRelease";
5 +import * as Effect from "effect/Effect";
6 +import * as Layer from "effect/Layer";
7 +
8 +import * as DesktopConfig from "../app/DesktopConfig.ts";
9 +import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
10 +import { resolveDesktopSshCliRunner } from "./DesktopSshEnvironment.ts";
11 +
12 +const packagedEnvironment = DesktopEnvironment.DesktopEnvironment.pipe(
13 + Effect.provide(
14 + DesktopEnvironment.layer({
15 + dirname: "/Applications/T3 Code.app/Contents/Resources/app.asar/dist-electron",
16 + homeDirectory: "/Users/alice",
17 + platform: "darwin",
18 + processArch: "arm64",
19 + appVersion: "0.0.22",
20 + appPath: "/Applications/T3 Code.app/Contents/Resources/app.asar",
21 + isPackaged: true,
22 + resourcesPath: "/Applications/T3 Code.app/Contents/Resources",
23 + runningUnderArm64Translation: false,
24 + }).pipe(
25 + Layer.provide(
26 + Layer.mergeAll(NodeServices.layer, NodePath.layerPosix, DesktopConfig.layerTest({})),
27 + ),
28 + ),
29 + ),
30 +);
31 +
32 +describe("resolveDesktopSshCliRunner", () => {
33 + it.effect("downloads the remote runner from the release mirror", () =>
34 + Effect.gen(function* () {
35 + const environment = yield* packagedEnvironment;
36 +
37 + const runner = resolveDesktopSshCliRunner(environment, {
38 + [CLI_RELEASE_BASE_URL_ENV]: "https://mirror.example.com/t3code",
39 + });
40 +
41 + assert.deepStrictEqual(runner, {
42 + archiveVersion: "0.0.22",
43 + releaseBaseUrl: "https://mirror.example.com/t3code",
44 + });
45 + }),
46 + );
47 +});
apps/desktop/src/ssh/DesktopSshEnvironment.ts
+23
@@ -3,6 +3,7 @@ import type {
3 DesktopSshEnvironmentBootstrap,
4 DesktopSshEnvironmentTarget,
5 } from "@t3tools/contracts";
6 +import { CLI_RELEASE_BASE_URL_ENV } from "@t3tools/shared/cliRelease";
7 import * as NetService from "@t3tools/shared/Net";
8 import * as SshAuth from "@t3tools/ssh/auth";
9 import { resolveSshTarget } from "@t3tools/ssh/command";
@@ -27,6 +28,10 @@ import * as Path from "effect/Path";
28 import * as Schema from "effect/Schema";
29 import * as HttpClient from "effect/http/HttpClient";
30 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
31 +import * as Option from "effect/Option";
32 +import serverPackageJson from "../../../server/package.json" with { type: "json" };
33 +
34 +import type * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
35
36 import * as DesktopSshPasswordPrompts from "./DesktopSshPasswordPrompts.ts";
37
@@ -74,6 +79,24 @@ export interface DesktopSshEnvironmentLayerOptions {
79 readonly resolveLauncherId?: Effect.Effect<string | null>;
80 }
81
82 +export const resolveDesktopSshCliRunner = (
83 + environment: DesktopEnvironment.DesktopEnvironment["Service"],
84 + env: NodeJS.ProcessEnv,
85 +): SshTunnel.RemoteT3RunnerOptions => {
86 + const devRemoteEntryPath = Option.getOrUndefined(environment.devRemoteT3ServerEntryPath);
87 + if (environment.isDevelopment && devRemoteEntryPath !== undefined) {
88 + return {
89 + nodeScriptPath: devRemoteEntryPath,
90 + nodeEngineRange: serverPackageJson.engines.node,
91 + };
92 + }
93 + const releaseBaseUrl = env[CLI_RELEASE_BASE_URL_ENV]?.trim() || undefined;
94 + return {
95 + archiveVersion: environment.appVersion,
96 + ...(releaseBaseUrl === undefined ? {} : { releaseBaseUrl }),
97 + };
98 +};
99 +
100 // Remote servers record this ID as their owner, so it has to outlive restarts,
101 // updates and edits to a saved connection. Without a stored one there is none.
102 export const readOrCreateLauncherId = Effect.fn("desktop.ssh.readOrCreateLauncherId")(
packages/contracts/src/resourceTelemetry.ts
+1
@@ -321,6 +321,7 @@ export const ShellEnvironmentPatch = Schema.Struct({
321 NODE_EXTRA_CA_CERTS: Schema.optionalKey(Schema.NullOr(Schema.String)),
322 T3CODE_TELEMETRY_ENABLED: Schema.optionalKey(Schema.NullOr(Schema.String)),
323 T3CODE_GITHUB_APP_CLIENT_ID: Schema.optionalKey(Schema.NullOr(Schema.String)),
324 + T3CODE_RELEASE_BASE_URL: Schema.optionalKey(Schema.NullOr(Schema.String)),
325 __MISE_DIFF: Schema.optionalKey(Schema.NullOr(Schema.String)),
326 JAVA_HOME: Schema.optionalKey(Schema.NullOr(Schema.String)),
327 FNM_DIR: Schema.optionalKey(Schema.NullOr(Schema.String)),