Resolve conflicts from the upstream bun->pnpm+Vite migration (#2899),
relay tunnels (#2837), and proof-key bootstrap auth:
- apps/web/src/environments/primary/auth.ts: upstream switched the
contracts import to `import type` and added ServerAuthSessionMethod;
keep that and re-add PRIMARY_LOCAL_ENVIRONMENT_ID as a value import
(still used at runtime to find the primary bootstrap entry).
- apps/web/src/environments/runtime/catalog.ts: keep both new optional
fields on SavedEnvironmentRecord (our desktopLocal marker and
upstream's relayManaged).
- apps/server/src/auth/PairingGrantStore.test.ts: keep upstream's new
proof-key thumbprint test and our reusable-bootstrap-grant test
(the desktop bootstrap credential is reusable: remainingUses
unbounded, 24h TTL).
- apps/web/src/components/settings/ConnectionsSettings.tsx: render both
the WSL row and upstream's CloudLinkRow in the connected section.
Resolves conflicts from upstream #2013 (mobile WIP), which moved several
web modules into @t3tools/client-runtime and deleted their old paths:
- ConnectionsSettings.tsx: drop the now-dead `~/rpc/wsRpcClient` type
import; WsRpcClient is now provided by @t3tools/client-runtime. Keep our
`~/environments/local` imports.
- runtime/service.ts: drop unused `projectReactQuery`/`providerReactQuery`
imports (source files removed upstream). Keep reconcileLocalSecondaryEnvironments.
- environments/local/index.ts (clean-merge breakage): `../remote/api` was
removed; repoint bootstrapRemoteBearerSession / fetchRemoteEnvironmentDescriptor
/ fetchRemoteSessionState to @t3tools/client-runtime. Those are now Effect.fn,
so wrap the three call sites in remoteHttpRuntime.runPromise(...), matching
the pattern upstream uses in runtime/service.ts.
Full typecheck green across all 14 packages; web tests 62/62.
Three things in one branch:
* fix(web): drop the per-thread container icon when every thread in
the project is already on WSL (a7a2e1bd, already pushed).
* feat(web): confirm before disable / distro-switch when WSL has
state (449e18f8, already pushed).
* This commit: add a third backend mode where the WSL backend runs
as the primary and the Windows backend isn't started.
The mode lands as a new `wslOnly` setting on DesktopAppSettings,
gated behind wslBackendEnabled. When both are true:
- DesktopBackendConfiguration.resolvePrimary now dispatches at
resolve time. The Windows path builds the same start config as
before; the WSL path reuses resolveWslStartConfig with the
primary port and the user's chosen distro, so the WSL backend
binds where the Windows backend would have, the renderer loads
from the same exposure endpoint, and cookie-auth keeps working.
- DesktopBackendPool reads settings once at layer init to pick the
primary's label ("Windows" vs "WSL (Ubuntu)"). The label is
captured per process; flipping the mode requires a restart.
- DesktopWslBackend.reconcile skips the parallel "wsl:<distro>"
registration when wsl-only is on, otherwise we'd run two WSL
processes on the same distro.
- New IPC channel SET_WSL_ONLY_CHANNEL plus a setWslOnly handler.
getWslState now includes the wslOnly flag, and the DesktopBridge
contract gains setWslOnly(enabled).
- Settings UI gets a third row ("Run WSL only") under the distro
picker, visible when WSL is enabled. The confirmation dialog
grows a third branch with restart-aware copy ("Save and restart
later") since the primary spec is captured at layer init.
Migration / defaults: wslOnly defaults to false. Existing setups
stay on parallel mode unless the user explicitly turns this on.
Tests: test bridges, settings mock, and IPC layerTest extended for
the new field. Existing settings + backend + WSL test suites pass.
PickFolderOptions gains an optional targetEnvironmentId so callers
that know which local backend they're targeting (a project opened in
WSL, for example) can ask for that backend's filesystem picker.
The default behavior is unchanged: when targetEnvironmentId is
undefined, the dialog opens against the Windows-native primary, which
is what every existing caller gets. This is deliberate — most users
never enable the WSL backend and shouldn't see a different picker
showing up. Only callers that explicitly opt in route to WSL.
When targetEnvironmentId starts with "wsl:", the handler uses the
WSL helpers in wslPathParsing.ts. The id encodes the distro
selection (e.g. "wsl:ubuntu") and falls back to the persisted
wslDistro setting when the id is the "wsl:default" sentinel, matching
how DesktopWslBackend.reconcile resolves the same input. The legacy
"if wslBackendEnabled then always use WSL picker" branch is gone —
that was the swap-mode mental model.
getLocalEnvironmentBootstrap used to hand back a single bootstrap for
the primary backend. With the WSL backend running as a second pool
instance, the renderer needs to learn about both so step 7 can
register them as separate local environments.
Rename the IPC to getLocalEnvironmentBootstraps (plural) and walk
pool.list, emitting one entry per instance that already has a config.
Instances that are registered but haven't produced a config yet (WSL
backend mid-registration before its first start cycle) are skipped
and will appear on the next call.
The bootstrap entry gains an id field that mirrors the backend
instance id (e.g. "primary" or "wsl:ubuntu"). The renderer uses that
to find the primary entry today (auth.ts, target.ts); step 7 keys
local environments off the same id. PRIMARY_LOCAL_ENVIRONMENT_ID is
exported from contracts so web code can reference the primary by name
without importing brand machinery from the desktop package. The
desktop side wraps the same constant in BackendInstanceId so the two
stay locked together.
Test bridge mocks updated. The DesktopBridge casts in
authBootstrap.test.ts went through `as DesktopBridge` previously; the
array-returning plural is structurally different enough that TS
flagged it, so they go through `as unknown as DesktopBridge` now.
This is the cut-over to parallel backends. The old "swap the primary
into WSL and bounce it" flow goes away; the WSL backend is now a
second instance registered with the pool, running alongside the
Windows primary. Toggling the WSL backend on/off doesn't touch the
primary at all.
New service DesktopWslBackend (apps/desktop/src/wsl/DesktopWslBackend.ts)
owns the orchestration. Its one entry point, reconcile, reads the
persisted wslBackendEnabled + wslDistro settings, looks at what's
currently registered with the pool, and brings the two in line:
- If WSL should be running and isn't, allocate a loopback port
starting one above the primary's, register a fresh instance via
pool.register({ id, label, configResolve: resolveWsl(...) }),
and kick off instance.start.
- If WSL is running with a stale distro selection, unregister the
old instance (which closes its scope and stops the child process)
before registering the new one.
- If WSL should not be running, unregister whatever wsl: instance
is registered.
reconcile never fails. Port-allocation failures, "WSL not available",
and pool-already-registered errors are logged and the call returns
having left the pool in a consistent state. The primary backend is
never affected.
Instance ids encode the user's distro selection: wsl:default when
wslDistro is null (track the WSL default) and wsl:<distro> otherwise.
These ids are what the env-id work in step 6/7 will key off, so they
stay stable across underlying-default-distro changes — picking
"track default" doesn't reshuffle env ids if the user later sets a
different WSL distro as the default.
Bootstrap call site (DesktopApp.ts) forks reconcile after the primary
start request. The WSL backend can take a moment to come up first
time (wsl.exe cold spawn, node-pty build); the fork keeps that off
the primary's critical path.
IPC surface change:
- Drop setWslBackend({mode, distro}) — the swap call with rollback
semantics — and the SWAP_READINESS_TIMEOUT / waitForReady /
in-process primary stop+start dance in apps/desktop/src/ipc/methods/wsl.ts.
- Add setWslBackendEnabled(boolean) + setWslDistro(string | null).
Each persists the setting via DesktopAppSettings and then calls
wslBackend.reconcile to bring the pool in line. No rollback path:
with both backends running, "WSL didn't come up" is transient
state on one instance, not a degraded app.
- Drop DesktopWslMode / DesktopWslModeSchema from contracts. The
DesktopWslState wire shape changes mode: "local" | "wsl" to a
plain enabled: boolean.
- New IPC channels SET_WSL_BACKEND_ENABLED_CHANNEL +
SET_WSL_DISTRO_CHANNEL.
DesktopBackendConfiguration's resolveWsl bootstrap now hardcodes
tailscaleServePort: 443 when tailscaleServeEnabled is false, because
PortSchema rejects 0. The backend only reads the port when serve is
on, so the value is inert.
Web UI (ConnectionsSettings.tsx) is wired against the new IPC. The
swap ceremony (reauth, welcome-race, suppressReconnect, 6-minute
flow timeout) goes away — toggling is fast and non-destructive now.
The dialog is still the same select-with-confirm shape; step 8 will
rework it into a proper "WSL backend: enabled + distro picker"
control. SettingsPanels.browser.tsx and localApi.test.ts pick up
the new mock shape.
Lets the desktop app launch the local backend inside a WSL distro
instead of natively on Windows. Adds:
- Backend plumbing (apps/desktop/src/wsl): pure path parsing
utilities, a DesktopWslEnvironment Effect service wrapping
wsl.exe operations (listDistros, preWarm, windowsToWslPath,
ensureNodePty, isAvailable), and an explicit preflight that
checks for missing node / build tools before spawning so the
failure message names the actual problem.
- Spawn path: DesktopBackendConfiguration branches on the new
wslMode setting and assembles "wsl.exe -d <distro> -- node
<linux-entry> --bootstrap-fd 0" with the bootstrap envelope on
stdin (wsl.exe drops additional file descriptors). Sensitive env
vars forward via WSLENV; --dev-url is passed as a CLI flag so the
WSL dev backend lands in dev/ instead of userdata/ deterministi-
cally. The Windows-side T3CODE_HOME is scrubbed and extendEnv is
disabled for WSL so the WSL backend cannot accidentally share a
baseDir with the local backend via /mnt/c/...
- Settings: wslMode + wslDistro on DesktopAppSettings, with
validation that drops distro names containing control or shell
meta characters. Contracts get DesktopWslMode / DesktopWslDistro
/ DesktopWslState schemas.
- IPC: getWslState and setWslBackend on the desktop bridge. The
setter pre-warms the WSL VM, persists settings, then drives an
in-process backend stop + start with a 2-minute readiness wait
and a rollback path that reverts to the previous mode if the new
backend never reports ready. pickFolder defaults to the WSL home
UNC path when wslMode is "wsl".
- Web UI: backend-runtime selector in Connection Settings with a
three-stage swap modal (restarting / re-establishing session /
syncing) that suppresses the WS reconnect toast for the duration
of the swap, waits for the new backend's welcome event before
closing, and clears the previous env's store state so the side-
bar does not render stale threads. New suppressReconnect helper
on the connection-status atom plus exports for the descriptor
refresh and reauth used by the swap flow.