Repository navigation
feat(toolchain): 可信位置可以单独添加和删除,拒绝把文件系统根目录设为可信位置(1lck/Lithe-IDEA#2207) - #144
Merged
Merged
Conversation
toolchains.editCatalog 新增 trustedLocations: {add?, remove?},供没有打开工作区的设置页增删可信位置:按平台大小写身份匹配,删除不存在的位置不算修改,已存在的位置保留原有写法,工作区上的明确决定不受影响。添加文件系统根目录(/、盘符、UNC 共享)返回 plugin.toolchain.rootLocation;手写进文档的根目录位置在读取时被拒绝,工作区保持安全模式。信任列表超过 256 项改为返回 plugin.toolchain.trustListFull(含原来 workspaceTrust 的超限),宿主可以提示“列表已满”而不是“文档无效”。offered_location 改用 paths::is_root 判断根目录。schema 补上 #118 漏掉的 distrustedWorkspaces 和 trustedLocations。
xiaoyumuxi
marked this pull request as ready for review
November 20, 2026 23:22
This was referenced Nov 21, 2026
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#2207(可信位置设置页)。它是 1lck/Lithe-IDEA#2231(远程开发完整设计)中工作区信任的前置项:#118 已让
trustedLocations参与信任判断,但没有任何命令能修改这个列表,用户只能手改toolchain-global.json。本 PR 补上 Core 侧的修改命令,桌面端设置页在后续 PR 中接入。类型
toolchains.editCatalog可以单独添加、删除可信位置;文件系统根目录不能成为可信位置改动说明
新增
trustedLocations修改(toolchain/src/catalog.rs)toolchains.editCatalog的请求新增trustedLocations: { add?: string[], remove?: string[] },可以不带edits和workspaceTrust单独使用。三者至少要有一个,否则仍是invalidDocument。\与/等价、尾部分隔符忽略,所以c:\code\能删掉文档里的C:/Code。删除不存在的位置、添加已有的位置都是无操作,不报错,changed照实返回。add和remove都为空、相对路径、含..的路径、未知字段都会被拒绝(invalidDocument,field指向trustedLocations或其下的add/remove)。workspaceTrust之后进行,不改动工具、默认 SDK、可信工作区和不信任工作区。文件系统根目录不能成为可信位置
paths::is_root:paths::normalize的输出只有根目录(/、C:/、//server/share/)保留结尾分隔符,以此判断。plugin.toolchain.rootLocation(field为trustedLocations.add)。信任一个根目录等于信任这台机器上的所有工作区,安全模式就失去意义了。catalogState/editCatalog都按invalidDocument(field为trustedLocations)拒绝整个文档。这样所有工作区都保持安全模式,不会因为一行手写配置被全部信任。远程信任将来也用同一条规则。offered_location(建议“信任父文件夹”时给出的路径)改为复用paths::is_root,原来的判断逻辑等价,只是写法更短。列表上限的错误码
plugin.toolchain.trustListFull:可信工作区、不信任工作区、可信位置任一列表修改后超过 256 项时返回,field为超限的列表名。workspaceTrust使可信工作区超过 256 项时返回invalidDocument(field为workspaceTrust)。这个码表示“文档或请求写错了”,而列表已满的处理方式(先删掉一些再加)不同,所以按错误码一一对应的规则单独给码。没有沿用limitExceeded:它是插件协议的 -32075,含义是插件回复超出预算。workspaceTrust分支移到所有修改之后统一做,所以一次修改中“删一项、加一项”在满表时也能通过。契约与文档
rust/contracts/rust-core-api.md:toolchains.editCatalog写明trustedLocations的语义、执行顺序和两个新错误码;toolchains.catalogState写明根目录在读取时被拒绝。rust/contracts/toolchain-global-v1.schema.json:补上 feat(build): 记录工作区信任,未信任时拒绝会运行项目代码的构建计划 #118 漏写的distrustedWorkspaces和trustedLocations(数组,最多 256 项,不重复,带说明)。原 schema 设置了additionalProperties: false,严格按 schema 校验会把 feat(build): 记录工作区信任,未信任时拒绝会运行项目代码的构建计划 #118 之后写出的合法文档判为无效。本 PR 不改插件契约、能力版本或插件函数协议,不需要更新协议更新记录,也不需要运行
sdk-e2e.mjs。测试
catalog.rs新增四个单元测试:trusted_locations_are_added_and_removed_on_their_own:macOS 和 Windows 分别验证规范化、按平台拼写匹配删除、无操作时changed为假,工具和不信任工作区不受影响。a_filesystem_root_is_never_added_or_read_as_a_location:/、Linux 的//、D:\、c:/、\\server\share、\\server\share\,单独添加和与合法文件夹一起添加都被拒绝;文档里手写的根目录在读取时被拒绝。a_trusted_locations_edit_must_name_one_meaning_per_folder:空修改、同时添加和删除同一文件夹、重复添加、相对路径、..、未知字段。a_trust_list_never_grows_past_its_bound:256 项再加一项返回trustListFull(field为trustedLocations);满表时一删一加可以通过;可信工作区已满时workspaceTrust返回trustListFull(field为trustedWorkspaces)。rust/fixtures/toolchain-global-catalog.json新增四个跨语言 fixture:不带工作区时添加并删除不存在的位置、Windows 按平台身份删除、Windows 添加D:\被拒、读取手写的/被拒。验证
scripts/rust-core/verify-rust-core-comments.shcargo fmt --all --checkcargo clippy -p lithe-toolchain -p lithe-core --all-targets -- -D warningscargo test -p lithe-toolchaincargo test -p lithe-core --lib toolchain(含 fixture 测试)未能执行的检查: Windows 本地没有运行;Windows 路径规则由单元测试里的
windows平台参数覆盖,改动不含cfg平台分支,依靠 CI。后续
桌面端在 1lck/Lithe-IDEA 新开 Draft:“构建、执行、部署 › 可信位置”设置页,通过本 PR 的
trustedLocations修改读写列表,并把rootLocation、trustListFull映射为界面文案。本 PR 合入后桌面端把PINNED_CORE_REVISION升到合入 commit。远程主机的可信位置(#2231 S04)在 R1 连接界面中接入。