diff --git a/.agents/notes/implemented/architecture/2026-11-22-remote-workspace-process-runs.md b/.agents/notes/implemented/architecture/2026-11-22-remote-workspace-process-runs.md new file mode 100644 index 000000000..f6813e17b --- /dev/null +++ b/.agents/notes/implemented/architecture/2026-11-22-remote-workspace-process-runs.md @@ -0,0 +1,80 @@ +# Agent 笔记:远程工作区在主机上运行内置的程序和脚本运行配置及其执行前步骤 + +状态:已实现 + +## 先说结论 + +本笔记覆盖 #2231 R1 的 #43a 和 #43b。远程工作区里,运行配置的读写、校验和启动计划由 Core 路由到主机(Core #161):配置文件经 `lithe_workspace::fs` 存在主机的项目目录,计划按主机平台(Linux、macOS)生成,从不生成批处理或 PowerShell。桌面端拿到计划后,用 `remote.runProcess` 在主机上启动内置的程序和脚本运行(`process.*`),输出进 Run 窗口,标签页带“主机”徽标。 + +配置“执行前”列表里引用的其他内置运行配置(#43b)同样在主机上按顺序运行,输出进同一个控制台。插件提供的执行前任务、构建工具、插件提供的运行和调试要由本机插件后端计划主机上的进程,属于 #2231 的 R3/R4,本阶段不做,各自说明原因(`desktop.run.remote.*`)。 + +## 问题 + +- 远程工作区的项目只在主机上,本机的占位目录永远是空的。照本机方式起进程,会在空目录里跑,读不到项目文件。 +- 运行配置本身存在项目目录里。不路由到主机,就会在占位目录里读到“没有配置”,写入时还会把文件写进占位目录。 +- 主机上的程序输出可能很快、很多。Core 只缓存 1024 个未送出的事件,观察回调一旦阻塞,Core 会丢事件甚至结束请求。 +- 程序输出里的路径是主机路径,本机打不开;工作区以外的主机文件也要能点开(与 Zed 一致)。 + +## 决策 + +### 只有内置运行在主机上启动 + +`startRunConfigurationWith` 在远程工作区只放行 `configuration.IsProcess()` 且不是调试的启动,其余以 `desktop.run.remote.unsupported` 拒绝。标题栏的“运行”放行选中的配置,“调试”和“当前文件”仍走 `refuseRemote`;选中的配置不是内置运行时,直接说明不支持,而不是报“构建目标缺失”。 + +`loadBuildSystems` 在远程工作区不探测构建系统:本机占位目录里没有项目,探测只会得到空结果。它把 `p.build.failed` 设成 `desktop.run.remote.buildTools`,运行配置菜单把这句话显示为不可点的说明;非空的 `failed` 也让生成层快照保持为空,所以不会往主机写生成层。 + +“执行前”列表里有插件任务的配置拒绝启动(`desktop.run.remote.beforeLaunch`):任务由插件后端在本机计划,读不到主机上的项目文件(#2231 §2,R3)。只引用内置运行配置的列表照常运行,见下文。需要通过工具链选择程序的计划(`executable.toolchain`)也拒绝(`desktop.run.remote.toolchain`),因为工具链解析读的是本机。 + +### 进程的启动、输出和结束 + +`desktop/internal/workbench/remote_run.go` 的 `launchRemoteProcessRun`: + +1. 用 `remote.hostRequest` 的 `tempDirectory` 在主机临时目录建 `lithe-run-script-*`,把它作为脚本基名交给 `runConfig.createLaunchPlan`。脚本按计划写到这个目录(写入用“文件必须不存在”的预期版本),运行结束后不论成败、是否被停止都递归删除。连接断开或主机崩溃时留下的目录,由主机的临时目录清理负责。 +2. 工作目录是项目相对的 `/` 路径,`remoteRunDirectory` 拼到主机根下,拒绝 `..` 和绝对路径。环境用主机的登录环境,叠加计划的 `environment` 和配置的 `env`。 +3. 输出经 `remoteRunOutput` 交给控制台:观察回调只追加到缓冲区,从不等待;独立的泵按顺序送出。缓冲区上限 8 MiB,超出时丢弃最旧的未送出部分,并在控制台写一行提示(`desktop.run.remote.outputDropped`)。 +4. “停止”先用 `process.kill`(force 为 false)给进程组发 SIGTERM,超过停止等待时间(`buildprocess.StopGrace`)仍未结束就取消请求,由 Core 强制结束。再按一次“停止”立即强制结束。 +5. 进程以非零退出码结束时运行失败,被信号结束时说明信号编号;连接断开时说明“无法确定是否仍在主机上运行”,并交给窗口重新连接(断线后接回输出是 #43c)。 + +主机上的进程 id 不是本机的,`Pid()` 返回 0,所以 Run 窗口不采样它的端口、CPU 和内存。主机端口由端口工具窗口列出。 + +### 执行前步骤(#43b) + +Core 只允许“执行前”列表引用内置进程运行(`process.*`),所以配置步骤在远程工作区一定能在主机上运行。`runBeforeLaunchSteps` 在远程工作区为这次启动建一个 `remoteRunHost`,每个配置步骤经 `remoteRunHost.runStep` 运行:与主运行一样在主机临时目录规划并写脚本、用 `remote.runProcess` 启动、输出经 `remoteRunOutput` 进同一个控制台,进程标签为步骤名;临时目录在下一步开始前删除。 + +步骤与本机步骤一样受准备时间(`runPreparationTimeout`)限制。请求本身不随准备上下文取消:准备上下文结束(“停止”或超时)时,先对已启动的进程调用 `remoteProcess.Stop`(SIGTERM,超过停止等待时间再取消请求),还没启动时直接取消请求。这样主机步骤的停止与本机 `buildprocess` 的先请求、后强杀一致。被要求结束后以 0 退出的步骤仍按停止或超时处理,不会接着启动配置。 + +`failBeforeLaunch` 按 `ExitCode() int` 读退出码,本机的 `*exec.ExitError` 和主机的 `remoteRunExit` 都能说明“以退出码 N 结束”。确认询问(按指纹记住)与本机共用,主机步骤不另加询问。 + +### 输出里的路径 + +`flushOutputLinks` 在远程工作区用主机根作为工作区根、按 `linux` 平台匹配路径。点击时用 `remote.stat` 找第一个主机上存在的文件,经 `remoteplaceholder.LocalPath` 换成占位路径交给编辑器打开;工作区以外的路径落在占位根旁的 `.lithe-remote-host` 下,与“工作区以外的远端文件按 Zed 方式打开”一致。需要插件解析的链接拒绝,因为插件读的是本机文件。 + +### 日志 + +日志只记命令和错误码,不记主机、路径、命令行或输出。早返回带 `// log-exempt:` 说明。 + +## 考虑过的备选方案 + +- **在本机用 ssh 直接起进程**:绕过 Core 的会话、认证和 S26 环境白名单,也拿不到 Core 的进程组管理和事件缓冲。 +- **把脚本写到主机的项目目录**:会弄脏用户的工作区,可能被 Git 看到或被提交。 +- **远程工作区也探测构建系统**:探测在本机占位目录里运行,结果永远为空,还会误导用户以为项目没有构建工具。 +- **远程工作区拒绝所有执行前步骤**(#43a 的做法):配置步骤只是另一个内置运行,主机已经能运行它;一起拒绝会让常见的“先编译再运行”脚本链用不了。 +- **把主机步骤的请求直接挂在准备上下文上**:停止时 Core 立即强杀,主机程序没有机会清理,与本机步骤的停止行为不一致。 + +## 后果 + +- 远程工作区里能直接运行项目自带的程序和脚本配置,输出、停止和退出码与本机一致;Run 窗口的“主机”徽标说明它在哪里运行。 +- “执行前”列表里的内置运行配置在主机上按顺序运行,失败、停止和超时与本机一致。 +- 插件提供的执行前任务、构建工具、插件运行、调试和“当前文件”暂时不可用,各自给出说明;它们依赖 #2231 的 R3(插件按主机路径计划进程)和 R4(远程调试),本阶段不做。 +- 断线时运行结束为“无法确定是否仍在主机上运行”,主机上的进程可能还在;断线后接回输出由 #43c 负责。 +- 主机临时目录里可能残留断线或崩溃时没删掉的 `lithe-run-script-*` 目录,由主机的临时目录清理回收。 + +## 验证 + +- `desktop/internal/workbench/remote_run_test.go`:主机上的启动参数、工作目录、环境、脚本写入和删除;退出码和信号;“停止”先发 SIGTERM;执行前的配置步骤在主机上依次运行、失败时不启动配置、停止时先发 SIGTERM;插件任务步骤、工具链和调试的拒绝;输出缓冲丢弃最旧部分;输出链接的主机文件查找;不记主机和路径。 +- `desktop/internal/core/remote_process_test.go`:`remote.runProcess` 事件的解析。 +- `scripts/desktop/verify/verify-runtime-bundle-immutability.sh`:运行时不写发行目录。 + +## 适用范围 + +适用于远程工作区(`project.remote` 非空)里运行配置的读取、启动、停止、输出和输出链接。本机工作区的运行流程不受影响;插件任务步骤、构建工具、插件运行和调试在主机上的执行以 #2231 R3/R4 的笔记为准。 diff --git a/desktop/internal/core/remote_process.go b/desktop/internal/core/remote_process.go new file mode 100644 index 000000000..e65fbf490 --- /dev/null +++ b/desktop/internal/core/remote_process.go @@ -0,0 +1,174 @@ +package core + +import ( + "bytes" + "context" + "encoding/base64" + "encoding/json" + "errors" +) + +// RemoteProcessOpen is how a host process starts. +type RemoteProcessOpen struct { + // Argv is the program and its arguments; a program without "/" is looked up on the PATH of + // Environment. + Argv []string `json:"argv"` + // Cwd is the absolute host working directory; empty starts in the user's home. + Cwd string `json:"cwd,omitempty"` + // Environment is the base environment: "login" asks the user's login shell for it, as an SSH + // login sees it, and "server" (the default when empty) is the remote server's own. + Environment string `json:"environment,omitempty"` + // Env adds variables to the base environment. + Env map[string]string `json:"env,omitempty"` + // PipeStdin keeps the program's standard input open; false gives it /dev/null. + PipeStdin bool `json:"pipeStdin,omitempty"` + // Label is what server.state reports for the process, so the window that closes the session + // can name what still runs. Nil reports none. + Label *RemoteResourceLabel `json:"label,omitempty"` +} + +// RemoteProcessEnvironmentLogin is the base environment of a process the user starts: the one +// their login shell sets up, so tools installed through the profile are on the PATH. +const RemoteProcessEnvironmentLogin = "login" + +// RemoteProcessEvents receive a host process's events. Both run on the request's goroutine and +// must return at once: they must not wait for a UI thread. Core holds 1024 undelivered events +// per process and ends the process, and with it the request, when a subscriber stops reading. +type RemoteProcessEvents struct { + // Started is called once, before any output, with the id process.kill takes and the + // process's id on the host. + Started func(processID uint64, pid int) + // Output receives the bytes the program wrote to stream, "stdout" or "stderr", in order. + // Output owns data. + Output func(stream string, data []byte) +} + +// RemoteProcessExit is how a host process's leader ended: ExitCode when it exited, Signal when a +// signal ended it. +type RemoteProcessExit struct { + ExitCode *int `json:"exitCode"` + Signal *int `json:"signal"` +} + +// remoteProcessEvent is one remote event of remote.runProcess. +type remoteProcessEvent struct { + Type string `json:"type"` + Event string `json:"event"` + Params struct { + ProcessID uint64 `json:"processId"` + PID *int `json:"pid"` + Stream string `json:"stream"` + Data string `json:"data"` + } `json:"params"` +} + +// errRemoteProcessEvent is an event of remote.runProcess the client cannot read. +var errRemoteProcessEvent = errors.New("core: unreadable remote process event") + +// RemoteRunProcess runs a process on the host of sessionID until its leader exits, and returns +// how it ended. It blocks the calling goroutine for the process's whole life, so run it off the +// UI thread. Ending ctx kills the process: Core sends process.kill with force, which kills every +// process of its session, and returns the context's error. A broken or unknown session fails +// with CodeConnectionClosed, and a program that cannot start with CodeProcessFailed. An event +// the client cannot read ends the process too and is returned as the error, since its output +// would be incomplete. +func (c *Client) RemoteRunProcess(ctx context.Context, sessionID string, open RemoteProcessOpen, events RemoteProcessEvents) (RemoteProcessExit, error) { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + var unreadable error + observer := func(raw json.RawMessage) { + if unreadable != nil { + return + } + if err := deliverRemoteProcessEvent(raw, events); err != nil { + // Cancelling ends the process rather than letting it run unseen. + unreadable = err + cancel() + } + } + var exit RemoteProcessExit + observationErr, err := c.ExecuteWithEvents(ctx, "remote.runProcess", struct { + SessionID string `json:"sessionId"` + Params RemoteProcessOpen `json:"params"` + }{sessionID, open}, &exit, observer) + switch { + case unreadable != nil: + return RemoteProcessExit{}, unreadable + case err != nil: + return RemoteProcessExit{}, err + case observationErr != nil: + return RemoteProcessExit{}, observationErr + } + return exit, nil +} + +// deliverRemoteProcessEvent hands one event of remote.runProcess to events. Events of other kinds +// are not the process's and are ignored. +func deliverRemoteProcessEvent(raw json.RawMessage, events RemoteProcessEvents) error { + if !bytes.Contains(raw, []byte(`"remote"`)) { + return nil + } + var event remoteProcessEvent + if err := json.Unmarshal(raw, &event); err != nil || event.Type != "remote" { + return nil + } + switch event.Event { + case "process.started": + if events.Started != nil { + pid := 0 + if event.Params.PID != nil { + pid = *event.Params.PID + } + events.Started(event.Params.ProcessID, pid) + } + case "process.output": + if event.Params.Stream != "stdout" && event.Params.Stream != "stderr" { + return errRemoteProcessEvent + } + data, err := base64.StdEncoding.DecodeString(event.Params.Data) + if err != nil { + return errRemoteProcessEvent + } + if events.Output != nil && len(data) > 0 { + events.Output(event.Params.Stream, data) + } + } + return nil +} + +// RemoteProcessKill signals every process of the host process processID of sessionID: SIGTERM, +// or SIGKILL with force. A process whose session already ended is no error. +func (c *Client) RemoteProcessKill(ctx context.Context, sessionID string, processID uint64, force bool) error { + err := c.RemoteHostRequest(ctx, sessionID, "process.kill", struct { + ProcessID uint64 `json:"processId"` + Force bool `json:"force"` + }{processID, force}, nil) + if remoteHostCode(err) == "UNKNOWN_RESOURCE" { + return nil + } + return err +} + +// RemoteTempDirectory creates a fresh folder only the host account can open (0700) in the host's +// temporary directory and returns its absolute path. prefix names it for diagnostics: one to 64 +// ASCII letters, digits, "-" and "_". The caller removes it (RemoteRemove) when done. +func (c *Client) RemoteTempDirectory(ctx context.Context, sessionID, prefix string) (string, error) { + var result struct { + Path string `json:"path"` + } + if err := c.RemoteHostRequest(ctx, sessionID, "fs.tempDirectory", struct { + Prefix string `json:"prefix"` + }{prefix}, &result); err != nil { + return "", err + } + return result.Path, nil +} + +// RemoteRemove deletes the host path, a folder with everything in it when recursive. Links are +// removed, never followed. +func (c *Client) RemoteRemove(ctx context.Context, sessionID, path string, recursive bool) error { + return c.RemoteHostRequest(ctx, sessionID, "fs.remove", struct { + Path string `json:"path"` + Recursive bool `json:"recursive"` + }{path, recursive}, nil) +} diff --git a/desktop/internal/core/remote_process_test.go b/desktop/internal/core/remote_process_test.go new file mode 100644 index 000000000..d523648c1 --- /dev/null +++ b/desktop/internal/core/remote_process_test.go @@ -0,0 +1,46 @@ +package core + +import ( + "encoding/json" + "errors" + "slices" + "testing" +) + +// A host process's events reach their callbacks in order: started with its process id, then its +// output as bytes. Events that are not the process's and empty output are not delivered. Output of +// an unknown stream or that is not base64 is an error, since the console would miss it. +func TestRemoteProcessEventsReachTheirCallbacks(t *testing.T) { + var got []string + events := RemoteProcessEvents{ + Started: func(processID uint64, pid int) { + if processID == 7 && pid == 4242 { + got = append(got, "started") + } + }, + Output: func(stream string, data []byte) { got = append(got, stream+":"+string(data)) }, + } + for _, raw := range []string{ + `{"type":"progress","event":"process.output","params":{"stream":"stdout","data":"aGk="}}`, + `{"type":"remote","event":"process.started","params":{"processId":7,"pid":4242}}`, + `{"type":"remote","event":"process.output","params":{"stream":"stdout","data":"aGk="}}`, + `{"type":"remote","event":"process.output","params":{"stream":"stderr","data":""}}`, + `{"type":"remote","event":"process.output","params":{"stream":"stderr","data":"b29wcw=="}}`, + `{"type":"remote","event":"terminal.output","params":{}}`, + } { + if err := deliverRemoteProcessEvent(json.RawMessage(raw), events); err != nil { + t.Fatalf("event %d: %v", len(got), err) + } + } + if want := []string{"started", "stdout:hi", "stderr:oops"}; !slices.Equal(got, want) { + t.Fatalf("delivered %d events, want %d", len(got), len(want)) + } + for _, bad := range []string{ + `{"type":"remote","event":"process.output","params":{"stream":"stdin","data":"aGk="}}`, + `{"type":"remote","event":"process.output","params":{"stream":"stdout","data":"not base64!"}}`, + } { + if err := deliverRemoteProcessEvent(json.RawMessage(bad), events); !errors.Is(err, errRemoteProcessEvent) { + t.Fatalf("an unreadable event was %v", err) + } + } +} diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index acdaa4802..a75305fbc 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -2046,7 +2046,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.viaHosts": "via {hosts}", "desktop.remote.workspace.banner": "This is a remote workspace. Its files open, edit, save and are searched on the host, and terminals and Git run on the host; running, debugging and language servers do not work here yet.", "desktop.remote.workspace.gitAbove": "This folder is inside a Git repository that starts in a folder above it on the host. Open the repository's top folder to use Git in a remote workspace.", - "desktop.remote.workspace.localOnly": "This feature does not work in a remote workspace yet. You can browse, edit, save and search the host's files, run terminals and use Git on the host.", + "desktop.remote.workspace.localOnly": "This feature does not work in a remote workspace yet. You can browse, edit, save and search the host's files, run terminals, use Git and run program and script configurations on the host.", "desktop.remote.workspace.safeBanner": "This remote workspace is in safe mode: you can browse, edit, save and search its files on the host. Trust the folder to use Git.", "desktop.remote.workspace.title": "{folder} [{kind}: {connection}]", "desktop.remote.worktree.connectionRemoved": "The connection this workspace was opened over was deleted, so its worktree cannot be opened. Add the connection again, then open the worktree.", @@ -2133,6 +2133,16 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.run.ports.more": "+{count}", "desktop.run.ports.open": "Open in browser", "desktop.run.ports.openFailed": "Could not open {url}.", + "desktop.run.remote.badge": "Host", + "desktop.run.remote.badgeHelp": "This program runs on the remote workspace's host.", + "desktop.run.remote.beforeLaunch": "a remote workspace does not run plugin tasks before launch yet; remove them from the Before launch list to run the configuration on the host", + "desktop.run.remote.buildTools": "Build tools and plugin runs do not work in a remote workspace yet; program and script configurations run on the host.", + "desktop.run.remote.connectionLost": "the connection to the host broke while the program ran; whether it still runs on the host is unknown", + "desktop.run.remote.notConnected": "the remote workspace is not connected; run it again once it reconnects", + "desktop.run.remote.outputDropped": "Some output arrived faster than it could be shown and was left out.", + "desktop.run.remote.signal": "the program was ended by signal {signal}", + "desktop.run.remote.toolchain": "a remote workspace cannot run a program chosen through a toolchain yet; name the program or its path on the host", + "desktop.run.remote.unsupported": "a remote workspace runs only program and script configurations, on the host, and does not debug yet", "desktop.run.rerun": "Run again", "desktop.run.signalled": "Process stopped by signal {signal}.", "desktop.run.snapshot.menu": "Snapshot output", @@ -5937,7 +5947,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.viaHosts": "经由 {hosts}", "desktop.remote.workspace.banner": "这是远程工作区。主机上的文件可以打开、编辑、保存和搜索,终端和 Git 在主机上运行;运行、调试和语言服务器暂不可用。", "desktop.remote.workspace.gitAbove": "此文件夹位于主机上更上层文件夹开始的 Git 仓库中。请打开仓库的顶层文件夹,以便在远程工作区中使用 Git。", - "desktop.remote.workspace.localOnly": "远程工作区暂不支持此功能,可以浏览、编辑、保存和搜索主机上的文件,也可以在主机上运行终端和使用 Git。", + "desktop.remote.workspace.localOnly": "远程工作区暂不支持此功能,可以浏览、编辑、保存和搜索主机上的文件,也可以在主机上运行终端、使用 Git,以及运行程序和脚本运行配置。", "desktop.remote.workspace.safeBanner": "此远程工作区处于安全模式:可以浏览、编辑、保存和搜索主机上的文件。信任此文件夹后即可使用 Git。", "desktop.remote.workspace.title": "{folder} [{kind}: {connection}]", "desktop.remote.worktree.connectionRemoved": "打开此工作区所用的连接已被删除,无法打开它的工作树。请重新添加该连接后再打开工作树。", @@ -6024,6 +6034,16 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.run.ports.more": "+{count}", "desktop.run.ports.open": "在浏览器中打开", "desktop.run.ports.openFailed": "无法打开 {url}。", + "desktop.run.remote.badge": "主机", + "desktop.run.remote.badgeHelp": "此程序运行在远程工作区的主机上。", + "desktop.run.remote.beforeLaunch": "远程工作区暂不支持插件提供的执行前任务,请从“执行前”列表中删除这些任务后再在主机上运行", + "desktop.run.remote.buildTools": "远程工作区暂不支持构建工具和插件提供的运行;程序和脚本运行配置会在主机上运行。", + "desktop.run.remote.connectionLost": "程序运行时与主机的连接断开了,无法确定它是否仍在主机上运行", + "desktop.run.remote.notConnected": "远程工作区未连接,请在重新连接后再运行", + "desktop.run.remote.outputDropped": "部分输出到达太快,来不及显示,已略去。", + "desktop.run.remote.signal": "程序被信号 {signal} 结束", + "desktop.run.remote.toolchain": "远程工作区暂不支持运行通过工具链选择的程序,请填写主机上的程序名或路径", + "desktop.run.remote.unsupported": "远程工作区只在主机上运行程序和脚本运行配置,暂不支持调试", "desktop.run.rerun": "再次运行", "desktop.run.signalled": "进程被信号 {signal} 终止。", "desktop.run.snapshot.menu": "快照当前输出", diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 2d029ba88..7dee97853 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -243,6 +243,10 @@ type Kernel interface { RemoteRunWatch(ctx context.Context, sessionID, root string, excludeNames []string, events core.RemoteWatchEvents) error RemoteTerminalWrite(ctx context.Context, sessionID string, terminalID uint64, data []byte) (bool, error) RemoteTerminalResize(ctx context.Context, sessionID string, terminalID uint64, columns, rows uint16) error + RemoteRunProcess(ctx context.Context, sessionID string, open core.RemoteProcessOpen, events core.RemoteProcessEvents) (core.RemoteProcessExit, error) + RemoteProcessKill(ctx context.Context, sessionID string, processID uint64, force bool) error + RemoteTempDirectory(ctx context.Context, sessionID, prefix string) (string, error) + RemoteRemove(ctx context.Context, sessionID, path string, recursive bool) error RemoteStartForward(ctx context.Context, sessionID string, target core.RemoteForwardTarget) (core.RemoteForward, bool, error) RemoteStartHostForward(ctx context.Context, sessionID string, rule core.RemoteHostForwardRule) (core.RemoteForward, bool, error) RemoteStartReverseForward(ctx context.Context, sessionID string, rule core.RemoteReverseForwardRule, preferences *string) (core.RemoteForward, bool, error) diff --git a/desktop/internal/workbench/build.go b/desktop/internal/workbench/build.go index aba2fbbca..eba426a3d 100644 --- a/desktop/internal/workbench/build.go +++ b/desktop/internal/workbench/build.go @@ -144,7 +144,7 @@ type buildOperation struct { then func(*App, *project) provider *buildprovider.Client request *buildprovider.Operation - process *buildprocess.Process + process runProcess cancelled bool // stopped is closed by stop. stopped chan struct{} @@ -182,6 +182,7 @@ func (a *App) beginOperation(p *project, kind, label, configuration, key string, operation.session = &runEntry{ id: "build-" + strconv.Itoa(p.build.sessions), label: label, restart: restart, operation: operation, running: true, started: a.now(), output: newOutputBuffer(buildOutputMaxLines, buildOutputBytes), + remote: p.remote != nil, } a.addRunSession(p, operation.session) operation.ide = p.recordIDEOperation(kind, label, configuration) @@ -251,9 +252,10 @@ func (b *buildState) active() bool { return b.operation != nil || len(b.running) // 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. A -// remote workspace's project runs on its host, which a run does not reach yet. +// remote workspace runs only its run configurations, on its host (startRunConfigurationWith +// checks which); its build systems' tasks and entry points are not run there yet. func (a *App) startRun(p *project, key string, start func(*App, *project)) { - if a.refuseRemote(p, "run_start") { + if !strings.HasPrefix(key, configurationRunKey("")) && a.refuseRemote(p, "run_start") { return } if p.safeMode() { @@ -355,9 +357,20 @@ var errBuildBusy = refuseBuild(refusalBusy, "the Build window is already running // window stops and reruns it instead (startRun). var errRunRunning = refuseBuild(refusalBusy, "the run configuration is already running") +// runProcess is an operation's process as stop ends it: a process of this computer +// (*buildprocess.Process) or a remote workspace's process on its host (*remoteProcess). +type runProcess interface { + // Stop asks the process tree to end and kills it once the stop time passed. + Stop() + // Kill ends the process tree at once. + Kill() + // Pid is the process's id on this computer, 0 for one that runs elsewhere. + Pid() int +} + // attachProcess makes process the operation's process once it started. It reports false, and // stops the process, when the operation was stopped or replaced while the process started. -func (a *App) attachProcess(p *project, op *buildOperation, process *buildprocess.Process) bool { +func (a *App) attachProcess(p *project, op *buildOperation, process runProcess) bool { if op.cancelled || !p.build.owns(op) { process.Stop() return false @@ -784,7 +797,10 @@ func (a *App) loadBuildSystems(p *project) { } if p.remote != nil { // log-exempt: 远程工作区的构建工具要在主机上运行,现在还不支持:本机的占位文件夹里没有项目,不探测构建系统; - // 构建、运行和测试窗口显示只在本机可用的说明,按下运行时 refuseRemote 记录并提示。 + // 运行配置菜单用 failed 说明这一点,内置的程序和脚本运行照常从 Core 读出、在主机上启动(remote_run.go)。 + p.build.loaded = true + p.build.failed = i18n.Shared(a.language(), "desktop.run.remote.buildTools") + a.refreshRunConfigurations(p) return } if a.plugins == nil || a.plugins.Backend == nil { @@ -2282,7 +2298,8 @@ func (a *App) finishBuildTask(p *project, op *buildOperation, result json.RawMes // that exited is summarized with its exit code, as a run a plugin reports is, not as a build. func (a *App) finishBuildRun(p *project, op *buildOperation, err error) { a.endServiceDebugSession(p, op) - var exit *exec.ExitError + // A local process's *exec.ExitError and a host process's remoteRunExit both carry the code. + var exit interface{ ExitCode() int } switch { case op.cancelled: a.endBuildOperation(p, op, "cancelled", nil, "", a.text.Build.Cancelled) @@ -2313,7 +2330,8 @@ func (a *App) finishBuildError(p *project, op *buildOperation, err error) { failure = message } if a.endBuildOperation(p, op, "failed", nil, failure, message) { - a.operationFailed("build", err) + // A remote workspace's reason may name the host or a host path, which the log does not keep. + a.operationFailed("build", p.logError(err)) } } diff --git a/desktop/internal/workbench/outputlinks.go b/desktop/internal/workbench/outputlinks.go index 2aefb242d..03da9dece 100644 --- a/desktop/internal/workbench/outputlinks.go +++ b/desktop/internal/workbench/outputlinks.go @@ -10,6 +10,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteplaceholder" ) const ( @@ -125,7 +126,12 @@ func (a *App) flushOutputLinks(p *project) { if sources == nil { sources = []core.OutputLinkSource{} } - roots := []string{p.root} + roots, platform := []string{p.root}, buildPlatform() + if p.remote != nil { + // A remote workspace's programs print host paths: Core matches them against the host + // folder, as paths of a Unix host (Linux and macOS name paths alike here). + roots, platform = []string{p.remote.binding.RemoteRoot()}, "linux" + } kernel := a.kernel a.background(p, outputLinkTimeout, func(ctx context.Context) func(*App) { answers := make(map[string][]core.OutputLink) @@ -135,7 +141,7 @@ func (a *App) flushOutputLinks(p *project) { for start := 0; start < len(lines); start += outputLinkBatch { batch := lines[start:min(start+outputLinkBatch, len(lines))] links, err := kernel.MatchOutputLinks(ctx, core.OutputLinkRequest{ - Scope: scope, Platform: buildPlatform(), WorkspaceRoots: roots, Sources: sources, Lines: batch, + Scope: scope, Platform: platform, WorkspaceRoots: roots, Sources: sources, Lines: batch, }) if err != nil { failure = err @@ -191,8 +197,12 @@ func (a *App) openOutputLink(p *project, link core.OutputLink) { } case link.Location != nil: location := *link.Location + find := firstExistingFile + if p.remote != nil { + find = p.remoteFileFinder(a.kernel) + } a.background(p, outputLinkTimeout, func(ctx context.Context) func(*App) { - path := firstExistingFile(location.Paths) + path := find(ctx, location.Paths) if path == "" { return func(a *App) { a.operationRejected("output_link_open", "target_missing") @@ -201,6 +211,9 @@ func (a *App) openOutputLink(p *project, link core.OutputLink) { } return func(a *App) { a.openFileAtPosition(p, path, zeroBased(location.Line), zeroBased(location.Column)) } }) + case link.Resolve != nil && p.remote != nil: + // The plugin that resolves the link reads this computer's files, not the host's. + a.refuseRemote(p, "output_link_resolve") case link.Resolve != nil && a.plugins != nil: function, groups, pluginID := link.Resolve.Function, link.Resolve.Groups, link.PluginID a.background(p, outputLinkTimeout, func(ctx context.Context) func(*App) { @@ -217,7 +230,7 @@ func (a *App) openOutputLink(p *project, link core.OutputLink) { a.notifyError(messages.LinkUnresolved) } } - path := firstExistingFile([]string{location.Path}) + path := firstExistingFile(ctx, []string{location.Path}) if path == "" { return func(a *App) { a.operationRejected("output_link_open", "target_missing") @@ -238,8 +251,8 @@ func zeroBased(position int) int { return position - 1 } -// firstExistingFile returns the first candidate that is a regular file. -func firstExistingFile(candidates []string) string { +// firstExistingFile returns the first candidate that is a regular file of this computer. +func firstExistingFile(_ context.Context, candidates []string) string { for _, candidate := range candidates { if info, err := os.Stat(candidate); err == nil && info.Mode().IsRegular() { return candidate @@ -247,3 +260,28 @@ func firstExistingFile(candidates []string) string { } return "" } + +// remoteFileFinder finds, for a remote workspace, the first candidate host path that is a file +// on the host, and returns its path in the workspace's placeholder, which the editor opens +// through the host (remoteplaceholder.LocalPath). A host that does not answer finds none. It is +// taken on the window thread and runs off it. +func (p *project) remoteFileFinder(kernel Kernel) func(context.Context, []string) string { + root, binding := p.root, p.remote.binding + remoteRoot := binding.RemoteRoot() + return func(ctx context.Context, candidates []string) string { + session := binding.SessionID() + if session == "" { + return "" + } + for _, candidate := range candidates { + local, ok := remoteplaceholder.LocalPath(root, remoteRoot, candidate) + if !ok { + continue + } + if metadata, err := kernel.RemoteStat(ctx, session, candidate); err == nil && metadata.Kind == core.RemoteFileKindFile { + return local + } + } + return "" + } +} diff --git a/desktop/internal/workbench/remote_git_test.go b/desktop/internal/workbench/remote_git_test.go index e01a36f4a..de1d237bc 100644 --- a/desktop/internal/workbench/remote_git_test.go +++ b/desktop/internal/workbench/remote_git_test.go @@ -461,15 +461,16 @@ func TestRemoteWorkspaceSaysItsRepositoryStartsAbove(t *testing.T) { } // What runs the project's code on this computer refuses in a trusted remote workspace too, and -// says so: Run and Debug, the current file's run, the tests and the build tasks, and their tool -// windows. +// says so: Debug, the current file's run, a run that is not a configuration, the tests and the +// build tasks, and the Debug tool window. Run configurations start on the host +// (remote_run_test.go). func TestRemoteWorkspaceRefusesToRunItsCode(t *testing.T) { h, k, _, logger := remoteWorkspaceHarness(t) lang := h.app.language() k.trustAtHost(core.WorkspaceTrusted, ".") p := h.openRemoteTestProject(t) h.awaitRemoteGit(p) - h.app.titleStart(p, titleActionRun) + h.app.titleStart(p, titleActionDebug) h.app.performCurrentFileAction(p, titleActionRun) h.app.startRun(p, "run", func(*App, *project) { t.Error("a run started") }) h.app.startTests(p, testSelection{}) @@ -486,10 +487,10 @@ func TestRemoteWorkspaceRefusesToRunItsCode(t *testing.T) { if !h.notified(localOnly) || p.trust.asking { t.Fatal("the refusal was not notified, or the trusted workspace asked to be trusted") } - h.app.openToolWindow(itemRun) + h.app.openToolWindow(itemDebug) h.redraw() if !h.showsWrapped(localOnly) { - t.Fatal("the Run tool window does not say it does not work here") + t.Fatal("the Debug tool window does not say it does not work here") } sessionKept(t, logger, p, "session-1") } diff --git a/desktop/internal/workbench/remote_run.go b/desktop/internal/workbench/remote_run.go new file mode 100644 index 000000000..26fb05015 --- /dev/null +++ b/desktop/internal/workbench/remote_run.go @@ -0,0 +1,401 @@ +package workbench + +import ( + "context" + "errors" + "maps" + "path" + "strconv" + "strings" + "sync" + "sync/atomic" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/buildprocess" + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" +) + +// This file runs the built-in process runs of a remote workspace on its host (#2231 R1). Core +// plans the run for the host through the workspace's binding, so the plan names host paths; the +// window writes a script saved as text to a fresh host temporary folder only the host account +// can open, and remote.runProcess starts the program there in the user's login environment, with +// its output in the Run window. Nothing of the run is read from or written to this computer's +// file system, and no plugin takes part. +// +// Note: 远程工作区运行配置的决策见 .agents/notes/implemented/architecture/2026-11-22-remote-workspace-process-runs.md + +const ( + // remoteRunScratchPrefix names the host temporary folder of a run. It is removed once the + // process ended; one a lost connection leaves is the host's temporary directory's to clean. + remoteRunScratchPrefix = "lithe-run-script" + // remoteRunRequestTimeout bounds the removal of a run's temporary folder. + remoteRunRequestTimeout = 30 * time.Second + // remoteRunOutputLimit bounds what a host process wrote that the console has not taken yet. + // The request's goroutine must never wait (core.RemoteProcessEvents), so beyond it the + // oldest output is dropped and the console says so. + remoteRunOutputLimit = 8 << 20 +) + +// launchRemoteProcessRun is launchProcessRun for a remote workspace: it plans the run on the +// host, starts its process there and waits for it off the window thread. The plan is bounded by +// the run preparation time; the process runs until it exits, the user stops it, the project +// closes or the connection is lost, which ends it on the host too. +func (a *App) launchRemoteProcessRun(p *project, op *buildOperation, id string) { + host := remoteRunHost{ + kernel: a.kernel, binding: p.remote.binding, root: p.root, language: a.language(), + label: core.NewRemoteResourceLabel("run", op.session.label), + output: func(text string) { a.streamBuildOutput(p, op, text) }, + lost: a.remoteSessionLost(p), + } + a.background(p, 0, func(ctx context.Context) func(*App) { + host.failed = func(operation string, err error) { a.backgroundFailedIn(ctx, operation, remoteLogError(err)) } + bounded, cancel := context.WithTimeout(ctx, runPreparationTimeout) + prepare, release := op.bind(bounded) + start, err := host.prepare(prepare, id) + release() + cancel() + defer host.cleanup(ctx, start) + if err != nil { + return func(a *App) { a.finishBuildError(p, op, err) } + } + err = host.run(ctx, start, func(process *remoteProcess) { + a.post(func(a *App) { a.attachProcess(p, op, process) }) + }) + return func(a *App) { a.finishBuildRun(p, op, err) } + }) +} + +// runStep runs a before-launch step that starts built-in run configuration step.ConfigurationID +// on the host and waits for it, with its output in the console of the configuration that starts. +// prepare bounds the step like a local one: once it ends, through a stop or the preparation +// time, the step's processes are asked to end and killed after the stop time, as a local step's +// process tree is. The step's temporary folder is removed after ctx ended too. +func (h remoteRunHost) runStep(ctx, prepare context.Context, step core.RunBeforeLaunchItem) error { + h.label = core.NewRemoteResourceLabel("run", step.Name) + start, err := h.prepare(prepare, step.ConfigurationID) + defer h.cleanup(ctx, start) + if err != nil { + return err + } + request, cancel := context.WithCancel(context.WithoutCancel(prepare)) + defer cancel() + var attached atomic.Pointer[remoteProcess] + defer context.AfterFunc(prepare, func() { + if process := attached.Load(); process != nil { + process.Stop() + return + } + cancel() + })() + if err := h.run(request, start, func(process *remoteProcess) { attached.Store(process) }); err != nil { + return err + } + // A step that exited cleanly once asked to end was still stopped or ran out of time. + return prepare.Err() +} + +// remoteRunHost is what one run of a remote workspace takes from the window thread. +type remoteRunHost struct { + kernel Kernel + binding *core.RemoteWorkspace + root string + language i18n.Language + label *core.RemoteResourceLabel + // output adds text to the run's console. Decoding it may wait for Core, so only the run's + // output pump calls it, never the request's goroutine. + output func(string) + // lost tells the window the session's connection closed. + lost func(session string) + // failed logs a failure of the run's housekeeping, such as removing its temporary folder. + failed func(operation string, err error) +} + +// remoteRunStart is a planned run: the session it runs over, its host temporary folder ("" when +// none was created) and how its process starts. +type remoteRunStart struct { + session, scratch string + open core.RemoteProcessOpen +} + +// prepare plans run configuration id on the host under ctx and writes a script saved as text to +// the run's temporary folder. The start it returns names the folder whenever one was created, so +// the caller removes it even when preparing failed. +func (h remoteRunHost) prepare(ctx context.Context, id string) (remoteRunStart, error) { + start := remoteRunStart{session: h.binding.SessionID()} + if start.session == "" { + return start, errors.New(i18n.Shared(h.language, "desktop.run.remote.notConnected")) + } + scratch, err := h.kernel.RemoteTempDirectory(ctx, start.session, remoteRunScratchPrefix) + if err != nil { + return start, h.failure(start.session, err) + } + start.scratch = scratch + plan, err := h.kernel.CreateRunLaunchPlan(ctx, h.root, id, path.Join(scratch, "script")) + if err != nil { + return start, h.failure(start.session, err) + } + if start.open, err = h.processOpen(plan); err != nil { + return start, err + } + if plan.InlineScript != nil { + if err := h.writeScript(ctx, start, *plan.InlineScript); err != nil { + return start, err + } + } + return start, ctx.Err() +} + +// processOpen turns a launch plan Core made for the host into the host process to start: the +// program and its arguments as planned, the working directory under the workspace's host folder, +// and the plan's variables over the user's login environment. A bare command is looked up on the +// host's PATH. A toolchain executable is resolved from this computer's toolchains, which do not +// run on the host, so such a run is refused. +func (h remoteRunHost) processOpen(plan core.RunLaunchPlan) (core.RemoteProcessOpen, error) { + directory, err := remoteRunDirectory(h.binding.RemoteRoot(), plan.WorkingDirectory) + if err != nil { + return core.RemoteProcessOpen{}, err + } + var program string + switch executable := plan.Executable; { + case executable.Path != "": + if !path.IsAbs(executable.Path) { + return core.RemoteProcessOpen{}, errors.New("run program path is not an absolute host path") + } + program = executable.Path + case executable.Command != "": + program = executable.Command + case executable.Toolchain != "": + return core.RemoteProcessOpen{}, errors.New(i18n.Shared(h.language, "desktop.run.remote.toolchain")) + default: + return core.RemoteProcessOpen{}, errors.New("run launch plan has no executable") + } + environment := make(map[string]string, len(plan.Environment)+len(plan.Env)) + maps.Copy(environment, plan.Environment) + maps.Copy(environment, plan.Env) + return core.RemoteProcessOpen{ + Argv: append([]string{program}, plan.Arguments...), + Cwd: directory, + Environment: core.RemoteProcessEnvironmentLogin, + Env: environment, + Label: h.label, + }, nil +} + +// remoteRunDirectory is the host path of a project-relative '/' working directory below the +// workspace's host folder remoteRoot. Core keeps it inside the project; one that leaves it is +// refused here too. +func remoteRunDirectory(remoteRoot, directory string) (string, error) { + clean := path.Clean(directory) + if path.IsAbs(clean) || clean == ".." || strings.HasPrefix(clean, "../") { + return "", errors.New("run working directory is outside the project") + } + return path.Join(remoteRoot, clean), nil +} + +// writeScript writes a script saved as text where Core planned it, which must be a new file +// directly in the run's temporary folder. The host runs it through its interpreter, so it needs +// no execute permission. +func (h remoteRunHost) writeScript(ctx context.Context, start remoteRunStart, script core.RunInlineScript) error { + if path.Dir(script.Path) != start.scratch { + return errors.New("inline script is outside its temporary folder") + } + _, saved, err := h.kernel.RemoteWriteFile(ctx, start.session, script.Path, []byte(script.Content), nil) + if err != nil { + return h.failure(start.session, err) + } + if !saved { + return errors.New("inline script file already exists") + } + return nil +} + +// run starts the planned process under ctx and waits for its leader to exit; attach receives the +// process once the host started it. The output reaches the console before run returns. It +// returns nil for a clean exit, a remoteRunExit for a nonzero exit code, and why the run ended +// otherwise. +func (h remoteRunHost) run(ctx context.Context, start remoteRunStart, attach func(*remoteProcess)) error { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + process := &remoteProcess{kernel: h.kernel, session: start.session, cancel: cancel, done: make(chan struct{}), failed: h.failed} + output := newRemoteRunOutput(h.output, "\n\x1b[2m"+i18n.Shared(h.language, "desktop.run.remote.outputDropped")+"\x1b[0m\n") + exit, err := h.kernel.RemoteRunProcess(ctx, start.session, start.open, core.RemoteProcessEvents{ + Started: func(processID uint64, _ int) { + if process.id.CompareAndSwap(0, processID) { + attach(process) + } + }, + Output: func(_ string, data []byte) { output.add(data) }, + }) + close(process.done) + output.close() + return h.endError(ctx, start.session, exit, err) +} + +// endError is why a run's request ended as the console reads it. A request ctx ended was +// stopped or closed with its project; a lost connection is told to the window, which connects +// again. +func (h remoteRunHost) endError(ctx context.Context, session string, exit core.RemoteProcessExit, err error) error { + switch { + case err != nil && ctx.Err() != nil: + return ctx.Err() + case err != nil: + return h.failure(session, err) + case exit.ExitCode != nil && *exit.ExitCode != 0: + return remoteRunExit(*exit.ExitCode) + case exit.Signal != nil: + return errors.New(i18n.SharedFormat(h.language, "desktop.run.remote.signal", map[string]string{"signal": strconv.Itoa(*exit.Signal)})) + } + return nil +} + +// failure is err of a request over session as the console shows it: a closed connection is told +// to the window and reads as a lost connection. +func (h remoteRunHost) failure(session string, err error) error { + if remoteConnectionClosed(err) { + h.lost(session) + return errors.New(i18n.Shared(h.language, "desktop.run.remote.connectionLost")) + } + return err +} + +// cleanup removes the run's host temporary folder, after ctx ended too, so a stopped run leaves +// none. A folder a lost connection keeps is left to the host. +func (h remoteRunHost) cleanup(ctx context.Context, start remoteRunStart) { + if start.scratch == "" { + return + } + ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), remoteRunRequestTimeout) + defer cancel() + if err := h.kernel.RemoteRemove(ctx, start.session, start.scratch, true); err != nil && !remoteConnectionClosed(err) { + h.failed("run_inline_script_cleanup", err) + } +} + +// remoteRunExit is a host process's nonzero exit code, which finishBuildRun reads as an exit. +type remoteRunExit int + +func (e remoteRunExit) Error() string { return "remote run: exit status " + strconv.Itoa(int(e)) } + +// ExitCode is the code the process exited with. +func (e remoteRunExit) ExitCode() int { return int(e) } + +// remoteProcess is a run's process on the host as the Run window stops it (runProcess). +type remoteProcess struct { + kernel Kernel + session string + // cancel ends the run's request, and with it every process of the run: Core kills them. + cancel context.CancelFunc + // id is the process's id for process.kill, set before the process is attached. + id atomic.Uint64 + // done is closed once the request returned. + done chan struct{} + stopping sync.Once + failed func(operation string, err error) +} + +// Pid is 0: the host's process ids are not this computer's, whose ports the Run window samples. +func (r *remoteProcess) Pid() int { return 0 } + +// Stop asks every process of the run to end, SIGTERM to its process group, and kills them once +// the stop time passed. A stop the host could not be asked for kills them at once. +func (r *remoteProcess) Stop() { + r.stopping.Do(func() { + grace := buildprocess.StopGrace() + if grace <= 0 || r.id.Load() == 0 { + r.cancel() + return + } + go func() { + timer := time.NewTimer(grace) + defer timer.Stop() + ctx, cancel := context.WithTimeout(context.Background(), grace) + err := r.kernel.RemoteProcessKill(ctx, r.session, r.id.Load(), false) + cancel() + if err != nil { + if ctx.Err() == nil && !remoteConnectionClosed(err) { + r.failed("run_stop", err) + } + r.cancel() + return + } + select { + case <-r.done: + case <-timer.C: + r.cancel() + } + }() + }) +} + +// Kill ends every process of the run at once. +func (r *remoteProcess) Kill() { r.cancel() } + +// remoteRunOutput carries a host process's output from the request's goroutine, which must return +// at once, to the console, whose decoder may wait for Core. Its pump delivers in order. +type remoteRunOutput struct { + deliver func(string) + // notice marks where output was dropped. + notice string + wake chan struct{} + done chan struct{} + + mu sync.Mutex + pending []byte + dropped bool + closed bool +} + +func newRemoteRunOutput(deliver func(string), notice string) *remoteRunOutput { + o := &remoteRunOutput{deliver: deliver, notice: notice, wake: make(chan struct{}, 1), done: make(chan struct{})} + go o.pump() + return o +} + +// add keeps data for the console and never waits. Output beyond remoteRunOutputLimit drops what +// the console has not taken yet, which the console then says. +func (o *remoteRunOutput) add(data []byte) { + o.mu.Lock() + if len(o.pending)+len(data) > remoteRunOutputLimit { + o.pending, o.dropped = o.pending[:0], true + data = data[max(0, len(data)-remoteRunOutputLimit):] + } + o.pending = append(o.pending, data...) + o.mu.Unlock() + o.signal() +} + +// close delivers what is left and waits for the pump to finish. +func (o *remoteRunOutput) close() { + o.mu.Lock() + o.closed = true + o.mu.Unlock() + o.signal() + <-o.done +} + +func (o *remoteRunOutput) signal() { + select { + case o.wake <- struct{}{}: + default: + } +} + +func (o *remoteRunOutput) pump() { + defer close(o.done) + for range o.wake { + o.mu.Lock() + data, dropped, closed := o.pending, o.dropped, o.closed + o.pending, o.dropped = nil, false + o.mu.Unlock() + if dropped { + o.deliver(o.notice) + } + if len(data) > 0 { + o.deliver(string(data)) + } + if closed { + return + } + } +} diff --git a/desktop/internal/workbench/remote_run_test.go b/desktop/internal/workbench/remote_run_test.go new file mode 100644 index 000000000..ddec25953 --- /dev/null +++ b/desktop/internal/workbench/remote_run_test.go @@ -0,0 +1,517 @@ +package workbench + +import ( + "context" + "path/filepath" + "strings" + "sync" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/buildprocess" + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteplaceholder" +) + +// remoteTestRunScratch is the temporary folder the host makes for a run's script. +const remoteTestRunScratch = "/tmp/lithe-run-script-1" + +// remoteHostRuns stands in for Core's run configurations of the workspace and the host's +// processes (remote.runProcess): a process prints remoteHostRunOutput and exits with exit, or, +// with hold, runs until it is signalled or its request ends. +type remoteHostRuns struct { + mu sync.Mutex + // configurations are what Core resolves, and plan is the launch plan of each. + configurations []core.RunConfiguration + plan core.RunLaunchPlan + // steps are the before-launch steps of every configuration. + steps []core.RunBeforeLaunchItem + // exit is how a process that is not held ends; hold keeps it running. + exit core.RemoteProcessExit + hold bool + // bases are the inline script bases the plans were asked with; opens the processes the host + // started and sessions their sessions; removed the paths removed; kills the signals sent, + // as "term" or "kill". + bases, sessions, removed, kills []string + opens []core.RemoteProcessOpen + // scripts are what the script a process ran held when the process started. + scripts []string + // signalled ends a held process. + signalled chan struct{} + // ended is closed once a process's request returned. + ended chan struct{} +} + +// remoteHostRunOutput is what a host process prints. +const remoteHostRunOutput = "hello from the host\n" + +func (k *remoteHostKernel) ResolveRunConfigurations(context.Context, string, []core.RunInstalledPlugin) (core.RunConfigResolution, error) { + r := &k.runs + r.mu.Lock() + defer r.mu.Unlock() + return core.RunConfigResolution{Configurations: append([]core.RunConfiguration(nil), r.configurations...)}, nil +} + +func (k *remoteHostKernel) RunConfigurationTypes(context.Context, *core.RunTypePlugins) ([]core.RunConfigurationType, []core.RunTypeLocalization, error) { + return []core.RunConfigurationType{}, nil, nil +} + +func (k *remoteHostKernel) RunBeforeLaunch(context.Context, string, string, *core.RunTypePlugins) (core.RunBeforeLaunch, error) { + r := &k.runs + r.mu.Lock() + defer r.mu.Unlock() + return core.RunBeforeLaunch{Status: "ok", Steps: r.steps}, nil +} + +func (k *remoteHostKernel) CreateRunLaunchPlan(_ context.Context, _, _, base string) (core.RunLaunchPlan, error) { + r := &k.runs + r.mu.Lock() + defer r.mu.Unlock() + r.bases = append(r.bases, base) + plan := r.plan + if plan.InlineScript != nil { + script := *plan.InlineScript + script.Path = base + ".sh" + plan.InlineScript = &script + plan.Arguments = []string{script.Path} + } + return plan, nil +} + +func (k *remoteHostKernel) RemoteTempDirectory(_ context.Context, _, prefix string) (string, error) { + if prefix != remoteRunScratchPrefix { + return "", &core.Error{Command: "remote.hostRequest", Code: core.CodeInvalidRequest, Message: "unexpected prefix"} + } + return remoteTestRunScratch, nil +} + +func (k *remoteHostKernel) RemoteRemove(_ context.Context, _, path string, recursive bool) error { + k.mu.Lock() + for name := range k.files { + if strings.HasPrefix(name, path+"/") { + delete(k.files, name) + } + } + k.mu.Unlock() + r := &k.runs + r.mu.Lock() + defer r.mu.Unlock() + if recursive { + r.removed = append(r.removed, path) + } + return nil +} + +func (k *remoteHostKernel) RemoteRunProcess(ctx context.Context, session string, open core.RemoteProcessOpen, events core.RemoteProcessEvents) (core.RemoteProcessExit, error) { + script, written := "", false + if len(open.Argv) > 1 { + script, written = k.file(open.Argv[1]) + } + r := &k.runs + r.mu.Lock() + r.opens, r.sessions = append(r.opens, open), append(r.sessions, session) + if written { + r.scripts = append(r.scripts, script) + } + exit, hold, signalled, ended := r.exit, r.hold, r.signalled, r.ended + r.mu.Unlock() + if ended != nil { + defer close(ended) + } + events.Started(7, 4242) + events.Output("stdout", []byte(remoteHostRunOutput)) + if !hold { + return exit, nil + } + select { + case <-signalled: + signal := 15 + return core.RemoteProcessExit{Signal: &signal}, nil + case <-ctx.Done(): + return core.RemoteProcessExit{}, ctx.Err() + } +} + +func (k *remoteHostKernel) RemoteProcessKill(_ context.Context, _ string, processID uint64, force bool) error { + r := &k.runs + r.mu.Lock() + defer r.mu.Unlock() + if processID != 7 { + return nil + } + if force { + r.kills = append(r.kills, "kill") + } else { + r.kills = append(r.kills, "term") + } + if r.signalled != nil { + close(r.signalled) + r.signalled = nil + } + return nil +} + +// setRuns changes the host's runs under their lock. +func (k *remoteHostKernel) setRuns(change func(r *remoteHostRuns)) { + k.runs.mu.Lock() + defer k.runs.mu.Unlock() + change(&k.runs) +} + +// hostRuns is a copy of what the host's runs were asked. +func (k *remoteHostKernel) hostRuns() (opens []core.RemoteProcessOpen, sessions, bases, removed, kills []string) { + k.runs.mu.Lock() + defer k.runs.mu.Unlock() + r := &k.runs + return append(opens, r.opens...), append(sessions, r.sessions...), append(bases, r.bases...), append(removed, r.removed...), append(kills, r.kills...) +} + +// remoteTestRunConfiguration is the built-in shell run the workspace keeps. +var remoteTestRunConfiguration = core.RunConfiguration{ID: "greet", Name: "Greet", Provider: runProviderShell} + +// openRemoteRunProject opens the remote workspace with one shell run saved as text, whose plan +// runs its script in src, and waits until the configurations are listed. +func openRemoteRunProject(t *testing.T) (*harness, *remoteHostKernel, *project, *treeRecordingLog) { + t.Helper() + h, k, _, logger := remoteWorkspaceHarness(t) + k.setRuns(func(r *remoteHostRuns) { + r.configurations = []core.RunConfiguration{remoteTestRunConfiguration} + zero := 0 + r.exit = core.RemoteProcessExit{ExitCode: &zero} + r.plan = core.RunLaunchPlan{ + Executable: core.RunPlanExecutable{Command: "sh"}, + WorkingDirectory: "src", + Environment: map[string]string{"FROM_PLAN": "1"}, + Env: map[string]string{"FROM_CONFIG": "2"}, + InlineScript: &core.RunInlineScript{Content: "echo hi\n"}, + } + }) + p := h.openRemoteTestProject(t) + h.app.post(func(a *App) { a.loadBuildSystems(p) }) + h.await("the remote workspace's run configurations", func() bool { + return p.runConfigs.generation > 0 && !p.runConfigs.loading && len(p.runConfigs.list) == 1 + }) + return h, k, p, logger +} + +// startRemoteRun starts the configuration as the title bar's Run does, without the trust +// question the folder's safe mode asks first. +func (h *harness) startRemoteRun(p *project, id string) { + h.app.post(func(a *App) { + if _, err := a.startRunConfiguration(p, id); err == nil { + a.showBuildConsole(p) + } + }) +} + +// awaitRemoteRun waits until a run labelled label other than previous ended and returns it. +func (h *harness) awaitRemoteRun(p *project, label string, previous *runEntry) *runEntry { + h.t.Helper() + var found *runEntry + h.await("the remote run of "+label, func() bool { + for _, entry := range p.build.runs { + if entry != previous && entry.label == label && !entry.running && !p.build.active() { + found = entry + return true + } + } + return false + }) + return found +} + +// A remote workspace's built-in run starts on the host over the workspace's session: Core plans +// it with a host script base, the script is written below the host's temporary folder, the +// process starts in the host folder's working directory with the plan's environment over the +// login one, and its output reaches the Run window, whose tab says it runs on the host. The +// temporary folder is removed once the run ended. The Run window is not the local-only notice. +// Neither the host nor its paths are logged. +func TestRemoteWorkspaceRunsBuiltInConfigurationsOnTheHost(t *testing.T) { + h, k, p, logger := openRemoteRunProject(t) + lang := h.app.language() + if p.build.failed != i18n.Shared(lang, "desktop.run.remote.buildTools") { + t.Fatal("the run configuration menu does not say build tools do not work here") + } + + h.startRemoteRun(p, remoteTestRunConfiguration.ID) + run := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, nil) + if run.outcome != runSucceeded || !strings.Contains(run.output.all(), "hello from the host") { + t.Fatalf("the run ended %v: %s; console:\n%s", run.outcome, run.summary, run.output.all()) + } + if !run.remote { + t.Fatal("the Run window's tab does not say the program runs on the host") + } + opens, sessions, bases, removed, _ := k.hostRuns() + if len(opens) != 1 || sessions[0] != p.remote.session { + t.Fatalf("the host started %d processes over the workspace's session %v", len(opens), len(sessions) == 1 && sessions[0] == p.remote.session) + } + open := opens[0] + script := remoteTestRunScratch + "/script.sh" + if len(bases) != 1 || bases[0] != remoteTestRunScratch+"/script" { + t.Fatal("Core did not plan the script below the host's temporary folder") + } + if strings.Join(open.Argv, " ") != "sh "+script || open.Cwd != remoteTestFolder+"/src" || open.Environment != core.RemoteProcessEnvironmentLogin { + t.Fatalf("the process started with %d arguments, cwd matched %v, environment %q", len(open.Argv), open.Cwd == remoteTestFolder+"/src", open.Environment) + } + if open.Env["FROM_PLAN"] != "1" || open.Env["FROM_CONFIG"] != "2" || open.Label == nil || open.Label.Kind != "run" || open.Label.Name != "Greet" { + t.Fatalf("the process started with %d variables and label %v", len(open.Env), open.Label != nil) + } + var written []string + k.setRuns(func(r *remoteHostRuns) { written = r.scripts }) + if len(written) != 1 || written[0] != "echo hi\n" { + t.Fatal("the script was not written on the host") + } + if _, kept := k.file(script); kept { + t.Fatal("the script was left on the host") + } + if len(removed) != 1 || removed[0] != remoteTestRunScratch { + t.Fatalf("the host's temporary folder was removed %d times", len(removed)) + } + + h.app.openToolWindow(itemRun) + h.redraw() + if h.showsWrapped(i18n.Shared(lang, "desktop.remote.workspace.localOnly")) { + t.Fatal("the Run window says it does not work in a remote workspace") + } + if !h.shows(i18n.Shared(lang, "desktop.run.remote.badge")) { + t.Fatal("the Run window's tab shows no host badge") + } + sessionKept(t, logger, p, p.remote.session) + if event := loggedAny(t, logger, remoteTestHost, remoteTestHome); event != "" { + t.Fatalf("logged the host or its paths: %s", event) + } +} + +// A run that exits with a code fails with it, and one a signal ended says which. Stopping a run +// sends the host process SIGTERM first; the run ends once the host reports the process gone. +func TestRemoteWorkspaceRunEndsAsTheHostProcessEnds(t *testing.T) { + previous := buildprocess.StopGrace() + t.Cleanup(func() { buildprocess.SetStopGrace(previous) }) + // The window sets the stop time from the setting when it opens; the harness never opens one. + buildprocess.SetStopGrace(8 * time.Second) + h, k, p, logger := openRemoteRunProject(t) + three := 3 + k.setRuns(func(r *remoteHostRuns) { r.exit = core.RemoteProcessExit{ExitCode: &three} }) + h.startRemoteRun(p, remoteTestRunConfiguration.ID) + failed := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, nil) + if failed.outcome != runFailed || failed.summary != h.app.text.Run.Exited(3) { + t.Fatalf("an exit code of 3 ended the run %v: %q", failed.outcome, failed.summary) + } + + ended := make(chan struct{}) + k.setRuns(func(r *remoteHostRuns) { r.hold, r.signalled, r.ended = true, make(chan struct{}), ended }) + h.app.post(func(a *App) { p.closeRunSession(failed.id) }) + h.startRemoteRun(p, remoteTestRunConfiguration.ID) + h.await("the held run to start", func() bool { + run := p.build.runOf(configurationRunKey(remoteTestRunConfiguration.ID)) + return run != nil && run.process != nil + }) + h.app.post(func(a *App) { a.stopOperation(p, p.build.runOf(configurationRunKey(remoteTestRunConfiguration.ID))) }) + h.await("stopping the run to end the host process", func() bool { + select { + case <-ended: + return true + default: + return false + } + }) + stopped := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, failed) + if _, _, _, _, kills := k.hostRuns(); len(kills) == 0 || kills[0] != "term" { + t.Fatalf("the stop sent %v, want SIGTERM first", kills) + } + if stopped.outcome == runSucceeded { + t.Fatal("a stopped run ended as succeeded") + } + sessionKept(t, logger, p, p.remote.session) +} + +// A remote workspace refuses, with its reason, what it cannot run on the host yet: a +// configuration whose before-launch list names a plugin's task, a debug session and a program +// chosen through a toolchain. None of them starts a host process. +func TestRemoteWorkspaceRefusesRunsItCannotStartOnTheHost(t *testing.T) { + h, k, p, _ := openRemoteRunProject(t) + lang := h.app.language() + + k.setRuns(func(r *remoteHostRuns) { + r.steps = []core.RunBeforeLaunchItem{ + {ConfigurationID: remoteTestRunConfiguration.ID, Name: "Prepare"}, + {Task: &core.RunTaskReference{RunTypeKey: core.RunTypeKey{PluginID: "dev.example.build", BuildSystemID: "example", Type: "compile"}}, Name: "Compile"}, + } + }) + h.startRemoteRun(p, remoteTestRunConfiguration.ID) + refused := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, nil) + if !h.notified(i18n.Shared(lang, "desktop.run.remote.beforeLaunch")) { + t.Fatal("the before-launch steps were not refused with their reason") + } + + k.setRuns(func(r *remoteHostRuns) { + r.steps = nil + r.plan.Executable = core.RunPlanExecutable{Toolchain: "python"} + }) + h.app.post(func(a *App) { p.closeRunSession(refused.id) }) + h.startRemoteRun(p, remoteTestRunConfiguration.ID) + run := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, refused) + if !strings.Contains(run.output.all(), i18n.Shared(lang, "desktop.run.remote.toolchain")) && !strings.Contains(run.summary, i18n.Shared(lang, "desktop.run.remote.toolchain")) { + t.Fatalf("a toolchain program was not refused with its reason: %q\n%s", run.summary, run.output.all()) + } + + done := make(chan error, 1) + h.app.post(func(a *App) { + _, err := a.startRunConfigurationWith(p, remoteTestRunConfiguration.ID, &connectionDebug{}) + done <- err + }) + h.settle() + if err := <-done; err == nil || !h.notified(i18n.Shared(lang, "desktop.run.remote.unsupported")) { + t.Fatalf("a debug session was not refused: %v", err) + } + if opens, _, _, _, _ := k.hostRuns(); len(opens) != 0 { + t.Fatalf("the host started %d processes", len(opens)) + } +} + +// A remote workspace runs the before-launch steps that start another built-in run on its host, +// in order and over the workspace's session, with their output and headers in the console of the +// configuration that starts, which starts once every step exited with 0. Each step's temporary +// folder is removed before the next starts. A step that exits with a code ends the start with +// it, and stopping the start while a step runs asks the step's host process to end first. +func TestRemoteWorkspaceRunsBeforeLaunchStepsOnTheHost(t *testing.T) { + previous := buildprocess.StopGrace() + t.Cleanup(func() { buildprocess.SetStopGrace(previous) }) + // The window sets the stop time from the setting when it opens; the harness never opens one. + buildprocess.SetStopGrace(8 * time.Second) + h, k, p, logger := openRemoteRunProject(t) + lang := h.app.language() + k.setRuns(func(r *remoteHostRuns) { + r.steps = []core.RunBeforeLaunchItem{{ConfigurationID: remoteTestRunConfiguration.ID, Name: "Prepare"}} + }) + h.startRemoteRun(p, remoteTestRunConfiguration.ID) + run := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, nil) + header := i18n.SharedFormat(lang, "desktop.runConfig.beforeLaunch.stepHeader", map[string]string{"index": "1", "count": "1", "name": "Prepare"}) + console := run.output.all() + if run.outcome != runSucceeded || !strings.Contains(console, header) || strings.Count(console, "hello from the host") != 2 { + t.Fatalf("the run ended %v: %s; console:\n%s", run.outcome, run.summary, console) + } + opens, sessions, bases, removed, _ := k.hostRuns() + if len(opens) != 2 || opens[0].Label == nil || opens[0].Label.Name != "Prepare" || opens[1].Label == nil || opens[1].Label.Name != remoteTestRunConfiguration.Name { + t.Fatalf("the host started %d processes, want the step's and then the configuration's", len(opens)) + } + for _, session := range sessions { + if session != p.remote.session { + t.Fatal("a process started over another session") + } + } + if len(bases) != 2 || len(removed) != 2 || opens[0].Cwd != remoteTestFolder+"/src" { + t.Fatalf("%d plans, %d temporary folders removed, step cwd matched %v", len(bases), len(removed), opens[0].Cwd == remoteTestFolder+"/src") + } + + three := 3 + k.setRuns(func(r *remoteHostRuns) { r.exit = core.RemoteProcessExit{ExitCode: &three} }) + h.app.post(func(a *App) { p.closeRunSession(run.id) }) + h.startRemoteRun(p, remoteTestRunConfiguration.ID) + failed := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, run) + exited := i18n.SharedFormat(lang, "desktop.runConfig.beforeLaunch.exited", map[string]string{"name": "Prepare", "code": "3"}) + if failed.outcome == runSucceeded || !strings.Contains(failed.output.all(), exited) { + t.Fatalf("a step that exited with 3 ended the start %v; console:\n%s", failed.outcome, failed.output.all()) + } + if opens, _, _, _, _ := k.hostRuns(); len(opens) != 3 { + t.Fatalf("the configuration started after its step failed: %d processes", len(opens)) + } + + ended := make(chan struct{}) + k.setRuns(func(r *remoteHostRuns) { r.hold, r.signalled, r.ended = true, make(chan struct{}), ended }) + h.app.post(func(a *App) { p.closeRunSession(failed.id) }) + h.startRemoteRun(p, remoteTestRunConfiguration.ID) + h.await("the held step to start", func() bool { + opens, _, _, _, _ := k.hostRuns() + return len(opens) == 4 + }) + h.app.post(func(a *App) { a.stopOperation(p, p.build.runOf(configurationRunKey(remoteTestRunConfiguration.ID))) }) + h.await("stopping the start to end the step's host process", func() bool { + select { + case <-ended: + return true + default: + return false + } + }) + stopped := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, failed) + opens, _, _, removed, kills := k.hostRuns() + if len(kills) == 0 || kills[0] != "term" || len(opens) != 4 || len(removed) != 4 { + t.Fatalf("the stop sent %v; %d processes started, %d temporary folders removed", kills, len(opens), len(removed)) + } + if stopped.outcome == runSucceeded { + t.Fatal("a stopped start ended as succeeded") + } + sessionKept(t, logger, p, p.remote.session) + if event := loggedAny(t, logger, remoteTestHost, remoteTestHome); event != "" { + t.Fatalf("logged the host or its paths: %s", event) + } +} + +// remoteRunDirectory keeps a plan's working directory inside the host folder. +func TestRemoteRunDirectoryStaysInTheHostFolder(t *testing.T) { + for directory, want := range map[string]string{"": "/srv/app", ".": "/srv/app", "src": "/srv/app/src", "src/../lib": "/srv/app/lib"} { + if got, err := remoteRunDirectory("/srv/app", directory); err != nil || got != want { + t.Errorf("%q: %q, %v; want %q", directory, got, err, want) + } + } + for _, directory := range []string{"..", "../other", "/etc", "src/../../other"} { + if _, err := remoteRunDirectory("/srv/app", directory); err == nil { + t.Errorf("%q left the host folder", directory) + } + } +} + +// remoteRunOutput delivers output in order off the request's goroutine and, past its limit, +// keeps the newest output and says some was left out. +func TestRemoteRunOutputDropsTheOldestPastItsLimit(t *testing.T) { + release := make(chan struct{}) + var mu sync.Mutex + var delivered strings.Builder + output := newRemoteRunOutput(func(text string) { + <-release + mu.Lock() + delivered.WriteString(text) + mu.Unlock() + }, "[dropped]") + output.add([]byte("first ")) + output.add([]byte(strings.Repeat("x", remoteRunOutputLimit))) + output.add([]byte("last")) + close(release) + output.close() + mu.Lock() + defer mu.Unlock() + got := delivered.String() + if !strings.Contains(got, "[dropped]") || !strings.HasSuffix(got, "last") || len(got) > 2*remoteRunOutputLimit+64 { + t.Fatalf("delivered %d bytes, notice %v, newest kept %v", len(got), strings.Contains(got, "[dropped]"), strings.HasSuffix(got, "last")) + } +} + +// An output link in a remote workspace names host paths: the first that is a file on the host +// opens through the workspace's placeholder, below the folder or, outside it, below the host's +// sibling (the Zed way). A relative path, a folder and a missing file open nothing. +func TestRemoteOutputLinksFindHostFiles(t *testing.T) { + h, k, _, _ := remoteWorkspaceHarness(t) + p := h.openRemoteTestProject(t) + k.put(remoteTestFolder+"/src/main.go", "package main\n") + k.put("/usr/include/stdio.h", "") + k.set(func(k *remoteHostKernel) { + if k.kinds == nil { + k.kinds = map[string]core.RemoteFileKind{} + } + k.kinds[remoteTestFolder+"/src"] = core.RemoteFileKindDirectory + }) + find := p.remoteFileFinder(h.app.kernel) + ctx := context.Background() + candidates := []string{"src/main.go", remoteTestFolder + "/src", remoteTestFolder + "/gone.go", remoteTestFolder + "/src/main.go"} + if got := find(ctx, candidates); got != filepath.Join(p.root, "src", "main.go") { + t.Fatalf("a file in the folder opened %v", got != "") + } + if got := find(ctx, []string{"/usr/include/stdio.h"}); got != filepath.Join(p.root+remoteplaceholder.HostSuffix, "usr", "include", "stdio.h") { + t.Fatalf("a host file outside the folder opened %v", got != "") + } + if got := find(ctx, []string{remoteTestFolder + "/gone.go", remoteTestFolder + "/src"}); got != "" { + t.Fatal("a missing host file or a folder opened") + } +} diff --git a/desktop/internal/workbench/remote_run_visual_test.go b/desktop/internal/workbench/remote_run_visual_test.go new file mode 100644 index 000000000..e8caba701 --- /dev/null +++ b/desktop/internal/workbench/remote_run_visual_test.go @@ -0,0 +1,121 @@ +//go:build vivahead && lithevisual + +package workbench + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteplaceholder" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteserver" + "github.com/1lck/Lithe-IDEA/desktop/internal/store" + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/headless" +) + +// TestVisualRemoteRun captures a built-in run configuration of a remote workspace that ran on the +// host after its before-launch step, another built-in run, ran there: the Run window's tab with +// the host badge, the step's header and both host processes' output, and the title bar's run +// configuration menu, which says build tools do not run in a remote workspace yet. +func TestVisualRemoteRun(t *testing.T) { + out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") + if out == "" { + t.Skip("set LITHE_VISUAL_OUTPUT_DIR") + } + if err := os.MkdirAll(out, 0755); err != nil { + t.Fatal(err) + } + for _, look := range []struct{ theme, language, suffix string }{ + {"light", "en-US", "light-en-US"}, + {"dark", "zh-Hans", "dark-zh-CN"}, + } { + t.Run(look.suffix, func(t *testing.T) { + prefs := store.At(t.TempDir()) + if err := prefs.Save(settingsFile, settings{Theme: themeChoice(look.theme), Language: look.language, DisableAutoSave: true}); err != nil { + t.Fatal(err) + } + var session *headless.Session + kernel := &remoteHostKernel{testKernel: &testKernel{Client: core.NewClient()}} + // The folder was kept in safe mode before, so it opens without the trust question. + kernel.git.trust = map[string]string{remoteTestFolder: core.WorkspaceDistrusted} + zero := 0 + // Greet starts once Prepare, another built-in run, ran before it on the host. + prepare := core.RunConfiguration{ID: "prepare", Name: "Prepare", Provider: runProviderShell} + kernel.runs.configurations = []core.RunConfiguration{prepare, remoteTestRunConfiguration} + kernel.runs.steps = []core.RunBeforeLaunchItem{{ConfigurationID: prepare.ID, Name: prepare.Name}} + kernel.runs.exit = core.RemoteProcessExit{ExitCode: &zero} + kernel.runs.plan = core.RunLaunchPlan{ + Executable: core.RunPlanExecutable{Command: "sh"}, + WorkingDirectory: "src", + InlineScript: &core.RunInlineScript{Content: "echo hello from the host\n"}, + } + h := newHarnessWithDriver(t, Options{Kernel: kernel, Store: prefs, Languages: []string{look.language}}, func(config app.Config) (*app.Driver, func(), error) { + config.Width, config.Height = 1200, 760 + var err error + session, err = headless.Open(config, nil, headless.Options{}) + if err != nil { + return nil, nil, err + } + return session.Driver(), session.Close, nil + }) + shot := func(scene string) { + t.Helper() + // The scenes set the window's state directly, which does not ask for a frame. + h.app.invalidator.Invalidate() + h.settleChain() + if err := session.Screenshot(filepath.Join(out, "remote-run-"+scene+"-"+look.suffix+".png")); err != nil { + t.Fatal(err) + } + } + timers := &remoteTimers{} + anchor := filepath.Join(t.TempDir(), remoteplaceholder.AnchorName) + h.app.remoteBundle = func() (remoteserver.Bundle, error) { + return remoteserver.Bundle{Version: "0.0.0-visual", Builds: []remoteserver.Build{{ + Target: "x86_64-unknown-linux-musl", Path: "/bundle/lithe-server", SHA256: strings.Repeat("0", 64), + }}}, nil + } + h.app.remoteAnchor = func() (string, error) { return anchor, nil } + h.app.remoteAfter = timers.start + h.app.openRemote(surfaceMenu) + h.settleChain() + r := &h.app.remote + r.selectNew() + r.form.name.SetText("Build box") + r.form.host.SetText(remoteTestHost) + r.form.user.SetText("dev") + h.app.saveRemote() + h.settleChain() + if r.err != "" || r.fieldErr.field != "" { + t.Fatalf("saving the connection: %q %+v", r.err, r.fieldErr) + } + + p := h.openRemoteTestProject(t) + h.app.post(func(a *App) { a.loadBuildSystems(p) }) + h.await("the remote workspace's run configurations", func() bool { + return p.runConfigs.generation > 0 && !p.runConfigs.loading && len(p.runConfigs.list) == 2 + }) + h.app.chooseTitleConfiguration(p, remoteTestRunConfiguration.ID) + h.app.openToolWindow(itemRun) + h.startRemoteRun(p, remoteTestRunConfiguration.ID) + run := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, nil) + h.await("the step's and the configuration's host output in the console", func() bool { + return strings.Count(run.output.all(), "hello from the host") == 2 + }) + // The pointer leaves the title bar, whose tooltip would cover the console. + if err := h.driver.Move(800, 300); err != nil { + t.Fatal(err) + } + shot("console") + + h.app.openRunConfigMenu() + h.settleChain() + if !h.app.title.runConfigOpen { + t.Fatal("the run configuration menu did not open") + } + shot("menu") + }) + } +} diff --git a/desktop/internal/workbench/remote_workspace_test.go b/desktop/internal/workbench/remote_workspace_test.go index b2d986978..531eb43bc 100644 --- a/desktop/internal/workbench/remote_workspace_test.go +++ b/desktop/internal/workbench/remote_workspace_test.go @@ -82,6 +82,8 @@ type remoteHostKernel struct { ports remoteHostPorts // wsl is this computer's WSL distributions (remote_wsl_test.go). wsl remoteHostWSL + // runs are the workspace's run configurations and the host's processes (remote_run_test.go). + runs remoteHostRuns // containers are this computer's running containers (remote_container_test.go). containers remoteHostContainers // devcontainers is this computer's Dev Container CLI (remote_devcontainer_test.go). diff --git a/desktop/internal/workbench/run_view.go b/desktop/internal/workbench/run_view.go index b2f405863..85f901468 100644 --- a/desktop/internal/workbench/run_view.go +++ b/desktop/internal/workbench/run_view.go @@ -54,13 +54,17 @@ func (a *App) runSessionTabs(c ui.C, p *project) { for index, run := range runs { k := c.Key(run.id) on := run == shown + tooltip := run.label + if run.remote { + tooltip += "\n" + i18n.Shared(a.language(), "desktop.run.remote.badgeHelp") + } chip := ui.Row(k).Height(rowHeight).Shrink(1).MinWidth(0).Items(ui.Center).Gap(6).PadX(toolTabPad). Radius(a.theme.Metrics.RadiusItem()). HitWith(ui.ID(k), run.label, gfx.HitOptions{ Role: gfx.RoleTab, Cursor: gfx.PointerCursorHand, Selected: on, PosInSet: int32(index + 1), SetSize: int32(len(runs)), }). - Tooltip(run.label). + Tooltip(tooltip). Pressed(ui.Look{}.Background(a.colors.Active)) if on { chip = chip.Background(a.colors.TabIdle).Stroke(1, a.colors.TabIdleBorder).Radius(6) @@ -80,6 +84,9 @@ func (a *App) runSessionTabs(c ui.C, p *project) { } else { text.Color(a.colors.Subtle).StateFrom(chip).Hover(ui.Look{}.Color(a.colors.Text)) } + if run.remote { + a.runTabBadge(k.Part("host"), i18n.Shared(a.language(), "desktop.run.remote.badge"), on) + } if run.running && len(run.ports) > 0 { a.runTabPortBadge(k.Part("ports"), run, on) } @@ -243,11 +250,19 @@ func runDetail(p *project, run *runEntry) string { return "" } +// runTabPortBadge declares the badge of a Run tab whose process listens: its first port, and how +// many more it has. func (a *App) runTabPortBadge(c ui.C, run *runEntry, selected bool) { badge := run.ports[0].Label if len(run.ports) > 1 { badge += " " + a.text.Run.Ports.More(len(run.ports)-1) } + a.runTabBadge(c, badge, selected) +} + +// runTabBadge declares a small label after a Run tab's name, such as the host a remote +// workspace's program runs on or the ports it listens on. +func (a *App) runTabBadge(c ui.C, badge string, selected bool) { fill := a.colors.Hover if selected { fill = a.colors.Active diff --git a/desktop/internal/workbench/runconfig.go b/desktop/internal/workbench/runconfig.go index b01cce80c..3577431e0 100644 --- a/desktop/internal/workbench/runconfig.go +++ b/desktop/internal/workbench/runconfig.go @@ -276,6 +276,14 @@ func (a *App) startRunConfigurationWith(p *project, id string, debug *connection a.notifyError(message) return nil, refuseBuild(refusalNotReady, message) } + // A remote workspace runs its built-in process runs on its host; a debugger and the runs of + // plugins, which run on this computer, do not reach it yet. + if p.remote != nil && (debug != nil || !configuration.IsProcess()) { + message := i18n.Shared(a.language(), "desktop.run.remote.unsupported") + a.operationRejected("run_configuration", "remote_workspace") + a.notifyError(message) + return nil, refuseBuild(refusalNotSupported, message) + } if configuration.IsProcess() { if debug != nil { return nil, refuseBuild(refusalNotSupported, "a built-in process run has no debugger") diff --git a/desktop/internal/workbench/runconfig_before_launch.go b/desktop/internal/workbench/runconfig_before_launch.go index 23277ec71..295f5bceb 100644 --- a/desktop/internal/workbench/runconfig_before_launch.go +++ b/desktop/internal/workbench/runconfig_before_launch.go @@ -17,7 +17,6 @@ import ( "encoding/json" "errors" "fmt" - "os/exec" "slices" "github.com/1lck/Lithe-IDEA/desktop/internal/buildprocess" @@ -73,6 +72,16 @@ func (a *App) runBeforeLaunch(p *project, op *buildOperation, id string, start f start() return } + // A remote workspace runs a step that starts another built-in run on its host. A + // plugin's task is planned by the plugin's backend on this computer, which reads no + // host files (#2231 §2, R3), so a list naming one does not start. + if p.remote != nil && slices.ContainsFunc(steps.Steps, func(step core.RunBeforeLaunchItem) bool { return step.Task != nil }) { + message := i18n.Shared(a.language(), "desktop.run.remote.beforeLaunch") + a.operationRejected("run_before_launch", "remote_workspace") + a.notifyError(message) + a.finishBuildError(p, op, errors.New(message)) + return + } run := func() { a.runBeforeLaunchSteps(p, op, steps.Steps, start) } if steps.Confirmation == nil || a.beforeLaunchApproved(root, steps.Confirmation.Fingerprint) { run() @@ -131,13 +140,14 @@ func (a *App) refuseBeforeLaunch(p *project, op *buildOperation, refusal *core.R // beforeLaunchRun is what the steps of one start take from the window thread: the project, // the kernel and language, the build messages and plugin directory a task's plan needs, and, // per step that runs a plugin's task, the detected instances of the build system that -// declares it. +// declares it. remote runs a remote workspace's steps on its host, nil for a local project. type beforeLaunchRun struct { root, pluginRoot string kernel Kernel language i18n.Language messages i18n.BuildMessages instances [][]buildInstance + remote *remoteRunHost } // runBeforeLaunchSteps starts each step in order off the window thread and waits for it; @@ -156,7 +166,17 @@ func (a *App) runBeforeLaunchSteps(p *project, op *buildOperation, steps []core. run.instances[index] = p.runTypeInstances(step.Task.RunTypeKey) } } + if p.remote != nil { + run.remote = &remoteRunHost{ + kernel: a.kernel, binding: p.remote.binding, root: p.root, language: run.language, + output: func(text string) { a.streamBuildOutput(p, op, text) }, + lost: a.remoteSessionLost(p), + } + } a.background(p, 0, func(ctx context.Context) func(*App) { + if run.remote != nil { + run.remote.failed = func(operation string, err error) { a.backgroundFailedIn(ctx, operation, remoteLogError(err)) } + } for index, step := range steps { header := i18n.SharedFormat(run.language, "desktop.runConfig.beforeLaunch.stepHeader", map[string]string{ "index": fmt.Sprint(index + 1), "count": fmt.Sprint(len(steps)), "name": step.Name, @@ -188,6 +208,9 @@ func (a *App) runBeforeLaunchStep(ctx context.Context, p *project, op *buildOper if step.Task != nil { return a.runBeforeLaunchTask(prepare, p, run, instances, step, output) } + if run.remote != nil { + return run.remote.runStep(ctx, prepare, step) + } process, cleanup, err := a.startConfiguredProcess(prepare, prepare, run.kernel, run.language, run.root, step.ConfigurationID, output) defer cleanup() if err != nil { @@ -233,7 +256,8 @@ func (a *App) failBeforeLaunch(p *project, op *buildOperation, step core.RunBefo return } language := a.language() - var exit *exec.ExitError + // A local process ends with an *exec.ExitError, a host process with a remoteRunExit. + var exit interface{ ExitCode() int } message := i18n.SharedFormat(language, "desktop.runConfig.beforeLaunch.failed", map[string]string{"name": step.Name, "reason": err.Error()}) if errors.As(err, &exit) { message = i18n.SharedFormat(language, "desktop.runConfig.beforeLaunch.exited", map[string]string{"name": step.Name, "code": fmt.Sprint(exit.ExitCode())}) diff --git a/desktop/internal/workbench/runconfig_process.go b/desktop/internal/workbench/runconfig_process.go index 7eefeddbf..892b89f5a 100644 --- a/desktop/internal/workbench/runconfig_process.go +++ b/desktop/internal/workbench/runconfig_process.go @@ -56,6 +56,10 @@ func (a *App) startProcessRun(p *project, configuration core.RunConfiguration) * a.launchDeclaredRun(p, op, id, key) return } + if p.remote != nil { + a.launchRemoteProcessRun(p, op, id) + return + } a.launchProcessRun(p, op, id) }) }) diff --git a/desktop/internal/workbench/runs.go b/desktop/internal/workbench/runs.go index 14aa5bb55..f361d4aa1 100644 --- a/desktop/internal/workbench/runs.go +++ b/desktop/internal/workbench/runs.go @@ -69,6 +69,8 @@ type runEntry struct { started, ended time.Time // summary is how the execution ended, shown under the console. summary string + // remote says the execution runs on a remote workspace's host, which its tab shows. + remote bool // console is the console's selection and scroll state. console textview.View // snapshots counts the output snapshots taken of this run, so each tab has its own URI. diff --git a/desktop/internal/workbench/shell_view.go b/desktop/internal/workbench/shell_view.go index c03504cbe..558103015 100644 --- a/desktop/internal/workbench/shell_view.go +++ b/desktop/internal/workbench/shell_view.go @@ -166,10 +166,11 @@ func (a *App) shellPanel(c ui.C, s slot, index int, hidden *slot) ui.Box { // remoteToolWindow reports whether the tool window id works in a remote workspace: the project // listing, search and terminals run on the host, and so do Git's log and commit once the -// workspace is trusted (in safe mode they say so, as in a local project); Ports exists only there. +// workspace is trusted (in safe mode they say so, as in a local project), and so does Run, for the +// built-in process runs; Ports exists only there. func remoteToolWindow(id string) bool { switch id { - case itemProject, itemNotifications, itemTerminal, itemFind, itemGit, itemCommit, itemPorts: + case itemProject, itemNotifications, itemTerminal, itemFind, itemGit, itemCommit, itemRun, itemPorts: return true } return false diff --git a/desktop/internal/workbench/title_run.go b/desktop/internal/workbench/title_run.go index 2838e9a16..19a405db9 100644 --- a/desktop/internal/workbench/title_run.go +++ b/desktop/internal/workbench/title_run.go @@ -150,8 +150,9 @@ func (a *App) titleDebug(p *project) { // while the configurations are read, and an answer that settles them while they are asked for // performs it; otherwise Core decides what the press does now. func (a *App) titleStart(p *project, action titleAction) { - // A remote workspace's project runs on its host, which Run and Debug do not reach yet. - if a.refuseRemote(p, "title_run") { + // A remote workspace's project runs on its host, where Run starts a built-in configuration + // (remote_run.go); Debug and the current file's run do not reach it yet. + if (action == titleActionDebug || p.runConfigs.currentFile) && a.refuseRemote(p, "title_run") { return } if !p.runConfigs.currentFile { @@ -186,6 +187,14 @@ func (a *App) decideTitleAction(p *project, action titleAction, trigger string) facts.Action = "debug" } configuration := p.titleConfiguration() + if p.remote != nil && configuration != nil && !configuration.IsProcess() && !configuration.Unavailable() { + // A remote workspace detects no build system and runs no plugin, so only a built-in + // configuration starts there; the others say why instead of a missing target. + p.runConfigs.pending = titleActionNone + a.operationRejected("title_run", "remote_workspace") + a.notifyError(i18n.Shared(a.language(), "desktop.run.remote.unsupported")) + return + } var reference core.RunProviderReference index := -1 if configuration != nil { diff --git a/docs/assets/remote-run/README.md b/docs/assets/remote-run/README.md new file mode 100644 index 000000000..0c9db9f66 --- /dev/null +++ b/docs/assets/remote-run/README.md @@ -0,0 +1,17 @@ +# 远程工作区在主机上运行(#2231 R1,#43a、#43b)无头测试截图 + +来自生产 Viva Page 的无头渲染。连接、主机和运行配置都由测试替身提供,不连接真实主机、不启动真实进程。截图覆盖深色中文和浅色英文界面,用于确认: + +- 远程工作区里内置的运行配置在主机上运行后,Run 窗口的标签页带“主机”徽标,控制台显示主机进程的输出和退出码; +- “执行前”列表里的另一个内置运行配置(Prepare)先在主机上运行,控制台先显示步骤标题和它的输出,再显示配置本身的输出; +- 标题栏的运行配置菜单列出内置配置,并用一行不可点的说明告诉用户构建工具和插件运行暂不在远程工作区里工作。 + +截图不代表 macOS/Windows 原生窗口验收。 + +| 场景 | 深色中文 | 浅色英文 | +| --- | --- | --- | +| Run 窗口 | [深色中文](remote-run-console-dark-zh-CN.png) | [浅色英文](remote-run-console-light-en-US.png) | +| 运行配置菜单 | [深色中文](remote-run-menu-dark-zh-CN.png) | [浅色英文](remote-run-menu-light-en-US.png) | + +复验:从仓库根目录设置绝对路径 `LITHE_VISUAL_OUTPUT_DIR="$(pwd)/docs/assets/remote-run"`,在 `desktop/` 下通过 +`../scripts/desktop/desktop-go.sh test -tags vivahead,lithevisual ./internal/workbench -run '^TestVisualRemoteRun$' -count=1 -timeout 300s` 生成。 diff --git a/docs/assets/remote-run/remote-run-console-dark-zh-CN.png b/docs/assets/remote-run/remote-run-console-dark-zh-CN.png new file mode 100644 index 000000000..8f53ed89a Binary files /dev/null and b/docs/assets/remote-run/remote-run-console-dark-zh-CN.png differ diff --git a/docs/assets/remote-run/remote-run-console-light-en-US.png b/docs/assets/remote-run/remote-run-console-light-en-US.png new file mode 100644 index 000000000..7c03493ea Binary files /dev/null and b/docs/assets/remote-run/remote-run-console-light-en-US.png differ diff --git a/docs/assets/remote-run/remote-run-menu-dark-zh-CN.png b/docs/assets/remote-run/remote-run-menu-dark-zh-CN.png new file mode 100644 index 000000000..9c295d82d Binary files /dev/null and b/docs/assets/remote-run/remote-run-menu-dark-zh-CN.png differ diff --git a/docs/assets/remote-run/remote-run-menu-light-en-US.png b/docs/assets/remote-run/remote-run-menu-light-en-US.png new file mode 100644 index 000000000..6de59b285 Binary files /dev/null and b/docs/assets/remote-run/remote-run-menu-light-en-US.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index 6e2ec55db..acbfcd1ee 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -331,11 +331,12 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # a kept one; remote.disconnect ends or keeps the host programs; remote.runningPrograms, # remote.endPrograms (all or the listed ones), the closePrograms preference and # closing.idleTimeoutSeconds; #161 plans the run configurations of a remote workspace (#2231). -# Lithe-core-rust feat/2231-remote-containers at b92fcaf (#162 merged with main ac80382): remote.connect -# enters a running Docker or Podman container (the container field), also on an SSH host or in a WSL -# distribution; remote.listContainers lists the running ones; remote.devcontainerConfigs and -# remote.devcontainerUp build and start the container of a devcontainer.json (#2231). -PINNED_CORE_REVISION="b92fcafeb42ee95faea20046ec459aa5fd53ef6f" +# Lithe-core-rust main at 57e55d6: #162 remote.connect enters a running Docker or Podman container +# (the container field), also on an SSH host or in a WSL distribution; remote.listContainers lists +# the running ones; remote.devcontainerConfigs and remote.devcontainerUp build and start the +# container of a devcontainer.json; #163 remote.portRecords keeps a workspace's ports and forwards; +# #164 fs.readFile reads only regular files, so a named pipe no longer blocks it (#2231, #2270). +PINNED_CORE_REVISION="57e55d6eb1769afffd15029f408def469fe7d3ab" PROFILE="debug" CHECKOUT_ONLY="no" while [[ $# -gt 0 ]]; do diff --git a/shared/i18n/features/remote-connections.json b/shared/i18n/features/remote-connections.json index dbdba9579..b9f08d365 100644 --- a/shared/i18n/features/remote-connections.json +++ b/shared/i18n/features/remote-connections.json @@ -1283,6 +1283,79 @@ "desktop" ] }, + { + "id": "desktop.run.remote.notConnected", + "description": "Run failure when the remote workspace is not connected", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.connectionLost", + "description": "Run failure when the connection to the host breaks while the program runs", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.toolchain", + "description": "Run failure when a remote run configuration asks for a toolchain, which a remote workspace does not resolve yet", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.outputDropped", + "description": "Run window line when output arrived faster than the window could show it and the oldest part was dropped", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.signal", + "description": "Run failure when a signal ended the program on the host; {signal} is the signal number", + "platforms": [ + "desktop" + ], + "parameters": { + "signal": "string" + } + }, + { + "id": "desktop.run.remote.beforeLaunch", + "description": "Run failure when a remote run configuration's Before launch list has a plugin task, which a remote workspace does not run yet", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.buildTools", + "description": "Run configuration menu note in a remote workspace: build tools and plugin runs do not work there yet", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.unsupported", + "description": "Run failure when a remote workspace is asked to debug or to run a kind of configuration it cannot run", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.badge", + "description": "Badge on a Run window tab whose program runs on the remote host", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.badgeHelp", + "description": "Tooltip of the Host badge on a Run window tab", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.remote.document.disconnected", "description": "Reason a file of a remote workspace could not be opened or saved, after “Could not open/save {name}: ”: the workspace has no connection", @@ -3430,7 +3503,17 @@ "desktop.remote.workspace.banner": "This is a remote workspace. Its files open, edit, save and are searched on the host, and terminals and Git run on the host; running, debugging and language servers do not work here yet.", "desktop.remote.workspace.safeBanner": "This remote workspace is in safe mode: you can browse, edit, save and search its files on the host. Trust the folder to use Git.", "desktop.remote.workspace.gitAbove": "This folder is inside a Git repository that starts in a folder above it on the host. Open the repository's top folder to use Git in a remote workspace.", - "desktop.remote.workspace.localOnly": "This feature does not work in a remote workspace yet. You can browse, edit, save and search the host's files, run terminals and use Git on the host.", + "desktop.remote.workspace.localOnly": "This feature does not work in a remote workspace yet. You can browse, edit, save and search the host's files, run terminals, use Git and run program and script configurations on the host.", + "desktop.run.remote.notConnected": "the remote workspace is not connected; run it again once it reconnects", + "desktop.run.remote.connectionLost": "the connection to the host broke while the program ran; whether it still runs on the host is unknown", + "desktop.run.remote.toolchain": "a remote workspace cannot run a program chosen through a toolchain yet; name the program or its path on the host", + "desktop.run.remote.outputDropped": "Some output arrived faster than it could be shown and was left out.", + "desktop.run.remote.signal": "the program was ended by signal {signal}", + "desktop.run.remote.beforeLaunch": "a remote workspace does not run plugin tasks before launch yet; remove them from the Before launch list to run the configuration on the host", + "desktop.run.remote.buildTools": "Build tools and plugin runs do not work in a remote workspace yet; program and script configurations run on the host.", + "desktop.run.remote.unsupported": "a remote workspace runs only program and script configurations, on the host, and does not debug yet", + "desktop.run.remote.badge": "Host", + "desktop.run.remote.badgeHelp": "This program runs on the remote workspace's host.", "desktop.remote.document.disconnected": "the remote workspace is not connected; try again once it reconnects", "desktop.remote.document.timedOut": "the host did not answer in time", "desktop.remote.document.notFound": "the file no longer exists on the host", @@ -3477,8 +3560,6 @@ "desktop.remote.wsl.unreachable": "This WSL distribution is not installed, or it did not start.", "desktop.remote.wsl.missing": "wsl.exe was not found on this computer. Install the Windows Subsystem for Linux to open a distribution.", "desktop.remote.wsl.start": "Start the distribution", - "desktop.remote.worktree.connectionRemoved": "The connection this workspace was opened over was deleted, so its worktree cannot be opened. Add the connection again, then open the worktree.", - "desktop.remote.worktree.destination": "The path is a folder on the host, created by Git there.", "desktop.remote.close.title": "Close the remote workspace?", "desktop.remote.close.running": "These programs are still running on {connection}:", "desktop.remote.close.end": "End and Close", @@ -3559,7 +3640,9 @@ "desktop.remote.devcontainer.unusable": "The Dev Container CLI started something Lithe cannot open: its result names no container or workspace folder.", "desktop.remote.devcontainer.untrustedRefused": "Nothing was built: this folder is not trusted.", "desktop.remote.devcontainer.upFailed": "Cannot build the dev container: {reason}", - "desktop.remote.devcontainer.stopped": "The build was stopped. A container it already started keeps running." + "desktop.remote.devcontainer.stopped": "The build was stopped. A container it already started keeps running.", + "desktop.remote.worktree.connectionRemoved": "The connection this workspace was opened over was deleted, so its worktree cannot be opened. Add the connection again, then open the worktree.", + "desktop.remote.worktree.destination": "The path is a folder on the host, created by Git there." }, "zh-CN": { "desktop.remote.title": "远程开发", @@ -3840,7 +3923,17 @@ "desktop.remote.workspace.banner": "这是远程工作区。主机上的文件可以打开、编辑、保存和搜索,终端和 Git 在主机上运行;运行、调试和语言服务器暂不可用。", "desktop.remote.workspace.safeBanner": "此远程工作区处于安全模式:可以浏览、编辑、保存和搜索主机上的文件。信任此文件夹后即可使用 Git。", "desktop.remote.workspace.gitAbove": "此文件夹位于主机上更上层文件夹开始的 Git 仓库中。请打开仓库的顶层文件夹,以便在远程工作区中使用 Git。", - "desktop.remote.workspace.localOnly": "远程工作区暂不支持此功能,可以浏览、编辑、保存和搜索主机上的文件,也可以在主机上运行终端和使用 Git。", + "desktop.remote.workspace.localOnly": "远程工作区暂不支持此功能,可以浏览、编辑、保存和搜索主机上的文件,也可以在主机上运行终端、使用 Git,以及运行程序和脚本运行配置。", + "desktop.run.remote.notConnected": "远程工作区未连接,请在重新连接后再运行", + "desktop.run.remote.connectionLost": "程序运行时与主机的连接断开了,无法确定它是否仍在主机上运行", + "desktop.run.remote.toolchain": "远程工作区暂不支持运行通过工具链选择的程序,请填写主机上的程序名或路径", + "desktop.run.remote.outputDropped": "部分输出到达太快,来不及显示,已略去。", + "desktop.run.remote.signal": "程序被信号 {signal} 结束", + "desktop.run.remote.beforeLaunch": "远程工作区暂不支持插件提供的执行前任务,请从“执行前”列表中删除这些任务后再在主机上运行", + "desktop.run.remote.buildTools": "远程工作区暂不支持构建工具和插件提供的运行;程序和脚本运行配置会在主机上运行。", + "desktop.run.remote.unsupported": "远程工作区只在主机上运行程序和脚本运行配置,暂不支持调试", + "desktop.run.remote.badge": "主机", + "desktop.run.remote.badgeHelp": "此程序运行在远程工作区的主机上。", "desktop.remote.document.disconnected": "远程工作区未连接,请在重新连接后再试", "desktop.remote.document.timedOut": "主机没有及时响应", "desktop.remote.document.notFound": "主机上已没有这个文件", @@ -3887,8 +3980,6 @@ "desktop.remote.wsl.unreachable": "这个 WSL 发行版没有安装,或者没能启动。", "desktop.remote.wsl.missing": "本机找不到 wsl.exe。安装适用于 Linux 的 Windows 子系统(WSL)后才能打开发行版。", "desktop.remote.wsl.start": "启动发行版", - "desktop.remote.worktree.connectionRemoved": "打开此工作区所用的连接已被删除,无法打开它的工作树。请重新添加该连接后再打开工作树。", - "desktop.remote.worktree.destination": "路径是主机上的文件夹,由主机上的 Git 创建。", "desktop.remote.close.title": "关闭远程工作区?", "desktop.remote.close.running": "以下进程仍在 {connection} 上运行:", "desktop.remote.close.end": "结束并关闭", @@ -3969,7 +4060,9 @@ "desktop.remote.devcontainer.unusable": "Dev Container CLI 启动的结果无法打开:结果里没有容器或工作区文件夹。", "desktop.remote.devcontainer.untrustedRefused": "没有构建:这个文件夹不受信任。", "desktop.remote.devcontainer.upFailed": "无法构建 dev container:{reason}", - "desktop.remote.devcontainer.stopped": "构建已停止。已经启动的容器会继续运行。" + "desktop.remote.devcontainer.stopped": "构建已停止。已经启动的容器会继续运行。", + "desktop.remote.worktree.connectionRemoved": "打开此工作区所用的连接已被删除,无法打开它的工作树。请重新添加该连接后再打开工作树。", + "desktop.remote.worktree.destination": "路径是主机上的文件夹,由主机上的 Git 创建。" } } } diff --git a/shared/platform-feature-matrix/features/remote-workspace.json b/shared/platform-feature-matrix/features/remote-workspace.json index 4dbeda376..1a9f74081 100644 --- a/shared/platform-feature-matrix/features/remote-workspace.json +++ b/shared/platform-feature-matrix/features/remote-workspace.json @@ -2,7 +2,7 @@ "id": "remote-workspace", "area": "工作区", "group": "远程开发", - "capability": "远程连接(SSH 主机、本机 WSL 发行版、本机及 SSH 主机与 WSL 发行版上的 Docker/Podman 容器,以及从本机文件夹的 devcontainer.json 构建并打开)、远程路径工作区、主机文件编辑与监听、按路径打开主机上的文件(工作区外只读)、主机终端、主机搜索与替换、远程信任与主机 Git(含打开和新建工作树)、端口转发(含主机侧转发规则与反向转发)、远程工作区设置(SSH 程序、断线重连与关闭时的远端进程)、关闭确认与保留远端进程", + "capability": "远程连接(SSH 主机、本机 WSL 发行版、本机及 SSH 主机与 WSL 发行版上的 Docker/Podman 容器,以及从本机文件夹的 devcontainer.json 构建并打开)、远程路径工作区、主机文件编辑与监听、按路径打开主机上的文件(工作区外只读)、主机终端、主机搜索与替换、远程信任与主机 Git(含打开和新建工作树)、主机上运行程序和脚本运行配置、端口转发(含主机侧转发规则与反向转发)、远程工作区设置(SSH 程序、断线重连与关闭时的远端进程)、关闭确认与保留远端进程", "macos": { "implementationStatus": "partial", "verificationStatus": "pending", @@ -56,9 +56,11 @@ "desktop/internal/remoteconn/preferences_test.go", "desktop/internal/settingswindow/remote_workspace_view_test.go", "desktop/internal/settingswindow/remote_workspace_visual_test.go", - "desktop/internal/workbench/remote_worktree.go", - "desktop/internal/workbench/remote_worktree_test.go", - "desktop/internal/workbench/remote_worktree_visual_test.go", + "desktop/internal/core/remote_process.go", + "desktop/internal/core/remote_process_test.go", + "desktop/internal/workbench/remote_run.go", + "desktop/internal/workbench/remote_run_test.go", + "desktop/internal/workbench/outputlinks.go", "desktop/internal/workbench/remote_port_rules.go", "desktop/internal/workbench/remote_port_rules_view.go", "desktop/internal/workbench/remote_port_rules_test.go", @@ -77,7 +79,10 @@ "desktop/internal/core/remote_devcontainer.go", "desktop/internal/core/remote_devcontainer_test.go", "desktop/internal/workbench/remote_devcontainer.go", - "desktop/internal/workbench/remote_devcontainer_test.go" + "desktop/internal/workbench/remote_devcontainer_test.go", + "desktop/internal/workbench/remote_worktree.go", + "desktop/internal/workbench/remote_worktree_test.go", + "desktop/internal/workbench/remote_worktree_visual_test.go" ] }, "windows": { @@ -116,9 +121,11 @@ "desktop/internal/workbench/remote_preferences.go", "desktop/internal/settingswindow/remote_preferences_state.go", "desktop/internal/settingswindow/remote_workspace_view.go", - "desktop/internal/workbench/remote_worktree.go", - "desktop/internal/workbench/remote_worktree_test.go", - "desktop/internal/workbench/remote_worktree_visual_test.go", + "desktop/internal/core/remote_process.go", + "desktop/internal/core/remote_process_test.go", + "desktop/internal/workbench/remote_run.go", + "desktop/internal/workbench/remote_run_test.go", + "desktop/internal/workbench/outputlinks.go", "desktop/internal/workbench/remote_port_rules.go", "desktop/internal/workbench/remote_port_rules_view.go", "desktop/internal/workbench/remote_close.go", @@ -128,11 +135,14 @@ "desktop/internal/workbench/remote_container.go", "desktop/internal/workbench/remote_host_containers.go", "desktop/internal/core/remote_devcontainer.go", - "desktop/internal/workbench/remote_devcontainer.go" + "desktop/internal/workbench/remote_devcontainer.go", + "desktop/internal/workbench/remote_worktree.go", + "desktop/internal/workbench/remote_worktree_test.go", + "desktop/internal/workbench/remote_worktree_visual_test.go" ] }, "owner": "Remote", - "verification": "在“远程开发”窗口选中已保存的 Linux SSH 连接点“连接”:SSH 询问出现在窗口中,连接后窗口改为主机的文件夹选择,从主目录开始列出子文件夹(跳过名称不是 UTF-8 的条目并说明数量),可输入 ~ 或 / 开头的路径跳转,不存在的路径说明原因且不能打开;“返回”断开这次会话回到连接表单。选中文件夹点“打开”:新标签页打开远程工作区,窗口标题为“文件夹 [SSH: 连接名]”,项目树经 Core 列出主机目录(本机占位目录始终为空),右键只有复制主机路径和刷新;以安全模式打开的文件夹,编辑器上方说明可以浏览、编辑、保存和搜索主机文件,信任文件夹后才能用 Git;受信任的文件夹说明文件、终端和 Git 都在主机上,运行、调试和语言服务器暂不可用;空白编辑区提示 Search Everywhere 和 Find in Files。在项目树双击文件:编辑器经会话读取主机文件(不超过 16 MiB),保存时带上打开时的大小和修改时间写回主机,新建的文件只在主机上不存在时创建;主机上的文件期间被别人改过时保存被拒绝并显示外部修改冲突,“加载磁盘版本”载入主机内容,本机占位目录始终为空。超过 8 MiB 的保存说明主机单次保存上限,编辑内容保留;主机上缺失、无权限、不是普通文件、超时和连接断开分别说明原因,连接断开后自动重连并把打开的文档和主机重新比对。图片、PDF 等查看器、本地历史和插件终端都被拒绝并提示,不回退到本机;在文件浏览器中显示(标签页右键、Search Everywhere 结果、Git 变更)在远程工作区里不提供。状态栏连接菜单的“打开主机上的文件…”(未连接时不可用)从窗口顶部弹出路径框,默认 ~/,经 remote.readDir 列出路径最后一个“/”之前的文件夹,按其后的文字(不分大小写)筛选名称开头,文件夹在前,以“.”开头时才列出隐藏条目,无法读取的条目说明数量;上下键移动、Tab 补全名称、回车进入文件夹或打开文件,没有匹配时回车按输入的路径打开,Esc 或点外面关闭;不以 / 或 ~/ 开头的输入说明要输入什么,名称含“\\”的路径说明在 Windows 上无法打开。工作区文件夹里的文件与项目树打开的相同、可以编辑;文件夹以外的文件(对标 Zed)在占位目录旁的 .lithe-remote-host 下以只读方式打开(S25):不能切换为可编辑(提示原因并记为拒绝),保存和新建都被拒绝并说明原因、不写主机,状态栏导航路径显示 ~ 开头的主机路径,复制相对路径不提供;重连和关闭前与其他文档一样和主机比对,主机上的改动在没有编辑时重新载入(主机监听只覆盖工作区文件夹)。日志只记 remote_open_host_file、remote_read_dir、toggle_read_only 等操作名和原因,不含主机路径。打开“终端”工具窗口:经会话的 remote.runTerminal 在主机文件夹运行主机账户的登录 shell(不带参数,不读本机 Shell 设置,没有本机 Shell 菜单),标签名为连接名,之后的标签为“连接名 (2)”等;输入按顺序、每块不超过 32 KiB 写入,主机说忙时稍后重试,窗口尺寸随输入发送;输出超过 8 MiB 未显示时丢弃最旧的部分并记一次失败。程序退出显示退出码,被信号结束显示 128+信号,关闭标签不算失败。连接断开时终端显示会话已结束,工作区按退避重连;未连接时按回车说明工作区未连接,重连后按回车在新会话上运行。终端起不来时显示 Core 给出的原因(可能含主机路径),日志只记命令名和错误码。拖到终端的文件粘贴为主机路径并按 POSIX shell 加引号,本机工作区外的文件不粘贴并提示原因;粘贴图片不可用(图片会存到本机)。每个会话连接后,经 remote.runWatch 在主机上递归监听整个文件夹,跳过已启用插件隐藏的文件夹名(按原样比较大小写),插件改变隐藏名称时重新开始监听;在主机上新建、修改、删除文件后,项目树重新列出受影响的目录(Core 的 workspace.filterChanges 按可见性规则过滤,不需要会话),打开的文档与主机比对:没有编辑的重新载入,有编辑的显示外部修改冲突;文件夹外和被隐藏文件夹里的变化不触发列表。监听开始时、主机丢失变化(overflow)时、一次超过 4096 个变化时,重新列出树中展开的目录并比对所有文档,日志每次监听各记一次;主机监听数用尽时其余部分继续监听,提示一次“项目文件可能无法自动更新”。监听中文件夹被删除或移走时立即重新监听;主机找不到文件夹时项目树显示根目录不可用,监听等树重新列出文件夹后再开始,主机与树结论不一致时也只等待、不反复重试。其他监听失败只记命令名和错误码、提示一次,等下一个会话再开始;监听发现连接断开时与心跳一样结束会话并重连。Find in Files 的搜索、计数和替换预览带远程绑定发送,Core 从主机文件夹建立索引并读取主机上的当前内容,结果路径相对主机文件夹;点结果在远程编辑器打开主机文件并定位到匹配处,本机占位目录始终为空。主机监听报告的变化路径在下一次查询前增量更新索引,不重建;监听开始和主机丢失变化时重建一次。包含生成文件的查询每次都重建索引(主机监听跳过插件隐藏的文件夹);主机监听数用尽后、会话断开到下一个会话的监听开始之间,每次查询都重建,只由监听提示一次“项目文件可能无法自动更新”,搜索不再另外提示。查询显示期间主机上的变化让结果重新查询。Search Everywhere 所有页签都可用,文件名和文本来自主机,打开弹窗时重新读取生成文件的名称;远程工作区不启动语言服务器,符号只有 Core 在主机文件中找到的。Replace All 在编辑器中替换打开的文档;未打开的文件经会话读取主机内容,由 Core 替换后,只在主机文件仍是读取时的内容时写回,期间被改过的报告冲突,已被删除的说明主机上找不到文件,其余文件照常替换,都不写本机占位目录。在文件夹选择中打开从未决定过的文件夹:先询问是否信任(显示连接名和主机文件夹,Core 给出上级文件夹时可勾选信任其下的所有文件夹),“信任并打开”把决定按连接名记入 Core 的远程信任记录后以受信任方式打开,“以安全模式打开”只读打开,“返回”回到文件夹选择;之前决定过的文件夹直接按记录打开。安全模式下 Git、提交和日志窗口与本机项目一样说明需要信任,编辑器上方的提示里可以信任文件夹,信任后不重开窗口就在主机上启动 Git。受信任的工作区经会话在主机上运行 Git:状态、暂存、提交、差异(含编辑器行号旁的变更标记)、日志与分支、逐行追溯(读取主机上的文件内容)、搁置与储藏都读写主机仓库,本机占位目录始终没有 .git;“排除到本地”写入主机仓库的 info/exclude(缺少 info 文件夹时在主机上创建,读写期间文件被别人改过时这次排除失败、不覆盖)。同一会话经 remote.runWatch 递归监听主机仓库的 git 目录(公共目录在别处时一并监听),主机上 git checkout、commit 等改动元数据后按路径分类并重新读取状态;监听开始、丢失变化或主机监听数用尽时重新读取一次完整状态,新会话重新开始监听。主机文件夹位于上级目录开始的仓库内时,Git 和提交窗口说明要打开仓库顶层文件夹,不显示变更也不记为失败。工作树列表、锁定、解锁、删除在主机上执行,列表和详情显示主机路径,复制路径复制主机路径。打开关联工作树时“远程开发”窗口打开,用打开工作区所用的连接(或 WSL 发行版)再连一次,显示连接步骤和 OpenSSH 的询问,从未决定过的文件夹先询问是否信任,然后在本窗口的新标签页经一个新会话打开该主机文件夹;再次打开时切到已打开的标签页,不再连接;连接在工作区打开后被删除时窗口说明原因、不连接。新建工作树对话框把 Core 在仓库旁的建议显示为主机路径(如 /home/dev/project-topic),输入框下说明路径是主机上的文件夹、由主机上的 Git 创建;输入的其他主机路径原样保留,“创建”在工作区会话上由主机上的 Git 创建并选中新工作树,“创建后打开”同样经新会话在新标签页打开。在新窗口打开和在文件浏览器中显示仍被拒绝并提示。受信任的远程工作区里运行、调试、当前文件运行、测试、构建任务和插件语言服务器都不在本机启动,都记为拒绝并提示,运行、测试和构建工具窗口说明暂不可用。状态栏前端显示连接名和心跳往返时间;连续两次心跳无响应显示“无响应”,第三次结束会话并按 Core 由“自动重连时长”给出的间隔重连(默认 1、2、4、8、16、29 秒,共 60 秒),每次失败后等下一个间隔,用完后显示“已断开”和原因,菜单里可“重新连接”;连接被关闭时同样按这些间隔重连;时长设为“不自动重连”时直接显示“已断开”。关闭窗口、退出 Lithe、菜单里“断开并关闭”和切换工作区时,先经 remote.runningPrograms 读取主机上 Lithe 为这个工作区启动的进程和终端;没有时直接结束会话,有时询问“关闭远程工作区?”,正文写明连接名并逐项列出类型(终端、进程)、名称、命令(原样显示,不脱敏)和已运行时长,按钮为“结束并关闭”(默认)、“保留在远端并关闭”和“取消”,“记住我的选择”旁的 ⓘ 说明之后不再询问、只能在 设置 › 工具 › 远程工作区 修改。“取消”保留窗口和会话;“结束并关闭”经 remote.disconnect 结束主机会话;“保留在远端并关闭”让主机保留会话,把恢复凭据按连接存入系统密钥存储后通知“N 个进程保留在 <连接名> 上”,凭据存不下时改为结束并说明原因,主机拒绝保留时同样结束并说明;读取进程列表失败时不询问、照常结束。勾选“记住我的选择”把结束或保留写入 Core 的远程工作区设置,之后直接按设置执行。下次经同一连接、同一 WSL 发行版或同一容器连接时带上最新的保留凭据接回会话,打开文件夹后列出上次保留、仍在运行的进程,可“结束这些进程”(经 remote.endPrograms 只结束它们,不动这次新开的)或“继续运行”;主机上已没有该会话时开新会话并忘掉凭据;接回后没打开工作区就停止的连接再次保留该会话,进程不会未经用户选择就结束。退出 Lithe 时每个远程工作区窗口同样询问,取消的窗口保持打开。最近项目不记录远程工作区。日志只有 remote.connect、remote.workspace.open/reconnect/disconnect、remote.close.cancel/keep/end、remote.kept.end/keep 等动作和失败的操作名,不含主机、用户名、主机路径、主目录、进程名称或命令。运行 remote_close_test.go 的 7 个测试、remoteconn 的 kept_test.go 3 个测试、TestVisualRemoteClose 无头截图(询问、保留后的通知、下次连接列出保留的进程)、remote_workspace_test.go 的 5 个测试、remote_git_test.go 的 6 个测试、remoteplaceholder 的 TestHostAndLocalPathsMapBothWays 与 TestHostNamedPathNamesEveryHostPathBelowTheSibling、remote_worktree_test.go 的 3 个测试、remote_documents_test.go 的 2 个测试、remote_terminal_test.go 的 9 个测试、remote_watch_test.go 的 5 个测试、remote_search_test.go 的 4 个测试、remote_host_files_test.go 的 TestRemoteOpenFileOnHost、internal/core 的 TestRemoteTerminal*、TestRemoteWatch* 与 TestRemoteWorkspaceFiltersChangesWithoutTheHost、termview 的 TestOpenStartsTheProgramElsewhere,以及 TestVisualRemoteWorkspace 与 TestVisualRemoteWorktrees 无头截图;在 Windows 运行 TestCoreRefusesUnadaptedCommandsAndAClosedSessionDetachesTheBinding,验证 Linux 主机路径能通过绑定校验。真实 SSH 主机上的整机验收(包括终端里 vim、top 等全屏程序与窗口缩放,主机上 git checkout 等大批量修改后的监听,以及大仓库上的搜索)仍待完成。远程工作区左侧多出“端口”工具窗口(本机工作区没有,关闭工作区后消失):窗口打开时每 3 秒经 ports.listening 读取主机上正在监听的端口和会话的转发,窗口关闭或未显示时停止读取;同一端口在 0.0.0.0 与 :: 上监听只显示一行;远端端口带上主机监听的 IP 地址,多个地址时显示第一个和其余数量,悬停提示列出全部,地址或网址过长被截断时悬停提示给出全文;列出远端端口、本机地址、进程(名称与 PID,读不到时为“未知”)、来源(监听发现、手动添加)和状态。默认不自动转发任何端口,打开窗口和发现新端口都不转发;行尾“转发”把端口转发到主机上对应族的回环地址,本机在 127.0.0.1 的同号端口监听,该端口被本机其他程序占用时改用空闲端口,本机地址用警告色显示并在提示里说明原端口。右键“转发到指定本机端口…”和已转发行的“更改本机端口…”打开对话框输入 1–65535 的本机端口,非法输入就地说明且不转发;改到另一个端口时先停止原转发再在新端口转发,选择在工作区打开期间保留,停止后再转发仍用该端口。顶部输入端口、主机:端口或网址(http、https、ws、wss,省略端口时按协议默认端口)可手动添加并转发,由 Core 的 remote.parseForwardAddress 解析;格式不对就地说明,网址里带用户名或密码时拒绝并说明,输入框保留原文、日志不记输入内容;同一目标再次添加不重复。网址行按输入的样子显示,转发到主机上提供该端口的回环地址;在浏览器打开和复制本机地址把主机部分换成本机地址并保留路径和查询,ws/wss 网址不提供在浏览器打开;浏览器打不开时提示网址,日志只记失败、不记网址。主机回环地址以外的目标先询问(S28),确认后才带 AllowNonLoopback 转发,取消记为拒绝。已转发行可在浏览器打开、复制本机地址、停止;手动添加且已停止、主机上也没有在监听的行可移除;窗口标题栏可全部停止,标题栏的 ⓘ 说明转发对本机其他程序可见(S30);会话转发数达到 Core 上限时说明上限;状态栏显示已转发数量,点击打开端口窗口;会话结束时转发随之结束,重连后不自动恢复。日志只记 remote.ports.forward/localPort/move/stop/status 等动作和失败操作名,不含主机、地址或进程名。运行 remote_ports_test.go 的 12 个测试、internal/core 的 TestRemoteSessionCommandsOfAnUnknownSession 与 TestRemoteParseForwardAddressReadsPortsAndURLs,以及 TestVisualRemotePorts 无头截图。手动添加的端口和本机端口选择只在工作区打开期间保留,关闭后不保存(需 Core 存储,后续阶段)。端口窗口标题栏的“+”打开“添加转发规则”:方向默认“主机端口 → 另一台服务器”,由主机自己连接目标,数据不经过本机;主机端口可留空由主机选择,目标接受端口、主机:端口或网址(由 Core 的 remote.parseForwardAddress 解析,网址里带用户名或密码时拒绝)。规则默认只在主机的回环地址 127.0.0.1 上监听;勾选“监听主机的全部网卡”时显示警告,每次添加都再次询问、不记住,列表里的监听地址用警告色显示并在悬停提示里说明;目标不是主机自身的回环地址时先询问(S28)。“主机端口 → 本机(反向转发)”只在 设置 › 工具 › 远程工作区 的“反向转发”允许时提供(默认自动,即不允许,对话框说明在哪里开启),每条都询问,主机只在回环地址监听,本机只连接回环地址上的端口。主机端口被占用、主机不允许监听(如 1024 以下)、远端服务不支持、达到会话转发上限(与本机转发合计)、反向转发未被允许分别说明原因,主机端口不是 1–65535 时就地说明,对话框保留输入。端口窗口的“转发规则”一节列出主机监听地址、转到的目标(反向转发为“本机 地址”)、连接数(有失败时注明失败数)和状态,每行可停止,标题栏的全部停止同样停止规则;规则随会话结束而停止,重连后不自动恢复,关闭工作区后也不保存。日志只记 remote.ports.addRule/ruleHost/ruleReverse/ruleConfirm/stopRule 等动作和失败的操作名,不含地址、网址或进程名。运行 remote_port_rules_test.go 的 5 个测试、settingswindow 的 TestRemoteWorkspaceReverseForwardingIsAppliedAndRestored,以及 TestVisualRemotePorts 的转发规则列表、添加对话框和全部网卡询问截图。远程 Git 的 AskPass 转交(推送、拉取时的凭据询问)、从上级目录开始的仓库尚未支持。Windows 上“远程开发”窗口在已保存的连接之后以“WSL”标题列出本机安装的 WSL 发行版(Core 的 remote.listWslDistributions,每次打开窗口读取一次;搜索时不列出,标题可折叠;macOS 和没有 WSL 的 Windows 不显示这一组)。选中发行版后右侧说明经本机 wsl.exe 打开、不保存任何信息,可填写 Linux 用户(留空为发行版默认用户),地址显示为 wsl:[用户@]发行版。“连接”经 remote.connect 的 wsl 参数启动,不经 OpenSSH、没有询问,步骤从“启动发行版”开始,不显示读取配置和身份验证;发行版没有安装或没能启动、本机找不到 wsl.exe 时分别说明,不显示 SSH 的排查提示,也没有“编辑连接”;Core 拒绝的用户名或发行版名就地说明。连接后与 SSH 相同:选择文件夹、信任询问、工作区、心跳与重连;窗口标题为“文件夹 [WSL: 发行版]”,状态栏为“WSL: 发行版”(SSH 工作区的“SSH”也由同一参数给出),列表和概览显示已打开该发行版的窗口数。发行版不写入已保存的连接,打开过的文件夹不记入最近文件夹。日志只有 remote.wsl.select、remote.connect 等动作,不含发行版名、用户名或主机路径。运行 remote_wsl_test.go 的 3 个测试、internal/core 的 TestRemoteConnectSendsWSLAloneAndCoreRefusesItByField 与 TestRemoteListWSLDistributionsIsUnavailableOutsideWindows,以及 TestVisualRemoteConnections 的 WSL 截图;真实 Windows 上的 WSL 验收(wsl.exe 的错误输出、--exec 的二进制透传、结束 wsl.exe 后 Linux 进程是否退出、未知用户)仍待完成。打开“设置 › 工具 › 远程工作区”:页面只读取、不创建任何文件。“SSH 程序”默认“自动(Core 在 PATH 上找到的 ssh 路径)”,找不到时为“自动(未找到 ssh)”;“选择…”选一个文件作为草稿,下拉菜单可回到自动;保存的程序缺失或不可执行时在行下说明。“SSH 配置文件”只显示 Core 读取的 ~/.ssh/config 路径,不存在时注明。“自动重连时长”可选“自动(1 分钟)”、不自动重连、15 秒到 1 小时,保存过的其他值也列出。“反向转发”默认“自动(不允许)”,可选允许或不允许,ⓘ 说明主机上的所有用户都能连接反向转发的端口、每条规则仍会确认。“关闭工作区”卡片里“关闭时的远端进程”可选“每次询问”(默认)、“结束”和“保留在远端”,关闭对话框勾选“记住我的选择”后只能在这里改回;“常驻会话的空闲超时”只读显示 Core 报告的远端服务超时(10 分钟),ⓘ 说明断线且没人保留的会话多久后由主机结束。“保存位置”显示偏好目录下的 remote/preferences.json,还没有文件时注明修改后才创建。修改只是草稿:侧栏和底部显示未应用数量,“应用”或“好”经 Core 的 remote.editPreferences 写入(程序先于时长),写入后重新读取显示;Core 拒绝相对路径、不存在、不可执行的程序或超出 0–3600 秒的时长时在页面说明原因并保留草稿,不写文件;文件期间被改过时重新读取并请用户再次应用;文件损坏时说明路径、不提供编辑,此时连接、测试连接、读取有效设置和导入 SSH 主机都失败并说明原因,不用未经用户选择的程序启动 OpenSSH。选中的 SSH 程序用于连接、测试连接、有效设置和 SSH 配置导入(WSL 经 wsl.exe 启动,不使用它)。日志只记 remote_preferences_settings_load/save 等操作名和 Core 错误码,不记路径。运行 settingswindow 的 TestRemoteWorkspace* 6 个测试、remoteconn 的 preferences_test.go、internal/core 的 TestRemotePreferences*,以及 TestVisualRemoteWorkspace 无头截图(中英文、深浅色,自动值、草稿和关闭时保留远端进程三种状态)。真实 SSH 主机上关闭后保留、重连接回和结束保留进程的整机验收,以及保留进程的输出重新接回终端和运行窗口(后续阶段),仍待完成。“远程开发”窗口在 WSL 发行版之后以“容器”标题列出本机 Docker 和 Podman 正在运行的容器(Core 的 remote.listContainers,每次打开窗口读取一次,两个引擎在同一个后台任务里依次读取,一个超时或报错时跳过它并记一次 remote_containers_list 失败,另一个照常列出;搜索时不列出,标题可折叠;两个引擎都没有时不显示这一组)。每行显示容器名和“引擎 · 镜像”,已有窗口打开它时显示绿点。选中容器后右侧显示引擎标签、地址 引擎:[用户@]容器、镜像与引擎给出的状态,说明经本机引擎进入正在运行的容器、不启动不创建不改动容器、不挂载目录、不保存任何信息,可填写容器内用户(用户名、uid 或 用户:组,留空为镜像默认用户)。“连接”经 remote.connect 的 container 参数进入,不经 OpenSSH、没有询问、不发送 SSH 偏好,步骤从“进入容器”开始;容器已停止或暂停、引擎没有应答时说明这几种可能,找不到引擎命令行时说明需要安装哪个引擎,引擎输出只显示在步骤下方,不显示 SSH 的排查提示,也没有“编辑连接”;Core 拒绝的用户或容器名就地说明。连接后与 SSH 相同:选择文件夹、信任询问(信任记录包含容器)、工作区、心跳与重连;窗口标题为“文件夹 [容器: 容器名]”,状态栏为“容器: 容器名”,列表和概览按引擎和容器名显示已打开的窗口数。按容器名连接,所以同名重建的容器仍能接上;容器不写入已保存的连接,打开过的文件夹不记入最近文件夹。日志只有 remote.container.select、remote.connect 等动作,不含容器名、镜像、状态或用户名。测试替换的内核不运行本机的 docker 或 podman。运行 remote_container_test.go 的 4 个测试、internal/core 的 TestRemoteConnectSendsAContainerAloneAndCoreRefusesItByField 与 TestRemoteListContainersNamesTheSessionAndTheEngine,以及 TestVisualRemoteConnections 的容器截图;真实 Docker、Podman 与 Windows 上的整机验收仍待完成。“远程开发”窗口列表工具栏和空白页的“从 devcontainer.json 打开…”打开“在 Dev Container 中打开”页(窗口标题为“远程开发 › 在 Dev Container 中打开”):说明用官方 Dev Container CLI 按本机文件夹的 devcontainer.json 构建并启动容器、构建会运行文件夹的 Dockerfile、features 和命令所以文件夹必须受信任、Lithe 不额外挂载目录也不额外加参数。“选择文件夹…”打开系统文件夹选择,也可输入路径后按回车;相对路径、不存在的路径就地说明。读取文件夹时经 Core 的 remote.devcontainerConfigs 按规范顺序列出 .devcontainer/devcontainer.json、.devcontainer.json 和 .devcontainer 下一层文件夹里的配置,配置有 name 时显示“名称(路径)”,默认选第一个;没有配置时说明并且不能构建。容器引擎可选 Docker 或 Podman。同时读取文件夹的信任:未受信任时说明并把按钮换成“信任并构建”,先以与打开受信任项目相同的方式写入本机信任记录(记一次 workspace.trust.grant),再构建;读取信任失败时说明原因、不能构建。“构建并打开”经 remote.devcontainerUp 运行 CLI(带 projectCodeAllowed),CLI 的输出逐行显示在“构建日志”里(Core 已隐藏敏感信息,最多保留最近 5000 行,Core 截断时在下方说明),只显示、不写入 Lithe 的日志;构建期间左侧列表、配置、引擎和文件夹都不能改,底部显示“正在构建 dev container…”和“停止”。“停止”取消这次构建,日志保留并说明已经启动的容器会继续运行,不记失败;“取消”和关闭窗口也会先停止构建。找不到 devcontainer CLI 时说明用 npm 安装,CLI 报告失败时显示它的输出,超过一小时、结果里没有容器或工作区文件夹、文件夹不受信任分别说明,各记一次 remote_devcontainer_up 失败。成功后选中 CLI 返回的容器(重新读取容器列表,显示镜像),以 CLI 返回的 remoteUser 为容器内用户,按容器连接并直接打开 CLI 返回的工作区文件夹(与容器入口相同的信任询问、工作区、心跳与重连)。日志只有 remote.devcontainer.open/choose/build/stop、remote.connect 等动作,不含文件夹、配置名、容器名、用户名或 CLI 输出。测试替换的内核不运行本机的 devcontainer、docker 或 podman。运行 remote_devcontainer_test.go 的 5 个测试、internal/core 的 TestRemoteDevcontainer*,以及 TestVisualRemoteConnections 的 devcontainer 截图;装有 Dev Container CLI 的真实 Docker、Podman 上的整机验收仍待完成。在 SSH 主机或 WSL 发行版的文件夹选择里,标题栏的“主机上的容器”在文件夹的位置列出那台主机上 Docker 和 Podman 正在运行的容器(经浏览会话的 remote.listContainers 依次读取两个引擎,在远端服务的环境里运行,所以列出的容器就是能进入的;主机没有引擎命令行时说明没有找到 Docker 或 Podman,引擎报错时显示它的输出、不写日志),每行显示容器名、“引擎 · 镜像”和状态,可填写容器内用户(留空为镜像默认用户)。“进入容器”或双击一行结束浏览会话,重新连接主机并经主机上的引擎 exec 进入容器(OpenSSH 会再次询问它要问的内容;步骤与主机相同,地址显示为“主机 › 引擎:[用户@]容器”),随后在容器里选择文件夹;“返回文件夹”回到主机的文件夹。主机连不上或容器已停止、暂停、引擎没有应答时用同一段文字说明并点名引擎,具体原因在诊断输出里;没有“编辑连接”,“重试”进入同一台主机上的同一个容器。工作区身份为“已保存连接或发行版的身份/引擎:[用户@]容器”,窗口名为“容器名(主机名)”,不写入已保存的连接,打开过的文件夹不记入最近文件夹;信任记录包含主机与容器。Core 同样只进正在运行的容器,不提权、不改容器、不挂载(S32)。主机上不支持从 devcontainer.json 构建(devcontainer up 只在本机运行)。日志只有 remote.browse.containers/folders、remote.browse.container.enter、remote.connect 等动作和 remote_host_containers_list 失败名,不含主机、容器名、镜像、用户名或主机路径。运行 remote_host_containers_test.go 的 3 个测试和 TestVisualRemoteConnections 的主机容器截图;真实 SSH 主机与 Windows WSL 上的容器验收仍待完成。", + "verification": "在“远程开发”窗口选中已保存的 Linux SSH 连接点“连接”:SSH 询问出现在窗口中,连接后窗口改为主机的文件夹选择,从主目录开始列出子文件夹(跳过名称不是 UTF-8 的条目并说明数量),可输入 ~ 或 / 开头的路径跳转,不存在的路径说明原因且不能打开;“返回”断开这次会话回到连接表单。选中文件夹点“打开”:新标签页打开远程工作区,窗口标题为“文件夹 [SSH: 连接名]”,项目树经 Core 列出主机目录(本机占位目录始终为空),右键只有复制主机路径和刷新;以安全模式打开的文件夹,编辑器上方说明可以浏览、编辑、保存和搜索主机文件,信任文件夹后才能用 Git;受信任的文件夹说明文件、终端和 Git 都在主机上,运行、调试和语言服务器暂不可用;空白编辑区提示 Search Everywhere 和 Find in Files。在项目树双击文件:编辑器经会话读取主机文件(不超过 16 MiB),保存时带上打开时的大小和修改时间写回主机,新建的文件只在主机上不存在时创建;主机上的文件期间被别人改过时保存被拒绝并显示外部修改冲突,“加载磁盘版本”载入主机内容,本机占位目录始终为空。超过 8 MiB 的保存说明主机单次保存上限,编辑内容保留;主机上缺失、无权限、不是普通文件、超时和连接断开分别说明原因,连接断开后自动重连并把打开的文档和主机重新比对。图片、PDF 等查看器、本地历史和插件终端都被拒绝并提示,不回退到本机;在文件浏览器中显示(标签页右键、Search Everywhere 结果、Git 变更)在远程工作区里不提供。状态栏连接菜单的“打开主机上的文件…”(未连接时不可用)从窗口顶部弹出路径框,默认 ~/,经 remote.readDir 列出路径最后一个“/”之前的文件夹,按其后的文字(不分大小写)筛选名称开头,文件夹在前,以“.”开头时才列出隐藏条目,无法读取的条目说明数量;上下键移动、Tab 补全名称、回车进入文件夹或打开文件,没有匹配时回车按输入的路径打开,Esc 或点外面关闭;不以 / 或 ~/ 开头的输入说明要输入什么,名称含“\\”的路径说明在 Windows 上无法打开。工作区文件夹里的文件与项目树打开的相同、可以编辑;文件夹以外的文件(对标 Zed)在占位目录旁的 .lithe-remote-host 下以只读方式打开(S25):不能切换为可编辑(提示原因并记为拒绝),保存和新建都被拒绝并说明原因、不写主机,状态栏导航路径显示 ~ 开头的主机路径,复制相对路径不提供;重连和关闭前与其他文档一样和主机比对,主机上的改动在没有编辑时重新载入(主机监听只覆盖工作区文件夹)。日志只记 remote_open_host_file、remote_read_dir、toggle_read_only 等操作名和原因,不含主机路径。打开“终端”工具窗口:经会话的 remote.runTerminal 在主机文件夹运行主机账户的登录 shell(不带参数,不读本机 Shell 设置,没有本机 Shell 菜单),标签名为连接名,之后的标签为“连接名 (2)”等;输入按顺序、每块不超过 32 KiB 写入,主机说忙时稍后重试,窗口尺寸随输入发送;输出超过 8 MiB 未显示时丢弃最旧的部分并记一次失败。程序退出显示退出码,被信号结束显示 128+信号,关闭标签不算失败。连接断开时终端显示会话已结束,工作区按退避重连;未连接时按回车说明工作区未连接,重连后按回车在新会话上运行。终端起不来时显示 Core 给出的原因(可能含主机路径),日志只记命令名和错误码。拖到终端的文件粘贴为主机路径并按 POSIX shell 加引号,本机工作区外的文件不粘贴并提示原因;粘贴图片不可用(图片会存到本机)。每个会话连接后,经 remote.runWatch 在主机上递归监听整个文件夹,跳过已启用插件隐藏的文件夹名(按原样比较大小写),插件改变隐藏名称时重新开始监听;在主机上新建、修改、删除文件后,项目树重新列出受影响的目录(Core 的 workspace.filterChanges 按可见性规则过滤,不需要会话),打开的文档与主机比对:没有编辑的重新载入,有编辑的显示外部修改冲突;文件夹外和被隐藏文件夹里的变化不触发列表。监听开始时、主机丢失变化(overflow)时、一次超过 4096 个变化时,重新列出树中展开的目录并比对所有文档,日志每次监听各记一次;主机监听数用尽时其余部分继续监听,提示一次“项目文件可能无法自动更新”。监听中文件夹被删除或移走时立即重新监听;主机找不到文件夹时项目树显示根目录不可用,监听等树重新列出文件夹后再开始,主机与树结论不一致时也只等待、不反复重试。其他监听失败只记命令名和错误码、提示一次,等下一个会话再开始;监听发现连接断开时与心跳一样结束会话并重连。Find in Files 的搜索、计数和替换预览带远程绑定发送,Core 从主机文件夹建立索引并读取主机上的当前内容,结果路径相对主机文件夹;点结果在远程编辑器打开主机文件并定位到匹配处,本机占位目录始终为空。主机监听报告的变化路径在下一次查询前增量更新索引,不重建;监听开始和主机丢失变化时重建一次。包含生成文件的查询每次都重建索引(主机监听跳过插件隐藏的文件夹);主机监听数用尽后、会话断开到下一个会话的监听开始之间,每次查询都重建,只由监听提示一次“项目文件可能无法自动更新”,搜索不再另外提示。查询显示期间主机上的变化让结果重新查询。Search Everywhere 所有页签都可用,文件名和文本来自主机,打开弹窗时重新读取生成文件的名称;远程工作区不启动语言服务器,符号只有 Core 在主机文件中找到的。Replace All 在编辑器中替换打开的文档;未打开的文件经会话读取主机内容,由 Core 替换后,只在主机文件仍是读取时的内容时写回,期间被改过的报告冲突,已被删除的说明主机上找不到文件,其余文件照常替换,都不写本机占位目录。在文件夹选择中打开从未决定过的文件夹:先询问是否信任(显示连接名和主机文件夹,Core 给出上级文件夹时可勾选信任其下的所有文件夹),“信任并打开”把决定按连接名记入 Core 的远程信任记录后以受信任方式打开,“以安全模式打开”只读打开,“返回”回到文件夹选择;之前决定过的文件夹直接按记录打开。安全模式下 Git、提交和日志窗口与本机项目一样说明需要信任,编辑器上方的提示里可以信任文件夹,信任后不重开窗口就在主机上启动 Git。受信任的工作区经会话在主机上运行 Git:状态、暂存、提交、差异(含编辑器行号旁的变更标记)、日志与分支、逐行追溯(读取主机上的文件内容)、搁置与储藏都读写主机仓库,本机占位目录始终没有 .git;“排除到本地”写入主机仓库的 info/exclude(缺少 info 文件夹时在主机上创建,读写期间文件被别人改过时这次排除失败、不覆盖)。同一会话经 remote.runWatch 递归监听主机仓库的 git 目录(公共目录在别处时一并监听),主机上 git checkout、commit 等改动元数据后按路径分类并重新读取状态;监听开始、丢失变化或主机监听数用尽时重新读取一次完整状态,新会话重新开始监听。主机文件夹位于上级目录开始的仓库内时,Git 和提交窗口说明要打开仓库顶层文件夹,不显示变更也不记为失败。工作树列表、锁定、解锁、删除在主机上执行,列表和详情显示主机路径,复制路径复制主机路径。打开关联工作树时“远程开发”窗口打开,用打开工作区所用的连接(或 WSL 发行版)再连一次,显示连接步骤和 OpenSSH 的询问,从未决定过的文件夹先询问是否信任,然后在本窗口的新标签页经一个新会话打开该主机文件夹;再次打开时切到已打开的标签页,不再连接;连接在工作区打开后被删除时窗口说明原因、不连接。新建工作树对话框把 Core 在仓库旁的建议显示为主机路径(如 /home/dev/project-topic),输入框下说明路径是主机上的文件夹、由主机上的 Git 创建;输入的其他主机路径原样保留,“创建”在工作区会话上由主机上的 Git 创建并选中新工作树,“创建后打开”同样经新会话在新标签页打开。在新窗口打开和在文件浏览器中显示仍被拒绝并提示。受信任的远程工作区里运行、调试、当前文件运行、测试、构建任务和插件语言服务器都不在本机启动,都记为拒绝并提示,运行、测试和构建工具窗口说明暂不可用。状态栏前端显示连接名和心跳往返时间;连续两次心跳无响应显示“无响应”,第三次结束会话并按 Core 由“自动重连时长”给出的间隔重连(默认 1、2、4、8、16、29 秒,共 60 秒),每次失败后等下一个间隔,用完后显示“已断开”和原因,菜单里可“重新连接”;连接被关闭时同样按这些间隔重连;时长设为“不自动重连”时直接显示“已断开”。关闭窗口、退出 Lithe、菜单里“断开并关闭”和切换工作区时,先经 remote.runningPrograms 读取主机上 Lithe 为这个工作区启动的进程和终端;没有时直接结束会话,有时询问“关闭远程工作区?”,正文写明连接名并逐项列出类型(终端、进程)、名称、命令(原样显示,不脱敏)和已运行时长,按钮为“结束并关闭”(默认)、“保留在远端并关闭”和“取消”,“记住我的选择”旁的 ⓘ 说明之后不再询问、只能在 设置 › 工具 › 远程工作区 修改。“取消”保留窗口和会话;“结束并关闭”经 remote.disconnect 结束主机会话;“保留在远端并关闭”让主机保留会话,把恢复凭据按连接存入系统密钥存储后通知“N 个进程保留在 <连接名> 上”,凭据存不下时改为结束并说明原因,主机拒绝保留时同样结束并说明;读取进程列表失败时不询问、照常结束。勾选“记住我的选择”把结束或保留写入 Core 的远程工作区设置,之后直接按设置执行。下次经同一连接、同一 WSL 发行版或同一容器连接时带上最新的保留凭据接回会话,打开文件夹后列出上次保留、仍在运行的进程,可“结束这些进程”(经 remote.endPrograms 只结束它们,不动这次新开的)或“继续运行”;主机上已没有该会话时开新会话并忘掉凭据;接回后没打开工作区就停止的连接再次保留该会话,进程不会未经用户选择就结束。退出 Lithe 时每个远程工作区窗口同样询问,取消的窗口保持打开。最近项目不记录远程工作区。日志只有 remote.connect、remote.workspace.open/reconnect/disconnect、remote.close.cancel/keep/end、remote.kept.end/keep 等动作和失败的操作名,不含主机、用户名、主机路径、主目录、进程名称或命令。运行 remote_close_test.go 的 7 个测试、remoteconn 的 kept_test.go 3 个测试、TestVisualRemoteClose 无头截图(询问、保留后的通知、下次连接列出保留的进程)、remote_workspace_test.go 的 5 个测试、remote_git_test.go 的 6 个测试、remoteplaceholder 的 TestHostAndLocalPathsMapBothWays 与 TestHostNamedPathNamesEveryHostPathBelowTheSibling、remote_worktree_test.go 的 3 个测试、remote_documents_test.go 的 2 个测试、remote_terminal_test.go 的 9 个测试、remote_watch_test.go 的 5 个测试、remote_search_test.go 的 4 个测试、remote_host_files_test.go 的 TestRemoteOpenFileOnHost、internal/core 的 TestRemoteTerminal*、TestRemoteWatch* 与 TestRemoteWorkspaceFiltersChangesWithoutTheHost、termview 的 TestOpenStartsTheProgramElsewhere,以及 TestVisualRemoteWorkspace 与 TestVisualRemoteWorktrees 无头截图;在 Windows 运行 TestCoreRefusesUnadaptedCommandsAndAClosedSessionDetachesTheBinding,验证 Linux 主机路径能通过绑定校验。真实 SSH 主机上的整机验收(包括终端里 vim、top 等全屏程序与窗口缩放,主机上 git checkout 等大批量修改后的监听,以及大仓库上的搜索)仍待完成。远程工作区左侧多出“端口”工具窗口(本机工作区没有,关闭工作区后消失):窗口打开时每 3 秒经 ports.listening 读取主机上正在监听的端口和会话的转发,窗口关闭或未显示时停止读取;同一端口在 0.0.0.0 与 :: 上监听只显示一行;远端端口带上主机监听的 IP 地址,多个地址时显示第一个和其余数量,悬停提示列出全部,地址或网址过长被截断时悬停提示给出全文;列出远端端口、本机地址、进程(名称与 PID,读不到时为“未知”)、来源(监听发现、手动添加)和状态。默认不自动转发任何端口,打开窗口和发现新端口都不转发;行尾“转发”把端口转发到主机上对应族的回环地址,本机在 127.0.0.1 的同号端口监听,该端口被本机其他程序占用时改用空闲端口,本机地址用警告色显示并在提示里说明原端口。右键“转发到指定本机端口…”和已转发行的“更改本机端口…”打开对话框输入 1–65535 的本机端口,非法输入就地说明且不转发;改到另一个端口时先停止原转发再在新端口转发,选择在工作区打开期间保留,停止后再转发仍用该端口。顶部输入端口、主机:端口或网址(http、https、ws、wss,省略端口时按协议默认端口)可手动添加并转发,由 Core 的 remote.parseForwardAddress 解析;格式不对就地说明,网址里带用户名或密码时拒绝并说明,输入框保留原文、日志不记输入内容;同一目标再次添加不重复。网址行按输入的样子显示,转发到主机上提供该端口的回环地址;在浏览器打开和复制本机地址把主机部分换成本机地址并保留路径和查询,ws/wss 网址不提供在浏览器打开;浏览器打不开时提示网址,日志只记失败、不记网址。主机回环地址以外的目标先询问(S28),确认后才带 AllowNonLoopback 转发,取消记为拒绝。已转发行可在浏览器打开、复制本机地址、停止;手动添加且已停止、主机上也没有在监听的行可移除;窗口标题栏可全部停止,标题栏的 ⓘ 说明转发对本机其他程序可见(S30);会话转发数达到 Core 上限时说明上限;状态栏显示已转发数量,点击打开端口窗口;会话结束时转发随之结束,重连后不自动恢复。日志只记 remote.ports.forward/localPort/move/stop/status 等动作和失败操作名,不含主机、地址或进程名。运行 remote_ports_test.go 的 12 个测试、internal/core 的 TestRemoteSessionCommandsOfAnUnknownSession 与 TestRemoteParseForwardAddressReadsPortsAndURLs,以及 TestVisualRemotePorts 无头截图。手动添加的端口和本机端口选择只在工作区打开期间保留,关闭后不保存(需 Core 存储,后续阶段)。端口窗口标题栏的“+”打开“添加转发规则”:方向默认“主机端口 → 另一台服务器”,由主机自己连接目标,数据不经过本机;主机端口可留空由主机选择,目标接受端口、主机:端口或网址(由 Core 的 remote.parseForwardAddress 解析,网址里带用户名或密码时拒绝)。规则默认只在主机的回环地址 127.0.0.1 上监听;勾选“监听主机的全部网卡”时显示警告,每次添加都再次询问、不记住,列表里的监听地址用警告色显示并在悬停提示里说明;目标不是主机自身的回环地址时先询问(S28)。“主机端口 → 本机(反向转发)”只在 设置 › 工具 › 远程工作区 的“反向转发”允许时提供(默认自动,即不允许,对话框说明在哪里开启),每条都询问,主机只在回环地址监听,本机只连接回环地址上的端口。主机端口被占用、主机不允许监听(如 1024 以下)、远端服务不支持、达到会话转发上限(与本机转发合计)、反向转发未被允许分别说明原因,主机端口不是 1–65535 时就地说明,对话框保留输入。端口窗口的“转发规则”一节列出主机监听地址、转到的目标(反向转发为“本机 地址”)、连接数(有失败时注明失败数)和状态,每行可停止,标题栏的全部停止同样停止规则;规则随会话结束而停止,重连后不自动恢复,关闭工作区后也不保存。日志只记 remote.ports.addRule/ruleHost/ruleReverse/ruleConfirm/stopRule 等动作和失败的操作名,不含地址、网址或进程名。运行 remote_port_rules_test.go 的 5 个测试、settingswindow 的 TestRemoteWorkspaceReverseForwardingIsAppliedAndRestored,以及 TestVisualRemotePorts 的转发规则列表、添加对话框和全部网卡询问截图。远程 Git 的 AskPass 转交(推送、拉取时的凭据询问)、从上级目录开始的仓库尚未支持。Windows 上“远程开发”窗口在已保存的连接之后以“WSL”标题列出本机安装的 WSL 发行版(Core 的 remote.listWslDistributions,每次打开窗口读取一次;搜索时不列出,标题可折叠;macOS 和没有 WSL 的 Windows 不显示这一组)。选中发行版后右侧说明经本机 wsl.exe 打开、不保存任何信息,可填写 Linux 用户(留空为发行版默认用户),地址显示为 wsl:[用户@]发行版。“连接”经 remote.connect 的 wsl 参数启动,不经 OpenSSH、没有询问,步骤从“启动发行版”开始,不显示读取配置和身份验证;发行版没有安装或没能启动、本机找不到 wsl.exe 时分别说明,不显示 SSH 的排查提示,也没有“编辑连接”;Core 拒绝的用户名或发行版名就地说明。连接后与 SSH 相同:选择文件夹、信任询问、工作区、心跳与重连;窗口标题为“文件夹 [WSL: 发行版]”,状态栏为“WSL: 发行版”(SSH 工作区的“SSH”也由同一参数给出),列表和概览显示已打开该发行版的窗口数。发行版不写入已保存的连接,打开过的文件夹不记入最近文件夹。日志只有 remote.wsl.select、remote.connect 等动作,不含发行版名、用户名或主机路径。运行 remote_wsl_test.go 的 3 个测试、internal/core 的 TestRemoteConnectSendsWSLAloneAndCoreRefusesItByField 与 TestRemoteListWSLDistributionsIsUnavailableOutsideWindows,以及 TestVisualRemoteConnections 的 WSL 截图;真实 Windows 上的 WSL 验收(wsl.exe 的错误输出、--exec 的二进制透传、结束 wsl.exe 后 Linux 进程是否退出、未知用户)仍待完成。打开“设置 › 工具 › 远程工作区”:页面只读取、不创建任何文件。“SSH 程序”默认“自动(Core 在 PATH 上找到的 ssh 路径)”,找不到时为“自动(未找到 ssh)”;“选择…”选一个文件作为草稿,下拉菜单可回到自动;保存的程序缺失或不可执行时在行下说明。“SSH 配置文件”只显示 Core 读取的 ~/.ssh/config 路径,不存在时注明。“自动重连时长”可选“自动(1 分钟)”、不自动重连、15 秒到 1 小时,保存过的其他值也列出。“反向转发”默认“自动(不允许)”,可选允许或不允许,ⓘ 说明主机上的所有用户都能连接反向转发的端口、每条规则仍会确认。“关闭工作区”卡片里“关闭时的远端进程”可选“每次询问”(默认)、“结束”和“保留在远端”,关闭对话框勾选“记住我的选择”后只能在这里改回;“常驻会话的空闲超时”只读显示 Core 报告的远端服务超时(10 分钟),ⓘ 说明断线且没人保留的会话多久后由主机结束。“保存位置”显示偏好目录下的 remote/preferences.json,还没有文件时注明修改后才创建。修改只是草稿:侧栏和底部显示未应用数量,“应用”或“好”经 Core 的 remote.editPreferences 写入(程序先于时长),写入后重新读取显示;Core 拒绝相对路径、不存在、不可执行的程序或超出 0–3600 秒的时长时在页面说明原因并保留草稿,不写文件;文件期间被改过时重新读取并请用户再次应用;文件损坏时说明路径、不提供编辑,此时连接、测试连接、读取有效设置和导入 SSH 主机都失败并说明原因,不用未经用户选择的程序启动 OpenSSH。选中的 SSH 程序用于连接、测试连接、有效设置和 SSH 配置导入(WSL 经 wsl.exe 启动,不使用它)。日志只记 remote_preferences_settings_load/save 等操作名和 Core 错误码,不记路径。运行 settingswindow 的 TestRemoteWorkspace* 6 个测试、remoteconn 的 preferences_test.go、internal/core 的 TestRemotePreferences*,以及 TestVisualRemoteWorkspace 无头截图(中英文、深浅色,自动值、草稿和关闭时保留远端进程三种状态)。真实 SSH 主机上关闭后保留、重连接回和结束保留进程的整机验收,以及保留进程的输出重新接回终端和运行窗口(后续阶段),仍待完成。“远程开发”窗口在 WSL 发行版之后以“容器”标题列出本机 Docker 和 Podman 正在运行的容器(Core 的 remote.listContainers,每次打开窗口读取一次,两个引擎在同一个后台任务里依次读取,一个超时或报错时跳过它并记一次 remote_containers_list 失败,另一个照常列出;搜索时不列出,标题可折叠;两个引擎都没有时不显示这一组)。每行显示容器名和“引擎 · 镜像”,已有窗口打开它时显示绿点。选中容器后右侧显示引擎标签、地址 引擎:[用户@]容器、镜像与引擎给出的状态,说明经本机引擎进入正在运行的容器、不启动不创建不改动容器、不挂载目录、不保存任何信息,可填写容器内用户(用户名、uid 或 用户:组,留空为镜像默认用户)。“连接”经 remote.connect 的 container 参数进入,不经 OpenSSH、没有询问、不发送 SSH 偏好,步骤从“进入容器”开始;容器已停止或暂停、引擎没有应答时说明这几种可能,找不到引擎命令行时说明需要安装哪个引擎,引擎输出只显示在步骤下方,不显示 SSH 的排查提示,也没有“编辑连接”;Core 拒绝的用户或容器名就地说明。连接后与 SSH 相同:选择文件夹、信任询问(信任记录包含容器)、工作区、心跳与重连;窗口标题为“文件夹 [容器: 容器名]”,状态栏为“容器: 容器名”,列表和概览按引擎和容器名显示已打开的窗口数。按容器名连接,所以同名重建的容器仍能接上;容器不写入已保存的连接,打开过的文件夹不记入最近文件夹。日志只有 remote.container.select、remote.connect 等动作,不含容器名、镜像、状态或用户名。测试替换的内核不运行本机的 docker 或 podman。运行 remote_container_test.go 的 4 个测试、internal/core 的 TestRemoteConnectSendsAContainerAloneAndCoreRefusesItByField 与 TestRemoteListContainersNamesTheSessionAndTheEngine,以及 TestVisualRemoteConnections 的容器截图;真实 Docker、Podman 与 Windows 上的整机验收仍待完成。“远程开发”窗口列表工具栏和空白页的“从 devcontainer.json 打开…”打开“在 Dev Container 中打开”页(窗口标题为“远程开发 › 在 Dev Container 中打开”):说明用官方 Dev Container CLI 按本机文件夹的 devcontainer.json 构建并启动容器、构建会运行文件夹的 Dockerfile、features 和命令所以文件夹必须受信任、Lithe 不额外挂载目录也不额外加参数。“选择文件夹…”打开系统文件夹选择,也可输入路径后按回车;相对路径、不存在的路径就地说明。读取文件夹时经 Core 的 remote.devcontainerConfigs 按规范顺序列出 .devcontainer/devcontainer.json、.devcontainer.json 和 .devcontainer 下一层文件夹里的配置,配置有 name 时显示“名称(路径)”,默认选第一个;没有配置时说明并且不能构建。容器引擎可选 Docker 或 Podman。同时读取文件夹的信任:未受信任时说明并把按钮换成“信任并构建”,先以与打开受信任项目相同的方式写入本机信任记录(记一次 workspace.trust.grant),再构建;读取信任失败时说明原因、不能构建。“构建并打开”经 remote.devcontainerUp 运行 CLI(带 projectCodeAllowed),CLI 的输出逐行显示在“构建日志”里(Core 已隐藏敏感信息,最多保留最近 5000 行,Core 截断时在下方说明),只显示、不写入 Lithe 的日志;构建期间左侧列表、配置、引擎和文件夹都不能改,底部显示“正在构建 dev container…”和“停止”。“停止”取消这次构建,日志保留并说明已经启动的容器会继续运行,不记失败;“取消”和关闭窗口也会先停止构建。找不到 devcontainer CLI 时说明用 npm 安装,CLI 报告失败时显示它的输出,超过一小时、结果里没有容器或工作区文件夹、文件夹不受信任分别说明,各记一次 remote_devcontainer_up 失败。成功后选中 CLI 返回的容器(重新读取容器列表,显示镜像),以 CLI 返回的 remoteUser 为容器内用户,按容器连接并直接打开 CLI 返回的工作区文件夹(与容器入口相同的信任询问、工作区、心跳与重连)。日志只有 remote.devcontainer.open/choose/build/stop、remote.connect 等动作,不含文件夹、配置名、容器名、用户名或 CLI 输出。测试替换的内核不运行本机的 devcontainer、docker 或 podman。运行 remote_devcontainer_test.go 的 5 个测试、internal/core 的 TestRemoteDevcontainer*,以及 TestVisualRemoteConnections 的 devcontainer 截图;装有 Dev Container CLI 的真实 Docker、Podman 上的整机验收仍待完成。在 SSH 主机或 WSL 发行版的文件夹选择里,标题栏的“主机上的容器”在文件夹的位置列出那台主机上 Docker 和 Podman 正在运行的容器(经浏览会话的 remote.listContainers 依次读取两个引擎,在远端服务的环境里运行,所以列出的容器就是能进入的;主机没有引擎命令行时说明没有找到 Docker 或 Podman,引擎报错时显示它的输出、不写日志),每行显示容器名、“引擎 · 镜像”和状态,可填写容器内用户(留空为镜像默认用户)。“进入容器”或双击一行结束浏览会话,重新连接主机并经主机上的引擎 exec 进入容器(OpenSSH 会再次询问它要问的内容;步骤与主机相同,地址显示为“主机 › 引擎:[用户@]容器”),随后在容器里选择文件夹;“返回文件夹”回到主机的文件夹。主机连不上或容器已停止、暂停、引擎没有应答时用同一段文字说明并点名引擎,具体原因在诊断输出里;没有“编辑连接”,“重试”进入同一台主机上的同一个容器。工作区身份为“已保存连接或发行版的身份/引擎:[用户@]容器”,窗口名为“容器名(主机名)”,不写入已保存的连接,打开过的文件夹不记入最近文件夹;信任记录包含主机与容器。Core 同样只进正在运行的容器,不提权、不改容器、不挂载(S32)。主机上不支持从 devcontainer.json 构建(devcontainer up 只在本机运行)。日志只有 remote.browse.containers/folders、remote.browse.container.enter、remote.connect 等动作和 remote_host_containers_list 失败名,不含主机、容器名、镜像、用户名或主机路径。运行 remote_host_containers_test.go 的 3 个测试和 TestVisualRemoteConnections 的主机容器截图;真实 SSH 主机与 Windows WSL 上的容器验收仍待完成。在远程工作区的标题栏选中程序或脚本运行配置点“运行”:程序在主机上启动(工作目录为主机文件夹下的相对目录,环境为主机登录环境加配置的变量),输出进入运行窗口,标签页带“主机”徽标;脚本写到主机临时目录,运行结束后删除;“停止”先发 SIGTERM,超过停止等待时间再强制结束;输出里的主机路径可点击并经占位路径在编辑器打开。配置的“执行前”列表里引用的其他程序或脚本运行配置按顺序在主机上先运行,步骤标题和输出写在同一个控制台,全部以 0 退出后才启动配置本身;某一步以非零退出码结束时说明步骤名和退出码,配置不启动;运行步骤时“停止”先给步骤的主机进程发 SIGTERM。列表里有插件提供的任务时说明远程工作区暂不支持插件任务,请从“执行前”列表删除后再运行。构建工具、插件提供的运行和调试在远程工作区说明暂不支持。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -169,5 +179,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva:连接和会话由 Core 的 remote.connect/remote.disconnect/remote.closeAll 管理,远端服务按嵌入清单上传;文件夹选择用 remote.readDir。打开的工作区以用户缓存目录下的空占位目录作为本机根,每个请求带上远程绑定(会话、占位根、主机根),Core 只对有远程适配的命令放行,其余以 not_supported 拒绝,所以没有远程实现的功能在桌面端直接拒绝而不读本机占位目录。编辑器的读、写和比对改走 remote.stat、remote.readFile、remote.writeFile(带预期版本,主机按大小和修改时间拒绝过期写入);解码、恢复、语言识别等纯计算命令不带远程绑定发送。日志只记命令名和错误码,不记 Core 返回的消息(可能含主机路径)。macOS 由单元测试与无头截图覆盖;Core 按 POSIX 规则校验 Linux 主机路径,按客户端规则处理本机占位根(#2264)。终端经 remote.runTerminal 运行,输入与尺寸经 remote.hostRequest 的 terminal.write/terminal.resize 发送;关闭标签取消这次请求,Core 随即向主机发 terminal.close;一个连接断开的终端让工作区按同一会话丢失处理(与心跳一致),其他失败只结束该终端。文件夹监听经 remote.runWatch 在请求的 goroutine 上运行整个会话期间,不计入窗口的后台任务;事件在锁内合并后只投递一次到窗口线程,停止监听时作废已排队的变化。Find in Files、Search Everywhere 和 Replace All 的 workspace.search、searchIndex.update/invalidate、searchEverywhere、replacePreview 带远程绑定发送,searchPresentation、replaceText 等纯计算命令不带绑定;Core 以“会话身份 + 主机路径”为键缓存索引,主机监听的变化经 workspace.filterChanges 过滤后更新它。会话结束后 Core 不释放该会话的索引,每次重连或重新打开多留一份(#2277)。 远程信任:Core 的 remote.workspaceTrust 按“会话身份 + 主机文件夹”读出记录,remote.editWorkspaceTrust 写入决定(含连接名),桌面端只把 Core 给出的文档存到偏好目录;projectCodeAllowed 且状态为 trusted 才算受信任。受信任后 git.* 请求带远程绑定发送,Core 在主机上运行 Git,返回的路径是占位路径(remoteplaceholder.LocalPath 把主机路径换成占位路径,文件夹外的主机路径映射到占位目录旁的 .lithe-remote-host 下,不会落到本机真实路径)。git 目录的监听与文件夹监听同样跑在请求自己的 goroutine 上,会话丢失或失去信任时取消。 端口:remote.startForward/stopForward/forwards 与 ports.listening 都带会话发送;Core 只在本机 127.0.0.1 监听,请求的本机端口被占用时选空闲端口并返回 localPortChanged 与 requestedLocalPort;同一目标再次转发返回已有转发(created=false),所以更改本机端口是先停止再转发。顶部输入由 Core 的 remote.parseForwardAddress 解析为目标端口、主机、协议和路径,不连接主机;桌面端把网址的主机换成主机上提供该端口的回环地址再转发。非回环目标需 allowNonLoopback(S28),超过上限返回 forward_limit_reached 并带 maximum。读取在窗口的后台任务里进行,只在窗口打开且被绘制过时排下一次,不做空闲轮询。 转发规则:remote.startHostForward 让主机在回环地址(allInterfaces 时在全部网卡)监听并由主机连接目标,remote.startReverseForward 让主机只在回环地址监听、把每个连接带回本机回环地址上的端口;两者与 remote.startForward 共用会话转发上限,remote.forwards 用 kind 区分三种转发,端口窗口的端口列表只列本机转发。主机端口被占用、被拒绝、远端服务不支持和反向转发未允许分别是 forward_host_port_in_use、forward_host_port_denied、forward_host_unsupported、reverse_forward_disabled。remote.preferences 返回 reverseForwarding(来源与是否允许):打开对话框时据此决定是否提供反向方向,startReverseForward 也带上偏好文档由 Core 再校验一次。 WSL:remote.connect 的 connection 与 wsl 二选一,Core 经 wsl.exe --distribution … --exec 启动同一个远端服务,会话身份为 wsl:[用户@]发行版;桌面端的 remoteHost 在 SSH 连接与 WSL 发行版之间二选一,步骤、文件夹选择、信任、工作区和重连共用同一流程。remote.listWslDistributions 在 Windows 以外直接返回不可用,不运行任何程序。 远程工作区设置:Core 的 remote.preferences 读取偏好文档并解析 SSH 程序(found/missing/notExecutable)、~/.ssh/config 是否存在和重连间隔,remote.editPreferences 一次修改一个字段并返回新文档或 null(全部为自动时删除文件);桌面端只把文档按版本写到偏好目录的 remote/preferences.json(不超过 16 KiB),期间被改过时以冲突拒绝。每次连接、测试连接、读取有效设置和 SSH 配置导入都在后台重新读取文档并随请求发送;连接丢失时在后台读取重连间隔,读取失败时工作区保持断开并说明原因。页面的“自动(…)”另用不带文档的 remote.preferences 求出 Core 的默认值,所以保存了其他值时也能显示自动值。 关闭确认:连接都以常驻会话建立,Core 的 remote.connect 返回 sessionKey、sessionToken 和 resumed;关闭时 remote.runningPrograms 列出主机进程,remote.disconnect 带 programs=end/keep,keep 由 Core 发 server.keep,主机拒绝时返回错误、桌面端改为结束。保留的 sessionKey 与 sessionToken 按连接存入系统密钥存储(每个连接最多 8 条、整项不超过 2560 字节以适配 Windows 凭据管理器,最新的排最后),下次连接带上最新一条作为 resume;resumed=false 时忘掉这条。resumed 会话的 keptPrograms 在打开文件夹后列出,remote.endPrograms 按列出的 ID 只结束这些进程;空闲超时来自 Core 的 closing.idleTimeoutSeconds。记住的选择经 remote.editPreferences 的 closePrograms 写入同一份偏好文档。进程名称和命令只在对话框里显示,不写日志。 容器:remote.connect 的 container 单独出现时由 Core 在本机运行 exec -i [-u 用户] 容器 进入(S32:只进正在运行的容器,不提权、不改容器、不挂载),会话身份为 engine:[用户@]容器;container 跟在 connection 或 wsl 后面时 Core 在那台主机上、远端服务的非登录环境里运行同样的 exec,信任键包含主机与容器,remote.listContainers 带 sessionId 时也在那里列出。桌面端 remoteHost 由 SSH 连接或 WSL 发行版加可选的容器组成:overSSH() 决定是否发送 SSH 偏好、显示配置与认证步骤,saved() 决定是否提供编辑和记住文件夹,hosted() 区分主机上的容器(失败文字、重试目标)。列表键为 引擎:完整 ID,请求只发容器名。 devcontainer.json:Core 的 remote.devcontainerConfigs 只读文件夹并列出配置,remote.devcontainerUp 要求 projectCodeAllowed,在本机运行 devcontainer up(只传 --workspace-folder、选中的 --config,选 Podman 时加 --docker-path podman,不加挂载或其他参数),按流式事件返回已隐藏敏感信息的输出,结束时给出容器 ID、名称、remoteUser 和 remoteWorkspaceFolder;桌面端随后走与容器入口相同的 remote.connect 的 container 参数。未受信任的文件夹由桌面端先写本机信任记录再构建。 工作树:打开远程工作区的工作树等于用同一个连接打开另一个主机文件夹,每个文件夹一个会话、一个标签页,已有标签页的会话还活着时直接切换;新建对话框把仓库、目标和建议路径都用 remoteplaceholder.HostNamedPath 映射到占位根旁的 .lithe-remote-host 下发给 Core,Core 按仓库路径推出的建议也落在那里,显示前换回主机路径,所以不用改 Core 的建议和映射规则,Windows 与 WSL 上的主机路径也是本机绝对路径。" + "notes": "Viva:连接和会话由 Core 的 remote.connect/remote.disconnect/remote.closeAll 管理,远端服务按嵌入清单上传;文件夹选择用 remote.readDir。打开的工作区以用户缓存目录下的空占位目录作为本机根,每个请求带上远程绑定(会话、占位根、主机根),Core 只对有远程适配的命令放行,其余以 not_supported 拒绝,所以没有远程实现的功能在桌面端直接拒绝而不读本机占位目录。编辑器的读、写和比对改走 remote.stat、remote.readFile、remote.writeFile(带预期版本,主机按大小和修改时间拒绝过期写入);解码、恢复、语言识别等纯计算命令不带远程绑定发送。日志只记命令名和错误码,不记 Core 返回的消息(可能含主机路径)。macOS 由单元测试与无头截图覆盖;Core 按 POSIX 规则校验 Linux 主机路径,按客户端规则处理本机占位根(#2264)。终端经 remote.runTerminal 运行,输入与尺寸经 remote.hostRequest 的 terminal.write/terminal.resize 发送;关闭标签取消这次请求,Core 随即向主机发 terminal.close;一个连接断开的终端让工作区按同一会话丢失处理(与心跳一致),其他失败只结束该终端。文件夹监听经 remote.runWatch 在请求的 goroutine 上运行整个会话期间,不计入窗口的后台任务;事件在锁内合并后只投递一次到窗口线程,停止监听时作废已排队的变化。Find in Files、Search Everywhere 和 Replace All 的 workspace.search、searchIndex.update/invalidate、searchEverywhere、replacePreview 带远程绑定发送,searchPresentation、replaceText 等纯计算命令不带绑定;Core 以“会话身份 + 主机路径”为键缓存索引,主机监听的变化经 workspace.filterChanges 过滤后更新它。会话结束后 Core 不释放该会话的索引,每次重连或重新打开多留一份(#2277)。 远程信任:Core 的 remote.workspaceTrust 按“会话身份 + 主机文件夹”读出记录,remote.editWorkspaceTrust 写入决定(含连接名),桌面端只把 Core 给出的文档存到偏好目录;projectCodeAllowed 且状态为 trusted 才算受信任。受信任后 git.* 请求带远程绑定发送,Core 在主机上运行 Git,返回的路径是占位路径(remoteplaceholder.LocalPath 把主机路径换成占位路径,文件夹外的主机路径映射到占位目录旁的 .lithe-remote-host 下,不会落到本机真实路径)。git 目录的监听与文件夹监听同样跑在请求自己的 goroutine 上,会话丢失或失去信任时取消。 端口:remote.startForward/stopForward/forwards 与 ports.listening 都带会话发送;Core 只在本机 127.0.0.1 监听,请求的本机端口被占用时选空闲端口并返回 localPortChanged 与 requestedLocalPort;同一目标再次转发返回已有转发(created=false),所以更改本机端口是先停止再转发。顶部输入由 Core 的 remote.parseForwardAddress 解析为目标端口、主机、协议和路径,不连接主机;桌面端把网址的主机换成主机上提供该端口的回环地址再转发。非回环目标需 allowNonLoopback(S28),超过上限返回 forward_limit_reached 并带 maximum。读取在窗口的后台任务里进行,只在窗口打开且被绘制过时排下一次,不做空闲轮询。 转发规则:remote.startHostForward 让主机在回环地址(allInterfaces 时在全部网卡)监听并由主机连接目标,remote.startReverseForward 让主机只在回环地址监听、把每个连接带回本机回环地址上的端口;两者与 remote.startForward 共用会话转发上限,remote.forwards 用 kind 区分三种转发,端口窗口的端口列表只列本机转发。主机端口被占用、被拒绝、远端服务不支持和反向转发未允许分别是 forward_host_port_in_use、forward_host_port_denied、forward_host_unsupported、reverse_forward_disabled。remote.preferences 返回 reverseForwarding(来源与是否允许):打开对话框时据此决定是否提供反向方向,startReverseForward 也带上偏好文档由 Core 再校验一次。 WSL:remote.connect 的 connection 与 wsl 二选一,Core 经 wsl.exe --distribution … --exec 启动同一个远端服务,会话身份为 wsl:[用户@]发行版;桌面端的 remoteHost 在 SSH 连接与 WSL 发行版之间二选一,步骤、文件夹选择、信任、工作区和重连共用同一流程。remote.listWslDistributions 在 Windows 以外直接返回不可用,不运行任何程序。 远程工作区设置:Core 的 remote.preferences 读取偏好文档并解析 SSH 程序(found/missing/notExecutable)、~/.ssh/config 是否存在和重连间隔,remote.editPreferences 一次修改一个字段并返回新文档或 null(全部为自动时删除文件);桌面端只把文档按版本写到偏好目录的 remote/preferences.json(不超过 16 KiB),期间被改过时以冲突拒绝。每次连接、测试连接、读取有效设置和 SSH 配置导入都在后台重新读取文档并随请求发送;连接丢失时在后台读取重连间隔,读取失败时工作区保持断开并说明原因。页面的“自动(…)”另用不带文档的 remote.preferences 求出 Core 的默认值,所以保存了其他值时也能显示自动值。 关闭确认:连接都以常驻会话建立,Core 的 remote.connect 返回 sessionKey、sessionToken 和 resumed;关闭时 remote.runningPrograms 列出主机进程,remote.disconnect 带 programs=end/keep,keep 由 Core 发 server.keep,主机拒绝时返回错误、桌面端改为结束。保留的 sessionKey 与 sessionToken 按连接存入系统密钥存储(每个连接最多 8 条、整项不超过 2560 字节以适配 Windows 凭据管理器,最新的排最后),下次连接带上最新一条作为 resume;resumed=false 时忘掉这条。resumed 会话的 keptPrograms 在打开文件夹后列出,remote.endPrograms 按列出的 ID 只结束这些进程;空闲超时来自 Core 的 closing.idleTimeoutSeconds。记住的选择经 remote.editPreferences 的 closePrograms 写入同一份偏好文档。进程名称和命令只在对话框里显示,不写日志。 容器:remote.connect 的 container 单独出现时由 Core 在本机运行 exec -i [-u 用户] 容器 进入(S32:只进正在运行的容器,不提权、不改容器、不挂载),会话身份为 engine:[用户@]容器;container 跟在 connection 或 wsl 后面时 Core 在那台主机上、远端服务的非登录环境里运行同样的 exec,信任键包含主机与容器,remote.listContainers 带 sessionId 时也在那里列出。桌面端 remoteHost 由 SSH 连接或 WSL 发行版加可选的容器组成:overSSH() 决定是否发送 SSH 偏好、显示配置与认证步骤,saved() 决定是否提供编辑和记住文件夹,hosted() 区分主机上的容器(失败文字、重试目标)。列表键为 引擎:完整 ID,请求只发容器名。 devcontainer.json:Core 的 remote.devcontainerConfigs 只读文件夹并列出配置,remote.devcontainerUp 要求 projectCodeAllowed,在本机运行 devcontainer up(只传 --workspace-folder、选中的 --config,选 Podman 时加 --docker-path podman,不加挂载或其他参数),按流式事件返回已隐藏敏感信息的输出,结束时给出容器 ID、名称、remoteUser 和 remoteWorkspaceFolder;桌面端随后走与容器入口相同的 remote.connect 的 container 参数。未受信任的文件夹由桌面端先写本机信任记录再构建。 工作树:打开远程工作区的工作树等于用同一个连接打开另一个主机文件夹,每个文件夹一个会话、一个标签页,已有标签页的会话还活着时直接切换;新建对话框把仓库、目标和建议路径都用 remoteplaceholder.HostNamedPath 映射到占位根旁的 .lithe-remote-host 下发给 Core,Core 按仓库路径推出的建议也落在那里,显示前换回主机路径,所以不用改 Core 的建议和映射规则,Windows 与 WSL 上的主机路径也是本机绝对路径。 运行配置在远程工作区由 Core 路由到主机(runConfig.*,计划按主机平台生成),桌面端用 remote.runProcess 启动内置的程序和脚本运行,输出经有界缓冲(8 MiB,超出丢弃最旧部分并提示)进入运行窗口;进程 id 不是本机的,不采样端口和资源。“执行前”列表里的内置运行配置步骤同样经 remote.runProcess 在主机上运行(各自的临时目录在下一步开始前删除,停止或超出准备时间先发 SIGTERM);插件任务步骤、构建工具、插件运行和调试要在本机插件后端计划主机上的进程(#2231 R3/R4),本阶段不做。" }