From d695ffed9504c23f962273e159108f55f1393862 Mon Sep 17 00:00:00 2001 From: Kinan Date: Mon, 19 Oct 2026 12:15:27 +0200 Subject: [PATCH 1/9] fix(desktop,web): Open in runs locally for a background service sharing the desktop's T3 home With Local environment off, the desktop reaches a background t3 service on the same machine through a saved connection (T3 Connect, pairing), so Open in, file reveal and the editor picker treated it as remote. Desktop now exposes the environment ID stored in its T3 home and the web client treats the matching environment as this machine. --- apps/desktop/src/ipc/DesktopIpcHandlers.ts | 2 ++ apps/desktop/src/ipc/channels.ts | 1 + .../src/ipc/methods/localEnvironment.test.ts | 30 +++++++++++++++- .../src/ipc/methods/localEnvironment.ts | 20 +++++++++++ apps/desktop/src/preload.ts | 4 +++ apps/web/src/components/ChatView.tsx | 9 ++--- .../src/components/chat/OpenInPicker.logic.ts | 6 ++-- .../src/components/chat/OpenInPicker.test.ts | 18 +++++----- .../src/components/files/FilePreviewPanel.tsx | 7 ++-- apps/web/src/localEnvironment.ts | 7 ++++ apps/web/src/remoteOpen.test.ts | 36 +++++++++++++++++++ apps/web/src/remoteOpen.ts | 5 ++- apps/web/src/state/primaryEnvironment.ts | 12 +++++++ apps/web/src/state/server.ts | 14 +++++--- docs/user/remote-access.md | 3 ++ packages/contracts/src/ipc.ts | 6 ++++ 16 files changed, 154 insertions(+), 26 deletions(-) diff --git a/apps/desktop/src/ipc/DesktopIpcHandlers.ts b/apps/desktop/src/ipc/DesktopIpcHandlers.ts index caed223e90e86..07cf0ed6910f0 100644 --- a/apps/desktop/src/ipc/DesktopIpcHandlers.ts +++ b/apps/desktop/src/ipc/DesktopIpcHandlers.ts @@ -10,6 +10,7 @@ import { setConnectionCatalog, } from "./methods/connectionCatalog.ts"; import { + getHomeEnvironmentId, getLocalEnvironmentEnabled, setLocalEnvironmentEnabled, } from "./methods/localEnvironment.ts"; @@ -99,6 +100,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers" yield* ipc.handleSync(getLocalEnvironmentBootstraps); yield* ipc.handleSync(getLocalEnvironmentEnabled); yield* ipc.handle(setLocalEnvironmentEnabled); + yield* ipc.handleSync(getHomeEnvironmentId); yield* ipc.handle(getLocalEnvironmentBearerToken); yield* ipc.handle(getClientSettings); diff --git a/apps/desktop/src/ipc/channels.ts b/apps/desktop/src/ipc/channels.ts index a6b617385b578..cfa2e2d44f3a6 100644 --- a/apps/desktop/src/ipc/channels.ts +++ b/apps/desktop/src/ipc/channels.ts @@ -33,6 +33,7 @@ export const GET_SYSTEM_LOCALE_CHANNEL = "desktop:get-system-locale"; export const GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL = "desktop:get-local-environment-bootstraps"; export const GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL = "desktop:get-local-environment-enabled"; export const SET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL = "desktop:set-local-environment-enabled"; +export const GET_HOME_ENVIRONMENT_ID_CHANNEL = "desktop:get-home-environment-id"; export const GET_LOCAL_ENVIRONMENT_BEARER_TOKEN_CHANNEL = "desktop:get-local-environment-bearer-token"; export const GET_CLIENT_SETTINGS_CHANNEL = "desktop:get-client-settings"; diff --git a/apps/desktop/src/ipc/methods/localEnvironment.test.ts b/apps/desktop/src/ipc/methods/localEnvironment.test.ts index 94bbf085a9921..2ea1b91c0414c 100644 --- a/apps/desktop/src/ipc/methods/localEnvironment.test.ts +++ b/apps/desktop/src/ipc/methods/localEnvironment.test.ts @@ -1,6 +1,9 @@ +import * as NodeServices from "@effect/platform-node/NodeServices"; import { assert, describe, it } from "@effect/vitest"; import * as Effect from "effect/Effect"; +import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; +import * as Path from "effect/Path"; import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts"; import * as DesktopLifecycle from "../../app/DesktopLifecycle.ts"; @@ -10,7 +13,11 @@ import * as ElectronApp from "../../electron/ElectronApp.ts"; import * as ElectronTheme from "../../electron/ElectronTheme.ts"; import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts"; import * as DesktopWindow from "../../window/DesktopWindow.ts"; -import { getLocalEnvironmentEnabled, setLocalEnvironmentEnabled } from "./localEnvironment.ts"; +import { + getHomeEnvironmentId, + getLocalEnvironmentEnabled, + setLocalEnvironmentEnabled, +} from "./localEnvironment.ts"; const layerUnusedLifecycleRuntime = Layer.mergeAll( DesktopShutdown.layer, @@ -58,4 +65,25 @@ describe("local environment IPC", () => { ]); }).pipe(Effect.provide(layer)); }); + + it.effect("reads the environment ID of whichever server owns the T3 home", () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const stateDir = yield* fileSystem.makeTempDirectoryScoped(); + const readHomeEnvironmentId = getHomeEnvironmentId.handler().pipe( + Effect.provideService( + DesktopEnvironment.DesktopEnvironment, + DesktopEnvironment.DesktopEnvironment.of({ + path, + stateDir, + } as unknown as DesktopEnvironment.DesktopEnvironment["Service"]), + ), + ); + + assert.isNull(yield* readHomeEnvironmentId); + yield* fileSystem.writeFileString(path.join(stateDir, "environment-id"), "env-home-1\n"); + assert.strictEqual(yield* readHomeEnvironmentId, "env-home-1"); + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), + ); }); diff --git a/apps/desktop/src/ipc/methods/localEnvironment.ts b/apps/desktop/src/ipc/methods/localEnvironment.ts index 74cccd04a0c58..80adc341796d0 100644 --- a/apps/desktop/src/ipc/methods/localEnvironment.ts +++ b/apps/desktop/src/ipc/methods/localEnvironment.ts @@ -1,6 +1,8 @@ import * as Effect from "effect/Effect"; +import * as FileSystem from "effect/FileSystem"; import * as Schema from "effect/Schema"; +import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts"; import * as DesktopLifecycle from "../../app/DesktopLifecycle.ts"; import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts"; import * as IpcChannels from "../channels.ts"; @@ -15,6 +17,24 @@ export const getLocalEnvironmentEnabled = makeSyncIpcMethod({ }), }); +export const getHomeEnvironmentId = makeSyncIpcMethod({ + channel: IpcChannels.GET_HOME_ENVIRONMENT_ID_CHANNEL, + result: Schema.NullOr(Schema.String), + handler: Effect.fn("desktop.ipc.localEnvironment.getHomeEnvironmentId")(function* () { + const environment = yield* DesktopEnvironment.DesktopEnvironment; + const fileSystem = yield* FileSystem.FileSystem; + // The server's environment identity file (apps/server/src/config.ts), absent + // until a server has started on this home. + const id = yield* fileSystem + .readFileString(environment.path.join(environment.stateDir, "environment-id")) + .pipe( + Effect.map((raw) => raw.trim()), + Effect.orElseSucceed(() => ""), + ); + return id.length > 0 ? id : null; + }), +}); + export const setLocalEnvironmentEnabled = makeIpcMethod({ channel: IpcChannels.SET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL, payload: Schema.Boolean, diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.ts index 2e046b7f238c8..a873617bbb1fa 100644 --- a/apps/desktop/src/preload.ts +++ b/apps/desktop/src/preload.ts @@ -113,6 +113,10 @@ contextBridge.exposeInMainWorld("desktopBridge", { ipcRenderer.sendSync(IpcChannels.GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL) !== false, setLocalEnvironmentEnabled: (enabled) => ipcRenderer.invoke(IpcChannels.SET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL, enabled), + getHomeEnvironmentId: () => { + const result = ipcRenderer.sendSync(IpcChannels.GET_HOME_ENVIRONMENT_ID_CHANNEL); + return typeof result === "string" ? result : null; + }, getClientSettings: () => ipcRenderer.invoke(IpcChannels.GET_CLIENT_SETTINGS_CHANNEL), setClientSettings: (settings) => ipcRenderer.invoke(IpcChannels.SET_CLIENT_SETTINGS_CHANNEL, settings), diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 98b3172d0c6e0..914ce8b0bfd30 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -361,10 +361,11 @@ import { useEnvironmentQuery } from "../state/query"; import { useEnvironmentScope } from "~/state/session"; import { environmentServerConfigsAtom, - primaryServerAvailableEditorsAtom, + localMachineAvailableEditorsAtom, primaryServerKeybindingsAtom, serverEnvironment, } from "../state/server"; +import { localMachineEnvironmentIdAtom } from "../state/primaryEnvironment"; import { threadEnvironment } from "../state/threads"; import { resolveProviderSkillsForCwd } from "@t3tools/client-runtime/providerSkills"; import { vcsEnvironment } from "../state/vcs"; @@ -1941,7 +1942,6 @@ export default function ChatView(props: ChatViewProps) { }, [activeEnvironmentBootstrapComplete, activeProject, activeThreadRef]); const allProjects = useProjects(); - const primaryEnvironmentId = primaryEnvironment?.environmentId ?? null; useEffect(() => { if (!activeThreadRef || !activeProjectRef) return; registerFaviconProjectForThread(activeThreadRef, activeProjectRef); @@ -2930,12 +2930,13 @@ export default function ChatView(props: ChatViewProps) { const scriptKeybindings = useAtomValue(serverEnvironment.configValueAtom(environmentId))?.keybindings ?? DEFAULT_RESOLVED_KEYBINDINGS; - const availableEditors = useAtomValue(primaryServerAvailableEditorsAtom); + const availableEditors = useAtomValue(localMachineAvailableEditorsAtom); + const localMachineEnvironmentId = useAtomValue(localMachineEnvironmentIdAtom); const remoteOpenState = useRemoteOpenState(activeThread?.environmentId ?? environmentId); const showOpenInPicker = shouldShowOpenInPicker({ activeProjectName: activeProject?.title, activeThreadEnvironmentId: activeThread?.environmentId ?? environmentId, - primaryEnvironmentId, + localMachineEnvironmentId, remoteOpenMode: remoteOpenState.mode, }); useOpenFavoriteEditorShortcut({ diff --git a/apps/web/src/components/chat/OpenInPicker.logic.ts b/apps/web/src/components/chat/OpenInPicker.logic.ts index f5c9e17c392c5..7585e1b34dec1 100644 --- a/apps/web/src/components/chat/OpenInPicker.logic.ts +++ b/apps/web/src/components/chat/OpenInPicker.logic.ts @@ -5,13 +5,13 @@ import type { RemoteOpenMode } from "../../remoteOpen"; export function shouldShowOpenInPicker(input: { readonly activeProjectName: string | undefined; readonly activeThreadEnvironmentId: EnvironmentId; - readonly primaryEnvironmentId: EnvironmentId | null; + readonly localMachineEnvironmentId: EnvironmentId | null; readonly remoteOpenMode: RemoteOpenMode; }): boolean { if (!input.activeProjectName) return false; if ( - input.primaryEnvironmentId !== null && - input.activeThreadEnvironmentId === input.primaryEnvironmentId + input.localMachineEnvironmentId !== null && + input.activeThreadEnvironmentId === input.localMachineEnvironmentId ) { return true; } diff --git a/apps/web/src/components/chat/OpenInPicker.test.ts b/apps/web/src/components/chat/OpenInPicker.test.ts index df4b668c882a2..9a0edba782842 100644 --- a/apps/web/src/components/chat/OpenInPicker.test.ts +++ b/apps/web/src/components/chat/OpenInPicker.test.ts @@ -7,14 +7,14 @@ import { describe, expect, it } from "vite-plus/test"; import { shouldShowOpenInPicker } from "./OpenInPicker.logic"; describe("shouldShowOpenInPicker", () => { - const primaryEnvironmentId = EnvironmentId.make("environment-primary"); + const localMachineEnvironmentId = EnvironmentId.make("environment-primary"); - it("shows the picker for projects in the primary environment", () => { + it("shows the picker for projects in the environment on this machine", () => { expect( shouldShowOpenInPicker({ activeProjectName: "codething-mvp", - activeThreadEnvironmentId: primaryEnvironmentId, - primaryEnvironmentId, + activeThreadEnvironmentId: localMachineEnvironmentId, + localMachineEnvironmentId, remoteOpenMode: "local-exec", }), ).toBe(true); @@ -25,7 +25,7 @@ describe("shouldShowOpenInPicker", () => { shouldShowOpenInPicker({ activeProjectName: "codething-mvp", activeThreadEnvironmentId: EnvironmentId.make("environment-remote"), - primaryEnvironmentId, + localMachineEnvironmentId, remoteOpenMode: "remote-links", }), ).toBe(true); @@ -36,7 +36,7 @@ describe("shouldShowOpenInPicker", () => { shouldShowOpenInPicker({ activeProjectName: "codething-mvp", activeThreadEnvironmentId: EnvironmentId.make("environment-remote"), - primaryEnvironmentId: null, + localMachineEnvironmentId: null, remoteOpenMode: "remote-unavailable", }), ).toBe(true); @@ -47,7 +47,7 @@ describe("shouldShowOpenInPicker", () => { shouldShowOpenInPicker({ activeProjectName: "codething-mvp", activeThreadEnvironmentId: EnvironmentId.make("environment-remote"), - primaryEnvironmentId, + localMachineEnvironmentId, remoteOpenMode: "local-exec", }), ).toBe(false); @@ -57,8 +57,8 @@ describe("shouldShowOpenInPicker", () => { expect( shouldShowOpenInPicker({ activeProjectName: undefined, - activeThreadEnvironmentId: primaryEnvironmentId, - primaryEnvironmentId, + activeThreadEnvironmentId: localMachineEnvironmentId, + localMachineEnvironmentId, remoteOpenMode: "remote-links", }), ).toBe(false); diff --git a/apps/web/src/components/files/FilePreviewPanel.tsx b/apps/web/src/components/files/FilePreviewPanel.tsx index dfbe629e3509e..c9eb378ba866a 100644 --- a/apps/web/src/components/files/FilePreviewPanel.tsx +++ b/apps/web/src/components/files/FilePreviewPanel.tsx @@ -66,7 +66,8 @@ import { type DraftId, useComposerDraftStore } from "~/composerDraftStore"; import { buildFileReviewComment } from "~/reviewCommentContext"; import { assetEnvironment } from "~/state/assets"; import { usePreviewAvailable } from "~/browser/previewRuntime"; -import { useEnvironmentHttpBaseUrl, usePrimaryEnvironmentId } from "~/state/environments"; +import { useEnvironmentHttpBaseUrl } from "~/state/environments"; +import { localMachineEnvironmentIdAtom } from "~/state/primaryEnvironment"; import { previewEnvironment } from "~/state/preview"; import { serverEnvironment } from "~/state/server"; import { useEnvironmentScope } from "~/state/session"; @@ -994,7 +995,7 @@ export default function FilePreviewPanel({ const { resolvedTheme } = useTheme(); const wordWrap = useClientSettings((settings) => settings.wordWrap); const canOperatePreview = useEnvironmentScope(environmentId, AuthPreviewOperateScope); - const primaryEnvironmentId = usePrimaryEnvironmentId(); + const localMachineEnvironmentId = useAtomValue(localMachineEnvironmentIdAtom); const remoteOpenState = useRemoteOpenState(environmentId); const serverConfig = useAtomValue(serverEnvironment.configValueAtom(environmentId)); const environmentHttpBaseUrl = useEnvironmentHttpBaseUrl(environmentId); @@ -1234,7 +1235,7 @@ export default function FilePreviewPanel({ {absolutePath && - (environmentId === primaryEnvironmentId || remoteOpenState.mode !== "local-exec") ? ( + (environmentId === localMachineEnvironmentId || remoteOpenState.mode !== "local-exec") ? ( { sshAlias: null, isDesktopRenderer: false, remoteOpenTargets: TAILSCALE_TARGETS, + desktopHomeEnvironmentId: null, }), ).toEqual({ mode: "local-exec" }); }); @@ -43,6 +44,7 @@ describe("resolveRemoteOpenState", () => { sshAlias: null, isDesktopRenderer: false, remoteOpenTargets: TAILSCALE_TARGETS, + desktopHomeEnvironmentId: null, }), ).toEqual({ mode: "remote-links", @@ -59,6 +61,7 @@ describe("resolveRemoteOpenState", () => { sshAlias: null, isDesktopRenderer: true, remoteOpenTargets: TAILSCALE_TARGETS, + desktopHomeEnvironmentId: null, }), ).toEqual({ mode: "local-exec" }); }); @@ -74,10 +77,40 @@ describe("resolveRemoteOpenState", () => { sshAlias: null, isDesktopRenderer: false, remoteOpenTargets: TAILSCALE_TARGETS, + desktopHomeEnvironmentId: null, }), ).toEqual({ mode: "local-exec" }); }); + it("keeps exec behavior for the environment that owns the desktop's T3 home", () => { + // With Local environment off, a background service on this machine can own the + // desktop's home and still be reached through T3 Connect. + expect( + resolveRemoteOpenState({ + target: new RelayConnectionTarget({ environmentId, label: "sol" }), + sshAlias: null, + isDesktopRenderer: true, + remoteOpenTargets: TAILSCALE_TARGETS, + desktopHomeEnvironmentId: environmentId, + }), + ).toEqual({ mode: "local-exec" }); + }); + + it("uses deep links for other environments when the desktop home has its own", () => { + expect( + resolveRemoteOpenState({ + target: new RelayConnectionTarget({ environmentId, label: "sol" }), + sshAlias: null, + isDesktopRenderer: true, + remoteOpenTargets: TAILSCALE_TARGETS, + desktopHomeEnvironmentId: EnvironmentId.make("environment-desktop-home"), + }), + ).toEqual({ + mode: "remote-links", + host: { kind: "tailscale", host: "sol.tail1234.ts.net" }, + }); + }); + it("prefers the desktop SSH alias over server-advertised hosts", () => { expect( resolveRemoteOpenState({ @@ -89,6 +122,7 @@ describe("resolveRemoteOpenState", () => { sshAlias: "sol", isDesktopRenderer: true, remoteOpenTargets: TAILSCALE_TARGETS, + desktopHomeEnvironmentId: null, }), ).toEqual({ mode: "remote-links", host: { kind: "ssh-alias", host: "sol" } }); }); @@ -101,6 +135,7 @@ describe("resolveRemoteOpenState", () => { sshAlias: null, isDesktopRenderer: false, remoteOpenTargets, + desktopHomeEnvironmentId: null, }), ).toEqual({ mode: "remote-unavailable" }); } @@ -113,6 +148,7 @@ describe("resolveRemoteOpenState", () => { sshAlias: null, isDesktopRenderer: false, remoteOpenTargets: undefined, + desktopHomeEnvironmentId: null, }), ).toEqual({ mode: "local-exec" }); }); diff --git a/apps/web/src/remoteOpen.ts b/apps/web/src/remoteOpen.ts index a10e39af003cb..b012824144acd 100644 --- a/apps/web/src/remoteOpen.ts +++ b/apps/web/src/remoteOpen.ts @@ -15,6 +15,7 @@ import { isDesktopLocalConnectionTarget } from "~/connection/desktopLocal"; import { isLoopbackHostname } from "~/environments/primary/target"; import { useLocalStorage } from "~/hooks/useLocalStorage"; import { environmentPresentations } from "~/state/presentation"; +import { desktopHomeEnvironmentIdAtom } from "~/state/primaryEnvironment"; export interface RemoteOpenHost { readonly kind: "ssh-alias" | RemoteOpenTarget["kind"]; @@ -53,9 +54,10 @@ export function resolveRemoteOpenState(input: { readonly sshAlias: string | null; readonly remoteOpenTargets: ReadonlyArray | undefined; readonly isDesktopRenderer: boolean; + readonly desktopHomeEnvironmentId: EnvironmentId | null; }): RemoteOpenState { const { target } = input; - if (target === null) { + if (target === null || target.environmentId === input.desktopHomeEnvironmentId) { return LOCAL_EXEC; } if (target._tag === "PrimaryConnectionTarget") { @@ -106,6 +108,7 @@ const remoteOpenResolutionAtom = Atom.family((environmentId: EnvironmentId) => profile !== null && profile._tag === "SshConnectionProfile" ? profile.target.alias : null, remoteOpenTargets: presentation?.serverConfig?.remoteOpenTargets, isDesktopRenderer: window.desktopBridge !== undefined, + desktopHomeEnvironmentId: get(desktopHomeEnvironmentIdAtom), }), isResolved: true, }; diff --git a/apps/web/src/state/primaryEnvironment.ts b/apps/web/src/state/primaryEnvironment.ts index 75739b8ddeffb..6ad13ed630aea 100644 --- a/apps/web/src/state/primaryEnvironment.ts +++ b/apps/web/src/state/primaryEnvironment.ts @@ -1,6 +1,7 @@ import { Atom } from "effect/reactivity"; import { environmentCatalog } from "../connection/catalog"; +import { readDesktopHomeEnvironmentId } from "../localEnvironment"; export const primaryEnvironmentIdAtom = Atom.make((get) => { for (const [environmentId, entry] of get(environmentCatalog.catalogValueAtom).entries) { @@ -10,3 +11,14 @@ export const primaryEnvironmentIdAtom = Atom.make((get) => { } return null; }).pipe(Atom.withLabel("web-primary-environment-id")); + +// With Local environment off, a background service can still own the desktop's +// T3 home. It runs on this machine just as the desktop's own backend would. +export const desktopHomeEnvironmentIdAtom = Atom.make(readDesktopHomeEnvironmentId).pipe( + Atom.keepAlive, + Atom.withLabel("web-desktop-home-environment-id"), +); + +export const localMachineEnvironmentIdAtom = Atom.make( + (get) => get(primaryEnvironmentIdAtom) ?? get(desktopHomeEnvironmentIdAtom), +).pipe(Atom.withLabel("web-local-machine-environment-id")); diff --git a/apps/web/src/state/server.ts b/apps/web/src/state/server.ts index a12dfde6e0bcd..a2e976fdcf81b 100644 --- a/apps/web/src/state/server.ts +++ b/apps/web/src/state/server.ts @@ -20,7 +20,7 @@ import { AsyncResult, Atom } from "effect/reactivity"; import { environmentCatalog } from "../connection/catalog"; import { connectionAtomRuntime } from "../connection/runtime"; import { environmentAtomList } from "./environmentAtomList"; -import { primaryEnvironmentIdAtom } from "./primaryEnvironment"; +import { localMachineEnvironmentIdAtom, primaryEnvironmentIdAtom } from "./primaryEnvironment"; import { environmentSession } from "./session"; import { reuseProvidersIgnoringCheckedAt } from "./serverProviders.logic"; @@ -113,10 +113,14 @@ export const primaryServerKeybindingsAtom = Atom.make((get): ServerConfig["keybi mergeWithDefaultKeybindings(get(primaryServerConfigAtom)?.keybindings ?? []), ).pipe(Atom.withLabel("web-primary-server-keybindings")); -export const primaryServerAvailableEditorsAtom = Atom.make( - (get): ReadonlyArray => - get(primaryServerConfigAtom)?.availableEditors ?? EMPTY_AVAILABLE_EDITORS, -).pipe(Atom.withLabel("web-primary-server-available-editors")); +export const localMachineAvailableEditorsAtom = Atom.make((get): ReadonlyArray => { + const environmentId = get(localMachineEnvironmentIdAtom); + if (environmentId === null) return EMPTY_AVAILABLE_EDITORS; + return ( + get(serverEnvironment.configValueAtom(environmentId))?.availableEditors ?? + EMPTY_AVAILABLE_EDITORS + ); +}).pipe(Atom.withLabel("web-local-machine-available-editors")); const EMPTY_ENVIRONMENT_THEMES: ReadonlyArray = []; diff --git a/docs/user/remote-access.md b/docs/user/remote-access.md index aaa80e39ca97d..a34b3b0e0fdca 100644 --- a/docs/user/remote-access.md +++ b/docs/user/remote-access.md @@ -357,6 +357,9 @@ desktop app, open **Settings → Connections** and switch off **Local environment**. T3 Code restarts without a local server: no local agents or terminals run, WSL backends stay off, and other devices can no longer connect to this computer. Your projects, history, and saved connections are kept, and you keep working through pairing, T3 Connect, or SSH. +If a [background service](./background-service.md) on this computer uses the same T3 home, the +app still treats it as this computer: **Open in** and file reveal for its projects run here, +whichever connection you reach it through. Switch **Local environment** back on in the same place to restart with your previous local settings. diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts index dcce2af0b0ea3..ad9bb8344e6d6 100644 --- a/packages/contracts/src/ipc.ts +++ b/packages/contracts/src/ipc.ts @@ -1042,6 +1042,12 @@ export interface DesktopBridge { getLocalEnvironmentBootstraps: () => readonly DesktopEnvironmentBootstrap[]; getLocalEnvironmentEnabled?: () => boolean; setLocalEnvironmentEnabled?: (enabled: boolean) => Promise; + /** + * The environment ID stored in this app's T3 home. Whichever server owns the + * home writes it: the app's own backend, or with Local environment off, a + * background service on this machine. + */ + getHomeEnvironmentId?: () => string | null; getLocalEnvironmentBearerToken: () => Promise; getClientSettings: () => Promise; setClientSettings: (settings: ClientSettings) => Promise; From c4bc20ce6e6a782d6322b806b42c3aa58c749a4d Mon Sep 17 00:00:00 2001 From: Kinan Date: Mon, 19 Oct 2026 12:49:28 +0200 Subject: [PATCH 2/9] fix(desktop): read the home environment ID without suspending the sync IPC --- .../src/ipc/methods/localEnvironment.test.ts | 39 +++++++++++++------ .../src/ipc/methods/localEnvironment.ts | 8 ++-- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/apps/desktop/src/ipc/methods/localEnvironment.test.ts b/apps/desktop/src/ipc/methods/localEnvironment.test.ts index 2ea1b91c0414c..b88646d049b20 100644 --- a/apps/desktop/src/ipc/methods/localEnvironment.test.ts +++ b/apps/desktop/src/ipc/methods/localEnvironment.test.ts @@ -12,6 +12,7 @@ import * as DesktopState from "../../app/DesktopState.ts"; import * as ElectronApp from "../../electron/ElectronApp.ts"; import * as ElectronTheme from "../../electron/ElectronTheme.ts"; import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts"; +import * as DesktopIpc from "../DesktopIpc.ts"; import * as DesktopWindow from "../../window/DesktopWindow.ts"; import { getHomeEnvironmentId, @@ -71,19 +72,35 @@ describe("local environment IPC", () => { const fileSystem = yield* FileSystem.FileSystem; const path = yield* Path.Path; const stateDir = yield* fileSystem.makeTempDirectoryScoped(); - const readHomeEnvironmentId = getHomeEnvironmentId.handler().pipe( - Effect.provideService( - DesktopEnvironment.DesktopEnvironment, - DesktopEnvironment.DesktopEnvironment.of({ - path, - stateDir, - } as unknown as DesktopEnvironment.DesktopEnvironment["Service"]), - ), - ); + let listener: DesktopIpc.DesktopIpcSyncListener | undefined; + // Registered through the real sync IPC path, which replies via Effect.runSync. + yield* DesktopIpc.make({ + removeHandler: () => {}, + handle: () => {}, + removeAllListeners: () => {}, + on: (_channel, registered) => { + listener = registered; + }, + }) + .handleSync(getHomeEnvironmentId) + .pipe( + Effect.provideService( + DesktopEnvironment.DesktopEnvironment, + DesktopEnvironment.DesktopEnvironment.of({ + path, + stateDir, + } as unknown as DesktopEnvironment.DesktopEnvironment["Service"]), + ), + ); + const readHomeEnvironmentId = () => { + const event = { returnValue: undefined as unknown }; + listener?.(event); + return event.returnValue; + }; - assert.isNull(yield* readHomeEnvironmentId); + assert.isNull(readHomeEnvironmentId()); yield* fileSystem.writeFileString(path.join(stateDir, "environment-id"), "env-home-1\n"); - assert.strictEqual(yield* readHomeEnvironmentId, "env-home-1"); + assert.strictEqual(readHomeEnvironmentId(), "env-home-1"); }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), ); }); diff --git a/apps/desktop/src/ipc/methods/localEnvironment.ts b/apps/desktop/src/ipc/methods/localEnvironment.ts index 80adc341796d0..8cc55131b0d2a 100644 --- a/apps/desktop/src/ipc/methods/localEnvironment.ts +++ b/apps/desktop/src/ipc/methods/localEnvironment.ts @@ -1,9 +1,9 @@ import * as Effect from "effect/Effect"; -import * as FileSystem from "effect/FileSystem"; import * as Schema from "effect/Schema"; import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts"; import * as DesktopLifecycle from "../../app/DesktopLifecycle.ts"; +import * as DesktopPreReadyFileSystem from "../../app/DesktopPreReadyFileSystem.ts"; import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts"; import * as IpcChannels from "../channels.ts"; import { makeIpcMethod, makeSyncIpcMethod } from "../DesktopIpc.ts"; @@ -22,10 +22,10 @@ export const getHomeEnvironmentId = makeSyncIpcMethod({ result: Schema.NullOr(Schema.String), handler: Effect.fn("desktop.ipc.localEnvironment.getHomeEnvironmentId")(function* () { const environment = yield* DesktopEnvironment.DesktopEnvironment; - const fileSystem = yield* FileSystem.FileSystem; // The server's environment identity file (apps/server/src/config.ts), absent - // until a server has started on this home. - const id = yield* fileSystem + // until a server has started on this home. Sync IPC handlers run under + // Effect.runSync, so the read must not suspend. + const id = yield* DesktopPreReadyFileSystem.make .readFileString(environment.path.join(environment.stateDir, "environment-id")) .pipe( Effect.map((raw) => raw.trim()), From e80e4f0311eb7c4c26583f2a711a0065987b8427 Mon Sep 17 00:00:00 2001 From: Kinan Date: Mon, 19 Oct 2026 14:42:27 +0200 Subject: [PATCH 3/9] fix(desktop): log unexpected failures reading the home environment ID --- apps/desktop/src/ipc/methods/localEnvironment.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/ipc/methods/localEnvironment.ts b/apps/desktop/src/ipc/methods/localEnvironment.ts index 8cc55131b0d2a..da665612ede3a 100644 --- a/apps/desktop/src/ipc/methods/localEnvironment.ts +++ b/apps/desktop/src/ipc/methods/localEnvironment.ts @@ -24,12 +24,19 @@ export const getHomeEnvironmentId = makeSyncIpcMethod({ const environment = yield* DesktopEnvironment.DesktopEnvironment; // The server's environment identity file (apps/server/src/config.ts), absent // until a server has started on this home. Sync IPC handlers run under - // Effect.runSync, so the read must not suspend. + // Effect.runSync, so the read must not suspend, and must not fail either: a + // failed sync handler never sets returnValue and leaves the renderer blocked. const id = yield* DesktopPreReadyFileSystem.make .readFileString(environment.path.join(environment.stateDir, "environment-id")) .pipe( Effect.map((raw) => raw.trim()), - Effect.orElseSucceed(() => ""), + Effect.catch((error) => + error.reason._tag === "NotFound" + ? Effect.succeed("") + : Effect.logWarning("Could not read the home environment ID.", { error }).pipe( + Effect.as(""), + ), + ), ); return id.length > 0 ? id : null; }), From 94b27d8792d5e41e0a9c8f7d0d5197926ee9760b Mon Sep 17 00:00:00 2001 From: Kinan Date: Wed, 28 Oct 2026 17:56:25 +0100 Subject: [PATCH 4/9] fix(web): Open In treats both the primary and the desktop home's server as local In WSL-only mode the primary has its own T3 home, so a service sharing the desktop's home resolved to local exec but still had Open In hidden and borrowed the primary's editors. --- apps/web/src/components/ChatView.tsx | 13 ++++++++----- .../src/components/files/FilePreviewPanel.tsx | 2 +- apps/web/src/state/primaryEnvironment.ts | 15 ++++++++++++--- apps/web/src/state/server.ts | 18 ++++++++++-------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 88eb69ced1e30..d89359b9005d4 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -1577,18 +1577,21 @@ export default function ChatView(props: ChatViewProps) { const scriptKeybindings = useAtomValue(serverEnvironment.configValueAtom(environmentId))?.keybindings ?? DEFAULT_RESOLVED_KEYBINDINGS; - const availableEditors = useAtomValue(localMachineAvailableEditorsAtom); - const localMachineEnvironmentId = useAtomValue(localMachineEnvironmentIdAtom); - const remoteOpenState = useRemoteOpenState(activeThread?.environmentId ?? environmentId); + const openInEnvironmentId = activeThread?.environmentId ?? environmentId; + const availableEditors = useAtomValue(localMachineAvailableEditorsAtom(openInEnvironmentId)); + const localMachineEnvironmentId = useAtomValue( + localMachineEnvironmentIdAtom(openInEnvironmentId), + ); + const remoteOpenState = useRemoteOpenState(openInEnvironmentId); const showOpenInPicker = shouldShowOpenInPicker({ activeProjectName: activeProject?.title, - activeThreadEnvironmentId: activeThread?.environmentId ?? environmentId, + activeThreadEnvironmentId: openInEnvironmentId, localMachineEnvironmentId, remoteOpenMode: remoteOpenState.mode, }); useOpenFavoriteEditorShortcut({ enabled: showOpenInPicker && !backgroundThread, - environmentId: activeThread?.environmentId ?? environmentId, + environmentId: openInEnvironmentId, keybindings, availableEditors, openInCwd: gitCwd, diff --git a/apps/web/src/components/files/FilePreviewPanel.tsx b/apps/web/src/components/files/FilePreviewPanel.tsx index 14ae15713ef94..615347b0c749e 100644 --- a/apps/web/src/components/files/FilePreviewPanel.tsx +++ b/apps/web/src/components/files/FilePreviewPanel.tsx @@ -1001,7 +1001,7 @@ export default function FilePreviewPanel({ const [wordWrapOverride, setWordWrapOverride] = useState(null); const wordWrap = wordWrapOverride ?? defaultWordWrap; const canOperatePreview = useEnvironmentScope(environmentId, AuthPreviewOperateScope); - const localMachineEnvironmentId = useAtomValue(localMachineEnvironmentIdAtom); + const localMachineEnvironmentId = useAtomValue(localMachineEnvironmentIdAtom(environmentId)); const remoteOpenState = useRemoteOpenState(environmentId); const serverConfig = useAtomValue(serverEnvironment.configValueAtom(environmentId)); const environmentHttpBaseUrl = useEnvironmentHttpBaseUrl(environmentId); diff --git a/apps/web/src/state/primaryEnvironment.ts b/apps/web/src/state/primaryEnvironment.ts index 6ad13ed630aea..b19dd301bec63 100644 --- a/apps/web/src/state/primaryEnvironment.ts +++ b/apps/web/src/state/primaryEnvironment.ts @@ -1,3 +1,4 @@ +import type { EnvironmentId } from "@t3tools/contracts"; import { Atom } from "effect/reactivity"; import { environmentCatalog } from "../connection/catalog"; @@ -19,6 +20,14 @@ export const desktopHomeEnvironmentIdAtom = Atom.make(readDesktopHomeEnvironment Atom.withLabel("web-desktop-home-environment-id"), ); -export const localMachineEnvironmentIdAtom = Atom.make( - (get) => get(primaryEnvironmentIdAtom) ?? get(desktopHomeEnvironmentIdAtom), -).pipe(Atom.withLabel("web-local-machine-environment-id")); +// WSL-only mode gives the primary its own home, so both can run here at once. +export const localMachineEnvironmentIdAtom = Atom.family((environmentId: EnvironmentId) => + Atom.make((get) => { + const primaryEnvironmentId = get(primaryEnvironmentIdAtom); + const desktopHomeEnvironmentId = get(desktopHomeEnvironmentIdAtom); + if (environmentId === primaryEnvironmentId || environmentId === desktopHomeEnvironmentId) { + return environmentId; + } + return primaryEnvironmentId ?? desktopHomeEnvironmentId; + }).pipe(Atom.withLabel(`web-local-machine-environment-id:${environmentId}`)), +); diff --git a/apps/web/src/state/server.ts b/apps/web/src/state/server.ts index ec249403d85b2..143655af123d0 100644 --- a/apps/web/src/state/server.ts +++ b/apps/web/src/state/server.ts @@ -166,14 +166,16 @@ export const primaryServerKeybindingsAtom = createShortcutKeybindingsAtom({ environmentsAtom: environmentConnectionsAtom, }).pipe(Atom.withLabel("web-primary-server-keybindings")); -export const localMachineAvailableEditorsAtom = Atom.make((get): ReadonlyArray => { - const environmentId = get(localMachineEnvironmentIdAtom); - if (environmentId === null) return EMPTY_AVAILABLE_EDITORS; - return ( - get(serverEnvironment.configValueAtom(environmentId))?.availableEditors ?? - EMPTY_AVAILABLE_EDITORS - ); -}).pipe(Atom.withLabel("web-local-machine-available-editors")); +export const localMachineAvailableEditorsAtom = Atom.family((targetEnvironmentId: EnvironmentId) => + Atom.make((get): ReadonlyArray => { + const environmentId = get(localMachineEnvironmentIdAtom(targetEnvironmentId)); + if (environmentId === null) return EMPTY_AVAILABLE_EDITORS; + return ( + get(serverEnvironment.configValueAtom(environmentId))?.availableEditors ?? + EMPTY_AVAILABLE_EDITORS + ); + }).pipe(Atom.withLabel(`web-local-machine-available-editors:${targetEnvironmentId}`)), +); const EMPTY_ENVIRONMENT_THEMES: ReadonlyArray = []; From 02c5c50ed978c9ebaa04829af4915ca084d883a0 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Fri, 30 Oct 2026 06:02:11 +0000 Subject: [PATCH 5/9] refactor(web): simplify shared-home editor selection --- .../src/ipc/methods/localEnvironment.ts | 5 +--- .../web/src/components/ChatView.logic.test.ts | 23 +++++++++++++++++++ apps/web/src/components/ChatView.tsx | 18 ++++++--------- .../src/components/chat/OpenInPicker.logic.ts | 7 +++--- .../src/components/files/FilePreviewPanel.tsx | 11 +++++---- apps/web/src/state/primaryEnvironment.ts | 13 ----------- apps/web/src/state/server.ts | 15 +----------- packages/contracts/src/ipc.ts | 6 +---- 8 files changed, 44 insertions(+), 54 deletions(-) diff --git a/apps/desktop/src/ipc/methods/localEnvironment.ts b/apps/desktop/src/ipc/methods/localEnvironment.ts index da665612ede3a..8402e7e1d5a8b 100644 --- a/apps/desktop/src/ipc/methods/localEnvironment.ts +++ b/apps/desktop/src/ipc/methods/localEnvironment.ts @@ -22,10 +22,7 @@ export const getHomeEnvironmentId = makeSyncIpcMethod({ result: Schema.NullOr(Schema.String), handler: Effect.fn("desktop.ipc.localEnvironment.getHomeEnvironmentId")(function* () { const environment = yield* DesktopEnvironment.DesktopEnvironment; - // The server's environment identity file (apps/server/src/config.ts), absent - // until a server has started on this home. Sync IPC handlers run under - // Effect.runSync, so the read must not suspend, and must not fail either: a - // failed sync handler never sets returnValue and leaves the renderer blocked. + // Sync IPC must reply without suspending or failing, including when the identity file is absent. const id = yield* DesktopPreReadyFileSystem.make .readFileString(environment.path.join(environment.stateDir, "environment-id")) .pipe( diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.ts index 3304899216fcd..316601af561ab 100644 --- a/apps/web/src/components/ChatView.logic.test.ts +++ b/apps/web/src/components/ChatView.logic.test.ts @@ -1,3 +1,4 @@ +import { shouldShowOpenInPicker } from "./chat/OpenInPicker.logic"; import { boundAttachmentIds, mergeDirectPreviewAnnotation, @@ -1178,3 +1179,25 @@ describe("deriveWorkspaceMutationId", () => { ); }); }); + +describe("Open in for the desktop home", () => { + it("shows both local environments when the primary has a separate WSL home", () => { + const primaryEnvironmentId = EnvironmentId.make("wsl"); + const desktopHomeEnvironmentId = EnvironmentId.make("desktop-home"); + for (const [activeThreadEnvironmentId, visible] of [ + [primaryEnvironmentId, true], + [desktopHomeEnvironmentId, true], + [EnvironmentId.make("other"), false], + ] as const) { + expect( + shouldShowOpenInPicker({ + activeProjectName: "Project", + activeThreadEnvironmentId, + primaryEnvironmentId, + desktopHomeEnvironmentId, + remoteOpenMode: "local-exec", + }), + ).toBe(visible); + } + }); +}); diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index afb3cd0298e83..08d21cf70fdb5 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -226,12 +226,8 @@ import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../termina import { useKnownTerminalSessions, useThreadRunningTerminalIds } from "../state/terminalSessions"; import { useEnvironmentQuery } from "../state/query"; import { useEnvironmentScope } from "~/state/session"; -import { - localMachineAvailableEditorsAtom, - primaryServerKeybindingsAtom, - serverEnvironment, -} from "../state/server"; -import { localMachineEnvironmentIdAtom } from "../state/primaryEnvironment"; +import { primaryServerKeybindingsAtom, serverEnvironment } from "../state/server"; +import { desktopHomeEnvironmentIdAtom } from "../state/primaryEnvironment"; import { threadEnvironment, useThreadFamily } from "../state/threads"; import { resolveProviderSkillsForCwd } from "@t3tools/client-runtime/providerSkills"; import { vcsEnvironment } from "../state/vcs"; @@ -1611,15 +1607,15 @@ export default function ChatView(props: ChatViewProps) { useAtomValue(serverEnvironment.configValueAtom(environmentId))?.keybindings ?? DEFAULT_RESOLVED_KEYBINDINGS; const openInEnvironmentId = activeThread?.environmentId ?? environmentId; - const availableEditors = useAtomValue(localMachineAvailableEditorsAtom(openInEnvironmentId)); - const localMachineEnvironmentId = useAtomValue( - localMachineEnvironmentIdAtom(openInEnvironmentId), - ); + const availableEditors = + useAtomValue(serverEnvironment.configValueAtom(openInEnvironmentId))?.availableEditors ?? []; + const desktopHomeEnvironmentId = useAtomValue(desktopHomeEnvironmentIdAtom); const remoteOpenState = useRemoteOpenState(openInEnvironmentId); const showOpenInPicker = shouldShowOpenInPicker({ activeProjectName: activeProject?.title, activeThreadEnvironmentId: openInEnvironmentId, - localMachineEnvironmentId, + primaryEnvironmentId: primaryEnvironment?.environmentId ?? null, + desktopHomeEnvironmentId, remoteOpenMode: remoteOpenState.mode, }); useOpenFavoriteEditorShortcut({ diff --git a/apps/web/src/components/chat/OpenInPicker.logic.ts b/apps/web/src/components/chat/OpenInPicker.logic.ts index 7585e1b34dec1..ecf447e78a5f3 100644 --- a/apps/web/src/components/chat/OpenInPicker.logic.ts +++ b/apps/web/src/components/chat/OpenInPicker.logic.ts @@ -5,13 +5,14 @@ import type { RemoteOpenMode } from "../../remoteOpen"; export function shouldShowOpenInPicker(input: { readonly activeProjectName: string | undefined; readonly activeThreadEnvironmentId: EnvironmentId; - readonly localMachineEnvironmentId: EnvironmentId | null; + readonly primaryEnvironmentId: EnvironmentId | null; + readonly desktopHomeEnvironmentId: EnvironmentId | null; readonly remoteOpenMode: RemoteOpenMode; }): boolean { if (!input.activeProjectName) return false; if ( - input.localMachineEnvironmentId !== null && - input.activeThreadEnvironmentId === input.localMachineEnvironmentId + input.activeThreadEnvironmentId === input.primaryEnvironmentId || + input.activeThreadEnvironmentId === input.desktopHomeEnvironmentId ) { return true; } diff --git a/apps/web/src/components/files/FilePreviewPanel.tsx b/apps/web/src/components/files/FilePreviewPanel.tsx index c0fb0a0f865dc..3a58604206cc6 100644 --- a/apps/web/src/components/files/FilePreviewPanel.tsx +++ b/apps/web/src/components/files/FilePreviewPanel.tsx @@ -71,8 +71,8 @@ import { type DraftId, useComposerDraftStore } from "~/composerDraftStore"; import { buildFileReviewComment } from "~/reviewCommentContext"; import { assetEnvironment } from "~/state/assets"; import { usePreviewAvailable } from "~/browser/previewRuntime"; -import { useEnvironmentHttpBaseUrl } from "~/state/environments"; -import { localMachineEnvironmentIdAtom } from "~/state/primaryEnvironment"; +import { useEnvironmentHttpBaseUrl, usePrimaryEnvironmentId } from "~/state/environments"; +import { desktopHomeEnvironmentIdAtom } from "~/state/primaryEnvironment"; import { previewEnvironment } from "~/state/preview"; import { serverEnvironment } from "~/state/server"; import { useEnvironmentScope } from "~/state/session"; @@ -1002,7 +1002,8 @@ export default function FilePreviewPanel({ const [wordWrapOverride, setWordWrapOverride] = useState(null); const wordWrap = wordWrapOverride ?? defaultWordWrap; const canOperatePreview = useEnvironmentScope(environmentId, AuthPreviewOperateScope); - const localMachineEnvironmentId = useAtomValue(localMachineEnvironmentIdAtom(environmentId)); + const primaryEnvironmentId = usePrimaryEnvironmentId(); + const desktopHomeEnvironmentId = useAtomValue(desktopHomeEnvironmentIdAtom); const remoteOpenState = useRemoteOpenState(environmentId); const serverConfig = useAtomValue(serverEnvironment.configValueAtom(environmentId)); const environmentHttpBaseUrl = useEnvironmentHttpBaseUrl(environmentId); @@ -1259,7 +1260,9 @@ export default function FilePreviewPanel({ {absolutePath && - (environmentId === localMachineEnvironmentId || remoteOpenState.mode !== "local-exec") ? ( + (environmentId === primaryEnvironmentId || + environmentId === desktopHomeEnvironmentId || + remoteOpenState.mode !== "local-exec") ? ( - Atom.make((get) => { - const primaryEnvironmentId = get(primaryEnvironmentIdAtom); - const desktopHomeEnvironmentId = get(desktopHomeEnvironmentIdAtom); - if (environmentId === primaryEnvironmentId || environmentId === desktopHomeEnvironmentId) { - return environmentId; - } - return primaryEnvironmentId ?? desktopHomeEnvironmentId; - }).pipe(Atom.withLabel(`web-local-machine-environment-id:${environmentId}`)), -); diff --git a/apps/web/src/state/server.ts b/apps/web/src/state/server.ts index 143655af123d0..709cbc731ae2e 100644 --- a/apps/web/src/state/server.ts +++ b/apps/web/src/state/server.ts @@ -1,6 +1,5 @@ import { DEFAULT_SERVER_SETTINGS, - type EditorId, type EnvironmentId, type EnvironmentTheme, type ServerConfig, @@ -26,7 +25,7 @@ import { isConnectedWithConfig } from "../components/settings/scopedSettings"; import { environmentCatalog } from "../connection/catalog"; import { connectionAtomRuntime } from "../connection/runtime"; import { environmentAtomList } from "./environmentAtomList"; -import { localMachineEnvironmentIdAtom, primaryEnvironmentIdAtom } from "./primaryEnvironment"; +import { primaryEnvironmentIdAtom } from "./primaryEnvironment"; import { environmentSession } from "./session"; import { reuseProvidersIgnoringCheckedAt } from "./serverProviders.logic"; @@ -53,7 +52,6 @@ interface PrimaryServerState { readonly welcome: ServerLifecycleWelcomePayload | null; } -const EMPTY_AVAILABLE_EDITORS: ReadonlyArray = []; export const EMPTY_SERVER_PROVIDERS: ReadonlyArray = []; const EMPTY_PRIMARY_SERVER_STATE: PrimaryServerState = { config: null, @@ -166,17 +164,6 @@ export const primaryServerKeybindingsAtom = createShortcutKeybindingsAtom({ environmentsAtom: environmentConnectionsAtom, }).pipe(Atom.withLabel("web-primary-server-keybindings")); -export const localMachineAvailableEditorsAtom = Atom.family((targetEnvironmentId: EnvironmentId) => - Atom.make((get): ReadonlyArray => { - const environmentId = get(localMachineEnvironmentIdAtom(targetEnvironmentId)); - if (environmentId === null) return EMPTY_AVAILABLE_EDITORS; - return ( - get(serverEnvironment.configValueAtom(environmentId))?.availableEditors ?? - EMPTY_AVAILABLE_EDITORS - ); - }).pipe(Atom.withLabel(`web-local-machine-available-editors:${targetEnvironmentId}`)), -); - const EMPTY_ENVIRONMENT_THEMES: ReadonlyArray = []; export const primaryServerEnvironmentThemesAtom = Atom.make( diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts index 8f9d91ba725c7..b538e7b1f24ad 100644 --- a/packages/contracts/src/ipc.ts +++ b/packages/contracts/src/ipc.ts @@ -1034,11 +1034,7 @@ export interface DesktopBridge { getLocalEnvironmentBootstraps: () => readonly DesktopEnvironmentBootstrap[]; getLocalEnvironmentEnabled: () => boolean; setLocalEnvironmentEnabled: (enabled: boolean) => Promise; - /** - * The environment ID stored in this app's T3 home. Whichever server owns the - * home writes it: the app's own backend, or with Local environment off, a - * background service on this machine. - */ + /** The identity of the server sharing the desktop's T3 home, if it has started. */ getHomeEnvironmentId: () => string | null; getLocalEnvironmentBearerToken: () => Promise; getClientSettings: () => Promise; From 5633aee2e7b0ab6a66031172a592bd031769f260 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Fri, 30 Oct 2026 06:09:11 +0000 Subject: [PATCH 6/9] fix(web): refresh home identity when connections change --- apps/web/src/state/primaryEnvironment.ts | 11 ++++----- apps/web/src/state/server.test.ts | 29 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/apps/web/src/state/primaryEnvironment.ts b/apps/web/src/state/primaryEnvironment.ts index 112e166fb7d2f..3e47cc528f817 100644 --- a/apps/web/src/state/primaryEnvironment.ts +++ b/apps/web/src/state/primaryEnvironment.ts @@ -12,9 +12,8 @@ export const primaryEnvironmentIdAtom = Atom.make((get) => { return null; }).pipe(Atom.withLabel("web-primary-environment-id")); -// With Local environment off, a background service can still own the desktop's -// T3 home. It runs on this machine just as the desktop's own backend would. -export const desktopHomeEnvironmentIdAtom = Atom.make(readDesktopHomeEnvironmentId).pipe( - Atom.keepAlive, - Atom.withLabel("web-desktop-home-environment-id"), -); +// A background service can create the identity file after this window opens. +export const desktopHomeEnvironmentIdAtom = Atom.make((get) => { + get(environmentCatalog.catalogValueAtom); + return readDesktopHomeEnvironmentId(); +}).pipe(Atom.keepAlive, Atom.withLabel("web-desktop-home-environment-id")); diff --git a/apps/web/src/state/server.test.ts b/apps/web/src/state/server.test.ts index 336f97c6ff8c2..e78b5a238e748 100644 --- a/apps/web/src/state/server.test.ts +++ b/apps/web/src/state/server.test.ts @@ -2,8 +2,10 @@ import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connect import { EnvironmentId, type KeybindingRule, type ServerConfig } from "@t3tools/contracts"; import { compileResolvedKeybindingsConfig } from "@t3tools/shared/keybindings"; import { Atom, AtomRegistry } from "effect/reactivity"; -import { afterEach, describe, expect, it } from "vite-plus/test"; +import { afterEach, describe, expect, it, vi } from "vite-plus/test"; +import { environmentCatalog } from "../connection/catalog"; +import { desktopHomeEnvironmentIdAtom } from "./primaryEnvironment"; import { resolveShortcutCommand } from "../keybindings"; import { createShortcutKeybindingsAtom } from "./server"; @@ -124,3 +126,28 @@ describe("createShortcutKeybindingsAtom", () => { expect(harness.cmdN()).toBe("chat.newLocal"); }); }); + +describe("desktopHomeEnvironmentIdAtom", () => { + it("discovers an identity created after the desktop starts", () => { + let homeId: string | null = null; + vi.stubGlobal("window", { desktopBridge: { getHomeEnvironmentId: () => homeId } }); + try { + const catalog = { isReady: false, entries: new Map() }; + const registry = AtomRegistry.make({ + initialValues: [[environmentCatalog.catalogValueAtom, catalog]], + }); + registries.push(registry); + registry.subscribe(desktopHomeEnvironmentIdAtom, () => {}); + expect(registry.get(desktopHomeEnvironmentIdAtom)).toBeNull(); + + homeId = "desktop-home"; + registry.ensureNode(environmentCatalog.catalogValueAtom).setInitialValue({ + ...catalog, + isReady: true, + }); + expect(registry.get(desktopHomeEnvironmentIdAtom)).toBe(homeId); + } finally { + vi.unstubAllGlobals(); + } + }); +}); From 590f811ce0abc8de1f23d180e257a0c66207b5ef Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Fri, 30 Oct 2026 06:19:13 +0000 Subject: [PATCH 7/9] test(web): include home identity in desktop link mock --- .../desktop/DesktopWebLinkCoordinator.browser.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/web/src/components/desktop/DesktopWebLinkCoordinator.browser.test.tsx b/apps/web/src/components/desktop/DesktopWebLinkCoordinator.browser.test.tsx index a2a0f874d6e90..fa852f67e6454 100644 --- a/apps/web/src/components/desktop/DesktopWebLinkCoordinator.browser.test.tsx +++ b/apps/web/src/components/desktop/DesktopWebLinkCoordinator.browser.test.tsx @@ -34,6 +34,7 @@ vi.mock(import("../../state/environments"), async (original) => ({ })); vi.mock(import("../../localEnvironment"), () => ({ isLocalEnvironmentDisabled: () => state.localEnvironmentDisabled, + readDesktopHomeEnvironmentId: () => null, })); vi.mock(import("../../state/server"), async (original) => { const { Atom } = await import("effect/reactivity"); From 99006e12ef0e88008237b6bebc7c37c2d59008f1 Mon Sep 17 00:00:00 2001 From: Kinan Date: Mon, 2 Nov 2026 17:28:54 +0100 Subject: [PATCH 8/9] ci: retrigger From 95fa3bd3c3f6e8ae51767f815e6c3c3e09d59848 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 06:02:04 +0000 Subject: [PATCH 9/9] test(web): keep Open in host-environment coverage beside its modules --- .../chat/OpenInPicker.logic.test.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 apps/web/src/components/chat/OpenInPicker.logic.test.ts diff --git a/apps/web/src/components/chat/OpenInPicker.logic.test.ts b/apps/web/src/components/chat/OpenInPicker.logic.test.ts new file mode 100644 index 0000000000000..10595e2f8cdbe --- /dev/null +++ b/apps/web/src/components/chat/OpenInPicker.logic.test.ts @@ -0,0 +1,26 @@ +import { EnvironmentId } from "@t3tools/contracts"; +import { describe, expect, it } from "vite-plus/test"; + +import { shouldShowOpenInPicker } from "./OpenInPicker.logic"; + +describe("shouldShowOpenInPicker", () => { + it("shows both local environments when the primary has a separate WSL home", () => { + const primaryEnvironmentId = EnvironmentId.make("wsl"); + const hostEnvironmentId = EnvironmentId.make("host"); + for (const [activeThreadEnvironmentId, visible] of [ + [primaryEnvironmentId, true], + [hostEnvironmentId, true], + [EnvironmentId.make("other"), false], + ] as const) { + expect( + shouldShowOpenInPicker({ + activeProjectName: "Project", + activeThreadEnvironmentId, + primaryEnvironmentId, + hostEnvironmentId, + remoteOpenMode: "local-exec", + }), + ).toBe(visible); + } + }); +});