Skip to content

feat(toolchain): 支持项目内工具环境解释器链接链校验与本机信任存储 - #93

Merged
Mucheen merged 4 commits into
mainfrom
feat/2122-venv-toolchain
Nov 18, 2026
Merged

Mucheen merged 4 commits into
mainfrom
feat/2122-venv-toolchain

Conversation

@Mucheen

@Mucheen Mucheen commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

关联 Issue / Linked issue

PR 类型 / Type

  • feat:新功能或用户可见的改进
  • fix:缺陷修复
  • docs:文档、Agent Note、Skill 等规则文件
  • release:稳定版发布准备

改动说明 / What changes

背景 / Why

在 Unix(macOS / Linux)上,.venv、venv 等项目虚拟环境中的解释器入口(如 .venv/bin/python)通常是指向系统或包管理器基础解释器的单跳或多跳符号链接。此前 Core 的 project_selection(rust/crates/toolchain/src/resolution/project.rs)只要遇到 canonicalPath != path 就一律返回 unsafePath,导致项目内虚拟环境无法被工具链四层选择解析;同时 toolchains.discoveryPlan、toolchains.candidates 和 toolchains.resolve 尚未把平台过滤后的项目内 projectFile 候选声明及校验状态结构化暴露给宿主,本机全局目录 toolchains/global.json 也缺少规范化的工作区信任列表,且 toolchains/README.md 与 capabilities-and-versions.md 仍残留多处已过时的平台与宿主能力描述。

