feat: add initial WSL environment detection - #4
Open
onedotmint wants to merge 2 commits into
Open
Conversation
Owner
|
在保证代码可维护的情况下,我认为这个功能可以拓展。您可以随时提交您的PR🤗 下一个版本我会审核您的PR,并合并 |
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.
背景
我目前是在 Windows 上使用 Pi Switch,但 Pi 本身主要运行在 WSL 中。现有 Pi Switch 还不能直接识别或管理 WSL 内的 Pi 环境
这个 PR 先补充一层基础的、只读的 WSL 环境检测能力,为后续支持 Windows / WSL Pi 环境切换和配置管理做准备。
目前这个 PR 仍然不涉及配置修改或 UI,只包含两个基础步骤:
本次改动
WSL distribution detection
wsl.exe --list --quiet枚举已安装的 distributionsApp.GetWSLDetectionwsl.exeUTF-16LE 输出的解析wsl.exe时使用CREATE_NO_WINDOW,避免弹出命令行窗口当前可以区分:
WSL Pi detection
新增
App.GetWSLPiDetection(distro),用于只读检测指定 WSL distro 中的:$HOMEpi是否能在固定的非交互环境 PATH 中找到pi的实际路径~/.pi是否存在~/.pi/agent/settings.json是否存在~/.pi/agent/models.json是否存在Windows 下通过结构化参数执行:
distro作为独立 argument 传入,不会拼接到 shell script 中。probe 本身是固定的只读脚本,不会读取或修改 Pi 配置,也不会 source
.bashrc、.profile、.zshrc或启动 login / interactive shell。因此这里的
PiAvailable只表示pi能否在这个固定的非交互 WSL 环境中通过 PATH 找到,并不表示 Pi 一定没有安装。例如只通过 NVM shell profile 暴露的 Pi,目前可能返回PiAvailable: false。不存在的 distro 会返回明确错误;Pi、
.pi或配置文件不存在则作为正常检测结果返回。实现说明
WSL distribution 枚举直接调用:
Pi detection 则调用:
两处都没有经过
cmd.exe、PowerShell 或动态 shell 字符串拼接。distribution list 在实际 Windows 环境中返回 UTF-16LE,因此单独进行了对应解析;WSL 内 probe 的输出则使用严格 UTF-8 和固定 NUL 分隔协议。
测试
已通过:
go test -count=1 ./...go vet ./...go build ./...internal/wslcompile checkinternal/wslcompile checknpm --prefix frontend run buildwails build -platform windows/amd64gofmt -dgit diff --check另外进行了真实 Windows 11 + WSL2 smoke test:
wsl.exe --list --quiet一致当前范围
这个 PR 仍然只做只读 detection,没有涉及:
settings.json/models.json修改后续规划
如果这个方向符合项目预期,后续可以继续逐步补充:
我会继续尽量保持每一步范围较小、可测试,也方便单独 review。如果您对后续实现方式或功能边界有其他偏好,我可以再按项目方向调整。