Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions apps/server/src/environment/ServerEnvironmentLabel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ const neverExits = ChildProcessSpawner.make(() =>
),
);

it.effect("falls back to the hostname when hostnamectl never answers", () =>
// Without /etc/machine-info the label comes from hostnamectl, which waits on D-Bus.
const linuxLabelWithoutPrettyHostname = (environment: NodeJS.ProcessEnv) =>
Effect.gen(function* () {
// Without /etc/machine-info the label comes from hostnamectl, which waits on D-Bus.
const label = yield* resolveServerEnvironmentLabel({ cwdBaseName: "project" }).pipe(
Effect.provideService(HostProcess.Platform, "linux"),
Effect.provideService(HostProcess.Hostname, "devbox"),
Effect.provideService(HostProcess.Environment, environment),
Effect.provide(
Layer.mergeAll(
FileSystem.layerNoop({ exists: () => Effect.succeed(false) }),
Expand All @@ -47,6 +48,24 @@ it.effect("falls back to the hostname when hostnamectl never answers", () =>
Effect.forkChild,
);
yield* TestClock.adjust("5 seconds");
assert.equal(yield* Fiber.join(label), "devbox");
return yield* Fiber.join(label);
});

it.effect("falls back to the hostname when hostnamectl never answers", () =>
Effect.gen(function* () {
assert.equal(yield* linuxLabelWithoutPrettyHostname({}), "devbox");
}),
);

it.effect("names a WSL backend apart from the Windows hostname it inherits", () =>
Effect.gen(function* () {
assert.equal(
yield* linuxLabelWithoutPrettyHostname({ WSL_DISTRO_NAME: "Ubuntu-24.04" }),
"WSL (Ubuntu-24.04)",
);
assert.equal(
yield* linuxLabelWithoutPrettyHostname({ WSL_INTEROP: "/run/WSL/8_interop" }),
"WSL",
);
}),
);
13 changes: 13 additions & 0 deletions apps/server/src/environment/ServerEnvironmentLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ const runFriendlyLabelCommand = Effect.fn("runFriendlyLabelCommand")(function* (
return normalizeLabel(result.value.stdout);
});

// WSL inherits the Windows hostname, so without this a Windows host and its WSL backend share one name.
function resolveWslLabel(platform: NodeJS.Platform, environment: NodeJS.ProcessEnv): string | null {
if (platform !== "linux") return null;
const distro = normalizeLabel(environment.WSL_DISTRO_NAME);
if (distro) return `WSL (${distro})`;
return normalizeLabel(environment.WSL_INTEROP) ? "WSL" : null;
}

const resolveFriendlyHostLabel = Effect.fn("resolveFriendlyHostLabel")(function* () {
const platform = yield* HostProcess.Platform;
if (platform === "darwin") {
Expand Down Expand Up @@ -189,6 +197,11 @@ export const resolveServerEnvironmentLabel = Effect.fn("resolveServerEnvironment
return friendlyHostLabel;
}

const wslLabel = resolveWslLabel(yield* HostProcess.Platform, yield* HostProcess.Environment);
if (wslLabel) {
return wslLabel;
}

const hostname = normalizeLabel(yield* HostProcess.Hostname);
if (hostname) {
return hostname;
Expand Down
28 changes: 28 additions & 0 deletions apps/web/src/components/settings/ConnectionsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ import {
supportsDesktopAppUpdate,
} from "~/versionSkew";
import { hasCloudPublicConfig } from "~/cloud/publicConfig";
import { useCloudLinkState } from "~/cloud/cloudLinkState";
import { isManagedTunnelActive } from "~/cloud/t3ConnectState";
import { RemoveT3ConnectEnvironmentDialog } from "../clerk/RemoveT3ConnectEnvironmentDialog";
import { authEnvironment } from "~/state/auth";
import { environmentCatalog } from "~/connection/catalog";
Expand Down Expand Up @@ -135,6 +137,7 @@ import { ITEM_ROW_CLASSNAME } from "./itemRows";
import {
CloudLinkRow,
CloudRemoteEnvironmentRows,
LocalBackendConnectRow,
SavedBackendListRow,
} from "./SavedEnvironmentRows";
import { AddEnvironmentDialog } from "./AddEnvironmentDialog";
Expand Down Expand Up @@ -230,6 +233,7 @@ function AccessSettings() {
view="access"
accessEnvironmentId={accessEnvironmentId}
accessEnvironmentPicker={picker}
onSelectAccessEnvironment={setSelectedEnvironmentId}
/>
);
}
Expand All @@ -238,10 +242,12 @@ function ConnectionsSettingsContent({
view,
accessEnvironmentId,
accessEnvironmentPicker = null,
onSelectAccessEnvironment,
}: {
readonly view: "environments" | "access";
readonly accessEnvironmentId: EnvironmentId | null;
readonly accessEnvironmentPicker?: ReactNode;
readonly onSelectAccessEnvironment?: (environmentId: EnvironmentId) => void;
}) {
const desktopBridge = window.desktopBridge;
const { environments } = useEnvironments();
Expand All @@ -267,6 +273,18 @@ function ConnectionsSettingsContent({
const listedEnvironments = savedEnvironments.filter(
(environment) => !isDesktopLocalConnectionTarget(environment.entry.target),
);
// A WSL backend runs its own server and needs its own T3 Connect link; point to it from the host.
const accessLinkState = useCloudLinkState(accessEnvironmentId).data;
const desktopLocalBackends =
isPrimaryAccess &&
desktopBridge !== undefined &&
accessLinkState !== null &&
isManagedTunnelActive(accessLinkState, undefined)
? savedEnvironments.filter(
(environment) =>
environment.entry.enabled && isDesktopLocalConnectionTarget(environment.entry.target),
)
: [];
const savedUpdateStates = useAtomValue(
environmentUpdateStatesAtom(
environmentIdsKey(savedEnvironments.map(({ environmentId }) => environmentId)),
Expand Down Expand Up @@ -1239,6 +1257,16 @@ function ConnectionsSettingsContent({
canManageRelay={canManageRelay}
/>
) : null}
{onSelectAccessEnvironment
? desktopLocalBackends.map((environment) => (
<LocalBackendConnectRow
key={environment.environmentId}
environmentId={environment.environmentId}
label={environment.label}
onSelect={onSelectAccessEnvironment}
/>
))
: null}
{accessEnvironment ? (
<details className="group px-3 sm:px-4">
<summary className="flex min-h-11 cursor-pointer list-none items-center gap-2 rounded-md text-sm font-medium outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring [&::-webkit-details-marker]:hidden">
Expand Down
26 changes: 26 additions & 0 deletions apps/web/src/components/settings/SavedEnvironmentRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import { hasCloudPublicConfig } from "~/cloud/publicConfig";
import { isElectron } from "~/env";
import { useT3ConnectTurnOn } from "~/cloud/useT3ConnectTurnOn";
import { useCloudLinkController } from "~/cloud/useCloudLinkController";
import { useCloudLinkState } from "~/cloud/cloudLinkState";
import { isManagedTunnelActive } from "~/cloud/t3ConnectState";
import { useManagedTunnelUsage } from "~/cloud/managedRelayState";
import { useT3ConnectAccountPage } from "../clerk/T3ConnectAccountPages";
import { TunnelLimitAlert, TunnelUsageMeter } from "../cloud/TunnelUsage";
Expand Down Expand Up @@ -768,6 +770,30 @@ export function CloudLinkRow({
return <ConfiguredCloudLinkRow environmentId={environmentId} canManageRelay={canManageRelay} />;
}

export function LocalBackendConnectRow({
environmentId,
label,
onSelect,
}: {
readonly environmentId: EnvironmentId;
readonly label: string;
readonly onSelect: (environmentId: EnvironmentId) => void;
}) {
const linkState = useCloudLinkState(environmentId).data;
if (linkState === null || isManagedTunnelActive(linkState, undefined)) return null;
return (
<SettingsRow
title={`${label} is not on T3 Connect`}
description="T3 Connect links one environment at a time. Link this machine too so your other devices can reach it."
control={
<Button size="sm" variant="outline" onClick={() => onSelect(environmentId)}>
Set up
</Button>
}
/>
);
}

function EmptyRemoteEnvironments({ cloudEnabled = true }: { readonly cloudEnabled?: boolean }) {
return (
<Empty className="min-h-52">
Expand Down
7 changes: 3 additions & 4 deletions apps/web/src/components/settings/useAccessEnvironment.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { EnvironmentId } from "@t3tools/contracts";

import { isDesktopLocalConnectionTarget } from "../../connection/desktopLocal";
import { useEnvironments, usePrimaryEnvironmentId } from "../../state/environments";
import { resolveAccessEnvironmentId } from "./ConnectionsSettings.logic";
import { settingsScopeEnvironmentLabel } from "./settingsScopeAxis";

/**
* The environments Sharing & access manages, the one `requested` resolves to, and its name.
* The MCP wizard uses the same, so both name an environment alike. A requested environment
* always counts, so a thread on a second WSL backend opens on that backend.
* The MCP wizard uses the same, so both name an environment alike. A desktop-local WSL backend
* is its own environment with its own access, so it is listed too.
*/
export function useAccessEnvironment(requested: EnvironmentId | null) {
const { environments } = useEnvironments();
Expand All @@ -17,7 +16,7 @@ export function useAccessEnvironment(requested: EnvironmentId | null) {
(environment) =>
environment.environmentId === primaryEnvironmentId ||
environment.environmentId === requested ||
(environment.entry.enabled && !isDesktopLocalConnectionTarget(environment.entry.target)),
environment.entry.enabled,
);
const environmentId = resolveAccessEnvironmentId({
primaryEnvironmentId,
Expand Down
6 changes: 6 additions & 0 deletions docs/user/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ there. Install the provider CLIs inside that distro. T3 Code installs its own
server runtime there automatically; the first launch after an app update can
take longer.

The WSL environment is separate from the Windows one and has its own access
settings. To reach it from your phone or another device, open **Settings →
Sharing & access**, choose **WSL (distro)** under **Showing access for**, and
turn on **T3 Connect** there. Once Windows is on T3 Connect, its page also
points to a WSL environment that is not.

### Open a project from a terminal

With the desktop app already running on the same machine:
Expand Down
Loading