Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

状态:已实现

> 2026-11-19 更新:打开项目时就识别构建系统并加载每个实例的模型,标题栏不再停在“当前文件”、等用户先点运行或打开下拉。见下文“模型加载后自动生成”。
>
> 2026-11-18 更新:用户层改存 `.lithe/run/configurations.yaml`、`local.yaml` 和按插件拆分的 `.lithe/run/plugin/<插件 ID>.toml`、`<插件 ID>.local.toml`;Core 不再写这些文件,编辑命令返回文件改动,由宿主按哈希检查后应用。内置的脚本与程序运行不经过生成层。决策见[脚本与程序运行由 Core 内置,运行配置存 YAML 和 TOML](2026-11-18-builtin-process-runs-and-run-file-formats.md)。
>
> 2026-11-16 更新:Core 删除了内置的运行发现探测器、项目内容指纹和工具链需求([Lithe-core-rust #77](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/77),#1856 第 4 项)。生成层现在只由构建插件声明的 `buildSystems[].run` 组成。原来的“跨会话缓存语言服务入口”和“识别前也能选 JDK”两节随之删除;分类与重名规则从已归档的 `.agents/notes/archived/feature/2026-09-20-run-configuration-discovery-quality.md` 并入本文,指纹相关的旧做法见已归档的 `.agents/notes/archived/bug-fix/2026-09-22-run-panel-fingerprint-loading.md`。
Expand Down Expand Up @@ -41,6 +43,10 @@ Core 按规范化后的工作区路径保存最近一次 `runConfig.generate`

`inspect` 在本进程还没生成过这个工作区时返回 `requiresGeneration: true`。保存过构建任务的工作区即使没有生成层也可以返回 `ready`,因此宿主不能只检查 `missing`:否则重启后只剩用户任务,自动入口不会恢复。桌面端在构建模型加载后生成(`desktop/internal/workbench/runconfig.go` 的 `refreshRunConfigurations`),不停在“请生成”的空状态。

模型在打开项目时就开始加载:`openProjectHere`(`desktop/internal/workbench/app.go`)调用 `loadTitleRunConfigs`,先识别构建系统,再加载每个识别到的实例的模型,因为标题栏要列出所有实例声明的运行,不只是构建窗口选中的那一个。以前只有按下标题栏的运行、打开运行配置下拉或打开构建窗口时才识别,用户打开 Spring Boot 工程后看到的是“当前文件”和空列表,以为启动类没被识别出来。

自动加载把执行时机提前了:命令来源的模型(如 Maven 的 `mvn`,清单标了 `executesProjectCode`)会在打开项目时运行,而 pom 里的扩展和插件就是仓库代码。此前构建窗口、测试窗口或运行菜单第一次出现时同样会运行它,构建窗口随布局恢复时也就是打开时,所以这不是新增的门槛缺口,但范围变大了。所以打开项目前先确认工作区信任:没有信任记录时先问,安全模式下不加载模型,Core 也会拒绝会运行项目代码的计划,见 [工作区信任与安全模式](../feature/2026-11-19-workspace-trust-and-safe-mode.md)。加载模型不写用户工程。

### 默认配置由 Core 选

`.lithe/project.json` 仍是用户可以编辑的团队文档,里面的默认运行配置优先。没有写默认值时,`resolve` 依次选择第一个声明为 service 的生成条目、第一个不是 Current File 的生成条目。宿主不实现这套挑选规则。
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Agent 笔记:工作区信任与安全模式对齐 IntelliJ IDEA

状态:已实现

## 先说结论

打开一个没有信任记录的文件夹前,桌面端先问“信任并打开项目?”,三个选择和 IntelliJ IDEA 一样:信任项目、以安全模式预览、不打开;可以勾选“信任父文件夹中的所有项目”。安全模式(Safe Mode,只浏览代码、不运行项目代码的打开方式)下不加载构建模型,运行、构建、测试和重新加载前都先问“信任项目?”,编辑器上方有“安全模式,功能受限”的提示条。信任记录是本机的,由 Core 存进偏好目录的工具链目录(`toolchains/global.json`),不写项目。

## 问题

Maven 这类命令来源的模型会运行 `mvn`,pom 里的扩展和插件就是仓库代码。打开项目时自动加载模型(见 [运行配置检测](../architecture/2026-10-29-run-configuration-detection-in-memory.md))以后,打开一个陌生仓库就会运行它的代码。原来唯一的门槛是工具链各层不选工作区里的程序(`mvnw`、`gradlew`),模型命令、运行、测试本身没有按信任把关,也没有任何界面告诉用户。

## 决策

- **三种状态由 Core 判定。** Core 的工具链目录记着信任过的工作区、明确不信任的工作区和信任的位置(父文件夹)。`toolchains.catalogState` 返回 `workspaceTrust`(`trusted`、`distrusted`、`unknown`,以及可以提供的父文件夹);显式决定优先于位置,和 IDEA 的 `TrustedPaths` 一致。根目录、盘符和网络共享根不作为可信位置提供。
- **Core 拒绝会运行项目代码的计划。** 计划请求带 `projectCodeAllowed`;为假时,命令模型(清单标了 `executesProjectCode`)、执行类提供者计划和声明了运行项目代码的提供者都会被拒绝,错误码 `plugin.build.untrustedWorkspace`。宿主只负责把项目当前的信任带进请求(`desktop/internal/workbench` 中 11 处请求都填 `p.trust.allowed()`),不自己判断哪些计划危险。
- **先问再打开。** `openProjectHere` 先读信任(`toolchain.ReadWorkspaceTrust`),再决定直接打开、以安全模式打开或提问;选“不打开”时当前项目原样保留,新开的项目页签直接关掉。“以安全模式预览”记成不信任,下次打开不再问,和 IDEA 的 `setProjectTrusted(false)` 相同。
- **安全模式下的动作先问。** `startRun`、`runBuildTask`、`startTests`、运行当前文件和重新加载模型前,安全模式会弹出“信任项目?/ 保持安全模式”。信任保存成功后才执行原动作;保存失败按未信任处理。自动加载的模型不运行,构建窗口在模型位置显示安全模式说明。
- **设置页和对话框是同一份记录。** 构建设置里撤销或授予工作区信任后,工作台重新读取信任并应用;离开安全模式时重新加载被跳过的模型和失败的语言服务器。

## 考虑过的备选方案

- **只靠工具链层不选 `mvnw`。** 被否:`mvn` 本身也会执行 pom 里的扩展,这道门槛挡不住模型命令和测试。
- **宿主按插件类型判断哪些动作危险。** 被否:危险与否取决于清单和计划类型,属于 Core 的计划逻辑;放在宿主会在每个平台重复一份并逐渐漂移。
- **打开后再问。** 被否:打开时就会恢复布局、加载模型,问之前代码可能已经运行;IDEA 也是先问再打开。
- **把信任写进项目的 `.lithe/`。** 被否:仓库可以自带“已信任”,等于没有门槛。

## 后果

- 测试 harness 默认把所有工作区当作信任(`Options.trustEveryWorkspace`,相当于 IDEA 单元测试模式关闭信任检查);测试信任流程的用例要显式关掉。
- 语言服务器和 Git 在安全模式下仍照常启动(#2208),可信位置也还没有独立的设置页(#2207)。
- 通过 IDE API 发起的构建任务在安全模式下会被拒绝,同时提示用户信任。

## 验证

- `desktop/internal/workbench/workspace_trust_test.go`:信任后打开并记住、勾选父文件夹后同级项目也被信任、不打开不留下任何状态、安全模式不加载模型且动作先问、提示条信任后消失。
- Core 的 `rust/crates/toolchain` 和 `rust/crates/build` 测试,以及 `build-plans.json`、`toolchain-global-catalog.json` 两份 fixture 覆盖状态判定和计划拒绝。

```bash
scripts/desktop/desktop-go.sh test ./internal/workbench/ -run 'TestTrusting|TestDontOpen|TestSafeMode'
```

## 适用范围

所有会运行项目代码的桌面端动作:加载构建模型、运行、调试、构建任务、测试、运行前任务。新增这类动作时,请求里必须带 `ProjectCodeAllowed`,用户触发的入口要先经过 `requireProjectTrust` 或 `askToTrustProject`。
5 changes: 3 additions & 2 deletions desktop/internal/buildprovider/buildprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ func TestProviderModelTaskAndCancellation(t *testing.T) {
t.Fatalf("model = %+v", model)
}

taskPlan, err := client.PlanBuildTask(ctx, validated, "fixture", core.BuildPlanRequest{Root: ".", WorkspaceRoot: workspace, Task: "build"})
// A provider task runs the workspace's build, which the workspace's trust allows.
taskPlan, err := client.PlanBuildTask(ctx, validated, "fixture", core.BuildPlanRequest{Root: ".", WorkspaceRoot: workspace, Task: "build", ProjectCodeAllowed: true})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -288,7 +289,7 @@ func TestProviderModelTaskAndCancellation(t *testing.T) {
t.Fatalf("execution = %+v", execution)
}

slowPlan, err := client.PlanBuildTask(ctx, validated, "fixture", core.BuildPlanRequest{Root: ".", WorkspaceRoot: workspace, Task: "slow"})
slowPlan, err := client.PlanBuildTask(ctx, validated, "fixture", core.BuildPlanRequest{Root: ".", WorkspaceRoot: workspace, Task: "slow", ProjectCodeAllowed: true})
if err != nil {
t.Fatal(err)
}
Expand Down
11 changes: 11 additions & 0 deletions desktop/internal/core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,15 @@ type BuildPlanRequest struct {
LaunchOptions *RunLaunchOptions `json:"launchOptions,omitempty"`
// File is the workspace-relative source file build.runEntrypointsPlan asks about.
File string `json:"file,omitempty"`
// ProjectCodeAllowed is the workspace's trust; without it Core refuses a plan that runs
// project code with BuildUntrustedWorkspace.
ProjectCodeAllowed bool `json:"projectCodeAllowed,omitempty"`
}

// BuildUntrustedWorkspace is the code Core refuses a plan with when it would run project
// code in a workspace the user has not trusted.
const BuildUntrustedWorkspace = "plugin.build.untrustedWorkspace"

// BuildProviderRequest is the typed request a provider-backed plan names.
type BuildProviderRequest struct {
Method string `json:"method"`
Expand Down Expand Up @@ -459,6 +466,8 @@ type RunConfigurationPlanRequest struct {
Instances []RunTypeInstance `json:"instances"`
PluginDirectory string `json:"pluginDirectory,omitempty"`
WorkspaceStateDirectory string `json:"workspaceStateDirectory,omitempty"`
// ProjectCodeAllowed is the workspace's trust, as in BuildPlanRequest.
ProjectCodeAllowed bool `json:"projectCodeAllowed,omitempty"`
}

// PlanRunConfiguration plans a saved configuration of a plugin-declared run kind
Expand Down Expand Up @@ -493,6 +502,8 @@ type BeforeLaunchTaskPlanRequest struct {
Instances []RunTypeInstance `json:"instances"`
PluginDirectory string `json:"pluginDirectory,omitempty"`
WorkspaceStateDirectory string `json:"workspaceStateDirectory,omitempty"`
// ProjectCodeAllowed is the workspace's trust, as in BuildPlanRequest.
ProjectCodeAllowed bool `json:"projectCodeAllowed,omitempty"`
}

// PlanBeforeLaunchTask plans a task step of a Before Launch list
Expand Down
2 changes: 2 additions & 0 deletions desktop/internal/core/build_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ func TestBuildOptionDefaultsAndExclusionsRoundTripThroughStorageAndTree(t *testi
Root: ".",
Task: "compile",
Options: map[string]json.RawMessage{"profiles": states.Options[0].Value},
// The task runs the build tool on the workspace, which needs its trust.
ProjectCodeAllowed: true,
})
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 2 additions & 0 deletions desktop/internal/core/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func TestBuildTaskPlanCarriesProviderParams(t *testing.T) {
Task: "build",
UserArguments: []string{"--warning-mode", "all"},
Options: map[string]json.RawMessage{"offline": json.RawMessage("true")},
// The task runs the build tool on the workspace, which needs its trust.
ProjectCodeAllowed: true,
})
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 2 additions & 0 deletions desktop/internal/core/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type BuildTestRequest struct {
Case string `json:"case,omitempty"`
UserArguments []string `json:"userArguments,omitempty"`
Projects []string `json:"projects,omitempty"`
// ProjectCodeAllowed is the workspace's trust, as in BuildPlanRequest.
ProjectCodeAllowed bool `json:"projectCodeAllowed,omitempty"`
}

// BuildTestResultsRequest asks Core to normalize the results of one test run.
Expand Down
3 changes: 2 additions & 1 deletion desktop/internal/core/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ func TestBuildTestPlanDecodesReportsAndResolvesOutcome(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

// Running the tests runs the workspace's code, which needs its trust.
plan, err := client.PlanBuildTest(ctx, testsManifest(t), "fixture-tests", BuildTestRequest{
Root: ".", WorkspaceRoot: root,
Root: ".", WorkspaceRoot: root, ProjectCodeAllowed: true,
})
if err != nil {
t.Fatalf("PlanBuildTest: %v", err)
Expand Down
24 changes: 23 additions & 1 deletion desktop/internal/core/toolchain_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ type ToolchainCatalogEntry struct {
type ToolchainCatalogState struct {
Document ToolchainCatalog `json:"document"`
ProjectCodeAllowed bool `json:"projectCodeAllowed,omitempty"`
Storage struct {
// WorkspaceTrust is the trust of the requested workspace root; nil without one.
WorkspaceTrust *ToolchainWorkspaceTrust `json:"workspaceTrust,omitempty"`
Storage struct {
RelativePath string `json:"relativePath"`
MaximumBytes int64 `json:"maximumBytes"`
} `json:"storage"`
Expand All @@ -31,9 +33,29 @@ type ToolchainCatalogEdit struct {
DefaultHome *string `json:"defaultHome"`
}

// ToolchainWorkspaceTrustEdit records one decision on a workspace: Trusted lets its project code
// run and false keeps it in safe mode; Location also trusts its offered parent folder.
type ToolchainWorkspaceTrustEdit struct {
Workspace string `json:"workspace"`
Trusted bool `json:"trusted"`
Location bool `json:"location,omitempty"`
}

// Workspace trust states Core reports.
const (
WorkspaceTrusted = "trusted"
WorkspaceDistrusted = "distrusted"
WorkspaceTrustUnset = "unknown"
)

// ToolchainWorkspaceTrust is a workspace's trust as Core decides it from the machine-local
// catalog: State is WorkspaceTrusted, WorkspaceDistrusted (kept in safe mode) or
// WorkspaceTrustUnset (never asked). Location is the trusted folder that trusts it, and
// OfferedLocation the parent folder a trust prompt may offer; nil when there is none.
type ToolchainWorkspaceTrust struct {
State string `json:"state"`
Location *string `json:"location"`
OfferedLocation *string `json:"offeredLocation"`
}

type ToolchainCatalogPublication struct {
Expand Down
26 changes: 26 additions & 0 deletions desktop/internal/i18n/shared.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading