Skip to content

feat(build): 记录工作区信任,未信任时拒绝会运行项目代码的构建计划 - #118

Merged
1lck merged 3 commits into
mainfrom
feat/workspace-trust
Nov 19, 2026
Merged

1lck merged 3 commits into
mainfrom
feat/workspace-trust

Conversation

@1lck

@1lck 1lck commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

关联 Issue / Linked issue

PR 类型 / Type

  • feat

改动说明

打开项目时,构建插件会运行 Maven 等工具加载模型,pom 里的扩展和插件就是仓库代码。契约原先写着“Lithe 没有工作区信任状态,逐次征求同意”,但桌面端打开项目就加载模型,没有任何询问。本 PR 按 IntelliJ IDEA 社区版的做法(TrustedProjects.getProjectTrustedState、TrustedProjectsDialog.confirmOpeningOrLinkingUntrustedProject)补上信任状态,并由 Core 决定哪些计划需要信任。

信任状态(toolchains.catalogState / toolchains.editCatalog)

  • 本机工具链目录在原有的 trustedWorkspaces 之外,新增 distrustedWorkspaces(选了安全模式的工作区)和 trustedLocations(其下任意深度的工作区都受信任)。新字段只在用到时写入,没有这些决定的用户,旧宿主照常能读。
  • 判定顺序与 IDEA 一致:先看对工作区本身的决定,再看包含它的受信任位置。所以在受信任位置里,单独选择安全模式的项目仍保持安全模式。
  • 带非空 workspaceRoot 的 catalogState 返回 workspaceTrust: {state: trusted|distrusted|unknown, location, offeredLocation},projectCodeAllowed 等于 state == trusted。offeredLocation 是询问时可一并信任的上级目录;上级是文件系统根(/、盘符、UNC 共享)时为 null,避免一次信任整个卷。
  • editCatalog 的 workspaceTrust 增加 location。trusted: true 记为信任;trusted: false 改为记录安全模式,原先是从名单删除,对 projectCodeAllowed 的效果相同;location: true 同时信任上级目录。

计划按信任把关(build.*Plan)

  • 计划请求的公共字段新增 projectCodeAllowed(缺省为 false),runConfigurationPlan 和 beforeLaunchTaskPlan 的请求也加上它。
  • 工作区未受信任时,以下计划以新错误码 plugin.build.untrustedWorkspace 拒绝:所有任务、测试、运行配置、启动前任务、运行准备和调试准备(它们就是在运行项目);声明了 executesProjectCode: true 的模型或依赖命令;以及发给声明了该标记的构建提供者的请求。
  • 声明 executesProjectCode: false 的模型或依赖命令(例如 go list)不受信任限制;从已解码模型列出运行项、以及 build.decodeTestDiscovery 借测试计划检查选择器能否运行,都不返回计划,也不受限。
  • 实现集中在 PlanContext 的 plan_with_arguments 和 provider_plan 两个出口;provider_plan 改为返回 Validation。

契约与文档

  • 契约 README 新增 “Workspace trust” 一节,错误码表加入 plugin.build.untrustedWorkspace。原先三处“没有工作区信任状态”的说法(启动方式、插件页面、后端激活)改为指向该节。
  • rust-core-api.md 更新计划公共字段、两个运行类请求、catalogState 和 editCatalog;后端指南和 domains/backend.md 的中英文同步更新。
  • fixture:build-plans.json 的计划请求显式带上 projectCodeAllowed;Go 的模型计划改为 false,演示无需信任;新增两个拒绝用例。toolchain-global-catalog.json 新增“记录安全模式”和“受信任位置覆盖下层工作区”两个用例。

验证

  • cargo test -p lithe-build -p lithe-execution -p lithe-toolchain -p lithe-core -p lithe-plugin-manifest -p lithe-plugin-output-links -p lithe-plugin-marketplace -p lithe-plugin-web-content(affected-crates.mjs 列出的全部 crate)在 macOS ARM64 上全部通过。
  • 新增测试:
    • catalog::tests 三个:状态在“未决定 / 安全模式 / 信任”之间转换;受信任位置覆盖下层但不覆盖同名前缀的兄弟目录,显式安全模式优先;文件系统根不提供上级目录。macOS 和 Windows 路径各测一次。
    • provider_requests_that_run_project_code_need_a_trusted_workspace。
    • golden 中的两个拒绝用例。
  • cargo clippy -D warnings、cargo fmt --check、verify-rust-core-comments.sh build toolchain、verify-platform-tests.mjs、shared/plugins/scripts/verify-docs.mjs 都通过。
  • 没有修改插件后端协议,不需要运行 sdk-e2e.mjs。宿主须同时在计划请求里传入 projectCodeAllowed,配套桌面 PR 升级 PINNED_CORE_REVISION 后验收。

🤖 Generated with Claude Code

1lck and others added 2 commits November 19, 2026 03:20
… code in untrusted workspaces

The toolchain catalog records a decision on each workspace as IntelliJ IDEA
does: trusted, distrusted (kept in safe mode) or unknown, plus trusted
locations whose every workspace is trusted. catalogState reports the state,
the location that trusts the workspace and the parent folder a prompt may
offer; editCatalog records trust, safe mode, or trust with the parent folder.

Plan requests take projectCodeAllowed. Without it Core refuses with
plugin.build.untrustedWorkspace every task, test, run configuration,
before-launch task, run and debug preparation, a model or dependency command
declaring executesProjectCode, and a request to a provider declaring it.
Run entries from a decoded model and test discovery decoding need no trust.

The contract replaces "Lithe has no workspace trust state" with a Workspace
trust section and documents the new code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…quests

The SDK scenarios plan builds of their own fixture workspaces, which they
trust: models, tasks, tests and run preparations of the sample providers run
the workspace's code, so Core now refuses them without projectCodeAllowed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@1lck
1lck marked this pull request as ready for review November 19, 2026 12:05
@1lck
1lck merged commit 8c77c3f into main Nov 19, 2026
10 checks passed
1lck added a commit that referenced this pull request Nov 19, 2026
…changelog (#119)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
xiaoyumuxi added a commit that referenced this pull request Nov 20, 2026
toolchains.editCatalog 新增 trustedLocations: {add?, remove?},供没有打开工作区的设置页增删可信位置:按平台大小写身份匹配,删除不存在的位置不算修改,已存在的位置保留原有写法,工作区上的明确决定不受影响。添加文件系统根目录(/、盘符、UNC 共享)返回 plugin.toolchain.rootLocation;手写进文档的根目录位置在读取时被拒绝,工作区保持安全模式。信任列表超过 256 项改为返回 plugin.toolchain.trustListFull(含原来 workspaceTrust 的超限),宿主可以提示“列表已满”而不是“文档无效”。offered_location 改用 paths::is_root 判断根目录。schema 补上 #118 漏掉的 distrustedWorkspaces 和 trustedLocations。
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