@devries-cameron20 / t3code Mirror · read-only / commits / 921a54c2fd
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, 03:37 UTC

fix(server): t3 connect status reports a link made in the app as on (#39471)

Julius Marminge committed Nov 20, 2026 at 15:02 UTC 921a54c2fd7004166deb4410244b7a3d63a8a895
2 files changed +65 -17
apps/server/src/cli/connect.test.ts
+40 -4
@@ -18,6 +18,11 @@ import { Command } from "effect/cli";
18
19 import { makeCli } from "../binCli.ts";
20 import { CLOUD_CLI_DESIRED_LINK_SECRET } from "../cloud/CliState.ts";
21 +import {
22 + CLOUD_ENDPOINT_RUNTIME_CONFIG,
23 + CLOUD_LINKED_USER_ID,
24 + RELAY_ENVIRONMENT_CREDENTIAL_SECRET,
25 +} from "../cloud/config.ts";
26 import {
27 makePersistedServerRuntimeState,
28 persistServerRuntimeState,
@@ -104,6 +109,8 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer))
109 readonly portFreed?: boolean;
110 readonly command?: "unlink" | "status";
111 readonly linkMode?: "managed" | "publish_only";
112 + /** Linked from desktop, web, or mobile: no CLI-desired link is stored. */
113 + readonly linkedByApp?: boolean;
114 },
115 ) =>
116 Effect.gen(function* () {
@@ -143,10 +150,25 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer))
150 if (options?.command === "status") {
151 // Status asks the server for reachability only for a managed link.
152 yield* fs.makeDirectory(`${baseDir}/userdata/secrets`, { recursive: true });
146 - yield* fs.writeFileString(
147 - `${baseDir}/userdata/secrets/${CLOUD_CLI_DESIRED_LINK_SECRET}.bin`,
148 - options.linkMode ?? "managed",
149 - );
153 + yield* options.linkedByApp
154 + ? Effect.all([
155 + fs.writeFileString(
156 + `${baseDir}/userdata/secrets/${CLOUD_LINKED_USER_ID}.bin`,
157 + "user_app_linked",
158 + ),
159 + fs.writeFileString(
160 + `${baseDir}/userdata/secrets/${CLOUD_ENDPOINT_RUNTIME_CONFIG}.bin`,
161 + "{}",
162 + ),
163 + fs.writeFileString(
164 + `${baseDir}/userdata/secrets/${RELAY_ENVIRONMENT_CREDENTIAL_SECRET}.bin`,
165 + "relay_credential",
166 + ),
167 + ])
168 + : fs.writeFileString(
169 + `${baseDir}/userdata/secrets/${CLOUD_CLI_DESIRED_LINK_SECRET}.bin`,
170 + options.linkMode ?? "managed",
171 + );
172 }
173
174 yield* Command.runWith(makeCli({ cloudEnabled: true }), { version: "0.0.0" })([
@@ -219,6 +241,20 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer))
241 }),
242 );
243
244 + it.effect("status checks reachability for an environment linked from the app", () =>
245 + Effect.gen(function* () {
246 + const { requests, printed } = yield* runConnect(process.pid, {
247 + command: "status",
248 + linkedByApp: true,
249 + });
250 +
251 + assert.deepEqual(requests, ["POST /api/connect/reachability"]);
252 + assert.notInclude(printed, "Exposure: disabled");
253 + assert.notInclude(printed, "Authorization: missing");
254 + assert.notInclude(printed, "Next:");
255 + }),
256 + );
257 +
258 it.effect("status does not report a publish-only link as exposed", () =>
259 Effect.gen(function* () {
260 const { printed } = yield* runConnect(process.pid, {
apps/server/src/cli/connect.ts
+25 -13
@@ -36,10 +36,12 @@ import * as CliTokenManager from "../cloud/CliTokenManager.ts";
36 import { formatReachabilityFailure } from "../cloud/ConnectReachability.ts";
37 import { filterRelayResponse } from "../cloud/relayResponse.ts";
38 import {
39 + CLOUD_ENDPOINT_RUNTIME_CONFIG,
40 CLOUD_LINK_REVOKED,
41 CLOUD_LINKED_USER_ID,
42 isAgentActivityPublishingEnabledValue,
43 PUBLISH_AGENT_ACTIVITY_SECRET,
44 + RELAY_ENVIRONMENT_CREDENTIAL_SECRET,
45 RELAY_URL_SECRET,
46 } from "../cloud/config.ts";
47 import { relayUrlConfig } from "../cloud/publicConfig.ts";
@@ -199,17 +201,19 @@ function formatCloudStatus(
201 ? "pending server startup"
202 : "not provisioned";
203 const publishOnly = status.desired && status.linkMode === "publish_only";
202 - const nextStep = !status.authenticated
203 - ? `Run \`${commands.link}\` to authorize and enable T3 Connect.`
204 - : status.revoked
205 - ? `Run \`${commands.link}\` to link this environment again.`
206 - : !status.desired
207 - ? `Run \`${commands.link}\` to enable T3 Connect.`
208 - : !status.linked
209 - ? publishOnly
210 - ? "Start T3 to provision the environment link."
211 - : "Start T3 to provision the environment link and launch its managed tunnel."
212 - : undefined;
204 + // An app-made link needs no CLI credential once provisioned.
205 + const nextStep =
206 + status.desired && status.linked && !status.revoked
207 + ? undefined
208 + : !status.authenticated
209 + ? `Run \`${commands.link}\` to authorize and enable T3 Connect.`
210 + : status.revoked
211 + ? `Run \`${commands.link}\` to link this environment again.`
212 + : !status.desired
213 + ? `Run \`${commands.link}\` to enable T3 Connect.`
214 + : publishOnly
215 + ? "Start T3 to provision the environment link."
216 + : "Start T3 to provision the environment link and launch its managed tunnel.";
217
218 return [
219 "T3 Connect",
@@ -672,8 +676,10 @@ const connectStatusCommand = Command.make("status", {
676 const relayClient = yield* RelayClient.RelayClient;
677 const tokens = yield* CliTokenManager.CloudCliTokenManager;
678 const [
675 - desired,
676 - authenticated,
679 + cliDesired,
680 + managedTunnel,
681 + cliAuthenticated,
682 + relayCredential,
683 cloudUserId,
684 relayUrl,
685 publishAgentActivity,
@@ -683,7 +689,9 @@ const connectStatusCommand = Command.make("status", {
689 ] = yield* Effect.all(
690 [
691 CliState.readCliDesiredCloudLink,
692 + secrets.get(CLOUD_ENDPOINT_RUNTIME_CONFIG),
693 tokens.hasCredential,
694 + secrets.get(RELAY_ENVIRONMENT_CREDENTIAL_SECRET),
695 secrets.get(CLOUD_LINKED_USER_ID),
696 secrets.get(RELAY_URL_SECRET),
697 secrets.get(PUBLISH_AGENT_ACTIVITY_SECRET),
@@ -693,6 +701,10 @@ const connectStatusCommand = Command.make("status", {
701 ],
702 { concurrency: "unbounded" },
703 );
704 + // A link made in the desktop, web, or mobile app saves the tunnel config but no CLI marker.
705 + const desired = cliDesired || Option.isSome(managedTunnel);
706 + // Such a link authorizes the environment with its relay credential, not a CLI sign-in.
707 + const authenticated = cliAuthenticated || Option.isSome(relayCredential);
708 // A publish-only link has no tunnel for other devices to reach.
709 const reachability =
710 desired && linkMode === "managed" ? yield* checkLiveReachability() : null;