feat(wsl): add WSL project runtime support#245
Open
Duducoco wants to merge 3 commits into
Open
Conversation
- add WSL project selection, settings, and runtime metadata - run agents, git, filesystem, and shell commands in WSL contexts - support WSL session discovery and structured session locations
Owner
|
这个PR 的改动有点过于大了,请问在群里吗~ |
Author
我不在群里,我也发现改动的文件太多,我想办法看如何减少一些改动 |
- run WSL detection commands without creating console windows - hide session home lookups during WSL session discovery
- share interactive shell helpers across WSL agent launch paths - remove optional WSL labels and copy actions from ancillary UI - drop accidental pnpm workspace placeholder
Author
|
我已经重新审查并收敛了 WSL 相关改动,尽量减少了受影响的文件数量。目前保留的改动基本都是 WSL 功能链路必需的部分。 这组 WSL 提交主要包含以下能力:
剩下的文件改动主要是为了把 runtime 参数传递到 Tauri 命令边界,以及让文件、Git、终端、任务和会话这些核心模块真正能在 WSL 项目中工作 |
Owner
|
@Duducoco pr 太大,我可能需要花时间评估一下引入 wsl 支持这个特性~,感谢贡献代码 |
Author
好的,感谢作者。不知后续有没有支持ssh的计划 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(wsl): add WSL project runtime support
Summary
This PR adds first-class WSL project support to Nezha. Users can now open Linux projects from a selected WSL distribution, persist them as WSL-backed projects, and run Nezha workflows against the Linux filesystem and Linux toolchain instead of the Windows host environment.
The implementation introduces a runtime abstraction for projects, then threads that runtime through the frontend and Tauri backend so agent tasks, embedded shells, file browsing, Git operations, session discovery, settings, and task persistence all understand whether a project is local or WSL-backed.
This is intentionally implemented as an MVP without WSL hook installation. WSL projects use session-file polling and structured session locations instead of injecting local Windows hooks into distro-local Claude/Codex configuration.
Why
Before this change, Nezha assumed that every project path and tool invocation belonged to the Windows host environment:
That breaks for users whose real development environment is inside WSL. In that setup:
/home/user/project.\\wsl.localhost\Rocky8\home\user\project.This PR makes Nezha preserve that runtime boundary instead of flattening WSL projects into ordinary Windows paths.
What Changed
Project Runtime Model
Added a runtime model that distinguishes local projects from WSL projects.
New frontend types include:
ProjectRuntimeSessionLocationWslDistroInfoWslProjectValidationProjects can now carry runtime metadata such as:
This lets the UI keep displaying and persisting a normal project while still routing backend operations through WSL when needed.
WSL Runtime Backend Module
Added
src-tauri/src/runtime.rsto centralize WSL-specific helpers and Tauri commands.The new runtime module handles:
wsl.exe.The WSL agent detection path uses the configured shell in interactive mode so user shell initialization is respected. This is required for setups where
claudeorcodexare exposed through Linuxbrew, nvm, or shell aliases rather than the distro's minimal non-interactive PATH.App Settings: WSL Panel
Added a WSL settings panel under application settings.
The panel supports:
The settings panel now correctly handles the
save_app_settingscommand returningvoid, keeping the current settings state after save instead of replacing it with an empty value.The check result reads backend camelCase fields correctly:
gitPathclaudeVersioncodexVersionWelcome Page: Open WSL Projects
The welcome flow now supports WSL-backed project creation/opening.
The WSL project flow:
WSL projects are deduplicated by distro and Linux path, not just by Windows path.
Agent Launching in WSL
Agent task execution now respects the project runtime.
For WSL projects, Claude Code and Codex are launched through
wsl.exewith:This fixes cases where
wsl.exe --exec claudefails because the command only exists after.bashrc, Linuxbrew, nvm, or aliases are loaded.Important behavior:
claudeandcodex.Embedded Shell in WSL
The embedded shell panel now opens the configured WSL shell inside the Linux project directory when the active project is WSL-backed.
This makes the shell environment match the selected project runtime rather than dropping users into a Windows shell for a Linux project.
Git Operations in WSL
Git operations now accept runtime context and route WSL project commands through the selected distro.
The Git integration supports WSL-aware behavior for:
The intent is that Git panels reflect what users would see when running Git inside the WSL project directory.
File System Operations in WSL
File operations now support WSL project paths and UNC-backed reads.
Updated areas include:
The backend preserves path validation so WSL file operations remain scoped to the selected project.
Project Config in WSL
Project config commands now accept runtime context.
This allows
.nezha/config.tomland related project-level config reads/writes to happen in the correct project environment for WSL-backed projects.Session Discovery and Reading
Session handling now supports structured session locations.
New behavior:
SessionLocation::Wsl.sessionPathor structuredsessionLocation.For WSL projects, session discovery avoids injecting
/statusinto the live terminal. Instead, it polls WSL session files and binds the most recent matching session. This prevents the UI from visibly typing/statusinto Claude/Codex interactive sessions.Task Persistence
Task storage now preserves structured session location fields:
claudeSessionLocationcodexSessionLocationThe existing session path fields remain for backward compatibility.
UI Routing and Props
Runtime metadata is threaded through the main UI so the correct backend behavior is selected from project context.
Updated areas include:
App.tsxProjectPageWelcomePageSettingsDialogLocalized UI Strings
Added WSL-related localization entries for the settings panel, welcome flow, validation states, unsupported worktree flow, and runtime labels.
Important Implementation Details
Interactive Shell Detection
WSL agent detection and WSL agent launching use an interactive shell command path because many real installations expose
claudeandcodexthrough shell initialization.This avoids the failure mode where:
fails with:
even though
claudeworks in the user's WSL terminal.WSL Hooks Are Intentionally Disabled
This PR does not install or use WSL-specific hooks.
For WSL projects:
This keeps the MVP isolated from Windows hook configuration and avoids mixing host-local and distro-local event paths.
Session Polling Avoids
/statusInjectionThe local fallback path can use
/statusto identify sessions. In WSL, that was visible and disruptive in interactive terminals.This PR changes WSL-backed tasks to poll session files instead. That prevents Nezha from typing
/statusinto the user's live Claude/Codex session.Worktrees Are Guarded for WSL
The new-task worktree launch path is blocked for WSL projects in this MVP. Worktree support requires additional Linux-path-aware branch and filesystem handling and should be implemented separately.
Files Added
src-tauri/src/runtime.rssrc/components/app-settings/WslPanel.tsxsrc/projectRuntime.tspnpm-workspace.yamlFiles Updated
Major backend updates:
src-tauri/src/pty.rssrc-tauri/src/session.rssrc-tauri/src/git.rssrc-tauri/src/fs.rssrc-tauri/src/config.rssrc-tauri/src/storage.rssrc-tauri/src/app_settings.rssrc-tauri/src/agent_assist.rssrc-tauri/src/analytics.rssrc-tauri/src/lib.rsMajor frontend updates:
src/App.tsxsrc/types.tssrc/components/WelcomePage.tsxsrc/components/AppSettingsDialog.tsxsrc/components/SettingsDialog.tsxsrc/components/ProjectPage.tsxsrc/components/RunningView.tsxsrc/components/SessionView.tsxsrc/components/ShellTerminalPanel.tsxsrc/components/FileExplorer.tsxsrc/components/FileViewer.tsxsrc/components/GitChanges.tsxsrc/components/GitDiffViewer.tsxsrc/components/GitHistory.tsxsrc/i18n.tsxManual Verification Performed
Verified on Windows with WSL distro
Rocky8.WSL shell verification:
gitresolves to/usr/bin/gitclauderesolves to/home/linuxbrew/.linuxbrew/bin/claudecodexresolves to/home/linuxbrew/.linuxbrew/bin/codex2.1.168 (Claude Code)codex-cli 0.136.0Verified behavior:
wsl.exe --exec claude./statuscommand from Nezha.Automated / Command Verification
Passed:
Passed:
Also checked before committing:
Not completed:
pnpm buildwas blocked by the local pnpm dependency policy:This appears to be an environment/package-manager approval issue rather than a TypeScript or Rust compile failure.
Risks
Session Matching Is Polling-Based for WSL
WSL sessions are discovered by polling session files instead of hook events. This is less immediate than hooks and may be less precise if multiple WSL agent sessions are launched simultaneously in the same project.
WSL Path Handling Is Broadly Threaded
This PR touches many UI and backend paths because project runtime affects nearly every workflow. The highest-risk areas are Git actions, file writes, and session path resolution.
WSL Worktrees Are Not Supported Yet
Worktree launch is guarded for WSL projects. Users should create/run tasks in the main WSL project path until WSL worktree support is implemented.
WSL Proxy Warnings May Still Appear
WSL can print localhost proxy warnings independently of Nezha. This PR fixes command resolution and session pollution, but does not change WSL networking/proxy configuration.
Backward Compatibility
Local Windows projects continue to use the existing behavior.
Existing fields are retained:
claudeSessionPathcodexSessionPathNew fields are additive:
runtimeclaudeSessionLocationcodexSessionLocationThis avoids forcing an immediate migration of existing local project/task data.
Follow-up Work
Recommended follow-ups:
PR Checklist
/statusinjection for WSL session discovery.pnpm buildonce local pnpm build-script approval is resolved.