diff --git a/.agents/notes/implemented/bug-fix/2026-09-20-oversized-java-launch-command.md b/.agents/notes/archived/bug-fix/2026-09-20-oversized-java-launch-command.md similarity index 97% rename from .agents/notes/implemented/bug-fix/2026-09-20-oversized-java-launch-command.md rename to .agents/notes/archived/bug-fix/2026-09-20-oversized-java-launch-command.md index c361b2f1bb..1616e0994e 100644 --- a/.agents/notes/implemented/bug-fix/2026-09-20-oversized-java-launch-command.md +++ b/.agents/notes/archived/bug-fix/2026-09-20-oversized-java-launch-command.md @@ -2,6 +2,10 @@ 状态:已实现 +归档日期:2026-11-13 + +> 已被[超长启动命令由插件缩短,宿主只按字节写临时文件](../../implemented/architecture/2026-11-13-plugin-owned-long-command-lines.md)取代。Core 的 `execution.planLaunchCommand` 和桌面端的参数文件写入已删除,下文描述的是旧客户端时期的做法。 + ## 先说结论 Java 项目现在由项目 JDK 直接启动,JDT 解析出的运行时 classpath 会原样出现在命令行上。 diff --git a/.agents/notes/implemented/architecture/2026-11-13-plugin-owned-long-command-lines.md b/.agents/notes/implemented/architecture/2026-11-13-plugin-owned-long-command-lines.md new file mode 100644 index 0000000000..46df162a77 --- /dev/null +++ b/.agents/notes/implemented/architecture/2026-11-13-plugin-owned-long-command-lines.md @@ -0,0 +1,77 @@ +# Agent 笔记:超长启动命令由插件缩短,宿主只按字节写临时文件 + +状态:已实现 + +## 先说结论 + +依赖很多的 Java 项目,命令行会超过 Windows 的 32767 个 UTF-16 字符上限,进程根本创建不出来。以前由 Core 的 `execution.planLaunchCommand` 判断长度、把类路径搬进 JDK 参数文件(argfile,`java @文件` 读取的选项文件),再由桌面端按系统代码页写文件。 + +Core 不能认识 Java,所以这条路径整个删掉了:Core 删除 `execution.planLaunchCommand`(Lithe-IDEA/Lithe-core-rust#23),桌面端删除 `launch_plan.go`、`runargs.go`、`argfile_encoding_*.go`。现在宿主按原样启动插件给出的命令行。命令行需要缩短时,由插件自己生成参数文件或 classpath JAR,通过 `run/start` 的 `temporaryFiles` 交给宿主写入。 + +对日常开发的直接影响:宿主和 Core 里不要再出现“这是不是 JDK”“这个选项是不是类路径”之类的判断;任何语言的命令行缩短都在插件里做。 + +## 问题 + +旧做法把三件只属于 Java 的事放进了通用层: + +1. **识别启动器。** Core 要知道 `java` 能读参数文件、JDK 9 以上才支持、JDK 8 要改用 classpath JAR。宿主要去读 JDK 的 `release` 文件确定版本。 +2. **识别选项。** Core 要知道 `-cp`、`--module-path` 是路径列表,遇到主类、`-jar`、`-m` 要停止搬运。 +3. **选择编码。** Windows 上 JDK 启动器按系统 ANSI 代码页读取参数文件,宿主为此写了一份只服务 Java 的编码器。 + +这违反“Core 对语言零依赖、零特判,语言知识全部由插件注入”的规则。Go、Node、.NET 也有各自的长命令行问题,按旧做法每种语言都要在 Core 里加一套。 + +## 决策 + +### 正确做法 + +1. **宿主按原样启动。** `desktop/internal/pluginservice/runs.go` 不再改写参数。插件给什么命令行,就启动什么命令行。 +2. **插件决定是否缩短、怎么缩短、用什么编码。** 插件知道自己的工具:Java 插件知道 JDK 版本、哪些选项能搬、启动器读文件时用什么编码。生成的文件放进 `run/start` 的 `temporaryFiles`,参数里写 `${temporaryFile:}` 引用它。 +3. **文件内容有两种形式。** `{name, contents}` 是 UTF-8 文本;`{name, base64}` 是插件自己编码好的字节,宿主解码后原样写入,不转码。需要系统代码页的 Windows 参数文件、二进制的 classpath JAR 都用 `base64`。两种字段同时给出或都不给,Core 拒绝。 +4. **校验在 Core,写入在宿主。** Core 的 `run.decodeStart` 检查个数(最多 4 个)、名字、大小(每个最多 4 MiB)和 base64 是否合法,并给出每个文件在临时目录里的路径。宿主只负责创建这次运行的临时目录、写入文件、运行结束后删除。 + +例子: + +```text +正确:Java 插件算出命令行超长 → 生成按代码页编码的参数文件 → + run/start { arguments: ["@${temporaryFile:args}", "Main"], + temporaryFiles: [{ name: "args", base64: "..." }] } + → 宿主写文件、启动 java + +不要这样做:宿主看到可执行文件名是 java,就去读 release 文件、自己拼参数文件。 +``` + +### 插件实现时仍然成立的事实 + +这些来自旧实现的排查结论,Java 插件实现缩短时必须遵守(插件侧工作见 Lithe-IDEA/lithe-plugin-java#7): + +- 只搬路径列表选项。JVM 选项、主类和程序参数留在命令行上;遇到主类、`-jar`、`-m` 或 `--module` 之后的参数属于应用程序,必须原样保留。 +- JEP 400 不改变 Windows 启动器读取参数文件的编码。不能因为 JDK 18 以上就写 UTF-8,要按系统 ANSI 代码页编码;代码页放不下的字符要报错,不能替换成问号。双字节字符的尾字节是 `0x5c` 时要再写一个 `0x5c`。 +- JDK 8 不认识参数文件,改用只含 `META-INF/MANIFEST.MF` 的 classpath JAR;manifest 里的路径写成绝对 `file:` URL,目录以 `/` 结尾。 +- 只有不缩短就必定失败时才缩短,普通长度的命令行保持原样。 + +## 考虑过的备选方案 + +- **保留 Core 的规划,只把名字改得中立。** 不采用:规划逻辑本身就要识别 JDK 和 Java 选项,换个名字仍然是 Java 特判。 +- **宿主提供一个“按系统代码页编码文本”的通用服务,插件只给 UTF-8 文本。** 不采用:“哪个程序用哪种编码读文件”是工具知识。Java 启动器用 ANSI 代码页,别的工具可能用 UTF-8 或 UTF-16;由宿主猜就又回到按程序名特判。插件直接给字节,宿主不需要知道编码。 +- **插件自己选目录写文件。** 不采用:文件只属于一次运行,生命周期应跟着运行走。由宿主在运行结束、启动失败或 Core 拒绝时统一删除,插件后端崩溃或被停用也不会留下文件;插件也不需要知道临时目录在哪里。 +- **改用 `CLASSPATH` 环境变量。** 不采用:Windows 对单个环境变量和整个环境块同样有 32767 的限制。 + +## 后果 + +- Core 和宿主不再包含任何 Java 启动知识,新增语言不需要改 Core。 +- `temporaryFiles` 成为所有插件都能用的通用能力:任何需要写临时文件的启动都可以用,内容可以是任意字节。 +- 代价:在 Java 插件接上缩短逻辑之前,Windows 上依赖很多的 Java 项目会因命令行超长无法启动。macOS 的 `ARG_MAX` 远大于 Windows 上限,实际不受影响。 +- 代价:每个需要缩短命令行的插件都要自己实现,不能复用 Core 的规划器。Java 插件已经有从 Core 移植的规划代码(`crates/java-domain/src/execution/`),只缺接线和 Windows 编码。 +- 运行临时目录 `/lithe-run-/` 在 `scripts/resources/worktree-resources.json` 的 `run-temporary-files` 中登记为不可复用资源,任何阶段都不得跨工作树复制,也不写发行目录。 + +## 验证 + +- `./scripts/desktop/desktop-go.sh test ./internal/pluginservice/ -run TestRunStartWritesTemporaryFilesAsGiven`:进程读到的文件与插件给出的内容逐字节一致,包括非 UTF-8 字节和空文件。 +- `./scripts/desktop/desktop-go.sh test ./internal/core/ -run TestDecodeRunStartFollowsTheContractFixture`:回放 Core 的 `run-start.json`,覆盖 `contents` 和 `base64` 同时给出、都不给、base64 不合法的拒绝。 +- `node scripts/resources/test-reuse-worktree-resources.mjs`:`run-temporary-files` 不能跨工作树复用。 + +## 适用范围 + +- 宿主:`desktop/internal/pluginservice/runs.go`、`desktop/internal/core/run_start.go` +- 资源登记:`scripts/resources/worktree-resources.json` +- 取代的笔记:`.agents/notes/archived/bug-fix/2026-09-20-oversized-java-launch-command.md` diff --git a/desktop/internal/core/launch_plan.go b/desktop/internal/core/launch_plan.go deleted file mode 100644 index 2bcb6f9581..0000000000 --- a/desktop/internal/core/launch_plan.go +++ /dev/null @@ -1,36 +0,0 @@ -package core - -import "context" - -// LaunchCommandRequest is a process launch for Core to fit to the command-line limit -// (execution.planLaunchCommand). Arguments do not include the executable. -// JavaReleaseContents are the release files of the JDK the launcher may belong to, nearest -// first, as the host read them; Core reads the version from the first with JAVA_VERSION. -type LaunchCommandRequest struct { - Executable string `json:"executable"` - Arguments []string `json:"arguments"` - JavaFeatureVersion *int `json:"javaFeatureVersion,omitempty"` - JavaReleaseContents []string `json:"javaReleaseContents,omitempty"` -} - -// LaunchArgumentFile is the JDK argument file a planned launch reads: Text in Unicode, and -// the index of the argument the host replaces with "@" and the file's path. -type LaunchArgumentFile struct { - Text string `json:"text"` - ArgumentIndex int `json:"argumentIndex"` -} - -// LaunchCommandPlan is the launch to start: Arguments unchanged and ArgumentFile nil when it -// fits, otherwise the arguments with a placeholder for the argument file. -type LaunchCommandPlan struct { - Arguments []string `json:"arguments"` - ArgumentFile *LaunchArgumentFile `json:"argumentFile"` -} - -// PlanLaunchCommand asks Core whether a launch needs an argument file to fit the command -// line, and what goes into it. -func (c *Client) PlanLaunchCommand(ctx context.Context, request LaunchCommandRequest) (LaunchCommandPlan, error) { - var plan LaunchCommandPlan - err := c.Execute(ctx, "execution.planLaunchCommand", request, &plan) - return plan, err -} diff --git a/desktop/internal/core/run_start.go b/desktop/internal/core/run_start.go index 275d05b264..ad8bec7141 100644 --- a/desktop/internal/core/run_start.go +++ b/desktop/internal/core/run_start.go @@ -2,6 +2,7 @@ package core import ( "context" + "encoding/base64" "encoding/json" ) @@ -14,9 +15,23 @@ type RunStartExecutable struct { } // RunStartFile is a temporary file the host writes before the process starts. +// Core gives exactly one of Contents (UTF-8 text) and Base64 (standard padded +// base64 of bytes the plugin encoded itself, such as a JDK argument file in the +// Windows ANSI code page); an empty file has an empty Contents. type RunStartFile struct { Path string `json:"path"` Contents string `json:"contents"` + Base64 string `json:"base64,omitempty"` +} + +// Bytes returns the bytes to write: the decoded Base64 when Core gave bytes, +// otherwise Contents unchanged. Core has already checked the encoding and the +// size limit, so an error means Core and the host disagree on the contract. +func (f RunStartFile) Bytes() ([]byte, error) { + if f.Base64 != "" { + return base64.StdEncoding.DecodeString(f.Base64) + } + return []byte(f.Contents), nil } // RunStartDebug makes a run a debug session. Target.Kind is "connection" (the diff --git a/desktop/internal/pluginservice/argfile_encoding_other.go b/desktop/internal/pluginservice/argfile_encoding_other.go deleted file mode 100644 index 98c06b8fa1..0000000000 --- a/desktop/internal/pluginservice/argfile_encoding_other.go +++ /dev/null @@ -1,9 +0,0 @@ -//go:build !windows - -package pluginservice - -// encodeArgumentFile is the argument file as the launcher reads it: the JDK launchers of -// macOS and Linux read UTF-8. -func encodeArgumentFile(text string) ([]byte, error) { - return []byte(text), nil -} diff --git a/desktop/internal/pluginservice/argfile_encoding_windows.go b/desktop/internal/pluginservice/argfile_encoding_windows.go deleted file mode 100644 index 6d0b0456d1..0000000000 --- a/desktop/internal/pluginservice/argfile_encoding_windows.go +++ /dev/null @@ -1,68 +0,0 @@ -//go:build windows - -package pluginservice - -import ( - "errors" - "fmt" - "unicode/utf16" - "unsafe" - - "golang.org/x/sys/windows" -) - -var ( - kernel32 = windows.NewLazySystemDLL("kernel32.dll") - procGetACP = kernel32.NewProc("GetACP") - procWideCharToMultiByte = kernel32.NewProc("WideCharToMultiByte") -) - -const ( - codePageUTF8 = 65001 - wcNoBestFitChars = 0x00000400 - argfileBackslash = '\\' - maxCodePageBytes = 8 - errUnrepresentable = "the path character %q cannot be written in the system code page %d; move the project or its libraries to a path without it" -) - -// encodeArgumentFile is the argument file as the Windows JDK launcher reads it: in the -// system (ANSI) code page, whatever the JDK version, since the launcher's arguments are not -// UTF-8. A character the code page cannot hold is an error, never a substitute. The -// launcher parses the file by bytes, so a backslash byte that is the trail byte of a -// double-byte character is doubled; Core quotes every value, so each is inside quotes. -func encodeArgumentFile(text string) ([]byte, error) { - acp, _, _ := procGetACP.Call() - if acp == codePageUTF8 { - return []byte(text), nil - } - out := make([]byte, 0, len(text)) - var buffer [maxCodePageBytes]byte - for _, r := range text { - if r < 0x80 { - out = append(out, byte(r)) - continue - } - units := utf16.Encode([]rune{r}) - var usedDefault int32 - n, _, err := procWideCharToMultiByte.Call(acp, wcNoBestFitChars, - uintptr(unsafe.Pointer(&units[0])), uintptr(len(units)), - uintptr(unsafe.Pointer(&buffer[0])), uintptr(len(buffer)), - 0, uintptr(unsafe.Pointer(&usedDefault))) - if n == 0 { - if err == nil { - err = errors.New("WideCharToMultiByte failed") - } - return nil, err - } - if usedDefault != 0 { - return nil, fmt.Errorf(errUnrepresentable, r, acp) - } - for _, b := range buffer[:n] { - if b == argfileBackslash { - out = append(out, argfileBackslash) - } - out = append(out, b) - } - } - return out, nil -} diff --git a/desktop/internal/pluginservice/runargs.go b/desktop/internal/pluginservice/runargs.go deleted file mode 100644 index b432a9f1b3..0000000000 --- a/desktop/internal/pluginservice/runargs.go +++ /dev/null @@ -1,97 +0,0 @@ -package pluginservice - -import ( - "context" - "errors" - "os" - "path/filepath" - - "github.com/1lck/Lithe-IDEA/desktop/internal/core" -) - -// A launch whose command line would overflow the operating system's limit starts with its -// path-list options in a JDK argument file. Core decides (execution.planLaunchCommand): -// whether the launcher is a JDK that reads argument files, what moves, and the file's text. -// The host reads the JDK's release files for it, encodes the text as the launcher reads it -// (argfile_encoding_*.go) and owns the file. - -// argumentFileName names the argument file a shortened launch reads. -const argumentFileName = "launch.args" - -// launchPlanner is the part of Core the run launch uses. -type launchPlanner interface { - PlanLaunchCommand(ctx context.Context, request core.LaunchCommandRequest) (core.LaunchCommandPlan, error) -} - -// planLaunch asks Core to fit a launch to the command line. A plan without an argument file -// starts the launch as it is. -func planLaunch(ctx context.Context, kernel launchPlanner, executable string, arguments []string) (core.LaunchCommandPlan, error) { - return kernel.PlanLaunchCommand(ctx, core.LaunchCommandRequest{ - Executable: executable, - Arguments: append([]string{}, arguments...), - JavaReleaseContents: javaReleaseContents(executable), - }) -} - -// javaReleaseContents reads the release files of the JDK the executable may belong to, -// nearest first: the one beside its bin directory, then the one above it (a JDK 8 jre/bin -// launcher). A link to the launcher is followed first. Unreadable files are left out. -func javaReleaseContents(executable string) []string { - if resolved, err := filepath.EvalSymlinks(executable); err == nil { - executable = resolved - } - home := filepath.Dir(filepath.Dir(executable)) - var contents []string - for _, directory := range []string{home, filepath.Dir(home)} { - if data, err := os.ReadFile(filepath.Join(directory, "release")); err == nil { - contents = append(contents, string(data)) - } - } - return contents -} - -// launchArguments writes the plan's argument file into directory and returns the arguments -// that read it; a plan without one returns its arguments. -func launchArguments(plan core.LaunchCommandPlan, directory string) ([]string, error) { - file := plan.ArgumentFile - if file == nil { - return plan.Arguments, nil - } - if file.ArgumentIndex < 0 || file.ArgumentIndex >= len(plan.Arguments) { - return nil, errors.New("the launch plan names no argument for its file") - } - data, err := encodeArgumentFile(file.Text) - if err != nil { - return nil, err - } - path, err := writeArgumentFile(directory, data) - if err != nil { - return nil, err - } - arguments := append([]string(nil), plan.Arguments...) - arguments[file.ArgumentIndex] = "@" + path - return arguments, nil -} - -// writeArgumentFile writes the argument file into directory, readable by the owner only. -// The file is made new, so a launch never reads another's. -func writeArgumentFile(directory string, data []byte) (string, error) { - if directory == "" { - return "", errors.New("the argument file has no directory") - } - path := filepath.Join(directory, argumentFileName) - file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600) - if err != nil { - return "", err - } - if _, err := file.Write(data); err != nil { - file.Close() - os.Remove(path) - return "", err - } - if err := file.Close(); err != nil { - os.Remove(path) - return "", err - } - return path, nil -} diff --git a/desktop/internal/pluginservice/runs.go b/desktop/internal/pluginservice/runs.go index 3887229bdf..d5043ace05 100644 --- a/desktop/internal/pluginservice/runs.go +++ b/desktop/internal/pluginservice/runs.go @@ -341,7 +341,11 @@ func (r *Runs) handleStart(ctx context.Context, params json.RawMessage) (json.Ra return nil, refusal } for _, file := range start.TemporaryFiles { - if err := os.WriteFile(file.Path, []byte(file.Contents), 0o600); err != nil { + data, err := file.Bytes() + if err == nil { + err = os.WriteFile(file.Path, data, 0o600) + } + if err != nil { cleanup() return nil, failure(pluginhost.CodeHostFailure, "a temporary file cannot be written") } @@ -393,35 +397,12 @@ func (r *Runs) handleStart(ctx context.Context, params json.RawMessage) (json.Ra } }} } else { - // A JDK launch whose class path would overflow the command line starts with an - // argument file in the run's temporary directory, removed when the run ends. Core - // plans it; a kernel that cannot leaves the launch as it is. - arguments := start.Arguments - if planner, ok := r.service.kernel.(launchPlanner); ok { - plan, err := planLaunch(runCtx, planner, executable, start.Arguments) - if err != nil { - cancel() - cleanup() - return nil, failure(pluginhost.CodeHostFailure, err.Error()) - } - if plan.ArgumentFile != nil && temporary == "" { - temporary, err = os.MkdirTemp("", "lithe-run-") - if err != nil { - cancel() - cleanup() - return nil, failure(pluginhost.CodeHostFailure, "the run's temporary directory cannot be created") - } - } - arguments, err = launchArguments(plan, temporary) - if err != nil { - cancel() - cleanup() - return nil, failure(pluginhost.CodeHostFailure, "the run's argument file cannot be written: "+err.Error()) - } - } + // The command line is the plugin's, started as it is. A launch that would + // overflow the system limit is the plugin's to shorten, for example with an + // argument file passed in temporaryFiles. spawned, err := buildprocess.Start(runCtx, buildprocess.Spec{ Executable: executable, - Arguments: arguments, + Arguments: start.Arguments, WorkingDirectory: workingDirectory, Environment: environment, }, func(_ buildprocess.Stream, text string) { diff --git a/desktop/internal/pluginservice/runs_test.go b/desktop/internal/pluginservice/runs_test.go index d6b6c4749d..dece0c4544 100644 --- a/desktop/internal/pluginservice/runs_test.go +++ b/desktop/internal/pluginservice/runs_test.go @@ -2,6 +2,7 @@ package pluginservice import ( "context" + "encoding/base64" "encoding/json" "fmt" "github.com/1lck/Lithe-IDEA/desktop/internal/contractfixture" @@ -55,6 +56,16 @@ func TestRunHelperProcess(t *testing.T) { case "sleep": time.Sleep(time.Minute) os.Exit(0) + case "files": + // Prints each file named in LITHE_RUN_FILES as hex, one line per file. + for _, path := range strings.Split(os.Getenv("LITHE_RUN_FILES"), string(os.PathListSeparator)) { + data, err := os.ReadFile(path) + if err != nil { + os.Exit(2) + } + fmt.Printf("file %x\n", data) + } + os.Exit(0) case "listen": listener, err := net.Listen("tcp", "127.0.0.1:"+os.Getenv("LITHE_RUN_PORT")) if err != nil { @@ -208,6 +219,49 @@ func TestRunStartReportsOutputAndTheExitCode(t *testing.T) { } } +// TestRunStartWritesTemporaryFilesAsGiven checks that the process finds each +// temporary file with exactly the plugin's contents: text as UTF-8, and base64 +// bytes unchanged, including bytes that are not UTF-8. +func TestRunStartWritesTemporaryFilesAsGiven(t *testing.T) { + h := newRunHarness(t) + bytes := []byte{0x2d, 0x63, 0x70, 0x20, 0x95, 0x5c, 0x5c, 0x00, 0xff, 0x0a} + params := h.params(t, "files", map[string]any{ + "temporaryFiles": []map[string]string{ + {"name": "text", "contents": "-cp \"é\"\n"}, + {"name": "bytes", "base64": base64.StdEncoding.EncodeToString(bytes)}, + {"name": "empty", "base64": ""}, + }, + }) + var decoded map[string]any + if err := json.Unmarshal([]byte(params), &decoded); err != nil { + t.Fatal(err) + } + process := decoded["process"].(map[string]any) + process["environment"].(map[string]any)["LITHE_RUN_FILES"] = strings.Join([]string{ + "${temporaryFile:text}", "${temporaryFile:bytes}", "${temporaryFile:empty}", + }, string(os.PathListSeparator)) + data, err := json.Marshal(decoded) + if err != nil { + t.Fatal(err) + } + result, refusal := respond(t, h.service, runFixturePlugin, "run/start", string(data)) + startedRunID(t, result, refusal) + events := h.await(t, "the run to exit", func(events []RunEvent) bool { return exitedEvent(events) != nil }) + var output strings.Builder + for _, event := range events { + if event.Type == RunOutput { + output.WriteString(event.Text) + } + } + want := fmt.Sprintf("file %x\nfile %x\nfile \n", []byte("-cp \"é\"\n"), bytes) + if got := strings.ReplaceAll(output.String(), "\r\n", "\n"); !strings.Contains(got, want) { + t.Fatalf("output = %q, want %q", got, want) + } + if exited := exitedEvent(events); exited.ExitCode == nil || *exited.ExitCode != 0 { + t.Fatalf("exit = %+v, want code 0", exited) + } +} + func TestRunStopEndsTheRunAndOnlyForItsOwner(t *testing.T) { h := newRunHarness(t) result, refusal := respond(t, h.service, runFixturePlugin, "run/start", h.params(t, "sleep", nil)) diff --git a/docs/ci-builds.md b/docs/ci-builds.md index cacc92ee81..f923a6a963 100644 --- a/docs/ci-builds.md +++ b/docs/ci-builds.md @@ -828,13 +828,14 @@ Viva 的 `app.RegisterFont` 把字型按内容摘要暂存到用户缓存目录 `excludedResources.sparkle-baseline-staging` 经排除路由直接拒绝,任何复制阶段 都不得跨工作树复用;每次发布仍从选定的 GitHub Release 下载基线。 -- Java 启动临时文件:`/lithe-run/launch--.argfile` - 和同目录的 `.classpath.jar` 由平台启动 adapter 为单次执行独占创建,包含该次 - 执行的绝对类路径、工作目录、JDK 版本及编码语义,没有可复用的版本、平台、架构 - 或工具链 identity stamp。准备失败、准备完成前已取消、启动失败或进程退出后由 - 所有者删除;系统临时目录由平台解析,不写安装包或 JDK,不影响签名或增量更新。 - `excludedResources.java-launch-temporaries` 经复用脚本的排除路由直接拒绝,任何 - 复制阶段都不得共享;内容哈希相同也不能转移进程所有权。 +- 插件运行的临时文件:`/lithe-run-/`。插件在 `run/start` 的 + `temporaryFiles` 里给出文件时,桌面端运行服务为这次运行单独创建这个目录,按插件给的 + 文本或字节写入文件,例如 Java 插件生成的 JDK 参数文件或 classpath JAR。文件内容是该次 + 运行的类路径、工作目录和插件选定的编码,没有可复用的版本、平台、架构或工具链 + identity stamp。Core 拒绝启动、进程无法启动或运行结束后,运行服务删除整个目录; + 系统临时目录由平台解析,不写安装包或工具链目录,不影响签名或增量更新。 + `excludedResources.run-temporary-files` 经复用脚本的排除路由直接拒绝,任何复制阶段 + 都不得共享;内容哈希相同也不能转移进程所有权。 - Agent CLI 的用户级安装与下载缓存:npm 的 global prefix/cache、Homebrew 的 Cellar/Caskroom/cache、用户目录下 `.local/share/claude/versions`。它们由运行时 diff --git a/docs/viva-migration.md b/docs/viva-migration.md index a069027777..d327648076 100644 --- a/docs/viva-migration.md +++ b/docs/viva-migration.md @@ -409,7 +409,7 @@ | `run-output-snapshot` | 运行输出快照 | 必须迁移 | 缺/实现 | 完成 | `workbench/runs.go` | | `login-shell-environment` | 从 Finder / Dock 启动时继承登录 shell 的环境 | 平台专属 | 实现/专属 | 完成 | `loginenv/loginenv_unix.go`、`cmd/lithe/main.go` | | `run-discovery` | 入口点与运行配置发现 | 必须迁移 | 实现/实现 | 部分 | `core/run_discovery.go` | -| `run-java-long-classpath` | 超长 Java 类路径自动缩短 | 插件提供 | 插件/实现 | 未开始 | 扩展点:executablePlan/argfile;无 desktop/ 证据 | +| `run-java-long-classpath` | 超长 Java 类路径自动缩短 | 插件提供 | 插件/实现 | 未开始 | 扩展点:`run/start` 的 `temporaryFiles`(文本或 base64 字节);插件接线见 Lithe-IDEA/lithe-plugin-java#7 | | `run-java-test` | Java main 与测试运行 | 插件提供 | 实现/实现 | 未开始 | 扩展点:executionProviders、test 模型;无 desktop/ 证据 | | `run-node-launch-path` | Node 生态运行脚本的启动 PATH | 必须迁移 | 实现/实现 | 部分 | `workbench/toolchains.go` | | `run-save-toolchain` | 保存前同步与工具链解析 | 必须迁移 | 实现/实现 | 部分 | `workbench/toolchains.go` | diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index ef6b693c60..3de62bc76b 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -28,16 +28,17 @@ native_path() { } PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" -# Lithe-core-rust #22 (IDE find/replace, recovery, preferences, navigation, keymaps and -# Scratch lifecycle), squash-merged into main, on top of #21 (debug.setBreakpointsMuted, debug.planMemoryWindow and +# Lithe-core-rust #23 (Java, Maven and JDT special cases removed, execution.planLaunchCommand +# among them; run/start temporaryFiles may carry base64 bytes) on top of #22 (IDE find/replace, +# recovery, preferences, navigation, keymaps and Scratch lifecycle), squash-merged into main, on top of #21 (debug.setBreakpointsMuted, debug.planMemoryWindow and # debug.locateMemoryWindow, runConfig.decideTitleAction), squash-merged into main, on top of #20 # (lsp.declarationOrUsages and the references operation's includeDeclaration, for Go to # Declaration or Usages), #19 (MCP configuration and library commands removed) and #17: the plugin contract is one # baseline with pluginAPIVersion and every capability, protocol and document version at 0, and # 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 (execution.planLaunchCommand), #8, #7, #6 and #4. -PINNED_CORE_REVISION="65cf82343c5e315aae2e335b2e8f0217b703e89a" +# rows), #13, #8, #7, #6 and #4. +PINNED_CORE_REVISION="5a8e67d4b73f5e633e67dc09e722c3b22b47b280" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/scripts/resources/test-reuse-worktree-resources.mjs b/scripts/resources/test-reuse-worktree-resources.mjs index e0ee15c04d..df7da7a402 100644 --- a/scripts/resources/test-reuse-worktree-resources.mjs +++ b/scripts/resources/test-reuse-worktree-resources.mjs @@ -318,13 +318,13 @@ try { assert.notEqual(refused.status, 0); assert.match(diagnostics(refused), /frontend-install-state.*node_modules.*bun-tmp.*cannot be reused/); }); - await test("Java launch files are never listed or copied between worktrees", { timeout: 15000 }, () => { + await test("run temporary files are never listed or copied between worktrees", { timeout: 15000 }, () => { const listed = run(process.execPath, [reuseScript, "--list"]); assertSucceeded(listed); - assert.ok(!listed.stdout.includes("java-launch-temporaries")); - const refused = reuse(["--resource", "java-launch-temporaries"]); + assert.ok(!listed.stdout.includes("run-temporary-files")); + const refused = reuse(["--resource", "run-temporary-files"]); assert.notEqual(refused.status, 0); - assert.match(diagnostics(refused), /java-launch-temporaries.*classpath\.jar.*cannot be reused/); + assert.match(diagnostics(refused), /run-temporary-files.*lithe-run-.*cannot be reused/); }); await test("IDE MCP credentials and helpers cannot cross worktrees", { timeout: 15000 }, () => { const refused = reuse(["--resource", "ide-mcp"]); diff --git a/scripts/resources/worktree-resources.json b/scripts/resources/worktree-resources.json index 145b444caf..6d08350945 100644 --- a/scripts/resources/worktree-resources.json +++ b/scripts/resources/worktree-resources.json @@ -324,14 +324,13 @@ "reason": "Build helpers separately before packaging; never copy runtime connection files or locks. Installed helpers remain read-only. There is no permitted worktree copy stage." }, { - "id": "java-launch-temporaries", + "id": "run-temporary-files", "locations": [ - "/lithe-run/launch--.argfile", - "/lithe-run/launch--.classpath.jar" + "/lithe-run-/" ], "reusable": false, - "identity": "Owned by one Java execution: absolute classpath, working directory, JDK version and native encoding. No reusable version/platform/architecture/toolchain identity stamp.", - "reason": "Created exclusively by the platform launch adapter and deleted on preparation failure, cancelled launch, spawn failure or process exit. Never copy, publish or share between worktrees at any stage; installed bundles and JDK directories remain read-only." + "identity": "Owned by one plugin-started run: the run/start temporaryFiles the plugin gave, such as a JDK argument file or classpath JAR in the encoding the plugin chose. No reusable version/platform/architecture/toolchain identity stamp.", + "reason": "Created by the desktop run service only when a run/start names temporary files, and removed when the start is refused, the process cannot start or the run ends. Never copy, publish or share between worktrees at any stage; installed bundles and toolchain directories remain read-only." }, { "id": "platform-feature-matrix", diff --git a/shared/platform-feature-matrix/features/run-java-long-classpath.json b/shared/platform-feature-matrix/features/run-java-long-classpath.json index 320cd83f91..f24d730eb0 100644 --- a/shared/platform-feature-matrix/features/run-java-long-classpath.json +++ b/shared/platform-feature-matrix/features/run-java-long-classpath.json @@ -4,31 +4,25 @@ "group": "运行配置", "capability": "超长 Java 类路径自动缩短", "macos": { - "implementationStatus": "implemented", - "verificationStatus": "pending", + "implementationStatus": "plugin-provided", + "verificationStatus": "not-applicable", "evidence": [ "docs/viva-migration.md", - "desktop/internal/pluginservice/runargs.go", - "desktop/internal/pluginservice/argfile_encoding_windows.go", - "desktop/internal/pluginservice/argfile_encoding_other.go", "desktop/internal/pluginservice/runs.go", - "desktop/internal/core/launch_plan.go" + "desktop/internal/core/run_start.go" ] }, "windows": { - "implementationStatus": "implemented", - "verificationStatus": "pending", + "implementationStatus": "plugin-provided", + "verificationStatus": "not-applicable", "evidence": [ "docs/viva-migration.md", - "desktop/internal/pluginservice/runargs.go", - "desktop/internal/pluginservice/argfile_encoding_windows.go", - "desktop/internal/pluginservice/argfile_encoding_other.go", "desktop/internal/pluginservice/runs.go", - "desktop/internal/core/launch_plan.go" + "desktop/internal/core/run_start.go" ] }, "owner": "Run", - "verification": "使用包含大量依赖的 Java 项目运行 main,确认超长类路径自动写入参数文件、进程可启动且参数文件在退出后清理。 Windows 上分别用 JDK 8 和 JDK 17 运行同一个依赖很多、路径含空格和中文的项目 main:JDK 8 应在临时目录生成只含 META-INF/MANIFEST.MF 的 .classpath.jar 并以 -cp 引用,JDK 17 仍使用 @argfile;两者都能启动,进程退出或启动失败后临时文件被删除,安装目录与 JDK 目录不新增文件。 在慢速网络盘 classpath 准备期间确认工作台可交互;停止或重新运行后,旧准备结果不得启动进程,旧 executionId 的停止请求不得影响新执行。 macOS 从 JDK release 文件读取原始内容并交 Core 解析现代及旧版版本,未知版本不启用参数文件。 macOS:该能力由独立的 Java/Maven/Gradle 插件(Lithe-IDEA/lithe-plugin-java、lithe-plugin-maven、lithe-plugin-gradle)实现,宿主只验证通用契约与接线,运行时验证记录归插件仓库。", + "verification": "独立源码由 https://github.com/Lithe-IDEA/lithe-plugin-java 维护,运行时验证记录归插件仓库(Lithe-IDEA/lithe-plugin-java#7):Windows 上分别用 JDK 8 和 JDK 17 运行同一个依赖很多、路径含空格和中文的项目 main,JDK 8 用只含 META-INF/MANIFEST.MF 的 classpath JAR,JDK 17 用 @argfile,两者都能启动;参数文件按系统 ANSI 代码页编码,代码页放不下的字符明确报错。宿主只验证通用契约:run/start 的 temporaryFiles 按文本或 base64 字节原样写入宿主为这次运行创建的临时目录,进程退出、启动失败或 Core 拒绝后删除该目录,安装目录与工具链目录不新增文件(desktop/internal/pluginservice/runs_test.go 的 TestRunStartWritesTemporaryFilesAsGiven;desktop/internal/core/run_start_test.go 回放 Core 的 run-start.json)。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -50,5 +44,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva:命令行会超过系统上限的启动,由 Core(execution.planLaunchCommand)判断启动器是否为能读参数文件的 JDK、移走哪些路径列表选项以及参数文件内容;宿主读 JDK 的 release 文件、按启动器读取的编码写参数文件并负责其生命周期(runargs.go、argfile_encoding_*.go)。" + "notes": "Viva:宿主不再判断命令行长度,也不认识 JDK。Core 已删除 execution.planLaunchCommand(Lithe-IDEA/Lithe-core-rust#23),桌面端删除 launch_plan.go、runargs.go、argfile_encoding_*.go,按原样启动插件给出的命令行。命令行会超过系统上限时,由 Java 插件生成参数文件或 classpath JAR,自己选定编码,通过 run/start 的 temporaryFiles({name, base64} 字节或 {name, contents} 文本)交给宿主写入。插件接线前,Windows 上依赖很多的 Java 项目会因命令行超长无法启动(Lithe-IDEA/lithe-plugin-java#7)。" }