Skip to content

feat: 支持从 WSL 发行版读取 Pi 配置文档 - #6

Merged
Wing900 merged 1 commit into
Wing900:masterfrom
onedotmint:feat/wsl-pi-config-read
Aug 23, 2026
Merged

feat: 支持从 WSL 发行版读取 Pi 配置文档#6
Wing900 merged 1 commit into
Wing900:masterfrom
onedotmint:feat/wsl-pi-config-read

Conversation

@onedotmint

Copy link
Copy Markdown
Contributor

概述

本 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将会作为后续的处理,或者您可以修改为您想要的效果。

@Wing900

Wing900 commented Aug 22, 2026

Copy link
Copy Markdown
Owner

Got it and reviewing!(

@Wing900 Wing900 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Wing900
Wing900 merged commit bc98e28 into Wing900:master Aug 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants