Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat: add WSL support #2402

ClosedUtkarshUsername(GitHub profile, opens in a new tab)wants to merge 61 commits intomain fromrefs/pull/2402/headopened View on GitHub

Summary

This PR adds first-class WSL execution support for Windows users running T3 Code with the local backend. WSL is now treated as a real execution target, not a mounted Windows folder. Backend-owned project, terminal, provider, workspace, and persistence flows can carry WSL distro identity and POSIX cwd values through the system.

What works

  • Open WSL folders from the app UI
  • Persist WSL project/session metadata
  • Run Codex from inside WSL on Windows
  • Launch terminals in WSL with POSIX cwd values
  • Route WSL project file and workspace operations through backend WSL commands
  • List and browse WSL distros from bun run dev, npx t3, and packaged desktop
  • Reopen WSL projects and keep the execution target

Notes

  • The implementation stays backend-owned in apps/server so it works across desktop and non-desktop local modes.
  • The WSL path model follows Zed-style execution targets and explicit path translation.
  • WSL provider startup is currently validated on Codex; other providers can be verified on the same execution-target foundation.

Video Demo

https://github.com/user-attachments/assets/05facc3a-36c6-42d1-bab1-f09feb206751

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Add WSL-native execution targets for Windows projects across git, terminal, and provider sessions

  • Introduces ExecutionTarget contracts and a new wsl package with CLI helpers (WslCli.ts, WslPath.ts, WslBrowse.ts) to run git, terminal, and file operations inside WSL distributions via wsl.exe.
  • Threads executionTarget through git operations in GitCore.ts and GitStatusBroadcaster.ts using AsyncLocalStorage context so all git commands (status, branch list, checkout, pull, init) are dispatched via WSL when a WSL target is active.
  • Terminal sessions in Manager.ts spawn wsl.exe with the appropriate shell and cwd when executionTarget.kind === 'wsl', resolving the Linux shell from inside the distro.
  • Provider session runtimes (CodexSessionRuntime.ts) resolve the Codex binary and home directory inside WSL and launch via wsl.exe; executionTarget is persisted to the database via migration 027_ExecutionTargets.ts.
  • The command palette (CommandPalette.tsx) gains a WSL browse flow that lists distributions and lets users add projects from Linux filesystems.
  • Risk: git status cache keys change from plain cwd to execution-target-prefixed keys (wsl:<distro>:<user>:<cwd> / local:<cwd>), which will invalidate existing in-memory caches on upgrade.
📊 Macroscope summarized 84aef00. 49 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.

