feat: 支持从 WSL 发行版读取 Pi 配置文档 - #6
Merged
Merged
Conversation
Owner
|
Got it and reviewing!( |
Wing900
approved these changes
Aug 22, 2026
Wing900
left a comment
Owner
There was a problem hiding this comment.
Reviewed locally on Windows (go1.26.2): go build / go vet / go test ./internal/wsl/... all pass, including the new PiConfig tests and the Windows-tagged argv & CREATE_NO_WINDOW assertions. Remote CI green.
Verified highlights:
- argv-only wsl.exe --exec cat invocation, no shell interpolation; distro whitelisted via DetectPi
- path.Join (not filepath) for in-WSL Linux paths — correct detail
- Clear error contract, locked by tests: zero-value on partial failure, 8 MiB hard limit without truncation, strict UTF-8
- Good injection seams and table-driven tests; bindings match Go json tags
Non-blocking notes only (unwrapped cmd.Wait() error style, TOCTOU strictness as documented contract). Ship it.
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.
概述
本 PR 在现有 WSL 发行版检测和 Pi 可用性检测基础上,新增只读的 Pi 配置文档读取能力。
通过新的 Wails 后端 API:
GetWSLPiConfigDocuments(distro string)
可以从指定 WSL 发行版读取:
~/.pi/agent/settings.json
和:
~/.pi/agent/models.json
本 PR 仅负责后端读取能力及 Wails bindings
主要改动
新增 wsl.PiConfigDocuments 数据结构及 ReadPiConfigDocuments
复用现有 DetectPi(distro) 完成发行版验证、Pi home 和配置文件存在性检测
缺失配置文件作为正常状态返回,不执行额外读取
通过独立 argv 调用 wsl.exe --distribution --exec cat ,避免 shell 字符串拼接
单个配置文件最大读取 8 MiB,超限直接返回错误,不返回截断内容
保留原始 UTF-8 文本,不解析或验证 JSON 内容
任一文件读取失败时,整个调用返回错误和零值,避免暴露部分读取结果
新增 Windows 实现和 non-Windows stub
更新 Wails 自动生成 bindings
增加后端测试,覆盖缺失文件、空文件、非 JSON、UTF-8、读取失败、路径包含空格、大小限制以及 Windows argv / CREATE_NO_WINDOW 等行为
验证
已完成后端单元测试、Windows 交叉编译、Windows Wails release 构建和应用启动 smoke test。
另外在真实 Windows → WSL 环境完成运行时验证:
Ubuntu:检测到 Pi,settings.json 和 models.json 均存在并成功读取,大小分别为 756 和 8678 字节。
Ubuntu-24.04:检测到 Pi,两个配置文件均存在并成功读取,大小分别为 208 和 7083 字节。
实际验证确认了 WSL distro 枚举、逐个 Pi 探测、wsl.exe 参数调用、Linux 路径处理、配置文件读取以及缺失文件处理均符合设计契约。
本 PR 保持为后端只读能力,前端目前没有增加用于调用该 API 的 UI;UI将会作为后续的处理,或者您可以修改为您想要的效果。