改动 / Changes

  • 项目内环境解释器符号链接链校验与字面路径保留(通用规则,无语言特判)
    • rust/crates/toolchain/src/resolution/project.rs:
      • projectCodeAllowed != true 时,所有 projectFile 候选严格返回 projectCodeRequiresAction,且在 candidates.project 与 resolve.projectCandidates 中不发出 executable 探针目标,确保宿主绝不对未信任工作区代码运行版本探针。
      • 对 projectKind == "environment"(声明了 home,如 .venv):环境根目录 home、从 home 到叶子可执行文件之间的全部中间父目录(如 .venv/bin、.venv/Scripts;缺失事实或软链逃逸均按 unsafePath 失败关闭)、环境内 requires 标记文件以及实际存在的 pathPrepend 目录,其 canonicalPath 均必须留在工作区根与 home 目录之内;叶子可执行文件 path 允许是常规可执行文件或指向工作区内/工作区外常规可执行文件的单跳或多跳符号链接(宿主事实证实 path 与最终 canonicalPath 均为 file 且 executable: true),在探测前先校验 exports 与 pathPrepend,探测与最终 selection.executable(及 ${executable} 导出)严格保留字面路径 path(如 <root>/.venv/bin/python),使虚拟环境保有自身的 pyvenv.cfg / sys.prefix。
      • 对 projectKind == "wrapper"(无 home):允许工作区根之内的符号链接并保留字面路径,指向工作区根之外的软链仍拒绝为 unsafePath;仅在调用方要求 minimumVersion 时强制版本探针。
    • rust/crates/toolchain/src/resolution/snapshot.rs:
      • environment_selection 处理跨平台 pathPrepend(如同时声明 ${home}/bin 与 ${home}/Scripts)时,跳过宿主已显式观测为 kind: "missing" 的目录;未观测到事实或软链逃逸 home 的目录仍按 unsafePath 失败关闭。
      • output 新增 projectCandidates 字段。
  • 宿主发现计划、候选列表与解析输出对齐
    • rust/crates/toolchain/src/resolution/discovery.rs:toolchains.discoveryPlan 的每个工具新增按目标 platform 过滤后的 projectFiles: [{ id?, projectKind, path, home?, requires }],宿主无需重复解析插件清单即可沿祖先链观测目录、标记文件与可执行入口。
    • rust/crates/toolchain/src/resolution/automatic.rs:toolchains.candidates 返回新增根级 project: [{ candidateID, projectKind, path, home?, executable?, version?, reason? }](global: true 时为空数组,不混入外部安装列表 installations)。
    • rust/crates/toolchain/src/resolution.rs:toolchains.resolve 返回新增最近声明层的 projectCandidates;当所有层均跳过且无选中结果时,outcome.reason 保留最高优先级候选的跳过原因(如 projectCodeRequiresAction、unsafePath、notExecutable、probeFailed),仅在各层均为空时返回 notFound。
  • 本机工作区信任存储(绝不写入工作区 .lithe/)
    • rust/crates/toolchain/src/catalog.rs、rust/contracts/toolchain-global-v1.schema.json、rust/fixtures/toolchain-global-catalog.json:
      • toolchains/global.json 新增可选 trustedWorkspaces(最多 256 个规范化绝对路径,按目标平台分隔符与大小写策略去重排序,空列表省略以保持旧文档格式兼容)。
      • toolchains.catalogState 支持可选 workspaceRoot 参数并返回 projectCodeAllowed: bool(不传 workspaceRoot 时省略该字段以兼容既有调用)。
      • toolchains.editCatalog 支持可选 workspaceTrust: { workspace, trusted } 原子增删工作区信任,与 SDK tools 注册互不覆盖;缺省文档上撤销信任返回 changed: false, document: null 且不落盘空文件。
  • 契约、参考文档与过时说明修复
    • rust/contracts/rust-core-api.md:同步更新 toolchains.catalogState、editCatalog、discoveryPlan、candidates、resolve 的契约说明。
    • shared/plugins/contract/v1/toolchains/README.md:补齐项目环境符号链接链校验、projectFiles、candidates.project、resolve.projectCandidates 与 pathPrepend 规则,并修正开头“Windows has no toolchain adapter and does not advertise toolDefinitions”等过时表述。
    • shared/plugins/reference/domains/toolchains.md:中英文同步更新选择顺序、Core 命令表、本机文档说明与桌面端现状(commandInstallers 已声明、语言服务器 {kind: "tool"} 已接通工具链解析、pin 保存已实现)。
    • shared/plugins/reference/capabilities-and-versions.md:中英文同步将指向已停用 preview 分支的 pluginhost.go 链接改为 main,将 commandInstallers、vcsProviders、sourceSettings(0/1)、litheVcs 更新为桌面端已声明状态,并按 desktop/internal/pluginhost/pluginhost.go 的 Declared() 注释更新脚注¹中语言服务器、系统命令、构建提供者与 VCS 提供者的未呈现范围说明。
    • shared/plugins/reference/protocol-changelog.md:登记本次 toolDefinitions 0 内补充说明,并将指向 preview 分支的计划文档链接更新为 main。
  • 跨平台单测与合成插件回归测试
    • rust/crates/toolchain/src/catalog.rs、rust/crates/core/src/tests/toolchain_resolution.rs:覆盖 Unix(macos、linux)与 Windows(windows)下的单跳/多跳外部软链 .venv、Windows 复制式与软链式 .venv\Scripts\...、.venv 根目录软链逃逸被拒、bin/Scripts 中间父目录软链逃逸或漏观测被拒、requires 标记软链逃逸被拒、pathPrepend 软链逃逸探测前被拒、目标不可执行被拒、projectCodeAllowed: false 拦截与授权后字面路径/exports/pathPrepend 保留,以及纯内联合成插件 dev.lithe.test.runtime-support 全链路测试。

