From 4ca88a7cdfdcef8ff7d2a1182e5e42742874a69f Mon Sep 17 00:00:00 2001 From: lick <2188718831@qq.com> Date: Thu, 19 Nov 2026 01:47:43 -0800 Subject: [PATCH 1/5] =?UTF-8?q?fix(run):=20=E6=89=93=E5=BC=80=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=97=B6=E5=B0=B1=E8=AF=86=E5=88=AB=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=EF=BC=8C=E6=A0=87=E9=A2=98=E6=A0=8F=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=88=97=E5=87=BA=E5=90=AF=E5=8A=A8=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 打开项目后只启动了语言服务器,构建系统识别和模型加载要等用户按下标题栏的 运行、打开运行配置下拉或构建窗口才开始。装了 Maven 插件的 Spring Boot 工程 因此一直显示“当前文件”和空列表,看起来像启动类没有被识别。 openProjectHere 现在调用 loadTitleRunConfigs:识别构建系统并加载每个实例的 模型,插件声明的运行生成后由 Core 选出默认项显示在标题栏。构建工具仍经工具链 各层解析,工作区未被信任时不会选中 mvnw 这类仓库里的程序;加载模型不写工程。 测试:新增 TestOpeningAProjectListsItsDeclaredRuns(合成 provider 插件,修复前 超时失败);原先在“打开后尚未识别”的前提下手工注入构建状态的测试改为通过 setDetected 替换打开时的识别结果,并用 awaitRunConfigsAfter 等待自己触发的那一轮 读取;插件设置作废未选中实例的模型后,现在会为标题栏重新加载它。 Refs #2074 Co-Authored-By: Claude Opus 5.5 --- ...9-run-configuration-detection-in-memory.md | 6 +++ desktop/internal/workbench/app.go | 5 +++ desktop/internal/workbench/app_test.go | 19 ++++++++ .../build_connection_debug_visual_test.go | 6 +-- .../internal/workbench/build_menus_test.go | 2 +- desktop/internal/workbench/build_test.go | 1 + desktop/internal/workbench/build_tree_test.go | 3 +- .../workbench/runconfig_browser_test.go | 5 ++- .../internal/workbench/runconfig_edit_test.go | 5 ++- desktop/internal/workbench/runconfig_test.go | 5 ++- .../workbench/settings_plugin_effects_test.go | 8 +++- .../internal/workbench/tests_provider_test.go | 43 +++++++++++++++---- .../workbench/title_run_empty_visual_test.go | 7 ++- desktop/internal/workbench/title_run_test.go | 18 ++++---- .../features/run-discovery.json | 2 +- 15 files changed, 100 insertions(+), 35 deletions(-) diff --git a/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md b/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md index 6af1f05b7e..c917873925 100644 --- a/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md +++ b/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md @@ -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`。 @@ -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 工程后看到的是“当前文件”和空列表,以为启动类没被识别出来。 + +自动加载不放宽执行仓库代码的限制:加载模型时构建工具经工具链各层解析,工作区还没被信任时,`mvnw`、`gradlew` 这类工作区里的程序不会被选中,和用户手动触发时是同一道门槛。加载模型也不写用户工程。 + ### 默认配置由 Core 选 `.lithe/project.json` 仍是用户可以编辑的团队文档,里面的默认运行配置优先。没有写默认值时,`resolve` 依次选择第一个声明为 service 的生成条目、第一个不是 Current File 的生成条目。宿主不实现这套挑选规则。 diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 5c60b237c0..043a221dc5 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -1526,6 +1526,11 @@ func (a *App) openProjectHere(path string) { a.startGitObservation(p) a.loadLog(p) a.activatePluginWorkspace(p) + // The title bar lists the runs the build plugins declare as soon as the project opens, + // so its application is found without a press on Run or on the run menu first. Loading + // a model resolves the build tool through the toolchain layers, which leave out + // workspace programs such as a wrapper until the user trusts the workspace. + a.loadTitleRunConfigs(p) a.restoreEditorSession(p) a.restoreCheckpoints(p) a.openPendingFiles(p) diff --git a/desktop/internal/workbench/app_test.go b/desktop/internal/workbench/app_test.go index 00af7b707b..639239d2fd 100644 --- a/desktop/internal/workbench/app_test.go +++ b/desktop/internal/workbench/app_test.go @@ -187,6 +187,25 @@ func (h *harness) open(dir string) { h.settle() } +// setDetected gives p the instances a finished detection reports. Opening a project already +// detects its build systems, which ends with the plugins unavailable in a harness without a +// plugin service; a test that supplies its own instances replaces that answer. It runs on the +// window thread. +func setDetected(p *project, instances []buildInstance) { + p.build.instances, p.build.loaded, p.build.loading = instances, true, false + p.build.failed, p.build.status = "", "" +} + +// awaitRunConfigsAfter waits until Core resolved p's configurations again after the read +// numbered since, so the read a test asked for is the one it checks: opening the project +// already read them once. +func awaitRunConfigsAfter(t *testing.T, h *harness, p *project, since uint64) { + t.Helper() + awaitStateWithin(t, h, 10*time.Second, "the run configurations", func() bool { + return p.runConfigs.generation > since && !p.runConfigs.loading + }) +} + // shows reports whether a label in the current frame contains value. func (h *harness) shows(value string) bool { for _, label := range h.driver.Snapshot().Labels { diff --git a/desktop/internal/workbench/build_connection_debug_visual_test.go b/desktop/internal/workbench/build_connection_debug_visual_test.go index 75868ac3e1..9f9cd8fb04 100644 --- a/desktop/internal/workbench/build_connection_debug_visual_test.go +++ b/desktop/internal/workbench/build_connection_debug_visual_test.go @@ -51,16 +51,16 @@ func TestVisualServiceDebugWithoutAnAdapter(t *testing.T) { }) h.open(runConfigRoot(t)) p := h.app.project + since := p.runConfigs.generation h.app.post(func(a *App) { instance := runConfigInstance("app") instance.System.Runs = []pluginservice.BuildRunDeclaration{{ ID: "service", Name: "Serve", Execution: "service", Tags: []string{"app"}, DebugConfigurationType: "fixture-attach", }} - p.build.loaded = true - p.build.instances = []buildInstance{instance} + setDetected(p, []buildInstance{instance}) a.refreshRunConfigurations(p) }) - awaitStateWithin(t, h, 10*time.Second, "the run configurations", func() bool { return p.runConfigs.generation > 0 && !p.runConfigs.loading }) + awaitRunConfigsAfter(t, h, p, since) language := h.app.language() want := i18n.SharedFormat(language, "desktop.build.noConnectionDebugAdapter", map[string]string{"type": "fixture-attach"}) h.app.post(func(a *App) { a.titleDebug(p) }) diff --git a/desktop/internal/workbench/build_menus_test.go b/desktop/internal/workbench/build_menus_test.go index cbf29cf74b..1c0ff49033 100644 --- a/desktop/internal/workbench/build_menus_test.go +++ b/desktop/internal/workbench/build_menus_test.go @@ -31,7 +31,7 @@ func TestBuildRowMenusRunTargetsAndOpenTheBuildFile(t *testing.T) { instance := runConfigInstance("app") instance.Manifest = buildTestManifest(&instance) h.app.post(func(a *App) { - p.build.instances, p.build.loaded = []buildInstance{instance}, true + setDetected(p, []buildInstance{instance}) // Every node opens, so the target shows in its project's Targets folder. p.setAllBuildGroups(true) a.reduceChrome(core.ToggleChrome(itemBuild)) diff --git a/desktop/internal/workbench/build_test.go b/desktop/internal/workbench/build_test.go index 69d6be5352..796fd35cbf 100644 --- a/desktop/internal/workbench/build_test.go +++ b/desktop/internal/workbench/build_test.go @@ -99,6 +99,7 @@ func TestBuildLoadKeepsWorkingWhenDetectionReportsAnInvalidManifest(t *testing.T h := newHarness(t, &testKernel{Client: core.NewClient()}) h.open(t.TempDir()) p := h.app.project + setDetected(p, nil) p.build.loading = true h.app.finishBuildDetection(p, p.build.generation, []buildInstance{{BuildInstance: instance}}, context.Canceled) if p.build.failed != "" { diff --git a/desktop/internal/workbench/build_tree_test.go b/desktop/internal/workbench/build_tree_test.go index 97de943ee1..66b8e1907f 100644 --- a/desktop/internal/workbench/build_tree_test.go +++ b/desktop/internal/workbench/build_tree_test.go @@ -238,7 +238,8 @@ func openBuildTree(t *testing.T, kernel Kernel, instances []buildInstance) (*har h.open(t.TempDir()) p := h.app.project h.app.post(func(a *App) { - p.build.instances, p.build.loaded, p.build.selected = instances, true, 0 + setDetected(p, instances) + p.build.selected = 0 }) h.settle() return h, p diff --git a/desktop/internal/workbench/runconfig_browser_test.go b/desktop/internal/workbench/runconfig_browser_test.go index 3adc09b0da..ec72f06e6b 100644 --- a/desktop/internal/workbench/runconfig_browser_test.go +++ b/desktop/internal/workbench/runconfig_browser_test.go @@ -45,8 +45,9 @@ func TestRunConfigurationListScopesGroupsPinsAndRuns(t *testing.T) { if err := h.driver.Resize(1280, 1200); err != nil { t.Fatal(err) } + since := p.runConfigs.generation h.app.post(func(a *App) { - p.build.instances, p.build.loaded = runBrowserInstances(), true + setDetected(p, runBrowserInstances()) a.refreshRunConfigurations(p) if !a.chrome.isOpen(catalogIndex[itemBuild]) { a.reduceChrome(core.SetChromeOpen(itemBuild, true)) @@ -54,7 +55,7 @@ func TestRunConfigurationListScopesGroupsPinsAndRuns(t *testing.T) { }) s := &p.runConfigs b := &s.browser - awaitStateWithin(t, h, 10*time.Second, "the run configurations", func() bool { return s.generation > 0 && !s.loading }) + awaitRunConfigsAfter(t, h, p, since) h.settle() if s.failure != "" || len(s.list) != 3 { t.Fatalf("configurations = %+v, failure %q", s.list, s.failure) diff --git a/desktop/internal/workbench/runconfig_edit_test.go b/desktop/internal/workbench/runconfig_edit_test.go index 966f250ce9..4ac9b3c62e 100644 --- a/desktop/internal/workbench/runconfig_edit_test.go +++ b/desktop/internal/workbench/runconfig_edit_test.go @@ -25,11 +25,12 @@ func loadedRunConfigs(t *testing.T, kernel Kernel, root string) (*harness, *proj h := newHarness(t, kernel) h.open(root) p := h.app.project + since := p.runConfigs.generation h.app.post(func(a *App) { - p.build.instances = []buildInstance{runConfigInstance("app")} + setDetected(p, []buildInstance{runConfigInstance("app")}) a.refreshRunConfigurations(p) }) - awaitStateWithin(t, h, 10*time.Second, "the run configurations", func() bool { return p.runConfigs.generation > 0 && !p.runConfigs.loading }) + awaitRunConfigsAfter(t, h, p, since) if s := &p.runConfigs; s.failure != "" || len(s.list) != 1 { t.Fatalf("configurations = %+v failure %q", s.list, s.failure) } diff --git a/desktop/internal/workbench/runconfig_test.go b/desktop/internal/workbench/runconfig_test.go index e0d85ef8c1..b61643704a 100644 --- a/desktop/internal/workbench/runconfig_test.go +++ b/desktop/internal/workbench/runconfig_test.go @@ -69,11 +69,12 @@ func TestRunConfigurationRunsWithItsSavedChoices(t *testing.T) { h := newHarness(t, gate) h.open(root) p := h.app.project + since := p.runConfigs.generation h.app.post(func(a *App) { - p.build.instances = []buildInstance{runConfigInstance("app")} + setDetected(p, []buildInstance{runConfigInstance("app")}) a.refreshRunConfigurations(p) }) - awaitStateWithin(t, h, 10*time.Second, "the run configurations", func() bool { return p.runConfigs.generation > 0 && !p.runConfigs.loading }) + awaitRunConfigsAfter(t, h, p, since) s := &p.runConfigs if s.failure != "" || len(s.list) != 1 || s.selected != s.list[0].ID || s.list[0].Name != "Run Main" { t.Fatalf("configurations = %+v selected %q failure %q", s.list, s.selected, s.failure) diff --git a/desktop/internal/workbench/settings_plugin_effects_test.go b/desktop/internal/workbench/settings_plugin_effects_test.go index e774413803..7453e8e056 100644 --- a/desktop/internal/workbench/settings_plugin_effects_test.go +++ b/desktop/internal/workbench/settings_plugin_effects_test.go @@ -29,11 +29,15 @@ func TestPluginSettingsReloadInvalidatesOnlyOwningModelsAndKeepsRunningTask(t *t t.Fatal("in-flight model did not retain the pending reload") } // The old read completes after publication. Its stale model must not become - // loaded, and an unselected instance must not eagerly start another process. + // loaded; the title bar lists the runs of every instance, so the unselected one + // is read again instead of waiting for the Build window to select it. h.app.finishBuildModel(p, "changed", core.BuildModel{}, nil) - if p.build.instances[0].modelLoaded || p.build.instances[0].modelLoading || p.build.instances[0].modelReloadPending { + if p.build.instances[0].modelLoaded || p.build.instances[0].modelReloadPending { t.Fatal("superseded model became current") } + if !p.build.instances[0].modelLoading { + t.Fatal("the invalidated model was not read again for the title bar") + } if p.build.operation != running || !p.build.instances[1].modelLoaded { t.Fatal("completion disturbed the active task or unrelated model") } diff --git a/desktop/internal/workbench/tests_provider_test.go b/desktop/internal/workbench/tests_provider_test.go index 1a24095883..0c9c4c337f 100644 --- a/desktop/internal/workbench/tests_provider_test.go +++ b/desktop/internal/workbench/tests_provider_test.go @@ -486,11 +486,11 @@ var providerRunManifest = strings.Replace(providerTestsManifest, `"model": {"sou `"model": {"source": "provider"}, "run": [{"id": "application", "source": "provider", "fromTargets": {"tags": ["app"]}, "execution": "application"}],`, 1) -// What a provider prints while it prepares a run, such as the compile error that ends the -// preparation, is the run's console output: the user reads it there when the run fails. The -// host used to wait for the answer without reading the progress, so the console stayed empty. -func TestProviderRunPreparationShowsItsBuildOutput(t *testing.T) { - h := providerTestsHarnessWith(t, providerRunManifest) +// providerRunWorkspace is a workspace the provider fixture detects, with the fixture's build +// tool on PATH: the host resolves the provider's build tool before it starts the provider, and +// the fixture provider never runs it. +func providerRunWorkspace(t *testing.T) string { + t.Helper() root := t.TempDir() for _, marker := range []string{"fixture.marker", "discovery.marker"} { if err := os.WriteFile(filepath.Join(root, marker), []byte("fixture\n"), 0o600); err != nil { @@ -500,8 +500,6 @@ func TestProviderRunPreparationShowsItsBuildOutput(t *testing.T) { if err := os.MkdirAll(filepath.Join(root, "lib"), 0o700); err != nil { t.Fatal(err) } - // The host resolves the provider's build tool before it starts the provider; the fixture - // provider never runs it. bin := t.TempDir() tool := filepath.Join(bin, "fixture-tool") if runtime.GOOS == "windows" { @@ -512,7 +510,36 @@ func TestProviderRunPreparationShowsItsBuildOutput(t *testing.T) { t.Fatal(err) } t.Setenv("PATH", bin+string(filepath.ListSeparator)+os.Getenv("PATH")) - h.open(root) + return root +} + +// Opening a project lists the runs its build plugins declare, and the title bar shows the one +// it starts, without the user opening the run menu or pressing Run first. The host used to +// detect the build systems only on such a press, so a project opened on Current File with an +// empty run list and its application was never found. +func TestOpeningAProjectListsItsDeclaredRuns(t *testing.T) { + h := providerTestsHarnessWith(t, providerRunManifest) + h.open(providerRunWorkspace(t)) + p := h.app.project + awaitStateWithin(t, h, time.Minute, "the declared run in the title bar", func() bool { + return p.titleConfiguration() != nil + }) + configuration := p.titleConfiguration() + reference, ok := configuration.BuildReference() + if !ok || reference.Run != "application" || reference.PluginID != "dev.lithe.test.provider-tests" { + t.Fatalf("the title bar runs %+v, want the provider's application run", configuration) + } + if label := h.app.titleRunLabel(); label != configuration.Name { + t.Fatalf("the title bar reads %q, want %q", label, configuration.Name) + } +} + +// What a provider prints while it prepares a run, such as the compile error that ends the +// preparation, is the run's console output: the user reads it there when the run fails. The +// host used to wait for the answer without reading the progress, so the console stayed empty. +func TestProviderRunPreparationShowsItsBuildOutput(t *testing.T) { + h := providerTestsHarnessWith(t, providerRunManifest) + h.open(providerRunWorkspace(t)) p := h.app.project h.app.post(func(a *App) { a.loadBuildSystems(p) }) awaitStateWithin(t, h, time.Minute, "the provider model", func() bool { diff --git a/desktop/internal/workbench/title_run_empty_visual_test.go b/desktop/internal/workbench/title_run_empty_visual_test.go index 7b667d3c36..90de8952d3 100644 --- a/desktop/internal/workbench/title_run_empty_visual_test.go +++ b/desktop/internal/workbench/title_run_empty_visual_test.go @@ -7,7 +7,6 @@ import ( "os" "path/filepath" "testing" - "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" @@ -61,14 +60,14 @@ func TestVisualTitleRunWithoutConfigurations(t *testing.T) { }) h.open(root) p := h.app.project + since := p.runConfigs.generation h.app.post(func(a *App) { instance := runConfigInstance("app") instance.System.Runs = nil - p.build.loaded = true - p.build.instances = []buildInstance{instance} + setDetected(p, []buildInstance{instance}) a.refreshRunConfigurations(p) }) - awaitStateWithin(t, h, 10*time.Second, "the run configurations", func() bool { return p.runConfigs.generation > 0 && !p.runConfigs.loading }) + awaitRunConfigsAfter(t, h, p, since) language := h.app.language() h.click(center(h.button(itemRunConfig))) h.settle() diff --git a/desktop/internal/workbench/title_run_test.go b/desktop/internal/workbench/title_run_test.go index f8552a25f2..c19905624c 100644 --- a/desktop/internal/workbench/title_run_test.go +++ b/desktop/internal/workbench/title_run_test.go @@ -32,14 +32,14 @@ func titleRunHarness(t *testing.T, kernel Kernel, run pluginservice.BuildRunDecl h := newHarness(t, kernel) h.open(runConfigRoot(t)) p := h.app.project + since := p.runConfigs.generation h.app.post(func(a *App) { instance := runConfigInstance("app") instance.System.Runs = []pluginservice.BuildRunDeclaration{run} - p.build.loaded = true - p.build.instances = []buildInstance{instance} + setDetected(p, []buildInstance{instance}) a.refreshRunConfigurations(p) }) - awaitStateWithin(t, h, 10*time.Second, "the run configurations", func() bool { return p.runConfigs.generation > 0 && !p.runConfigs.loading }) + awaitRunConfigsAfter(t, h, p, since) if len(p.runConfigs.list) != 1 || p.titleConfiguration() == nil { t.Fatalf("configurations = %+v failure %q", p.runConfigs.list, p.runConfigs.failure) } @@ -72,8 +72,7 @@ func TestTitleRunWaitsForTheConfigurationsAndRunsTheChosenOne(t *testing.T) { h.open(runConfigRoot(t)) p := h.app.project h.app.post(func(a *App) { - p.build.loaded = true - p.build.instances = []buildInstance{runConfigInstance("app")} + setDetected(p, []buildInstance{runConfigInstance("app")}) a.refreshRunConfigurations(p) a.titleRun(p) if p.runConfigs.pending != titleActionRun { @@ -184,10 +183,11 @@ func TestStaticModelDetectionResolvesRunConfigurations(t *testing.T) { h := newHarness(t, &testKernel{Client: core.NewClient()}) h.open(runConfigRoot(t)) p := h.app.project + since := p.runConfigs.generation h.app.post(func(a *App) { a.finishBuildDetection(p, p.build.generation, []buildInstance{runConfigInstance("app")}, nil) }) - awaitStateWithin(t, h, 10*time.Second, "the run configurations", func() bool { return p.runConfigs.generation > 0 && !p.runConfigs.loading }) + awaitRunConfigsAfter(t, h, p, since) if len(p.runConfigs.list) != 1 || p.runConfigs.list[0].Name != "Run Main" || h.app.titleRunLabel() != "Run Main" { t.Fatalf("configurations = %+v failure %q", p.runConfigs.list, p.runConfigs.failure) } @@ -219,14 +219,14 @@ func emptyRunConfigHarness(t *testing.T, root string) (*harness, *project) { h := newHarness(t, &testKernel{Client: core.NewClient()}) h.open(root) p := h.app.project + since := p.runConfigs.generation h.app.post(func(a *App) { instance := runConfigInstance("app") instance.System.Runs = nil - p.build.loaded = true - p.build.instances = []buildInstance{instance} + setDetected(p, []buildInstance{instance}) a.refreshRunConfigurations(p) }) - awaitStateWithin(t, h, 10*time.Second, "the run configurations", func() bool { return p.runConfigs.generation > 0 && !p.runConfigs.loading }) + awaitRunConfigsAfter(t, h, p, since) if len(p.runConfigs.list) != 0 || p.runConfigs.failure != "" { t.Fatalf("configurations = %+v failure %q", p.runConfigs.list, p.runConfigs.failure) } diff --git a/shared/platform-feature-matrix/features/run-discovery.json b/shared/platform-feature-matrix/features/run-discovery.json index 527d758d00..98666e75c1 100644 --- a/shared/platform-feature-matrix/features/run-discovery.json +++ b/shared/platform-feature-matrix/features/run-discovery.json @@ -21,7 +21,7 @@ }, "owner": "Run", "verification": "Windows Run Actions 仍处于关闭状态;扩展 Run Actions 测试验证插件启用、禁用和声明的执行计划,TypeScript 检查所有调用方;重新启用前需完成实际应用验收。 多模块项目把服务工作目录改成模块目录后,服务仍留在列表中并以该目录启动;填写不存在的目录或 ${workspaceFolder} 等变量时,保存被拒绝并提示原因;在 Windows 确认重新扫描服务使用双箭头刷新图标,配置按语言生态、类型与实例呈现三栏布局;语言切换和外部选中能定位配置,空生态不显示,语言和配置栏不显示重复栏头,生态不显示配置数量;语言侧栏通过拖动阈值折叠和展开,收起与展开阈值不同以避免边界跳动,不显示专门折叠按钮;键盘可调整宽度及恢复展开,保存展开宽度与拖动折叠状态,拖动期间只更新局部宽度和紧凑标记,文字与图标对齐即时切换,结束后保存;语言行、类型行和实例行使用一致的紧凑行高,去掉列表上下留白和选中实例的圆角边距;窄面板自动缩成带提示的图标栏且扩大后恢复,右侧输出保留可用空间,窗口缩放或卸载时清理正在进行的拖动;所选配置的日志、运行状态、顶部停止按钮、清空输出与标准输入均指向其自身会话;保持选中 application 并后台启动服务后,顶部停止仍指向该应用的独立会话,不停止后台服务,左侧使用 SVG 箭头和类型图标,基础设施默认折叠,选择配置自动展开所在分组,运行、停止、编辑和完整名称提示可用;根据 Core 提供的元数据展示明确识别的框架图标,构建与测试任务保留工具图标,未知类型回退通用图标;同名自定义 provider 与已知框架分别分组且折叠状态独立,相同已知框架跨 provider 合组,项目与基础设施不合组;macOS Run 缺少配置且可重新生成时,检查空状态文字与链接在深浅主题下按 IDEA 工具窗口样式显示、窄面板不截断,并确认“识别并生成”仍触发原有生成流程;应用语言设为英文而系统语言为中文时,Run 空状态及其他本面板文案仍应显示英文;Run 顶部标题字号、颜色、41pt 高度和底部分隔线应与 Terminal、Git Log 等工具窗口一致;有项目配置或 Current File 正在运行/已有退出结果时,运行、重启、重新扫描和软换行按钮显示在独立的 36pt 操作栏,检查 16pt IDEA 图标、22pt 共享按钮的悬停、按下、选中及禁用状态;操作栏只保留一个运行/重运行动作:首次启动显示 Run,当前配置已运行过后显示 Rerun;右侧固定停止按钮,未运行禁用、运行中启用,两者始终指向当前选中配置;操作栏不重复显示 Running 圆点及状态文字,重运行按钮复用顶部工具栏的绿色 rerun_stroke 图标;标题栏菜单中的清空输出与原操作一致,收起按钮沿用共享样式;仅有 Current File 的项目启动后也可从 Run 操作栏停止,结束后保留重运行入口;Run 内容区不额外插入语言服务准备状态行,准备进度和失败入口保留在工作台状态栏;Run 标题、操作栏、配置列表标题、控制台标签底边及两侧纵向分割线统一使用工具窗口边框颜色和 1pt 绘制,左侧图标栏不出现 5pt 实心粗线,栏内分组线与 Git Log 一致使用共享 divider 颜色、22pt 宽度、1pt 高度及上下 3pt 间距;操作按钮组之间使用专用 ActionToolbar.separator,详情编辑按钮的边框由共享按钮样式负责,拖动命中范围保持不变;配置树直接显示分组与数量,不显示 Application types 标题;默认隐藏勾选框,通过更多菜单或右键进入批量选择,退出清空选择;配置单行显示名称,类型及服务地址放到悬停提示,行内仅运行/停止,编辑/固定/打开服务保留在共享右键菜单,固定后显示标记;分组与配置使用共享树行高、缩进及焦点选择样式;Run 范围筛选以固定图标栏呈现,应用范围筛选及当前运行导航使用中性 ToolWindowRun 图标,实际运行操作继续使用绿色 Execute 图标;全部采用 IDEA groups、服务采用 server 图标,固定、应用及任务沿用对应 IDEA 原始资源;检查所有图标的 16pt 尺寸、明暗 SVG 自动切换、提示和筛选,右键勾选范围和配置行勾选共享同一批量选择;配置行使用 IDEA 固定、编辑、运行及停止图标,悬停与点击维持箭头光标;配置过期提示使用共享中性通知表面及警告图标,操作仍可重新识别;Run 标题栏仅显示 Run,移除重复配置名与右侧状态胶囊;Console 和 Configuration details 标签位于运行操作按钮组右侧,配置列表选中项表示当前配置,内容区直接显示日志或详情;配置详情使用共享 13pt 字体、原生 Grid 自适应标签列、可选择且可换行的路径及值,编辑配置按钮复用共享 LitheCommitDialogButtonStyle 与 IDEA EditSource 图标,检查深浅主题、窄列及点击跳转设置,服务链接保留原动作;两个标签使用共享 LitheToolWindowTabStyle,检查 13pt 文字、28pt 标签、原始明暗 SVG、悬停及内容区聚焦/失焦状态,保留标签切换;Run 与 Debug 均启用共享 OutputTextView 的 IDEA 渲染入口,运行日志采用一致的 13pt 字体、1.2 倍行高和 ANSI 配色,不给普通 INFO 日志整行染蓝,源码链接继续跳转;Copy 与 Jump to latest 为共享图标按钮,复制不带 ANSI,向上滚动后可恢复跟随;其他配置恢复状态保留各自提示。 Current File 运行一次后修改未保存并切换编辑标签,重运行应先保存原运行文件再构建启动计划;原文件保存失败时提示错误并中止重启,当前焦点文档不被误保存;调整 Run 面板高度,外层横向操作栏固定为 36pt,剩余高度交给配置树和控制台。 保存构建任务后重启,确认用户任务和自动入口同时恢复;再次加载不重复生成。 #1562:Windows 普通应用 A/B 独立会话和输出;先启动 A 再 B,停止及重跑 B 不影响 A,切换配置只显示所属输出,关闭项目清理两者。 IDE API 在 primary 忙碌时仍能启动独立应用,同一配置准备期间拒绝重复启动;保存期间会话可见且可停止,停止后不再启动进程,顶部停止不影响后台服务;旧 Debug 回调不能停止重跑后的应用。 缺少工具链时错误只归属目标应用,不覆盖 primary 或后台会话,也不把已运行的目标实例标记为退出。 macOS 通用 Provider 运行发现:按当前公开声明及目标标签生成 build.provider;名称/执行类型变化保留 ID 和参数、环境、目录覆盖;模型撤回、重排、恢复、停用及重新生成核对指纹,撤回目标不从旧检测层复活。默认项优先 service,不依赖框架名单。 通用 Provider 选项:团队/本机层覆盖运行时 argv、入口与 Build 选项,覆盖空字符串参数、引号、反斜杠、Unicode、false/空数组、显式清空、旧调用者省略、未知/超限字段和重存目录保持。 旧 Run v2 转换:验证稳定 ID、默认项、两层覆盖和目标唯一性;转换前预检两层,覆盖源文件变化、未改写输入变化、偏好变化、各写入阶段取消、外部修改与回滚冲突。工作区/模型/任务取消及新生成撤销写入资格;只读安装目录和越界链接不写入。 当前 Provider 归属投影改用 build={pluginID,buildSystemID,root,projectID}。共享 provider-project-ownership fixture 由 Rust、Swift bridge 与 Windows 映射回归共同读取,覆盖同名类、非标准源码根、角色、稳定身份和 cwd 覆盖;团队/本机伪造 build 身份被当前模型拥有的值替换。原生精确导入查找拒绝错误插件/构建声明/根/项目以及已撤销模型。旧 Windows 生成路径在未提供 Provider 归属时保留,删除前需先迁移真实消费者。 macOS Debug 缺少精确源码路径时,使用通用 Build 归属根加模块路径定位源码;嵌套实例与工作区根实例优先,当前实例没有源码时不得选择其他实例的同名类。原生源码选择回归不替代 Registry/DAP 与完整产品验收。 编辑器行首入口的运行、调试及编辑配置使用 Core 的同一选择规则:精确匹配入口和源码、排除禁用项,优先已选配置,再优先用户配置;配置或工作区在异步选择期间发生变化时不得启动旧结果。 Viva 桌面端运行配置列表:范围选择器依次为全部配置、置顶及 Core 给出的服务/应用/任务/组合,各带数量;配置按提供它的构建系统分组、组按名称排序且可折叠,组内按名称排序;行内运行/停止,Enter 或双击运行,右键菜单运行/停止、编辑运行配置、置顶/取消置顶;置顶写入客户端数据目录 run-configuration-pins.json,不写项目或安装目录,重开后读回。批量选择与并发运行、服务地址尚未迁移。", - "notes": "Viva:构建模型加载后,宿主把已加载实例中每个运行声明适用的目标作为 providerRuns 交给 Core 的 runConfig.generate(不写工作区),再用 runConfig.resolve 合并生成层与已保存的项目层、本机层(2026-11-18 起为 .lithe/run/configurations.yaml、local.yaml 与插件运行的 .lithe/run/plugin/<插件>.toml、<插件>.local.toml,旧版 JSON 在没有对应 YAML 时仍读取,见 builtin-process-runs);Run 窗口顶部的“运行配置”选择器列出 build.provider 配置(默认选 Core 给出的默认项),“运行”经 runConfig.providerLaunchInputs 取出保存的参数、环境、工作目录与入口,按 buildProviders 10 的 launchOptions 交给 provider 的 prepareRun 与 decodeRunPreparation;没有任何自定义的 application 运行不带 launchOptions,保持旧 provider 可用。选择器旁的“编辑”打开运行配置编辑对话框:程序参数经 runConfig.argumentText 回显为可逆文本,工作目录与环境变量(每行 KEY=VALUE)回显当前生效值,保存时由 runConfig.updateOptions 生成所选层(插件运行写 .lithe/run/plugin/<插件>.local.toml 或 <插件>.toml)的文档,宿主用 configfile 按读取时的字节做冲突检查后原子替换,再重新解析。尚未实现:provider 运行时参数/入口/工具等 providerRunOptions 的编辑、未加载模型的实例的运行(快照只含已加载实例)、调试配置。 2026-11-12:运行配置检测走 Core(GenerateRunConfigurations/ResolveRunConfigurations/ResolveExecutionEnvironment),宿主没有 GOOS 分支,矩阵原记的 windows=missing 属失真:两个平台共缺 providerRunOptions 编辑与调试配置,与平台无关。 2026-11-16(#1856 第 4 项,Core #77):Core 删除内置运行发现探测器(Cargo、Go、npm/pnpm/yarn/bun、Python、Make、just、Procfile、Compose)、项目内容指纹和工具链需求,Run 列表的自动条目只来自已启用构建插件声明的 buildSystems[].run,加上用户保存的配置;没有插件声明 run 的生态不再出现自动条目。桌面端删除只有测试使用的 InspectRunConfigurations,GenerateRunConfigurations 不再传缓存目录;run_discovery_test.go 用合成的 provider run 验证生成不写工作区。", + "notes": "Viva:构建模型加载后,宿主把已加载实例中每个运行声明适用的目标作为 providerRuns 交给 Core 的 runConfig.generate(不写工作区),再用 runConfig.resolve 合并生成层与已保存的项目层、本机层(2026-11-18 起为 .lithe/run/configurations.yaml、local.yaml 与插件运行的 .lithe/run/plugin/<插件>.toml、<插件>.local.toml,旧版 JSON 在没有对应 YAML 时仍读取,见 builtin-process-runs);Run 窗口顶部的“运行配置”选择器列出 build.provider 配置(默认选 Core 给出的默认项),“运行”经 runConfig.providerLaunchInputs 取出保存的参数、环境、工作目录与入口,按 buildProviders 10 的 launchOptions 交给 provider 的 prepareRun 与 decodeRunPreparation;没有任何自定义的 application 运行不带 launchOptions,保持旧 provider 可用。选择器旁的“编辑”打开运行配置编辑对话框:程序参数经 runConfig.argumentText 回显为可逆文本,工作目录与环境变量(每行 KEY=VALUE)回显当前生效值,保存时由 runConfig.updateOptions 生成所选层(插件运行写 .lithe/run/plugin/<插件>.local.toml 或 <插件>.toml)的文档,宿主用 configfile 按读取时的字节做冲突检查后原子替换,再重新解析。尚未实现:provider 运行时参数/入口/工具等 providerRunOptions 的编辑、未加载模型的实例的运行(快照只含已加载实例)、调试配置。 2026-11-12:运行配置检测走 Core(GenerateRunConfigurations/ResolveRunConfigurations/ResolveExecutionEnvironment),宿主没有 GOOS 分支,矩阵原记的 windows=missing 属失真:两个平台共缺 providerRunOptions 编辑与调试配置,与平台无关。 2026-11-16(#1856 第 4 项,Core #77):Core 删除内置运行发现探测器(Cargo、Go、npm/pnpm/yarn/bun、Python、Make、just、Procfile、Compose)、项目内容指纹和工具链需求,Run 列表的自动条目只来自已启用构建插件声明的 buildSystems[].run,加上用户保存的配置;没有插件声明 run 的生态不再出现自动条目。桌面端删除只有测试使用的 InspectRunConfigurations,GenerateRunConfigurations 不再传缓存目录;run_discovery_test.go 用合成的 provider run 验证生成不写工作区。 2026-11-19:打开项目时(openProjectHere)就识别构建系统并加载每个实例的模型,标题栏直接列出插件声明的运行并选中 Core 的默认项,不再停在“当前文件”、等用户先按运行或打开下拉;TestOpeningAProjectListsItsDeclaredRuns 用合成 provider 插件验证,macOS 上用真实 Maven 多模块 Spring Boot 工程无头验证;Windows 未本机验证,宿主无平台分支。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { From 7a9d407a18eafde8cd7d482eb221da89583a012b Mon Sep 17 00:00:00 2001 From: lick <2188718831@qq.com> Date: Thu, 19 Nov 2026 01:54:23 -0800 Subject: [PATCH 2/5] =?UTF-8?q?fix(run):=20=E5=88=A0=E9=99=A4=E6=89=93?= =?UTF-8?q?=E5=BC=80=E9=A1=B9=E7=9B=AE=E5=90=8E=E6=81=92=E4=B8=BA=E7=9C=9F?= =?UTF-8?q?=E7=9A=84=20runConfigs.wanted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wanted 只在 loadTitleRunConfigs 里置真、从不置假,而打开项目时就会调用它, 所以对任何打开的项目都恒为真。识别完成后直接加载每个实例的模型,被作废的 模型无论构建窗口是否显示它的实例都重新加载。 Refs #2074 Co-Authored-By: Claude Opus 5.5 --- desktop/internal/workbench/build.go | 12 ++++++------ desktop/internal/workbench/runconfig.go | 3 --- desktop/internal/workbench/title_run.go | 5 ++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/desktop/internal/workbench/build.go b/desktop/internal/workbench/build.go index b31c31573a..de90e5c248 100644 --- a/desktop/internal/workbench/build.go +++ b/desktop/internal/workbench/build.go @@ -781,10 +781,10 @@ func (a *App) finishBuildDetection(p *project, generation uint64, instances []bu p.build.status = a.text.Build.NoBuildSystems return } + // The instance the Build window shows loads first, then every other one, whose runs the + // title bar lists too. a.loadBuildModel(p, p.build.selected) - if p.runConfigs.wanted { - a.loadTitleRunConfigs(p) - } + a.loadTitleRunConfigs(p) } // loadBuildModel loads the model of an instance whose detection did not carry one (a @@ -1099,9 +1099,9 @@ func (a *App) finishBuildModel(p *project, id string, model core.BuildModel, err if err != nil { a.backgroundFailed("plugin_model_superseded", err) } - if index == p.build.selected || p.runConfigs.wanted { - a.loadBuildModel(p, index) - } + // The title bar lists the runs of every instance, so a superseded model loads again + // whether or not the Build window shows its instance. + a.loadBuildModel(p, index) a.settleTitleAction(p) return } diff --git a/desktop/internal/workbench/runconfig.go b/desktop/internal/workbench/runconfig.go index 2087ee898d..3c9067f977 100644 --- a/desktop/internal/workbench/runconfig.go +++ b/desktop/internal/workbench/runconfig.go @@ -72,9 +72,6 @@ type runConfigState struct { currentFile bool // pending is the title bar's Run or Debug waiting for the configurations to be read. pending titleAction - // wanted says the title bar asked for the configurations, so every detected instance - // loads its model and not only the one the Build window shows. - wanted bool } // configuration is the listed configuration id, or nil. diff --git a/desktop/internal/workbench/title_run.go b/desktop/internal/workbench/title_run.go index ecf91fbfa8..f14da6badc 100644 --- a/desktop/internal/workbench/title_run.go +++ b/desktop/internal/workbench/title_run.go @@ -59,13 +59,12 @@ func hiddenRunConfigurations(language i18n.Language, count int) string { } // loadTitleRunConfigs reads what the title bar lists. Detection runs once; after it every -// detected instance loads its model, since each offers its own runs, where the Build window -// only loads the instance it shows. +// detected instance loads its model, since each offers its own runs. The project calls it as +// soon as it opens, so the title bar lists them without a press first. func (a *App) loadTitleRunConfigs(p *project) { if p == nil { return } - p.runConfigs.wanted = true if !p.build.loaded { a.loadBuildSystems(p) return From 91d651e5f495e67f3ada3b7b7bf08da54da74199 Mon Sep 17 00:00:00 2001 From: lick <2188718831@qq.com> Date: Thu, 19 Nov 2026 02:49:58 -0800 Subject: [PATCH 3/5] fix(desktop): open build options with profiles and name their text options Opening the Build options of a Maven project with profiles closed the application: the multi-select choices were keyed as siblings of the other fields, so the first choice took the first field's key and the paint panicked. The choices are now keyed inside the field's own column. The JDK, settings file and local repository fields showed no name, since a text field's label only names it to accessibility; the option's name is now a text above the field, as for the multi-select. The note and the open-project comment now say that loading a model at open runs the plugin's model command (mvn), and that only workspace programs such as a wrapper wait for workspace trust. Co-Authored-By: Claude Opus 5.5 --- ...9-run-configuration-detection-in-memory.md | 2 +- desktop/internal/workbench/app.go | 5 +- .../workbench/build_tree_options_test.go | 56 ++++++++++++++++++- desktop/internal/workbench/runconfig_view.go | 29 +++++++--- 4 files changed, 80 insertions(+), 12 deletions(-) diff --git a/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md b/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md index c917873925..eba4062cc5 100644 --- a/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md +++ b/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md @@ -45,7 +45,7 @@ Core 按规范化后的工作区路径保存最近一次 `runConfig.generate` 模型在打开项目时就开始加载:`openProjectHere`(`desktop/internal/workbench/app.go`)调用 `loadTitleRunConfigs`,先识别构建系统,再加载每个识别到的实例的模型,因为标题栏要列出所有实例声明的运行,不只是构建窗口选中的那一个。以前只有按下标题栏的运行、打开运行配置下拉或打开构建窗口时才识别,用户打开 Spring Boot 工程后看到的是“当前文件”和空列表,以为启动类没被识别出来。 -自动加载不放宽执行仓库代码的限制:加载模型时构建工具经工具链各层解析,工作区还没被信任时,`mvnw`、`gradlew` 这类工作区里的程序不会被选中,和用户手动触发时是同一道门槛。加载模型也不写用户工程。 +自动加载把执行时机提前了:命令来源的模型(如 Maven 的 `mvn`,清单标了 `executesProjectCode`)会在打开项目时运行,而 pom 里的扩展和插件就是仓库代码。此前构建窗口、测试窗口或运行菜单第一次出现时同样会运行它,构建窗口随布局恢复时也就是打开时,所以这不是新增的门槛缺口,但范围变大了。现有的信任门槛只有一道:构建工具经工具链各层解析,工作区还没被信任时,`mvnw`、`gradlew` 这类工作区里的程序不会被选中;模型命令本身没有按信任把关。加载模型不写用户工程。 ### 默认配置由 Core 选 diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 043a221dc5..caebd72317 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -1528,8 +1528,9 @@ func (a *App) openProjectHere(path string) { a.activatePluginWorkspace(p) // The title bar lists the runs the build plugins declare as soon as the project opens, // so its application is found without a press on Run or on the run menu first. Loading - // a model resolves the build tool through the toolchain layers, which leave out - // workspace programs such as a wrapper until the user trusts the workspace. + // a model runs the plugin's model command, such as mvn, which runs the project's build + // extensions, as the Build window did when it first showed; the toolchain layers leave + // out workspace programs such as a wrapper until the user trusts the workspace. a.loadTitleRunConfigs(p) a.restoreEditorSession(p) a.restoreCheckpoints(p) diff --git a/desktop/internal/workbench/build_tree_options_test.go b/desktop/internal/workbench/build_tree_options_test.go index c91a5de560..b66c635f49 100644 --- a/desktop/internal/workbench/build_tree_options_test.go +++ b/desktop/internal/workbench/build_tree_options_test.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "slices" + "strings" "testing" "time" @@ -101,6 +102,12 @@ dev = true ` func openTreeOptionsProject(t *testing.T, kernel Kernel) (*harness, *project) { + t.Helper() + return openTreeOptionsProjectWith(t, kernel, treeOptionsStaticManifest) +} + +// openTreeOptionsProjectWith is openTreeOptionsProject with the plugin's manifest. +func openTreeOptionsProjectWith(t *testing.T, kernel Kernel, manifest string) (*harness, *project) { t.Helper() dir := t.TempDir() if err := os.WriteFile(filepath.Join(dir, settingsFile), []byte(`{"theme":"dark"}`), 0o600); err != nil { @@ -112,7 +119,7 @@ func openTreeOptionsProject(t *testing.T, kernel Kernel) (*harness, *project) { if err := os.MkdirAll(installed, 0o700); err != nil { t.Fatal(err) } - if err := os.WriteFile(filepath.Join(installed, "plugin.json"), []byte(treeOptionsStaticManifest), 0o600); err != nil { + if err := os.WriteFile(filepath.Join(installed, "plugin.json"), []byte(manifest), 0o600); err != nil { t.Fatal(err) } if err := pluginstate.New(preferences).SetEnabled("dev.lithe.test.tree-options", true); err != nil { @@ -367,3 +374,50 @@ func TestBuildAndRunOptionEditorsResolveAndSaveModelChoices(t *testing.T) { t.Fatalf("instance profiles passed to the run plan = %q (err %v), want [-dev local]", runTokens, err) } } + +// treeOptionsDirectoryFirstManifest declares a directory option, as a JDK is, before the +// multi-select Profiles option. +var treeOptionsDirectoryFirstManifest = strings.Replace(treeOptionsStaticManifest, `"options": [{ + "id": "profiles",`, `"options": [{"id": "home", "displayName": "Home", "kind": "directory", "environment": {"FIXTURE_HOME": "${value}"}}, { + "id": "profiles",`, 1) + +// A multi-select option after another option opens in both editors, and a text option shows its +// name: a text field's label only names it to accessibility. Its choices were keyed among +// the editor's fields, so the first choice took the key of the first field and the paint panicked: +// opening the Build options of a Maven project with profiles closed the application. +func TestOptionEditorsShowAMultiSelectAfterAnotherOption(t *testing.T) { + h, p := openTreeOptionsProjectWith(t, &testKernel{Client: core.NewClient()}, treeOptionsDirectoryFirstManifest) + + h.clickNamed(h.shared("desktop.build.options")) + h.settleUntil("build options dialog resolved", func() bool { + e := &p.build.options + return e.open && e.ignored.loaded && len(e.fields) == 2 && e.fields[1].kind == "multiSelect" + }) + h.settle() + if !h.shows("local") || !h.shows("prod") { + t.Fatal("the Build options dialog does not show the profile choices") + } + if !h.shows("Home") { + t.Fatal("the Build options dialog does not name its directory option") + } + h.app.post(func(a *App) { p.build.options.open = false }) + h.settle() + + awaitStateWithin(t, h, 10*time.Second, "provider run configuration", func() bool { + return !p.runConfigs.loading && len(p.runConfigs.list) == 1 + }) + configID := p.runConfigs.list[0].ID + dialog := &p.runConfigs.dialog + h.app.post(func(a *App) { a.openRunConfigDialog(p, configID) }) + awaitStateWithin(t, h, 10*time.Second, "run configuration editor resolved", func() bool { + draft := dialog.drafts[configID] + return draft != nil && draft.editor != nil && draft.editor.ready() && len(draft.editor.optionFields) == 2 + }) + h.settle() + if !h.shows("local") || !h.shows("prod") { + t.Fatal("the run configuration editor does not show the profile choices") + } + if !h.shows("Home") { + t.Fatal("the run configuration editor does not name its directory option") + } +} diff --git a/desktop/internal/workbench/runconfig_view.go b/desktop/internal/workbench/runconfig_view.go index af12e70240..118b9208ba 100644 --- a/desktop/internal/workbench/runconfig_view.go +++ b/desktop/internal/workbench/runconfig_view.go @@ -372,16 +372,24 @@ func (a *App) drawRunOptionField(c ui.C, language i18n.Language, field *runOptio return labels[value] }).Label(field.title).FillWidth().Disabled(!ready) case "text", "file", "directory": - ui.TextField(c, &field.text, field.title, "").FillWidth().Disabled(!ready) + // A text field's label only names it to accessibility, so the option's name is a text above it. + ui.Column(c).FillWidth().Gap(6).Children(func() { + a.drawRunOptionTitle(c, field.title) + ui.TextField(c, &field.text, field.title, "").FillWidth().Disabled(!ready) + }) case "multiSelect": - ui.Text(c, field.title).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) - for index := range field.choices { - title := field.choices[index].title - if field.choices[index].defaultActive { - title = i18n.SharedFormat(language, "desktop.build.optionChoiceDefaultLabel", map[string]string{"title": title}) + // The choices are keyed inside the field's own column: c names only the next element, so + // keyed as siblings of the other fields the first choice took the first field's key. + ui.Column(c).FillWidth().Gap(6).Children(func() { + a.drawRunOptionTitle(c, field.title) + for index := range field.choices { + title := field.choices[index].title + if field.choices[index].defaultActive { + title = i18n.SharedFormat(language, "desktop.build.optionChoiceDefaultLabel", map[string]string{"title": title}) + } + ui.Checkbox(c.KeyInt(index), &field.picks[index], title).Disabled(!ready) } - ui.Checkbox(c.KeyInt(index), &field.picks[index], title).Disabled(!ready) - } + }) default: text := field.title + ": " + i18n.Shared(language, "desktop.runConfig.optionReadOnly") if field.raw != nil { @@ -391,6 +399,11 @@ func (a *App) drawRunOptionField(c ui.C, language i18n.Language, field *runOptio } } +// drawRunOptionTitle declares the name shown above an option's text field or choices. +func (a *App) drawRunOptionTitle(c ui.C, title string) { + ui.Text(c, title).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) +} + // runConfigDeletion is the user configuration the delete confirmation asks about. type runConfigDeletion struct { id, name string From 25c334e79279375e6f33b069296e50c1bba1d090 Mon Sep 17 00:00:00 2001 From: lick <2188718831@qq.com> Date: Thu, 19 Nov 2026 03:45:29 -0800 Subject: [PATCH 4/5] =?UTF-8?q?feat(workspace):=20=E6=89=93=E5=BC=80?= =?UTF-8?q?=E5=89=8D=E7=A1=AE=E8=AE=A4=E5=B7=A5=E4=BD=9C=E5=8C=BA=E4=BF=A1?= =?UTF-8?q?=E4=BB=BB=EF=BC=8C=E6=9C=AA=E4=BF=A1=E4=BB=BB=E6=97=B6=E4=BB=A5?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=A8=A1=E5=BC=8F=E6=89=93=E5=BC=80=EF=BC=88?= =?UTF-8?q?=E5=AF=B9=E9=BD=90=20IDEA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 打开没有信任记录的文件夹前先问“信任并打开项目”:信任项目、以安全模式预览、不打开, 可勾选信任父文件夹;决定由 Core 记在偏好目录的 toolchains/global.json,不写项目。 - 安全模式下不加载构建模型;运行、构建任务、测试、运行当前文件和重新加载前先问 “信任项目?/保持安全模式”;编辑器上方显示安全模式提示条,可直接信任。 - 11 处计划请求带 ProjectCodeAllowed,Core 拒绝会运行项目代码的计划 (plugin.build.untrustedWorkspace);Core 固定到 Lithe-core-rust#118 的 150c857。 - 设置页授予或撤销信任后工作台重新读取并应用;测试 harness 默认信任所有工作区。 - 新增 Agent Note、功能矩阵条目 workspace-trust 和中英词条;跟进项 #2207、#2208。 Closes #2201 Co-Authored-By: Claude Opus 5.5 --- ...9-run-configuration-detection-in-memory.md | 2 +- ...026-11-19-workspace-trust-and-safe-mode.md | 45 +++ .../buildprovider/buildprovider_test.go | 5 +- desktop/internal/core/build.go | 11 + desktop/internal/core/build_options_test.go | 2 + desktop/internal/core/build_test.go | 2 + desktop/internal/core/test.go | 2 + desktop/internal/core/test_test.go | 3 +- desktop/internal/core/toolchain_catalog.go | 24 +- desktop/internal/i18n/shared.generated.go | 26 ++ desktop/internal/toolchain/catalog.go | 69 ++++- .../internal/toolchain/project_trust_test.go | 17 +- desktop/internal/workbench/app.go | 20 +- desktop/internal/workbench/app_test.go | 3 + desktop/internal/workbench/build.go | 65 +++-- .../internal/workbench/build_dependencies.go | 2 +- desktop/internal/workbench/build_tests.go | 2 +- desktop/internal/workbench/editor_view.go | 3 + .../workbench/runconfig_before_launch.go | 1 + desktop/internal/workbench/runconfig_types.go | 1 + .../internal/workbench/settings_toolchains.go | 6 +- desktop/internal/workbench/tests.go | 21 +- .../workbench/title_run_entrypoints.go | 6 +- desktop/internal/workbench/workspace_trust.go | 276 ++++++++++++++++++ .../workbench/workspace_trust_test.go | 197 +++++++++++++ scripts/desktop/build-desktop-core.sh | 9 +- shared/i18n/locales/en-US.json | 13 + shared/i18n/locales/zh-CN.json | 13 + shared/i18n/messages.json | 100 +++++++ .../features/workspace-trust.json | 27 ++ 30 files changed, 921 insertions(+), 52 deletions(-) create mode 100644 .agents/notes/implemented/feature/2026-11-19-workspace-trust-and-safe-mode.md create mode 100644 desktop/internal/workbench/workspace_trust.go create mode 100644 desktop/internal/workbench/workspace_trust_test.go create mode 100644 shared/platform-feature-matrix/features/workspace-trust.json diff --git a/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md b/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md index eba4062cc5..36aa043f65 100644 --- a/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md +++ b/.agents/notes/implemented/architecture/2026-10-29-run-configuration-detection-in-memory.md @@ -45,7 +45,7 @@ Core 按规范化后的工作区路径保存最近一次 `runConfig.generate` 模型在打开项目时就开始加载:`openProjectHere`(`desktop/internal/workbench/app.go`)调用 `loadTitleRunConfigs`,先识别构建系统,再加载每个识别到的实例的模型,因为标题栏要列出所有实例声明的运行,不只是构建窗口选中的那一个。以前只有按下标题栏的运行、打开运行配置下拉或打开构建窗口时才识别,用户打开 Spring Boot 工程后看到的是“当前文件”和空列表,以为启动类没被识别出来。 -自动加载把执行时机提前了:命令来源的模型(如 Maven 的 `mvn`,清单标了 `executesProjectCode`)会在打开项目时运行,而 pom 里的扩展和插件就是仓库代码。此前构建窗口、测试窗口或运行菜单第一次出现时同样会运行它,构建窗口随布局恢复时也就是打开时,所以这不是新增的门槛缺口,但范围变大了。现有的信任门槛只有一道:构建工具经工具链各层解析,工作区还没被信任时,`mvnw`、`gradlew` 这类工作区里的程序不会被选中;模型命令本身没有按信任把关。加载模型不写用户工程。 +自动加载把执行时机提前了:命令来源的模型(如 Maven 的 `mvn`,清单标了 `executesProjectCode`)会在打开项目时运行,而 pom 里的扩展和插件就是仓库代码。此前构建窗口、测试窗口或运行菜单第一次出现时同样会运行它,构建窗口随布局恢复时也就是打开时,所以这不是新增的门槛缺口,但范围变大了。所以打开项目前先确认工作区信任:没有信任记录时先问,安全模式下不加载模型,Core 也会拒绝会运行项目代码的计划,见 [工作区信任与安全模式](../feature/2026-11-19-workspace-trust-and-safe-mode.md)。加载模型不写用户工程。 ### 默认配置由 Core 选 diff --git a/.agents/notes/implemented/feature/2026-11-19-workspace-trust-and-safe-mode.md b/.agents/notes/implemented/feature/2026-11-19-workspace-trust-and-safe-mode.md new file mode 100644 index 0000000000..e54ed0a2f1 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-11-19-workspace-trust-and-safe-mode.md @@ -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`。 diff --git a/desktop/internal/buildprovider/buildprovider_test.go b/desktop/internal/buildprovider/buildprovider_test.go index b331c6f2ef..cbb2f84d75 100644 --- a/desktop/internal/buildprovider/buildprovider_test.go +++ b/desktop/internal/buildprovider/buildprovider_test.go @@ -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) } @@ -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) } diff --git a/desktop/internal/core/build.go b/desktop/internal/core/build.go index 5cad67cd0a..d811639952 100644 --- a/desktop/internal/core/build.go +++ b/desktop/internal/core/build.go @@ -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"` @@ -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 @@ -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 diff --git a/desktop/internal/core/build_options_test.go b/desktop/internal/core/build_options_test.go index 748b6fabcc..35b3ae683a 100644 --- a/desktop/internal/core/build_options_test.go +++ b/desktop/internal/core/build_options_test.go @@ -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) diff --git a/desktop/internal/core/build_test.go b/desktop/internal/core/build_test.go index d419542010..6048b2421d 100644 --- a/desktop/internal/core/build_test.go +++ b/desktop/internal/core/build_test.go @@ -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) diff --git a/desktop/internal/core/test.go b/desktop/internal/core/test.go index 6a780baadc..4e3fbcc7e8 100644 --- a/desktop/internal/core/test.go +++ b/desktop/internal/core/test.go @@ -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. diff --git a/desktop/internal/core/test_test.go b/desktop/internal/core/test_test.go index e6ebbd8b7a..18c8b88b51 100644 --- a/desktop/internal/core/test_test.go +++ b/desktop/internal/core/test_test.go @@ -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) diff --git a/desktop/internal/core/toolchain_catalog.go b/desktop/internal/core/toolchain_catalog.go index 2bf1d813df..63662ed3a7 100644 --- a/desktop/internal/core/toolchain_catalog.go +++ b/desktop/internal/core/toolchain_catalog.go @@ -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"` @@ -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 { diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 02b05586c1..b8cee28d49 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -2171,6 +2171,19 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.tools.moveToTitleBar": "Move to Title Bar", "desktop.tools.structure": "Structure", "desktop.tools.withShortcut": "{name} {keys}", + "desktop.trust.actionText": "Loading, running, building or testing this project may run code from its build scripts. If you don’t trust the source, stay in safe mode.", + "desktop.trust.banner": "Safe mode, limited functionality. Trust the project to access full IDE functionality.", + "desktop.trust.bannerLink": "Trust Project…", + "desktop.trust.dontOpen": "Don’t Open", + "desktop.trust.location": "Trust all projects in the “{folder}” folder", + "desktop.trust.modelSafeMode": "Safe mode: the model is not loaded. Reload to trust the project and load it.", + "desktop.trust.openText": "Lithe provides features that may run code from this folder, such as build scripts, build wrappers and build-tool extensions. If you don’t trust the source, preview the project in safe mode to only browse its code.", + "desktop.trust.openTitle": "Trust and Open Project “{project}”?", + "desktop.trust.previewSafeMode": "Preview in Safe Mode", + "desktop.trust.saveFailed": "Could not save the trust decision: {reason}", + "desktop.trust.stayInSafeMode": "Stay in Safe Mode", + "desktop.trust.title": "Trust Project?", + "desktop.trust.trustProject": "Trust Project", "desktop.updates.arrow.available": "Lithe {version} is available. Click to see what changed", "desktop.updates.arrow.downloading": "Downloading Lithe {version}… {percent}%", "desktop.updates.arrow.ready": "Lithe {version} is downloaded. Click to review and restart", @@ -5332,6 +5345,19 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.tools.moveToTitleBar": "移到标题栏", "desktop.tools.structure": "结构", "desktop.tools.withShortcut": "{name} {keys}", + "desktop.trust.actionText": "加载、运行、构建或测试此项目可能会运行其构建脚本中的代码。如果不信任来源,请保持安全模式。", + "desktop.trust.banner": "安全模式,功能受限。信任此项目后即可使用完整的 IDE 功能。", + "desktop.trust.bannerLink": "信任项目…", + "desktop.trust.dontOpen": "不打开", + "desktop.trust.location": "信任“{folder}”文件夹中的所有项目", + "desktop.trust.modelSafeMode": "安全模式:未加载项目模型。点击重新加载可信任项目并加载。", + "desktop.trust.openText": "Lithe 的部分功能可能运行此文件夹中的代码,例如构建脚本、构建包装器和构建工具扩展。如果不信任来源,请以安全模式预览项目,只浏览代码。", + "desktop.trust.openTitle": "信任并打开项目“{project}”?", + "desktop.trust.previewSafeMode": "以安全模式预览", + "desktop.trust.saveFailed": "无法保存信任设置:{reason}", + "desktop.trust.stayInSafeMode": "保持安全模式", + "desktop.trust.title": "信任项目?", + "desktop.trust.trustProject": "信任项目", "desktop.updates.arrow.available": "Lithe {version} 可更新,点击查看更新内容", "desktop.updates.arrow.downloading": "正在下载 Lithe {version}… {percent}%", "desktop.updates.arrow.ready": "Lithe {version} 已下载,点击查看并重启更新", diff --git a/desktop/internal/toolchain/catalog.go b/desktop/internal/toolchain/catalog.go index a80078e201..671b813935 100644 --- a/desktop/internal/toolchain/catalog.go +++ b/desktop/internal/toolchain/catalog.go @@ -3,6 +3,7 @@ package toolchain import ( "context" "errors" + "os" "runtime" "github.com/1lck/Lithe-IDEA/desktop/internal/configfile" @@ -116,6 +117,61 @@ func (s Snapshot) SaveWorkspaceTrust(ctx context.Context, kernel Kernel, trusted if s.Global || s.Root == "" || s.catalog == nil { return false, ErrPinConflict } + return saveWorkspaceTrust(ctx, kernel, s.catalog, s.Root, s.rootIdentity, core.ToolchainWorkspaceTrustEdit{ + Workspace: s.Root, + Trusted: trusted, + }) +} + +// WorkspaceTrust is one workspace's trust decision as Core reads it from the +// machine-local catalog, with the source it was read from so a decision is saved +// against the same bytes. +type WorkspaceTrust struct { + // Root is the workspace folder. + Root string + core.ToolchainWorkspaceTrust + catalog *catalogSource + rootIdentity os.FileInfo +} + +// ReadWorkspaceTrust reads the trust of the workspace at root from the catalog in +// globalRoot, the platform preference directory. Reading creates nothing. +func ReadWorkspaceTrust(ctx context.Context, kernel Kernel, globalRoot, root string) (WorkspaceTrust, error) { + if globalRoot == "" || root == "" { + return WorkspaceTrust{}, errors.New("toolchain: workspace trust needs the preference directory and a workspace") + } + identity, err := directoryIdentity(ctx, root) + if err != nil { + return WorkspaceTrust{}, err + } + catalog, err := captureCatalog(ctx, kernel, globalRoot, root, "") + if err != nil { + return WorkspaceTrust{}, err + } + if catalog.state.WorkspaceTrust == nil { + return WorkspaceTrust{}, errors.New("toolchain: Core returned no workspace trust") + } + return WorkspaceTrust{Root: root, ToolchainWorkspaceTrust: *catalog.state.WorkspaceTrust, catalog: catalog, rootIdentity: identity}, nil +} + +// Save records the user's decision: trusted lets the workspace's project code run +// and false keeps it in safe mode; location also trusts its offered parent folder. +// It writes only toolchains/global.json in the preference directory and refuses a +// catalog changed since it was read or a workspace folder replaced since. +func (t WorkspaceTrust) Save(ctx context.Context, kernel Kernel, trusted, location bool) (bool, error) { + if t.catalog == nil { + return false, ErrPinConflict + } + return saveWorkspaceTrust(ctx, kernel, t.catalog, t.Root, t.rootIdentity, core.ToolchainWorkspaceTrustEdit{ + Workspace: t.Root, + Trusted: trusted, + Location: location, + }) +} + +// saveWorkspaceTrust publishes one trust decision on root against the catalog +// bytes it was read from. +func saveWorkspaceTrust(ctx context.Context, kernel Kernel, catalog *catalogSource, root string, rootIdentity os.FileInfo, edit core.ToolchainWorkspaceTrustEdit) (bool, error) { native, ok := kernel.(catalogKernel) if !ok { return false, ErrPinConflict @@ -124,10 +180,10 @@ func (s Snapshot) SaveWorkspaceTrust(ctx context.Context, kernel Kernel, trusted return false, err } check := func() error { - if err := checkDirectoryIdentity(ctx, s.Root, s.rootIdentity); err != nil { + if err := checkDirectoryIdentity(ctx, root, rootIdentity); err != nil { return err } - if err := s.catalog.file.Verify(ctx); err != nil { + if err := catalog.file.Verify(ctx); err != nil { if errors.Is(err, configfile.ErrConflict) { return errors.Join(ErrPinConflict, err) } @@ -138,14 +194,11 @@ func (s Snapshot) SaveWorkspaceTrust(ctx context.Context, kernel Kernel, trusted if err := check(); err != nil { return false, err } - text, err := s.catalog.file.Text() + text, err := catalog.file.Text() if err != nil { return false, err } - change, err := native.EditToolchainWorkspaceTrust(ctx, text, s.catalog.platform, core.ToolchainWorkspaceTrustEdit{ - Workspace: s.Root, - Trusted: trusted, - }) + change, err := native.EditToolchainWorkspaceTrust(ctx, text, catalog.platform, edit) if err != nil { return false, err } @@ -155,7 +208,7 @@ func (s Snapshot) SaveWorkspaceTrust(ctx context.Context, kernel Kernel, trusted if change.Document == nil { return false, errors.New("toolchain: changed catalog has no source") } - committed, err := s.catalog.file.Replace(ctx, []byte(*change.Document), check) + committed, err := catalog.file.Replace(ctx, []byte(*change.Document), check) if errors.Is(err, configfile.ErrConflict) { err = errors.Join(ErrPinConflict, err) } diff --git a/desktop/internal/toolchain/project_trust_test.go b/desktop/internal/toolchain/project_trust_test.go index b3b9c63b99..8d8b6a6ef3 100644 --- a/desktop/internal/toolchain/project_trust_test.go +++ b/desktop/internal/toolchain/project_trust_test.go @@ -276,12 +276,19 @@ func TestTrustedWorkspacePersistsInLocalSettingsOnlyAndResolvesSymlinkedVenv(t * if err != nil { t.Fatal(err) } - // Revoking trust when already untrusted is a no-op and creates no file. - if changed, err := initial.SaveWorkspaceTrust(ctx, kernel, false); err != nil || changed { - t.Fatalf("no-op revoke = %v, %v", changed, err) + // Revoking trust of a workspace with no decision records the distrust, as IDEA's "Preview in + // Safe Mode" does, in the preference directory and never inside the workspace. + if changed, err := initial.SaveWorkspaceTrust(ctx, kernel, false); err != nil || !changed { + t.Fatalf("revoke without a decision = %v, %v", changed, err) } - if _, statErr := os.Stat(filepath.Join(settingsDir, "toolchains", "global.json")); !errors.Is(statErr, os.ErrNotExist) { - t.Fatalf("no-op revoke created global.json: %v", statErr) + if distrusted, err := ReadWorkspaceTrust(ctx, kernel, settingsDir, root); err != nil || distrusted.State != core.WorkspaceDistrusted { + t.Fatalf("trust after the revoke = %q, %v, want distrusted", distrusted.State, err) + } + if _, statErr := os.Stat(filepath.Join(root, ".lithe")); !errors.Is(statErr, os.ErrNotExist) { + t.Fatalf("revoking workspace trust wrote inside workspace .lithe: %v", statErr) + } + if initial, err = Load(ctx, kernel, root, ".", manifests, options); err != nil { + t.Fatal(err) } // Grant trust for root: stored in settingsDir/toolchains/global.json, NEVER in root/.lithe. diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index caebd72317..bcd41fbf7c 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -280,6 +280,10 @@ type Options struct { // first is the window's first workbench when this one is another project tab of its // window; nil for the first (window_sessions.go). first *App + // trustEveryWorkspace opens every folder trusted without asking. Only the tests' harness + // sets it, as IDEA turns trust checks off in unit-test mode; the project tabs of the window + // share it through the options they are made with. + trustEveryWorkspace bool } // LogSink is the client's log as the window uses it: the log window reads it and the @@ -439,6 +443,9 @@ type project struct { root string // pluginContext belongs to this open project, not to any background consumer. pluginContext pluginservice.ContextRef + // trust says whether the project's code may run; a project opens in safe mode without it + // (workspace_trust.go). + trust projectTrust // indexing is the search exclusion policy the project installed in Core (directory_exclusions.go). indexing projectIndexing // name is the folder's name, shown in the title bar. @@ -724,6 +731,8 @@ type App struct { missing map[string]bool project *project + // trustEveryWorkspace is Options.trustEveryWorkspace; tests of the trust flow clear it. + trustEveryWorkspace bool // toolchainRoot is the open project's root, read by the settings window from // its own thread. Nil means no project is open. toolchainRoot atomic.Pointer[string] @@ -813,6 +822,7 @@ func New(options Options) *App { } a := &App{ kernel: options.Kernel, + trustEveryWorkspace: options.trustEveryWorkspace, documentWriter: documentio.WriteGuarded, documentLinkedWriter: documentio.WriteGuardedLinked, documentCreator: documentio.WriteMissing, @@ -1504,11 +1514,18 @@ func (a *App) openProjectHere(path string) { a.notifyError(a.text.Errors.FolderMissing(root)) return } + a.openProjectByTrust(root) +} + +// openProjectWithTrust closes the open project and opens the folder at root, with its project +// code allowed to run when trusted and in safe mode otherwise (workspace_trust.go). +func (a *App) openProjectWithTrust(root string, trusted bool) { a.requestCloseProject(func() { a.reduceRecent(a.recent, core.RecordRecent(root, a.now()), true) // Every Git command the project runs is kept in the Git console. ctx, cancel := context.WithCancel(core.WithGitConsole(context.Background(), a.gitConsole, root)) p := &project{root: root, name: filepath.Base(root), ctx: ctx, cancel: cancel, commit: newCommitState()} + p.trust.codeAllowed.Store(trusted) a.searchView.reset() a.openTerminals(p) a.project = p @@ -1529,8 +1546,7 @@ func (a *App) openProjectHere(path string) { // The title bar lists the runs the build plugins declare as soon as the project opens, // so its application is found without a press on Run or on the run menu first. Loading // a model runs the plugin's model command, such as mvn, which runs the project's build - // extensions, as the Build window did when it first showed; the toolchain layers leave - // out workspace programs such as a wrapper until the user trusts the workspace. + // extensions, so in safe mode the models stay unloaded until the user trusts the project. a.loadTitleRunConfigs(p) a.restoreEditorSession(p) a.restoreCheckpoints(p) diff --git a/desktop/internal/workbench/app_test.go b/desktop/internal/workbench/app_test.go index 639239d2fd..5663cb929d 100644 --- a/desktop/internal/workbench/app_test.go +++ b/desktop/internal/workbench/app_test.go @@ -99,6 +99,9 @@ func newHarnessWithDriver(t testing.TB, options Options, open func(app.Config) ( } return start.Add(h.driver.Now()) } + // Tests open their folders trusted, as IDEA's unit-test mode does; the trust flow's own tests + // clear it before they open one. + options.trustEveryWorkspace = true h.app = New(options) h.config = h.app.Config() driver, closeDriver, err := open(h.config) diff --git a/desktop/internal/workbench/build.go b/desktop/internal/workbench/build.go index de90e5c248..e8ccbf0948 100644 --- a/desktop/internal/workbench/build.go +++ b/desktop/internal/workbench/build.go @@ -107,6 +107,9 @@ type buildInstance struct { // it, which shows without the warning of a failure. modelError string modelStopped bool + // modelUntrusted says the model was left unloaded because the project is in safe mode; + // trusting the project clears it and loads the model. + modelUntrusted bool // modelVersion counts the models the instance loaded, so a tree laid out from an earlier // one is known stale; trees are the Build window's trees of the model (build_tree.go). modelVersion uint64 @@ -237,7 +240,13 @@ func (b *buildState) active() bool { return b.operation != nil || len(b.running) // startRun starts the application run of key through start, at once when none of that key // runs; otherwise it stops the one that runs and starts the new one once it ended, so the two // never share a port or files. A start that is asked again while one waits replaces it. +// +// In safe mode the user is first asked to trust the project, since a run runs its code. func (a *App) startRun(p *project, key string, start func(*App, *project)) { + if p.safeMode() { + a.askToTrustProject(p, func() { a.startRun(p, key, start) }) + return + } running := p.build.runOf(key) if running == nil { start(a, p) @@ -803,6 +812,15 @@ func (a *App) loadBuildModelWith(p *project, index int, refresh bool) { if instance.modelLoaded || instance.modelLoading { return } + // Loading a model runs the build tool on the project, which safe mode does not allow: a + // reload the user asked for asks to trust the project, which then loads every model. + if p.safeMode() { + a.skipUntrustedModel(instance) + if refresh { + a.askToTrustProject(p, nil) + } + return + } instance.modelLoading = true instance.modelError, instance.modelStopped = "", false captured := *instance @@ -886,6 +904,7 @@ func (a *App) commandModel(ctx context.Context, p *project, instance buildInstan WorkspaceStateDirectory: state, WorkspaceRoot: p.root, OutputFile: outputFile, + ProjectCodeAllowed: p.trust.allowed(), }) if err != nil { return fail(core.StagePlan, err) @@ -1027,6 +1046,7 @@ func (a *App) providerModel(ctx context.Context, p *project, instance buildInsta WorkspaceStateDirectory: "", Refresh: refresh, Tool: tool, + ProjectCodeAllowed: p.trust.allowed(), }) if err != nil { return core.BuildModel{}, err @@ -1227,6 +1247,12 @@ func buildTaskSelection(instance *buildInstance, task *pluginservice.BuildTaskDe // client chose. It returns the execution it reserved; validation refusals are returned instead // so a tool call can report them, and the Build window keeps its notification and ignores them. func (a *App) runBuildTask(p *project, projectID, targetID, taskID string, userArguments []string) (*buildOperation, error) { + // A task runs the build tool on the project: in safe mode the user is asked to trust it + // first, and the task starts once trusted. The caller, such as the IDE API, is refused. + if p.safeMode() { + a.askToTrustProject(p, func() { _, _ = a.runBuildTask(p, projectID, targetID, taskID, userArguments) }) + return nil, refuseBuild(refusalNotReady, "the workspace is not trusted") + } instance := p.selectedBuildInstance() if instance == nil || taskID == "" { a.notify(a.text.Build.ChooseTask) @@ -1240,10 +1266,11 @@ func (a *App) runBuildTask(p *project, projectID, targetID, taskID string, userA return nil, refuseBuild(refusalNotFound, "unknown build task") } request := core.BuildPlanRequest{ - Root: instance.Root, - Options: instance.Options, - WorkspaceRoot: p.root, - UserArguments: append([]string(nil), userArguments...), + Root: instance.Root, + Options: instance.Options, + WorkspaceRoot: p.root, + UserArguments: append([]string(nil), userArguments...), + ProjectCodeAllowed: p.trust.allowed(), } if projectID != "" { project, ok := buildProjectByID(instance.Model, projectID) @@ -1737,12 +1764,13 @@ func (a *App) debugProviderTarget(p *project, index int, projectID, targetID, ru reference := core.RunProviderReference{PluginID: captured.PluginID, BuildSystemID: captured.BuildSystemID, Root: captured.Root} rerun := func() { a.redebugProviderTarget(p, reference, projectID, targetID, runID) } request := core.BuildPlanRequest{ - Root: captured.Root, - Options: captured.Options, - WorkspaceRoot: p.root, - Run: runID, - Project: &core.BuildSelection{Name: project.Name, Path: project.Path, Properties: project.Properties}, - Target: &core.BuildSelection{Name: target.Name, Path: target.Path, Tags: target.Tags, Properties: target.Properties}, + Root: captured.Root, + Options: captured.Options, + WorkspaceRoot: p.root, + Run: runID, + Project: &core.BuildSelection{Name: project.Name, Path: project.Path, Properties: project.Properties}, + Target: &core.BuildSelection{Name: target.Name, Path: target.Path, Tags: target.Tags, Properties: target.Properties}, + ProjectCodeAllowed: p.trust.allowed(), } p.debug.preparing = true fail := func(err error) func(*App) { @@ -1884,14 +1912,15 @@ func (a *App) runBuildTargetWith(p *project, op *buildOperation, instance *build prepare, release := op.bind(bounded) defer release() request := core.BuildPlanRequest{ - Root: captured.Root, - Options: captured.Options, - WorkspaceRoot: p.root, - Run: runID, - Project: &core.BuildSelection{Name: project.Name, Path: project.Path, Properties: project.Properties}, - Target: selectedTarget, - LaunchOptions: options, - OptionOverrides: overrides, + Root: captured.Root, + Options: captured.Options, + WorkspaceRoot: p.root, + Run: runID, + Project: &core.BuildSelection{Name: project.Name, Path: project.Path, Properties: project.Properties}, + Target: selectedTarget, + LaunchOptions: options, + OptionOverrides: overrides, + ProjectCodeAllowed: p.trust.allowed(), } a.addBuildToolHint(prepare, p, captured, &request) plan, err := kernel.PlanBuildRun(prepare, captured.Manifest, captured.BuildSystemID, request) diff --git a/desktop/internal/workbench/build_dependencies.go b/desktop/internal/workbench/build_dependencies.go index 02963168cd..6383f300aa 100644 --- a/desktop/internal/workbench/build_dependencies.go +++ b/desktop/internal/workbench/build_dependencies.go @@ -126,7 +126,7 @@ func (a *App) buildDependencyTree(ctx context.Context, p *project, instance buil return fail(core.StageResolve, err) } // The package directory expands ${pluginDir} in a dependency command. - request := core.BuildPlanRequest{Root: instance.Root, Options: instance.Options, PluginDirectory: instance.PackageDirectory, WorkspaceRoot: p.root, Project: selection} + request := core.BuildPlanRequest{Root: instance.Root, Options: instance.Options, PluginDirectory: instance.PackageDirectory, WorkspaceRoot: p.root, Project: selection, ProjectCodeAllowed: p.trust.allowed()} decode := core.BuildDecodeDependenciesRequest{WorkspaceRoot: p.root, Root: instance.Root} if selection != nil { decode.Project = selection.Path diff --git a/desktop/internal/workbench/build_tests.go b/desktop/internal/workbench/build_tests.go index 4ac0cb0a74..67a5063f89 100644 --- a/desktop/internal/workbench/build_tests.go +++ b/desktop/internal/workbench/build_tests.go @@ -216,7 +216,7 @@ func (a *App) buildTestDiscovery(ctx context.Context, p *project, instance build if err != nil { return core.BuildTestDiscovery{}, err } - request := core.BuildPlanRequest{Root: instance.Root, Options: instance.Options, WorkspaceRoot: p.root, Refresh: refresh} + request := core.BuildPlanRequest{Root: instance.Root, Options: instance.Options, WorkspaceRoot: p.root, Refresh: refresh, ProjectCodeAllowed: p.trust.allowed()} if execution.Executable != "" { request.Tool = &core.BuildTool{Executable: execution.Executable, Environment: execution.Environment} } diff --git a/desktop/internal/workbench/editor_view.go b/desktop/internal/workbench/editor_view.go index 96405ccf70..c5977d5ce2 100644 --- a/desktop/internal/workbench/editor_view.go +++ b/desktop/internal/workbench/editor_view.go @@ -91,6 +91,9 @@ func (a *App) editorGroup(c ui.C, id string) ui.Box { } }) }) + if doc != nil && p.safeMode() { + a.safeModeNotice(c.Part("safeMode"), p) + } if doc != nil && doc.conflicted { a.documentConflict(c, doc) } diff --git a/desktop/internal/workbench/runconfig_before_launch.go b/desktop/internal/workbench/runconfig_before_launch.go index 78db2299df..23277ec715 100644 --- a/desktop/internal/workbench/runconfig_before_launch.go +++ b/desktop/internal/workbench/runconfig_before_launch.go @@ -209,6 +209,7 @@ func (a *App) runBeforeLaunchTask(ctx context.Context, p *project, run beforeLau return run.kernel.PlanBeforeLaunchTask(ctx, manifest, task.BuildSystemID, run.root, core.BeforeLaunchTaskPlanRequest{ Task: task, WorkingDirectory: step.WorkingDirectory, Instances: sources.instances, PluginDirectory: sources.pluginDirectory, WorkspaceStateDirectory: sources.stateDirectory, + ProjectCodeAllowed: p.trust.allowed(), }) }) if err == nil { diff --git a/desktop/internal/workbench/runconfig_types.go b/desktop/internal/workbench/runconfig_types.go index 7537360c2e..91557049df 100644 --- a/desktop/internal/workbench/runconfig_types.go +++ b/desktop/internal/workbench/runconfig_types.go @@ -266,6 +266,7 @@ func (a *App) declaredRunSpec(ctx context.Context, p *project, kernel Kernel, ro return kernel.PlanRunConfiguration(ctx, manifest, key.BuildSystemID, root, core.RunConfigurationPlanRequest{ ConfigurationID: id, Instances: sources.instances, PluginDirectory: sources.pluginDirectory, WorkspaceStateDirectory: sources.stateDirectory, + ProjectCodeAllowed: p.trust.allowed(), }) }) } diff --git a/desktop/internal/workbench/settings_toolchains.go b/desktop/internal/workbench/settings_toolchains.go index 08eaab840b..6507fd8b66 100644 --- a/desktop/internal/workbench/settings_toolchains.go +++ b/desktop/internal/workbench/settings_toolchains.go @@ -72,7 +72,11 @@ func (s settingsToolchains) SetWorkspaceTrust(ctx context.Context, snapshot tool if _, err := snapshot.SaveWorkspaceTrust(ctx, s.app.kernel, trusted); err != nil { return snapshot, err } - s.app.post(func(a *App) { a.retryFailedPluginServers() }) + // The open project leaves or enters safe mode with the decision. + s.app.post(func(a *App) { + a.retryFailedPluginServers() + a.reloadProjectTrust(a.project) + }) updated, err = s.loadAt(ctx, snapshot.Root) if err != nil { return snapshot, errors.Join(toolchain.ErrPinCommitted, err) diff --git a/desktop/internal/workbench/tests.go b/desktop/internal/workbench/tests.go index d746e3406c..f3a30ed1a3 100644 --- a/desktop/internal/workbench/tests.go +++ b/desktop/internal/workbench/tests.go @@ -196,6 +196,10 @@ func (a *App) startTests(p *project, selection testSelection) { if p == nil || p.tests.running { return } + if p.safeMode() { + a.askToTrustProject(p, func() { a.startTests(p, selection) }) + return + } instance := p.buildInstanceByID(selection.instanceID) if instance == nil || instance.System.Test == nil { a.notifyInfo(a.text.Tests.NoSystems) @@ -226,14 +230,15 @@ func (a *App) startTests(p *project, selection testSelection) { // the publication callback; Core calls happen here, never on the window thread. func (a *App) executeTestRun(ctx context.Context, p *project, instance buildInstance, selection testSelection, generation uint64, startedMillis int64) func(*App) { request := core.BuildTestRequest{ - Root: instance.Root, - Options: instance.Options, - WorkspaceRoot: p.root, - Project: selection.project, - Target: selection.target, - Suite: selection.suite, - Case: selection.caseName, - Projects: selection.projects, + Root: instance.Root, + Options: instance.Options, + WorkspaceRoot: p.root, + Project: selection.project, + Target: selection.target, + Suite: selection.suite, + Case: selection.caseName, + Projects: selection.projects, + ProjectCodeAllowed: p.trust.allowed(), } plan, err := a.kernel.PlanBuildTest(ctx, instance.Manifest, instance.BuildSystemID, request) if err != nil { diff --git a/desktop/internal/workbench/title_run_entrypoints.go b/desktop/internal/workbench/title_run_entrypoints.go index e11863eec2..0db8581018 100644 --- a/desktop/internal/workbench/title_run_entrypoints.go +++ b/desktop/internal/workbench/title_run_entrypoints.go @@ -39,6 +39,10 @@ type entrypointFound struct { // loaded first, since the configuration names the model's project; a press waits for it as a // press on a configuration does. func (a *App) runCurrentFileEntrypoint(p *project) { + if p.safeMode() { + a.askToTrustProject(p, func() { a.runCurrentFileEntrypoint(p) }) + return + } s := &p.runConfigs if s.findingEntrypoint { return @@ -141,7 +145,7 @@ func (a *App) findEntrypoint(ctx context.Context, p *project, kernel Kernel, can // runEntrypoints plans, sends and decodes one instance's lithe/build/runEntrypoints request. func (a *App) runEntrypoints(ctx context.Context, p *project, kernel Kernel, instance buildInstance, file string) ([]core.BuildRunEntrypoint, error) { - request := core.BuildPlanRequest{Root: instance.Root, Options: instance.Options, PluginDirectory: instance.PackageDirectory, WorkspaceRoot: p.root, File: file} + request := core.BuildPlanRequest{Root: instance.Root, Options: instance.Options, PluginDirectory: instance.PackageDirectory, WorkspaceRoot: p.root, File: file, ProjectCodeAllowed: p.trust.allowed()} plan, err := kernel.PlanBuildRunEntrypoints(ctx, instance.Manifest, instance.BuildSystemID, request) if err != nil { return nil, err diff --git a/desktop/internal/workbench/workspace_trust.go b/desktop/internal/workbench/workspace_trust.go new file mode 100644 index 0000000000..050bb3ec34 --- /dev/null +++ b/desktop/internal/workbench/workspace_trust.go @@ -0,0 +1,276 @@ +package workbench + +import ( + "context" + "os" + "path/filepath" + "sync/atomic" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/1lck/Lithe-IDEA/desktop/internal/toolchain" + "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/ui" +) + +// Workspace trust follows IntelliJ IDEA's trusted projects. Before a folder Lithe has no +// decision for opens, the user is asked to trust it, to preview it in safe mode or not to open +// it; trusting may cover every project of the parent folder. The decision is machine-local, +// kept by Core in the toolchain catalog of the preference directory (toolchains/global.json), +// never in the project. In safe mode the project's code is not run: models are not loaded and +// Core refuses the plans that would run the build tool, a wrapper or a build extension +// (plugin.build.untrustedWorkspace). A run, build, test or reload the user asks for first asks +// to trust the project, and the notice above the editor offers it too. + +// workspaceTrustTimeout bounds reading or saving a trust decision: a Core call and a look at +// the workspace folder. +const workspaceTrustTimeout = 10 * time.Second + +// projectTrust is the trust of an open project. +type projectTrust struct { + // codeAllowed tells the plans built on background goroutines whether the project's code may + // run (BuildPlanRequest.ProjectCodeAllowed and the like). + codeAllowed atomic.Bool + // asking is set while the question to trust the project is shown, so a second action does + // not queue a second question. + asking bool +} + +// allowed reports whether the project's code may run; any goroutine may ask. +func (t *projectTrust) allowed() bool { return t.codeAllowed.Load() } + +// safeMode reports whether p is open without trust. +func (p *project) safeMode() bool { return p != nil && !p.trust.allowed() } + +// openProjectByTrust opens the folder at root once its trust is known. A trusted folder opens at +// once; one the user previewed in safe mode before opens in safe mode; for one with no +// decision the user is asked first, and "Don't Open" leaves the open project as it was. A +// decision that cannot be read opens the folder in safe mode, from where it can be trusted. +func (a *App) openProjectByTrust(root string) { + if a.trustEveryWorkspace { + a.openProjectWithTrust(root, true) + return + } + kernel, globalRoot := a.kernel, a.globalToolchainRoot() + a.background(nil, workspaceTrustTimeout, func(ctx context.Context) func(*App) { + trust, err := toolchain.ReadWorkspaceTrust(ctx, kernel, globalRoot, root) + return func(a *App) { + switch { + case err != nil: + a.backgroundFailed("workspace_trust_read", err) + a.openProjectWithTrust(root, false) + case trust.State == core.WorkspaceTrusted: + a.openProjectWithTrust(root, true) + case trust.State == core.WorkspaceDistrusted: + a.openProjectWithTrust(root, false) + default: + a.askToOpenUntrusted(trust) + } + } + }) +} + +// askToOpenUntrusted asks before a folder with no trust decision opens: "Trust and Open +// Project", as IDEA asks. The parent folder is offered when Core may trust it as a location. +func (a *App) askToOpenUntrusted(trust toolchain.WorkspaceTrust) { + language := a.language() + prompt := &pluginPrompt{ + title: i18n.SharedFormat(language, "desktop.trust.openTitle", map[string]string{"project": filepath.Base(trust.Root)}), + text: i18n.Shared(language, "desktop.trust.openText"), + actions: []string{ + i18n.Shared(language, "desktop.trust.dontOpen"), + i18n.Shared(language, "desktop.trust.previewSafeMode"), + i18n.Shared(language, "desktop.trust.trustProject"), + }, + } + if trust.OfferedLocation != nil { + home, _ := os.UserHomeDir() + prompt.check = i18n.SharedFormat(language, "desktop.trust.location", map[string]string{"folder": trustFolderLabel(*trust.OfferedLocation, home)}) + } + prompt.onAnswer = func(choice *int) { + if choice == nil || *choice == 0 { + // A project tab made to open the folder has nothing to show without it. + if a.project == nil { + a.sessions.leave(a) + } + return + } + trusted := *choice == 2 + a.saveWorkspaceTrust(trust, trusted, trusted && prompt.checked, func(saved bool) { + a.openProjectWithTrust(trust.Root, trusted && saved) + }) + } + a.prompts.queue = append(a.prompts.queue, prompt) +} + +// trustFolderMaxRunes is the longest folder the trust question's checkbox names in full: the +// checkbox is one line in a dialog 520 points wide. +const trustFolderMaxRunes = 48 + +// trustFolderLabel is how the checkbox names folder: under home as "~" plus the rest, as IDEA +// writes it, and a longer one with its middle left out, so its start and its own name stay. +func trustFolderLabel(folder, home string) string { + label := []rune(welcomeShorten(folder, home)) + if len(label) <= trustFolderMaxRunes { + return string(label) + } + head := trustFolderMaxRunes / 3 + tail := trustFolderMaxRunes - head - 1 + return string(label[:head]) + "…" + string(label[len(label)-tail:]) +} + +// saveWorkspaceTrust records the user's decision and calls done with whether it was kept. A +// decision that cannot be saved is told and logged; the caller then treats the workspace as +// not trusted, since nothing on disk says it is. +func (a *App) saveWorkspaceTrust(trust toolchain.WorkspaceTrust, trusted, location bool, done func(saved bool)) { + kernel := a.kernel + if trusted { + a.performed("workspace.trust.grant", surfaceButton) + } else { + a.performed("workspace.trust.distrust", surfaceButton) + } + a.background(nil, workspaceTrustTimeout, func(ctx context.Context) func(*App) { + _, err := trust.Save(ctx, kernel, trusted, location) + return func(a *App) { + if err != nil { + a.backgroundFailed("workspace_trust_save", err) + a.notifyError(i18n.SharedFormat(a.language(), "desktop.trust.saveFailed", map[string]string{"reason": err.Error()})) + } + done(err == nil) + } + }) +} + +// requireProjectTrust runs proceed at once in a trusted project. In safe mode it first asks +// to trust the project ("Trust Project" or "Stay in Safe Mode"); proceed runs once the trust +// is saved, and not at all when the user stays in safe mode. +func (a *App) requireProjectTrust(p *project, proceed func()) { + if p == nil { + return + } + if !p.safeMode() { + proceed() + return + } + a.askToTrustProject(p, proceed) +} + +// askToTrustProject asks to trust the open project p in safe mode, from the notice above the +// editor or before an action that runs project code; then, when set, it runs proceed. +func (a *App) askToTrustProject(p *project, proceed func()) { + if p.trust.asking { + return + } + p.trust.asking = true + language := a.language() + a.prompts.queue = append(a.prompts.queue, &pluginPrompt{ + title: i18n.Shared(language, "desktop.trust.title"), + text: i18n.Shared(language, "desktop.trust.actionText"), + actions: []string{ + i18n.Shared(language, "desktop.trust.stayInSafeMode"), + i18n.Shared(language, "desktop.trust.trustProject"), + }, + onAnswer: func(choice *int) { + p.trust.asking = false + if choice == nil || *choice != 1 || a.project != p { + return + } + a.trustOpenProject(p, proceed) + }, + }) +} + +// trustOpenProject saves the trust of the open project p, read again so the decision is saved +// against the catalog as it is now, and leaves safe mode. +func (a *App) trustOpenProject(p *project, proceed func()) { + kernel, globalRoot, root := a.kernel, a.globalToolchainRoot(), p.root + a.background(p, workspaceTrustTimeout, func(ctx context.Context) func(*App) { + trust, err := toolchain.ReadWorkspaceTrust(ctx, kernel, globalRoot, root) + return func(a *App) { + if err != nil { + a.backgroundFailed("workspace_trust_read", err) + a.notifyError(i18n.SharedFormat(a.language(), "desktop.trust.saveFailed", map[string]string{"reason": err.Error()})) + return + } + a.saveWorkspaceTrust(trust, true, false, func(saved bool) { + if !saved || a.project != p { + return + } + a.applyProjectTrust(p, true) + if proceed != nil { + proceed() + } + }) + } + }) +} + +// reloadProjectTrust reads the trust of the open project again, after the settings window +// changed it, and applies it. +func (a *App) reloadProjectTrust(p *project) { + if p == nil || a.trustEveryWorkspace { + return + } + kernel, globalRoot, root := a.kernel, a.globalToolchainRoot(), p.root + a.background(p, workspaceTrustTimeout, func(ctx context.Context) func(*App) { + trust, err := toolchain.ReadWorkspaceTrust(ctx, kernel, globalRoot, root) + return func(a *App) { + if err != nil { + a.backgroundFailed("workspace_trust_read", err) + return + } + if a.project == p { + a.applyProjectTrust(p, trust.State == core.WorkspaceTrusted) + } + } + }) +} + +// applyProjectTrust makes trusted the trust of p. Leaving safe mode loads what safe mode left +// out: the models, and through them the run configurations of the title bar, and the language +// servers that failed for want of the workspace's tools. +func (a *App) applyProjectTrust(p *project, trusted bool) { + was := p.trust.allowed() + p.trust.codeAllowed.Store(trusted) + if !trusted || was { + return + } + for index := range p.build.instances { + instance := &p.build.instances[index] + if instance.modelUntrusted { + instance.modelUntrusted, instance.modelStopped, instance.modelError = false, false, "" + } + } + a.loadTitleRunConfigs(p) + a.retryFailedPluginServers() +} + +// skipUntrustedModel keeps the model of instance unloaded in safe mode, since loading it runs +// the build tool. The Build window says so in place of the model, and a reload asks to trust. +func (a *App) skipUntrustedModel(instance *buildInstance) { + instance.modelUntrusted, instance.modelStopped = true, true + instance.modelError = i18n.Shared(a.language(), "desktop.trust.modelSafeMode") +} + +// safeModeNotice declares the notice above the editor of a project in safe mode, with the link +// that asks to trust it, as IDEA's editor notification does. +func (a *App) safeModeNotice(c ui.C, p *project) { + background, border, foreground := gfx.RGB24(0xFFF6E9), gfx.RGB24(0xF4CD9A), gfx.RGB24(0x000000) + if a.colors.Dark { + background, border, foreground = gfx.RGB24(0x44321D), gfx.RGB24(0x694820), gfx.RGB24(0xD1D3D9) + } + language := a.language() + ui.Column(c).FillWidth().Shrink(0).Background(background).Children(func() { + ui.Row(c.Part("top")).FillWidth().Height(1).Shrink(0).Background(border) + ui.Row(c).FillWidth().Gap(conflictGap).PadX(conflictPadX).PadY(conflictPadY).Items(ui.Center).Children(func() { + ui.Icon(c, icons.BannerWarning).Size(conflictIcon, conflictIcon).Shrink(0).Color(gfx.RGB24(0xFFFFFF)) + ui.Paragraph(c, i18n.Shared(language, "desktop.trust.banner"), conflictMaxRows).FontSize(13).Color(foreground).Grow(1).Shrink(1) + if ui.Button(c.Key("trust"), i18n.Shared(language, "desktop.trust.bannerLink")).Link().Disabled(p.trust.asking).Clicked() { + c.After(func() { a.askToTrustProject(p, nil) }) + } + }) + ui.Row(c.Part("bottom")).FillWidth().Height(1).Shrink(0).Background(border) + }) +} diff --git a/desktop/internal/workbench/workspace_trust_test.go b/desktop/internal/workbench/workspace_trust_test.go new file mode 100644 index 0000000000..ecab664161 --- /dev/null +++ b/desktop/internal/workbench/workspace_trust_test.go @@ -0,0 +1,197 @@ +package workbench + +import ( + "os" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" +) + +// trustHarness is a window that asks about trust, as a user's does: the harness otherwise +// opens every folder trusted. Its trust decisions go to the toolchain catalog in the window's +// own temporary preference directory. +func trustHarness(t *testing.T) *harness { + t.Helper() + h := newHarness(t, &testKernel{Client: core.NewClient()}) + h.app.trustEveryWorkspace = false + return h +} + +// trustFolder is a new folder named name in a new parent folder. +func trustFolder(t *testing.T, name string) string { + t.Helper() + dir := filepath.Join(t.TempDir(), name) + if err := os.Mkdir(dir, 0o755); err != nil { + t.Fatal(err) + } + return dir +} + +// openAsking opens dir and waits for the question about trusting it. +func openAsking(t *testing.T, h *harness, dir string) *pluginPrompt { + t.Helper() + h.app.openProjectHere(dir) + awaitStateWithin(t, h, 10*time.Second, "the trust question", func() bool { return len(h.app.prompts.queue) == 1 }) + h.settle() + return h.app.prompts.queue[0] +} + +// awaitOpened waits until dir is the open project. +func awaitOpened(t *testing.T, h *harness, dir string) *project { + t.Helper() + awaitStateWithin(t, h, 10*time.Second, "the project to open", func() bool { + return h.app.project != nil && h.app.project.root == dir + }) + return h.app.project +} + +// reopen closes the open project and opens dir again. +func reopen(t *testing.T, h *harness, dir string) *project { + t.Helper() + h.app.closeProject() + awaitStateWithin(t, h, 10*time.Second, "the project to close", func() bool { return h.app.project == nil }) + h.app.openProjectHere(dir) + return awaitOpened(t, h, dir) +} + +func TestTrustingAFolderOpensItAndIsRemembered(t *testing.T) { + h := trustHarness(t) + dir := trustFolder(t, "demo") + language := h.app.language() + + prompt := openAsking(t, h, dir) + if h.app.project != nil { + t.Fatal("the folder opened before the user answered") + } + title := i18n.SharedFormat(language, "desktop.trust.openTitle", map[string]string{"project": "demo"}) + home, _ := os.UserHomeDir() + location := i18n.SharedFormat(language, "desktop.trust.location", map[string]string{"folder": trustFolderLabel(filepath.Dir(dir), home)}) + if prompt.title != title || !h.shows(i18n.Shared(language, "desktop.trust.previewSafeMode")) || !h.shows(location) { + t.Fatalf("the question is %q with the check %q, want %q offering the parent folder", prompt.title, prompt.check, title) + } + + h.clickShared("desktop.trust.trustProject") + p := awaitOpened(t, h, dir) + if p.safeMode() { + t.Fatal("a trusted project opened in safe mode") + } + if p = reopen(t, h, dir); p.safeMode() || len(h.app.prompts.queue) != 0 { + t.Fatalf("reopening asked again (%d questions) or opened in safe mode", len(h.app.prompts.queue)) + } + if _, err := os.Stat(filepath.Join(dir, ".lithe")); !os.IsNotExist(err) { + t.Fatalf("trusting wrote into the project: %v", err) + } +} + +func TestTrustingTheParentFolderTrustsItsOtherProjects(t *testing.T) { + h := trustHarness(t) + dir := trustFolder(t, "first") + sibling := filepath.Join(filepath.Dir(dir), "second") + if err := os.Mkdir(sibling, 0o755); err != nil { + t.Fatal(err) + } + + openAsking(t, h, dir) + h.clickLabeled(h.app.prompts.queue[0].check) + if !h.app.prompts.queue[0].checked { + t.Fatal("clicking the parent folder's checkbox did not check it") + } + h.clickShared("desktop.trust.trustProject") + awaitOpened(t, h, dir) + + if p := reopen(t, h, sibling); p.safeMode() || len(h.app.prompts.queue) != 0 { + t.Fatal("a project in the trusted folder was not trusted") + } +} + +func TestDontOpenLeavesTheWindowAsItWas(t *testing.T) { + h := trustHarness(t) + dir := trustFolder(t, "demo") + + openAsking(t, h, dir) + h.clickShared("desktop.trust.dontOpen") + h.settle() + if h.app.project != nil || len(h.app.prompts.queue) != 0 { + t.Fatal("Don't Open opened the folder or left the question") + } + // Nothing was decided, so the next open asks again. + openAsking(t, h, dir) +} + +func TestSafeModeKeepsProjectCodeFromRunningUntilTrusted(t *testing.T) { + h := trustHarness(t) + dir := trustFolder(t, "demo") + source := filepath.Join(dir, "Main.java") + if err := os.WriteFile(source, []byte("class Main {}\n"), 0o644); err != nil { + t.Fatal(err) + } + language := h.app.language() + + openAsking(t, h, dir) + h.clickShared("desktop.trust.previewSafeMode") + p := awaitOpened(t, h, dir) + if !p.safeMode() { + t.Fatal("Preview in Safe Mode opened the project trusted") + } + // The choice is remembered: the folder opens in safe mode without asking. + if p = reopen(t, h, dir); !p.safeMode() || len(h.app.prompts.queue) != 0 { + t.Fatal("reopening a folder previewed in safe mode asked again or trusted it") + } + + // A model is not loaded: loading one runs the build tool. + setDetected(p, []buildInstance{{BuildInstance: core.BuildInstance{ID: "fixture:."}}}) + h.app.loadBuildModel(p, 0) + if instance := p.build.instances[0]; instance.modelLoading || !instance.modelUntrusted || instance.modelError != i18n.Shared(language, "desktop.trust.modelSafeMode") { + t.Fatalf("in safe mode the model load = loading %v, untrusted %v, %q", instance.modelLoading, instance.modelUntrusted, instance.modelError) + } + + // A run asks first; staying in safe mode runs nothing. + ran := 0 + h.app.startRun(p, "app", func(*App, *project) { ran++ }) + awaitStateWithin(t, h, 10*time.Second, "the question before the run", func() bool { return len(h.app.prompts.queue) == 1 }) + h.settle() + h.clickShared("desktop.trust.stayInSafeMode") + h.settle() + if ran != 0 || !p.safeMode() { + t.Fatal("staying in safe mode ran the program or left safe mode") + } + + // The notice above the editor offers to trust the project; trusting it leaves safe mode. + h.app.openFile(p, source) + h.settle() + if !h.shows(i18n.Shared(language, "desktop.trust.banner")) { + t.Fatal("the editor does not say the project is in safe mode") + } + h.clickShared("desktop.trust.bannerLink") + awaitStateWithin(t, h, 10*time.Second, "the trust question", func() bool { return len(h.app.prompts.queue) == 1 }) + h.settle() + h.clickShared("desktop.trust.trustProject") + awaitStateWithin(t, h, 10*time.Second, "the project to leave safe mode", func() bool { return !p.safeMode() }) + h.settle() + if h.shows(i18n.Shared(language, "desktop.trust.banner")) { + t.Fatal("the safe mode notice stayed after trusting the project") + } + if p.build.instances[0].modelUntrusted { + t.Fatal("trusting the project left the model unloaded for safe mode") + } + h.app.startRun(p, "app", func(*App, *project) { ran++ }) + if ran != 1 { + t.Fatalf("a run in the trusted project ran %d times, want at once", ran) + } +} + +func TestTrustFolderLabelShortensHomeAndLongPaths(t *testing.T) { + home := filepath.Join(string(filepath.Separator)+"Users", "ann") + if got, want := trustFolderLabel(filepath.Join(home, "IdeaProjects"), home), "~"+string(filepath.Separator)+"IdeaProjects"; got != want { + t.Fatalf("label = %q, want %q", got, want) + } + long := filepath.Join(string(filepath.Separator)+"srv", "builds", "a-very-long-folder-name-for-every-checkout", "of-the-team", "projects") + got := []rune(trustFolderLabel(long, home)) + if len(got) != trustFolderMaxRunes || string(got[:5]) != string([]rune(long)[:5]) || !strings.HasSuffix(string(got), "projects") || !strings.Contains(string(got), "…") { + t.Fatalf("long label = %q, want %d runes keeping its start and its own name", string(got), trustFolderMaxRunes) + } +} diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index a5aabf2655..e3215c3d20 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -27,7 +27,12 @@ native_path() { fi } -# Lithe-core-rust main at ce628c7: #116, squash-merged into main: content search and its index read +# Lithe-core-rust branch feat/workspace-trust at 150c857 (#118, on top of main 06a4c79, #117 plugin +# SDK documentation only): the toolchain catalog records a decision on each workspace (trusted, +# distrusted for safe mode, or unknown) and trusted locations, toolchains.catalogState reports it as +# workspaceTrust, and build plan requests take projectCodeAllowed, without which every plan that +# runs project code is refused as plugin.build.untrustedWorkspace (#2201). +# Below it, Lithe-core-rust main at ce628c7: #116, squash-merged into main: content search and its index read # every file the editor opens as text (up to 16 MiB, decoded like file.read, binary files skipped) # and match a CRLF line without its \r; replacement previews still read only strict UTF-8 up to # 2 MiB. It is on top of #115 (929b8c6, documentation only), #112 (44d62e4, command test @@ -279,7 +284,7 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # the contract, plugin guides, reference and SDKs live only in shared/plugins; on top of #16 (reported Git queries folded in the console), # #15 (git.write cherryPick, revert and reset fields), #14 (word-level changed ranges of diff # rows), #13, #8, #7, #6 and #4. -PINNED_CORE_REVISION="ce628c7e00c5707a6321eaf9a3062402c980d208" +PINNED_CORE_REVISION="150c857efc3c286798e224a9d04b78d062eba9ce" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index 8d3e2f935b..4b7ce26cf8 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -1680,6 +1680,19 @@ "desktop.tools.dragHint": "Drag to move elsewhere", "desktop.tools.withShortcut": "{name} {keys}", "desktop.tools.structure": "Structure", + "desktop.trust.actionText": "Loading, running, building or testing this project may run code from its build scripts. If you don’t trust the source, stay in safe mode.", + "desktop.trust.banner": "Safe mode, limited functionality. Trust the project to access full IDE functionality.", + "desktop.trust.bannerLink": "Trust Project…", + "desktop.trust.dontOpen": "Don’t Open", + "desktop.trust.location": "Trust all projects in the “{folder}” folder", + "desktop.trust.modelSafeMode": "Safe mode: the model is not loaded. Reload to trust the project and load it.", + "desktop.trust.openText": "Lithe provides features that may run code from this folder, such as build scripts, build wrappers and build-tool extensions. If you don’t trust the source, preview the project in safe mode to only browse its code.", + "desktop.trust.openTitle": "Trust and Open Project “{project}”?", + "desktop.trust.previewSafeMode": "Preview in Safe Mode", + "desktop.trust.saveFailed": "Could not save the trust decision: {reason}", + "desktop.trust.stayInSafeMode": "Stay in Safe Mode", + "desktop.trust.title": "Trust Project?", + "desktop.trust.trustProject": "Trust Project", "desktop.welcome.emptyHint": "Open a local folder to start working.", "desktop.welcome.emptyTitle": "No recent projects", "desktop.welcome.menuPin": "Pin to Top", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 6dcbe1be61..d6d470ca09 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -1680,6 +1680,19 @@ "desktop.tools.dragHint": "可拖动到其他位置", "desktop.tools.withShortcut": "{name} {keys}", "desktop.tools.structure": "结构", + "desktop.trust.actionText": "加载、运行、构建或测试此项目可能会运行其构建脚本中的代码。如果不信任来源,请保持安全模式。", + "desktop.trust.banner": "安全模式,功能受限。信任此项目后即可使用完整的 IDE 功能。", + "desktop.trust.bannerLink": "信任项目…", + "desktop.trust.dontOpen": "不打开", + "desktop.trust.location": "信任“{folder}”文件夹中的所有项目", + "desktop.trust.modelSafeMode": "安全模式:未加载项目模型。点击重新加载可信任项目并加载。", + "desktop.trust.openText": "Lithe 的部分功能可能运行此文件夹中的代码,例如构建脚本、构建包装器和构建工具扩展。如果不信任来源,请以安全模式预览项目,只浏览代码。", + "desktop.trust.openTitle": "信任并打开项目“{project}”?", + "desktop.trust.previewSafeMode": "以安全模式预览", + "desktop.trust.saveFailed": "无法保存信任设置:{reason}", + "desktop.trust.stayInSafeMode": "保持安全模式", + "desktop.trust.title": "信任项目?", + "desktop.trust.trustProject": "信任项目", "desktop.welcome.emptyHint": "打开本地文件夹开始工作。", "desktop.welcome.emptyTitle": "没有最近项目", "desktop.welcome.menuPin": "固定到顶部", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index a6fcb6328e..9d8795e15a 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -20228,6 +20228,106 @@ "desktop" ] }, + { + "id": "desktop.trust.actionText", + "description": "Body of the question asked before running, building or testing a project in safe mode", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trust.banner", + "description": "Notice above the editor while the project is in safe mode", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trust.bannerLink", + "description": "Link in the safe mode notice that asks to trust the project", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trust.dontOpen", + "description": "Button that cancels opening an untrusted project", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trust.location", + "description": "Checkbox in the trust question that also trusts every project in the parent folder. {folder} is that folder", + "platforms": [ + "desktop" + ], + "parameters": { + "folder": "string" + } + }, + { + "id": "desktop.trust.modelSafeMode", + "description": "Build window line in place of a model that is not loaded because the project is in safe mode", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trust.openText", + "description": "Body of the question asked before an untrusted project opens", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trust.openTitle", + "description": "Title of the question asked before a project Lithe has no trust decision for opens. {project} is the folder name", + "platforms": [ + "desktop" + ], + "parameters": { + "project": "string" + } + }, + { + "id": "desktop.trust.previewSafeMode", + "description": "Button that opens the project in safe mode without trusting it", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trust.saveFailed", + "description": "Error shown when the trust decision could not be saved. {reason} is the cause", + "platforms": [ + "desktop" + ], + "parameters": { + "reason": "string" + } + }, + { + "id": "desktop.trust.stayInSafeMode", + "description": "Button that keeps the project in safe mode and cancels the action", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trust.title", + "description": "Title of the question asked before an action runs project code in a project opened in safe mode", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trust.trustProject", + "description": "Button that trusts the project", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.updates.available", "description": "Notice after an update check Lithe made by itself finds a newer version of the channel; its button opens the update dialog. The green arrow is the update button at the top right of the title bar.", diff --git a/shared/platform-feature-matrix/features/workspace-trust.json b/shared/platform-feature-matrix/features/workspace-trust.json new file mode 100644 index 0000000000..e9ade6db16 --- /dev/null +++ b/shared/platform-feature-matrix/features/workspace-trust.json @@ -0,0 +1,27 @@ +{ + "id": "workspace-trust", + "area": "工作区", + "group": "工作区生命周期", + "capability": "工作区信任与安全模式", + "macos": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/workspace_trust.go", + "desktop/internal/workbench/workspace_trust_test.go", + "desktop/internal/toolchain/catalog.go" + ] + }, + "windows": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/workspace_trust.go", + "desktop/internal/workbench/workspace_trust_test.go", + "desktop/internal/toolchain/catalog.go" + ] + }, + "owner": "Workspace", + "verification": "打开一个没有信任记录的文件夹,先出现“信任并打开项目”对话框,按钮依次为不打开、以安全模式预览、信任项目,并可勾选信任父文件夹;不打开时当前项目不变。信任后再次打开不再询问;勾选父文件夹后同级项目直接以信任打开。以安全模式预览后,编辑器上方显示安全模式提示条,构建窗口不加载模型,运行、构建、测试和重新加载前先问“信任项目?”,选择保持安全模式时不运行;点提示条的“信任项目…”信任后提示条消失,模型和标题栏运行配置自动加载。确认偏好目录 toolchains/global.json 记录决定,项目目录中没有新增 .lithe 文件。", + "notes": "2026-11-19(#2201):对齐 IntelliJ IDEA 的可信项目。信任状态(trusted/distrusted/unknown 与可信位置)由 Core 的工具链目录判定,计划请求带 projectCodeAllowed,Core 拒绝会运行项目代码的计划(plugin.build.untrustedWorkspace)。宿主无平台分支,两个平台共用同一实现;尚未在两个平台做真实应用验收。语言服务器和 Git 在安全模式下仍启动、可信位置没有独立设置页,分别由 #2208、#2207 跟进。" +} From a81b5d90a0ae58a380883ee9089fe3a81ca6b659 Mon Sep 17 00:00:00 2001 From: lick <2188718831@qq.com> Date: Thu, 19 Nov 2026 04:07:47 -0800 Subject: [PATCH 5/5] chore(desktop): pin Core to main 98e6940 with workspace trust (#118) merged Co-Authored-By: Claude Opus 5.5 --- scripts/desktop/build-desktop-core.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index e3215c3d20..6a2b0e2d5e 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -27,7 +27,7 @@ native_path() { fi } -# Lithe-core-rust branch feat/workspace-trust at 150c857 (#118, on top of main 06a4c79, #117 plugin +# Lithe-core-rust main at 98e6940 (#119 protocol changelog only) on top of #118 (8c77c3f, on top of #117 plugin # SDK documentation only): the toolchain catalog records a decision on each workspace (trusted, # distrusted for safe mode, or unknown) and trusted locations, toolchains.catalogState reports it as # workspaceTrust, and build plan requests take projectCodeAllowed, without which every plan that @@ -284,7 +284,7 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # the contract, plugin guides, reference and SDKs live only in shared/plugins; on top of #16 (reported Git queries folded in the console), # #15 (git.write cherryPick, revert and reset fields), #14 (word-level changed ranges of diff # rows), #13, #8, #7, #6 and #4. -PINNED_CORE_REVISION="150c857efc3c286798e224a9d04b78d062eba9ce" +PINNED_CORE_REVISION="98e694049fde68b61a3783c69e341ec887e06049" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in