Repository navigation
feat(remote): 通过 wsl.exe 打开本机 WSL 发行版作为远程工作区 (1lck/Lithe-IDEA#2231) - #157
Merged
Merged
Conversation
1lck/Lithe-IDEA#2231) remote.connect accepts wsl: { distribution, user? } instead of connection. Core then runs %SystemRoot%\System32\wsl.exe --distribution <d> [--user <u>] --cd ~ --exec … in place of OpenSSH; the probe, the checked upload, the stages and the session are the same as over SSH. - Transport: the WSL hop validates the user as a Linux login name (at most 32 bytes), is allowed as the first hop only, keeps the Windows environment wsl.exe needs and sets WSL_UTF8=1. Identity is wsl:[user@]distribution. - Trust: decisions name the distribution and the account as the first and only hop; WSL after SSH, WSL after WSL and unknown fields are refused. - Connection: WSL starts no AskPass session. A wsl.exe that exits before the server starts is classified from its stable error codes (WSL_E_DISTRO_NOT_FOUND is unreachable), with its UTF-16 or UTF-8 message decoded for diagnostics; a silent exit names wsl.exe and the status. A request naming both connection and wsl, or neither, is invalid_request with the field, before anything starts. - remote.listWslDistributions (no payload) runs wsl.exe --list --quiet with a 15 s bound and returns { available, distributions, diagnostics }: at most 64 names in wsl.exe order, without Docker Desktop's engine distributions and case-insensitive repeats. Other systems answer unavailable without running anything. - Logging: the connection kind wsl, and the cleanup and diagnostics stage descriptions cover wsl.exe; catalog regenerated. - Contract: remote.connect's wsl field, its refusals, and the new command. Tests use a stand-in wsl.exe to run the whole connection, check the arguments and environment it receives, the UTF-16 failure path and the listing.
xiaoyumuxi
marked this pull request as ready for review
November 21, 2026 15:08
This was referenced Nov 21, 2026
fix(desktop): 固定 Core #169,WSL 没装的发行版说明无法连接、未知用户带 wsl.exe 的消息,补真实主机验收测试 (#2231)
1lck/Lithe-IDEA#2300
Merged
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.
关联 Issue
1lck/Lithe-IDEA#2231(远程开发完整设计):远程工作区要能打开本机的 WSL 发行版。本 PR 是 Core 部分,桌面端的连接窗口接入另开 PR。
类型
remote.connect支持wsl: { distribution, user? },通过wsl.exe打开本机 WSL 发行版作为远程工作区;新增remote.listWslDistributions列出已安装的发行版改动说明
传输链(
crates/remote/src/client/transport.rs)Hop::Wsl(WslHop),命令行是%SystemRoot%\System32\wsl.exe --distribution <d> [--user <u>] --cd ~ --exec <命令…>:wsl.exe从 Windows 系统目录取,不走PATH,PATH上同名程序顶替不了;--exec不经过 shell,参数不需要再做 shell 转义;含 NUL 的参数拒绝(UnsafeArgument),因为 Windows 命令行放不下 NUL;--cd ~让服务从 Linux 主目录启动,不落在/mnt下那个很慢的 Windows 挂载目录。wsl.exe --import认的写法(ASCII 字母、数字、.、_、-,字母或数字开头,最长 64 字节);用户名沿用 SSH 的登录名规则,最长 32 字节(useradd的上限)。InvalidHop);WSL 之后接容器可以,即发行版里的容器。restrict_environment:WSL 链保留全部环境变量(wsl.exe只把WSLENV列出的变量传进发行版),并设置WSL_UTF8=1,让wsl.exe的提示用 UTF-8 输出。identity()为wsl:<发行版>或wsl:<用户>@<发行版>,最近项目和按主机保存的数据用它作键。starts_with_ssh(),会话据此决定是否需要 AskPass。连接参数与发行版列表(新文件
crates/remote/src/client/wsl.rs)WslConnection { distribution, user? }就是remote.connect的wsl字段,拒绝未知字段(例如program,请求不能指定要运行的程序)。hop()先去掉首尾空白,空user表示发行版默认用户;拒绝时给出字段和原因:distribution的required、tooLong、invalid,user的tooLong、invalid。list_command()是wsl.exe --list --quiet。parse_distributions():WSL_UTF8;docker-desktop、docker-desktop-data(和 VS Code 一样),忽略大小写去重(WSL 比较名称时不分大小写),跳过不是发行版名的行(如“没有安装发行版”的提示);output_text()用同样的规则把wsl.exe的输出解码成文本,供诊断信息使用。信任记录(
crates/remote/src/client/trust.rs)TargetHop::Wsl(WslTarget { distribution, user? })。键只包含发行版和账户,不包含wsl.exe的路径。日志(
rust/logging/events/remote.json)wsl(ConnectionKind::Wsl);cleanup_failed、diagnostics_failed的说明补上wsl.exe。目录已重新生成(146 个事件)。wsl.exe的诊断只显示给用户,不写日志;日志里没有发行版名和用户名。连接流程(
crates/workspace/src/sessions.rs、probe.rs)remote.connect必须且只能给出connection或wsl中的一个,否则在启动任何进程前返回invalid_request:两个都没有时details为{ field: "connection", reason: "required" },两个都有时为{ field: "wsl", reason: "invalid" }。原有的connection请求不受影响。remote.authRespond;探测、校验后上传、各阶段和会话本身都和 SSH 相同,进程树同样登记在会话表里,断开时结束。wsl.exe就退出时,用新增的classify_wsl按wsl.exe固定的错误码分类:WSL_E_DISTRO_NOT_FOUND归为unreachable,其余归为failed;诊断信息按 UTF-16 或 UTF-8 解码后脱敏。列出发行版(新文件
crates/workspace/src/wsl.rs,命令remote.listWslDistributions){ available, distributions, diagnostics },不保存任何内容。available: false,不运行任何程序;Windows 上找不到wsl.exe时也返回available: false。wsl.exe --list --quiet时设置WSL_UTF8=1,最多等 15 秒(开机后第一次调用要启动 WSL 服务),超时返回timed_out,并响应请求取消。wsl.exe返回非零时available: true、列表为空,diagnostics是它输出内容的脱敏文本(例如还没装 WSL 的提示),只显示、不写日志。crates/core只加命令名映射和 dispatcher 分支。契约(
rust/contracts/rust-core-api.md)remote.connect写明 SSH 或本机 WSL 发行版;remote.disconnect写明结束 OpenSSH 或wsl.exe的进程树;新增remote.listWslDistributions一行。wsl字段的写法、不走 AskPass、发行版不存在时为unreachable、信任记录里的跳形状,以及connection、wsl都给或都不给时的错误和字段规则。范围
crates/remote;crates/workspace只负责把它接到连接流程和命令上,crates/core只做转接。ConnectionError::at改成pub(crate),供wsl.rs构造字段错误。验证
cargo test -p lithe-remote:122 个通过。新增:transport:WSL 跳的命令行(不经 shell、--cd ~、--user)、identity、拒绝不合法名称和 NUL、不是第一跳时拒绝、发行版里接容器、wsl.exe取自系统目录、环境变量保留并设置WSL_UTF8=1;trust:WSL 目标的序列化与往返、不同发行版或账户互不覆盖、拒绝不是第一跳的 WSL 和未知字段;wsl:UTF-16(有无 BOM)和 UTF-8 解析、去掉 Docker 引擎发行版、去重、跳过提示行、64 个与 64 KiB 上限、字段去空白和逐项拒绝原因、拒绝program字段。cargo test -p lithe-workspace:53 个通过。用替身wsl.exe跑完整个连接流程:--distribution Ubuntu-24.04 --user dev --cd ~ --exec …)和环境(有WSL_UTF8=1、保留调用方变量、没有SSH_ASKPASS_REQUIRE);unreachable且诊断可读,静默exit 3时为failed并写明退出码;connection、wsl都给或都不给,以及发行版、用户名不合法时直接拒绝,替身一次都没运行;--list --quiet参数和WSL_UTF8=1、失败时带提示且无名称、找不到程序和非 Windows 系统都是available: false。cargo test -p lithe-core --lib:888 个通过。connection_window_helpers_answer_through_the_dispatcher新增:非 Windows 上列表返回available: false;同时给connection和wsl时返回invalid_request,details为{"field":"wsl","reason":"invalid"};wsl带未知字段时返回invalid_request。cargo test -p lithe-diagnostics:71 个通过(日志目录重新生成后)。cargo clippy -p lithe-remote -p lithe-workspace -p lithe-core --all-targets --all-features -- -D warnings、cargo fmt --all --check:通过。scripts/rust-core/verify-rust-core-comments.sh、node scripts/rust-core/verify-platform-tests.mjs、node scripts/logging/generate-log-events.mjs(生成后无差异):通过。还没在真 Windows 上确认的行为
替身程序按文档和 VS Code 的做法写,下面几项要在 Windows 虚拟机上装 WSL 实测,桌面端 PR 会一起做:
wsl.exe的错误提示(发行版不存在、WSL 未安装)写到标准输出还是标准错误。现在两边都读:连接失败读标准错误,列表失败两边合并。--exec下标准输入输出是否完全不改字节(远端服务协议是二进制帧)。wsl.exe进程树后,发行版里的服务进程是否随之退出。--user指定不存在的用户时wsl.exe输出什么、退出码是多少;现在会归为failed,并显示它的原文。x86_64-pc-windows-msvc)的 clippy 本机跑不了(libsqlite3-sys需要 Windows 的 C 编译器),交给 CI 的 Windows 任务。