不在本 PR 范围内 / Out of scope

  • 桌面端宿主工作区项目工具链观测、本机信任开关 UI、i18n 与日志接线(在 1lck/Lithe-IDEA 仓库配套 PR 中实现,关联 1lck/Lithe-IDEA#2122)。
  • 桌面端 LSP code actions / signature help / inlay hints 编辑器呈现(已建宿主跟进单 1lck/Lithe-IDEA#2128)。
  • Python 插件 io.github.lithe-idea.python-support 本体(在独立插件仓库 Lithe-IDEA/lithe-plugin-python 维护)。

类型专属:feat

多平台对齐

Lithe 的目标是 macOS 与 Windows 能力对齐。必须选下面一项:

  • 两端都具备:合入后 macOS 与 Windows 都具备该能力(本 PR 同时实现,或本 PR 补齐另一端)
  • 只实现了 macOS:已为 Windows 提交跟进 Issue:#
  • 只实现了 Windows:已为 macOS 提交跟进 Issue:#
  • 刻意只属于某个平台(功能矩阵中另一端记为 platform-specific),理由:

范围检查 / Scope checks

功能矩阵 / Feature matrix

N/A:本仓库为 Lithe-core-rust,跨平台功能矩阵位于宿主仓库 1lck/Lithe-IDEA 并在对应桌面端 PR 中同步更新。

插件归属 / Plugin ownership

  • 已在仓库根目录运行 develop-lithe 第三节“插件归属与宿主零依赖”的自查,本次改动零具体插件依赖
  • 新增或修改的测试只使用测试内联的合成插件(dev.lithe.test.*)和 Core 契约 fixture(dev.lithe.fixture.*);没有读取具体插件的插件包、仓库检出、构建产物或清单,没有使用真实插件 ID,没有“缺少插件时跳过”的测试
  • [N/A] 没有为具体插件提供的能力新建或更新宿主功能矩阵条目:本仓库不维护宿主功能矩阵
  • 插件文案与具体插件的构建步骤、资源路径和补丁没有进入本仓库
  • 修改了通用扩展点、可能影响已发布插件的,已结合桌面端与合成/真实工具定义回归验证向后兼容(新增请求参数均为可选字段,既有调用行为保持不变)

UI 验证 / UI evidence

N/A:纯 Rust Core 策略、契约与文档改动,不包含界面视图代码(桌面端 UI 无头截图在配套桌面端 PR 提供)。

统一日志系统 / Structured logging

N/A:纯确定性 JSON 策略计算模块(无 I/O、无进程生命周期或新增日志目录事件);node scripts/logging/generate-log-events.mjs --check 校验通过。

界面文案 / i18n

N/A:Core 仅返回稳定结构化状态码(如 projectCodeRequiresAction、unsafePath、notExecutable、probeFailed),不包含宿主界面文案。

逻辑归属 / Logic placement

  • 可共享的逻辑(项目环境链接链与目录边界校验、路径规范化与大小写去重、工作区信任合并、候选状态投影)全部在 Rust Core 实现,并同步更新契约 schema 与 fixture;平台层只做原生文件系统观测、受限探针执行与呈现
  • [N/A] 修改平台层已有的可共享逻辑时已迁入 Core:本 PR 仅修改 Rust Core 仓库
  • 工具或运行时专属的知识放在插件声明,Core 不按工具名或语言名分支

性能与内存 / Performance and memory

N/A:无常驻后台任务、子进程、轮询或无界缓存;trustedWorkspaces(上限 256)、filesystem 事实与祖先链(上限 64)均有显式常数上界。

设置 / Settings

N/A:本 PR 提供 toolchains.catalogState / editCatalog 与 candidates / resolve 底层契约数据,设置页 UI 交互在桌面端仓库实现。

插件契约 / Plugin contract

  • 契约改动已在 Rust Core PR 里随执行它的代码一起提交,同一个 Core PR 已登记插件协议更新记录(shared/plugins/reference/protocol-changelog.md)
  • [N/A] scripts/desktop/build-desktop-core.sh 的 PINNED_CORE_REVISION 升级在桌面端仓库 PR 合入本 PR 后执行
  • [N/A] 未修改插件后端 JSON-RPC 协议
  • [N/A] 未新增或修改插件后端可调用的 lithe/host/* 宿主方法或通知

发行包与资源 / Bundle and resources

N/A:Core 不执行任何文件写入;toolchains/global.json 仍位于宿主平台用户偏好存储目录(toolchains/global.json),不写入已安装应用包或工作区 .lithe/。

无用代码与重构 / Dead code and refactoring

  • 本次改动导致变成无用的代码已在本 PR 删除(resolution.rs 内联项目候选收集逻辑已合并至 project::collect_project_file_choices)
  • [N/A] 本次改动涉及模块未发现既有无用代码

验证 / Verification

命令或操作 平台 结果
node shared/plugins/scripts/verify-docs.mjs macOS (arm64) 通过
./scripts/rust-core/verify-rust-core-comments.sh toolchain core macOS (arm64) 通过
node scripts/rust-core/verify-platform-tests.mjs macOS (arm64) 通过(52 crates)
node --test scripts/rust-core/*.test.mjs macOS (arm64) 通过(16/16)
cargo fmt --manifest-path rust/Cargo.toml --all -- --check macOS (arm64) 通过
cargo clippy --manifest-path rust/Cargo.toml -p lithe-toolchain -p lithe-core -p lithe-execution -p lithe-plugin-manifest -p lithe-plugin-output-links --all-targets --all-features -- -D warnings macOS (arm64) 通过(0 warnings)
cargo clippy --manifest-path rust/Cargo.toml -p lithe-toolchain --all-targets --target x86_64-pc-windows-msvc -- -D warnings macOS → Windows MSVC target 通过(0 warnings)
cargo test --manifest-path rust/Cargo.toml -p lithe-toolchain -p lithe-core -p lithe-execution -p lithe-plugin-manifest -p lithe-plugin-output-links macOS (arm64),覆盖 Platform::Unix 与 Platform::Windows 规则向量 通过(913 passed, 0 failed)

未能执行的检查和原因:

  • Windows 真机上的 lithe-platform / lithe-platform-tests 原生测试未在本机直接执行(本次改动位于平台参数化的纯数据校验模块 lithe-toolchain,不涉及 #[cfg(windows)] 系统调用,已在同一测试套件内同时覆盖 macos、linux、windows 三套路径/大小写规则并通过 x86_64-pc-windows-msvc 目标 clippy 检查)。

提交前确认 / Final checks

  • 分支从最新的 main 创建;目标分支:main
  • 以 Draft 提交,本地验证通过后才标记 ready
  • 没有无关改动,没有提交 .build/、target/、dist/、.artifacts/ 等产物,没有凭据、个人路径和未脱敏的日志或截图
  • 本次构建、测试未启动任何常驻应用实例,已确认没有进程残留

- project.rs/snapshot.rs:projectCodeAllowed != true 保持返回 projectCodeRequiresAction 且不暴露探针目标;projectKind == "environment" 要求 home、中间父目录、环境内 requires 标记与存在的 pathPrepend 目录留在工作区和 home 内,允许叶子可执行文件经单跳或多跳软链指向外部常规可执行文件并保留字面 executable 路径;wrapper 仍要求链接目标留在工作区根内;pathPrepend 记为 missing 的跨平台目录安全跳过
- discovery.rs/automatic.rs/resolution.rs:discoveryPlan 新增平台过滤后的 projectFiles,candidates 新增根级 project 候选,resolve 新增 projectCandidates 并在全部候选跳过时保留最高层跳过原因
- catalog.rs:toolchains/global.json 新增规范化与去重的 trustedWorkspaces,支持通过 catalogState 查询 projectCodeAllowed、通过 editCatalog 的 workspaceTrust 原子变更工作区信任
- 更新契约、schema、fixture、协议更新记录,并修正 toolchains/README.md 与 capabilities-and-versions.md 的过时宿主能力说明

Refs 1lck/Lithe-IDEA#2122
按目录组件判定最近声明,并在解析无结果时保留首个失败原因。
跳过无法表示的可选项目路径,避免它阻断有效的固定选择。
补齐合成事实回归并同步工具链接口说明。
@Mucheen
Mucheen merged commit e56dbb6 into main Nov 18, 2026
12 of 14 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.

1 participant