>
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 1785d4e7-0054-4a17-aedd-8c018263cd2d

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High

      https://github.com/pingdotgg/t3code/blob/fcdbec88af160db0757efa4c278c331d0c0f1cb1/apps/web/src/lib/gitReactQuery.ts#L107

      gitResolvePullRequestQueryOptions passes input.executionTarget to the API call but omits it from the queryKey. When the same function is called twice with different executionTarget values but identical environmentId, cwd, and reference, the second call returns the cached result from the first instead of fetching fresh data. Include executionTarget in the queryKey array to ensure each execution target produces a separate cache entry.

      ✅ Resolved in a32cc8594378ea39094b6c0c909b50aa58a7bf06

    4. github-actions[bot](GitHub profile, opens in a new tab) removed labelsvouch:unvouched

    5. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    6. @@ -552,3 +566,8 @@
      552566 (persistedBinding?.providerInstanceId === resolvedInstanceId
      553567 ? readPersistedCwd(persistedBinding.runtimePayload)
      554568 : undefined);
      569+ const effectiveExecutionTarget =
      570+ input.executionTarget ??
      571+ (persistedBinding?.provider === input.provider
      572+ ? readPersistedExecutionTarget(persistedBinding.runtimePayload)
      573+ : undefined);
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Layers/ProviderService.ts:569

      In startSession, the condition for inheriting executionTarget from a persisted binding checks persistedBinding?.provider === input.provider, but the conditions for effectiveCwd and effectiveResumeCursor check persistedBinding?.providerInstanceId === resolvedInstanceId. This means when switching between two instances of the same provider type (e.g., Claude instance A → Claude instance B on the same thread), the executionTarget from instance A is incorrectly inherited to instance B, while cwd correctly resets. The condition on line 571 should use persistedBinding?.providerInstanceId === resolvedInstanceId to match the other inherited settings.

              const effectiveExecutionTarget =
                input.executionTarget ??
      -          (persistedBinding?.provider === input.provider
      +          (persistedBinding?.providerInstanceId === resolvedInstanceId
                  ? readPersistedExecutionTarget(persistedBinding.runtimePayload)
                  : undefined);
      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/provider/Layers/ProviderService.ts around lines 569-573:
      
      In `startSession`, the condition for inheriting `executionTarget` from a persisted binding checks `persistedBinding?.provider === input.provider`, but the conditions for `effectiveCwd` and `effectiveResumeCursor` check `persistedBinding?.providerInstanceId === resolvedInstanceId`. This means when switching between two instances of the same provider type (e.g., Claude instance A → Claude instance B on the same thread), the `executionTarget` from instance A is incorrectly inherited to instance B, while `cwd` correctly resets. The condition on line 571 should use `persistedBinding?.providerInstanceId === resolvedInstanceId` to match the other inherited settings.
      
      Evidence trail:
      apps/server/src/provider/Layers/ProviderService.ts lines 559-573 at REVIEWED_COMMIT (showing the inconsistent condition checks). Commit 08e6d4cfbfe55af83fe5fb6b9e75364f42f1f22f diff on ProviderService.ts shows the multi-provider migration explicitly changed resumeCursor and cwd from `persistedBinding?.provider === input.provider` to `persistedBinding?.providerInstanceId === resolvedInstanceId` and removed executionTarget inheritance entirely. The executionTarget was later re-added with the old provider-level check, creating the inconsistency.
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/84aef00c6cb2d955e87fe522ce786ecd42ab4bbd/apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts#L1302

      getCommandReadModel omits executionTarget from the returned OrchestrationProject objects even though the SQL query fetches the column. The sibling function getSnapshot includes ...(row.executionTarget != null ? { executionTarget: row.executionTarget } : {}) when building projects, but getCommandReadModel at lines 1302-1311 does not. Both functions return OrchestrationReadModel, so the command read model has incomplete project data compared to the full snapshot.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts around line 1302:
      
      `getCommandReadModel` omits `executionTarget` from the returned `OrchestrationProject` objects even though the SQL query fetches the column. The sibling function `getSnapshot` includes `...(row.executionTarget != null ? { executionTarget: row.executionTarget } : {})` when building projects, but `getCommandReadModel` at lines 1302-1311 does not. Both functions return `OrchestrationReadModel`, so the command read model has incomplete project data compared to the full snapshot.
      
      Evidence trail:
      - OrchestrationProject type definition: packages/contracts/src/orchestration.ts:201-212 (executionTarget is Schema.optional)
      - getSnapshot project mapping WITH executionTarget: apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts:1178-1189 (line 1182)
      - getCommandReadModel project mapping WITHOUT executionTarget: apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts:1302-1311
      - SQL queries that fetch executionTarget: apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts:320, 682, 705
      - git grep for executionTarget confirms it appears in getSnapshot mapping but not getCommandReadModel mapping
      @@ -1835,4 +1836,5 @@
      18351836 worktreePath: activeThread?.worktreePath ?? null,
      18361837 })
      18371838 : null;
      1839+ const activeProjectExecutionTarget = activeProject?.executionTarget;
      18381840 const gitStatusQuery = useVcsStatus({ environmentId, cwd: gitCwd });
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High components/ChatView.tsx:1840

      useVcsStatus at line 1840 is called without executionTarget, even though activeProjectExecutionTarget is available from the line above. When a project defines a non-undefined executionTarget, the hook resolves VCS status against the wrong execution context, so isGitRepo and branch data may be incorrect. Pass executionTarget: activeProjectExecutionTarget to the hook.

      Also found in 2 other location(s)

      apps/web/src/components/BranchToolbarBranchSelector.tsx:205

      The useVcsStatus call on line 205 does not include executionTarget, despite the changes to vcsStatusState.ts adding support for executionTarget in the watcher. The executionTarget variable is defined on line 204 and is consistently passed to all other VCS-related operations in this component (branchRefTarget at line 212, api.vcs.switchRef at line 345, api.vcs.createRef at line 380), but is omitted from useVcsStatus. This inconsistency could cause the VCS status query to use incorrect execution settings, potentially returning wrong branch status information when executionTarget affects how VCS operations are performed.

      packages/client-runtime/src/vcsStatusState.ts:224

      Missing executionTarget parameter in subscribeStream call when using explicit client. At line 224, subscribeStream(targetKey, target.cwd, client) is called without the executionTarget argument, but the other two call sites (line 183 in createDynamicSubscription and line 232 in the one-shot resolution path) correctly pass executionTarget. This means when watch(target, client) is called with an explicit client for a WSL target, the subscription will be created without the execution target context, causing it to subscribe to the wrong data stream (local instead of WSL).

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/web/src/components/ChatView.tsx around line 1840:
      
      `useVcsStatus` at line 1840 is called without `executionTarget`, even though `activeProjectExecutionTarget` is available from the line above. When a project defines a non-`undefined` `executionTarget`, the hook resolves VCS status against the wrong execution context, so `isGitRepo` and branch data may be incorrect. Pass `executionTarget: activeProjectExecutionTarget` to the hook.
      
      Evidence trail:
      apps/web/src/components/ChatView.tsx lines 1839-1840: `activeProjectExecutionTarget` defined but not passed to `useVcsStatus`.
      packages/client-runtime/src/vcsStatusState.ts lines 21-25: `VcsStatusTarget` interface with optional `executionTarget`.
      packages/client-runtime/src/vcsStatusState.ts lines 71-76: `getVcsStatusTargetKey` uses `executionTarget` to differentiate `local` vs `wsl:distroName`.
      apps/web/src/lib/vcsStatusState.ts lines 52-62: `useVcsStatus` passes `executionTarget` to `manager.watch()`.
      apps/web/src/components/DiffPanel.tsx line 157: passes `executionTarget: activeProject?.executionTarget`.
      apps/web/src/components/ThreadStatusIndicators.tsx line 156: passes `executionTarget: threadProject?.executionTarget`.
      apps/web/src/components/GitActionsControl.tsx line 1066: passes `executionTarget`.
      
      Also found in 2 other location(s):
      - apps/web/src/components/BranchToolbarBranchSelector.tsx:205 -- The `useVcsStatus` call on line 205 does not include `executionTarget`, despite the changes to `vcsStatusState.ts` adding support for `executionTarget` in the watcher. The `executionTarget` variable is defined on line 204 and is consistently passed to all other VCS-related operations in this component (`branchRefTarget` at line 212, `api.vcs.switchRef` at line 345, `api.vcs.createRef` at line 380), but is omitted from `useVcsStatus`. This inconsistency could cause the VCS status query to use incorrect execution settings, potentially returning wrong branch status information when `executionTarget` affects how VCS operations are performed.
      - packages/client-runtime/src/vcsStatusState.ts:224 -- Missing `executionTarget` parameter in `subscribeStream` call when using explicit client. At line 224, `subscribeStream(targetKey, target.cwd, client)` is called without the `executionTarget` argument, but the other two call sites (line 183 in `createDynamicSubscription` and line 232 in the one-shot resolution path) correctly pass `executionTarget`. This means when `watch(target, client)` is called with an explicit client for a WSL target, the subscription will be created without the execution target context, causing it to subscribe to the wrong data stream (local instead of WSL).
      
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟢 Low

      https://github.com/pingdotgg/t3code/blob/84aef00c6cb2d955e87fe522ce786ecd42ab4bbd/apps/server/src/terminal/Layers/Manager.ts#L2041

      In openLocked, when an existing session is restarted at lines 2041–2056, assertValidCwd validates input.cwd against openExecutionTarget (from input.executionTarget at line 1945), but startSession uses liveSession.executionTarget at line 2052. If the input target differs from the stored session target, the cwd passes validation against one target but the shell starts under a different target, causing the PTY spawn to fail with an invalid cwd.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/terminal/Layers/Manager.ts around line 2041:
      
      In `openLocked`, when an existing session is restarted at lines 2041–2056, `assertValidCwd` validates `input.cwd` against `openExecutionTarget` (from `input.executionTarget` at line 1945), but `startSession` uses `liveSession.executionTarget` at line 2052. If the input target differs from the stored session target, the cwd passes validation against one target but the shell starts under a different target, causing the PTY spawn to fail with an invalid cwd.
      
      Evidence trail:
      apps/server/src/terminal/Layers/Manager.ts lines 1942-1945 (openExecutionTarget derived from input, used in assertValidCwd), lines 2006-2029 (existing session found, launchContextChanged block never updates liveSession.executionTarget), lines 2030-2038 (exited/error block also never updates liveSession.executionTarget), lines 2041-2056 (startSession called with liveSession.executionTarget at line 2048 instead of openExecutionTarget), lines 1990-2002 (new session path correctly uses openExecutionTarget for comparison)
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/84aef00c6cb2d955e87fe522ce786ecd42ab4bbd/apps/web/src/components/CommandPalette.tsx#L783

      When the user navigates back from WSL browse mode via popView(), wslBrowseTarget is only cleared when viewStack.length <= 1 (line 787-788). If the user is deeper in the stack (e.g., returned to the WSL distribution selection submenu), wslBrowseTarget remains non-null. This causes isBrowsing to stay true (lines 506-508), which incorrectly forces displayedGroups to show browseGroups instead of the submenu groups — leaving the user stuck in an empty browse UI.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/web/src/components/CommandPalette.tsx around line 783:
      
      When the user navigates back from WSL browse mode via `popView()`, `wslBrowseTarget` is only cleared when `viewStack.length <= 1` (line 787-788). If the user is deeper in the stack (e.g., returned to the WSL distribution selection submenu), `wslBrowseTarget` remains non-null. This causes `isBrowsing` to stay `true` (lines 506-508), which incorrectly forces `displayedGroups` to show `browseGroups` instead of the submenu groups — leaving the user stuck in an empty browse UI.
      
      Evidence trail:
      apps/web/src/components/CommandPalette.tsx lines 783-792 (popView function with conditional clear at line 785-788), lines 816-824 (startWslProjectBrowse setting wslBrowseTarget and pushing view), lines 506-508 (isBrowsing derived from wslBrowseTarget !== null), lines 1498-1504 (displayedGroups overridden to browseGroups when isBrowsing is true), lines 1112-1145 (WSL submenu item that pushes a distro selection view before startWslProjectBrowse pushes the browse view), line 415 (viewStack initialized as empty array)
    7. Closing in favor of #2751 (Btw, if anyone is exploring this PR in the future, it is in a broken state now. Check it from before the commit which merged main into this branch)

Sign in to join this conversation.