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 index f6813e17b..3d765ceea 100644 --- 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 @@ -4,9 +4,9 @@ ## 先说结论 -本笔记覆盖 #2231 R1 的 #43a 和 #43b。远程工作区里,运行配置的读写、校验和启动计划由 Core 路由到主机(Core #161):配置文件经 `lithe_workspace::fs` 存在主机的项目目录,计划按主机平台(Linux、macOS)生成,从不生成批处理或 PowerShell。桌面端拿到计划后,用 `remote.runProcess` 在主机上启动内置的程序和脚本运行(`process.*`),输出进 Run 窗口,标签页带“主机”徽标。 +本笔记覆盖 #2231 R1 的 #43a、#43b 和 #43c。远程工作区里,运行配置的读写、校验和启动计划由 Core 路由到主机(Core #161):配置文件经 `lithe_workspace::fs` 存在主机的项目目录,计划按主机平台(Linux、macOS)生成,从不生成批处理或 PowerShell。桌面端拿到计划后,用 `remote.runProcess` 在主机上启动内置的程序和脚本运行(`process.*`),输出进 Run 窗口,标签页带“主机”徽标。 -配置“执行前”列表里引用的其他内置运行配置(#43b)同样在主机上按顺序运行,输出进同一个控制台。插件提供的执行前任务、构建工具、插件提供的运行和调试要由本机插件后端计划主机上的进程,属于 #2231 的 R3/R4,本阶段不做,各自说明原因(`desktop.run.remote.*`)。 +配置“执行前”列表里引用的其他内置运行配置(#43b)同样在主机上按顺序运行,输出进同一个控制台。运行中连接断开时(#43c),主机保留会话就不结束运行:Run 窗口等窗口重新连接,接上同一个主机会话后经 `remote.attachProcess`(Core #167)从丢失的位置接着接收输出;关闭时保留在主机上的进程,下次连接可在 Run 窗口里接回。插件提供的执行前任务、构建工具、插件提供的运行和调试要由本机插件后端计划主机上的进程,属于 #2231 的 R3/R4,本阶段不做,各自说明原因(`desktop.run.remote.*`)。 ## 问题 @@ -33,7 +33,7 @@ 2. 工作目录是项目相对的 `/` 路径,`remoteRunDirectory` 拼到主机根下,拒绝 `..` 和绝对路径。环境用主机的登录环境,叠加计划的 `environment` 和配置的 `env`。 3. 输出经 `remoteRunOutput` 交给控制台:观察回调只追加到缓冲区,从不等待;独立的泵按顺序送出。缓冲区上限 8 MiB,超出时丢弃最旧的未送出部分,并在控制台写一行提示(`desktop.run.remote.outputDropped`)。 4. “停止”先用 `process.kill`(force 为 false)给进程组发 SIGTERM,超过停止等待时间(`buildprocess.StopGrace`)仍未结束就取消请求,由 Core 强制结束。再按一次“停止”立即强制结束。 -5. 进程以非零退出码结束时运行失败,被信号结束时说明信号编号;连接断开时说明“无法确定是否仍在主机上运行”,并交给窗口重新连接(断线后接回输出是 #43c)。 +5. 进程以非零退出码结束时运行失败,被信号结束时说明信号编号;连接断开时交给窗口重新连接:主机保留会话时运行继续,见下文“断线后接回(#43c)”;主机不保留会话,或断线时主机还没给出进程 id 时,说明“无法确定是否仍在主机上运行”。 主机上的进程 id 不是本机的,`Pid()` 返回 0,所以 Run 窗口不采样它的端口、CPU 和内存。主机端口由端口工具窗口列出。 @@ -45,9 +45,28 @@ Core 只允许“执行前”列表引用内置进程运行(`process.*`), `failBeforeLaunch` 按 `ExitCode() int` 读退出码,本机的 `*exec.ExitError` 和主机的 `remoteRunExit` 都能说明“以退出码 N 结束”。确认询问(按指纹记住)与本机共用,主机步骤不另加询问。 +### 断线后接回(#43c) + +Core #167 在连接断开后把会话里进程的事件停放在主机上,带 `resume` 的重新连接接回同一个会话(`resumed=true`)后,`remote.attachProcess` 从这次连接还没收到的第一个事件开始转发:先发 `process.attached`(`truncated` 表示停放的事件超过上限、丢了一部分),再发之后的输出和退出。错误码一一对应:`connection_closed`(连接断开)、`remote_process_gone`(主机上没有这个进程了)、`remote_process_attached`(另一个连接正在接收它)。 + +`remoteRunHost.follow` 负责一次运行跨断线的接收: + +1. 请求因连接断开结束、主机已给出进程 id、会话有主机会话键(主机保留会话)时,不结束运行:控制台另起一行写 `desktop.run.remote.waiting`,经 `remoteRunRejoin` 把等待交给窗口线程,等工作区的下一个会话。窗口线程在 `rejoinRemoteRuns` 里把新会话交给所有等待者;等待用带缓冲的通道,窗口线程不等运行。 +2. 新会话的主机会话键相同时,`remoteProcess.move` 把停止、强制结束改走新会话,再用 `remote.attachProcess` 接收;`process.attached` 到达时先写 `desktop.run.remote.resumed`,`truncated` 时再写 `desktop.run.remote.outputLost`,然后才是之后的输出。可以断线多次,每次重复这一步。 +3. 新会话的主机会话键不同(主机开了新会话),说明 `desktop.run.remote.sessionEnded` 结束运行:旧会话的进程已无法接收。工作区关闭时等待被关闭,运行按 `connectionLost` 结束,主机上的程序由关闭确认决定结束还是保留。接回被拒时分别说明 `processGone` 和 `attachedElsewhere`。 +4. 等待期间用户按“停止”或项目关闭时,主机还不知道这次停止:`remoteRunAbandon` 把(主机会话键,进程 id)交给窗口,`endAbandonedRuns` 在接上同一个主机会话后立即强制结束这些进程;主机会话已变时直接忘掉,因为进程随旧会话结束。 + +控制台里窗口自己的说明用暗色另起一行(`remoteRunNotice`、`remoteRunLine`),不和进程没换行的输出接在一起。 + +### 保留进程的接回(#43c,设计 §9.2、S35) + +关闭确认保留在主机上的进程,下次连接接回会话后列出(见关闭确认的笔记)。列表里有进程时,对话框除“结束这些进程”“继续运行”外还有“在运行窗口中接回”;列表里同时有终端时说明终端无法接回(终端没有可回放的输出)。选它时 `attachKeptPrograms` 为每个进程建一个运行,键为 `remote-attach:<进程 id>`(已有同键运行就跳过,所以重复选择不会开两个标签页),用 `launchRemoteAttachRun` 在 Run 窗口里接收,最后打开 Run 窗口。标签页带“主机”徽标,控制台先写 `desktop.run.remote.attachedKept`;“停止”与普通运行一样先发 SIGTERM。之后的断线同样按上一节接回。 + ### 输出里的路径 -`flushOutputLinks` 在远程工作区用主机根作为工作区根、按 `linux` 平台匹配路径。点击时用 `remote.stat` 找第一个主机上存在的文件,经 `remoteplaceholder.LocalPath` 换成占位路径交给编辑器打开;工作区以外的路径落在占位根旁的 `.lithe-remote-host` 下,与“工作区以外的远端文件按 Zed 方式打开”一致。需要插件解析的链接拒绝,因为插件读的是本机文件。 +`flushOutputLinks` 在远程工作区用主机根作为工作区根、按 `linux` 平台匹配路径。点击时用 `remote.stat` 找第一个主机上存在的文件,经 `remoteplaceholder.LocalPath` 换成占位路径交给编辑器打开;工作区以外的路径落在占位根旁的 `.lithe-remote-host` 下,与“工作区以外的远端文件按 Zed 方式打开”一致。需要插件解析的链接拒绝,因为插件读的是本机文件。接回的进程(#43c)用同一个控制台,输出里的主机路径同样可点击。 + +设计 §7.3 还要求测试报告和构建诊断里的主机路径映射成工作区文件。这两者都由插件提供的构建系统产生:测试结果经 `DecodeBuildTestResults` 按插件的清单和构建系统解码,构建诊断来自构建工具的输出。远程工作区在 R3 之前不探测构建系统,不运行插件任务,所以 R1 里没有测试报告和构建诊断。它们的路径映射随 R3 插件按主机路径计划进程一起做,由 Core 在报告解码时完成,桌面端不另写一份。 ### 日志 @@ -60,19 +79,25 @@ Core 只允许“执行前”列表引用内置进程运行(`process.*`), - **远程工作区也探测构建系统**:探测在本机占位目录里运行,结果永远为空,还会误导用户以为项目没有构建工具。 - **远程工作区拒绝所有执行前步骤**(#43a 的做法):配置步骤只是另一个内置运行,主机已经能运行它;一起拒绝会让常见的“先编译再运行”脚本链用不了。 - **把主机步骤的请求直接挂在准备上下文上**:停止时 Core 立即强杀,主机程序没有机会清理,与本机步骤的停止行为不一致。 +- **断线时结束运行,让用户重新运行**:主机上的程序还在跑,重新运行会起第二份进程,端口和文件可能冲突;设计 §9.3 要求从上次的位置接着输出。 +- **断线等待期间的“停止”只在本机结束运行**:主机上的进程会一直留在会话里,只能在下次关闭时才被发现;所以接上同一个主机会话后立即强制结束。 +- **接回保留进程时自动打开所有标签页**:用户可能只想结束或让它们继续运行,接回由用户在对话框里选择。 ## 后果 - 远程工作区里能直接运行项目自带的程序和脚本配置,输出、停止和退出码与本机一致;Run 窗口的“主机”徽标说明它在哪里运行。 - “执行前”列表里的内置运行配置在主机上按顺序运行,失败、停止和超时与本机一致。 - 插件提供的执行前任务、构建工具、插件运行、调试和“当前文件”暂时不可用,各自给出说明;它们依赖 #2231 的 R3(插件按主机路径计划进程)和 R4(远程调试),本阶段不做。 -- 断线时运行结束为“无法确定是否仍在主机上运行”,主机上的进程可能还在;断线后接回输出由 #43c 负责。 +- 主机保留会话时,断线不结束运行;重新连接到同一个主机会话后接着输出,丢了部分输出时明确说明。主机开了新会话时,旧会话里的进程无法接收,运行结束并说明原因。 +- 关闭时保留的进程可以在下次连接时接回 Run 窗口,终端不能接回。 - 主机临时目录里可能残留断线或崩溃时没删掉的 `lithe-run-script-*` 目录,由主机的临时目录清理回收。 ## 验证 -- `desktop/internal/workbench/remote_run_test.go`:主机上的启动参数、工作目录、环境、脚本写入和删除;退出码和信号;“停止”先发 SIGTERM;执行前的配置步骤在主机上依次运行、失败时不启动配置、停止时先发 SIGTERM;插件任务步骤、工具链和调试的拒绝;输出缓冲丢弃最旧部分;输出链接的主机文件查找;不记主机和路径。 -- `desktop/internal/core/remote_process_test.go`:`remote.runProcess` 事件的解析。 +- `desktop/internal/workbench/remote_run_test.go`:主机上的启动参数、工作目录、环境、脚本写入和删除;退出码和信号;“停止”先发 SIGTERM;执行前的配置步骤在主机上依次运行、失败时不启动配置、停止时先发 SIGTERM;插件任务步骤、工具链和调试的拒绝;输出缓冲丢弃最旧部分;输出链接的主机文件查找;不记主机和路径;断线后等待、接上同一个主机会话后接着输出并说明丢失(`TestRemoteWorkspaceRunFollowsItsProcessAcrossAReconnection`);新会话、进程已不在、被别处接收时结束(`TestRemoteWorkspaceRunEndsWhenItsProcessCannotBeReceivedAgain`);等待期间停止的运行在重连后强制结束主机进程(`TestRemoteWorkspaceRunStoppedWhileDisconnectedEndsOnceReconnected`)。 +- `desktop/internal/workbench/remote_close_test.go`:“在运行窗口中接回”为每个保留的进程开 Run 标签页并打开 Run 窗口。 +- `TestVisualRemoteRun`、`TestVisualRemoteClose`:断线等待、重连后接着输出、接回保留进程的无头截图(`docs/assets/remote-run/`、`docs/assets/remote-close/`)。 +- `desktop/internal/core/remote_process_test.go`:`remote.runProcess`、`remote.attachProcess` 事件的解析。 - `scripts/desktop/verify/verify-runtime-bundle-immutability.sh`:运行时不写发行目录。 ## 适用范围 diff --git a/desktop/internal/core/errors.go b/desktop/internal/core/errors.go index ba940c102..324572f7b 100644 --- a/desktop/internal/core/errors.go +++ b/desktop/internal/core/errors.go @@ -91,6 +91,13 @@ const ( // CodeDevcontainerUntrustedFolder means remote.devcontainerUp named a folder the user has not // trusted; the Dev Container CLI did not run, because building runs the folder's code here. CodeDevcontainerUntrustedFolder ErrorCode = "devcontainer_untrusted_folder" + // CodeRemoteProcessGone means remote.attachProcess found no host process to receive: the + // connection resumed no session, the process ended before what this Core received, or an + // earlier attach already received it to its end. + CodeRemoteProcessGone ErrorCode = "remote_process_gone" + // CodeRemoteProcessAttached means another remote.attachProcess request already receives the + // host process. + CodeRemoteProcessAttached ErrorCode = "remote_process_attached" // CodeUnknown means the failure fits no more specific category. CodeUnknown ErrorCode = "unknown" ) diff --git a/desktop/internal/core/remote_process.go b/desktop/internal/core/remote_process.go index e65fbf490..7e5015a53 100644 --- a/desktop/internal/core/remote_process.go +++ b/desktop/internal/core/remote_process.go @@ -31,13 +31,16 @@ type RemoteProcessOpen struct { // 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 +// RemoteProcessEvents receive a host process's events. They 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. + // process's id on the host. remote.attachProcess does not call it. Started func(processID uint64, pid int) + // Attached is called once, before any output, when remote.attachProcess receives the process + // again. truncated means some of what the process wrote while nobody received it is missing. + Attached func(truncated bool) // Output receives the bytes the program wrote to stream, "stdout" or "stderr", in order. // Output owns data. Output func(stream string, data []byte) @@ -50,7 +53,7 @@ type RemoteProcessExit struct { Signal *int `json:"signal"` } -// remoteProcessEvent is one remote event of remote.runProcess. +// remoteProcessEvent is one remote event of remote.runProcess or remote.attachProcess. type remoteProcessEvent struct { Type string `json:"type"` Event string `json:"event"` @@ -59,10 +62,12 @@ type remoteProcessEvent struct { PID *int `json:"pid"` Stream string `json:"stream"` Data string `json:"data"` + Truncated bool `json:"truncated"` } `json:"params"` } -// errRemoteProcessEvent is an event of remote.runProcess the client cannot read. +// errRemoteProcessEvent is an event of remote.runProcess or remote.attachProcess 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 @@ -73,6 +78,30 @@ var errRemoteProcessEvent = errors.New("core: unreadable remote process 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) { + return c.receiveRemoteProcess(ctx, "remote.runProcess", struct { + SessionID string `json:"sessionId"` + Params RemoteProcessOpen `json:"params"` + }{sessionID, open}, events) +} + +// RemoteAttachProcess receives again the host process processID that an earlier connection to +// the host session started, after sessionID resumed that session (design §9.3): first Attached, +// then what the process wrote meanwhile and after, until its leader exits, and returns how it +// ended. The request then owns the process as RemoteRunProcess's does: ending ctx kills it. A +// broken or unknown session fails with CodeConnectionClosed, a process nothing can receive any +// more with CodeRemoteProcessGone, and one another request receives with +// CodeRemoteProcessAttached. +func (c *Client) RemoteAttachProcess(ctx context.Context, sessionID string, processID uint64, events RemoteProcessEvents) (RemoteProcessExit, error) { + return c.receiveRemoteProcess(ctx, "remote.attachProcess", struct { + SessionID string `json:"sessionId"` + ProcessID uint64 `json:"processId"` + }{sessionID, processID}, events) +} + +// receiveRemoteProcess runs command, which relays one host process's events until its leader +// exits, and returns the exit. An event the client cannot read cancels the request, which ends +// the process, and is returned as the error. +func (c *Client) receiveRemoteProcess(ctx context.Context, command string, payload any, events RemoteProcessEvents) (RemoteProcessExit, error) { ctx, cancel := context.WithCancel(ctx) defer cancel() var unreadable error @@ -87,10 +116,7 @@ func (c *Client) RemoteRunProcess(ctx context.Context, sessionID string, open Re } } var exit RemoteProcessExit - observationErr, err := c.ExecuteWithEvents(ctx, "remote.runProcess", struct { - SessionID string `json:"sessionId"` - Params RemoteProcessOpen `json:"params"` - }{sessionID, open}, &exit, observer) + observationErr, err := c.ExecuteWithEvents(ctx, command, payload, &exit, observer) switch { case unreadable != nil: return RemoteProcessExit{}, unreadable @@ -102,8 +128,8 @@ func (c *Client) RemoteRunProcess(ctx context.Context, sessionID string, open Re return exit, nil } -// deliverRemoteProcessEvent hands one event of remote.runProcess to events. Events of other kinds -// are not the process's and are ignored. +// deliverRemoteProcessEvent hands one event of remote.runProcess or remote.attachProcess 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 @@ -121,6 +147,10 @@ func deliverRemoteProcessEvent(raw json.RawMessage, events RemoteProcessEvents) } events.Started(event.Params.ProcessID, pid) } + case "process.attached": + if events.Attached != nil { + events.Attached(event.Params.Truncated) + } case "process.output": if event.Params.Stream != "stdout" && event.Params.Stream != "stderr" { return errRemoteProcessEvent diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index f1c8cee96..2c5f41bd8 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1828,6 +1828,9 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.keepAlive": "Keep-Alive (s)", "desktop.remote.keepAliveHelp": "How often OpenSSH checks that the server still answers (ServerAliveInterval), so a dropped network is noticed.", "desktop.remote.keepAlivePlaceholder": "Auto (SSH config)", + "desktop.remote.kept.attach": "Show in Run Window", + "desktop.remote.kept.attachFailed": "Could not show the programs kept on {connection}: the workspace is not connected to the host session that runs them.", + "desktop.remote.kept.attachTerminals": "Terminals cannot be shown again; they keep running until you end them.", "desktop.remote.kept.end": "End Them", "desktop.remote.kept.endFailed": "Could not end the programs kept on {connection}.", "desktop.remote.kept.ended": "Ended programs on {connection}: {count}", @@ -2147,6 +2150,8 @@ 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.attachedElsewhere": "another window already shows this program's output", + "desktop.run.remote.attachedKept": "Showing again a program a closed window kept running on the host.", "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", @@ -2154,9 +2159,14 @@ var sharedCatalogs = map[string]map[string]string{ "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.outputLost": "Some output was lost while nothing received it.", + "desktop.run.remote.processGone": "the host no longer has the program, or its output can no longer be received", + "desktop.run.remote.resumed": "Reconnected; the output continues.", + "desktop.run.remote.sessionEnded": "the workspace reconnected to a new host session; the program of the earlier session cannot be shown again", "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.remote.waiting": "The connection to the host broke. Waiting to reconnect…", "desktop.run.rerun": "Run again", "desktop.run.signalled": "Process stopped by signal {signal}.", "desktop.run.snapshot.menu": "Snapshot output", @@ -5743,6 +5753,9 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.keepAlive": "保活间隔(秒)", "desktop.remote.keepAliveHelp": "OpenSSH 每隔多久确认一次服务器仍有响应(ServerAliveInterval),以便发现网络已断开。", "desktop.remote.keepAlivePlaceholder": "自动(SSH 配置)", + "desktop.remote.kept.attach": "在运行窗口中接回", + "desktop.remote.kept.attachFailed": "无法接回 {connection} 上保留的进程:工作区没有连接到运行它们的主机会话。", + "desktop.remote.kept.attachTerminals": "终端无法接回,会一直运行,直到你结束它们。", "desktop.remote.kept.end": "结束这些进程", "desktop.remote.kept.endFailed": "无法结束 {connection} 上保留的进程。", "desktop.remote.kept.ended": "已结束 {connection} 上的 {count} 个进程", @@ -6062,6 +6075,8 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.run.ports.more": "+{count}", "desktop.run.ports.open": "在浏览器中打开", "desktop.run.ports.openFailed": "无法打开 {url}。", + "desktop.run.remote.attachedElsewhere": "另一个窗口已在显示这个程序的输出", + "desktop.run.remote.attachedKept": "已接回上次关闭时保留在主机上运行的进程。", "desktop.run.remote.badge": "主机", "desktop.run.remote.badgeHelp": "此程序运行在远程工作区的主机上。", "desktop.run.remote.beforeLaunch": "远程工作区暂不支持插件提供的执行前任务,请从“执行前”列表中删除这些任务后再在主机上运行", @@ -6069,9 +6084,14 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.run.remote.connectionLost": "程序运行时与主机的连接断开了,无法确定它是否仍在主机上运行", "desktop.run.remote.notConnected": "远程工作区未连接,请在重新连接后再运行", "desktop.run.remote.outputDropped": "部分输出到达太快,来不及显示,已略去。", + "desktop.run.remote.outputLost": "部分输出已丢失:没有接收方期间程序写出的内容没能全部保留。", + "desktop.run.remote.processGone": "主机上已没有这个程序,或已无法再接收它的输出", + "desktop.run.remote.resumed": "已重新连接,输出继续。", + "desktop.run.remote.sessionEnded": "工作区重新连接到了新的主机会话,无法再接回之前会话里的程序", "desktop.run.remote.signal": "程序被信号 {signal} 结束", "desktop.run.remote.toolchain": "远程工作区暂不支持运行通过工具链选择的程序,请填写主机上的程序名或路径", "desktop.run.remote.unsupported": "远程工作区只在主机上运行程序和脚本运行配置,暂不支持调试", + "desktop.run.remote.waiting": "与主机的连接断开了,正在等待重新连接…", "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 e4a43d525..42c9151b2 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -244,6 +244,7 @@ type Kernel interface { 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) + RemoteAttachProcess(ctx context.Context, sessionID string, processID uint64, 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 diff --git a/desktop/internal/workbench/remote_close.go b/desktop/internal/workbench/remote_close.go index c7eaf0ae1..89558e37f 100644 --- a/desktop/internal/workbench/remote_close.go +++ b/desktop/internal/workbench/remote_close.go @@ -3,6 +3,7 @@ package workbench import ( "context" "errors" + "path" "strconv" "strings" @@ -273,23 +274,39 @@ func (a *App) returnRemoteSession(connectionID string, session core.RemoteSessio } // offerKeptPrograms tells, once workspace p attached a session an earlier window kept, which -// programs that window left running on the host, and offers to end them (§9.2, S35): those alone, -// not the ones p started since. Keeping them needs nothing; closing p lists them again. +// programs that window left running on the host, and offers to end them or to receive the +// processes again in the Run window (§9.2, S35): those alone, not the ones p started since. +// Keeping them needs nothing; closing p lists them again. A terminal has no output to replay, so +// it is not received again. func (a *App) offerKeptPrograms(p *project, session core.RemoteSession) { if !session.Resumed || len(session.KeptPrograms) == 0 { return } - r, kept, language := p.remote, session.KeptPrograms, a.language() + r, kept, key, language := p.remote, session.KeptPrograms, session.SessionKey, a.language() + var processes []core.RemoteProgram + for _, program := range kept { + if program.Kind == core.RemoteProgramProcess { + processes = append(processes, program) + } + } + text := i18n.SharedFormat(language, "desktop.remote.kept.text", map[string]string{ + "connection": r.name, + "count": strconv.Itoa(len(kept)), + }) + "\n\n" + remoteProgramLines(language, kept) + actions := []string{i18n.Shared(language, "desktop.remote.kept.end")} + attach := -1 + if len(processes) > 0 { + attach = len(actions) + actions = append(actions, i18n.Shared(language, "desktop.remote.kept.attach")) + if len(processes) < len(kept) { + text += "\n\n" + i18n.Shared(language, "desktop.remote.kept.attachTerminals") + } + } + actions = append(actions, i18n.Shared(language, "desktop.remote.kept.keep")) a.prompts.queue = append(a.prompts.queue, &pluginPrompt{ - title: i18n.Shared(language, "desktop.remote.kept.title"), - text: i18n.SharedFormat(language, "desktop.remote.kept.text", map[string]string{ - "connection": r.name, - "count": strconv.Itoa(len(kept)), - }) + "\n\n" + remoteProgramLines(language, kept), - actions: []string{ - i18n.Shared(language, "desktop.remote.kept.end"), - i18n.Shared(language, "desktop.remote.kept.keep"), - }, + title: i18n.Shared(language, "desktop.remote.kept.title"), + text: text, + actions: actions, onAnswer: func(choice *int) { switch { case choice == nil: @@ -297,6 +314,9 @@ func (a *App) offerKeptPrograms(p *project, session core.RemoteSession) { case *choice == 0: a.performed("remote.kept.end", surfaceButton) a.endKeptPrograms(p, kept) + case *choice == attach: + a.performed("remote.kept.attach", surfaceButton) + a.attachKeptPrograms(p, key, processes) default: a.performed("remote.kept.keep", surfaceButton) } @@ -304,6 +324,45 @@ func (a *App) offerKeptPrograms(p *project, session core.RemoteSession) { }) } +// attachKeptPrograms receives processes, which an earlier window kept running in host session +// key, again over the session of p, each in a Run tab of its own until it exits, and shows the +// Run window on the last one; stopping the tab ends it on the host. A process a tab already +// receives gets no second one. +func (a *App) attachKeptPrograms(p *project, key string, processes []core.RemoteProgram) { + r := p.remote + if session := r.current(); r.closed || session.id == "" || session.key != key { + a.operationRejected("remote_attach_programs", "disconnected") + a.notifyError(i18n.SharedFormat(a.language(), "desktop.remote.kept.attachFailed", map[string]string{"connection": r.name})) + return + } + shown := false + for _, program := range processes { + runKey := "remote-attach:" + strconv.FormatUint(program.ID, 10) + if p.build.runOf(runKey) != nil { + // log-exempt: 用户重复操作:这个进程已经在自己的运行标签里接回,不开第二个。 + continue + } + op := a.beginRunOperation(p, remoteProgramName(program), "", runKey, nil) + a.launchRemoteAttachRun(p, op, key, program.ID) + shown = true + } + if shown { + a.showBuildConsole(p) + } +} + +// remoteProgramName is what the Run tab of a received program is called: its label's name, else +// the name of the file it runs. It is user content, never logged. +func remoteProgramName(program core.RemoteProgram) string { + if program.Label != nil && program.Label.Name != "" { + return program.Label.Name + } + if len(program.Argv) > 0 { + return path.Base(program.Argv[0]) + } + return "" +} + // endKeptPrograms ends programs, which an earlier window kept on the host of p, over the // workspace's session; one that already ended is not counted. func (a *App) endKeptPrograms(p *project, programs []core.RemoteProgram) { diff --git a/desktop/internal/workbench/remote_close_test.go b/desktop/internal/workbench/remote_close_test.go index 1230561ff..dc6feeff6 100644 --- a/desktop/internal/workbench/remote_close_test.go +++ b/desktop/internal/workbench/remote_close_test.go @@ -212,7 +212,8 @@ func TestRemoteCloseKeepsTheProgramsForTheNextConnection(t *testing.T) { h.settle() offer := h.app.prompts.queue[0] if offer.title != i18n.Shared(lang, "desktop.remote.kept.title") || !strings.Contains(offer.text, "npm run dev") || - !slices.Equal(offer.actions, []string{"End Them", "Keep Running"}) { + !strings.Contains(offer.text, i18n.Shared(lang, "desktop.remote.kept.attachTerminals")) || + !slices.Equal(offer.actions, []string{"End Them", "Show in Run Window", "Keep Running"}) { t.Fatalf("offer %q %q %q", offer.title, offer.text, offer.actions) } h.answer(0) @@ -238,6 +239,45 @@ func TestRemoteCloseKeepsTheProgramsForTheNextConnection(t *testing.T) { } } +// Show in Run Window receives each kept process again, in a Run tab of its own that says so, over +// the session that resumed the kept one; the tab ends with the process. A terminal is not received +// again. Neither the programs' commands nor their names are logged. +func TestRemoteCloseShowsTheKeptProcessesInTheRunWindow(t *testing.T) { + h, k, _, logger := remoteWorkspaceHarness(t) + lang := h.app.language() + h.openRemoteTestProject(t) + k.set(func(k *remoteHostKernel) { k.close.running = remoteTestPrograms }) + h.closeQuestion(t) + h.answer(1) + h.awaitClosed(t) + k.set(func(k *remoteHostKernel) { k.close.running = nil }) + h.app.openRemote(surfaceMenu) + h.settle() + h.settle() + p := h.openRemoteTestProject(t) + h.await("the offer about the kept programs", func() bool { return len(h.app.prompts.queue) == 1 }) + h.settle() + h.answer(1) + run := h.awaitRemoteRun(p, "npm", nil) + console := run.output.all() + if run.outcome != runSucceeded || !run.remote || !strings.Contains(console, i18n.Shared(lang, "desktop.run.remote.attachedKept")) || + !strings.Contains(console, remoteHostAttachOutput) { + t.Fatalf("the kept process's tab ended %v: %s; console:\n%s", run.outcome, run.summary, console) + } + if !h.app.chrome.isOpen(catalogIndex[itemRun]) { + t.Fatal("Show in Run Window did not open the Run window") + } + if got := k.remoteAttaches(); !slices.Equal(got, []string{"session-2"}) || len(p.build.runs) != 1 { + t.Fatalf("received %d kept processes in %d tabs, over the resumed session %v", len(got), len(p.build.runs), slices.Equal(got, []string{"session-2"})) + } + if actions := remoteActions(logger); actions[len(actions)-1] != "remote.kept.attach" { + t.Fatalf("performed %q", actions) + } + if event := loggedAny(t, logger, append(slices.Clone(remoteCloseSecrets), "npm")...); event != "" { + t.Fatalf("logged a command, a name or a token: %s", event) + } +} + // A connection that resumes a kept session and gives it back without opening a folder keeps it // again, so its programs do not end without the user choosing it. func TestRemoteCloseKeepsAResumedSessionNoWorkspaceTook(t *testing.T) { diff --git a/desktop/internal/workbench/remote_close_visual_test.go b/desktop/internal/workbench/remote_close_visual_test.go index 2e968a7b8..072c1be17 100644 --- a/desktop/internal/workbench/remote_close_visual_test.go +++ b/desktop/internal/workbench/remote_close_visual_test.go @@ -19,7 +19,8 @@ import ( // TestVisualRemoteClose captures closing a remote workspace whose host still runs a terminal and a // process of it: the question with the programs, Remember my choice and its help; the notice once -// they are kept on the host; and, on the next connection, the offer to end the kept programs. +// they are kept on the host; on the next connection, the offer to end the kept programs or show +// the process in the Run window; and the Run tab that receives the kept process again. func TestVisualRemoteClose(t *testing.T) { out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") if out == "" { @@ -94,12 +95,40 @@ func TestVisualRemoteClose(t *testing.T) { kernel.set(func(k *remoteHostKernel) { k.close.running = nil }) h.app.openRemote(surfaceMenu) h.settleChain() - h.openRemoteTestProject(t) + p := h.openRemoteTestProject(t) h.await("the offer to end the kept programs", func() bool { return len(h.app.prompts.queue) == 1 }) shot("offer") if h.app.prompts.queue[0].title != i18n.Shared(h.app.language(), "desktop.remote.kept.title") { t.Fatal("the offer to end the kept programs is not shown") } + + // Show in Run Window receives the kept process, which goes on running, in a Run tab. + kernel.setRuns(func(r *remoteHostRuns) { + r.hold, r.signalled = true, make(chan struct{}) + r.attachOutput = " VITE ready in 312 ms\n\n ➜ Local: http://localhost:5173/\n" + }) + attach := 1 + h.app.answerPrompt(&attach) + h.await("the kept process's output in its Run tab", func() bool { + op := p.build.runOf("remote-attach:7") + return op != nil && op.session != nil && strings.Contains(op.session.output.all(), "VITE ready") + }) + // The pointer leaves the dialog's buttons, whose highlight would stay. + if err := h.driver.Move(800, 300); err != nil { + t.Fatal(err) + } + h.app.invalidator.Invalidate() + for range 3 { + if err := h.driver.Pump(); err != nil { + t.Fatal(err) + } + } + if err := session.Screenshot(filepath.Join(out, "remote-close-attached-"+look.suffix+".png")); err != nil { + t.Fatal(err) + } + // The process ends before the window closes, which waits for every run. + kernel.setRuns(func(r *remoteHostRuns) { close(r.signalled) }) + h.awaitRemoteRun(p, "npm", nil) }) } } diff --git a/desktop/internal/workbench/remote_run.go b/desktop/internal/workbench/remote_run.go index 26fb05015..1e8a4a4ce 100644 --- a/desktop/internal/workbench/remote_run.go +++ b/desktop/internal/workbench/remote_run.go @@ -23,6 +23,13 @@ import ( // 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. // +// A connection lost while the program runs does not end the run when the host keeps the session +// (design §9.3): the Run window says so and waits for the workspace to connect again. A session +// that resumed the same host session receives the process again (remote.attachProcess), from the +// first event the lost connection did not receive, and the window says when some output is +// missing; any other session ends the run. A kept program a closed window left running is +// received the same way, in a Run tab of its own (remote_close.go, design §9.2, S35). +// // Note: 远程工作区运行配置的决策见 .agents/notes/implemented/architecture/2026-11-22-remote-workspace-process-runs.md const ( @@ -39,15 +46,12 @@ const ( // 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. +// the run preparation time; the process runs until it exits, the user stops it or the project +// closes, which ends it on the host too. A lost connection ends the run only when the host keeps +// no session for it, or the session that replaces it is another (follow). 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), - } + host := a.remoteRunHostOf(p, op) + host.label = core.NewRemoteResourceLabel("run", op.session.label) 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) @@ -66,6 +70,36 @@ func (a *App) launchRemoteProcessRun(p *project, op *buildOperation, id string) }) } +// launchRemoteAttachRun receives host process id, which a closed window kept running in the host +// session key, in op's console until it exits, off the window thread. The process is op's at +// once: stopping op ends it on the host. It follows the process across lost connections as a run +// does. +func (a *App) launchRemoteAttachRun(p *project, op *buildOperation, key string, id uint64) { + host := a.remoteRunHostOf(p, op) + a.streamBuildOutput(p, op, remoteRunLine(i18n.Shared(host.language, "desktop.run.remote.attachedKept"))) + a.background(p, 0, func(ctx context.Context) func(*App) { + host.failed = func(operation string, err error) { a.backgroundFailedIn(ctx, operation, remoteLogError(err)) } + err := host.receive(ctx, key, id, func(process *remoteProcess) { + a.post(func(a *App) { a.attachProcess(p, op, process) }) + }) + return func(a *App) { a.finishBuildRun(p, op, err) } + }) +} + +// remoteRunHostOf is what a run of p with its output in op's console takes from the window +// thread. +func (a *App) remoteRunHostOf(p *project, op *buildOperation) remoteRunHost { + r := p.remote + return remoteRunHost{ + kernel: a.kernel, binding: r.binding, root: p.root, language: a.language(), + current: r.current, + output: func(text string) { a.streamBuildOutput(p, op, text) }, + lost: a.remoteSessionLost(p), + rejoin: a.remoteRunRejoin(p), + abandon: a.remoteRunAbandon(p), + } +} + // 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 @@ -102,38 +136,48 @@ type remoteRunHost struct { root string language i18n.Language label *core.RemoteResourceLabel + // current is the workspace's session now (remoteProject.current). + current func() remoteSessionRef // 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) + // rejoin waits under ctx for the workspace's session that replaces lost; false when ctx ended + // or the workspace closed first (App.remoteRunRejoin). + rejoin func(ctx context.Context, lost string) (remoteSessionRef, bool) + // abandon hands the window host process id of host session key, whose run ended while the + // connection was lost, to end once a session resumes key (App.remoteRunAbandon). + abandon func(key string, id uint64) // 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. +// remoteRunStart is a planned run: the session it runs over and the host session that is +// (remoteSessionRef), its host temporary folder ("" when none was created) and how its process +// starts. type remoteRunStart struct { - session, scratch string - open core.RemoteProcessOpen + session remoteSessionRef + 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 == "" { + start := remoteRunStart{session: h.current()} + if start.session.id == "" { return start, errors.New(i18n.Shared(h.language, "desktop.run.remote.notConnected")) } - scratch, err := h.kernel.RemoteTempDirectory(ctx, start.session, remoteRunScratchPrefix) + scratch, err := h.kernel.RemoteTempDirectory(ctx, start.session.id, remoteRunScratchPrefix) if err != nil { - return start, h.failure(start.session, err) + return start, h.failure(start.session.id, 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) + return start, h.failure(start.session.id, err) } if start.open, err = h.processOpen(plan); err != nil { return start, err @@ -200,9 +244,9 @@ func (h remoteRunHost) writeScript(ctx context.Context, start remoteRunStart, sc 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) + _, saved, err := h.kernel.RemoteWriteFile(ctx, start.session.id, script.Path, []byte(script.Content), nil) if err != nil { - return h.failure(start.session, err) + return h.failure(start.session.id, err) } if !saved { return errors.New("inline script file already exists") @@ -211,25 +255,122 @@ func (h remoteRunHost) writeScript(ctx context.Context, start remoteRunStart, sc } // 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. +// process once the host started it. A lost connection waits for the workspace to connect again +// (follow). 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) { + process := h.newProcess(start.session.id, cancel) + defer close(process.done) + return h.follow(ctx, start.session.key, process, func(session string, events core.RemoteProcessEvents) (core.RemoteProcessExit, error) { + events.Started = func(processID uint64, _ int) { if process.id.CompareAndSwap(0, processID) { attach(process) } - }, - Output: func(_ string, data []byte) { output.add(data) }, + } + return h.kernel.RemoteRunProcess(ctx, session, start.open, events) }) - close(process.done) - output.close() - return h.endError(ctx, start.session, exit, err) +} + +// receive receives host process id, which an earlier connection to host session key started, +// over the workspace's session under ctx until its leader exits; attach receives the process at +// once. It ends as run does. +func (h remoteRunHost) receive(ctx context.Context, key string, id uint64, attach func(*remoteProcess)) error { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + session := h.current() + switch { + case session.id == "": + return errors.New(i18n.Shared(h.language, "desktop.run.remote.notConnected")) + case session.key != key: + return errors.New(i18n.Shared(h.language, "desktop.run.remote.sessionEnded")) + } + process := h.newProcess(session.id, cancel) + defer close(process.done) + process.id.Store(id) + attach(process) + return h.follow(ctx, key, process, h.attachRequest(ctx, id)) +} + +// remoteReceive sends the request that receives a run's process over session, with events. +type remoteReceive func(session string, events core.RemoteProcessEvents) (core.RemoteProcessExit, error) + +// attachRequest is the remoteReceive of remote.attachProcess for host process id under ctx. +func (h remoteRunHost) attachRequest(ctx context.Context, id uint64) remoteReceive { + return func(session string, events core.RemoteProcessEvents) (core.RemoteProcessExit, error) { + return h.kernel.RemoteAttachProcess(ctx, session, id, events) + } +} + +// newProcess is a run's process over session, whose request cancel ends. +func (h remoteRunHost) newProcess(session string, cancel context.CancelFunc) *remoteProcess { + process := &remoteProcess{kernel: h.kernel, cancel: cancel, done: make(chan struct{}), failed: h.failed} + process.session.Store(&session) + return process +} + +// follow receives process over first, then, while the host keeps host session key, again over +// each session that resumes key after a lost connection, until its leader exits; it returns why +// the run ended as run does. A request the lost connection ended waits for the workspace's next +// session, with the wait in the console, once the host started the process: a process the +// connection lost before Core named it cannot be received again. A run that ends meanwhile +// leaves its process to the window, which ends it once a session resumes key. key "" is a +// connection whose host keeps no session, which a lost connection ends. +func (h remoteRunHost) follow(ctx context.Context, key string, process *remoteProcess, first remoteReceive) error { + receive, resumed := first, false + for { + session := process.over() + output := newRemoteRunOutput(h.output, remoteRunNotice(i18n.Shared(h.language, "desktop.run.remote.outputDropped"))) + exit, err := receive(session, core.RemoteProcessEvents{ + // Core calls it before the request's first output. + Attached: func(truncated bool) { + if resumed { + output.lead(remoteRunLine(i18n.Shared(h.language, "desktop.run.remote.resumed"))) + } + if truncated { + output.lead(remoteRunLine(i18n.Shared(h.language, "desktop.run.remote.outputLost"))) + } + }, + Output: func(_ string, data []byte) { output.add(data) }, + }) + output.close() + id := process.id.Load() + if err == nil || !remoteConnectionClosed(err) || id == 0 || key == "" { + return h.endError(ctx, session, exit, err) + } + if ctx.Err() != nil { + // The run was stopped as the connection broke: the host never heard of it. + h.abandon(key, id) + return ctx.Err() + } + h.lost(session) + h.output(remoteRunNotice(i18n.Shared(h.language, "desktop.run.remote.waiting"))) + next, ok := h.rejoin(ctx, session) + switch { + case ctx.Err() != nil: + h.abandon(key, id) + return ctx.Err() + case !ok: + // The workspace closed, which decided what happens to the host's programs. + return errors.New(i18n.Shared(h.language, "desktop.run.remote.connectionLost")) + case next.key != key: + return errors.New(i18n.Shared(h.language, "desktop.run.remote.sessionEnded")) + } + process.move(next.id) + receive, resumed = h.attachRequest(ctx, id), true + } +} + +// remoteRunNotice is the window's own console text on a line of its own, after output that may +// not end its line. +func remoteRunNotice(text string) string { + return "\n" + remoteRunLine(text) +} + +// remoteRunLine is the window's own console text as a line, at the start of one. +func remoteRunLine(text string) string { + return "\x1b[2m" + text + "\x1b[0m\n" } // endError is why a run's request ended as the console reads it. A request ctx ended was @@ -250,24 +391,33 @@ func (h remoteRunHost) endError(ctx context.Context, session string, exit core.R } // 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. +// to the window and reads as a lost connection, and the refusals of remote.attachProcess say why +// the process cannot be received. func (h remoteRunHost) failure(session string, err error) error { - if remoteConnectionClosed(err) { + var coreErr *core.Error + switch { + case remoteConnectionClosed(err): h.lost(session) return errors.New(i18n.Shared(h.language, "desktop.run.remote.connectionLost")) + case errors.As(err, &coreErr) && coreErr.Code == core.CodeRemoteProcessGone: + return errors.New(i18n.Shared(h.language, "desktop.run.remote.processGone")) + case errors.As(err, &coreErr) && coreErr.Code == core.CodeRemoteProcessAttached: + return errors.New(i18n.Shared(h.language, "desktop.run.remote.attachedElsewhere")) } 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. +// none. It goes over the workspace's session now, which the run may have followed to a later +// one; a folder the workspace is disconnected from is left to the host. func (h remoteRunHost) cleanup(ctx context.Context, start remoteRunStart) { - if start.scratch == "" { + session := h.current().id + if start.scratch == "" || session == "" { 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) { + if err := h.kernel.RemoteRemove(ctx, session, start.scratch, true); err != nil && !remoteConnectionClosed(err) { h.failed("run_inline_script_cleanup", err) } } @@ -282,8 +432,10 @@ 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 + kernel Kernel + // session is the session the process is received over: the one it started in, then each one + // that resumed its host session after a lost connection. + session atomic.Pointer[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. @@ -297,8 +449,15 @@ type remoteProcess struct { // 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 } +// over is the session the process is received over now. +func (r *remoteProcess) over() string { return *r.session.Load() } + +// move makes session, which resumed the process's host session, the one it is received over. +func (r *remoteProcess) move(session string) { r.session.Store(&session) } + // 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. +// the stop time passed. A stop the host could not be asked for kills them at once; while the +// connection is lost, that is once a session resumes the host session (follow). func (r *remoteProcess) Stop() { r.stopping.Do(func() { grace := buildprocess.StopGrace() @@ -310,7 +469,7 @@ func (r *remoteProcess) Stop() { 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) + err := r.kernel.RemoteProcessKill(ctx, r.over(), r.id.Load(), false) cancel() if err != nil { if ctx.Err() == nil && !remoteConnectionClosed(err) { @@ -340,7 +499,9 @@ type remoteRunOutput struct { wake chan struct{} done chan struct{} - mu sync.Mutex + mu sync.Mutex + // leading is the window's own text, delivered before pending. + leading []string pending []byte dropped bool closed bool @@ -365,6 +526,15 @@ func (o *remoteRunOutput) add(data []byte) { o.signal() } +// lead adds text of the window's own before the output, which nothing was added of yet, and +// never waits. +func (o *remoteRunOutput) lead(text string) { + o.mu.Lock() + o.leading = append(o.leading, text) + o.mu.Unlock() + o.signal() +} + // close delivers what is left and waits for the pump to finish. func (o *remoteRunOutput) close() { o.mu.Lock() @@ -385,9 +555,12 @@ 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 + leading, data, dropped, closed := o.leading, o.pending, o.dropped, o.closed + o.leading, o.pending, o.dropped = nil, nil, false o.mu.Unlock() + for _, text := range leading { + o.deliver(text) + } if dropped { o.deliver(o.notice) } @@ -399,3 +572,117 @@ func (o *remoteRunOutput) pump() { } } } + +// remoteSessionRef is a session of a remote workspace with the host session it is attached to +// (core.RemoteSession.SessionKey), "" for a host that keeps no session for the connection. Two +// sessions of one key reach the same host processes, whose ids are per host session. +type remoteSessionRef struct { + id, key string +} + +// remoteAbandoned is a host process of host session key whose run ended while the connection was +// lost: nothing could tell the host to end it. +type remoteAbandoned struct { + key string + id uint64 +} + +// remoteRunRejoin is how a run of p waits, off the window thread, for the session that replaces +// the lost one (remoteRunHost.rejoin). +func (a *App) remoteRunRejoin(p *project) func(context.Context, string) (remoteSessionRef, bool) { + return func(ctx context.Context, lost string) (remoteSessionRef, bool) { + // Buffered, so the window thread hands the session over without waiting for the run. + wait := make(chan remoteSessionRef, 1) + a.post(func(a *App) { a.awaitRemoteSession(p, lost, wait) }) + select { + case next, ok := <-wait: + return next, ok + case <-ctx.Done(): + return remoteSessionRef{}, false + } + } +} + +// awaitRemoteSession hands wait the workspace's session once there is one other than lost, and +// closes it when the workspace closed. +func (a *App) awaitRemoteSession(p *project, lost string, wait chan<- remoteSessionRef) { + r := p.remote + switch session := r.current(); { + case a.project != p || r.closed: + close(wait) + case session.id != "" && session.id != lost: + wait <- session + default: + r.rejoins = append(r.rejoins, wait) + } +} + +// remoteRunAbandon is how a run of p that ended while its connection was lost hands its host +// process to the window, off the window thread (remoteRunHost.abandon). +func (a *App) remoteRunAbandon(p *project) func(key string, id uint64) { + return func(key string, id uint64) { + a.post(func(a *App) { + r := p.remote + if a.project != p || r.closed { + // log-exempt: 用户取消:工作区已关闭,关闭时已决定主机上的程序是结束还是保留。 + return + } + r.abandoned = append(r.abandoned, remoteAbandoned{key: key, id: id}) + if r.session != "" { + a.endAbandonedRuns(p) + } + }) + } +} + +// rejoinRemoteRuns hands the workspace's new session to the runs waiting for one and ends the +// host processes of the runs that ended meanwhile once it resumed their host session; with any +// other, they ended with their own. +func (a *App) rejoinRemoteRuns(p *project) { + r := p.remote + session := r.current() + for _, wait := range r.rejoins { + wait <- session + } + r.rejoins = nil + a.endAbandonedRuns(p) +} + +// endAbandonedRuns ends, at once and over the workspace's session, the abandoned host processes +// of its host session, and forgets the others: their host session ended. +func (a *App) endAbandonedRuns(p *project) { + r := p.remote + session := r.current() + var ids []uint64 + for _, process := range r.abandoned { + if session.key != "" && process.key == session.key { + ids = append(ids, process.id) + } + } + r.abandoned = nil + if len(ids) == 0 { + return + } + kernel := a.kernel + a.background(p, remoteRunRequestTimeout, func(ctx context.Context) func(*App) { + var failed error + for _, id := range ids { + if err := kernel.RemoteProcessKill(ctx, session.id, id, true); err != nil && !remoteConnectionClosed(err) { + failed = err + } + } + if failed == nil { + return nil + } + return func(a *App) { a.backgroundFailed("run_stop_after_reconnect", remoteLogError(failed)) } + }) +} + +// closeRemoteRuns closes the waits of the runs of a closing workspace and forgets its abandoned +// host processes: closing it decides what happens to the host's programs. +func (r *remoteProject) closeRemoteRuns() { + for _, wait := range r.rejoins { + close(wait) + } + r.rejoins, r.abandoned = nil, nil +} diff --git a/desktop/internal/workbench/remote_run_test.go b/desktop/internal/workbench/remote_run_test.go index ddec25953..9fdf79f1f 100644 --- a/desktop/internal/workbench/remote_run_test.go +++ b/desktop/internal/workbench/remote_run_test.go @@ -1,8 +1,10 @@ package workbench import ( + "cmp" "context" "path/filepath" + "slices" "strings" "sync" "testing" @@ -18,8 +20,9 @@ import ( 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. +// processes (remote.runProcess, remote.attachProcess): a process prints remoteHostRunOutput and +// exits with exit, or, with hold, runs until it is signalled, the connection of its session breaks +// or its request ends. Receiving it again prints remoteHostAttachOutput and ends the same way. type remoteHostRuns struct { mu sync.Mutex // configurations are what Core resolves, and plan is the launch plan of each. @@ -41,6 +44,67 @@ type remoteHostRuns struct { signalled chan struct{} // ended is closed once a process's request returned. ended chan struct{} + // drops are closed once the connection of their session broke (breakConnection). + drops map[string]chan struct{} + // attaches are the sessions remote.attachProcess went over; attachTruncated says output was + // lost before the request; attachErr refuses it; attachOutput, when set, is what the process + // prints once received instead of remoteHostAttachOutput. + attaches []string + attachTruncated bool + attachErr error + attachOutput string +} + +// remoteHostAttachOutput is what a host process prints once it is received again. +const remoteHostAttachOutput = "after the reconnection\n" + +// remoteTestConnectionClosed is how a request over a broken connection ends. +var remoteTestConnectionClosed = &core.Error{Command: "remote.runProcess", Code: core.CodeConnectionClosed, Message: "closed"} + +// dropped is closed once the connection of session broke. It runs under r.mu. +func (r *remoteHostRuns) dropped(session string) chan struct{} { + if r.drops == nil { + r.drops = map[string]chan struct{}{} + } + if r.drops[session] == nil { + r.drops[session] = make(chan struct{}) + } + return r.drops[session] +} + +// broken reports whether the connection of session broke. It runs under r.mu. +func (r *remoteHostRuns) broken(session string) bool { + select { + case <-r.dropped(session): + return true + default: + return false + } +} + +// breakConnection breaks the SSH connection of session under the host's processes: the requests +// over it end with a closed connection, as Core's do, and so does every later one. +func (k *remoteHostKernel) breakConnection(session string) { + r := &k.runs + r.mu.Lock() + defer r.mu.Unlock() + if !r.broken(session) { + close(r.dropped(session)) + } +} + +// heldProcess waits for a held process to end: SIGTERM through signalled, a broken connection +// through drop, or its request through ctx. +func heldProcess(ctx context.Context, signalled, drop <-chan struct{}) (core.RemoteProcessExit, error) { + select { + case <-signalled: + signal := 15 + return core.RemoteProcessExit{Signal: &signal}, nil + case <-drop: + return core.RemoteProcessExit{}, remoteTestConnectionClosed + case <-ctx.Done(): + return core.RemoteProcessExit{}, ctx.Err() + } } // remoteHostRunOutput is what a host process prints. @@ -114,7 +178,7 @@ func (k *remoteHostKernel) RemoteRunProcess(ctx context.Context, session string, if written { r.scripts = append(r.scripts, script) } - exit, hold, signalled, ended := r.exit, r.hold, r.signalled, r.ended + exit, hold, signalled, ended, drop := r.exit, r.hold, r.signalled, r.ended, r.dropped(session) r.mu.Unlock() if ended != nil { defer close(ended) @@ -124,19 +188,40 @@ func (k *remoteHostKernel) RemoteRunProcess(ctx context.Context, session string, if !hold { return exit, nil } - select { - case <-signalled: - signal := 15 - return core.RemoteProcessExit{Signal: &signal}, nil - case <-ctx.Done(): - return core.RemoteProcessExit{}, ctx.Err() + return heldProcess(ctx, signalled, drop) +} + +func (k *remoteHostKernel) RemoteAttachProcess(ctx context.Context, session string, processID uint64, events core.RemoteProcessEvents) (core.RemoteProcessExit, error) { + r := &k.runs + r.mu.Lock() + r.attaches = append(r.attaches, session) + exit, hold, signalled, drop, truncated, err := r.exit, r.hold, r.signalled, r.dropped(session), r.attachTruncated, r.attachErr + output := cmp.Or(r.attachOutput, remoteHostAttachOutput) + broken := r.broken(session) + r.mu.Unlock() + switch { + case broken: + return core.RemoteProcessExit{}, remoteTestConnectionClosed + case err != nil: + return core.RemoteProcessExit{}, err + case processID != 7: + return core.RemoteProcessExit{}, &core.Error{Command: "remote.attachProcess", Code: core.CodeRemoteProcessGone, Message: "gone"} + } + events.Attached(truncated) + events.Output("stdout", []byte(output)) + if !hold { + return exit, nil } + return heldProcess(ctx, signalled, drop) } -func (k *remoteHostKernel) RemoteProcessKill(_ context.Context, _ string, processID uint64, force bool) error { +func (k *remoteHostKernel) RemoteProcessKill(_ context.Context, session string, processID uint64, force bool) error { r := &k.runs r.mu.Lock() defer r.mu.Unlock() + if r.broken(session) { + return remoteTestConnectionClosed + } if processID != 7 { return nil } @@ -174,7 +259,14 @@ var remoteTestRunConfiguration = core.RunConfiguration{ID: "greet", Name: "Greet // 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) + h, k, _, p, logger := openRemoteRunProjectTimed(t) + return h, k, p, logger +} + +// openRemoteRunProjectTimed is openRemoteRunProject that also gives the workspace's timers. +func openRemoteRunProjectTimed(t *testing.T) (*harness, *remoteHostKernel, *remoteTimers, *project, *treeRecordingLog) { + t.Helper() + h, k, timers, logger := remoteWorkspaceHarness(t) k.setRuns(func(r *remoteHostRuns) { r.configurations = []core.RunConfiguration{remoteTestRunConfiguration} zero := 0 @@ -192,7 +284,53 @@ func openRemoteRunProject(t *testing.T) (*harness, *remoteHostKernel, *project, 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 + return h, k, timers, p, logger +} + +// startHeldRemoteRun starts the configuration with a process that runs until it is signalled and +// waits until the run has it. +func (h *harness) startHeldRemoteRun(k *remoteHostKernel, p *project) *buildOperation { + h.t.Helper() + k.setRuns(func(r *remoteHostRuns) { r.hold, r.signalled = true, make(chan struct{}) }) + h.startRemoteRun(p, remoteTestRunConfiguration.ID) + var op *buildOperation + h.await("the held run to start", func() bool { + op = p.build.runOf(configurationRunKey(remoteTestRunConfiguration.ID)) + return op != nil && op.process != nil + }) + return op +} + +// breakRunConnection breaks the connection of the workspace's session under op's process and +// waits until op's console says it waits for the workspace to connect again. +func (h *harness) breakRunConnection(k *remoteHostKernel, p *project, op *buildOperation) { + h.t.Helper() + waiting := i18n.Shared(h.app.language(), "desktop.run.remote.waiting") + k.breakConnection(p.remote.session) + h.await("the run to wait for the connection", func() bool { return strings.Contains(op.session.output.all(), waiting) }) +} + +// reconnectWhileRunning runs the pause before the first attempt to connect again, as +// fireReconnect does, and waits for the new session without waiting for every background task: +// a run that waits for the connection is one until the session comes. +func (h *harness) reconnectWhileRunning(t *testing.T, timers *remoteTimers, r *remoteProject) { + t.Helper() + h.await("the pause before connecting again", func() bool { + return r.session == "" && len(r.delays) > 0 && r.attempt == 0 && timers.live() == 1 + }) + timer := timers.take(t) + if timer.after != time.Second { + t.Fatalf("paused %v before connecting again, want Core's first pause of 1s", timer.after) + } + timer.run() + h.await("the new session", func() bool { return r.session != "" }) +} + +// remoteAttaches are the sessions remote.attachProcess went over. +func (k *remoteHostKernel) remoteAttaches() []string { + k.runs.mu.Lock() + defer k.runs.mu.Unlock() + return slices.Clone(k.runs.attaches) } // startRemoteRun starts the configuration as the title bar's Run does, without the trust @@ -326,6 +464,117 @@ func TestRemoteWorkspaceRunEndsAsTheHostProcessEnds(t *testing.T) { sessionKept(t, logger, p, p.remote.session) } +// A run whose connection breaks waits in its console for the workspace to connect again. When the +// workspace resumes the host session, the run receives its process again over the new session, +// says so, says the output the host could not keep is lost, and goes on until the process exits; +// the host's temporary folder is then removed over the new session. Neither the host nor its paths +// are logged. +func TestRemoteWorkspaceRunFollowsItsProcessAcrossAReconnection(t *testing.T) { + h, k, timers, p, logger := openRemoteRunProjectTimed(t) + lang := h.app.language() + k.set(func(k *remoteHostKernel) { k.close.resumable = true }) + op := h.startHeldRemoteRun(k, p) + k.setRuns(func(r *remoteHostRuns) { r.hold, r.attachTruncated = false, true }) + h.breakRunConnection(k, p, op) + if op.cancelled || p.build.runOf(configurationRunKey(remoteTestRunConfiguration.ID)) != op { + t.Fatal("the broken connection ended the run") + } + h.reconnectWhileRunning(t, timers, p.remote) + run := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, nil) + console := run.output.all() + if run.outcome != runSucceeded { + t.Fatalf("the run ended %v: %s; console:\n%s", run.outcome, run.summary, console) + } + at := -1 + for _, want := range []string{ + remoteHostRunOutput, + i18n.Shared(lang, "desktop.run.remote.waiting"), + i18n.Shared(lang, "desktop.run.remote.resumed"), + i18n.Shared(lang, "desktop.run.remote.outputLost"), + remoteHostAttachOutput, + } { + next := strings.Index(console, want) + if next <= at { + t.Fatalf("the console does not continue with %q:\n%s", want, console) + } + at = next + } + if got := k.remoteAttaches(); !slices.Equal(got, []string{"session-2"}) || p.remote.session != "session-2" { + t.Fatalf("received the process again %d times, over the new session %v", len(got), slices.Equal(got, []string{"session-2"})) + } + if _, _, _, removed, _ := k.hostRuns(); len(removed) != 1 || removed[0] != remoteTestRunScratch { + t.Fatalf("the host's temporary folder was removed %d times", len(removed)) + } + if event := loggedAny(t, logger, remoteTestHost, remoteTestHome); event != "" { + t.Fatalf("logged the host or its paths: %s", event) + } +} + +// A run whose process cannot be received after the connection broke fails with why: the +// workspace connected to a new host session, the host no longer has the process, or another +// window receives it. +func TestRemoteWorkspaceRunEndsWhenItsProcessCannotBeReceivedAgain(t *testing.T) { + for _, c := range []struct { + name string + resumable bool + refusal core.ErrorCode + want string + }{ + {name: "new session", want: "desktop.run.remote.sessionEnded"}, + {name: "process gone", resumable: true, refusal: core.CodeRemoteProcessGone, want: "desktop.run.remote.processGone"}, + {name: "received elsewhere", resumable: true, refusal: core.CodeRemoteProcessAttached, want: "desktop.run.remote.attachedElsewhere"}, + } { + t.Run(c.name, func(t *testing.T) { + h, k, timers, p, _ := openRemoteRunProjectTimed(t) + k.set(func(k *remoteHostKernel) { k.close.resumable = c.resumable }) + if c.refusal != "" { + k.setRuns(func(r *remoteHostRuns) { + r.attachErr = &core.Error{Command: "remote.attachProcess", Code: c.refusal, Message: "refused"} + }) + } + op := h.startHeldRemoteRun(k, p) + h.breakRunConnection(k, p, op) + h.reconnectWhileRunning(t, timers, p.remote) + run := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, nil) + if want := h.app.text.Build.ProcessFailed(i18n.Shared(h.app.language(), c.want)); run.outcome != runFailed || run.summary != want { + t.Fatalf("the run ended %v: %q, want %q", run.outcome, run.summary, want) + } + if attaches := k.remoteAttaches(); (len(attaches) == 1) != c.resumable { + t.Fatalf("asked the host for the process %d times", len(attaches)) + } + }) + } +} + +// Stopping a run while its connection is broken ends the run at once; the host, which could not +// be asked, kills the process once the workspace resumes the host session. The stop the broken +// connection refused is not logged as a failure. +func TestRemoteWorkspaceRunStoppedWhileDisconnectedEndsOnceReconnected(t *testing.T) { + previous := buildprocess.StopGrace() + t.Cleanup(func() { buildprocess.SetStopGrace(previous) }) + buildprocess.SetStopGrace(8 * time.Second) + h, k, timers, p, logger := openRemoteRunProjectTimed(t) + k.set(func(k *remoteHostKernel) { k.close.resumable = true }) + op := h.startHeldRemoteRun(k, p) + h.breakRunConnection(k, p, op) + h.app.post(func(a *App) { a.stopOperation(p, op) }) + stopped := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, nil) + if stopped.outcome == runSucceeded { + t.Fatal("a stopped run ended as succeeded") + } + if _, _, _, _, kills := k.hostRuns(); len(kills) != 0 { + t.Fatalf("sent %d signals over the broken connection", len(kills)) + } + h.reconnectWhileRunning(t, timers, p.remote) + h.await("the stopped run's process to be killed", func() bool { + _, _, _, _, kills := k.hostRuns() + return slices.Equal(kills, []string{"kill"}) + }) + if n := countFailures(logger, "run_stop") + countFailures(logger, "run_stop_after_reconnect"); n != 0 || len(k.remoteAttaches()) != 0 { + t.Fatalf("logged %d stop failures, received the process again %d times", n, len(k.remoteAttaches())) + } +} + // 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. diff --git a/desktop/internal/workbench/remote_run_visual_test.go b/desktop/internal/workbench/remote_run_visual_test.go index e8caba701..e6104b86b 100644 --- a/desktop/internal/workbench/remote_run_visual_test.go +++ b/desktop/internal/workbench/remote_run_visual_test.go @@ -19,7 +19,10 @@ import ( // 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. +// configuration menu, which says build tools do not run in a remote workspace yet. Then the +// connection breaks while the configuration runs again: the tab waits for the workspace to connect +// again, and once the workspace resumes the host session it goes on with the process's output, +// after a line that says some of it was lost. func TestVisualRemoteRun(t *testing.T) { out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") if out == "" { @@ -70,6 +73,19 @@ func TestVisualRemoteRun(t *testing.T) { t.Fatal(err) } } + // shotRunning is shot while a run waits on the host, which settle would wait for. + shotRunning := func(scene string) { + t.Helper() + h.app.invalidator.Invalidate() + for range 3 { + if err := h.driver.Pump(); err != nil { + t.Fatal(err) + } + } + 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) { @@ -116,6 +132,25 @@ func TestVisualRemoteRun(t *testing.T) { t.Fatal("the run configuration menu did not open") } shot("menu") + h.app.title.runConfigOpen = false + + // Greet runs again, without its step, and the connection breaks while it runs. + kernel.set(func(k *remoteHostKernel) { k.close.resumable = true }) + kernel.setRuns(func(r *remoteHostRuns) { + r.steps = nil + r.attachTruncated = true + r.attachOutput = "hello again from the host\n" + }) + op := h.startHeldRemoteRun(kernel, p) + h.breakRunConnection(kernel, p, op) + shotRunning("waiting") + kernel.setRuns(func(r *remoteHostRuns) { r.hold = false }) + h.reconnectWhileRunning(t, timers, p.remote) + again := h.awaitRemoteRun(p, remoteTestRunConfiguration.Name, run) + if again.outcome != runSucceeded { + t.Fatalf("the run ended %v after the reconnection", again.outcome) + } + shot("resumed") }) } } diff --git a/desktop/internal/workbench/remote_workspace.go b/desktop/internal/workbench/remote_workspace.go index 7be4fa431..e2a874ebf 100644 --- a/desktop/internal/workbench/remote_workspace.go +++ b/desktop/internal/workbench/remote_workspace.go @@ -4,6 +4,7 @@ import ( "context" "errors" "path" + "sync/atomic" "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" @@ -121,10 +122,26 @@ type remoteProject struct { ports remotePorts // hostFiles is Open File on Host's state (remote_host_files.go). hostFiles remoteHostFiles + // live is session with its host session (remoteSessionRef), nil while there is none; runs + // read it off the window thread (remoteProject.current). + live atomic.Pointer[remoteSessionRef] + // rejoins are the runs waiting, after their connection was lost, for the session that + // replaces it; abandoned are the host processes of runs that ended meanwhile (remote_run.go). + rejoins []chan<- remoteSessionRef + abandoned []remoteAbandoned // closed is set once the project closes; nothing of the workspace runs afterwards. closed bool } +// current is the workspace's session with its host session, safe from any goroutine; the zero +// value while there is none. +func (r *remoteProject) current() remoteSessionRef { + if live := r.live.Load(); live != nil { + return *live + } + return remoteSessionRef{} +} + // remoteTarget is a host folder to open as a workspace over a connected session. type remoteTarget struct { connectionID string @@ -313,6 +330,11 @@ func (a *App) attachRemote(p *project, session core.RemoteSession) { r.session, r.link, r.attempt, r.misses, r.failure = session.ID, remoteConnected, 0, 0, nil r.resume = session.Resume() r.binding.Attach(session.ID) + key := "" + if r.resume != nil { + key = r.resume.Key + } + r.live.Store(&remoteSessionRef{id: session.ID, key: key}) a.beatRemote(p) r.watchWait = remoteWatchReady a.startRemoteWatch(p) @@ -320,6 +342,8 @@ func (a *App) attachRemote(p *project, session core.RemoteSession) { // The Ports window reads its records and restores the forwards left running. r.ports.recordsAttach = true a.syncRemotePorts(p) + // Runs that waited for the connection receive their processes again. + a.rejoinRemoteRuns(p) } // beatRemote asks the server of the workspace's session what still runs, and schedules the next @@ -379,6 +403,7 @@ func (a *App) loseRemote(p *project, session string, err error) { r.ports.reset() r.session, r.misses = "", 0 r.binding.Detach() + r.live.Store(nil) r.stopRemoteTimer() a.releaseRemoteSession(session) a.startRemoteReconnection(p) @@ -526,6 +551,8 @@ func (a *App) closeRemoteWorkspace(p *project) { r.reconnecting = nil } r.binding.Detach() + r.live.Store(nil) + r.closeRemoteRuns() a.releaseRemoteSession(r.session) r.session, r.resume, r.menuOpen = "", nil, false } diff --git a/desktop/internal/workbench/remote_workspace_test.go b/desktop/internal/workbench/remote_workspace_test.go index 531eb43bc..0853e6db8 100644 --- a/desktop/internal/workbench/remote_workspace_test.go +++ b/desktop/internal/workbench/remote_workspace_test.go @@ -107,6 +107,9 @@ type remoteHostClose struct { // close a session it was asked to keep. kept map[string][]core.RemoteProgram refuseKeep bool + // resumable makes the host keep every session whose connection broke, so presenting its token + // resumes it with its programs. + resumable bool // resumes are what each SSH connection presented, nil for nothing. resumes []*core.RemoteResume // ended are the programs each request to end some named. @@ -126,6 +129,8 @@ func (c *remoteHostClose) session(n int, resume *core.RemoteResume) *core.Remote if kept, ok := c.kept[resume.Key]; ok { delete(c.kept, resume.Key) session.SessionKey, session.Resumed, session.KeptPrograms = resume.Key, true, kept + } else if c.resumable { + session.SessionKey, session.Resumed = resume.Key, true } } token := "token-" + strings.TrimPrefix(session.SessionKey, "key-") diff --git a/desktop/internal/workbench/runconfig_before_launch.go b/desktop/internal/workbench/runconfig_before_launch.go index 295f5bceb..8150932f0 100644 --- a/desktop/internal/workbench/runconfig_before_launch.go +++ b/desktop/internal/workbench/runconfig_before_launch.go @@ -167,11 +167,8 @@ func (a *App) runBeforeLaunchSteps(p *project, op *buildOperation, steps []core. } } 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), - } + host := a.remoteRunHostOf(p, op) + run.remote = &host } a.background(p, 0, func(ctx context.Context) func(*App) { if run.remote != nil { diff --git a/docs/assets/remote-close/README.md b/docs/assets/remote-close/README.md index 2ee9f3fdc..017cc2522 100644 --- a/docs/assets/remote-close/README.md +++ b/docs/assets/remote-close/README.md @@ -4,7 +4,8 @@ - 关闭窗口时,只要主机上还有 Lithe 启动的进程就先问:标题“关闭远程工作区?”,正文列出每个进程的类型、名称、命令(原样显示,不脱敏)和已运行时长;按钮依次是“取消”“保留在远端并关闭”“结束并关闭”(默认);“记住我的选择”旁的 ⓘ 说明之后不再询问、可在 设置 › 工具 › 远程工作区 中修改; - 选“保留在远端并关闭”后,欢迎页通知“N 个进程保留在 <连接名> 上”; -- 下次连接同一主机并打开文件夹时,接上被保留的会话,列出上次保留的进程,可以“结束这些进程”(只结束它们,不动这次新开的)或“继续运行”。 +- 下次连接同一主机并打开文件夹时,接上被保留的会话,列出上次保留的进程,可以“结束这些进程”(只结束它们,不动这次新开的)、“在运行窗口中接回”或“继续运行”;列表里有终端时说明终端无法接回; +- 选“在运行窗口中接回”后,每个保留的进程在 Run 窗口里各开一个带“主机”徽标的标签页,显示接回后的输出,进程继续运行。 截图不代表 macOS/Windows 原生窗口验收,也不代表真实 SSH 主机上的整机验收。 @@ -16,3 +17,4 @@ | 关闭时询问 | [浅色英文](remote-close-question-light-en-US.png) | [深色中文](remote-close-question-dark-zh-CN.png) | | 保留后的通知 | [浅色英文](remote-close-kept-light-en-US.png) | [深色中文](remote-close-kept-dark-zh-CN.png) | | 下次连接列出保留的进程 | [浅色英文](remote-close-offer-light-en-US.png) | [深色中文](remote-close-offer-dark-zh-CN.png) | +| 在运行窗口中接回 | [浅色英文](remote-close-attached-light-en-US.png) | [深色中文](remote-close-attached-dark-zh-CN.png) | diff --git a/docs/assets/remote-close/remote-close-attached-dark-zh-CN.png b/docs/assets/remote-close/remote-close-attached-dark-zh-CN.png new file mode 100644 index 000000000..995dfef2f Binary files /dev/null and b/docs/assets/remote-close/remote-close-attached-dark-zh-CN.png differ diff --git a/docs/assets/remote-close/remote-close-attached-light-en-US.png b/docs/assets/remote-close/remote-close-attached-light-en-US.png new file mode 100644 index 000000000..59dcf8a61 Binary files /dev/null and b/docs/assets/remote-close/remote-close-attached-light-en-US.png differ diff --git a/docs/assets/remote-close/remote-close-offer-dark-zh-CN.png b/docs/assets/remote-close/remote-close-offer-dark-zh-CN.png index 3abd79a5e..840997799 100644 Binary files a/docs/assets/remote-close/remote-close-offer-dark-zh-CN.png and b/docs/assets/remote-close/remote-close-offer-dark-zh-CN.png differ diff --git a/docs/assets/remote-close/remote-close-offer-light-en-US.png b/docs/assets/remote-close/remote-close-offer-light-en-US.png index 667cdd14e..ad33c75c1 100644 Binary files a/docs/assets/remote-close/remote-close-offer-light-en-US.png and b/docs/assets/remote-close/remote-close-offer-light-en-US.png differ diff --git a/docs/assets/remote-close/remote-close-question-dark-zh-CN.png b/docs/assets/remote-close/remote-close-question-dark-zh-CN.png index 39c04daf9..dda519693 100644 Binary files a/docs/assets/remote-close/remote-close-question-dark-zh-CN.png and b/docs/assets/remote-close/remote-close-question-dark-zh-CN.png differ diff --git a/docs/assets/remote-run/README.md b/docs/assets/remote-run/README.md index 0c9db9f66..9c06f2801 100644 --- a/docs/assets/remote-run/README.md +++ b/docs/assets/remote-run/README.md @@ -1,10 +1,12 @@ -# 远程工作区在主机上运行(#2231 R1,#43a、#43b)无头测试截图 +# 远程工作区在主机上运行(#2231 R1,#43a、#43b、#43c)无头测试截图 来自生产 Viva Page 的无头渲染。连接、主机和运行配置都由测试替身提供,不连接真实主机、不启动真实进程。截图覆盖深色中文和浅色英文界面,用于确认: - 远程工作区里内置的运行配置在主机上运行后,Run 窗口的标签页带“主机”徽标,控制台显示主机进程的输出和退出码; - “执行前”列表里的另一个内置运行配置(Prepare)先在主机上运行,控制台先显示步骤标题和它的输出,再显示配置本身的输出; - 标题栏的运行配置菜单列出内置配置,并用一行不可点的说明告诉用户构建工具和插件运行暂不在远程工作区里工作。 +- 运行中和主机的连接断开时,标签页仍是运行中,控制台另起一行说明正在等待重新连接,状态栏显示正在重新连接; +- 重新连接接上原来的会话后,控制台说明已接上运行中的程序、断线期间部分输出已丢失,接着显示之后的输出和退出码。 截图不代表 macOS/Windows 原生窗口验收。 @@ -12,6 +14,8 @@ | --- | --- | --- | | 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) | +| 断线等待重新连接 | [深色中文](remote-run-waiting-dark-zh-CN.png) | [浅色英文](remote-run-waiting-light-en-US.png) | +| 重新连接后接着输出 | [深色中文](remote-run-resumed-dark-zh-CN.png) | [浅色英文](remote-run-resumed-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 index 8f53ed89a..c5ae6e741 100644 Binary files a/docs/assets/remote-run/remote-run-console-dark-zh-CN.png 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 index 7c03493ea..db24cffe7 100644 Binary files a/docs/assets/remote-run/remote-run-console-light-en-US.png 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 index 9c295d82d..dd715dad2 100644 Binary files a/docs/assets/remote-run/remote-run-menu-dark-zh-CN.png 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 index 6de59b285..ec9c0ce61 100644 Binary files a/docs/assets/remote-run/remote-run-menu-light-en-US.png and b/docs/assets/remote-run/remote-run-menu-light-en-US.png differ diff --git a/docs/assets/remote-run/remote-run-resumed-dark-zh-CN.png b/docs/assets/remote-run/remote-run-resumed-dark-zh-CN.png new file mode 100644 index 000000000..002852908 Binary files /dev/null and b/docs/assets/remote-run/remote-run-resumed-dark-zh-CN.png differ diff --git a/docs/assets/remote-run/remote-run-resumed-light-en-US.png b/docs/assets/remote-run/remote-run-resumed-light-en-US.png new file mode 100644 index 000000000..abc41b5c7 Binary files /dev/null and b/docs/assets/remote-run/remote-run-resumed-light-en-US.png differ diff --git a/docs/assets/remote-run/remote-run-waiting-dark-zh-CN.png b/docs/assets/remote-run/remote-run-waiting-dark-zh-CN.png new file mode 100644 index 000000000..cff378946 Binary files /dev/null and b/docs/assets/remote-run/remote-run-waiting-dark-zh-CN.png differ diff --git a/docs/assets/remote-run/remote-run-waiting-light-en-US.png b/docs/assets/remote-run/remote-run-waiting-light-en-US.png new file mode 100644 index 000000000..9ced83af1 Binary files /dev/null and b/docs/assets/remote-run/remote-run-waiting-light-en-US.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index 0c51463b8..ecb0137e8 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -339,7 +339,7 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # Lithe-core-rust main at 2e4be2c: #166 a connection accepts a Windows domain user (DOMAIN\name, # name@domain) and remote.mottyHosts marks a refused setting on its own field with the invalid # status; #165 ending a remote session releases the search indexes it built (#2231, #2277). -PINNED_CORE_REVISION="2e4be2ca23bd8ba83bea93278067b566a7194ead" +PINNED_CORE_REVISION="18feb4af3cfbf86eaad978ad92fb0593ce96ca3c" 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 b9f08d365..a49da7d18 100644 --- a/shared/i18n/features/remote-connections.json +++ b/shared/i18n/features/remote-connections.json @@ -1269,6 +1269,30 @@ "connection": "string" } }, + { + "id": "desktop.remote.kept.attach", + "description": "Question after connecting to a kept host session: button that shows the kept processes again in the Run window, each in a tab of its own", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.kept.attachTerminals", + "description": "Question after connecting to a kept host session: note under the list when some kept programs are terminals, which cannot be shown again", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.kept.attachFailed", + "description": "Notification: the kept processes could not be shown again because the workspace is not connected to their host session; {connection} is the connection's name", + "platforms": [ + "desktop" + ], + "parameters": { + "connection": "string" + } + }, { "id": "desktop.remote.worktree.connectionRemoved", "description": "Remote Development window: error when a worktree of a remote workspace is opened but the saved connection the workspace was opened over was deleted", @@ -1356,6 +1380,55 @@ "desktop" ] }, + { + "id": "desktop.run.remote.attachedKept", + "description": "Run console line at the start of a tab that shows again a process an earlier window kept running on the host", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.waiting", + "description": "Run console line: the connection to the host broke while a program ran there, and the tab waits for the workspace to reconnect", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.resumed", + "description": "Run console line: the workspace reconnected and the program's output continues", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.outputLost", + "description": "Run console line: some of what the program wrote while nothing received it is missing", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.sessionEnded", + "description": "Run failure: the workspace reconnected to a new host session, so the earlier session's program cannot be shown again", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.processGone", + "description": "Run failure: the host no longer has the program, or its output can no longer be received", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.run.remote.attachedElsewhere", + "description": "Run failure: another window already shows the program's output", + "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", @@ -3514,6 +3587,13 @@ "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.run.remote.attachedKept": "Showing again a program a closed window kept running on the host.", + "desktop.run.remote.waiting": "The connection to the host broke. Waiting to reconnect…", + "desktop.run.remote.resumed": "Reconnected; the output continues.", + "desktop.run.remote.outputLost": "Some output was lost while nothing received it.", + "desktop.run.remote.sessionEnded": "the workspace reconnected to a new host session; the program of the earlier session cannot be shown again", + "desktop.run.remote.processGone": "the host no longer has the program, or its output can no longer be received", + "desktop.run.remote.attachedElsewhere": "another window already shows this program's output", "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", @@ -3584,6 +3664,9 @@ "desktop.remote.kept.keep": "Keep Running", "desktop.remote.kept.ended": "Ended programs on {connection}: {count}", "desktop.remote.kept.endFailed": "Could not end the programs kept on {connection}.", + "desktop.remote.kept.attach": "Show in Run Window", + "desktop.remote.kept.attachTerminals": "Terminals cannot be shown again; they keep running until you end them.", + "desktop.remote.kept.attachFailed": "Could not show the programs kept on {connection}: the workspace is not connected to the host session that runs them.", "desktop.remote.container.heading": "Containers", "desktop.remote.container.kind": "Container", "desktop.remote.container.docker": "Docker", @@ -3934,6 +4017,13 @@ "desktop.run.remote.unsupported": "远程工作区只在主机上运行程序和脚本运行配置,暂不支持调试", "desktop.run.remote.badge": "主机", "desktop.run.remote.badgeHelp": "此程序运行在远程工作区的主机上。", + "desktop.run.remote.attachedKept": "已接回上次关闭时保留在主机上运行的进程。", + "desktop.run.remote.waiting": "与主机的连接断开了,正在等待重新连接…", + "desktop.run.remote.resumed": "已重新连接,输出继续。", + "desktop.run.remote.outputLost": "部分输出已丢失:没有接收方期间程序写出的内容没能全部保留。", + "desktop.run.remote.sessionEnded": "工作区重新连接到了新的主机会话,无法再接回之前会话里的程序", + "desktop.run.remote.processGone": "主机上已没有这个程序,或已无法再接收它的输出", + "desktop.run.remote.attachedElsewhere": "另一个窗口已在显示这个程序的输出", "desktop.remote.document.disconnected": "远程工作区未连接,请在重新连接后再试", "desktop.remote.document.timedOut": "主机没有及时响应", "desktop.remote.document.notFound": "主机上已没有这个文件", @@ -4004,6 +4094,9 @@ "desktop.remote.kept.keep": "继续运行", "desktop.remote.kept.ended": "已结束 {connection} 上的 {count} 个进程", "desktop.remote.kept.endFailed": "无法结束 {connection} 上保留的进程。", + "desktop.remote.kept.attach": "在运行窗口中接回", + "desktop.remote.kept.attachTerminals": "终端无法接回,会一直运行,直到你结束它们。", + "desktop.remote.kept.attachFailed": "无法接回 {connection} 上保留的进程:工作区没有连接到运行它们的主机会话。", "desktop.remote.container.heading": "容器", "desktop.remote.container.kind": "容器", "desktop.remote.container.docker": "Docker", diff --git a/shared/platform-feature-matrix/features/remote-workspace.json b/shared/platform-feature-matrix/features/remote-workspace.json index d028f6a20..d23f9b5cb 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", @@ -152,7 +152,7 @@ ] }, "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 上限时说明上限;状态栏显示已转发数量,点击打开端口窗口;会话结束时转发随之结束;重连或重新打开工作区后,用户没停的本机转发按记住的本机端口和确认自动重新转发,没能重新转发的行标为失败并给出 Core 的原因,窗口说明有几个没能恢复。日志只记 remote.ports.forward/localPort/move/stop/status 等动作和失败操作名,不含主机、地址或进程名。运行 remote_ports_test.go 的 12 个测试、internal/core 的 TestRemoteSessionCommandsOfAnUnknownSession 与 TestRemoteParseForwardAddressReadsPortsAndURLs,以及 TestVisualRemotePorts 无头截图。手动添加的端口、本机端口选择、行和规则的标签(右键“编辑标签…”,标签列显示,最多 64 个字符,不能含控制字符,留空即删除)、没停的本机转发和启动过的规则,按连接目标和主机上工作区的真实路径记在本机偏好目录的 remote/ports.json(Core 的 remote.portRecords、remote.editPortRecords、remote.restoreForwards),不写主机、工作区、应用包或安装目录;文件无法解析时窗口说明且从不覆盖,之后的修改只留在内存。端口窗口标题栏的“+”打开“添加转发规则”:方向默认“主机端口 → 另一台服务器”,由主机自己连接目标,数据不经过本机;主机端口可留空由主机选择,目标接受端口、主机:端口或网址(由 Core 的 remote.parseForwardAddress 解析,网址里带用户名或密码时拒绝)。规则默认只在主机的回环地址 127.0.0.1 上监听;勾选“监听主机的全部网卡”时显示警告,每次添加都再次询问、不记住,列表里的监听地址用警告色显示并在悬停提示里说明;目标不是主机自身的回环地址时先询问(S28)。“主机端口 → 本机(反向转发)”只在 设置 › 工具 › 远程工作区 的“反向转发”允许时提供(默认自动,即不允许,对话框说明在哪里开启),每条都询问,主机只在回环地址监听,本机只连接回环地址上的端口。主机端口被占用、主机不允许监听(如 1024 以下)、远端服务不支持、达到会话转发上限(与本机转发合计)、反向转发未被允许分别说明原因,主机端口不是 1–65535 时就地说明,对话框保留输入。端口窗口的“转发规则”一节列出主机监听地址、转到的目标(反向转发为“本机 地址”)、连接数(有失败时注明失败数)和状态,每行可停止,标题栏的全部停止同样停止规则;规则随会话结束而停止,重连或重新打开后列为“未运行”,从不自动启动:行尾“启动”把规则填进“添加转发规则”由用户再提交,“忘记”删除记录;监听全部网卡从不记住,再启动时按回环地址填入,要全部网卡须重新勾选并确认(S27)。日志只记 remote.ports.addRule/ruleHost/ruleReverse/ruleConfirm/stopRule 等动作和失败的操作名,不含地址、网址或进程名。运行 remote_port_rules_test.go 的 5 个测试、remote_port_records_test.go 的 3 个测试、remoteconn/ports_test.go、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。列表里有插件提供的任务时说明远程工作区暂不支持插件任务,请从“执行前”列表删除后再运行。构建工具、插件提供的运行和调试在远程工作区说明暂不支持。", + "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 上限时说明上限;状态栏显示已转发数量,点击打开端口窗口;会话结束时转发随之结束;重连或重新打开工作区后,用户没停的本机转发按记住的本机端口和确认自动重新转发,没能重新转发的行标为失败并给出 Core 的原因,窗口说明有几个没能恢复。日志只记 remote.ports.forward/localPort/move/stop/status 等动作和失败操作名,不含主机、地址或进程名。运行 remote_ports_test.go 的 12 个测试、internal/core 的 TestRemoteSessionCommandsOfAnUnknownSession 与 TestRemoteParseForwardAddressReadsPortsAndURLs,以及 TestVisualRemotePorts 无头截图。手动添加的端口、本机端口选择、行和规则的标签(右键“编辑标签…”,标签列显示,最多 64 个字符,不能含控制字符,留空即删除)、没停的本机转发和启动过的规则,按连接目标和主机上工作区的真实路径记在本机偏好目录的 remote/ports.json(Core 的 remote.portRecords、remote.editPortRecords、remote.restoreForwards),不写主机、工作区、应用包或安装目录;文件无法解析时窗口说明且从不覆盖,之后的修改只留在内存。端口窗口标题栏的“+”打开“添加转发规则”:方向默认“主机端口 → 另一台服务器”,由主机自己连接目标,数据不经过本机;主机端口可留空由主机选择,目标接受端口、主机:端口或网址(由 Core 的 remote.parseForwardAddress 解析,网址里带用户名或密码时拒绝)。规则默认只在主机的回环地址 127.0.0.1 上监听;勾选“监听主机的全部网卡”时显示警告,每次添加都再次询问、不记住,列表里的监听地址用警告色显示并在悬停提示里说明;目标不是主机自身的回环地址时先询问(S28)。“主机端口 → 本机(反向转发)”只在 设置 › 工具 › 远程工作区 的“反向转发”允许时提供(默认自动,即不允许,对话框说明在哪里开启),每条都询问,主机只在回环地址监听,本机只连接回环地址上的端口。主机端口被占用、主机不允许监听(如 1024 以下)、远端服务不支持、达到会话转发上限(与本机转发合计)、反向转发未被允许分别说明原因,主机端口不是 1–65535 时就地说明,对话框保留输入。端口窗口的“转发规则”一节列出主机监听地址、转到的目标(反向转发为“本机 地址”)、连接数(有失败时注明失败数)和状态,每行可停止,标题栏的全部停止同样停止规则;规则随会话结束而停止,重连或重新打开后列为“未运行”,从不自动启动:行尾“启动”把规则填进“添加转发规则”由用户再提交,“忘记”删除记录;监听全部网卡从不记住,再启动时按回环地址填入,要全部网卡须重新勾选并确认(S27)。日志只记 remote.ports.addRule/ruleHost/ruleReverse/ruleConfirm/stopRule 等动作和失败的操作名,不含地址、网址或进程名。运行 remote_port_rules_test.go 的 5 个测试、remote_port_records_test.go 的 3 个测试、remoteconn/ports_test.go、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。列表里有插件提供的任务时说明远程工作区暂不支持插件任务,请从“执行前”列表删除后再运行。构建工具、插件提供的运行和调试在远程工作区说明暂不支持。运行中和主机的连接断开、主机保留会话时,运行不结束:Run 标签页仍是运行中,控制台另起一行说明正在等待重新连接;窗口重新连接到同一个主机会话后经 remote.attachProcess 接着接收输出,先说明已接上运行中的程序,丢了部分输出时说明部分输出已丢失,再显示之后的输出和退出码,可以多次断线;主机开了新会话、进程已不在主机上或另一个连接正在接收它时,运行结束并说明原因;等待期间按“停止”的运行在接上同一个主机会话后立即强制结束主机进程。下次连接列出的保留进程里有进程时多一个“在运行窗口中接回”,同时有终端时说明终端无法接回;选它后每个保留的进程在 Run 窗口里各开一个带“主机”徽标的标签页,显示接回后的输出,“停止”先发 SIGTERM,Run 窗口随之打开。运行 remote_run_test.go 的 TestRemoteWorkspaceRunFollowsItsProcessAcrossAReconnection、TestRemoteWorkspaceRunEndsWhenItsProcessCannotBeReceivedAgain、TestRemoteWorkspaceRunStoppedWhileDisconnectedEndsOnceReconnected,remote_close_test.go 的 TestRemoteCloseShowsTheKeptProcessesInTheRunWindow,以及 TestVisualRemoteRun、TestVisualRemoteClose 的断线等待、重连后接着输出、接回保留进程截图;真实 SSH 主机断网重连与 Windows WSL 上的验收仍待完成。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -189,5 +189,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 上的主机路径也是本机绝对路径。 运行配置在远程工作区由 Core 路由到主机(runConfig.*,计划按主机平台生成),桌面端用 remote.runProcess 启动内置的程序和脚本运行,输出经有界缓冲(8 MiB,超出丢弃最旧部分并提示)进入运行窗口;进程 id 不是本机的,不采样端口和资源。“执行前”列表里的内置运行配置步骤同样经 remote.runProcess 在主机上运行(各自的临时目录在下一步开始前删除,停止或超出准备时间先发 SIGTERM);插件任务步骤、构建工具、插件运行和调试要在本机插件后端计划主机上的进程(#2231 R3/R4),本阶段不做。 端口记录:文件由 Core 校验、按连接目标与主机上工作区的真实路径分组,桌面端只按读到的字节整体原子替换(configfile),与读到时不一致就重读后重试;桌面端把内存状态和上次写入的记录比较得出编辑,所以停止、移除、改标签和规则启停都只写变化的部分;remote.restoreForwards 在每次接上会话(打开、重连)时按行重新转发,失败的单独报告,其余照常启动,规则从不自动启动。日志不记主机、标签、端口或转发地址。" + "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),本阶段不做。 端口记录:文件由 Core 校验、按连接目标与主机上工作区的真实路径分组,桌面端只按读到的字节整体原子替换(configfile),与读到时不一致就重读后重试;桌面端把内存状态和上次写入的记录比较得出编辑,所以停止、移除、改标签和规则启停都只写变化的部分;remote.restoreForwards 在每次接上会话(打开、重连)时按行重新转发,失败的单独报告,其余照常启动,规则从不自动启动。日志不记主机、标签、端口或转发地址。 断线接回:Core 在连接断开后把会话里进程的事件停放在主机上,带 resume 接回同一个会话后,remote.attachProcess 从这次连接没收到的第一个事件开始转发,先发 process.attached(truncated 表示停放的事件超过上限),错误码 connection_closed、remote_process_gone、remote_process_attached 一一对应。桌面端 remoteRunHost.follow 只在主机已给出进程 id 且会话有主机会话键时等待重新连接,按主机会话键判断新会话是否接回了同一个会话;等待期间停止的运行把(主机会话键,进程 id)交给窗口,接上同一个主机会话后经 process.kill 强制结束。保留进程的接回用运行键 remote-attach:<进程 id>,同键运行已存在时不再开。进程名称、命令和输出不写日志。" }