diff --git a/.agents/notes/implemented/feature/2026-11-22-remote-local-containers.md b/.agents/notes/implemented/feature/2026-11-22-remote-local-containers.md new file mode 100644 index 000000000..5f772e774 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-11-22-remote-local-containers.md @@ -0,0 +1,104 @@ +# Agent 笔记:远程开发窗口——进入本机及主机上的容器,以及从 devcontainer.json 打开 + +状态:已实现 + +## 先说结论 + +“远程开发”窗口在已保存的连接和 WSL 发行版之后,以“容器”分组列出本机 Docker 和 Podman 正在运行的容器。选中一个容器、可选地填写容器内用户,点“连接”后,Core 用本机的 `docker exec -i` 或 `podman exec -i`(在正在运行的容器里执行一条命令)启动和 SSH 相同的远端服务。之后的文件夹选择、信任询问、工作区、心跳和重连都与 SSH、WSL 共用同一流程。容器不写入已保存的连接,打开过的文件夹也不记住;列表每次打开窗口时向引擎重新读取。 + +“从 devcontainer.json 打开…”选一个本机文件夹,经 Core 用官方 Dev Container CLI(`devcontainer up`)按它的 `devcontainer.json` 构建并启动容器,然后按上面的容器入口连接,直接打开 CLI 给出的工作区文件夹。构建会运行文件夹里的 Dockerfile、features 和命令,所以文件夹必须先受信任;CLI 的输出只显示在页面上,不写日志。 + +连上 SSH 主机或 WSL 发行版后,文件夹选择页标题栏的“主机上的容器”在文件夹的位置列出那台主机上正在运行的 Docker 和 Podman 容器。“进入容器”结束浏览会话,重新连接主机并经主机上的引擎进入容器,再在容器里选择文件夹。主机上的容器同样不保存:工作区身份是“已保存连接或发行版的身份/引擎:[用户@]容器”,打开过的文件夹不记入已保存的连接。 + +## 问题 + +Issue #2231 要求兼容 Dev Container(按 `devcontainer.json` 规范构建并运行的开发容器)。不管容器是谁建起来的,第一步都是“进入一个正在运行的容器并在里面打开文件夹”: + +- 容器的生命周期由 Docker、Podman 或 Dev Container CLI 管理,同名容器可以被删掉再建,内部 ID 会变; +- 进入容器不经过 OpenSSH,没有主机密钥、密码和 `ssh -G` 配置,SSH 的步骤、提示和“编辑连接”都不适用; +- 容器名、镜像名和容器内用户名都可能暴露项目信息,不能进日志; +- 测试会打开“远程开发”窗口,不能因此在开发者电脑上运行真的 `docker ps`(会唤起 OrbStack 等,慢且结果不确定)。 + +## 决策 + +### 容器进入规则在 Core,窗口只选择和展示 + +- Core #162 给 `remote.connect` 增加 `container: { engine, container, user? }`,单独出现时在本机执行 ` exec -i [-u 用户] 容器 …`;跟在 `connection` 或 `wsl` 后面时先登录那台主机再进入它上面的容器。会话身份为 `engine:[用户@]容器`,信任记录的键包含容器。 +- Core 只进入正在运行的容器:不启动、不创建、不改动容器,不挂载目录,不提权;不填用户时使用镜像的默认用户(S32)。 +- `remote.listContainers(engine, sessionId)` 在本机(`sessionId` 为空)或会话的主机上运行 ` ps`,最多 15 秒、256 个容器;没有该引擎时返回 `available: false`,引擎报错时返回只用于显示的诊断。 +- 桌面端的 `remoteHost` 由 SSH 连接或 WSL 发行版加可选的容器组成,三个判断各管一件事,不再让一个判断兼两种含义: + - `overSSH()`:经 OpenSSH 登录(SSH 连接,或 SSH 主机上的容器),决定是否发送 SSH 偏好、显示读取配置和身份验证步骤; + - `saved()`:就是一个已保存的 SSH 连接,决定是否提供“编辑连接”、记住打开过的文件夹; + - `hosted()`:主机上的容器,决定失败说明和“重试”的目标。 + +### 按名字连接,不保存 + +- 列表行的键是 `engine:完整 ID`,用于区分两个引擎里的同名容器;连接请求只发容器名,所以按同一个名字重建的容器(Dev Container 重建后就是这样)仍能用同一个标题、信任记录和窗口计数接上。 +- 容器不写入 `remote/connections.json`,打开过的文件夹不记入最近文件夹:容器随时会被删除,保存下来的条目大多会失效,而列表本来就每次从引擎读取。 + +### 一个引擎失败不影响另一个 + +窗口打开时在一个后台任务里依次列出 Docker 和 Podman。某个引擎超时或报错就跳过它,日志记一次 `remote_containers_list` 失败(只有命令名和错误码),另一个引擎的容器照常列出;两个引擎都没有时不显示“容器”分组。 + +### 失败说明用引擎自己的话 + +连接失败时步骤从“进入容器”开始;容器已停止、暂停或引擎没有应答时说明这几种可能,找不到引擎命令行时说明需要安装哪个引擎;不显示 SSH 的排查提示。引擎原始输出只显示在步骤下方,不写日志。Core 拒绝用户或容器名时,按字段给出原因。 + +### 日志只记动作 + +日志只有 `remote.container.select`、`remote.connect`、`remote.workspace.open` 等动作和失败的操作名,不含容器名、镜像、状态或用户名。 + +### 从 devcontainer.json 打开:用官方 CLI,Lithe 不加东西 + +- 构建交给官方 Dev Container CLI,不自己实现规范:规范里的 features、生命周期命令、`docker compose`、变量替换和镜像元数据合并都由 CLI 处理,行为与 VS Code 一致,CLI 升级就跟着升级;Lithe 只是调用者。 +- Core #162 的 `remote.devcontainerConfigs(folder)` 只读文件夹,按规范的查找顺序列出 `.devcontainer/devcontainer.json`、`.devcontainer.json` 和 `.devcontainer` 下一层文件夹里的配置及其 `name`;`remote.devcontainerUp` 只传 `--workspace-folder`、选中的 `--config`,选 Podman 时加 `--docker-path podman`。挂载、端口和运行参数只来自 `devcontainer.json`,Lithe 不额外挂载目录、不加参数(S32)。 +- `devcontainer up` 会在本机运行文件夹提供的代码,Core 要求请求带 `projectCodeAllowed`。桌面端先读本机信任:未受信任时按钮变成“信任并构建”,按与“以受信任项目打开”相同的方式写入信任记录后再构建,不另开一种“只为构建而信任”的状态。 +- CLI 的输出经 Core 隐藏敏感信息后按行流式返回,页面最多保留最近 5000 行;输出、文件夹、配置名、容器名和用户都不写日志,失败只记 `remote_devcontainer_up` 和错误码。 +- 构建期间左侧列表、配置、引擎和文件夹都不能改;“停止”“取消”和关闭窗口都会取消这次构建。已经启动的容器继续运行,页面保留日志并说明这一点:停止不等于删除,删除容器是用户在引擎里的决定。 +- 成功后不新建一种连接:重新读取容器列表并选中 CLI 返回的容器,以它的 `remoteUser` 作为容器内用户,走同一个 `remote.connect` 的 `container` 参数,再直接打开 `remoteWorkspaceFolder`。重建后的容器同名,所以信任记录和窗口计数照常接上。 + +### SSH 主机和 WSL 上的容器:从文件夹选择页进入 + +- 入口放在已连接主机的文件夹选择页标题栏,而不是左侧列表:主机上的容器要先连上主机才能列出,列表本身属于这台主机。容器列表替换文件夹列表显示,“返回文件夹”回到原来的文件夹;容器里的浏览页不再提供这个入口(容器里不再嵌套容器)。 +- 列表经浏览会话的 `remote.listContainers(engine, sessionId)` 依次读取 Docker 和 Podman,在远端服务的非登录环境里运行,所以列出来的容器就是这条连接能进入的。主机没有任何引擎命令行时说明没有找到 Docker 或 Podman;引擎报错时显示它的原始输出,不写日志,失败只记 `remote_host_containers_list` 和错误码。 +- “进入容器”先结束浏览会话,再用同一个 `remote.connect` 发送 `connection`(或 `wsl`)加 `container`。不在已有会话里切换:会话的身份、信任记录和心跳都按“主机/容器”这一对建立,复用浏览会话会让信任键和窗口计数对不上。代价是 OpenSSH 会再问一次它要问的内容(密码、一次性验证码),步骤页照常显示这些问题。 +- 主机上的容器不写入已保存的连接:不给已保存连接加子条目,打开过的文件夹也不记入它的最近文件夹,理由与本机容器相同(容器随时被删除重建)。工作区身份是 `已保存连接或发行版的身份/引擎:[用户@]容器`,窗口名为“容器名(主机名)”,地址显示为“主机 › 引擎:[用户@]容器”。 +- 主机连不上和容器已停止、暂停或引擎没有应答,在 Core 看来都是连接失败,桌面端分不出来,所以用同一段说明并点名引擎,具体原因在诊断输出里;不显示 OpenSSH 的排查提示,也没有“编辑连接”。“重试”进入同一台主机上的同一个容器,而不是回到主机。 +- 不支持在主机上从 `devcontainer.json` 构建:`devcontainer up` 只在本机运行,要在主机上构建需要主机装 CLI 并把文件夹信任扩展到主机,留给以后单独设计。 +- 日志只有 `remote.browse.containers`、`remote.browse.folders`、`remote.browse.container.enter`、`remote.connect` 等动作名,不含主机、容器名、镜像、用户或主机路径。 + +## 考虑过的备选方案 + +- **把容器当作一种可保存的连接**:可以给容器起名、分组。没有采用:容器随时会被删除和重建,保存的条目会大量失效;容器信息每次都能从引擎读到,保存只会多一份需要同步的状态。 +- **按容器 ID 连接**:ID 唯一,但重建后会变,信任记录和标题都对不上;Dev Container 每次重建都会换 ID。名字只在同一个引擎里有效,所以列表键里带上引擎。 +- **在桌面端直接运行 `docker ps` 和 `docker exec`**:Windows 和 macOS 都能用 Go 实现,但会在 Core 之外多一套参数转义、超时和输出上限规则,也无法复用 SSH 主机上的容器跳转。通用逻辑放在 Core。 +- **自己实现 Dev Container 规范**:不依赖 Node 和 npm 包。没有采用:规范面很大(features 的安装顺序、生命周期命令、compose、镜像标签里的元数据合并),自己实现容易与 VS Code 的结果不一致,还要长期跟进规范;官方 CLI 就是规范的参考实现。缺少 CLI 时页面说明用 `npm install -g @devcontainers/cli` 安装。 +- **构建前不要求信任,只在页面上提醒**:没有采用。构建等于运行文件夹提供的 Dockerfile 和命令,与打开受信任项目运行构建一样,必须由同一个信任记录决定。 +- **主机上的容器放在左侧列表,挂在已保存连接下面**:一眼能看到。没有采用:列出它们要先连上主机,打开窗口时不能为此逐台登录;挂在连接下面也就等于把容器保存进连接。 +- **在浏览会话里直接切进容器,不重新登录**:少问一次密码。没有采用:会话的身份、信任键和心跳都按“主机/容器”建立,原地切换需要 Core 为一个会话换身份,边界不清;重新连接沿用已有的同一条路径。 +- **把主机连接失败和容器失败分开说明**:更准确。没有采用:Core 对二者返回同一个连接失败,桌面端只能猜;诊断输出已经给出原因。 + +## 后果 + +- 收益:Dev Container、`docker compose` 或手工运行的容器都能直接打开,不需要在容器里装 SSH 服务;进入容器的安全边界只由 Core 一处决定;测试不碰本机引擎。 +- 代价:打开窗口时多两次 `ps` 调用(各最多 15 秒,后台进行);容器的用户不保存,每次需要重新填写;同名容器在两个引擎里各自打开时窗口计数按引擎区分。 +- 从 devcontainer.json 打开需要本机装好 Dev Container CLI(Node.js 程序),构建可能很久(Core 最长等一小时);停止构建不会删除已启动的容器。 +- 进入主机上的容器要重新登录主机,OpenSSH 会再问一次密码或验证码。 +- 尚未完成:在 SSH 主机和 WSL 上从 devcontainer.json 构建;装有 Dev Container CLI 的真实 Docker/Podman、真实 SSH 主机上的容器与 Windows WSL 上的整机验收。 + +## 验证 + +- `desktop/internal/workbench/remote_container_test.go`:列表分组、排序、选中页、用户填写后的身份、连接只发一次请求且不带 SSH 偏好、标题与状态栏、不写已保存连接、不记住文件夹、日志不含容器信息;停止的容器、被拒绝的用户、找不到引擎时的说明与步骤;搜索与折叠;一个引擎失败时另一个照常列出;没有引擎时不显示分组。 +- `desktop/internal/core/remote_session_test.go`:`container` 单独发送、`remote.listContainers` 的请求与回应。 +- `desktop/internal/workbench/remote_devcontainer_test.go`:读取文件夹的配置并默认选第一个、构建请求的字段、按 CLI 结果选中容器并打开工作区文件夹、日志里没有文件夹和容器信息;未受信任时先写信任再构建;找不到 CLI、CLI 报告失败、Core 以未受信任拒绝时的说明,且 CLI 输出不进日志;构建中“停止”后保留日志、列表不能切换;相对路径、不存在的文件夹和没有配置的文件夹。 +- `desktop/internal/core/remote_devcontainer_test.go`:`remote.devcontainerConfigs` 的列出、`remote.devcontainerUp` 在运行 CLI 之前的拒绝、流式输出事件。 +- `desktop/internal/workbench/remote_host_containers_test.go`:经浏览会话列出两个引擎、未选中时“进入容器”不可用、进入时结束浏览会话并按填写的用户在同一台主机上连接、工作区身份与窗口名、不记住文件夹、动作顺序与日志不含主机和容器信息;容器已不在时的说明、没有“编辑连接”、地址带主机、“重试”进入同一台主机上的同一个容器、“返回文件夹”;`remoteHost` 的 `hosted`/`overSSH`/`saved` 与请求字段。 +- `desktop/internal/workbench/remote_connections_visual_test.go` 生成 `docs/assets/remote-connections/` 下的容器、主机上的容器和 devcontainer 截图。 + +```bash +scripts/desktop/desktop-go.sh test ./internal/core ./internal/workbench -run 'Remote|Container|Devcontainer' -count=1 +``` + +## 适用范围 + +`desktop/internal/workbench/remote_container.go`、`desktop/internal/workbench/remote_host_containers.go`、`desktop/internal/workbench/remote_wsl.go` 中的 `remoteHost`、`desktop/internal/core/remote_session.go` 中的 `ContainerConnection` 与 `RemoteListContainers`,`desktop/internal/workbench/remote_devcontainer.go` 与 `desktop/internal/core/remote_devcontainer.go`。之后的 Dev Container 和远端主机上的容器入口都复用同一个 `remoteHost{container}` 和 Core 的 `remote.connect`,不要在桌面端另写一套容器命令。 diff --git a/desktop/internal/core/errors.go b/desktop/internal/core/errors.go index 77123f0a5..ba940c102 100644 --- a/desktop/internal/core/errors.go +++ b/desktop/internal/core/errors.go @@ -88,6 +88,9 @@ const ( // read, or its SHA-256 is not the one the application's manifest names; nothing was sent to // the host. CodeRemoteServerInvalid ErrorCode = "remote_server_invalid" + // 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" // CodeUnknown means the failure fits no more specific category. CodeUnknown ErrorCode = "unknown" ) diff --git a/desktop/internal/core/remote_devcontainer.go b/desktop/internal/core/remote_devcontainer.go new file mode 100644 index 000000000..3a795a937 --- /dev/null +++ b/desktop/internal/core/remote_devcontainer.go @@ -0,0 +1,116 @@ +package core + +import ( + "bytes" + "context" + "encoding/json" +) + +// DevcontainerConfig is one devcontainer.json remote.devcontainerConfigs found in a folder. +type DevcontainerConfig struct { + // Path is relative to the folder with / separators, such as .devcontainer/devcontainer.json. + Path string `json:"path"` + // Name is the configuration's name, at most 128 bytes without control characters; empty when + // it has none. It is the folder's text: shown as it is and never logged. + Name string `json:"name,omitempty"` +} + +// RemoteDevcontainerConfigs lists the devcontainer.json files of folder, an absolute folder on this +// machine, in the order the Dev Container specification searches them. Listing starts nothing. A +// relative folder is CodeInvalidRequest and one that is not a directory CodeWorkspaceNotFound. +func (c *Client) RemoteDevcontainerConfigs(ctx context.Context, folder string) ([]DevcontainerConfig, error) { + var result struct { + Configs []DevcontainerConfig `json:"configs"` + } + request := struct { + Folder string `json:"folder"` + }{Folder: folder} + if err := c.Execute(ctx, "remote.devcontainerConfigs", request, &result); err != nil { + return nil, err + } + return nonNil(result.Configs), nil +} + +// DevcontainerUpRequest asks remote.devcontainerUp to build or reuse and start a folder's dev +// container. +type DevcontainerUpRequest struct { + // Folder is the absolute folder on this machine. + Folder string `json:"folder"` + // Config is one of the paths RemoteDevcontainerConfigs listed; empty lets the CLI search. + Config string `json:"config,omitempty"` + // Engine is ContainerEngineDocker or ContainerEnginePodman. + Engine string `json:"engine"` + // ProjectCodeAllowed is the folder's trust decision. Building runs the folder's code on this + // machine, so without it Core runs nothing (CodeDevcontainerUntrustedFolder). + ProjectCodeAllowed bool `json:"projectCodeAllowed"` +} + +// Devcontainer is the running container remote.devcontainerUp started and the folder to open in it. +type Devcontainer struct { + Engine string `json:"engine"` + // Container is the container's name, or its id when the engine reports no name. + Container string `json:"container"` + ContainerID string `json:"containerId"` + // User is the configuration's remoteUser; empty is the image's default user. + User string `json:"user,omitempty"` + // WorkspaceFolder is the absolute folder inside the container to open. + WorkspaceFolder string `json:"workspaceFolder"` +} + +// Connection is the container as remote.connect's container field names it. +func (d Devcontainer) Connection() ContainerConnection { + return ContainerConnection{Engine: d.Engine, Container: d.Container, User: d.User} +} + +// DevcontainerUp is what remote.devcontainerUp reported. +type DevcontainerUp struct { + // Container is nil when the CLI reported a failure. + Container *Devcontainer `json:"container,omitempty"` + // Diagnostics is the end of the CLI's log and its error, redacted, when it failed. It is + // upstream text: shown as it is and never logged. + Diagnostics string `json:"diagnostics"` +} + +// DevcontainerOutput is one devcontainerOutput event: a redacted line of the CLI's log, or the note +// that later lines were dropped. It is upstream text: shown as it is and never logged. +type DevcontainerOutput struct { + Text string `json:"text"` + Truncated bool `json:"truncated"` +} + +// devcontainerOutputEvent marks the execution events that carry the CLI's log. +var devcontainerOutputEvent = []byte(`"devcontainerOutput"`) + +// RemoteDevcontainerUp runs the Dev Container CLI's up for request, at most an hour and cancelled +// with ctx, and hands each line of its log to output on the request's goroutine; output must +// return promptly. A missing CLI is CodeRuntimeMissing, an untrusted folder +// CodeDevcontainerUntrustedFolder, a config the folder does not list CodeInvalidRequest and a +// result Lithe cannot enter CodeParseFailed. +func (c *Client) RemoteDevcontainerUp(ctx context.Context, request DevcontainerUpRequest, output func(DevcontainerOutput)) (DevcontainerUp, error) { + var result DevcontainerUp + if _, err := c.ExecuteWithEvents(ctx, "remote.devcontainerUp", request, &result, devcontainerOutputObserver(output)); err != nil { + return DevcontainerUp{}, err + } + return result, nil +} + +// devcontainerOutputObserver hands output the devcontainerOutput events among an operation's +// execution events and skips the rest; a nil output observes nothing. +func devcontainerOutputObserver(output func(DevcontainerOutput)) func(json.RawMessage) { + if output == nil { + return nil + } + return func(raw json.RawMessage) { + if !bytes.Contains(raw, devcontainerOutputEvent) { + return + } + var event struct { + Type string `json:"type"` + Text string `json:"text"` + Truncated bool `json:"truncated"` + } + if json.Unmarshal(raw, &event) == nil && event.Type == "devcontainerOutput" { + output(DevcontainerOutput{Text: event.Text, Truncated: event.Truncated}) + } + } +} diff --git a/desktop/internal/core/remote_devcontainer_test.go b/desktop/internal/core/remote_devcontainer_test.go new file mode 100644 index 000000000..fe3e69733 --- /dev/null +++ b/desktop/internal/core/remote_devcontainer_test.go @@ -0,0 +1,92 @@ +package core + +import ( + "encoding/json" + "errors" + "os" + "path/filepath" + "reflect" + "testing" +) + +// Core lists a folder's devcontainer.json files with their names in the specification's order, and +// refuses a relative folder before reading anything. +func TestRemoteDevcontainerConfigsListTheFolder(t *testing.T) { + folder := t.TempDir() + write := func(path, text string) { + t.Helper() + full := filepath.Join(folder, filepath.FromSlash(path)) + if err := os.MkdirAll(filepath.Dir(full), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(full, []byte(text), 0o644); err != nil { + t.Fatal(err) + } + } + write(".devcontainer/devcontainer.json", "{\n // the default\n \"name\": \"Go\",\n}\n") + write(".devcontainer/node/devcontainer.json", `{"image": "node"}`) + client := NewClient() + configs, err := client.RemoteDevcontainerConfigs(testContext(t), folder) + want := []DevcontainerConfig{ + {Path: ".devcontainer/devcontainer.json", Name: "Go"}, + {Path: ".devcontainer/node/devcontainer.json"}, + } + if err != nil || !reflect.DeepEqual(configs, want) { + t.Fatalf("configs = %+v, %v; want %d configurations", configs, err, len(want)) + } + empty, err := client.RemoteDevcontainerConfigs(testContext(t), t.TempDir()) + if err != nil || empty == nil || len(empty) != 0 { + t.Fatalf("configs of an empty folder = %+v, %v; want an empty list", empty, err) + } + var coreErr *Error + if _, err := client.RemoteDevcontainerConfigs(testContext(t), "relative"); !errors.As(err, &coreErr) || coreErr.Code != CodeInvalidRequest { + t.Fatalf("configs of a relative folder = %v, want invalid_request", err) + } +} + +// An untrusted folder runs nothing, and a config the folder does not list is refused before the +// CLI starts; neither depends on what this machine has installed. +func TestRemoteDevcontainerUpRefusesBeforeTheCLIRuns(t *testing.T) { + folder := t.TempDir() + client := NewClient() + output := func(DevcontainerOutput) { t.Error("the CLI's log reached the window although nothing ran") } + var coreErr *Error + _, err := client.RemoteDevcontainerUp(testContext(t), DevcontainerUpRequest{Folder: folder, Engine: ContainerEngineDocker}, output) + if !errors.As(err, &coreErr) || coreErr.Code != CodeDevcontainerUntrustedFolder { + t.Fatalf("up of an untrusted folder = %v, want devcontainer_untrusted_folder", err) + } + request := DevcontainerUpRequest{Folder: folder, Config: "../devcontainer.json", Engine: ContainerEngineDocker, ProjectCodeAllowed: true} + if _, err := client.RemoteDevcontainerUp(testContext(t), request, output); !errors.As(err, &coreErr) || coreErr.Code != CodeInvalidRequest { + t.Fatalf("up with an unlisted config = %v, want invalid_request", err) + } + wire, err := json.Marshal(DevcontainerUpRequest{Folder: "/f", Engine: ContainerEnginePodman}) + if err != nil || string(wire) != `{"folder":"/f","engine":"podman","projectCodeAllowed":false}` { + t.Fatalf("request = %s, %v", wire, err) + } +} + +// Only devcontainerOutput events reach the window, in order, with the truncation note. +func TestDevcontainerOutputObserverPassesTheCLIsLog(t *testing.T) { + if devcontainerOutputObserver(nil) != nil { + t.Fatal("a nil output must observe nothing") + } + var got []DevcontainerOutput + observe := devcontainerOutputObserver(func(line DevcontainerOutput) { got = append(got, line) }) + for _, raw := range []string{ + `{"type":"remoteStage","stage":"connecting","operationId":"a"}`, + `{"type":"devcontainerOutput","text":"Step 1/3","operationId":"a"}`, + `{"type":"other","text":"devcontainerOutput"}`, + `{"type":"devcontainerOutput","truncated":true,"operationId":"a"}`, + `not json "devcontainerOutput"`, + } { + observe(json.RawMessage(raw)) + } + want := []DevcontainerOutput{{Text: "Step 1/3"}, {Truncated: true}} + if !reflect.DeepEqual(got, want) { + t.Fatalf("output = %+v, want %d events", got, len(want)) + } + connection := Devcontainer{Engine: ContainerEngineDocker, Container: "web", ContainerID: "abc", User: "dev", WorkspaceFolder: "/workspaces/app"}.Connection() + if connection != (ContainerConnection{Engine: ContainerEngineDocker, Container: "web", User: "dev"}) { + t.Fatalf("connection = %+v", connection) + } +} diff --git a/desktop/internal/core/remote_session.go b/desktop/internal/core/remote_session.go index c22c67a97..f417ebaaf 100644 --- a/desktop/internal/core/remote_session.go +++ b/desktop/internal/core/remote_session.go @@ -23,15 +23,21 @@ type RemoteServerBuild struct { SHA256 string `json:"sha256"` } -// RemoteConnectRequest opens a session to the host of Connection, or to the local WSL -// distribution WSL names, installing the server build for the host's platform when the host does -// not already run that exact build. Exactly one of the two is set; Core refuses a request with -// both or neither as CodeInvalidRequest, before anything starts. +// RemoteConnectRequest opens a session to the host of Connection, to the local WSL distribution +// WSL names, or to the running container Container names, installing the server build for the +// host's platform when the host does not already run that exact build. At most one of Connection +// and WSL is set; without either, Container is a container on this machine. Core refuses a +// request that names none of the three, or both Connection and WSL, as CodeInvalidRequest, before +// anything starts. type RemoteConnectRequest struct { Connection SSHConnection `json:"connection,omitzero"` // WSL opens a distribution of the Windows Subsystem for Linux through the system's wsl.exe // instead of OpenSSH. Core asks nothing of the user for it: there is no AskPass. WSL *WSLConnection `json:"wsl,omitempty"` + // Container enters a running Docker or Podman container through its engine's exec: on the + // host Connection or WSL names, or, on its own, on this machine, where Core starts the engine + // CLI in place of OpenSSH and asks nothing. Core never starts, creates or changes it. + Container *ContainerConnection `json:"container,omitempty"` // Servers are the builds the application ships; Core picks the one for the host. Servers []RemoteServerBuild `json:"servers"` // ServerVersion is the version of the shipped builds. @@ -39,7 +45,7 @@ type RemoteConnectRequest struct { // InstallRoot is where the host keeps installed servers; empty is $HOME/.lithe-server. InstallRoot string `json:"installRoot,omitempty"` // Preferences is the remote workspace preference document, or nil. It names the SSH program; - // a WSL connection ignores it. + // a WSL connection or a container on this machine ignores it. Preferences *string `json:"preferences,omitempty"` // Resume attaches to the host session an earlier connection kept; nil starts a new session. // Core refuses a malformed key or token as CodeInvalidRequest naming resume in @@ -76,6 +82,74 @@ func (c WSLConnection) Identity() string { return "wsl:" + user + "@" + distribution } +// Container engines whose CLI remote.connect and remote.listContainers run. +const ( + ContainerEngineDocker = "docker" + ContainerEnginePodman = "podman" +) + +// ContainerConnection is a running container, as remote.connect's container field names it. +// Core trims Container and User; an empty User is the image's default user. Core refuses a +// malformed field by name ("container" or "user") with the reasons required and invalid, read by +// RemoteConnectionFieldError. +type ContainerConnection struct { + // Engine is ContainerEngineDocker or ContainerEnginePodman. + Engine string `json:"engine"` + // Container is the container's name or id, as remote.listContainers lists it. + Container string `json:"container"` + // User is the user, uid or user:group inside the container, passed as exec --user. + User string `json:"user,omitempty"` +} + +// Identity is the container as the window and the recent projects name it: +// engine:container, or engine:user@container, the form RemoteWorkspaceTrustTarget.Place uses. +func (c ContainerConnection) Identity() string { + container, user := strings.TrimSpace(c.Container), strings.TrimSpace(c.User) + if user == "" { + return c.Engine + ":" + container + } + return c.Engine + ":" + user + "@" + container +} + +// RemoteContainer is a running container remote.listContainers found. +type RemoteContainer struct { + // ID is the container's full id. + ID string `json:"id"` + // Name is the first of the container's names. + Name string `json:"name"` + // Image and Status are the engine's text, such as nginx:1 and Up 2 hours, at most 256 bytes + // each and without control characters. They are upstream text, shown as they are. + Image string `json:"image"` + Status string `json:"status"` +} + +// RemoteContainers is what remote.listContainers found. +type RemoteContainers struct { + // Available says whether the engine CLI ran: false when the machine has no such CLI. + Available bool `json:"available"` + // Containers are the running containers in the engine's order, at most 256. + Containers []RemoteContainer `json:"containers"` + // Diagnostics is what the CLI printed when it failed, such as the message that its service is + // not running, redacted. It is upstream text, shown as it is and never logged. + Diagnostics string `json:"diagnostics"` +} + +// RemoteListContainers lists the running containers of engine on this machine, or on the host of +// session sessionID when it is set. Core runs the engine CLI's ps, bounded to 15 seconds +// (CodeTimedOut past them), and saves nothing; an unknown session is CodeConnectionClosed. +func (c *Client) RemoteListContainers(ctx context.Context, engine, sessionID string) (RemoteContainers, error) { + var result RemoteContainers + request := struct { + Engine string `json:"engine"` + SessionID string `json:"sessionId,omitempty"` + }{Engine: engine, SessionID: sessionID} + if err := c.Execute(ctx, "remote.listContainers", request, &result); err != nil { + return RemoteContainers{}, err + } + result.Containers = nonNil(result.Containers) + return result, nil +} + // RemoteWSLDistributions is what remote.listWslDistributions found on this machine. type RemoteWSLDistributions struct { // Available says whether wsl.exe ran: false on systems other than Windows and on a Windows diff --git a/desktop/internal/core/remote_session_test.go b/desktop/internal/core/remote_session_test.go index 0ffa38059..a1409b8b7 100644 --- a/desktop/internal/core/remote_session_test.go +++ b/desktop/internal/core/remote_session_test.go @@ -293,3 +293,44 @@ func TestRemoteListWSLDistributionsIsUnavailableOutsideWindows(t *testing.T) { t.Fatalf("listing = %+v, %v, want unavailable with an empty list", listed, err) } } + +// A container is sent as the container field alone, and Core refuses a malformed one by the field +// it names before the engine starts. +func TestRemoteConnectSendsAContainerAloneAndCoreRefusesItByField(t *testing.T) { + container := &ContainerConnection{Engine: ContainerEnginePodman, Container: "web"} + wire, err := json.Marshal(RemoteConnectRequest{Container: container, Servers: []RemoteServerBuild{}}) + if err != nil || strings.Contains(string(wire), `"connection"`) || !strings.Contains(string(wire), `"container":{"engine":"podman","container":"web"}`) { + t.Fatalf("request = %s, %v, want the container field without a connection", wire, err) + } + if identity := (ContainerConnection{Engine: ContainerEngineDocker, Container: " web ", User: " dev "}).Identity(); identity != "docker:dev@web" { + t.Fatalf("identity = %q", identity) + } + client := NewClient() + for _, tc := range []struct { + container ContainerConnection + field, reason string + }{ + {ContainerConnection{Engine: ContainerEngineDocker, Container: " "}, "container", "required"}, + {ContainerConnection{Engine: ContainerEngineDocker, Container: "-web"}, "container", "invalid"}, + {ContainerConnection{Engine: ContainerEngineDocker, Container: "web", User: "root;id"}, "user", "invalid"}, + } { + request := RemoteConnectRequest{Container: &tc.container, Servers: shippedTargets, ServerVersion: "0.0.0-test"} + _, err := client.RemoteConnect(testContext(t), request) + if field, reason, ok := RemoteConnectionFieldError(err); !ok || field != tc.field || reason != tc.reason { + t.Fatalf("connect refused %q %q (%v), want %q %q", field, reason, ok, tc.field, tc.reason) + } + } +} + +// Listing over a session that is not open is CodeConnectionClosed, and an engine Core does not +// know is refused before anything runs; neither depends on what this machine has installed. +func TestRemoteListContainersNamesTheSessionAndTheEngine(t *testing.T) { + client := NewClient() + var coreErr *Error + if _, err := client.RemoteListContainers(testContext(t), ContainerEngineDocker, "absent"); !errors.As(err, &coreErr) || coreErr.Code != CodeConnectionClosed { + t.Fatalf("listing over an absent session = %v, want connection_closed", err) + } + if _, err := client.RemoteListContainers(testContext(t), "nerdctl", ""); !errors.As(err, &coreErr) || coreErr.Code != CodeInvalidRequest { + t.Fatalf("listing with an unknown engine = %v, want invalid_request", err) + } +} diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 575a0aea9..d60bf62fe 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1639,6 +1639,22 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.connectedNow": "Connected", "desktop.remote.connectedWindows": "{count} window(s) open", "desktop.remote.connecting": "Connecting… OpenSSH may ask for a password or to confirm the host key.", + "desktop.remote.container.about": "Enters this running container through {engine} on this computer, as the user below. Lithe does not start, create or change the container, mounts no folder into it, and needs no more rights than the {engine} command line has. Nothing about the container is saved: the folders opened in it are not remembered, and the list is read again each time this window opens.", + "desktop.remote.container.docker": "Docker", + "desktop.remote.container.heading": "Containers", + "desktop.remote.container.hostUnreachable": "The host could not be reached, or this container on it is no longer running, is paused, or {engine} did not answer.", + "desktop.remote.container.kind": "Container", + "desktop.remote.container.missing": "The {engine} command line was not found on this computer. Install {engine} to enter its containers.", + "desktop.remote.container.nameInvalid": "The container engine does not accept this container name.", + "desktop.remote.container.podman": "Podman", + "desktop.remote.container.row": "{engine} · {image}", + "desktop.remote.container.start": "Enter the container", + "desktop.remote.container.state": "Image {image} · {status}", + "desktop.remote.container.unreachable": "This container is no longer running, is paused, or its engine did not answer.", + "desktop.remote.container.user": "User in the container", + "desktop.remote.container.userHelp": "The user, uid or user:group the workspace runs as inside the container. Leave it empty to use the image's default user.", + "desktop.remote.container.userInvalid": "Use a user name, uid or user:group of at most 64 letters, digits and _ . : -, not starting with -.", + "desktop.remote.container.userPlaceholder": "Image's default user", "desktop.remote.copyAsNew": "Duplicate as New", "desktop.remote.copyName": "{name} copy", "desktop.remote.damaged": "The saved connections in {path} cannot be read. Repair or remove the file before saving.", @@ -1646,6 +1662,38 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.deleteConfirm": "Delete “{name}”?", "desktop.remote.deleteFailed": "Cannot delete the connection: {reason}", "desktop.remote.deleteNamed": "Delete “{name}”…", + "desktop.remote.devcontainer.about": "Builds and starts the dev container a local folder’s devcontainer.json describes, with the official Dev Container CLI, and opens its workspace folder in it. Building runs the folder’s Dockerfile, features and commands here, so the folder must be trusted. Lithe adds no mount or option.", + "desktop.remote.devcontainer.build": "Build and Open", + "desktop.remote.devcontainer.building": "Building the dev container…", + "desktop.remote.devcontainer.choose": "Choose Folder…", + "desktop.remote.devcontainer.chooseTitle": "Choose the Folder to Open in Its Dev Container", + "desktop.remote.devcontainer.config": "Configuration", + "desktop.remote.devcontainer.configHelp": "The devcontainer.json files of this folder, in the order the Dev Container specification looks for them: .devcontainer/devcontainer.json, .devcontainer.json, then one folder below .devcontainer.", + "desktop.remote.devcontainer.configNamed": "{name} ({path})", + "desktop.remote.devcontainer.engine": "Engine", + "desktop.remote.devcontainer.engineHelp": "Docker or Podman runs the container. With Podman, the CLI is given podman as its docker path.", + "desktop.remote.devcontainer.failed": "The Dev Container CLI could not start the container. Its output is below.", + "desktop.remote.devcontainer.folder": "Folder on this computer", + "desktop.remote.devcontainer.folderMissing": "This folder does not exist on this computer.", + "desktop.remote.devcontainer.folderPlaceholder": "Choose a folder, or type its path and press Return", + "desktop.remote.devcontainer.folderRelative": "Enter the folder’s full path, such as /Users/me/project.", + "desktop.remote.devcontainer.log": "Build Log", + "desktop.remote.devcontainer.logHelp": "The Dev Container CLI’s own output, with secrets hidden. It is shown here and not written to Lithe’s logs.", + "desktop.remote.devcontainer.logWaiting": "Waiting for the Dev Container CLI…", + "desktop.remote.devcontainer.missing": "The Dev Container CLI (devcontainer) was not found on this computer. Install it with npm install -g @devcontainers/cli, then build again.", + "desktop.remote.devcontainer.none": "This folder has no devcontainer.json in .devcontainer or at its top.", + "desktop.remote.devcontainer.open": "Open from devcontainer.json…", + "desktop.remote.devcontainer.readFailed": "Cannot read the folder’s configurations: {reason}", + "desktop.remote.devcontainer.stopped": "The build was stopped. A container it already started keeps running.", + "desktop.remote.devcontainer.timedOut": "The build took longer than an hour and was stopped.", + "desktop.remote.devcontainer.title": "Open in Dev Container", + "desktop.remote.devcontainer.truncated": "Later lines are not shown: the log is too long.", + "desktop.remote.devcontainer.trustAndBuild": "Trust and Build", + "desktop.remote.devcontainer.trustFailed": "Cannot read whether this folder is trusted: {reason}", + "desktop.remote.devcontainer.untrusted": "This folder is not trusted. Trust and Build trusts it, the same as opening it as a trusted project, and then builds.", + "desktop.remote.devcontainer.untrustedRefused": "Nothing was built: this folder is not trusted.", + "desktop.remote.devcontainer.unusable": "The Dev Container CLI started something Lithe cannot open: its result names no container or workspace folder.", + "desktop.remote.devcontainer.upFailed": "Cannot build the dev container: {reason}", "desktop.remote.diagnostics": "OpenSSH Output", "desktop.remote.document.disconnected": "the remote workspace is not connected; try again once it reconnects", "desktop.remote.document.failed": "the host could not read or write it", @@ -1694,6 +1742,15 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.host": "Host", "desktop.remote.host.cores": "{count} cores", "desktop.remote.host.diskOf": "of {total}", + "desktop.remote.hostContainers.about": "The Docker and Podman containers running on this host. Entering one ends this connection, connects to the host again and on into the container, where you then choose a folder. Lithe never starts, creates or changes a container, and mounts no folder.", + "desktop.remote.hostContainers.back": "Back to Folders", + "desktop.remote.hostContainers.empty": "No containers are running on this host.", + "desktop.remote.hostContainers.enter": "Enter Container", + "desktop.remote.hostContainers.failed": "The containers on this host could not be listed: {reason}", + "desktop.remote.hostContainers.name": "{container} on {host}", + "desktop.remote.hostContainers.noEngine": "Neither the Docker nor the Podman command line was found on this host.", + "desktop.remote.hostContainers.show": "Containers on This Host", + "desktop.remote.hostContainers.title": "Choose a Container on {name}", "desktop.remote.hostFile.empty": "No matching files or folders", "desktop.remote.hostFile.pathHint": "Type a path that starts with / or ~/", "desktop.remote.hostFile.placeholder": "A host path, such as ~/notes.txt or /etc/hosts", @@ -5471,6 +5528,22 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.connectedNow": "已连接", "desktop.remote.connectedWindows": "{count} 个窗口已打开", "desktop.remote.connecting": "正在连接…OpenSSH 可能会询问密码或请你确认主机密钥。", + "desktop.remote.container.about": "通过本机的 {engine} 进入这个正在运行的容器,以下方的用户运行。Lithe 不启动、不创建、不改动容器,不往容器里挂载目录,需要的权限也不超过 {engine} 命令行本身。不保存这个容器的任何信息:不记住在其中打开过的文件夹,每次打开本窗口时重新读取列表。", + "desktop.remote.container.docker": "Docker", + "desktop.remote.container.heading": "容器", + "desktop.remote.container.hostUnreachable": "无法连接主机,或者主机上的这个容器已经不在运行、已暂停,或者 {engine} 没有应答。", + "desktop.remote.container.kind": "容器", + "desktop.remote.container.missing": "本机没有找到 {engine} 命令行。安装 {engine} 后才能进入它的容器。", + "desktop.remote.container.nameInvalid": "容器引擎不接受这个容器名。", + "desktop.remote.container.podman": "Podman", + "desktop.remote.container.row": "{engine} · {image}", + "desktop.remote.container.start": "进入容器", + "desktop.remote.container.state": "镜像 {image} · {status}", + "desktop.remote.container.unreachable": "这个容器已经不在运行或已暂停,或者容器引擎没有应答。", + "desktop.remote.container.user": "容器内用户", + "desktop.remote.container.userHelp": "工作区在容器里以哪个用户运行,可以填用户名、uid 或“用户:组”。留空则使用镜像的默认用户。", + "desktop.remote.container.userInvalid": "用户最多 64 个字符,只能包含字母、数字和 _ . : -,且不能以 - 开头。", + "desktop.remote.container.userPlaceholder": "镜像默认用户", "desktop.remote.copyAsNew": "复制为新连接", "desktop.remote.copyName": "{name} 副本", "desktop.remote.damaged": "无法读取 {path} 里保存的连接。修复或删除这个文件之前不能保存。", @@ -5478,6 +5551,38 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.deleteConfirm": "删除“{name}”?", "desktop.remote.deleteFailed": "无法删除连接:{reason}", "desktop.remote.deleteNamed": "删除“{name}”…", + "desktop.remote.devcontainer.about": "用官方 Dev Container CLI 按本机文件夹里 devcontainer.json 的描述构建并启动 dev container,然后在容器里打开它的工作区文件夹。构建会在本机运行这个文件夹的 Dockerfile、features 和命令,因此文件夹必须受信任。Lithe 不额外挂载目录,也不额外加参数。", + "desktop.remote.devcontainer.build": "构建并打开", + "desktop.remote.devcontainer.building": "正在构建 dev container…", + "desktop.remote.devcontainer.choose": "选择文件夹…", + "desktop.remote.devcontainer.chooseTitle": "选择要在 Dev Container 中打开的文件夹", + "desktop.remote.devcontainer.config": "配置", + "desktop.remote.devcontainer.configHelp": "这个文件夹里的 devcontainer.json,按 Dev Container 规范查找的顺序列出:.devcontainer/devcontainer.json、.devcontainer.json,然后是 .devcontainer 下一层文件夹里的。", + "desktop.remote.devcontainer.configNamed": "{name}({path})", + "desktop.remote.devcontainer.engine": "容器引擎", + "desktop.remote.devcontainer.engineHelp": "由 Docker 或 Podman 运行容器。选 Podman 时,CLI 的 docker 路径设为 podman。", + "desktop.remote.devcontainer.failed": "Dev Container CLI 没能启动容器,输出如下。", + "desktop.remote.devcontainer.folder": "本机文件夹", + "desktop.remote.devcontainer.folderMissing": "本机没有这个文件夹。", + "desktop.remote.devcontainer.folderPlaceholder": "选择文件夹,或输入路径后按回车", + "desktop.remote.devcontainer.folderRelative": "请输入文件夹的完整路径,例如 /Users/me/project。", + "desktop.remote.devcontainer.log": "构建日志", + "desktop.remote.devcontainer.logHelp": "Dev Container CLI 自己的输出,已隐藏敏感信息。只在这里显示,不写入 Lithe 的日志。", + "desktop.remote.devcontainer.logWaiting": "正在等待 Dev Container CLI…", + "desktop.remote.devcontainer.missing": "本机没有找到 Dev Container CLI(devcontainer)。请用 npm install -g @devcontainers/cli 安装后再构建。", + "desktop.remote.devcontainer.none": "这个文件夹的 .devcontainer 里和顶层都没有 devcontainer.json。", + "desktop.remote.devcontainer.open": "从 devcontainer.json 打开…", + "desktop.remote.devcontainer.readFailed": "无法读取文件夹的配置:{reason}", + "desktop.remote.devcontainer.stopped": "构建已停止。已经启动的容器会继续运行。", + "desktop.remote.devcontainer.timedOut": "构建超过一小时,已停止。", + "desktop.remote.devcontainer.title": "在 Dev Container 中打开", + "desktop.remote.devcontainer.truncated": "日志太长,后面的内容不再显示。", + "desktop.remote.devcontainer.trustAndBuild": "信任并构建", + "desktop.remote.devcontainer.trustFailed": "无法读取这个文件夹是否受信任:{reason}", + "desktop.remote.devcontainer.untrusted": "这个文件夹还不受信任。“信任并构建”会信任它(与以受信任项目打开时相同),然后开始构建。", + "desktop.remote.devcontainer.untrustedRefused": "没有构建:这个文件夹不受信任。", + "desktop.remote.devcontainer.unusable": "Dev Container CLI 启动的结果无法打开:结果里没有容器或工作区文件夹。", + "desktop.remote.devcontainer.upFailed": "无法构建 dev container:{reason}", "desktop.remote.diagnostics": "OpenSSH 输出", "desktop.remote.document.disconnected": "远程工作区未连接,请在重新连接后再试", "desktop.remote.document.failed": "主机无法读取或写入这个文件", @@ -5526,6 +5631,15 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.host": "主机", "desktop.remote.host.cores": "{count} 核", "desktop.remote.host.diskOf": "共 {total}", + "desktop.remote.hostContainers.about": "这台主机上正在运行的 Docker 和 Podman 容器。进入容器会断开当前连接,重新连接主机后再进入容器,然后在容器里选择文件夹。Lithe 不会启动、创建或修改容器,也不会挂载文件夹。", + "desktop.remote.hostContainers.back": "返回文件夹", + "desktop.remote.hostContainers.empty": "这台主机上没有正在运行的容器。", + "desktop.remote.hostContainers.enter": "进入容器", + "desktop.remote.hostContainers.failed": "无法列出主机上的容器:{reason}", + "desktop.remote.hostContainers.name": "{container}({host})", + "desktop.remote.hostContainers.noEngine": "这台主机上没有找到 Docker 或 Podman 命令行。", + "desktop.remote.hostContainers.show": "主机上的容器", + "desktop.remote.hostContainers.title": "选择 {name} 上的容器", "desktop.remote.hostFile.empty": "没有匹配的文件或文件夹", "desktop.remote.hostFile.pathHint": "请输入以 / 或 ~/ 开头的路径", "desktop.remote.hostFile.placeholder": "主机上的路径,例如 ~/notes.txt 或 /etc/hosts", diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 275140390..2d029ba88 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -214,6 +214,9 @@ type Kernel interface { EditRemoteConnections(ctx context.Context, document *string, edit core.RemoteConnectionEdit) (core.RemoteConnectionsPublication, error) RemoteProbe(ctx context.Context, connection core.SSHConnection, preferences *string) (core.RemoteProbeResult, error) RemoteListWSLDistributions(ctx context.Context) (core.RemoteWSLDistributions, error) + RemoteListContainers(ctx context.Context, engine, sessionID string) (core.RemoteContainers, error) + RemoteDevcontainerConfigs(ctx context.Context, folder string) ([]core.DevcontainerConfig, error) + RemoteDevcontainerUp(ctx context.Context, request core.DevcontainerUpRequest, output func(core.DevcontainerOutput)) (core.DevcontainerUp, error) RemoteAuthRespond(ctx context.Context, requestID string, answer *string) (bool, error) RemoteConnect(ctx context.Context, request core.RemoteConnectRequest) (core.RemoteConnectResult, error) RemoteDisconnect(ctx context.Context, sessionID string, programs core.RemoteClosePrograms) (core.RemoteDisconnectResult, error) diff --git a/desktop/internal/workbench/remote.go b/desktop/internal/workbench/remote.go index 54596ac1c..83b9f92cf 100644 --- a/desktop/internal/workbench/remote.go +++ b/desktop/internal/workbench/remote.go @@ -106,6 +106,12 @@ type remoteState struct { importer *remoteImporter // wsl is this computer's WSL distributions, read once per opening (remote_wsl.go). wsl remoteWSL + // containers is this computer's running containers, read once per opening + // (remote_container.go). + containers remoteContainers + // devcontainer is the page that opens a folder of this computer in its dev container, nil + // when it is not shown (remote_devcontainer.go). + devcontainer *remoteDevcontainer // log folds OpenSSH's words under a failed test or connection. log ui.CollapsibleState imports remoteImportCounts @@ -128,17 +134,20 @@ type remoteForm struct { // have this name, since Core refuses control characters in one. const remoteNewGroup = "\x00new" -// remoteListRow is a row of the list: a section's heading, a saved connection, or a WSL -// distribution. +// remoteListRow is a row of the list: a section's heading, a saved connection, a WSL +// distribution or a running container. type remoteListRow struct { // heading is set on a section's heading, which names group ("" for the connections without - // one, remoteWSLHeading for the WSL distributions) and the number of rows in the section. + // one, remoteWSLHeading for the WSL distributions, remoteContainerHeading for the containers) + // and the number of rows in the section. heading bool group string count int entry *core.SavedRemoteConnection // wsl is the distribution of a WSL row. wsl string + // container is the container of a container's row. + container *remoteListedContainer } // remoteProbe is a test in progress, cancelled by Stop or by closing the window. @@ -152,8 +161,12 @@ type remoteProbeOutcome struct { // at is when the test ended, for the overview's "tested 5 minutes ago". at time.Time err error - // wsl is set when the host was a WSL distribution, whose failures read differently. - wsl bool + // wsl is set when the host was a WSL distribution, a container in one included, and engine + // is the engine of a container host; hosted is set when that container was on an SSH host or + // a WSL distribution. The failures of each read differently. + wsl bool + engine string + hosted bool } // remoteFieldRefusal is the field of the form Core (or the form's own number check) refused, and @@ -182,6 +195,7 @@ func (a *App) openRemote(surface actionSurface) { a.performed("remote.connections.open", surface) a.loadRemote(remoteLoadSelectFirst, "") a.loadRemoteWSL() + a.loadRemoteContainers() } // closeRemote closes the window, stopping a running test or connection and ending the session a @@ -192,6 +206,7 @@ func (a *App) closeRemote() { r.stopConnect() a.leaveRemoteBrowser() a.leaveRemoteTrust() + a.leaveRemoteDevcontainer() r.generation++ r.open, r.saving, r.loading = false, false, false r.form = remoteForm{} @@ -389,20 +404,24 @@ func (r *remoteState) probedOutcome(connection core.SSHConnection) *remoteProbeO } // resetEditing drops the last test or connection, its errors, the delete question and the WSL -// distribution shown. +// distribution or container shown. func (r *remoteState) resetEditing() { r.stopProbe() r.stopConnect() r.result, r.err, r.fieldErr, r.confirmDelete = nil, "", remoteFieldRefusal{}, false r.wsl.selected = "" + r.containers.selected = nil } -// syncListSelection selects the row of the edited connection or the WSL distribution shown, none -// for a new connection. +// syncListSelection selects the row of the edited connection, or of the WSL distribution or +// container shown, none for a new connection. func (r *remoteState) syncListSelection() { at := r.rowOf(r.selected) - if r.wsl.selected != "" { + switch { + case r.wsl.selected != "": at = r.wslRow(r.wsl.selected) + case r.containers.selected != nil: + at = r.containerRow(r.containers.selected.key()) } if r.list.Selected() != at { r.list.Select(at) diff --git a/desktop/internal/workbench/remote_browse.go b/desktop/internal/workbench/remote_browse.go index 644fed17a..5cc9493f4 100644 --- a/desktop/internal/workbench/remote_browse.go +++ b/desktop/internal/workbench/remote_browse.go @@ -24,14 +24,17 @@ import ( // the folder is chosen: Back, closing the window and quitting end it. Opening the folder hands it // to the workspace (remote_workspace.go) and remembers the folder with the connection. // -// Only a saved connection or a WSL distribution of this computer connects (remote_wsl.go), as -// shown: the workspace connects again with the same, and the folder it remembers belongs to the -// saved entry. OpenSSH's questions are asked in the authentication dialog, as a test asks them. +// Only a saved connection, a WSL distribution of this computer (remote_wsl.go), a running +// container of this computer (remote_container.go) or one running on the host a folder is chosen +// on (remote_host_containers.go) connects, as shown: the workspace connects again with the same, +// and the folder it remembers belongs to the saved entry. OpenSSH's questions are asked in the +// authentication dialog, as a test asks them. // remoteBrowser chooses the host folder to open over a session the window connected. type remoteBrowser struct { session core.RemoteSession - // entryID and name are the saved connection's, or the WSL distribution's identity and name. + // entryID and name are the saved connection's, or the WSL distribution's or the container's + // identity and name. entryID string name string host remoteHost @@ -57,6 +60,9 @@ type remoteBrowser struct { readErr string opening bool err string + // containers are the host's running containers, listed in place of its folders while set + // (remote_host_containers.go). + containers *remoteBrowserContainers } // stopConnect cancels a running connection; a session it opens anyway is ended when it returns. @@ -67,20 +73,29 @@ func (r *remoteState) stopConnect() { } } -// connectable says whether Connect may start for what the page shows: a WSL distribution, or a -// saved connection the form shows as saved; and nothing else runs. +// connectable says whether Connect may start for what the page shows: a WSL distribution, a +// container, or a saved connection the form shows as saved; and nothing else runs. func (r *remoteState) connectable() bool { - return r.open && r.browser == nil && r.connect == nil && r.probe == nil && !r.saving && - (r.wsl.selected != "" || (r.entry(r.selected) != nil && !r.dirty())) + return r.idle() && (r.wsl.selected != "" || r.containers.selected != nil || (r.entry(r.selected) != nil && !r.dirty())) } -// connectTarget is what Connect connects to: the WSL distribution shown, as an entry named after -// it with its identity for id, or the selected saved connection. +// idle says whether a connection may start: the window is open, and neither a folder is chosen, +// nor a connection, a test or a save runs. +func (r *remoteState) idle() bool { + return r.open && r.browser == nil && r.connect == nil && r.probe == nil && !r.saving +} + +// connectTarget is what Connect connects to: the WSL distribution or the container shown, as an +// entry named after it with its identity for id, or the selected saved connection. func (r *remoteState) connectTarget() (core.SavedRemoteConnection, remoteHost) { if r.wsl.selected != "" { wsl := r.wsl.connection() return core.SavedRemoteConnection{ID: wsl.Identity(), Name: wsl.Distribution}, remoteHost{wsl: &wsl} } + if r.containers.selected != nil { + container := r.containers.connection() + return core.SavedRemoteConnection{ID: container.Identity(), Name: container.Container}, remoteHost{container: &container} + } entry := *r.entry(r.selected) return entry, remoteHost{ssh: entry.Connection} } @@ -89,11 +104,20 @@ func (r *remoteState) connectTarget() (core.SavedRemoteConnection, remoteHost) { // asks on the page, then opens folder on it, or lists the host's folders to choose one when folder // is "". func (a *App) connectRemote(folder string) { + if !a.remote.connectable() { + return + } + entry, host := a.remote.connectTarget() + a.connectRemoteTo(entry, host, folder) +} + +// connectRemoteTo connects to host, named as entry, as connectRemote does: the connection the +// steps try again, and a container on the host a folder is chosen on (remote_host_containers.go). +func (a *App) connectRemoteTo(entry core.SavedRemoteConnection, host remoteHost, folder string) { r := &a.remote - if !r.connectable() { + if !r.idle() { return } - entry, host := r.connectTarget() r.result, r.err, r.fieldErr, r.confirmDelete, r.moreMenu = nil, "", remoteFieldRefusal{}, false, false a.performed("remote.connect", surfaceButton) ctx, cancel := context.WithTimeout(a.operationContext(context.Background()), remoteProbeTimeout) @@ -149,9 +173,12 @@ func (a *App) connectRemote(folder string) { a.operationRejected("remote_connect", "field_refused") r.steps = nil refusal := remoteFieldRefusal{field: field, reason: reason} - if host.wsl != nil { + switch { + case host.container != nil: + r.err = remoteContainerRefusalText(a.language(), refusal) + case host.wsl != nil: r.err = remoteWSLRefusalText(a.language(), refusal) - } else { + default: r.err = remoteRefusalText(a.language(), refusal) } return @@ -212,16 +239,19 @@ func (a *App) leaveRemoteBrowser() { } } -// leaveRemoteFlows ends the folder, trust or import page the window shows, so the list beside it -// can show another connection. It reports false, leaving them, while one of them is opening a -// folder or saving an import. +// leaveRemoteFlows ends the folder, trust, import or dev container page the window shows, so the +// list beside it can show another connection. It reports false, leaving them, while one of them is +// opening a folder, saving an import, or saving a folder's trust or building its dev container, +// which Cancel stops. func (a *App) leaveRemoteFlows() bool { r := &a.remote - if (r.trust != nil && r.trust.deciding) || (r.browser != nil && r.browser.opening) || (r.importer != nil && r.importer.applying) { + if (r.trust != nil && r.trust.deciding) || (r.browser != nil && r.browser.opening) || (r.importer != nil && r.importer.applying) || + (r.devcontainer != nil && r.devcontainer.busy()) { return false } r.trust = nil r.importer = nil + r.devcontainer = nil a.leaveRemoteBrowser() return true } @@ -435,7 +465,7 @@ func (a *App) openRemoteFolderNow(dir string, trusted bool) { return } b.opening, b.err = true, "" - entryID, remember := b.entryID, b.host.wsl == nil + entryID, remember := b.entryID, b.host.saved() generation, kernel, toolRoot := r.generation, a.kernel, a.globalToolchainRoot() a.background(nil, remoteReadTimeout, func(ctx context.Context) func(*App) { anchor, err := a.remotePlaceholderAnchor() diff --git a/desktop/internal/workbench/remote_browse_view.go b/desktop/internal/workbench/remote_browse_view.go index 7cee63bc5..8d20e6a26 100644 --- a/desktop/internal/workbench/remote_browse_view.go +++ b/desktop/internal/workbench/remote_browse_view.go @@ -19,13 +19,18 @@ const remoteFolderRowHeight = 34 // remoteBrowserView declares the browser: the connected host, the path field, the folders used // often, the path of the folder shown and its entries. A click selects a subfolder for Open; a -// double click or Enter lists it. Files show greyed, as what the folder holds. +// double click or Enter lists it. Files show greyed, as what the folder holds. While the host's +// containers are listed, they show in place of all but the head. func (a *App) remoteBrowserView(c ui.C, b *remoteBrowser) { language := a.language() k := c.Part("browser") ui.Column(k).Fill().Gap(12).PadSides(20, 24, 16, 24).Children(func() { a.remoteBrowserHead(k.Part("head"), language, b) ui.Row(k).FillWidth().Height(1).Shrink(0).Background(a.colors.Line) + if b.containers != nil { + a.remoteHostContainersView(k.Part("containers"), language, b.containers) + return + } ui.Row(k.Part("path")).FillWidth().Gap(8).Items(ui.Center).Children(func() { if ui.TextField(k.Part("field"), &b.path, i18n.Shared(language, "desktop.remote.browse.path"), i18n.Shared(language, "desktop.remote.browse.pathPlaceholder")). Grow(1).MinWidth(0).Disabled(b.opening).Submitted() { @@ -58,7 +63,8 @@ func (a *App) remoteBrowserView(c ui.C, b *remoteBrowser) { } // remoteBrowserHead declares the page's head: the host's mark, which host the folder is chosen -// on, that it is connected, its address and system, and Disconnect. +// on, that it is connected, its address and system, the host's containers for a host that can +// run them, and Disconnect. func (a *App) remoteBrowserHead(c ui.C, language i18n.Language, b *remoteBrowser) { r := &a.remote mark, system := "", "" @@ -71,7 +77,11 @@ func (a *App) remoteBrowserHead(c ui.C, language i18n.Language, b *remoteBrowser ui.Row(c).FillWidth().Items(ui.Center).Gap(14).Children(func() { a.remoteTile(c.Part("tile"), mark, b.name, color, remoteHeroTile, 15) ui.Column(c).Grow(1).Basis(0).MinWidth(0).Gap(5).Children(func() { - ui.Text(c, i18n.SharedFormat(language, "desktop.remote.browse.title", map[string]string{"name": b.name})). + title := i18n.SharedFormat(language, "desktop.remote.browse.title", map[string]string{"name": b.name}) + if b.containers != nil { + title = i18n.SharedFormat(language, "desktop.remote.hostContainers.title", map[string]string{"name": b.name}) + } + ui.Text(c, title). FontSize(16).Weight(gfx.WeightSemibold).Ellipsis().Shrink(1).MinWidth(0) ui.Row(c.Part("state")).FillWidth().Gap(8).Items(ui.Center).Children(func() { a.remoteStatusPill(c.Part("live"), i18n.Shared(language, "desktop.remote.browse.connected"), a.colors.Success) @@ -81,6 +91,10 @@ func (a *App) remoteBrowserHead(c ui.C, language i18n.Language, b *remoteBrowser } }) }) + if b.hostsContainers() && b.containers == nil && + ui.Button(c.Part("containers"), i18n.Shared(language, "desktop.remote.hostContainers.show")).Icon(icons.Server).Outline().Shrink(0).Disabled(b.opening).Clicked() { + c.After(a.showRemoteHostContainers) + } if ui.Button(c.Part("disconnect"), i18n.Shared(language, "desktop.remote.browse.disconnect")).Outline().Shrink(0).Disabled(b.opening).Clicked() { c.After(a.backFromRemoteBrowser) } @@ -253,6 +267,10 @@ func (a *App) remoteFolderList(c ui.C, b *remoteBrowser) { // it opens. func (a *App) remoteBrowserFooter(c ui.C, b *remoteBrowser) { language := a.language() + if b.containers != nil { + a.remoteHostContainersFooter(c, language, b.containers) + return + } ui.Spacer(c) if ui.Button(c.Part("back"), i18n.Shared(language, "desktop.remote.browse.back")).Outline().Disabled(b.opening).Clicked() { c.After(a.backFromRemoteBrowser) diff --git a/desktop/internal/workbench/remote_connections_visual_test.go b/desktop/internal/workbench/remote_connections_visual_test.go index 13ee38d16..95ffe1470 100644 --- a/desktop/internal/workbench/remote_connections_visual_test.go +++ b/desktop/internal/workbench/remote_connections_visual_test.go @@ -5,11 +5,13 @@ package workbench import ( "os" "path/filepath" + "strings" "testing" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/remoteconn" "github.com/1lck/Lithe-IDEA/desktop/internal/store" + "github.com/1lck/Lithe-IDEA/desktop/internal/toolchain" "github.com/vivaui/viva/app" "github.com/vivaui/viva/headless" ) @@ -18,8 +20,10 @@ import ( // saved, saved connections under their groups with the tested one's overview, its form, a new // connection whose host Core refused under its field, OpenSSH's password question over the window, // a refused test, the connection steps with OpenSSH's questions on the page and a failure, the -// question whether to trust a folder, Motty's hosts to import, the host's folders, and a WSL -// distribution's page and a failed connection to one. +// question whether to trust a folder, Motty's hosts to import, the host's folders and its running +// containers, a WSL +// distribution's page and a failed connection to one, a container's page and a failed connection +// to one, and a folder opening in its dev container, before and while it builds. func TestVisualRemoteConnections(t *testing.T) { out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") if out == "" { @@ -273,6 +277,25 @@ func TestVisualRemoteConnections(t *testing.T) { browser.path.SetText("/home/dev/src") r.browser = browser shot("folder") + + // The host's running Docker and Podman containers list in place of its folders, and one + // is entered as the user typed. The containers come from the host's docker ps and podman + // ps; the scene shows fixed ones. + browser.containers = &remoteBrowserContainers{engines: 2, list: []remoteListedContainer{ + {engine: core.ContainerEngineDocker, RemoteContainer: core.RemoteContainer{ + ID: strings.Repeat("c", 64), Name: "api-server", Image: "golang:1.26-bookworm", Status: "Up 3 days"}}, + {engine: core.ContainerEngineDocker, RemoteContainer: core.RemoteContainer{ + ID: strings.Repeat("e", 64), Name: "redis-cache", Image: "redis:8-alpine", Status: "Up 3 days"}}, + {engine: core.ContainerEnginePodman, RemoteContainer: core.RemoteContainer{ + ID: strings.Repeat("d", 64), Name: "pg-main", Image: "postgres:17", Status: "Up 1 hour"}}, + }} + // A list selects only among the rows it has drawn. + h.app.invalidator.Invalidate() + h.settleChain() + browser.containers.rows.Select(0) + browser.containers.user.SetText("app") + shot("host-containers") + browser.containers = nil r.browser = nil // This computer's WSL distributions list under their own heading, and one opens as the @@ -294,6 +317,65 @@ func TestVisualRemoteConnections(t *testing.T) { r.log.Open = true shot("wsl-failed") r.steps = nil + + // This computer's running Docker and Podman containers list after the distributions, + // and one opens as the user typed on its page; one that stopped fails with the engine's + // own text. The containers come from docker ps and podman ps; the scenes show fixed ones. + r.log.Open = false + r.containers.loaded = true + r.containers.list = []remoteListedContainer{ + {engine: core.ContainerEngineDocker, RemoteContainer: core.RemoteContainer{ + ID: strings.Repeat("a", 64), Name: "web-frontend", Image: "node:22-bookworm", Status: "Up 2 hours"}}, + {engine: core.ContainerEnginePodman, RemoteContainer: core.RemoteContainer{ + ID: strings.Repeat("b", 64), Name: "pg-main", Image: "postgres:17", Status: "Up 5 minutes"}}, + } + r.buildRows() + r.selectRemoteContainer(r.containers.list[0]) + r.containers.user.SetText("node") + shot("container") + r.selectRemoteContainer(r.containers.list[1]) + stopped := &core.ContainerConnection{Engine: core.ContainerEnginePodman, Container: "pg-main"} + steps = newRemoteSteps(core.SavedRemoteConnection{ID: stopped.Identity(), Name: "pg-main"}, remoteHost{container: stopped}, "", h.app.now()) + r.steps = steps + steps.fail(h.app.now(), &remoteProbeOutcome{result: core.RemoteProbeResult{ + Status: core.RemoteProbeUnreachable, Diagnostics: "Error: can only create exec sessions on running containers: container state improper", + }, engine: core.ContainerEnginePodman, at: h.app.now()}, h.app.language()) + r.log.Open = true + shot("container-failed") + r.steps = nil + + // A folder of this computer opens in its dev container: its devcontainer.json files + // list, an untrusted folder offers Trust and Build, and the CLI's log streams while it + // builds. The folder, its files and the log are fixed here. + r.log.Open = false + folder := "/Users/dev/src/payments-api" + d := &remoteDevcontainer{engine: core.ContainerEngineDocker, read: folder, config: ".devcontainer/devcontainer.json", + configs: []core.DevcontainerConfig{ + {Path: ".devcontainer/devcontainer.json", Name: "Go & PostgreSQL"}, + {Path: ".devcontainer/worker/devcontainer.json"}, + }, + trust: toolchain.WorkspaceTrust{Root: folder}, + } + d.folder.SetText(folder) + r.devcontainer = d + shot("devcontainer") + d.trusted, d.build = true, &remoteProbe{cancel: func() {}} + for _, line := range []string{ + "[1 ms] @devcontainers/cli 0.75.0. Node.js v22.11.0. darwin 25.0.0 arm64.", + "[4 ms] Start: Run: docker buildx build --load -t vsc-payments-api-features -f Dockerfile-with-features .", + "#1 [internal] load build definition from Dockerfile-with-features", + "#5 [dev_container_auto_added_stage_label 1/3] FROM mcr.microsoft.com/devcontainers/go:1.26", + "#7 [dev_containers_target_stage 2/3] COPY --from=dev_containers_feature_content_normalize /tmp/build-features/ /tmp/dev-container-features", + "#8 [dev_containers_target_stage 3/3] RUN /tmp/dev-container-features/postgresql_0/install.sh", + "#8 DONE 12.4s", + "[14821 ms] Start: Run: docker run --sig-proxy=false -a STDOUT -a STDERR --mount type=bind,source=/Users/dev/src/payments-api,target=/workspaces/payments-api", + "[15302 ms] Start: Run in container: /bin/sh -c go mod download", + } { + d.add(core.DevcontainerOutput{Text: line}) + } + shot("devcontainer-building") + d.build = nil + r.devcontainer = nil h.app.closeRemote() h.settleChain() }) diff --git a/desktop/internal/workbench/remote_container.go b/desktop/internal/workbench/remote_container.go new file mode 100644 index 000000000..9c9b7aa05 --- /dev/null +++ b/desktop/internal/workbench/remote_container.go @@ -0,0 +1,268 @@ +package workbench + +import ( + "context" + "slices" + "strconv" + "strings" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/ui" +) + +// The Remote Development window also opens the running Docker and Podman containers of this +// computer as remote workspaces (#2231, the first step of Dev Containers). Core lists them each +// time the window opens (remote.listContainers, once per engine, which answers unavailable +// without the engine's CLI), and the list shows them under their own heading after the WSL +// distributions, while no search is typed: a search finds saved connections only. +// +// Nothing about a container is saved. It connects through the engine's exec, as the user typed on +// its page or the image's default user, and asks nothing, so no authentication dialog opens. Core +// only enters the running container: it never starts, creates or changes it, mounts no folder and +// asks for no more rights than the engine CLI has (S32). The rest is the SSH path: the steps, the +// folder chosen in the container, the trust decision, which names the container, the workspace +// and its reconnection, which enters the container of the same name again. Its folders are not +// remembered, since the saved list holds SSH connections only. +// +// Neither the container, its image nor the user is logged; the engine's own words are shown under +// a failed connection and never logged. + +const ( + // remoteContainerHeading is the list's group of the containers' heading. No saved group can + // have it, since Core refuses control characters in one. + remoteContainerHeading = "\x00containers" + // remoteContainerTimeout bounds listing the containers of both engines. Core bounds each + // engine's CLI at 15 seconds, the time a first call may take to start the engine's service. + remoteContainerTimeout = 40 * time.Second +) + +// remoteContainerEngines are the engines the window lists, in the list's order. +var remoteContainerEngines = []string{core.ContainerEngineDocker, core.ContainerEnginePodman} + +// remoteListedContainer is a running container of engine on this computer. +type remoteListedContainer struct { + engine string + core.RemoteContainer +} + +// key tells the containers apart in the list: their engine and full id. +func (c remoteListedContainer) key() string { + return c.engine + ":" + c.ID +} + +// remoteContainers is the window's running containers. +type remoteContainers struct { + // loaded is set once Core answered for every engine; list is what it found, Docker's + // containers before Podman's. + loaded bool + list []remoteListedContainer + // selected is the container the page shows, nil while it shows anything else. + selected *remoteListedContainer + // user is the page's user inside the container; empty is the image's default user. + user ui.Field +} + +// connection is the selected container as the page connects to it: by name, so that a container +// created again under the same name is entered again. The user is passed as typed, and Core trims +// it. +func (c *remoteContainers) connection() core.ContainerConnection { + return core.ContainerConnection{Engine: c.selected.engine, Container: c.selected.Name, User: c.user.Text()} +} + +// remoteContainerEngineName is engine as the window names it: Docker or Podman. +func remoteContainerEngineName(language i18n.Language, engine string) string { + if engine == core.ContainerEnginePodman { + return i18n.Shared(language, "desktop.remote.container.podman") + } + return i18n.Shared(language, "desktop.remote.container.docker") +} + +// containersShown says whether the list shows the containers: Core found some, and no search is +// typed. +func (r *remoteState) containersShown() bool { + return r.found == nil && len(r.containers.list) > 0 +} + +// loadRemoteContainers asks Core for the running containers of each engine in the background and +// lists them. An engine without its CLI, or whose service does not answer, adds none. +func (a *App) loadRemoteContainers() { + r := &a.remote + generation, kernel := r.generation, a.kernel + a.background(nil, remoteContainerTimeout, func(ctx context.Context) func(*App) { + var listed []remoteListedContainer + var failure error + for _, engine := range remoteContainerEngines { + list, err := kernel.RemoteListContainers(ctx, engine, "") + if err != nil { + failure = err + continue + } + for _, container := range list.Containers { + listed = append(listed, remoteListedContainer{engine: engine, RemoteContainer: container}) + } + } + return func(a *App) { + r := &a.remote + if !r.open || r.generation != generation { + // log-exempt: 用户取消:窗口关闭后不再应用容器列表。 + return + } + r.containers.loaded = true + if failure != nil { + // The list only lacks that engine's containers; nothing else depends on them. + a.backgroundFailed("remote_containers_list", remoteLogError(failure)) + } + r.containers.list = listed + // The page of a listed container shows its image and state as listed now, such as the + // container a dev container's build just started. + if shown := r.containers.selected; shown != nil { + if at := slices.IndexFunc(listed, func(c remoteListedContainer) bool { return c.key() == shown.key() }); at >= 0 { + container := listed[at] + r.containers.selected = &container + } + } + r.buildRows() + r.syncListSelection() + } + }) +} + +// containerRows are the list's rows of the containers: their heading, and the containers unless +// the heading is folded. +func (r *remoteState) containerRows() []remoteListRow { + if !r.containersShown() { + return nil + } + rows := []remoteListRow{{heading: true, group: remoteContainerHeading, count: len(r.containers.list)}} + if r.collapsed[remoteContainerHeading] { + return rows + } + for i := range r.containers.list { + rows = append(rows, remoteListRow{container: &r.containers.list[i]}) + } + return rows +} + +// containerRow is the list row of the container key names, -1 when the list has none. +func (r *remoteState) containerRow(key string) int { + return slices.IndexFunc(r.rows, func(row remoteListRow) bool { return row.container != nil && row.container.key() == key }) +} + +// selectRemoteContainer shows the page of container, as the image's default user, dropping what +// the form held, the last test and its errors. +func (r *remoteState) selectRemoteContainer(container remoteListedContainer) { + r.resetEditing() + r.selected, r.editing = "", false + r.form.clear() + r.containers.selected = &container + r.containers.user.SetText("") + r.syncListSelection() +} + +// remoteContainerWindows counts the workspaces open in the container name of engine, as any user. +func (a *App) remoteContainerWindows(engine, name string) int { + return a.remoteWindowsWhere(func(id string) bool { + rest, ok := strings.CutPrefix(id, engine+":") + if !ok { + return false + } + if _, container, ok := strings.Cut(rest, "@"); ok { + rest = container + } + return rest == name + }) +} + +// remoteContainerRefusalText is the window's text for a container field Core refused. +func remoteContainerRefusalText(language i18n.Language, refusal remoteFieldRefusal) string { + if refusal.field == "user" { + return i18n.Shared(language, "desktop.remote.container.userInvalid") + } + return i18n.Shared(language, "desktop.remote.container.nameInvalid") +} + +// remoteContainerRow declares a container in the list: its mark, its name over its engine and +// image, and on the right whether a window has it open. +func (a *App) remoteContainerRow(row ui.ListRow, language i18n.Language, container remoteListedContainer) { + r := &a.remote + rc := row.C + small := a.theme.Metrics.FontSizeS + row.Element.Height(remoteRowHeight).Items(ui.Center).Gap(9).PadSides(0, 12, 0, 0).Radius(6) + if selected := r.containers.selected; selected != nil && selected.key() == container.key() { + row.Element.Background(a.colors.Selection) + } + // The stripe's room keeps the rows aligned with the saved connections'. + ui.Row(rc.Part("stripe")).Width(3).Height(remoteRowHeight - 14).Shrink(0) + a.remoteTile(rc.Part("tile"), "", container.Name, "", 26, 10) + ui.Column(rc).Grow(1).Basis(0).MinWidth(0).Gap(2).Children(func() { + ui.Text(rc, container.Name).Weight(gfx.WeightMedium).Ellipsis().MinWidth(0) + line := i18n.SharedFormat(language, "desktop.remote.container.row", map[string]string{ + "engine": remoteContainerEngineName(language, container.engine), "image": container.Image, + }) + ui.Text(rc, line).FontSize(small).Color(a.colors.Subtle).Ellipsis().MinWidth(0) + }) + if a.remoteContainerWindows(container.engine, container.Name) > 0 { + ui.Row(rc.Part("live")).Shrink(0).Items(ui.Center).Gap(5).Children(func() { + a.remoteDot(rc.Part("dot"), a.colors.Success, 6) + ui.Text(rc, i18n.Shared(language, "desktop.remote.connectedNow")).FontSize(small).Color(a.colors.Success) + }) + } +} + +// remoteContainerPage declares the selected container's page: its name, image and state, that it +// opens through its engine on this computer without being changed, the user it opens as, and +// Open Folder. +func (a *App) remoteContainerPage(c ui.C, language i18n.Language) { + r := &a.remote + container := *r.containers.selected + engine := remoteContainerEngineName(language, container.engine) + small := a.theme.Metrics.FontSizeS + ui.Scroll(c.Part("container")).Fill().Children(func() { + ui.Column(c).FillWidth().Gap(22).PadSides(20, 24, 24, 24).Children(func() { + a.remoteNotices(c) + h := c.Part("hero") + ui.Row(h).FillWidth().Items(ui.Center).Gap(14).Children(func() { + a.remoteTile(h.Part("tile"), "", container.Name, "", remoteHeroTile, 15) + ui.Column(h).Grow(1).Basis(0).MinWidth(0).Gap(5).Children(func() { + ui.Row(h).FillWidth().Items(ui.Center).Gap(8).Children(func() { + ui.Text(h, container.Name).FontSize(16).Weight(gfx.WeightSemibold).Ellipsis().Shrink(1).MinWidth(0) + a.remotePill(h.Part("kind"), engine, a.colors.Subtle) + if windows := a.remoteContainerWindows(container.engine, container.Name); windows > 0 { + a.remoteStatusPill(h.Part("live"), i18n.SharedFormat(language, "desktop.remote.connectedWindows", map[string]string{"count": strconv.Itoa(windows)}), a.colors.Success) + } + }) + connection := r.containers.connection() + ui.Text(h, connection.Identity()).Mono().FontSize(small).Color(a.colors.Subtle).Ellipsis().MinWidth(0) + state := i18n.SharedFormat(language, "desktop.remote.container.state", map[string]string{"image": container.Image, "status": container.Status}) + ui.Text(h, state).FontSize(small).Color(a.colors.Subtle).Ellipsis().MinWidth(0) + }) + if ui.Button(h.Part("open"), i18n.Shared(language, "desktop.remote.openFolder")).Icon(icons.FolderOpen).Shrink(0).Disabled(!r.connectable()).Clicked() { + c.After(func() { a.connectRemote("") }) + } + }) + ui.Paragraph(c.Part("about"), i18n.SharedFormat(language, "desktop.remote.container.about", map[string]string{"engine": engine}), 5).FontSize(small).Color(a.colors.Subtle) + label := i18n.Shared(language, "desktop.remote.container.user") + a.remoteSection(c.Part("account"), label, i18n.Shared(language, "desktop.remote.container.userHelp"), nil, func() { + ui.TextField(c.Part("user"), &r.containers.user, label, i18n.Shared(language, "desktop.remote.container.userPlaceholder")). + Width(260).Disabled(r.connect != nil || r.browser != nil) + }) + }) + }) +} + +// remoteContainerFooter declares the buttons under a container's page: Close, and Connect, which +// lists its folders to choose one. +func (a *App) remoteContainerFooter(c ui.C, language i18n.Language) { + r := &a.remote + ui.Spacer(c) + if ui.Button(c.Part("close"), i18n.Shared(language, "desktop.remote.close")).Outline().Clicked() { + c.After(a.closeRemote) + } + if ui.Button(c.Part("connect"), i18n.Shared(language, "desktop.remote.connect")).Disabled(!r.connectable()).Clicked() { + c.After(func() { a.connectRemote("") }) + } +} diff --git a/desktop/internal/workbench/remote_container_test.go b/desktop/internal/workbench/remote_container_test.go new file mode 100644 index 000000000..13c42ca49 --- /dev/null +++ b/desktop/internal/workbench/remote_container_test.go @@ -0,0 +1,342 @@ +package workbench + +import ( + "context" + "slices" + "strconv" + "strings" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteplaceholder" +) + +// The running containers of the test's computer: remoteTestContainer runs under Docker and +// connects, and remoteTestContainerGone runs under Podman and is gone by the time it is entered. +const ( + remoteTestContainer = "web-frontend" + remoteTestContainerGone = "pg-main" + remoteTestImage = "node:22-bookworm" +) + +// The test kernels over the real Core find no container engine, so that no test runs this +// computer's docker or podman: only remoteHostKernel lists containers, the ones its test sets. +func (k *testKernel) RemoteListContainers(context.Context, string, string) (core.RemoteContainers, error) { + return core.RemoteContainers{Containers: []core.RemoteContainer{}}, nil +} + +func (k *remoteProbeKernel) RemoteListContainers(context.Context, string, string) (core.RemoteContainers, error) { + return core.RemoteContainers{Containers: []core.RemoteContainer{}}, nil +} + +// Nor does any test run this computer's Dev Container CLI: the test kernels over the real Core +// find none, and only remoteHostKernel builds, as its test says (remote_devcontainer_test.go). +func (k *testKernel) RemoteDevcontainerUp(context.Context, core.DevcontainerUpRequest, func(core.DevcontainerOutput)) (core.DevcontainerUp, error) { + return core.DevcontainerUp{}, &core.Error{Command: "remote.devcontainerUp", Code: core.CodeRuntimeMissing, Message: "missing"} +} + +func (k *remoteProbeKernel) RemoteDevcontainerUp(context.Context, core.DevcontainerUpRequest, func(core.DevcontainerOutput)) (core.DevcontainerUp, error) { + return core.DevcontainerUp{}, &core.Error{Command: "remote.devcontainerUp", Code: core.CodeRuntimeMissing, Message: "missing"} +} + +// remoteHostContainers stands in for the engines' CLIs: each engine lists its containers, and +// only remoteTestContainer connects on this computer and remoteTestHostContainer on a host, each +// connection asked for being recorded. Its zero value lists none, as Core answers on a computer +// without either engine. +type remoteHostContainers struct { + // running are the containers each engine lists on this computer, and onHost those it lists + // over a session (remote_host_containers_test.go); an engine without an entry has no CLI. + // fail is the error an engine's listing ends with. + running, onHost map[string][]core.RemoteContainer + fail map[string]error + // listed are the engines listed and sessions the sessions they were listed over, in order. + listed, sessions []string + // requests are the connections asked for, in order, and hosts the hosts each went through: + // the SSH host, wsl:distribution, or "" for this computer. preferences counts those that + // carried the SSH preferences. + requests []core.ContainerConnection + hosts []string + preferences int + // refuse is the error the next connections end with; nil connects. + refuse error +} + +func (k *remoteHostKernel) RemoteListContainers(_ context.Context, engine, sessionID string) (core.RemoteContainers, error) { + k.mu.Lock() + defer k.mu.Unlock() + c := &k.containers + c.listed = append(c.listed, engine) + c.sessions = append(c.sessions, sessionID) + if err := c.fail[engine]; err != nil { + return core.RemoteContainers{}, err + } + containers := c.running + if sessionID != "" { + containers = c.onHost + } + running, ok := containers[engine] + return core.RemoteContainers{Available: ok, Containers: append([]core.RemoteContainer{}, running...)}, nil +} + +// connect answers the connect request numbered n, which names a container. It runs under the +// kernel's lock. +func (c *remoteHostContainers) connect(n int, request core.RemoteConnectRequest) (core.RemoteConnectResult, error) { + host, want := "", remoteTestContainer + switch { + case request.WSL != nil: + host, want = "wsl:"+request.WSL.Distribution, remoteTestHostContainer + case request.Connection != (core.SSHConnection{}): + host, want = request.Connection.Host, remoteTestHostContainer + } + c.requests = append(c.requests, *request.Container) + c.hosts = append(c.hosts, host) + if request.Preferences != nil { + c.preferences++ + } + if c.refuse != nil { + return core.RemoteConnectResult{}, c.refuse + } + if request.Container.Container != want || (request.WSL == nil && host != "" && host != remoteTestHost) { + return core.RemoteConnectResult{Status: core.RemoteProbeUnreachable}, nil + } + session := &core.RemoteSession{ID: "session-" + strconv.Itoa(n), HostName: "3f2a9c1d", UserName: "app", HomeDirectory: remoteTestHome} + return core.RemoteConnectResult{Status: core.RemoteProbeConnected, Session: session}, nil +} + +// remoteTestContainerKey is the list's key of the Docker container remoteTestContainer. +var remoteTestContainerKey = core.ContainerEngineDocker + ":" + strings.Repeat("a", 64) + +// remoteContainerHarness is remoteWorkspaceHarness on a computer running remoteTestContainer under +// Docker and remoteTestContainerGone under Podman, the window opened again so that it lists them. +func remoteContainerHarness(t *testing.T) (*harness, *remoteHostKernel, *treeRecordingLog) { + t.Helper() + h, k, _, logger := remoteWorkspaceHarness(t) + k.set(func(k *remoteHostKernel) { + k.containers.running = map[string][]core.RemoteContainer{ + core.ContainerEngineDocker: {{ID: strings.Repeat("a", 64), Name: remoteTestContainer, Image: remoteTestImage, Status: "Up 2 hours"}}, + core.ContainerEnginePodman: {{ID: strings.Repeat("b", 64), Name: remoteTestContainerGone, Image: "postgres:17", Status: "Up 5 minutes"}}, + } + }) + h.app.closeRemote() + h.app.openRemote(surfaceMenu) + h.await("the containers", func() bool { return h.app.remote.containers.loaded && !h.app.remote.loading }) + h.settle() + return h, k, logger +} + +// The window lists the running containers under their own heading after the saved connections, +// and a container's page opens a folder in it as the user typed: Core is asked to enter it through +// its engine, by name and without the SSH preferences, and the workspace names the container. +// Nothing is saved for it, and neither the container, its image nor the user is logged. +func TestRemoteContainerOpensAFolderInAContainer(t *testing.T) { + h, k, logger := remoteContainerHarness(t) + lang := h.app.language() + r := &h.app.remote + heading := i18n.Shared(lang, "desktop.remote.container.heading") + if !h.shows(heading) || !h.shows(remoteTestContainer) || !h.shows(remoteTestContainerGone) { + t.Fatal("the list does not show the containers' heading with the containers") + } + row := i18n.SharedFormat(lang, "desktop.remote.container.row", map[string]string{"engine": "Docker", "image": remoteTestImage}) + if !h.shows(row) { + t.Fatal("the container's row does not name its engine and image") + } + if at := r.containerRow(remoteTestContainerKey); at <= r.rowOf(r.selected) { + t.Fatalf("container row %d, saved row %d: the containers are not after the saved connections", at, r.rowOf(r.selected)) + } + + h.clickFront(remoteTestContainer) + h.settle() + if r.containers.selected == nil || r.containers.selected.key() != remoteTestContainerKey || r.selected != "" || + r.list.Selected() != r.containerRow(remoteTestContainerKey) { + t.Fatal("choosing the container does not show its page") + } + about := i18n.SharedFormat(lang, "desktop.remote.container.about", map[string]string{"engine": "Docker"}) + if !h.showsWrapped(about) || !h.shows("docker:"+remoteTestContainer) { + t.Fatal("the page does not say how the container opens") + } + r.containers.user.SetText("app") + h.redraw() + if !h.shows("docker:app@" + remoteTestContainer) { + t.Fatal("the page does not name the user typed") + } + + p := h.openBrowsedProject(t, h.connectAndBrowse(t)) + want := core.ContainerConnection{Engine: core.ContainerEngineDocker, Container: remoteTestContainer, User: "app"} + if got := k.containers.requests; len(got) != 1 || got[0] != want || k.containers.preferences != 0 || !slices.Equal(k.containers.hosts, []string{""}) { + t.Fatalf("asked for %d container connections, %d with SSH preferences; want the container by name as the user typed, on this computer", len(got), k.containers.preferences) + } + identity := "docker:app@" + remoteTestContainer + anchor, _ := h.app.remoteAnchor() + if want := remoteplaceholder.Root(anchor, identity, remoteTestHome+"/project"); p.root != want || p.remote.connectionID != identity { + t.Fatal("the workspace is not placed under the container's identity") + } + if got, want := h.app.projectDisplayName(p), "project [Container: "+remoteTestContainer+"]"; got != want { + t.Fatalf("title %q, want %q", got, want) + } + if status := remoteStatusText(lang, p.remote); !strings.HasPrefix(status, "Container: "+remoteTestContainer) || !h.shows(status) { + t.Fatalf("status %q does not name the container", status) + } + saved := savedRemoteConnections(t, h) + if len(saved) != 1 || len(saved[0].RecentFolders) != 0 || saved[0].LastConnectedAt != 0 { + t.Fatalf("%d saved connections: opening in a container changed the saved list", len(saved)) + } + if countFailures(logger, "remote_remember_folder") != 0 { + t.Fatal("remembering the folder was tried for a container") + } + actions := []string{"remote.connections.open", "remote.connection.new", "remote.connection.save", "remote.connections.open", "remote.container.select", "remote.connect", "remote.workspace.open"} + if got := remoteActions(logger); !slices.Equal(got, actions) { + t.Fatalf("performed %q, want %q", got, actions) + } + if event := loggedAny(t, logger, remoteTestContainer, remoteTestContainerGone, remoteTestImage, "app@", remoteTestHome); event != "" { + t.Fatal("logged a container, its image, the user or a host path") + } + + // Each opening of the window lists both engines on this computer, and a window over the + // container shows it connected, whatever the user. + h.app.openRemote(surfaceMenu) + h.await("the containers", func() bool { return h.app.remote.containers.loaded }) + var listed, sessions []string + k.set(func(k *remoteHostKernel) { + listed, sessions = slices.Clone(k.containers.listed), slices.Clone(k.containers.sessions) + }) + engines := []string{core.ContainerEngineDocker, core.ContainerEnginePodman} + if !slices.Equal(listed, slices.Concat(engines, engines, engines)) || slices.ContainsFunc(sessions, func(s string) bool { return s != "" }) { + t.Fatalf("listed %d times, want both engines on this computer at each of the 3 openings", len(listed)) + } + if h.app.remoteContainerWindows(core.ContainerEngineDocker, remoteTestContainer) != 1 || + h.app.remoteContainerWindows(core.ContainerEnginePodman, remoteTestContainer) != 0 || + h.app.remoteContainerWindows(core.ContainerEngineDocker, remoteTestContainerGone) != 0 { + t.Fatal("the windows open in the container are not counted by engine and name") + } +} + +// A container that is gone fails at the connection with the containers' own text and no OpenSSH +// hint, a refused user and a missing engine are explained, a search lists the saved connections +// only, and folding the heading hides the containers. +func TestRemoteContainerFailuresSearchAndFolding(t *testing.T) { + h, k, _ := remoteContainerHarness(t) + lang := h.app.language() + r := &h.app.remote + + h.clickFront(remoteTestContainerGone) + h.settle() + h.clickFront(i18n.Shared(lang, "desktop.remote.connect")) + h.await("the failed connection", func() bool { return r.steps != nil && r.steps.failed }) + h.settle() + outcome := r.steps.outcome + unreachable := i18n.Shared(lang, "desktop.remote.container.unreachable") + if outcome.engine != core.ContainerEnginePodman || remoteFailureText(lang, outcome) != unreachable || remoteFailureHint(lang, outcome) != "" { + t.Fatal("the failure does not read as a container's") + } + if !h.showsWrapped(unreachable) || h.showsWrapped(i18n.Shared(lang, "desktop.remote.probe.hint.unreachable")) { + t.Fatal("the page does not show the container's failure alone") + } + if !h.shows("podman:" + remoteTestContainerGone) { + t.Fatal("the steps do not name the container") + } + if !h.shows(i18n.Shared(lang, "desktop.remote.container.start")) || h.shows(i18n.Shared(lang, "desktop.remote.step.config")) || + h.shows(i18n.Shared(lang, "desktop.remote.step.authenticate")) || h.shows(i18n.Shared(lang, "desktop.remote.steps.editConnection")) { + t.Fatal("the steps of a container list OpenSSH's, or offer a connection's form") + } + + // Core refusing the user names the user, on the container's page. + h.app.stopRemoteConnect() + r.steps = nil + k.set(func(k *remoteHostKernel) { + k.containers.refuse = &core.Error{Command: "remote.connect", Code: core.CodeInvalidRequest, Message: "invalid", Details: `{"field":"user","reason":"invalid"}`} + }) + r.containers.user.SetText("root;id") + h.redraw() + h.clickFront(i18n.Shared(lang, "desktop.remote.connect")) + h.await("the refused user", func() bool { return r.connect == nil && r.err != "" }) + h.settle() + if r.err != i18n.Shared(lang, "desktop.remote.container.userInvalid") || r.steps != nil || !h.shows(r.err) { + t.Fatal("the refused user is not explained on the page") + } + + // Without the engine's CLI, the failure names the engine to install. + k.set(func(k *remoteHostKernel) { + k.containers.refuse = &core.Error{Command: "remote.connect", Code: core.CodeRuntimeMissing, Message: "missing"} + }) + r.containers.user.SetText("") + h.redraw() + h.clickFront(i18n.Shared(lang, "desktop.remote.connect")) + h.await("the missing engine", func() bool { return r.steps != nil && r.steps.failed }) + h.settle() + missing := i18n.SharedFormat(lang, "desktop.remote.container.missing", map[string]string{"engine": "Podman"}) + if remoteFailureText(lang, r.steps.outcome) != missing || !h.showsWrapped(missing) { + t.Fatal("the missing engine is not named") + } + h.app.stopRemoteConnect() + r.steps = nil + + // Choosing a saved connection leaves the container's page. + h.clickFront(remoteTestHost) + h.settle() + if r.containers.selected != nil || r.entry(r.selected) == nil { + t.Fatal("choosing the saved connection does not show it") + } + + r.query.SetText(remoteTestHost) + h.app.searchRemote() + h.await("the search", func() bool { return r.found != nil }) + h.settle() + if r.containerRow(remoteTestContainerKey) >= 0 || h.shows(remoteTestContainer) { + t.Fatal("a search lists the containers") + } + h.app.clearRemoteSearch() + h.settle() + if r.containerRow(remoteTestContainerKey) < 0 { + t.Fatal("clearing the search does not list the containers again") + } + h.app.toggleRemoteGroup(remoteContainerHeading) + h.redraw() + if r.containerRow(remoteTestContainerKey) >= 0 || !h.shows(i18n.Shared(lang, "desktop.remote.container.heading")) { + t.Fatal("folding the containers' heading does not keep the heading alone") + } +} + +// An engine whose listing fails leaves out its containers alone, and the failure is logged +// without what the other engine found. +func TestRemoteContainersKeepTheOtherEngineWhenOneFails(t *testing.T) { + h, k, _, logger := remoteWorkspaceHarness(t) + k.set(func(k *remoteHostKernel) { + k.containers.running = map[string][]core.RemoteContainer{ + core.ContainerEngineDocker: {{ID: strings.Repeat("a", 64), Name: remoteTestContainer, Image: remoteTestImage, Status: "Up 2 hours"}}, + } + k.containers.fail = map[string]error{core.ContainerEnginePodman: &core.Error{Command: "remote.listContainers", Code: core.CodeTimedOut, Message: "timed out"}} + }) + h.app.closeRemote() + h.app.openRemote(surfaceMenu) + h.await("the containers", func() bool { return h.app.remote.containers.loaded && !h.app.remote.loading }) + h.settle() + r := &h.app.remote + if r.containerRow(remoteTestContainerKey) < 0 || len(r.containers.list) != 1 || !h.shows(remoteTestContainer) { + t.Fatal("the containers of the engine that answered are not listed") + } + if countFailures(logger, "remote_containers_list") != 1 { + t.Fatal("the engine's failed listing is not logged once") + } + if event := loggedAny(t, logger, remoteTestContainer, remoteTestImage); event != "" { + t.Fatal("logged a container or its image") + } +} + +// Without an engine, Core answers the lists as unavailable, and the window shows no containers' +// heading. +func TestRemoteContainersAbsentShowsNothing(t *testing.T) { + h, k, _, _ := remoteWorkspaceHarness(t) + r := &h.app.remote + h.await("the containers", func() bool { return r.containers.loaded }) + h.settle() + if k.count(func(k *remoteHostKernel) int { return len(k.containers.listed) }) != 2 { + t.Fatal("the engines are not listed once each when the window opens") + } + if slices.ContainsFunc(r.rows, func(row remoteListRow) bool { return row.container != nil || row.group == remoteContainerHeading }) { + t.Fatal("the list shows container rows without an engine") + } + if h.shows(i18n.Shared(h.app.language(), "desktop.remote.container.heading")) { + t.Fatal("the window shows the containers' heading without an engine") + } +} diff --git a/desktop/internal/workbench/remote_detail_view.go b/desktop/internal/workbench/remote_detail_view.go index 1ad6896dd..af7616828 100644 --- a/desktop/internal/workbench/remote_detail_view.go +++ b/desktop/internal/workbench/remote_detail_view.go @@ -32,6 +32,8 @@ func (a *App) remotePage(c ui.C, language i18n.Language) { switch { case r.wsl.selected != "": a.remoteWSLPage(c, language) + case r.containers.selected != nil: + a.remoteContainerPage(c, language) case r.editing: a.remoteFormPage(c, language) case entry != nil: @@ -117,6 +119,9 @@ func (a *App) remoteEmptyPage(c ui.C, language i18n.Language) { if ui.Button(c.Part("manual"), i18n.Shared(language, "desktop.remote.empty.manual")).Link().Disabled(!r.editable()).Clicked() { c.After(a.newRemote) } + if ui.Button(c.Part("devcontainer"), i18n.Shared(language, "desktop.remote.devcontainer.open")).Link().Disabled(r.saving || r.connect != nil).Clicked() { + c.After(a.openRemoteDevcontainer) + } }) }) }) @@ -451,8 +456,9 @@ func (a *App) remoteHostTags(c ui.C, language i18n.Language, host core.RemotePro // remoteFailureHint says what to check after a test that did not connect, and is "" when there // is nothing more to say than why it failed. func remoteFailureHint(language i18n.Language, outcome *remoteProbeOutcome) string { - // The hints name OpenSSH's settings, which a WSL distribution does not have. - if outcome.err != nil || outcome.wsl { + // The hints name OpenSSH's settings, which a WSL distribution and a container of this + // computer do not have. + if outcome.err != nil || outcome.wsl || outcome.engine != "" { return "" } switch outcome.result.Status { @@ -583,6 +589,8 @@ func (a *App) remoteFooter(c ui.C, language i18n.Language) { switch { case r.wsl.selected != "": a.remoteWSLFooter(c, language) + case r.containers.selected != nil: + a.remoteContainerFooter(c, language) case r.editing: a.remoteFormFooter(c, language, entry) case entry != nil && r.confirmDelete: diff --git a/desktop/internal/workbench/remote_devcontainer.go b/desktop/internal/workbench/remote_devcontainer.go new file mode 100644 index 000000000..500a078df --- /dev/null +++ b/desktop/internal/workbench/remote_devcontainer.go @@ -0,0 +1,527 @@ +package workbench + +import ( + "context" + "errors" + "os" + "path/filepath" + "strings" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/1lck/Lithe-IDEA/desktop/internal/toolchain" + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/ui" +) + +// The Remote Development window opens a folder of this computer in its dev container (#2231, Dev +// Containers): the user chooses the folder, Core lists its devcontainer.json files +// (remote.devcontainerConfigs, which starts nothing), and Build runs the official Dev Container +// CLI's up under Docker or Podman (remote.devcontainerUp), whose log streams onto the page. Once +// the container runs, the window enters it as the configuration's remoteUser and opens its +// workspaceFolder, the way a listed container opens, the host's trust being asked as usual. +// +// Building runs the folder's code on this computer: its Dockerfile, features and lifecycle +// commands. So the folder must be trusted first, the same decision as opening it as a local +// project, asked on the page as Trust and Build. Lithe adds no mount, option or right of its own: +// the CLI does what devcontainer.json says (S32). +// +// Neither the folder, the configuration, the container nor its user is logged; the CLI's log is +// shown on the page and never logged. + +const ( + // remoteDevcontainerReadTimeout bounds listing a folder's configurations and reading its + // trust, both small reads of this computer. + remoteDevcontainerReadTimeout = 15 * time.Second + // remoteDevcontainerLines is how many of the CLI's latest lines the page keeps: Core sends at + // most 2 MiB of them, and the newest tell what is happening. + remoteDevcontainerLines = 5000 +) + +// errRemoteDevcontainerFailed is logged for an up the CLI itself reported failed, whose words are +// shown and never logged. +var errRemoteDevcontainerFailed = errors.New("the Dev Container CLI reported a failure") + +// remoteDevcontainer is the page that opens a folder of this computer in its dev container. +type remoteDevcontainer struct { + // folder is the folder as typed or chosen; read is the one last read, "" before. + folder ui.Field + read string + // reads numbers the reads, so that a read for a folder edited since is dropped; reading is + // set while one runs. + reads uint64 + reading bool + // configs are the folder's devcontainer.json files and config the one chosen. + configs []core.DevcontainerConfig + config string + // engine is the engine to build with: core.ContainerEngineDocker or Podman. + engine string + // trust is the folder's trust as read; trusted is set when its code may run, and location + // asks to trust the parent folder too when the folder is trusted on the page. trusting is set + // while the decision is saved. + trust toolchain.WorkspaceTrust + trusted bool + location bool + trusting bool + // build is the running up, nil while none runs; stopped is set once the user stopped one. + build *remoteProbe + stopped bool + // lines are the newest lines of the CLI's log, count how many arrived and seen how many the + // list showed; truncated is set once Core dropped later lines. + lines []string + count int + seen int + truncated bool + log ui.ListState + // err is the page's failure and diagnostics the CLI's own words under it. + err string + diagnostics string +} + +// busy says whether the page is saving the trust or building: the folder, the choices and Cancel +// wait for it. +func (d *remoteDevcontainer) busy() bool { + return d.trusting || d.build != nil +} + +// buildable says whether Build may start: the folder was read and has a configuration, and it is +// trusted or its trust can be saved. +func (d *remoteDevcontainer) buildable() bool { + return !d.busy() && !d.reading && d.read != "" && len(d.configs) > 0 && (d.trusted || d.trust.Root != "") +} + +// forget drops what was read for the folder once it is edited, and any read still running. +func (d *remoteDevcontainer) forget() { + d.reads++ + d.reading, d.read, d.configs, d.config = false, "", nil, "" + d.trust, d.trusted, d.location = toolchain.WorkspaceTrust{}, false, false + d.err, d.diagnostics = "", "" +} + +// add appends one line of the CLI's log, keeping the newest remoteDevcontainerLines. +func (d *remoteDevcontainer) add(line core.DevcontainerOutput) { + if line.Truncated { + d.truncated = true + return + } + d.lines = append(d.lines, line.Text) + d.count++ + if extra := len(d.lines) - remoteDevcontainerLines; extra > 0 { + d.lines = append(d.lines[:0:0], d.lines[extra:]...) + } +} + +// openRemoteDevcontainer shows the page, over the list's selection. +func (a *App) openRemoteDevcontainer() { + r := &a.remote + if !r.open || r.saving || r.connect != nil || r.devcontainer != nil || !a.leaveRemoteFlows() { + return + } + a.performed("remote.devcontainer.open", surfaceButton) + r.stopProbe() + r.steps = nil + r.devcontainer = &remoteDevcontainer{engine: core.ContainerEngineDocker} +} + +// leaveRemoteDevcontainer is Cancel and closing the window: a running build stops. +func (a *App) leaveRemoteDevcontainer() { + r := &a.remote + if d := r.devcontainer; d != nil && d.build != nil { + d.build.cancel() + } + r.devcontainer = nil +} + +// chooseRemoteDevcontainerFolder asks for the folder with the system's dialog, off the window +// thread, and reads the one chosen. +func (a *App) chooseRemoteDevcontainerFolder() { + r := &a.remote + d := r.devcontainer + if d == nil || d.busy() { + return + } + a.performed("remote.devcontainer.choose", surfaceButton) + generation, title := r.generation, i18n.Shared(a.language(), "desktop.remote.devcontainer.chooseTitle") + a.background(nil, 0, func(context.Context) func(*App) { + path, err := app.OpenDirectory(app.OpenDirectoryOptions{Title: title}) + return func(a *App) { + r := &a.remote + if errors.Is(err, app.ErrCanceled) { + // log-exempt: 用户取消:目录选择器没有选择结果。 + return + } + if err != nil { + a.operationFailed("remote_devcontainer_choose", documentLogError(err)) + } + if !r.open || r.generation != generation || r.devcontainer != d || d.busy() { + // log-exempt: 用户取消:页面已离开或正在构建,不再应用目录选择结果。 + return + } + if err != nil { + d.err = i18n.SharedFormat(a.language(), "desktop.remote.chooseFailed", map[string]string{"reason": documentLogError(err).Error()}) + return + } + d.folder.SetText(path) + a.readRemoteDevcontainer() + } + }) +} + +// readRemoteDevcontainer lists the folder's configurations and reads its trust in the background, +// choosing the first configuration, the one the specification looks for first. +func (a *App) readRemoteDevcontainer() { + r := &a.remote + d := r.devcontainer + if d == nil || d.busy() { + return + } + folder := strings.TrimSpace(d.folder.Text()) + if filepath.IsAbs(folder) { + folder = filepath.Clean(folder) + } + if folder == "" { + return + } + d.forget() + d.reading = true + reads, generation, kernel, root, everyTrusted := d.reads, r.generation, a.kernel, a.globalToolchainRoot(), a.trustEveryWorkspace + a.background(nil, remoteDevcontainerReadTimeout, func(ctx context.Context) func(*App) { + configs, err := kernel.RemoteDevcontainerConfigs(ctx, folder) + var trust toolchain.WorkspaceTrust + var trustErr error + if err == nil && !everyTrusted { + trust, trustErr = toolchain.ReadWorkspaceTrust(ctx, kernel, root, folder) + } + return func(a *App) { + r := &a.remote + if !r.open || r.generation != generation || r.devcontainer != d || d.reads != reads { + // log-exempt: 用户取消:页面已离开或文件夹已改,不再应用读取结果。 + return + } + d.reading = false + language := a.language() + if err != nil { + a.operationFailed("remote_devcontainer_configs", remoteLogError(err)) + var coreErr *core.Error + switch { + case errors.As(err, &coreErr) && coreErr.Code == core.CodeInvalidRequest: + d.err = i18n.Shared(language, "desktop.remote.devcontainer.folderRelative") + case errors.As(err, &coreErr) && coreErr.Code == core.CodeWorkspaceNotFound: + d.err = i18n.Shared(language, "desktop.remote.devcontainer.folderMissing") + default: + d.err = i18n.SharedFormat(language, "desktop.remote.devcontainer.readFailed", map[string]string{"reason": remoteLogError(err).Error()}) + } + return + } + d.read, d.configs = folder, configs + if len(configs) > 0 { + d.config = configs[0].Path + } + switch { + case everyTrusted: + d.trusted = true + case trustErr != nil: + // Building waits for a trust that can be read: nothing says the folder's code may run. + a.backgroundFailed("workspace_trust_read", documentLogError(trustErr)) + d.err = i18n.SharedFormat(language, "desktop.remote.devcontainer.trustFailed", map[string]string{"reason": documentLogError(trustErr).Error()}) + default: + d.trust, d.trusted = trust, trust.State == core.WorkspaceTrusted + } + } + }) +} + +// startRemoteDevcontainer is Build: it builds at once in a trusted folder, and otherwise first +// saves the folder as trusted, as Trust and Build says. +func (a *App) startRemoteDevcontainer() { + r := &a.remote + d := r.devcontainer + if d == nil || !d.buildable() { + return + } + if d.trusted { + a.buildRemoteDevcontainer(d) + return + } + d.trusting, d.err, d.diagnostics = true, "", "" + generation := r.generation + a.saveWorkspaceTrust(d.trust, true, d.location && d.trust.OfferedLocation != nil, func(saved bool) { + d.trusting = false + r := &a.remote + if !saved || !r.open || r.generation != generation || r.devcontainer != d { + // log-exempt: 用户取消:信任未保存(已提示并记录)或页面已离开,不再构建。 + return + } + d.trusted = true + a.buildRemoteDevcontainer(d) + }) +} + +// buildRemoteDevcontainer runs the CLI's up for the page's folder and configuration in the +// background, showing its log as it comes, and enters the container it started. +func (a *App) buildRemoteDevcontainer(d *remoteDevcontainer) { + r := &a.remote + a.performed("remote.devcontainer.build", surfaceButton) + ctx, cancel := context.WithCancel(a.operationContext(context.Background())) + build := &remoteProbe{cancel: cancel} + d.build, d.stopped = build, false + d.lines, d.count, d.seen, d.truncated, d.log = nil, 0, 0, false, ui.ListState{} + d.err, d.diagnostics = "", "" + request := core.DevcontainerUpRequest{Folder: d.read, Config: d.config, Engine: d.engine, ProjectCodeAllowed: true} + generation, kernel := r.generation, a.kernel + output := func(line core.DevcontainerOutput) { + a.post(func(a *App) { + if a.remote.devcontainer == d && d.build == build { + d.add(line) + } + }) + } + a.background(nil, 0, func(context.Context) func(*App) { + defer cancel() + result, err := kernel.RemoteDevcontainerUp(ctx, request, output) + return func(a *App) { + r := &a.remote + if !r.open || r.generation != generation || r.devcontainer != d || d.build != build { + // log-exempt: 用户取消:构建已停止或窗口已关闭,不再进入容器。 + return + } + d.build = nil + a.finishRemoteDevcontainer(d, result, err) + } + }) +} + +// finishRemoteDevcontainer shows a failed up on the page, or enters the container it started and +// opens its workspace folder. +func (a *App) finishRemoteDevcontainer(d *remoteDevcontainer, result core.DevcontainerUp, err error) { + r := &a.remote + language := a.language() + if err != nil { + a.operationFailed("remote_devcontainer_up", remoteLogError(err)) + var coreErr *core.Error + code := core.CodeUnknown + if errors.As(err, &coreErr) { + code = coreErr.Code + } + switch code { + case core.CodeRuntimeMissing: + d.err = i18n.Shared(language, "desktop.remote.devcontainer.missing") + case core.CodeTimedOut: + d.err = i18n.Shared(language, "desktop.remote.devcontainer.timedOut") + case core.CodeParseFailed: + d.err = i18n.Shared(language, "desktop.remote.devcontainer.unusable") + case core.CodeDevcontainerUntrustedFolder: + d.trusted = false + d.err = i18n.Shared(language, "desktop.remote.devcontainer.untrustedRefused") + default: + reason := err.Error() + if coreErr != nil { + reason = coreErr.Message + } + d.err = i18n.SharedFormat(language, "desktop.remote.devcontainer.upFailed", map[string]string{"reason": reason}) + } + return + } + c := result.Container + if c == nil { + a.operationFailed("remote_devcontainer_up", errRemoteDevcontainerFailed) + d.err, d.diagnostics = i18n.Shared(language, "desktop.remote.devcontainer.failed"), result.Diagnostics + return + } + r.devcontainer = nil + r.selectRemoteContainer(remoteListedContainer{engine: c.Engine, RemoteContainer: core.RemoteContainer{ID: c.ContainerID, Name: c.Container}}) + r.containers.user.SetText(c.User) + // The list shows the container once listed again, with its image and state. + a.loadRemoteContainers() + a.connectRemote(c.WorkspaceFolder) +} + +// stopRemoteDevcontainer is Stop: the CLI is stopped, and the page keeps its log. +func (a *App) stopRemoteDevcontainer() { + d := a.remote.devcontainer + if d == nil || d.build == nil { + return + } + a.performed("remote.devcontainer.stop", surfaceButton) + d.build.cancel() + d.build, d.stopped = nil, true +} + +// remoteDevcontainerConfigLabel names a configuration in the picker: its name with its path, or +// its path. +func remoteDevcontainerConfigLabel(language i18n.Language, configs []core.DevcontainerConfig, path string) string { + for _, config := range configs { + if config.Path == path && config.Name != "" { + return i18n.SharedFormat(language, "desktop.remote.devcontainer.configNamed", map[string]string{"name": config.Name, "path": path}) + } + } + return path +} + +// remoteDevcontainerView declares the page: what it does, the folder, its configuration and +// engine, its trust, and the CLI's log. +func (a *App) remoteDevcontainerView(c ui.C, language i18n.Language, d *remoteDevcontainer) { + small := a.theme.Metrics.FontSizeS + ui.Column(c.Part("devcontainer")).Fill().Gap(18).PadSides(20, 24, 16, 24).Children(func() { + h := c.Part("hero") + ui.Row(h).FillWidth().Shrink(0).Items(ui.Center).Gap(14).Children(func() { + ui.Row(h.Part("mark")).Size(40, 40).Shrink(0).Center().Radius(10).Background(a.colors.Hover).Stroke(1, a.colors.Line).Children(func() { + ui.Icon(h, icons.FileCode).Size(20, 20).Color(a.colors.Subtle) + }) + ui.Column(h).Grow(1).Basis(0).MinWidth(0).Gap(4).Children(func() { + ui.Text(h, i18n.Shared(language, "desktop.remote.devcontainer.title")).FontSize(16).Weight(gfx.WeightSemibold).Ellipsis().MinWidth(0) + ui.Paragraph(h.Part("about"), i18n.Shared(language, "desktop.remote.devcontainer.about"), 3).FontSize(small).Color(a.colors.Subtle) + }) + }) + label := i18n.Shared(language, "desktop.remote.devcontainer.folder") + a.remoteSection(c.Part("folder"), label, "", nil, func() { + field := ui.TextField(c.Part("folder-field"), &d.folder, label, i18n.Shared(language, "desktop.remote.devcontainer.folderPlaceholder")). + Mono().FillWidth().Disabled(d.busy()).Action(icons.FolderOpen, i18n.Shared(language, "desktop.remote.devcontainer.choose")) + if field.Changed() { + c.After(d.forget) + } + if field.Submitted() { + c.After(func() { + a.performed("remote.devcontainer.read", surfaceShortcut) + a.readRemoteDevcontainer() + }) + } + if field.ActionClicked() { + c.After(a.chooseRemoteDevcontainerFolder) + } + if d.reading { + ui.Text(c, i18n.Shared(language, "native.loading")).FontSize(small).Color(a.colors.Subtle) + } + }) + if d.read != "" { + ui.Row(c.Part("choices")).FillWidth().Shrink(0).Gap(16).Items(ui.Start).Children(func() { + ui.Column(c.Part("config")).Grow(1).Basis(0).MinWidth(0).Children(func() { + config := i18n.Shared(language, "desktop.remote.devcontainer.config") + a.remoteSection(c, config, i18n.Shared(language, "desktop.remote.devcontainer.configHelp"), nil, func() { + if len(d.configs) == 0 { + ui.Paragraph(c.Part("none"), i18n.Shared(language, "desktop.remote.devcontainer.none"), 3).FontSize(small).Color(a.colors.Warning) + return + } + paths := make([]string, len(d.configs)) + for i, config := range d.configs { + paths[i] = config.Path + } + configs := d.configs + ui.Select(c.Part("config-select"), &d.config, paths, func(path string) string { + return remoteDevcontainerConfigLabel(language, configs, path) + }).Label(config).FillWidth().Disabled(d.busy()) + }) + }) + ui.Column(c.Part("engine")).Width(180).Shrink(0).Children(func() { + engine := i18n.Shared(language, "desktop.remote.devcontainer.engine") + a.remoteSection(c, engine, i18n.Shared(language, "desktop.remote.devcontainer.engineHelp"), nil, func() { + ui.Select(c.Part("engine-select"), &d.engine, remoteContainerEngines, func(engine string) string { + return remoteContainerEngineName(language, engine) + }).Label(engine).FillWidth().Disabled(d.busy()) + }) + }) + }) + if !d.trusted && d.trust.Root != "" { + ui.Column(c.Part("trust")).FillWidth().Shrink(0).Gap(8).Children(func() { + a.remoteNotice(c, icons.ShieldCheck, a.colors.Warning, i18n.Shared(language, "desktop.remote.devcontainer.untrusted")) + if offered := d.trust.OfferedLocation; offered != nil { + home, _ := os.UserHomeDir() + text := i18n.SharedFormat(language, "desktop.trust.location", map[string]string{"folder": trustFolderLabel(*offered, home)}) + ui.Checkbox(c.Part("location"), &d.location, text).Disabled(d.busy()) + } + }) + } + } + if d.err != "" { + ui.Column(c.Part("error")).FillWidth().Shrink(0).Gap(8).Children(func() { + a.remoteNotice(c, icons.CircleX, a.theme.Danger, d.err) + if d.diagnostics != "" { + l := c.Part("diagnostics") + ui.Scroll(l).FillWidth().MaxHeight(120).Children(func() { + ui.Column(l).FillWidth().Pad(10).Radius(6).Background(a.colors.Hover).Stroke(1, a.colors.Line).Children(func() { + ui.Paragraph(l.Part("text"), d.diagnostics, 40).Mono().FontSize(small).Color(a.colors.Subtle) + }) + }) + } + }) + } + if d.stopped { + a.remoteNotice(c.Part("stopped"), icons.Info, a.colors.Subtle, i18n.Shared(language, "desktop.remote.devcontainer.stopped")) + } + if d.build != nil || len(d.lines) > 0 { + a.remoteDevcontainerLog(c.Part("log"), language, d) + } + }) +} + +// remoteDevcontainerLog declares the CLI's log: its newest lines, in a list that follows new lines +// while it shows its end. +func (a *App) remoteDevcontainerLog(c ui.C, language i18n.Language, d *remoteDevcontainer) { + small := a.theme.Metrics.FontSizeS + title := i18n.Shared(language, "desktop.remote.devcontainer.log") + ui.Column(c).FillWidth().Grow(1).Basis(0).MinHeight(120).Gap(8).Children(func() { + ui.Row(c.Part("head")).FillWidth().Height(22).Shrink(0).Items(ui.Center).Gap(4).Children(func() { + ui.Text(c, title).FontSize(small).Weight(gfx.WeightSemibold).Color(a.colors.Subtle).Shrink(0) + a.remoteHelp(c, i18n.Shared(language, "desktop.remote.devcontainer.logHelp")) + }) + a.remoteBordered(c.Part("box")).Grow(1).Basis(0).MinHeight(0).Background(a.colors.Hover).Children(func() { + box := c.Part("box") + if len(d.lines) == 0 { + ui.Row(box.Part("waiting")).FillWidth().Pad(10).Items(ui.Center).Gap(8).Children(func() { + ui.Text(box, i18n.Shared(language, "desktop.remote.devcontainer.logWaiting")).FontSize(small).Color(a.colors.Subtle) + }) + return + } + list := &d.log + if d.seen != d.count { + if d.seen == 0 || list.AtEnd() { + list.ScrollToEnd() + } + d.seen = d.count + } + lines := d.lines + list.Label = func(i int) string { return lines[i] } + ui.List(box, list, len(lines), func(row ui.ListRow) { + row.Element.Height(18).PadX(10).Items(ui.Center) + ui.Text(row.C, lines[row.Index]).FontSize(12).Mono().Color(a.colors.Text).Ellipsis().MinWidth(0) + }).Scrollbars().Label(title).Fill() + }) + if d.truncated { + ui.Text(c.Part("truncated"), i18n.Shared(language, "desktop.remote.devcontainer.truncated")).FontSize(small).Color(a.colors.Subtle) + } + }) +} + +// remoteDevcontainerFooter declares the buttons under the page: Cancel, and Build, or Stop while +// it builds. +func (a *App) remoteDevcontainerFooter(c ui.C, language i18n.Language, d *remoteDevcontainer) { + ui.Row(c).FillWidth().Items(ui.Center).Gap(8).Children(func() { + status := "" + if d.build != nil { + status = i18n.Shared(language, "desktop.remote.devcontainer.building") + } + ui.Text(c, status).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Grow(1).MinWidth(0).Ellipsis() + if ui.Button(c.Part("cancel"), i18n.Shared(language, "desktop.remote.cancel")).Outline().Disabled(d.trusting).Clicked() { + c.After(func() { + a.performed("remote.devcontainer.cancel", surfaceButton) + a.leaveRemoteDevcontainer() + }) + } + if d.build != nil { + if ui.Button(c.Part("stop"), i18n.Shared(language, "desktop.remote.stop")).Icon(icons.Square).Clicked() { + c.After(a.stopRemoteDevcontainer) + } + return + } + label := i18n.Shared(language, "desktop.remote.devcontainer.build") + if !d.trusted && d.trust.Root != "" { + label = i18n.Shared(language, "desktop.remote.devcontainer.trustAndBuild") + } + if ui.Button(c.Part("build"), label).Icon(icons.Play).Disabled(!d.buildable()).Clicked() { + c.After(a.startRemoteDevcontainer) + } + }) +} diff --git a/desktop/internal/workbench/remote_devcontainer_test.go b/desktop/internal/workbench/remote_devcontainer_test.go new file mode 100644 index 000000000..4482e9fb8 --- /dev/null +++ b/desktop/internal/workbench/remote_devcontainer_test.go @@ -0,0 +1,350 @@ +package workbench + +import ( + "context" + "os" + "path/filepath" + "slices" + "strings" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteplaceholder" + "github.com/1lck/Lithe-IDEA/desktop/internal/toolchain" +) + +// remoteHostDevcontainers stands in for this computer's Dev Container CLI: an up records what it +// was asked, prints lines and ends with result or fail, or with block set prints lines and runs +// until it is stopped. Listing a folder's configurations is the real Core's. +type remoteHostDevcontainers struct { + requests []core.DevcontainerUpRequest + lines []string + result core.DevcontainerUp + fail error + block bool + // ended counts the ups that returned. + ended int +} + +func (k *remoteHostKernel) RemoteDevcontainerUp(ctx context.Context, request core.DevcontainerUpRequest, output func(core.DevcontainerOutput)) (core.DevcontainerUp, error) { + k.mu.Lock() + d := &k.devcontainers + d.requests = append(d.requests, request) + lines, result, fail, block := slices.Clone(d.lines), d.result, d.fail, d.block + k.mu.Unlock() + defer k.set(func(k *remoteHostKernel) { k.devcontainers.ended++ }) + for _, line := range lines { + output(core.DevcontainerOutput{Text: line}) + } + if block { + timer := time.NewTimer(10 * time.Second) + defer timer.Stop() + select { + case <-ctx.Done(): + case <-timer.C: + } + return core.DevcontainerUp{}, &core.Error{Command: "remote.devcontainerUp", Code: core.CodeCancelled, Message: "cancelled"} + } + return result, fail +} + +// remoteTestConfig is the folder's first devcontainer.json, which names its configuration. +const remoteTestConfig = ".devcontainer/devcontainer.json" + +// remoteDevcontainerFolder is a new folder of this computer with two devcontainer.json files: the +// one the specification looks for first, named Go, and one in a folder below .devcontainer. +func remoteDevcontainerFolder(t *testing.T) string { + t.Helper() + folder := filepath.Join(t.TempDir(), "service") + files := map[string]string{ + remoteTestConfig: `{"name": "Go", "image": "golang:1.26"}`, + ".devcontainer/node/devcontainer.json": `{"image": "node:22"}`, + } + for name, text := range files { + path := filepath.Join(folder, filepath.FromSlash(name)) + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(path, []byte(text), 0o644); err != nil { + t.Fatal(err) + } + } + return folder +} + +// remoteDevcontainerHarness is remoteContainerHarness whose CLI starts remoteTestContainer as app, +// with the Dev Container page open on folder, read. +func remoteDevcontainerHarness(t *testing.T, folder string, trusting bool) (*harness, *remoteHostKernel, *treeRecordingLog) { + t.Helper() + h, k, logger := remoteContainerHarness(t) + h.app.trustEveryWorkspace = !trusting + k.set(func(k *remoteHostKernel) { + k.devcontainers.result = core.DevcontainerUp{Container: &core.Devcontainer{ + Engine: core.ContainerEngineDocker, Container: remoteTestContainer, ContainerID: strings.Repeat("a", 64), + User: "app", WorkspaceFolder: remoteTestFolder, + }} + }) + lang := h.app.language() + h.clickFront(i18n.Shared(lang, "desktop.remote.devcontainer.open")) + h.settle() + if h.app.remote.devcontainer == nil || !h.shows(i18n.Shared(lang, "desktop.remote.devcontainer.title")) { + t.Fatal("the toolbar does not open the Dev Container page") + } + h.driver.QueueOpenDirectory(folder, nil) + h.clickFront(i18n.Shared(lang, "desktop.remote.devcontainer.choose")) + awaitRemoteDevcontainerRead(t, h) + return h, k, logger +} + +// pressFront clicks the front-most control named label and paints the next frame, without +// waiting for background work, such as an up that runs until it is stopped. +func (h *harness) pressFront(label string) { + h.t.Helper() + point := center(h.frontLabeled(label)) + if err := h.driver.Click(point.X, point.Y); err != nil { + h.t.Fatal(err) + } + if err := h.driver.Pump(); err != nil { + h.t.Fatal(err) + } +} + +// awaitRemoteDevcontainerRead waits for the page's folder to be read. +func awaitRemoteDevcontainerRead(t *testing.T, h *harness) { + t.Helper() + awaitStateWithin(t, h, 10*time.Second, "the folder's configurations", func() bool { + d := h.app.remote.devcontainer + return d != nil && !d.reading && (d.read != "" || d.err != "") + }) + h.settle() +} + +// awaitRemoteDevcontainerWorkspace waits for the workspace opened in the container. +func awaitRemoteDevcontainerWorkspace(t *testing.T, h *harness) *project { + t.Helper() + awaitStateWithin(t, h, 10*time.Second, "the container's workspace", func() bool { + p := h.app.project + return p != nil && p.remote != nil && !p.remote.beating && p.tree.root != nil && p.tree.root.listed && !p.tree.reading + }) + h.settle() + return h.app.project +} + +// Choosing a folder lists its devcontainer.json files, the specification's first chosen, and Build +// runs the CLI's up for it, allowed to run the folder's code, under the engine chosen. The window +// then enters the container the CLI started as its remoteUser and opens its workspaceFolder, the +// container's way: by engine and name, its trust asked of the host. Neither the folder, the +// configuration, the container nor its user is logged. +func TestRemoteDevcontainerBuildsAndOpensTheWorkspaceFolder(t *testing.T) { + folder := remoteDevcontainerFolder(t) + h, k, logger := remoteDevcontainerHarness(t, folder, false) + lang := h.app.language() + r := &h.app.remote + d := r.devcontainer + paths := make([]string, len(d.configs)) + for i, config := range d.configs { + paths[i] = config.Path + } + if d.read != folder || !slices.Equal(paths, []string{remoteTestConfig, ".devcontainer/node/devcontainer.json"}) || d.config != remoteTestConfig { + t.Fatalf("read %d configurations, chose %q; want both, the specification's first chosen", len(paths), d.config) + } + named := i18n.SharedFormat(lang, "desktop.remote.devcontainer.configNamed", map[string]string{"name": "Go", "path": remoteTestConfig}) + if !h.shows(named) || !h.shows(i18n.Shared(lang, "desktop.remote.devcontainer.build")) || + h.shows(i18n.Shared(lang, "desktop.remote.devcontainer.trustAndBuild")) { + t.Fatal("the page does not show the named configuration and Build") + } + + h.clickFront(i18n.Shared(lang, "desktop.remote.devcontainer.build")) + p := awaitRemoteDevcontainerWorkspace(t, h) + want := core.DevcontainerUpRequest{Folder: folder, Config: remoteTestConfig, Engine: core.ContainerEngineDocker, ProjectCodeAllowed: true} + if got := k.devcontainers.requests; len(got) != 1 || got[0] != want { + t.Fatalf("asked for %d ups; want one for the folder's first configuration under Docker", len(got)) + } + connection := core.ContainerConnection{Engine: core.ContainerEngineDocker, Container: remoteTestContainer, User: "app"} + if got := k.containers.requests; len(got) != 1 || got[0] != connection { + t.Fatalf("asked for %d container connections; want the container started, as its remoteUser", len(got)) + } + identity := "docker:app@" + remoteTestContainer + anchor, _ := h.app.remoteAnchor() + if want := remoteplaceholder.Root(anchor, identity, remoteTestFolder); p.root != want || p.remote.connectionID != identity { + t.Fatal("the workspace folder is not opened in the container") + } + if r.devcontainer != nil || r.containers.selected == nil || r.containers.selected.key() != remoteTestContainerKey || + r.containers.selected.Image != remoteTestImage { + t.Fatal("the window does not show the started container's page as listed") + } + actions := []string{"remote.connections.open", "remote.connection.new", "remote.connection.save", "remote.connections.open", + "remote.devcontainer.open", "remote.devcontainer.choose", "remote.devcontainer.build", "remote.connect"} + if got := remoteActions(logger); !slices.Equal(got, actions) { + t.Fatalf("performed %q, want %q", got, actions) + } + if event := loggedAny(t, logger, folder, "service", "Go", remoteTestConfig, remoteTestContainer, "app@", remoteTestHome); event != "" { + t.Fatal("logged the folder, its configuration, the container or its user") + } +} + +// A folder that is not trusted shows why building trusts it, and Trust and Build saves the folder +// as trusted, the same decision as opening it as a project, before the CLI runs its code. +func TestRemoteDevcontainerTrustsTheFolderBeforeBuilding(t *testing.T) { + folder := remoteDevcontainerFolder(t) + h, k, logger := remoteDevcontainerHarness(t, folder, true) + lang := h.app.language() + d := h.app.remote.devcontainer + trustAndBuild := i18n.Shared(lang, "desktop.remote.devcontainer.trustAndBuild") + if d.trusted || d.trust.Root == "" || !h.showsWrapped(i18n.Shared(lang, "desktop.remote.devcontainer.untrusted")) || !h.shows(trustAndBuild) { + t.Fatal("the page does not say the folder is not trusted") + } + h.clickFront(trustAndBuild) + awaitRemoteDevcontainerWorkspace(t, h) + if got := k.count(func(k *remoteHostKernel) int { return len(k.devcontainers.requests) }); got != 1 { + t.Fatalf("asked for %d ups after trusting, want 1", got) + } + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + trust, err := toolchain.ReadWorkspaceTrust(ctx, k, h.app.globalToolchainRoot(), folder) + if err != nil { + t.Fatal(err) + } + if trust.State != core.WorkspaceTrusted { + t.Fatalf("the folder's trust is %q, want trusted", trust.State) + } + actions := remoteActions(logger) + if at := slices.Index(actions, "remote.devcontainer.build"); at < 0 || !loggedAction(logger, "workspace.trust.grant") { + t.Fatalf("performed %q: the folder was not trusted before building", actions) + } +} + +// loggedAction reports whether action was performed. +func loggedAction(logger *treeRecordingLog, action string) bool { + logger.mu.Lock() + defer logger.mu.Unlock() + return slices.ContainsFunc(logger.events, func(event core.LogEvent) bool { + got, _ := event.Fields["action"].(string) + return event.Event == "app.action.performed" && got == action + }) +} + +// A failed up explains itself on the page: a missing CLI says how to install it, a failure the CLI +// reported shows its words, which are not logged, and Core refusing an untrusted folder says +// nothing was built. Each failure is logged once by its code alone, and nothing is entered. +func TestRemoteDevcontainerFailuresAreExplained(t *testing.T) { + folder := remoteDevcontainerFolder(t) + h, k, logger := remoteDevcontainerHarness(t, folder, false) + lang := h.app.language() + d := h.app.remote.devcontainer + build := i18n.Shared(lang, "desktop.remote.devcontainer.build") + diagnostics := "Error: Command failed: docker build -f Dockerfile.private-dev" + for i, failure := range []struct { + name string + result core.DevcontainerUp + fail error + text string + }{ + {"missing", core.DevcontainerUp{}, &core.Error{Command: "remote.devcontainerUp", Code: core.CodeRuntimeMissing, Message: "missing"}, "desktop.remote.devcontainer.missing"}, + {"reported", core.DevcontainerUp{Diagnostics: diagnostics}, nil, "desktop.remote.devcontainer.failed"}, + {"untrusted", core.DevcontainerUp{}, &core.Error{Command: "remote.devcontainerUp", Code: core.CodeDevcontainerUntrustedFolder, Message: "untrusted"}, "desktop.remote.devcontainer.untrustedRefused"}, + } { + k.set(func(k *remoteHostKernel) { k.devcontainers.result, k.devcontainers.fail = failure.result, failure.fail }) + d.trusted = true + h.redraw() + h.clickFront(build) + awaitStateWithin(t, h, 10*time.Second, failure.name, func() bool { return d.build == nil && d.err != "" }) + h.settle() + if text := i18n.Shared(lang, failure.text); d.err != text || !h.showsWrapped(text) { + t.Fatalf("%s: the page does not explain the failure", failure.name) + } + if got := countFailures(logger, "remote_devcontainer_up"); got != i+1 { + t.Fatalf("%s: %d failures logged, want %d", failure.name, got, i+1) + } + } + if d.trusted { + t.Fatal("Core refusing an untrusted folder leaves it trusted on the page") + } + if got := k.count(func(k *remoteHostKernel) int { return len(k.containers.requests) }); got != 0 { + t.Fatalf("asked for %d container connections after failed ups", got) + } + if event := loggedAny(t, logger, diagnostics, "Dockerfile.private-dev"); event != "" { + t.Fatal("logged the CLI's words") + } +} + +// Stop stops the CLI while its log keeps what it printed, the up's late result is dropped, the +// list's other entries wait while it builds, and Cancel leaves the page. +func TestRemoteDevcontainerStopKeepsTheLog(t *testing.T) { + folder := remoteDevcontainerFolder(t) + h, k, logger := remoteDevcontainerHarness(t, folder, false) + lang := h.app.language() + r := &h.app.remote + d := r.devcontainer + lines := []string{"[2 ms] Start: Run: docker buildx build", "#5 [1/3] FROM golang:1.26"} + k.set(func(k *remoteHostKernel) { k.devcontainers.lines, k.devcontainers.block = lines, true }) + // The up runs until it is stopped, so the test paints frames without waiting for it. + h.pressFront(i18n.Shared(lang, "desktop.remote.devcontainer.build")) + awaitStateWithin(t, h, 10*time.Second, "the CLI's log", func() bool { return slices.Equal(d.lines, lines) && h.shows(lines[1]) }) + if d.build == nil || !h.shows(i18n.Shared(lang, "desktop.remote.devcontainer.building")) || !h.shows(i18n.Shared(lang, "desktop.remote.stop")) { + t.Fatal("the page does not show the CLI's log with Stop while it builds") + } + + // The list's other entries wait for the build. + h.pressFront(remoteTestContainer) + if r.devcontainer != d || r.containers.selected != nil { + t.Fatal("choosing a listed container left the page while it builds") + } + + h.pressFront(i18n.Shared(lang, "desktop.remote.stop")) + h.settle() + if got := k.count(func(k *remoteHostKernel) int { return k.devcontainers.ended }); got != 1 { + t.Fatalf("%d ups ended after Stop, want 1", got) + } + if d.build != nil || !d.stopped || d.err != "" || !slices.Equal(d.lines, lines) || r.devcontainer != d { + t.Fatal("stopping does not keep the page with its log") + } + if !h.showsWrapped(i18n.Shared(lang, "desktop.remote.devcontainer.stopped")) || !h.shows(lines[1]) { + t.Fatal("the page does not say the build was stopped") + } + if countFailures(logger, "remote_devcontainer_up") != 0 || k.count(func(k *remoteHostKernel) int { return len(k.containers.requests) }) != 0 { + t.Fatal("the stopped up's result was applied") + } + + h.clickFront(i18n.Shared(lang, "desktop.remote.cancel")) + h.settle() + if r.devcontainer != nil { + t.Fatal("Cancel does not leave the page") + } + if event := loggedAny(t, logger, lines[0], lines[1]); event != "" { + t.Fatal("logged the CLI's log") + } +} + +// A folder typed instead of chosen is read on Return: Core refuses a relative path and a missing +// folder, and a folder without devcontainer.json cannot be built. +func TestRemoteDevcontainerFolderErrors(t *testing.T) { + h, _, _ := remoteContainerHarness(t) + lang := h.app.language() + h.app.openRemoteDevcontainer() + h.settle() + d := h.app.remote.devcontainer + empty := t.TempDir() + for _, typed := range []struct { + folder, text string + }{ + {"relative/service", "desktop.remote.devcontainer.folderRelative"}, + {filepath.Join(empty, "gone"), "desktop.remote.devcontainer.folderMissing"}, + {empty, ""}, + } { + d.folder.SetText(typed.folder) + h.app.readRemoteDevcontainer() + awaitRemoteDevcontainerRead(t, h) + if typed.text == "" { + continue + } + if text := i18n.Shared(lang, typed.text); d.err != text || d.read != "" || !h.showsWrapped(text) { + t.Fatalf("%s: the page does not explain the folder", typed.text) + } + } + if d.read != empty || len(d.configs) != 0 || d.buildable() || !h.showsWrapped(i18n.Shared(lang, "desktop.remote.devcontainer.none")) { + t.Fatal("a folder without devcontainer.json does not say so, or may be built") + } +} diff --git a/desktop/internal/workbench/remote_host_containers.go b/desktop/internal/workbench/remote_host_containers.go new file mode 100644 index 000000000..e97b21c9a --- /dev/null +++ b/desktop/internal/workbench/remote_host_containers.go @@ -0,0 +1,232 @@ +package workbench + +import ( + "context" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/ui" +) + +// While a folder is chosen on an SSH host or a WSL distribution, the browser also lists the +// Docker and Podman containers running there and opens one as a remote workspace (#2231, R2). +// Core lists them over the browser's session (remote.listContainers with its id, once per engine), +// in the server's environment, which is the one entering a container then uses: what is listed can +// be entered. A host without an engine's CLI lists none of its containers. +// +// Entering a container ends the browser's session and connects again, to the host and on into the +// container through its engine's exec, as the user typed or the image's default user: the steps +// are the host's, OpenSSH asks again what it asks, and the folder is then chosen in the container. +// As for a container of this computer, Core never starts, creates or changes it, mounts no folder +// and asks for no more rights than the engine CLI has there (S32), and the trust decision names +// the host and the container. Nothing is saved for it: the workspace's identity is the host's and +// the container's, and its folders are not remembered. +// +// Neither the container, its image nor the user is logged; the engines' own words are shown and +// never logged. + +// remoteBrowserContainers is the running containers of the host a folder is chosen on, which the +// browser lists in place of the host's folders while it is set. +type remoteBrowserContainers struct { + loading bool + // list is what Core found, Docker's containers before Podman's; engines counts the engines + // whose CLI ran on the host. + list []remoteListedContainer + engines int + // diagnostics are what an engine printed when it ran and failed, such as that its service is + // not running: upstream text, shown and never logged. + diagnostics []string + // err is why the containers could not be listed for another reason. + err string + rows ui.ListState + // user is the user to enter the selected container as; empty is the image's default user. + user ui.Field +} + +// hostsContainers says whether the browser's host can list containers to enter: an SSH host or a +// WSL distribution, not a container. +func (b *remoteBrowser) hostsContainers() bool { + return b.host.container == nil +} + +// selectedContainer is the container the list selects, nil when it selects none. +func (l *remoteBrowserContainers) selectedContainer() *remoteListedContainer { + if at := l.rows.Selected(); at >= 0 && at < len(l.list) { + return &l.list[at] + } + return nil +} + +// showRemoteHostContainers lists the running containers of the browser's host in place of its +// folders. +func (a *App) showRemoteHostContainers() { + r := &a.remote + b := r.browser + if b == nil || b.opening || !b.hostsContainers() { + return + } + a.performed("remote.browse.containers", surfaceButton) + list := &remoteBrowserContainers{loading: true} + b.containers = list + generation, kernel, session := r.generation, a.kernel, b.session.ID + a.background(nil, remoteContainerTimeout, func(ctx context.Context) func(*App) { + var found []remoteListedContainer + var diagnostics []string + engines := 0 + var failure error + for _, engine := range remoteContainerEngines { + listed, err := kernel.RemoteListContainers(ctx, engine, session) + if err != nil { + failure = err + if remoteConnectionClosed(err) { + break + } + continue + } + if listed.Available { + engines++ + } + if listed.Diagnostics != "" { + diagnostics = append(diagnostics, listed.Diagnostics) + } + for _, container := range listed.Containers { + found = append(found, remoteListedContainer{engine: engine, RemoteContainer: container}) + } + } + return func(a *App) { + r := &a.remote + if !r.open || r.generation != generation || r.browser != b || b.containers != list { + // log-exempt: 用户取消:已回到文件夹、返回或关闭窗口,不再应用容器列表。 + return + } + list.loading = false + list.list, list.engines, list.diagnostics = found, engines, diagnostics + if failure != nil { + a.operationFailed("remote_host_containers_list", remoteLogError(failure)) + if remoteConnectionClosed(failure) { + // The session is gone: choosing over it cannot go on. + a.leaveRemoteBrowser() + r.err = i18n.Shared(a.language(), "desktop.remote.browse.lost") + return + } + list.err = i18n.SharedFormat(a.language(), "desktop.remote.hostContainers.failed", map[string]string{"reason": remoteLogError(failure).Error()}) + } + } + }) +} + +// hideRemoteHostContainers shows the host's folders again. +func (a *App) hideRemoteHostContainers() { + b := a.remote.browser + if b == nil || b.containers == nil { + return + } + a.performed("remote.browse.folders", surfaceButton) + b.containers = nil +} + +// remoteHostContainerTarget is the selected container of b's host as Connect connects to it: by +// name, as the user typed, after b's SSH connection or WSL distribution, named after both, with +// an identity no saved connection, WSL distribution or container of this computer has. +func remoteHostContainerTarget(language i18n.Language, b *remoteBrowser, container remoteListedContainer) (core.SavedRemoteConnection, remoteHost) { + connection := core.ContainerConnection{Engine: container.engine, Container: container.Name, User: b.containers.user.Text()} + host := remoteHost{ssh: b.host.ssh, wsl: b.host.wsl, container: &connection} + name := i18n.SharedFormat(language, "desktop.remote.hostContainers.name", map[string]string{"container": container.Name, "host": b.name}) + return core.SavedRemoteConnection{ID: b.entryID + "/" + connection.Identity(), Name: name}, host +} + +// enterRemoteHostContainer ends the browser's session and connects to the selected container on +// its host, listing the container's folders to choose one. +func (a *App) enterRemoteHostContainer() { + r := &a.remote + b := r.browser + if b == nil || b.opening || b.containers == nil { + return + } + container := b.containers.selectedContainer() + if container == nil { + return + } + a.performed("remote.browse.container.enter", surfaceButton) + entry, host := remoteHostContainerTarget(a.language(), b, *container) + a.leaveRemoteBrowser() + a.connectRemoteTo(entry, host, "") +} + +// remoteHostContainersView declares the host's containers in place of its folders: the user to +// enter as, the list, and the engines' words when listing failed. +func (a *App) remoteHostContainersView(c ui.C, language i18n.Language, list *remoteBrowserContainers) { + small := a.theme.Metrics.FontSizeS + ui.Paragraph(c.Part("about"), i18n.Shared(language, "desktop.remote.hostContainers.about"), 4).FontSize(small).Color(a.colors.Subtle) + label := i18n.Shared(language, "desktop.remote.container.user") + ui.Row(c.Part("account")).FillWidth().Gap(8).Items(ui.Center).Children(func() { + ui.Text(c, label).FontSize(small).Shrink(0) + ui.TextField(c.Part("user"), &list.user, label, i18n.Shared(language, "desktop.remote.container.userPlaceholder")).Width(260) + }) + if list.err != "" { + a.remoteNotice(c.Part("error"), icons.CircleAlert, a.theme.Danger, list.err) + } + ui.Column(c.Part("rows")).FillWidth().Grow(1).Shrink(1).MinHeight(0). + Border(1, a.colors.Line).Radius(a.theme.Metrics.RadiusItem()).Clip().Children(func() { + if list.loading || len(list.list) == 0 { + text := i18n.Shared(language, "desktop.remote.hostContainers.empty") + switch { + case list.loading: + text = i18n.Shared(language, "native.loading") + case list.engines == 0 && list.err == "": + text = i18n.Shared(language, "desktop.remote.hostContainers.noEngine") + } + ui.Column(c.Part("empty")).FillWidth().Pad(12).Gap(8).Children(func() { + ui.Paragraph(c, text, 3).FontSize(small).Color(a.colors.Subtle) + for i, words := range list.diagnostics { + ui.Paragraph(c.KeyInt(i), words, 6).Mono().FontSize(small).Color(a.colors.Subtle) + } + }) + return + } + list.rows.Label = func(row int) string { + if row >= 0 && row < len(list.list) { + return list.list[row].Name + } + return "" + } + ui.List(c.Part("list"), &list.rows, len(list.list), func(row ui.ListRow) { + rc := row.C + container := list.list[row.Index] + row.Element.Height(remoteRowHeight).PadX(12).Gap(10).Items(ui.Center) + if row.Selected() { + row.Element.Background(a.colors.Selection) + } else { + row.Element.Hover(ui.Look{}.Background(a.colors.Hover)) + } + row.Element.Children(func() { + a.remoteTile(rc.Part("tile"), "", container.Name, "", 26, 10) + ui.Column(rc).Grow(1).Basis(0).MinWidth(0).Gap(2).Children(func() { + ui.Text(rc, container.Name).Weight(gfx.WeightMedium).Ellipsis().MinWidth(0) + line := i18n.SharedFormat(language, "desktop.remote.container.row", map[string]string{ + "engine": remoteContainerEngineName(language, container.engine), "image": container.Image, + }) + ui.Text(rc, line).FontSize(small).Color(a.colors.Subtle).Ellipsis().MinWidth(0) + }) + ui.Text(rc, container.Status).FontSize(small).Color(a.colors.Subtle).Ellipsis().Shrink(1).MinWidth(0) + }) + }).Scrollbars().FillWidth().Grow(1).Shrink(1).MinHeight(0).Label(i18n.Shared(language, "desktop.remote.container.heading")) + if _, ok := list.rows.Submitted(); ok { + c.After(a.enterRemoteHostContainer) + } + }) +} + +// remoteHostContainersFooter declares the buttons under the host's containers: back to its +// folders, and Enter Container, which connects to the selected one. +func (a *App) remoteHostContainersFooter(c ui.C, language i18n.Language, list *remoteBrowserContainers) { + ui.Spacer(c) + if ui.Button(c.Part("folders"), i18n.Shared(language, "desktop.remote.hostContainers.back")).Outline().Clicked() { + c.After(a.hideRemoteHostContainers) + } + if ui.Button(c.Part("enter"), i18n.Shared(language, "desktop.remote.hostContainers.enter")).Disabled(list.selectedContainer() == nil).Clicked() { + c.After(a.enterRemoteHostContainer) + } +} diff --git a/desktop/internal/workbench/remote_host_containers_test.go b/desktop/internal/workbench/remote_host_containers_test.go new file mode 100644 index 000000000..c28b84483 --- /dev/null +++ b/desktop/internal/workbench/remote_host_containers_test.go @@ -0,0 +1,220 @@ +package workbench + +import ( + "slices" + "strings" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteplaceholder" +) + +// The running containers of the saved host remoteTestHost: remoteTestHostContainer runs under +// Docker and connects, and remoteTestContainerGone runs under Podman and is gone by the time it is +// entered. +const ( + remoteTestHostContainer = "api-server" + remoteTestHostImage = "golang:1.26-bookworm" +) + +// remoteHostContainersHarness is remoteContainerHarness whose saved host also runs containers, +// connected and browsing the host's home folder, the host's containers listed in place of its +// folders. +func remoteHostContainersHarness(t *testing.T) (*harness, *remoteHostKernel, *treeRecordingLog, *remoteBrowser) { + t.Helper() + h, k, logger := remoteContainerHarness(t) + k.set(func(k *remoteHostKernel) { + k.containers.onHost = map[string][]core.RemoteContainer{ + core.ContainerEngineDocker: {{ID: strings.Repeat("c", 64), Name: remoteTestHostContainer, Image: remoteTestHostImage, Status: "Up 3 days"}}, + core.ContainerEnginePodman: {{ID: strings.Repeat("d", 64), Name: remoteTestContainerGone, Image: "postgres:17", Status: "Up 1 hour"}}, + } + }) + if h.app.remote.entry(h.app.remote.selected) == nil { + t.Fatal("the saved connection is not selected") + } + b := h.connectAndBrowse(t) + k.set(func(k *remoteHostKernel) { k.containers.listed, k.containers.sessions = nil, nil }) + h.clickFront(i18n.Shared(h.app.language(), "desktop.remote.hostContainers.show")) + h.await("the host's containers", func() bool { return b.containers != nil && !b.containers.loading }) + h.settle() + return h, k, logger, b +} + +// On a saved SSH host, the folder browser lists the host's running containers over its own session, +// both engines, and Enter Container ends that session and connects to the host and on into the +// container as the user typed, logging in as the host does: the workspace's identity is the +// connection's and the container's, it is named after both, and nothing is remembered with the +// saved connection. Neither the host, the container, its image, the user nor a host path is logged. +func TestRemoteHostContainersOpenAFolderInAContainerOnTheHost(t *testing.T) { + h, k, logger, b := remoteHostContainersHarness(t) + lang := h.app.language() + r := &h.app.remote + entryID, session := b.entryID, b.session.ID + var listed, sessions []string + k.set(func(k *remoteHostKernel) { + listed, sessions = slices.Clone(k.containers.listed), slices.Clone(k.containers.sessions) + }) + if !slices.Equal(listed, []string{core.ContainerEngineDocker, core.ContainerEnginePodman}) || !slices.Equal(sessions, []string{session, session}) { + t.Fatalf("listed %d times, want both engines over the browser's session", len(listed)) + } + if len(b.containers.list) != 2 || b.containers.list[0].Name != remoteTestHostContainer || b.containers.engines != 2 { + t.Fatal("the browser does not list the host's containers, Docker's first") + } + row := i18n.SharedFormat(lang, "desktop.remote.container.row", map[string]string{"engine": "Docker", "image": remoteTestHostImage}) + title := i18n.SharedFormat(lang, "desktop.remote.hostContainers.title", map[string]string{"name": b.name}) + if !h.shows(title) || !h.shows(remoteTestHostContainer) || !h.shows(row) || !h.showsWrapped(i18n.Shared(lang, "desktop.remote.hostContainers.about")) { + t.Fatal("the browser does not show the host's containers") + } + enter := i18n.Shared(lang, "desktop.remote.hostContainers.enter") + enabled := false + for _, hit := range h.driver.Snapshot().Hits { + if hit.Label == enter && !hit.IsLabel { + enabled = !hit.Disabled + } + } + if enabled || b.containers.selectedContainer() != nil { + t.Fatal("Enter Container is enabled with no container selected") + } + + b.containers.user.SetText("app") + b.containers.rows.Select(0) + h.redraw() + h.clickFront(enter) + h.await("the container's folders", func() bool { + next := r.browser + return next != nil && next != b && !next.loading + }) + h.settle() + want := core.ContainerConnection{Engine: core.ContainerEngineDocker, Container: remoteTestHostContainer, User: "app"} + var closed []string + var requests []core.ContainerConnection + var hosts []string + k.set(func(k *remoteHostKernel) { + closed, requests, hosts = slices.Clone(k.closed), slices.Clone(k.containers.requests), slices.Clone(k.containers.hosts) + }) + if !slices.Contains(closed, session) { + t.Fatal("entering the container does not end the browser's session") + } + // The harness keeps no settings, so no connection carries the preferences; that a container on + // an SSH host is connected with them is remoteHost.overSSH's (TestRemoteHostOfAContainer). + if len(requests) != 1 || requests[0] != want || !slices.Equal(hosts, []string{remoteTestHost}) || !r.browser.host.hosted() || !r.browser.host.overSSH() { + t.Fatalf("asked for %d container connections; want the container on the host as the user typed", len(requests)) + } + if h.shows(i18n.Shared(lang, "desktop.remote.hostContainers.show")) { + t.Fatal("a container's browser offers the containers of a host") + } + + name := i18n.SharedFormat(lang, "desktop.remote.hostContainers.name", map[string]string{"container": remoteTestHostContainer, "host": b.name}) + p := h.openBrowsedProject(t, r.browser) + identity := entryID + "/docker:app@" + remoteTestHostContainer + anchor, _ := h.app.remoteAnchor() + if want := remoteplaceholder.Root(anchor, identity, remoteTestHome+"/project"); p.root != want || p.remote.connectionID != identity { + t.Fatal("the workspace is not placed under the connection's and the container's identity") + } + if got, want := h.app.projectDisplayName(p), "project [Container: "+name+"]"; got != want { + t.Fatalf("title %q, want %q", got, want) + } + saved := savedRemoteConnections(t, h) + if len(saved) != 1 || len(saved[0].RecentFolders) != 0 { + t.Fatalf("%d saved connections: opening in a container on the host remembered the folder", len(saved)) + } + if countFailures(logger, "remote_remember_folder") != 0 { + t.Fatal("remembering the folder was tried for a container on the host") + } + actions := []string{ + "remote.connections.open", "remote.connection.new", "remote.connection.save", "remote.connections.open", + "remote.connect", "remote.browse.containers", "remote.browse.container.enter", "remote.connect", "remote.workspace.open", + } + if got := remoteActions(logger); !slices.Equal(got, actions) { + t.Fatalf("performed %q, want %q", got, actions) + } + if event := loggedAny(t, logger, remoteTestHost, remoteTestHostContainer, remoteTestContainerGone, remoteTestHostImage, "app@", remoteTestHome); event != "" { + t.Fatal("logged the host, a container, its image, the user or a host path") + } +} + +// A container on the host that is gone fails with the text of a container on a host, which names +// its engine, without OpenSSH's hint or the connection's form, and Retry enters the same container +// on the host again. Back to Folders shows the host's folders. +func TestRemoteHostContainerFailureRetriesTheContainer(t *testing.T) { + h, k, _, b := remoteHostContainersHarness(t) + lang := h.app.language() + r := &h.app.remote + + h.clickFront(i18n.Shared(lang, "desktop.remote.hostContainers.back")) + h.settle() + if b.containers != nil || !h.shows("project") { + t.Fatal("Back to Folders does not show the host's folders") + } + h.clickFront(i18n.Shared(lang, "desktop.remote.hostContainers.show")) + h.await("the host's containers", func() bool { return b.containers != nil && !b.containers.loading }) + h.settle() + + b.containers.rows.Select(1) + h.redraw() + h.clickFront(i18n.Shared(lang, "desktop.remote.hostContainers.enter")) + h.await("the failed connection", func() bool { return r.steps != nil && r.steps.failed }) + h.settle() + outcome := r.steps.outcome + text := i18n.SharedFormat(lang, "desktop.remote.container.hostUnreachable", map[string]string{"engine": "Podman"}) + if !outcome.hosted || remoteFailureText(lang, outcome) != text || remoteFailureHint(lang, outcome) != "" { + t.Fatal("the failure does not read as a container's on a host") + } + if !h.showsWrapped(text) || h.shows(i18n.Shared(lang, "desktop.remote.steps.editConnection")) { + t.Fatal("the page does not show the failure alone, or offers the connection's form") + } + if address := r.steps.host.address(); !strings.HasSuffix(address, " › podman:"+remoteTestContainerGone) || !h.shows(address) { + t.Fatal("the steps do not name the host and the container") + } + + h.clickFront(i18n.Shared(lang, "desktop.remote.steps.retry")) + h.await("the second failed connection", func() bool { + return r.steps != nil && r.steps.failed && k.count(func(k *remoteHostKernel) int { return len(k.containers.requests) }) == 2 + }) + var requests []core.ContainerConnection + var hosts []string + k.set(func(k *remoteHostKernel) { + requests, hosts = slices.Clone(k.containers.requests), slices.Clone(k.containers.hosts) + }) + gone := core.ContainerConnection{Engine: core.ContainerEnginePodman, Container: remoteTestContainerGone} + if !slices.Equal(requests, []core.ContainerConnection{gone, gone}) || !slices.Equal(hosts, []string{remoteTestHost, remoteTestHost}) { + t.Fatalf("asked for %d container connections; Retry does not enter the same container on the host", len(requests)) + } +} + +// A container on an SSH host or a WSL distribution logs in as its host does, is never a saved +// connection, and is named after its host and itself; one of this computer goes through no host. +func TestRemoteHostOfAContainer(t *testing.T) { + ssh := core.SSHConnection{Host: remoteTestHost, User: "dev"} + wsl := &core.WSLConnection{Distribution: "Ubuntu-24.04"} + container := &core.ContainerConnection{Engine: core.ContainerEngineDocker, Container: remoteTestHostContainer} + cases := []struct { + name string + host remoteHost + hosted, overSSH, saved bool + }{ + {"ssh", remoteHost{ssh: ssh}, false, true, true}, + {"wsl", remoteHost{wsl: wsl}, false, false, false}, + {"container", remoteHost{container: container}, false, false, false}, + {"ssh container", remoteHost{ssh: ssh, container: container}, true, true, false}, + {"wsl container", remoteHost{wsl: wsl, container: container}, true, false, false}, + } + for _, tc := range cases { + h := tc.host + if h.hosted() != tc.hosted || h.overSSH() != tc.overSSH || h.saved() != tc.saved { + t.Fatalf("%s: hosted %v, overSSH %v, saved %v", tc.name, h.hosted(), h.overSSH(), h.saved()) + } + request := h.request(nil, "0.0.0-test") + if (request.WSL != nil) != (h.wsl != nil) || (request.Container != nil) != (h.container != nil) || + (h.wsl == nil && request.Connection != h.ssh) || (h.wsl != nil && request.Connection != (core.SSHConnection{})) { + t.Fatalf("%s: the request does not carry the host and the container", tc.name) + } + if h.hosted() && !strings.HasSuffix(h.address(), " › "+container.Identity()) { + t.Fatalf("%s: the address does not name the container after its host", tc.name) + } + } + if (remoteHost{container: container}).address() != container.Identity() { + t.Fatal("a container of this computer is not named by its identity alone") + } +} diff --git a/desktop/internal/workbench/remote_list.go b/desktop/internal/workbench/remote_list.go index fac423e2e..8112de161 100644 --- a/desktop/internal/workbench/remote_list.go +++ b/desktop/internal/workbench/remote_list.go @@ -41,8 +41,8 @@ type remoteFormValues struct { // buildRows lays out the list from the sections Core found for the query while one is typed, else // from the source's, under a heading for each group when any section names one, followed by the -// WSL distributions (remote_wsl.go). A folded group keeps its heading only, and a search unfolds -// every group. +// WSL distributions (remote_wsl.go) and the running containers (remote_container.go). A folded +// group keeps its heading only, and a search unfolds every group. func (r *remoteState) buildRows() { r.rows = nil byID := make(map[string]*core.SavedRemoteConnection, len(r.source.Connections)) @@ -72,6 +72,7 @@ func (r *remoteState) buildRows() { } } r.rows = append(r.rows, r.wslRows()...) + r.rows = append(r.rows, r.containerRows()...) } // toggleRemoteGroup folds or unfolds group in the list. diff --git a/desktop/internal/workbench/remote_shell_view.go b/desktop/internal/workbench/remote_shell_view.go index 915df700a..4502fc1c6 100644 --- a/desktop/internal/workbench/remote_shell_view.go +++ b/desktop/internal/workbench/remote_shell_view.go @@ -36,6 +36,8 @@ func (a *App) remoteView(c ui.C) { page := k.Part("page") ui.Column(page).Grow(1).Basis(0).MinWidth(0).FillHeight().Children(func() { switch { + case r.devcontainer != nil: + a.remoteDevcontainerView(page, language, r.devcontainer) case r.importer != nil: a.remoteImportView(page, language, r.importer) case r.trust != nil: @@ -50,6 +52,8 @@ func (a *App) remoteView(c ui.C) { }, func() { k := c.Part("remote-footer") switch { + case r.devcontainer != nil: + a.remoteDevcontainerFooter(k, language, r.devcontainer) case r.importer != nil: a.remoteImportFooter(k, language, r.importer) case r.trust != nil: @@ -73,6 +77,8 @@ func (a *App) remoteTitle(language i18n.Language) string { r := &a.remote crumb := "" switch { + case r.devcontainer != nil: + crumb = i18n.Shared(language, "desktop.remote.devcontainer.title") case r.importer != nil: crumb = i18n.Shared(language, "desktop.remote.import.titleMotty") if r.importer.source == remoteImportSSH { @@ -84,6 +90,8 @@ func (a *App) remoteTitle(language i18n.Language) string { crumb = r.steps.entry.Name case r.wsl.selected != "": crumb = r.wsl.selected + case r.containers.selected != nil: + crumb = r.containers.selected.Name case r.editing && r.entry(r.selected) == nil: crumb = i18n.Shared(language, "desktop.remote.newConnection") case r.editing: @@ -117,6 +125,9 @@ func (a *App) remoteList(c ui.C, language i18n.Language) { c.After(a.searchRemote) } a.remoteImportMenu(k.Part("import"), language) + if a.gitIconButton(k.Part("devcontainer"), i18n.Shared(language, "desktop.remote.devcontainer.open"), icons.FileCode, false, r.saving || r.connect != nil) { + c.After(a.openRemoteDevcontainer) + } if a.gitIconButton(k.Part("new"), i18n.Shared(language, "desktop.remote.new"), icons.Plus, false, r.saving) { c.After(a.newRemote) } @@ -163,6 +174,9 @@ func (a *App) remoteRows(k ui.C, language i18n.Language, title string, rows []re if r.rows[row].wsl != "" { return r.rows[row].wsl } + if r.rows[row].container != nil { + return r.rows[row].container.Name + } return r.rows[row].entry.Name } r.list.Header = func(row int) bool { return row >= 0 && row < len(r.rows) && r.rows[row].heading } @@ -172,15 +186,17 @@ func (a *App) remoteRows(k ui.C, language i18n.Language, title string, rows []re a.remoteHeadingRow(row, language, item) case item.wsl != "": a.remoteWSLRow(row, language, item.wsl) + case item.container != nil: + a.remoteContainerRow(row, language, *item.container) default: a.remoteEntryRow(row, language, *item.entry) } }).Scrollbars().FillWidth().Grow(1).Shrink(1).MinHeight(0).Label(title) if r.list.Changed() { - away := r.steps != nil || r.browser != nil || r.importer != nil + away := r.steps != nil || r.browser != nil || r.importer != nil || r.devcontainer != nil at := r.list.Selected() switch { - case at >= 0 && at < len(rows) && rows[at].entry != nil && (rows[at].entry.ID != r.selected || r.editing || r.wsl.selected != "" || away): + case at >= 0 && at < len(rows) && rows[at].entry != nil && (rows[at].entry.ID != r.selected || r.editing || r.wsl.selected != "" || r.containers.selected != nil || away): id := rows[at].entry.ID c := k c.After(func() { @@ -202,6 +218,18 @@ func (a *App) remoteRows(k ui.C, language i18n.Language, title string, rows []re a.performed("remote.wsl.select", surfaceButton) r.selectRemoteWSL(name) }) + case at >= 0 && at < len(rows) && rows[at].container != nil && + (r.containers.selected == nil || rows[at].container.key() != r.containers.selected.key() || away): + container := *rows[at].container + c := k + c.After(func() { + if !a.leaveRemoteFlows() { + r.syncListSelection() + return + } + a.performed("remote.container.select", surfaceButton) + r.selectRemoteContainer(container) + }) } } else { // The list selects only rows it has declared, so the row a save added becomes the diff --git a/desktop/internal/workbench/remote_steps.go b/desktop/internal/workbench/remote_steps.go index 41a06e5f1..4d328d21c 100644 --- a/desktop/internal/workbench/remote_steps.go +++ b/desktop/internal/workbench/remote_steps.go @@ -75,15 +75,21 @@ func newRemoteSteps(entry core.SavedRemoteConnection, host remoteHost, folder st return &remoteSteps{entry: entry, host: host, folder: folder, reached: remoteStepConnect, began: now} } -// shows says whether the page lists step: every step over SSH, and over WSL the steps after -// starting the distribution, which reads no configuration and asks nothing. +// shows says whether the page lists step: every step over SSH, a container on an SSH host +// included, and over WSL or into a container of this computer the steps after starting the +// distribution or entering the container, which read no configuration and ask nothing. func (s *remoteSteps) shows(step remoteStep) bool { - return s.host.wsl == nil || (step != remoteStepConfig && step != remoteStepAuthenticate) + return s.host.overSSH() || (step != remoteStepConfig && step != remoteStepAuthenticate) } -// name is step's name for this connection: over WSL, the connection starts the distribution. +// name is step's name for this connection: over WSL, the connection starts the distribution, and +// into a container of this computer it enters the container. A container on a host is entered by +// the same command that logs in there, so its steps are its host's. func (s *remoteSteps) name(language i18n.Language, step remoteStep) string { - if step == remoteStepConnect && s.host.wsl != nil { + switch { + case step == remoteStepConnect && s.host.container != nil && !s.host.hosted(): + return i18n.Shared(language, "desktop.remote.container.start") + case step == remoteStepConnect && s.host.wsl != nil: return i18n.Shared(language, "desktop.remote.wsl.start") } return remoteStepName(language, step) @@ -333,7 +339,8 @@ func (a *App) remoteQuestionCard(c ui.C, language i18n.Language, s *remoteSteps, } // remoteStepsFooter declares the buttons under a connection: Stop while it runs; back to the -// connection, its form, or again once it failed. A WSL distribution has no form to go to. +// connection, its form, or again once it failed. Only a saved connection has a form to go to; +// again connects to the same host, a container on a host included. func (a *App) remoteStepsFooter(c ui.C, language i18n.Language, s *remoteSteps) { r := &a.remote ui.Row(c).FillWidth().Items(ui.Center).Gap(8).Children(func() { @@ -348,7 +355,7 @@ func (a *App) remoteStepsFooter(c ui.C, language i18n.Language, s *remoteSteps) c.After(func() { r.steps = nil }) } ui.Spacer(c) - if s.host.wsl == nil && ui.Button(c.Part("edit"), i18n.Shared(language, "desktop.remote.steps.editConnection")).Outline().Disabled(!r.editable()).Clicked() { + if s.host.saved() && ui.Button(c.Part("edit"), i18n.Shared(language, "desktop.remote.steps.editConnection")).Outline().Disabled(!r.editable()).Clicked() { c.After(func() { r.steps = nil a.editSelectedRemote() @@ -358,6 +365,10 @@ func (a *App) remoteStepsFooter(c ui.C, language i18n.Language, s *remoteSteps) folder := s.folder c.After(func() { r.steps = nil + if s.host.hosted() { + a.connectRemoteTo(s.entry, s.host, folder) + return + } a.connectRemote(folder) }) } diff --git a/desktop/internal/workbench/remote_view.go b/desktop/internal/workbench/remote_view.go index 6bfed06f3..e4455dc36 100644 --- a/desktop/internal/workbench/remote_view.go +++ b/desktop/internal/workbench/remote_view.go @@ -44,6 +44,8 @@ func remoteGroupHeading(language i18n.Language, group string) string { return i18n.Shared(language, "desktop.remote.ungrouped") case remoteWSLHeading: return i18n.Shared(language, "desktop.remote.wsl.heading") + case remoteContainerHeading: + return i18n.Shared(language, "desktop.remote.container.heading") } return group } @@ -335,7 +337,12 @@ func remoteFailureText(language i18n.Language, outcome *remoteProbeOutcome) stri } var coreErr *core.Error if errors.As(err, &coreErr) && coreErr.Code == core.CodeRuntimeMissing { - if outcome.wsl { + // What is missing is a program of this computer: the engine's CLI only for a container + // of this computer, and wsl.exe or OpenSSH for one on a host. + switch { + case outcome.engine != "" && !outcome.hosted: + return i18n.SharedFormat(language, "desktop.remote.container.missing", map[string]string{"engine": remoteContainerEngineName(language, outcome.engine)}) + case outcome.wsl: return i18n.Shared(language, "desktop.remote.wsl.missing") } return i18n.Shared(language, "desktop.remote.probe.noSSH") @@ -357,7 +364,14 @@ func remoteFailureText(language i18n.Language, outcome *remoteProbeOutcome) stri case core.RemoteProbeHostKeyRejected: return i18n.Shared(language, "desktop.remote.probe.hostKeyRejected") case core.RemoteProbeUnreachable: - if outcome.wsl { + switch { + case outcome.hosted: + // Core answers the same for a host it cannot reach and a container that is gone there; + // the diagnostics under the text say which. + return i18n.SharedFormat(language, "desktop.remote.container.hostUnreachable", map[string]string{"engine": remoteContainerEngineName(language, outcome.engine)}) + case outcome.engine != "": + return i18n.Shared(language, "desktop.remote.container.unreachable") + case outcome.wsl: return i18n.Shared(language, "desktop.remote.wsl.unreachable") } return i18n.Shared(language, "desktop.remote.probe.unreachable") diff --git a/desktop/internal/workbench/remote_workspace.go b/desktop/internal/workbench/remote_workspace.go index 2bbc17d8b..17e477595 100644 --- a/desktop/internal/workbench/remote_workspace.go +++ b/desktop/internal/workbench/remote_workspace.go @@ -73,9 +73,10 @@ const ( type remoteProject struct { // binding carries the session and the two roots in every Core request of the project. binding *core.RemoteWorkspace - // connectionID, name and host are the saved connection, or the WSL distribution, the - // workspace was opened over, as it was when the workspace opened; connecting again uses the - // same. A WSL distribution's id is its identity (core.WSLConnection.Identity). + // connectionID, name and host are the saved connection, the WSL distribution or the + // container the workspace was opened over, as it was when the workspace opened; connecting + // again uses the same. A WSL distribution's or a container's id is its identity + // (core.WSLConnection.Identity, core.ContainerConnection.Identity). connectionID string name string host remoteHost @@ -224,8 +225,9 @@ func (a *App) connectRemoteHost(ctx context.Context, kernel Kernel, root string, } request := host.request(servers, bundle.Version) request.Resume = resume - if host.wsl == nil { - // A WSL distribution starts through wsl.exe, which the SSH program does not replace. + if host.overSSH() { + // A WSL distribution starts through wsl.exe, and a container of this computer through its + // engine's CLI, which the SSH program does not replace. if request.Preferences, err = remotePreferencesDocument(ctx, kernel, root); err != nil { return core.RemoteConnectResult{}, err } @@ -235,7 +237,11 @@ func (a *App) connectRemoteHost(ctx context.Context, kernel Kernel, root string, // remoteConnectOutcome is the result of a connection to host as the window shows a test's. func remoteConnectOutcome(host remoteHost, result core.RemoteConnectResult, err error) *remoteProbeOutcome { - return &remoteProbeOutcome{result: core.RemoteProbeResult{Status: result.Status, Host: result.Host, Diagnostics: result.Diagnostics}, err: err, wsl: host.wsl != nil} + outcome := &remoteProbeOutcome{result: core.RemoteProbeResult{Status: result.Status, Host: result.Host, Diagnostics: result.Diagnostics}, err: err, wsl: host.wsl != nil, hosted: host.hosted()} + if host.container != nil { + outcome.engine = host.container.Engine + } + return outcome } // remoteConnectFailure is the error the log keeps for a connection that failed: err, or Core's diff --git a/desktop/internal/workbench/remote_workspace_test.go b/desktop/internal/workbench/remote_workspace_test.go index fef597251..b2d986978 100644 --- a/desktop/internal/workbench/remote_workspace_test.go +++ b/desktop/internal/workbench/remote_workspace_test.go @@ -82,6 +82,10 @@ type remoteHostKernel struct { ports remoteHostPorts // wsl is this computer's WSL distributions (remote_wsl_test.go). wsl remoteHostWSL + // containers are this computer's running containers (remote_container_test.go). + containers remoteHostContainers + // devcontainers is this computer's Dev Container CLI (remote_devcontainer_test.go). + devcontainers remoteHostDevcontainers // close is what the host sessions run and keep (remote_close_test.go). close remoteHostClose } @@ -154,6 +158,9 @@ func (k *remoteHostKernel) RemoteConnect(_ context.Context, request core.RemoteC defer k.mu.Unlock() k.connects++ k.servers = append(k.servers, request.Servers) + if request.Container != nil { + return k.containers.connect(k.connects, request) + } if request.WSL != nil { return k.wsl.connect(k.connects, request) } diff --git a/desktop/internal/workbench/remote_wsl.go b/desktop/internal/workbench/remote_wsl.go index df606ddcd..d5338f66c 100644 --- a/desktop/internal/workbench/remote_wsl.go +++ b/desktop/internal/workbench/remote_wsl.go @@ -41,31 +41,69 @@ const ( remoteWSLPrefix = "wsl:" ) -// remoteHost is what a session connects to: a saved SSH connection, or a WSL distribution of this -// computer when wsl is set. +// remoteHost is what a session connects to: a saved SSH connection, a WSL distribution of this +// computer when wsl is set, or a running container when container is set. A container is on this +// computer when it is set alone, and on the SSH host ssh names or the WSL distribution wsl names +// otherwise (remote_host_containers.go): the session logs in there and enters it. type remoteHost struct { - ssh core.SSHConnection - wsl *core.WSLConnection + ssh core.SSHConnection + wsl *core.WSLConnection + container *core.ContainerConnection } -// address is the host as the window shows it: [user@]host[:port] for SSH and -// wsl:[user@]distribution for WSL. +// hosted says whether the host is a container on an SSH host or a WSL distribution. +func (h remoteHost) hosted() bool { + return h.container != nil && (h.wsl != nil || h.ssh != (core.SSHConnection{})) +} + +// overSSH says whether the session logs in through OpenSSH: a saved SSH connection, or a +// container on its host. Only these read the SSH program's preferences and have the steps that +// read OpenSSH's configuration and authenticate. +func (h remoteHost) overSSH() bool { + return h.wsl == nil && (h.container == nil || h.ssh != (core.SSHConnection{})) +} + +// saved says whether the host is the saved SSH connection itself: the only kind with a form to +// edit and remembered folders. +func (h remoteHost) saved() bool { + return h.wsl == nil && h.container == nil +} + +// address is the host as the window shows it: [user@]host[:port] for SSH, +// wsl:[user@]distribution for WSL and engine:[user@]container for a container, after its host's +// address and " › " when it is on one. func (h remoteHost) address() string { - if h.wsl != nil { - return h.wsl.Identity() + var host string + switch { + case h.wsl != nil: + host = h.wsl.Identity() + case h.ssh != (core.SSHConnection{}): + host = remoteAddress(h.ssh) + } + switch { + case h.container == nil: + return host + case host == "": + return h.container.Identity() } - return remoteAddress(h.ssh) + return host + " › " + h.container.Identity() } -// kind is how the host is reached, as the window title and the status bar name it: SSH or WSL. +// kind is how the host is reached, as the window title and the status bar name it: SSH, WSL or +// Container. func (h remoteHost) kind(language i18n.Language) string { - if h.wsl != nil { + switch { + case h.container != nil: + return i18n.Shared(language, "desktop.remote.container.kind") + case h.wsl != nil: return i18n.Shared(language, "desktop.remote.wsl.heading") } return i18n.Shared(language, "desktop.remote.kind.ssh") } -// request is Core's request to connect to the host with servers, the server builds of version. +// request is Core's request to connect to the host with servers, the server builds of version: +// its SSH connection or WSL distribution, followed by the container to enter there when it has +// one. A container of this computer has neither, so Core enters it here. func (h remoteHost) request(servers []core.RemoteServerBuild, version string) core.RemoteConnectRequest { request := core.RemoteConnectRequest{Servers: servers, ServerVersion: version} if h.wsl != nil { @@ -74,6 +112,10 @@ func (h remoteHost) request(servers []core.RemoteServerBuild, version string) co } else { request.Connection = h.ssh } + if h.container != nil { + container := *h.container + request.Container = &container + } return request } diff --git a/docs/assets/remote-connections/README.md b/docs/assets/remote-connections/README.md index 4259b2e80..338454695 100644 --- a/docs/assets/remote-connections/README.md +++ b/docs/assets/remote-connections/README.md @@ -8,6 +8,8 @@ - 导入页的 Motty 主机、逐项字段映射和 `~/.ssh/config` 的主机; - 选文件夹页的远程目录; - WSL 发行版列表和连接失败时 wsl.exe 的输出; +- Docker 和 Podman 容器列表和连接失败时容器引擎的输出; +- 已连接主机上正在运行的 Docker 和 Podman 容器; - OpenSSH 的主机密钥和密码询问。 截图里的主机、用户、指纹和路径都是虚构的。截图覆盖深色与浅色主题、中文与英文界面,用于确认: @@ -53,6 +55,9 @@ - **WSL 发行版:** 已保存的连接之后是“WSL”分组,列出本机的发行版(截图里的发行版由测试给出,不运行 wsl.exe): - 选中后右侧显示发行版名、“WSL”标签和 `wsl:用户@发行版` 地址,说明经本机 wsl.exe 打开、不保存任何信息,下方可填写 Linux 用户; - 连接失败时步骤从“启动发行版”开始,没有读取配置和身份验证;失败原因用 WSL 自己的说明,不显示 SSH 的排查提示,底部没有“编辑连接”。 +- **容器:** WSL 之后是“容器”分组,列出本机 Docker 和 Podman 正在运行的容器(截图里的容器由测试给出,不运行 docker 或 podman): + - 每行显示容器名和“引擎 · 镜像”;选中后右侧显示容器名、引擎标签、`引擎:用户@容器` 地址和“镜像 … · 状态”,说明只进入正在运行的容器、不改动容器、不挂载目录、不保存任何信息,下方可填写容器内用户(ⓘ 说明可填写的格式,留空用镜像默认用户); + - 连接失败时步骤从“进入容器”开始,没有读取配置和身份验证;失败原因说明容器已停止、暂停或引擎没有应答,下方是引擎的原始输出,不显示 SSH 的排查提示,底部没有“编辑连接”。 截图不能代替 macOS/Windows 原生窗口验收。 @@ -72,8 +77,13 @@ | 从 Motty 导入(展开字段映射) | [浅色英文](remote-connections-import-light-en-US.png) | [深色中文](remote-connections-import-dark-zh-CN.png) | | 从 SSH 配置导入 | [浅色英文](remote-connections-import-ssh-light-en-US.png) | [深色中文](remote-connections-import-ssh-dark-zh-CN.png) | | 选择远程文件夹 | [浅色英文](remote-connections-folder-light-en-US.png) | [深色中文](remote-connections-folder-dark-zh-CN.png) | +| 主机上的容器(选中一个、填写容器内用户) | [浅色英文](remote-connections-host-containers-light-en-US.png) | [深色中文](remote-connections-host-containers-dark-zh-CN.png) | | WSL 发行版页(填写 Linux 用户) | [浅色英文](remote-connections-wsl-light-en-US.png) | [深色中文](remote-connections-wsl-dark-zh-CN.png) | | 连接 WSL 发行版失败 | [浅色英文](remote-connections-wsl-failed-light-en-US.png) | [深色中文](remote-connections-wsl-failed-dark-zh-CN.png) | +| 容器页(填写容器内用户) | [浅色英文](remote-connections-container-light-en-US.png) | [深色中文](remote-connections-container-dark-zh-CN.png) | +| 进入已停止的容器失败 | [浅色英文](remote-connections-container-failed-light-en-US.png) | [深色中文](remote-connections-container-failed-dark-zh-CN.png) | +| 从 devcontainer.json 打开:文件夹未受信任 | [浅色英文](remote-connections-devcontainer-light-en-US.png) | [深色中文](remote-connections-devcontainer-dark-zh-CN.png) | +| 从 devcontainer.json 打开:构建中的 CLI 日志 | [浅色英文](remote-connections-devcontainer-building-light-en-US.png) | [深色中文](remote-connections-devcontainer-building-dark-zh-CN.png) | 复验方法:在仓库根目录把 `LITHE_VISUAL_OUTPUT_DIR` 设为绝对路径 `"$(pwd)/docs/assets/remote-connections"`,然后在 `desktop/` 下运行 `../scripts/desktop/desktop-go.sh test -tags vivahead,lithevisual ./internal/workbench -run '^TestVisualRemoteConnections$' -count=1 -timeout 300s`。 diff --git a/docs/assets/remote-connections/remote-connections-container-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-container-dark-zh-CN.png new file mode 100644 index 000000000..23a14ddb3 Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-container-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-container-failed-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-container-failed-dark-zh-CN.png new file mode 100644 index 000000000..33a5fc2e9 Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-container-failed-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-container-failed-light-en-US.png b/docs/assets/remote-connections/remote-connections-container-failed-light-en-US.png new file mode 100644 index 000000000..d9bd6997c Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-container-failed-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-container-light-en-US.png b/docs/assets/remote-connections/remote-connections-container-light-en-US.png new file mode 100644 index 000000000..85b87015b Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-container-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-devcontainer-building-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-devcontainer-building-dark-zh-CN.png new file mode 100644 index 000000000..8b8bd971f Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-devcontainer-building-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-devcontainer-building-light-en-US.png b/docs/assets/remote-connections/remote-connections-devcontainer-building-light-en-US.png new file mode 100644 index 000000000..624aa2119 Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-devcontainer-building-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-devcontainer-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-devcontainer-dark-zh-CN.png new file mode 100644 index 000000000..536753961 Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-devcontainer-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-devcontainer-light-en-US.png b/docs/assets/remote-connections/remote-connections-devcontainer-light-en-US.png new file mode 100644 index 000000000..40e61e3ed Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-devcontainer-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-edit-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-edit-dark-zh-CN.png index d30443032..a5345ec2d 100644 Binary files a/docs/assets/remote-connections/remote-connections-edit-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-edit-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-edit-light-en-US.png b/docs/assets/remote-connections/remote-connections-edit-light-en-US.png index a85bbe7c8..973d21b2b 100644 Binary files a/docs/assets/remote-connections/remote-connections-edit-light-en-US.png and b/docs/assets/remote-connections/remote-connections-edit-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-empty-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-empty-dark-zh-CN.png index 14f060b9a..e96558b46 100644 Binary files a/docs/assets/remote-connections/remote-connections-empty-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-empty-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-empty-light-en-US.png b/docs/assets/remote-connections/remote-connections-empty-light-en-US.png index 18b4a6a31..39fea1535 100644 Binary files a/docs/assets/remote-connections/remote-connections-empty-light-en-US.png and b/docs/assets/remote-connections/remote-connections-empty-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-folder-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-folder-dark-zh-CN.png index d34aab8c7..bede199c0 100644 Binary files a/docs/assets/remote-connections/remote-connections-folder-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-folder-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-folder-light-en-US.png b/docs/assets/remote-connections/remote-connections-folder-light-en-US.png index 065614900..1edd63d7a 100644 Binary files a/docs/assets/remote-connections/remote-connections-folder-light-en-US.png and b/docs/assets/remote-connections/remote-connections-folder-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-host-containers-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-host-containers-dark-zh-CN.png new file mode 100644 index 000000000..0f4efbd2a Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-host-containers-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-host-containers-light-en-US.png b/docs/assets/remote-connections/remote-connections-host-containers-light-en-US.png new file mode 100644 index 000000000..109cbc092 Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-host-containers-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-import-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-import-dark-zh-CN.png index cdcc40ff3..5bc2f825a 100644 Binary files a/docs/assets/remote-connections/remote-connections-import-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-import-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-import-light-en-US.png b/docs/assets/remote-connections/remote-connections-import-light-en-US.png index 254b38a1c..3d650483e 100644 Binary files a/docs/assets/remote-connections/remote-connections-import-light-en-US.png and b/docs/assets/remote-connections/remote-connections-import-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-import-ssh-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-import-ssh-dark-zh-CN.png index 0bf5a50c2..0da410aaf 100644 Binary files a/docs/assets/remote-connections/remote-connections-import-ssh-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-import-ssh-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-import-ssh-light-en-US.png b/docs/assets/remote-connections/remote-connections-import-ssh-light-en-US.png index 7139506d9..e78087c07 100644 Binary files a/docs/assets/remote-connections/remote-connections-import-ssh-light-en-US.png and b/docs/assets/remote-connections/remote-connections-import-ssh-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-overview-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-overview-dark-zh-CN.png index 34d59ac32..9f2813aac 100644 Binary files a/docs/assets/remote-connections/remote-connections-overview-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-overview-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-overview-light-en-US.png b/docs/assets/remote-connections/remote-connections-overview-light-en-US.png index 4a2cc9e1e..dd0cbf668 100644 Binary files a/docs/assets/remote-connections/remote-connections-overview-light-en-US.png and b/docs/assets/remote-connections/remote-connections-overview-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-password-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-password-dark-zh-CN.png index 080863c9f..4b7f927fc 100644 Binary files a/docs/assets/remote-connections/remote-connections-password-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-password-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-password-light-en-US.png b/docs/assets/remote-connections/remote-connections-password-light-en-US.png index ceb5ed81e..08cf298f7 100644 Binary files a/docs/assets/remote-connections/remote-connections-password-light-en-US.png and b/docs/assets/remote-connections/remote-connections-password-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-refused-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-refused-dark-zh-CN.png index 7698ab67b..0630c1984 100644 Binary files a/docs/assets/remote-connections/remote-connections-refused-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-refused-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-refused-light-en-US.png b/docs/assets/remote-connections/remote-connections-refused-light-en-US.png index 5c868f61c..c8099f1d4 100644 Binary files a/docs/assets/remote-connections/remote-connections-refused-light-en-US.png and b/docs/assets/remote-connections/remote-connections-refused-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-steps-failed-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-steps-failed-dark-zh-CN.png index 3cd853215..fdcd01e01 100644 Binary files a/docs/assets/remote-connections/remote-connections-steps-failed-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-steps-failed-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-steps-failed-light-en-US.png b/docs/assets/remote-connections/remote-connections-steps-failed-light-en-US.png index 07a6fce38..b61b8b4b8 100644 Binary files a/docs/assets/remote-connections/remote-connections-steps-failed-light-en-US.png and b/docs/assets/remote-connections/remote-connections-steps-failed-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-steps-host-key-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-steps-host-key-dark-zh-CN.png index 16f330ca2..f4a918935 100644 Binary files a/docs/assets/remote-connections/remote-connections-steps-host-key-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-steps-host-key-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-steps-host-key-light-en-US.png b/docs/assets/remote-connections/remote-connections-steps-host-key-light-en-US.png index 68e3b6697..cf04b08ef 100644 Binary files a/docs/assets/remote-connections/remote-connections-steps-host-key-light-en-US.png and b/docs/assets/remote-connections/remote-connections-steps-host-key-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-steps-password-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-steps-password-dark-zh-CN.png index 5aa4b7b1b..5e9cc5f24 100644 Binary files a/docs/assets/remote-connections/remote-connections-steps-password-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-steps-password-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-steps-password-light-en-US.png b/docs/assets/remote-connections/remote-connections-steps-password-light-en-US.png index a1e9f6b86..74858a3ad 100644 Binary files a/docs/assets/remote-connections/remote-connections-steps-password-light-en-US.png and b/docs/assets/remote-connections/remote-connections-steps-password-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-test-failed-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-test-failed-dark-zh-CN.png index e1fc5b212..54610a411 100644 Binary files a/docs/assets/remote-connections/remote-connections-test-failed-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-test-failed-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-test-failed-light-en-US.png b/docs/assets/remote-connections/remote-connections-test-failed-light-en-US.png index 79d3e3088..48663a4a9 100644 Binary files a/docs/assets/remote-connections/remote-connections-test-failed-light-en-US.png and b/docs/assets/remote-connections/remote-connections-test-failed-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-test-ok-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-test-ok-dark-zh-CN.png index 2bd1ee336..3e3c75984 100644 Binary files a/docs/assets/remote-connections/remote-connections-test-ok-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-test-ok-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-test-ok-light-en-US.png b/docs/assets/remote-connections/remote-connections-test-ok-light-en-US.png index eb59a29fa..c86efe704 100644 Binary files a/docs/assets/remote-connections/remote-connections-test-ok-light-en-US.png and b/docs/assets/remote-connections/remote-connections-test-ok-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-trust-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-trust-dark-zh-CN.png index 9867abc3f..946ce77ae 100644 Binary files a/docs/assets/remote-connections/remote-connections-trust-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-trust-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-trust-light-en-US.png b/docs/assets/remote-connections/remote-connections-trust-light-en-US.png index 5fe8ab86f..14ae46b2f 100644 Binary files a/docs/assets/remote-connections/remote-connections-trust-light-en-US.png and b/docs/assets/remote-connections/remote-connections-trust-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-wsl-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-wsl-dark-zh-CN.png index b8e4683e5..81d87c142 100644 Binary files a/docs/assets/remote-connections/remote-connections-wsl-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-wsl-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-wsl-failed-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-wsl-failed-dark-zh-CN.png index 2e23b5e2d..e3202aa6b 100644 Binary files a/docs/assets/remote-connections/remote-connections-wsl-failed-dark-zh-CN.png and b/docs/assets/remote-connections/remote-connections-wsl-failed-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-wsl-failed-light-en-US.png b/docs/assets/remote-connections/remote-connections-wsl-failed-light-en-US.png index 938d9c686..1ec7caf51 100644 Binary files a/docs/assets/remote-connections/remote-connections-wsl-failed-light-en-US.png and b/docs/assets/remote-connections/remote-connections-wsl-failed-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-wsl-light-en-US.png b/docs/assets/remote-connections/remote-connections-wsl-light-en-US.png index e735c9824..be0ac6305 100644 Binary files a/docs/assets/remote-connections/remote-connections-wsl-light-en-US.png and b/docs/assets/remote-connections/remote-connections-wsl-light-en-US.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index e3d0d0edf..6e2ec55db 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -331,7 +331,11 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # a kept one; remote.disconnect ends or keeps the host programs; remote.runningPrograms, # remote.endPrograms (all or the listed ones), the closePrograms preference and # closing.idleTimeoutSeconds; #161 plans the run configurations of a remote workspace (#2231). -PINNED_CORE_REVISION="ac80382df327579a92dba105abd9fddceef29a29" +# Lithe-core-rust feat/2231-remote-containers at b92fcaf (#162 merged with main ac80382): remote.connect +# enters a running Docker or Podman container (the container field), also on an SSH host or in a WSL +# distribution; remote.listContainers lists the running ones; remote.devcontainerConfigs and +# remote.devcontainerUp build and start the container of a devcontainer.json (#2231). +PINNED_CORE_REVISION="b92fcafeb42ee95faea20046ec459aa5fd53ef6f" 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 f1b6129e3..38b80319e 100644 --- a/shared/i18n/features/remote-connections.json +++ b/shared/i18n/features/remote-connections.json @@ -2695,6 +2695,445 @@ "platforms": [ "desktop" ] + }, + { + "id": "desktop.remote.container.heading", + "description": "Remote Development window: the list's heading over the running Docker and Podman containers of this computer", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.container.kind", + "description": "Remote Development window, the window title and the status bar: how a workspace in a container of this computer is reached, before its name, as SSH and WSL are", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.container.docker", + "description": "Remote Development window: the name of the Docker container engine, shown on a container's row and page", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.container.podman", + "description": "Remote Development window: the name of the Podman container engine, shown on a container's row and page", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.container.row", + "description": "Remote Development window: the line under a container's name in the list; {engine} is Docker or Podman and {image} the engine's image name, shown as it is", + "platforms": [ + "desktop" + ], + "parameters": { + "engine": "string", + "image": "string" + } + }, + { + "id": "desktop.remote.container.state", + "description": "Remote Development window: a container's image and the engine's status text (such as Up 2 hours), both shown as the engine prints them, under its name on its page", + "platforms": [ + "desktop" + ], + "parameters": { + "image": "string", + "status": "string" + } + }, + { + "id": "desktop.remote.container.about", + "description": "Remote Development window: what opening a running container does and does not do; {engine} is Docker or Podman", + "platforms": [ + "desktop" + ], + "parameters": { + "engine": "string" + } + }, + { + "id": "desktop.remote.container.user", + "description": "Remote Development window: the label of the field for the user a container's workspace runs as", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.container.userHelp", + "description": "Remote Development window: what the container's user field takes, and what leaving it empty does", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.container.userPlaceholder", + "description": "Remote Development window: the placeholder of the empty container's user field", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.container.userInvalid", + "description": "Remote Development window: why Core refused the container's user", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.container.nameInvalid", + "description": "Remote Development window: why Core refused the container's name", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.container.unreachable", + "description": "Remote Development window: why a connection to a container failed before the server started: the container is gone, stopped or paused, or its engine did not answer", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.container.missing", + "description": "Remote Development window: why a connection to a container failed when this computer has no command line of its engine; {engine} is Docker or Podman", + "platforms": [ + "desktop" + ], + "parameters": { + "engine": "string" + } + }, + { + "id": "desktop.remote.container.start", + "description": "Remote Development window: the step of a connection to a container that enters it, in place of connecting to a host", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.container.hostUnreachable", + "description": "Remote Development window: why a connection to a container on an SSH host or WSL distribution failed before the server started: the host or the container could not be reached; {engine} is Docker or Podman", + "platforms": [ + "desktop" + ], + "parameters": { + "engine": "string" + } + }, + { + "id": "desktop.remote.hostContainers.show", + "description": "Remote Development window: the button in the folder browser of an SSH host or WSL distribution that lists the containers running there", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostContainers.about", + "description": "Remote Development window: what the list of a host's containers is and what entering one does", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostContainers.failed", + "description": "Remote Development window: why a host's containers could not be listed; {reason} is the error's code", + "platforms": [ + "desktop" + ], + "parameters": { + "reason": "string" + } + }, + { + "id": "desktop.remote.hostContainers.empty", + "description": "Remote Development window: the list of a host's containers when none are running", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostContainers.noEngine", + "description": "Remote Development window: the list of a host's containers when the host has no Docker or Podman command line", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostContainers.back", + "description": "Remote Development window: the button that shows the host's folders again in place of its containers", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostContainers.enter", + "description": "Remote Development window: the button that connects to the selected container on the host", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostContainers.title", + "description": "Remote Development window: the heading of the page that lists the containers running on a connected host; {name} is the SSH connection's or WSL distribution's name", + "platforms": [ + "desktop" + ], + "parameters": { + "name": "string" + } + }, + { + "id": "desktop.remote.hostContainers.name", + "description": "Remote Development window: the name of a workspace in a container on a host; {container} is the container's name and {host} the SSH connection's or WSL distribution's", + "platforms": [ + "desktop" + ], + "parameters": { + "container": "string", + "host": "string" + } + }, + { + "id": "desktop.remote.devcontainer.open", + "description": "Remote Development window, dev container page: the list toolbar button and empty page link that open the page to open a folder of this computer in its dev container", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.title", + "description": "Remote Development window, dev container page: the page heading and the window title crumb", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.about", + "description": "Remote Development window, dev container page: what the page does and what it runs", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.folder", + "description": "Remote Development window, dev container page: the label of the field holding the folder of this computer", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.folderPlaceholder", + "description": "Remote Development window, dev container page: the placeholder of the folder field; Return reads the folder", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.choose", + "description": "Remote Development window, dev container page: the folder field's button that opens the system folder picker", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.chooseTitle", + "description": "Remote Development window, dev container page: the title of the system folder picker", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.folderRelative", + "description": "Remote Development window, dev container page: why the typed folder was refused: it is not an absolute path", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.folderMissing", + "description": "Remote Development window, dev container page: why the typed folder was refused: it is not a folder", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.readFailed", + "description": "Remote Development window, dev container page: why the folder's configurations could not be listed; {reason} is the failure", + "platforms": [ + "desktop" + ], + "parameters": { + "reason": "string" + } + }, + { + "id": "desktop.remote.devcontainer.trustFailed", + "description": "Remote Development window, dev container page: why the folder's trust could not be read; building waits for it; {reason} is the failure", + "platforms": [ + "desktop" + ], + "parameters": { + "reason": "string" + } + }, + { + "id": "desktop.remote.devcontainer.config", + "description": "Remote Development window, dev container page: the label of the picker of the folder's devcontainer.json files", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.configHelp", + "description": "Remote Development window, dev container page: the ⓘ help of the configuration picker", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.configNamed", + "description": "Remote Development window, dev container page: a configuration in the picker; {name} is its name and {path} its path in the folder", + "platforms": [ + "desktop" + ], + "parameters": { + "name": "string", + "path": "string" + } + }, + { + "id": "desktop.remote.devcontainer.none", + "description": "Remote Development window, dev container page: shown when the folder has no devcontainer.json", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.engine", + "description": "Remote Development window, dev container page: the label of the picker of the engine to build with", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.engineHelp", + "description": "Remote Development window, dev container page: the ⓘ help of the engine picker", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.untrusted", + "description": "Remote Development window, dev container page: the notice that the folder is not trusted and building trusts it", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.log", + "description": "Remote Development window, dev container page: the heading of the Dev Container CLI's log", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.logHelp", + "description": "Remote Development window, dev container page: the ⓘ help of the log", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.logWaiting", + "description": "Remote Development window, dev container page: the empty log while the CLI starts", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.truncated", + "description": "Remote Development window, dev container page: the note under the log once Core dropped later lines of a very long log", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.build", + "description": "Remote Development window, dev container page: the footer button that builds and starts the dev container", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.trustAndBuild", + "description": "Remote Development window, dev container page: the footer button that trusts the folder and then builds", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.building", + "description": "Remote Development window, dev container page: the footer status while the CLI builds", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.missing", + "description": "Remote Development window, dev container page: why the build failed: this computer has no Dev Container CLI", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.failed", + "description": "Remote Development window, dev container page: why the build failed: the CLI reported a failure, whose words are shown under it", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.timedOut", + "description": "Remote Development window, dev container page: why the build failed: it ran for more than an hour", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.unusable", + "description": "Remote Development window, dev container page: why the build failed: the CLI's result cannot be entered", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.untrustedRefused", + "description": "Remote Development window, dev container page: why the build was refused: the folder is not trusted", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.devcontainer.upFailed", + "description": "Remote Development window, dev container page: why the build failed for another reason; {reason} is Core's summary", + "platforms": [ + "desktop" + ], + "parameters": { + "reason": "string" + } + }, + { + "id": "desktop.remote.devcontainer.stopped", + "description": "Remote Development window, dev container page: the note once the user stopped the build", + "platforms": [ + "desktop" + ] } ], "locales": { @@ -3047,7 +3486,64 @@ "desktop.remote.wsl.distributionInvalid": "wsl.exe does not accept this distribution name.", "desktop.remote.wsl.unreachable": "This WSL distribution is not installed, or it did not start.", "desktop.remote.wsl.missing": "wsl.exe was not found on this computer. Install the Windows Subsystem for Linux to open a distribution.", - "desktop.remote.wsl.start": "Start the distribution" + "desktop.remote.wsl.start": "Start the distribution", + "desktop.remote.container.heading": "Containers", + "desktop.remote.container.kind": "Container", + "desktop.remote.container.docker": "Docker", + "desktop.remote.container.podman": "Podman", + "desktop.remote.container.row": "{engine} · {image}", + "desktop.remote.container.state": "Image {image} · {status}", + "desktop.remote.container.about": "Enters this running container through {engine} on this computer, as the user below. Lithe does not start, create or change the container, mounts no folder into it, and needs no more rights than the {engine} command line has. Nothing about the container is saved: the folders opened in it are not remembered, and the list is read again each time this window opens.", + "desktop.remote.container.user": "User in the container", + "desktop.remote.container.userHelp": "The user, uid or user:group the workspace runs as inside the container. Leave it empty to use the image's default user.", + "desktop.remote.container.userPlaceholder": "Image's default user", + "desktop.remote.container.userInvalid": "Use a user name, uid or user:group of at most 64 letters, digits and _ . : -, not starting with -.", + "desktop.remote.container.nameInvalid": "The container engine does not accept this container name.", + "desktop.remote.container.unreachable": "This container is no longer running, is paused, or its engine did not answer.", + "desktop.remote.container.missing": "The {engine} command line was not found on this computer. Install {engine} to enter its containers.", + "desktop.remote.container.start": "Enter the container", + "desktop.remote.container.hostUnreachable": "The host could not be reached, or this container on it is no longer running, is paused, or {engine} did not answer.", + "desktop.remote.hostContainers.show": "Containers on This Host", + "desktop.remote.hostContainers.about": "The Docker and Podman containers running on this host. Entering one ends this connection, connects to the host again and on into the container, where you then choose a folder. Lithe never starts, creates or changes a container, and mounts no folder.", + "desktop.remote.hostContainers.failed": "The containers on this host could not be listed: {reason}", + "desktop.remote.hostContainers.empty": "No containers are running on this host.", + "desktop.remote.hostContainers.noEngine": "Neither the Docker nor the Podman command line was found on this host.", + "desktop.remote.hostContainers.back": "Back to Folders", + "desktop.remote.hostContainers.enter": "Enter Container", + "desktop.remote.hostContainers.title": "Choose a Container on {name}", + "desktop.remote.hostContainers.name": "{container} on {host}", + "desktop.remote.devcontainer.open": "Open from devcontainer.json…", + "desktop.remote.devcontainer.title": "Open in Dev Container", + "desktop.remote.devcontainer.about": "Builds and starts the dev container a local folder’s devcontainer.json describes, with the official Dev Container CLI, and opens its workspace folder in it. Building runs the folder’s Dockerfile, features and commands here, so the folder must be trusted. Lithe adds no mount or option.", + "desktop.remote.devcontainer.folder": "Folder on this computer", + "desktop.remote.devcontainer.folderPlaceholder": "Choose a folder, or type its path and press Return", + "desktop.remote.devcontainer.choose": "Choose Folder…", + "desktop.remote.devcontainer.chooseTitle": "Choose the Folder to Open in Its Dev Container", + "desktop.remote.devcontainer.folderRelative": "Enter the folder’s full path, such as /Users/me/project.", + "desktop.remote.devcontainer.folderMissing": "This folder does not exist on this computer.", + "desktop.remote.devcontainer.readFailed": "Cannot read the folder’s configurations: {reason}", + "desktop.remote.devcontainer.trustFailed": "Cannot read whether this folder is trusted: {reason}", + "desktop.remote.devcontainer.config": "Configuration", + "desktop.remote.devcontainer.configHelp": "The devcontainer.json files of this folder, in the order the Dev Container specification looks for them: .devcontainer/devcontainer.json, .devcontainer.json, then one folder below .devcontainer.", + "desktop.remote.devcontainer.configNamed": "{name} ({path})", + "desktop.remote.devcontainer.none": "This folder has no devcontainer.json in .devcontainer or at its top.", + "desktop.remote.devcontainer.engine": "Engine", + "desktop.remote.devcontainer.engineHelp": "Docker or Podman runs the container. With Podman, the CLI is given podman as its docker path.", + "desktop.remote.devcontainer.untrusted": "This folder is not trusted. Trust and Build trusts it, the same as opening it as a trusted project, and then builds.", + "desktop.remote.devcontainer.log": "Build Log", + "desktop.remote.devcontainer.logHelp": "The Dev Container CLI’s own output, with secrets hidden. It is shown here and not written to Lithe’s logs.", + "desktop.remote.devcontainer.logWaiting": "Waiting for the Dev Container CLI…", + "desktop.remote.devcontainer.truncated": "Later lines are not shown: the log is too long.", + "desktop.remote.devcontainer.build": "Build and Open", + "desktop.remote.devcontainer.trustAndBuild": "Trust and Build", + "desktop.remote.devcontainer.building": "Building the dev container…", + "desktop.remote.devcontainer.missing": "The Dev Container CLI (devcontainer) was not found on this computer. Install it with npm install -g @devcontainers/cli, then build again.", + "desktop.remote.devcontainer.failed": "The Dev Container CLI could not start the container. Its output is below.", + "desktop.remote.devcontainer.timedOut": "The build took longer than an hour and was stopped.", + "desktop.remote.devcontainer.unusable": "The Dev Container CLI started something Lithe cannot open: its result names no container or workspace folder.", + "desktop.remote.devcontainer.untrustedRefused": "Nothing was built: this folder is not trusted.", + "desktop.remote.devcontainer.upFailed": "Cannot build the dev container: {reason}", + "desktop.remote.devcontainer.stopped": "The build was stopped. A container it already started keeps running." }, "zh-CN": { "desktop.remote.title": "远程开发", @@ -3398,7 +3894,64 @@ "desktop.remote.wsl.distributionInvalid": "wsl.exe 不接受这个发行版名称。", "desktop.remote.wsl.unreachable": "这个 WSL 发行版没有安装,或者没能启动。", "desktop.remote.wsl.missing": "本机找不到 wsl.exe。安装适用于 Linux 的 Windows 子系统(WSL)后才能打开发行版。", - "desktop.remote.wsl.start": "启动发行版" + "desktop.remote.wsl.start": "启动发行版", + "desktop.remote.container.heading": "容器", + "desktop.remote.container.kind": "容器", + "desktop.remote.container.docker": "Docker", + "desktop.remote.container.podman": "Podman", + "desktop.remote.container.row": "{engine} · {image}", + "desktop.remote.container.state": "镜像 {image} · {status}", + "desktop.remote.container.about": "通过本机的 {engine} 进入这个正在运行的容器,以下方的用户运行。Lithe 不启动、不创建、不改动容器,不往容器里挂载目录,需要的权限也不超过 {engine} 命令行本身。不保存这个容器的任何信息:不记住在其中打开过的文件夹,每次打开本窗口时重新读取列表。", + "desktop.remote.container.user": "容器内用户", + "desktop.remote.container.userHelp": "工作区在容器里以哪个用户运行,可以填用户名、uid 或“用户:组”。留空则使用镜像的默认用户。", + "desktop.remote.container.userPlaceholder": "镜像默认用户", + "desktop.remote.container.userInvalid": "用户最多 64 个字符,只能包含字母、数字和 _ . : -,且不能以 - 开头。", + "desktop.remote.container.nameInvalid": "容器引擎不接受这个容器名。", + "desktop.remote.container.unreachable": "这个容器已经不在运行或已暂停,或者容器引擎没有应答。", + "desktop.remote.container.missing": "本机没有找到 {engine} 命令行。安装 {engine} 后才能进入它的容器。", + "desktop.remote.container.start": "进入容器", + "desktop.remote.container.hostUnreachable": "无法连接主机,或者主机上的这个容器已经不在运行、已暂停,或者 {engine} 没有应答。", + "desktop.remote.hostContainers.show": "主机上的容器", + "desktop.remote.hostContainers.about": "这台主机上正在运行的 Docker 和 Podman 容器。进入容器会断开当前连接,重新连接主机后再进入容器,然后在容器里选择文件夹。Lithe 不会启动、创建或修改容器,也不会挂载文件夹。", + "desktop.remote.hostContainers.failed": "无法列出主机上的容器:{reason}", + "desktop.remote.hostContainers.empty": "这台主机上没有正在运行的容器。", + "desktop.remote.hostContainers.noEngine": "这台主机上没有找到 Docker 或 Podman 命令行。", + "desktop.remote.hostContainers.back": "返回文件夹", + "desktop.remote.hostContainers.enter": "进入容器", + "desktop.remote.hostContainers.title": "选择 {name} 上的容器", + "desktop.remote.hostContainers.name": "{container}({host})", + "desktop.remote.devcontainer.open": "从 devcontainer.json 打开…", + "desktop.remote.devcontainer.title": "在 Dev Container 中打开", + "desktop.remote.devcontainer.about": "用官方 Dev Container CLI 按本机文件夹里 devcontainer.json 的描述构建并启动 dev container,然后在容器里打开它的工作区文件夹。构建会在本机运行这个文件夹的 Dockerfile、features 和命令,因此文件夹必须受信任。Lithe 不额外挂载目录,也不额外加参数。", + "desktop.remote.devcontainer.folder": "本机文件夹", + "desktop.remote.devcontainer.folderPlaceholder": "选择文件夹,或输入路径后按回车", + "desktop.remote.devcontainer.choose": "选择文件夹…", + "desktop.remote.devcontainer.chooseTitle": "选择要在 Dev Container 中打开的文件夹", + "desktop.remote.devcontainer.folderRelative": "请输入文件夹的完整路径,例如 /Users/me/project。", + "desktop.remote.devcontainer.folderMissing": "本机没有这个文件夹。", + "desktop.remote.devcontainer.readFailed": "无法读取文件夹的配置:{reason}", + "desktop.remote.devcontainer.trustFailed": "无法读取这个文件夹是否受信任:{reason}", + "desktop.remote.devcontainer.config": "配置", + "desktop.remote.devcontainer.configHelp": "这个文件夹里的 devcontainer.json,按 Dev Container 规范查找的顺序列出:.devcontainer/devcontainer.json、.devcontainer.json,然后是 .devcontainer 下一层文件夹里的。", + "desktop.remote.devcontainer.configNamed": "{name}({path})", + "desktop.remote.devcontainer.none": "这个文件夹的 .devcontainer 里和顶层都没有 devcontainer.json。", + "desktop.remote.devcontainer.engine": "容器引擎", + "desktop.remote.devcontainer.engineHelp": "由 Docker 或 Podman 运行容器。选 Podman 时,CLI 的 docker 路径设为 podman。", + "desktop.remote.devcontainer.untrusted": "这个文件夹还不受信任。“信任并构建”会信任它(与以受信任项目打开时相同),然后开始构建。", + "desktop.remote.devcontainer.log": "构建日志", + "desktop.remote.devcontainer.logHelp": "Dev Container CLI 自己的输出,已隐藏敏感信息。只在这里显示,不写入 Lithe 的日志。", + "desktop.remote.devcontainer.logWaiting": "正在等待 Dev Container CLI…", + "desktop.remote.devcontainer.truncated": "日志太长,后面的内容不再显示。", + "desktop.remote.devcontainer.build": "构建并打开", + "desktop.remote.devcontainer.trustAndBuild": "信任并构建", + "desktop.remote.devcontainer.building": "正在构建 dev container…", + "desktop.remote.devcontainer.missing": "本机没有找到 Dev Container CLI(devcontainer)。请用 npm install -g @devcontainers/cli 安装后再构建。", + "desktop.remote.devcontainer.failed": "Dev Container CLI 没能启动容器,输出如下。", + "desktop.remote.devcontainer.timedOut": "构建超过一小时,已停止。", + "desktop.remote.devcontainer.unusable": "Dev Container CLI 启动的结果无法打开:结果里没有容器或工作区文件夹。", + "desktop.remote.devcontainer.untrustedRefused": "没有构建:这个文件夹不受信任。", + "desktop.remote.devcontainer.upFailed": "无法构建 dev container:{reason}", + "desktop.remote.devcontainer.stopped": "构建已停止。已经启动的容器会继续运行。" } } } diff --git a/shared/platform-feature-matrix/features/remote-workspace.json b/shared/platform-feature-matrix/features/remote-workspace.json index 60e207a3a..7d00e0f7d 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 发行版)、远程路径工作区、主机文件编辑与监听、按路径打开主机上的文件(工作区外只读)、主机终端、主机搜索与替换、远程信任与主机 Git、端口转发(含主机侧转发规则与反向转发)、远程工作区设置(SSH 程序、断线重连与关闭时的远端进程)、关闭确认与保留远端进程", + "capability": "远程连接(SSH 主机、本机 WSL 发行版、本机及 SSH 主机与 WSL 发行版上的 Docker/Podman 容器,以及从本机文件夹的 devcontainer.json 构建并打开)、远程路径工作区、主机文件编辑与监听、按路径打开主机上的文件(工作区外只读)、主机终端、主机搜索与替换、远程信任与主机 Git、端口转发(含主机侧转发规则与反向转发)、远程工作区设置(SSH 程序、断线重连与关闭时的远端进程)、关闭确认与保留远端进程", "macos": { "implementationStatus": "partial", "verificationStatus": "pending", @@ -20,9 +20,6 @@ "desktop/internal/workbench/remote_workspace.go", "desktop/internal/workbench/remote_status_view.go", "desktop/internal/workbench/remote_documents_test.go", - "desktop/internal/workbench/remote_host_files.go", - "desktop/internal/workbench/remote_host_files_view.go", - "desktop/internal/workbench/remote_host_files_test.go", "desktop/internal/workbench/remote_terminal.go", "desktop/internal/workbench/remote_watch.go", "desktop/internal/termview/open_test.go", @@ -50,7 +47,15 @@ "desktop/internal/workbench/remote_ports_test.go", "desktop/internal/workbench/remote_ports_visual_test.go", "desktop/internal/workbench/remote_wsl.go", + "desktop/internal/workbench/remote_container.go", "desktop/internal/workbench/remote_wsl_test.go", + "desktop/internal/workbench/remote_container_test.go", + "desktop/internal/workbench/remote_host_containers.go", + "desktop/internal/workbench/remote_host_containers_test.go", + "desktop/internal/core/remote_devcontainer.go", + "desktop/internal/core/remote_devcontainer_test.go", + "desktop/internal/workbench/remote_devcontainer.go", + "desktop/internal/workbench/remote_devcontainer_test.go", "desktop/internal/core/remote_preferences.go", "desktop/internal/remoteconn/preferences.go", "desktop/internal/workbench/remote_preferences.go", @@ -62,6 +67,9 @@ "desktop/internal/workbench/remote_port_rules.go", "desktop/internal/workbench/remote_port_rules_view.go", "desktop/internal/workbench/remote_port_rules_test.go", + "desktop/internal/workbench/remote_host_files.go", + "desktop/internal/workbench/remote_host_files_view.go", + "desktop/internal/workbench/remote_host_files_test.go", "desktop/internal/workbench/remote_close.go", "desktop/internal/workbench/remote_close_test.go", "desktop/internal/workbench/remote_close_visual_test.go", @@ -83,8 +91,6 @@ "desktop/internal/workbench/remote_documents.go", "desktop/internal/workbench/remote_workspace.go", "desktop/internal/workbench/remote_status_view.go", - "desktop/internal/workbench/remote_host_files.go", - "desktop/internal/workbench/remote_host_files_view.go", "desktop/internal/workbench/remote_terminal.go", "desktop/internal/core/remote_watch.go", "desktop/internal/workbench/remote_watch.go", @@ -102,6 +108,10 @@ "desktop/internal/workbench/remote_ports.go", "desktop/internal/workbench/remote_ports_view.go", "desktop/internal/workbench/remote_wsl.go", + "desktop/internal/workbench/remote_container.go", + "desktop/internal/workbench/remote_host_containers.go", + "desktop/internal/core/remote_devcontainer.go", + "desktop/internal/workbench/remote_devcontainer.go", "desktop/internal/core/remote_preferences.go", "desktop/internal/remoteconn/preferences.go", "desktop/internal/workbench/remote_preferences.go", @@ -109,12 +119,14 @@ "desktop/internal/settingswindow/remote_workspace_view.go", "desktop/internal/workbench/remote_port_rules.go", "desktop/internal/workbench/remote_port_rules_view.go", + "desktop/internal/workbench/remote_host_files.go", + "desktop/internal/workbench/remote_host_files_view.go", "desktop/internal/workbench/remote_close.go", "desktop/internal/remoteconn/kept.go" ] }, "owner": "Remote", - "verification": "在“远程开发”窗口选中已保存的 Linux SSH 连接点“连接”:SSH 询问出现在窗口中,连接后窗口改为主机的文件夹选择,从主目录开始列出子文件夹(跳过名称不是 UTF-8 的条目并说明数量),可输入 ~ 或 / 开头的路径跳转,不存在的路径说明原因且不能打开;“返回”断开这次会话回到连接表单。选中文件夹点“打开”:新标签页打开远程工作区,窗口标题为“文件夹 [SSH: 连接名]”,项目树经 Core 列出主机目录(本机占位目录始终为空),右键只有复制主机路径和刷新;以安全模式打开的文件夹,编辑器上方说明可以浏览、编辑、保存和搜索主机文件,信任文件夹后才能用 Git;受信任的文件夹说明文件、终端和 Git 都在主机上,运行、调试和语言服务器暂不可用;空白编辑区提示 Search Everywhere 和 Find in Files。在项目树双击文件:编辑器经会话读取主机文件(不超过 16 MiB),保存时带上打开时的大小和修改时间写回主机,新建的文件只在主机上不存在时创建;主机上的文件期间被别人改过时保存被拒绝并显示外部修改冲突,“加载磁盘版本”载入主机内容,本机占位目录始终为空。超过 8 MiB 的保存说明主机单次保存上限,编辑内容保留;主机上缺失、无权限、不是普通文件、超时和连接断开分别说明原因,连接断开后自动重连并把打开的文档和主机重新比对。图片、PDF 等查看器、本地历史和插件终端都被拒绝并提示,不回退到本机;在文件浏览器中显示(标签页右键、Search Everywhere 结果、Git 变更)在远程工作区里不提供。状态栏连接菜单的“打开主机上的文件…”(未连接时不可用)从窗口顶部弹出路径框,默认 ~/,经 remote.readDir 列出路径最后一个“/”之前的文件夹,按其后的文字(不分大小写)筛选名称开头,文件夹在前,以“.”开头时才列出隐藏条目,无法读取的条目说明数量;上下键移动、Tab 补全名称、回车进入文件夹或打开文件,没有匹配时回车按输入的路径打开,Esc 或点外面关闭;不以 / 或 ~/ 开头的输入说明要输入什么,名称含“\\”的路径说明在 Windows 上无法打开。工作区文件夹里的文件与项目树打开的相同、可以编辑;文件夹以外的文件(对标 Zed)在占位目录旁的 .lithe-remote-host 下以只读方式打开(S25):不能切换为可编辑(提示原因并记为拒绝),保存和新建都被拒绝并说明原因、不写主机,状态栏导航路径显示 ~ 开头的主机路径,复制相对路径不提供;重连和关闭前与其他文档一样和主机比对,主机上的改动在没有编辑时重新载入(主机监听只覆盖工作区文件夹)。日志只记 remote_open_host_file、remote_read_dir、toggle_read_only 等操作名和原因,不含主机路径。打开“终端”工具窗口:经会话的 remote.runTerminal 在主机文件夹运行主机账户的登录 shell(不带参数,不读本机 Shell 设置,没有本机 Shell 菜单),标签名为连接名,之后的标签为“连接名 (2)”等;输入按顺序、每块不超过 32 KiB 写入,主机说忙时稍后重试,窗口尺寸随输入发送;输出超过 8 MiB 未显示时丢弃最旧的部分并记一次失败。程序退出显示退出码,被信号结束显示 128+信号,关闭标签不算失败。连接断开时终端显示会话已结束,工作区按退避重连;未连接时按回车说明工作区未连接,重连后按回车在新会话上运行。终端起不来时显示 Core 给出的原因(可能含主机路径),日志只记命令名和错误码。拖到终端的文件粘贴为主机路径并按 POSIX shell 加引号,本机工作区外的文件不粘贴并提示原因;粘贴图片不可用(图片会存到本机)。每个会话连接后,经 remote.runWatch 在主机上递归监听整个文件夹,跳过已启用插件隐藏的文件夹名(按原样比较大小写),插件改变隐藏名称时重新开始监听;在主机上新建、修改、删除文件后,项目树重新列出受影响的目录(Core 的 workspace.filterChanges 按可见性规则过滤,不需要会话),打开的文档与主机比对:没有编辑的重新载入,有编辑的显示外部修改冲突;文件夹外和被隐藏文件夹里的变化不触发列表。监听开始时、主机丢失变化(overflow)时、一次超过 4096 个变化时,重新列出树中展开的目录并比对所有文档,日志每次监听各记一次;主机监听数用尽时其余部分继续监听,提示一次“项目文件可能无法自动更新”。监听中文件夹被删除或移走时立即重新监听;主机找不到文件夹时项目树显示根目录不可用,监听等树重新列出文件夹后再开始,主机与树结论不一致时也只等待、不反复重试。其他监听失败只记命令名和错误码、提示一次,等下一个会话再开始;监听发现连接断开时与心跳一样结束会话并重连。Find in Files 的搜索、计数和替换预览带远程绑定发送,Core 从主机文件夹建立索引并读取主机上的当前内容,结果路径相对主机文件夹;点结果在远程编辑器打开主机文件并定位到匹配处,本机占位目录始终为空。主机监听报告的变化路径在下一次查询前增量更新索引,不重建;监听开始和主机丢失变化时重建一次。包含生成文件的查询每次都重建索引(主机监听跳过插件隐藏的文件夹);主机监听数用尽后、会话断开到下一个会话的监听开始之间,每次查询都重建,只由监听提示一次“项目文件可能无法自动更新”,搜索不再另外提示。查询显示期间主机上的变化让结果重新查询。Search Everywhere 所有页签都可用,文件名和文本来自主机,打开弹窗时重新读取生成文件的名称;远程工作区不启动语言服务器,符号只有 Core 在主机文件中找到的。Replace All 在编辑器中替换打开的文档;未打开的文件经会话读取主机内容,由 Core 替换后,只在主机文件仍是读取时的内容时写回,期间被改过的报告冲突,已被删除的说明主机上找不到文件,其余文件照常替换,都不写本机占位目录。在文件夹选择中打开从未决定过的文件夹:先询问是否信任(显示连接名和主机文件夹,Core 给出上级文件夹时可勾选信任其下的所有文件夹),“信任并打开”把决定按连接名记入 Core 的远程信任记录后以受信任方式打开,“以安全模式打开”只读打开,“返回”回到文件夹选择;之前决定过的文件夹直接按记录打开。安全模式下 Git、提交和日志窗口与本机项目一样说明需要信任,编辑器上方的提示里可以信任文件夹,信任后不重开窗口就在主机上启动 Git。受信任的工作区经会话在主机上运行 Git:状态、暂存、提交、差异(含编辑器行号旁的变更标记)、日志与分支、逐行追溯(读取主机上的文件内容)、搁置与储藏都读写主机仓库,本机占位目录始终没有 .git;“排除到本地”写入主机仓库的 info/exclude(缺少 info 文件夹时在主机上创建,读写期间文件被别人改过时这次排除失败、不覆盖)。同一会话经 remote.runWatch 递归监听主机仓库的 git 目录(公共目录在别处时一并监听),主机上 git checkout、commit 等改动元数据后按路径分类并重新读取状态;监听开始、丢失变化或主机监听数用尽时重新读取一次完整状态,新会话重新开始监听。主机文件夹位于上级目录开始的仓库内时,Git 和提交窗口说明要打开仓库顶层文件夹,不显示变更也不记为失败。工作树列表、锁定、解锁、删除在主机上执行,复制路径复制主机路径;打开、在新窗口打开、在文件浏览器中显示和新建工作树被拒绝并提示。受信任的远程工作区里运行、调试、当前文件运行、测试、构建任务和插件语言服务器都不在本机启动,都记为拒绝并提示,运行、测试和构建工具窗口说明暂不可用。状态栏前端显示连接名和心跳往返时间;连续两次心跳无响应显示“无响应”,第三次结束会话并按 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、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 无头截图;在 Windows 运行 TestCoreRefusesUnadaptedCommandsAndAClosedSessionDetachesTheBinding,验证 Linux 主机路径能通过绑定校验。真实 SSH 主机上的整机验收(包括终端里 vim、top 等全屏程序与窗口缩放,主机上 git checkout 等大批量修改后的监听,以及大仓库上的搜索)仍待完成。远程工作区左侧多出“端口”工具窗口(本机工作区没有,关闭工作区后消失):窗口打开时每 3 秒经 ports.listening 读取主机上正在监听的端口和会话的转发,窗口关闭或未显示时停止读取;同一端口在 0.0.0.0 与 :: 上监听只显示一行;远端端口带上主机监听的 IP 地址,多个地址时显示第一个和其余数量,悬停提示列出全部,地址或网址过长被截断时悬停提示给出全文;列出远端端口、本机地址、进程(名称与 PID,读不到时为“未知”)、来源(监听发现、手动添加)和状态。默认不自动转发任何端口,打开窗口和发现新端口都不转发;行尾“转发”把端口转发到主机上对应族的回环地址,本机在 127.0.0.1 的同号端口监听,该端口被本机其他程序占用时改用空闲端口,本机地址用警告色显示并在提示里说明原端口。右键“转发到指定本机端口…”和已转发行的“更改本机端口…”打开对话框输入 1–65535 的本机端口,非法输入就地说明且不转发;改到另一个端口时先停止原转发再在新端口转发,选择在工作区打开期间保留,停止后再转发仍用该端口。顶部输入端口、主机:端口或网址(http、https、ws、wss,省略端口时按协议默认端口)可手动添加并转发,由 Core 的 remote.parseForwardAddress 解析;格式不对就地说明,网址里带用户名或密码时拒绝并说明,输入框保留原文、日志不记输入内容;同一目标再次添加不重复。网址行按输入的样子显示,转发到主机上提供该端口的回环地址;在浏览器打开和复制本机地址把主机部分换成本机地址并保留路径和查询,ws/wss 网址不提供在浏览器打开;浏览器打不开时提示网址,日志只记失败、不记网址。主机回环地址以外的目标先询问(S28),确认后才带 AllowNonLoopback 转发,取消记为拒绝。已转发行可在浏览器打开、复制本机地址、停止;手动添加且已停止、主机上也没有在监听的行可移除;窗口标题栏可全部停止,标题栏的 ⓘ 说明转发对本机其他程序可见(S30);会话转发数达到 Core 上限时说明上限;状态栏显示已转发数量,点击打开端口窗口;会话结束时转发随之结束,重连后不自动恢复。日志只记 remote.ports.forward/localPort/move/stop/status 等动作和失败操作名,不含主机、地址或进程名。运行 remote_ports_test.go 的 12 个测试、internal/core 的 TestRemoteSessionCommandsOfAnUnknownSession 与 TestRemoteParseForwardAddressReadsPortsAndURLs,以及 TestVisualRemotePorts 无头截图。手动添加的端口和本机端口选择只在工作区打开期间保留,关闭后不保存(需 Core 存储,后续阶段)。端口窗口标题栏的“+”打开“添加转发规则”:方向默认“主机端口 → 另一台服务器”,由主机自己连接目标,数据不经过本机;主机端口可留空由主机选择,目标接受端口、主机:端口或网址(由 Core 的 remote.parseForwardAddress 解析,网址里带用户名或密码时拒绝)。规则默认只在主机的回环地址 127.0.0.1 上监听;勾选“监听主机的全部网卡”时显示警告,每次添加都再次询问、不记住,列表里的监听地址用警告色显示并在悬停提示里说明;目标不是主机自身的回环地址时先询问(S28)。“主机端口 → 本机(反向转发)”只在 设置 › 工具 › 远程工作区 的“反向转发”允许时提供(默认自动,即不允许,对话框说明在哪里开启),每条都询问,主机只在回环地址监听,本机只连接回环地址上的端口。主机端口被占用、主机不允许监听(如 1024 以下)、远端服务不支持、达到会话转发上限(与本机转发合计)、反向转发未被允许分别说明原因,主机端口不是 1–65535 时就地说明,对话框保留输入。端口窗口的“转发规则”一节列出主机监听地址、转到的目标(反向转发为“本机 地址”)、连接数(有失败时注明失败数)和状态,每行可停止,标题栏的全部停止同样停止规则;规则随会话结束而停止,重连后不自动恢复,关闭工作区后也不保存。日志只记 remote.ports.addRule/ruleHost/ruleReverse/ruleConfirm/stopRule 等动作和失败的操作名,不含地址、网址或进程名。运行 remote_port_rules_test.go 的 5 个测试、settingswindow 的 TestRemoteWorkspaceReverseForwardingIsAppliedAndRestored,以及 TestVisualRemotePorts 的转发规则列表、添加对话框和全部网卡询问截图。远程 Git 的 AskPass 转交(推送、拉取时的凭据询问)、从上级目录开始的仓库、打开或新建远程工作树尚未支持。Windows 上“远程开发”窗口在已保存的连接之后以“WSL”标题列出本机安装的 WSL 发行版(Core 的 remote.listWslDistributions,每次打开窗口读取一次;搜索时不列出,标题可折叠;macOS 和没有 WSL 的 Windows 不显示这一组)。选中发行版后右侧说明经本机 wsl.exe 打开、不保存任何信息,可填写 Linux 用户(留空为发行版默认用户),地址显示为 wsl:[用户@]发行版。“连接”经 remote.connect 的 wsl 参数启动,不经 OpenSSH、没有询问,步骤从“启动发行版”开始,不显示读取配置和身份验证;发行版没有安装或没能启动、本机找不到 wsl.exe 时分别说明,不显示 SSH 的排查提示,也没有“编辑连接”;Core 拒绝的用户名或发行版名就地说明。连接后与 SSH 相同:选择文件夹、信任询问、工作区、心跳与重连;窗口标题为“文件夹 [WSL: 发行版]”,状态栏为“WSL: 发行版”(SSH 工作区的“SSH”也由同一参数给出),列表和概览显示已打开该发行版的窗口数。发行版不写入已保存的连接,打开过的文件夹不记入最近文件夹。日志只有 remote.wsl.select、remote.connect 等动作,不含发行版名、用户名或主机路径。运行 remote_wsl_test.go 的 3 个测试、internal/core 的 TestRemoteConnectSendsWSLAloneAndCoreRefusesItByField 与 TestRemoteListWSLDistributionsIsUnavailableOutsideWindows,以及 TestVisualRemoteConnections 的 WSL 截图;真实 Windows 上的 WSL 验收(wsl.exe 的错误输出、--exec 的二进制透传、结束 wsl.exe 后 Linux 进程是否退出、未知用户)仍待完成。打开“设置 › 工具 › 远程工作区”:页面只读取、不创建任何文件。“SSH 程序”默认“自动(Core 在 PATH 上找到的 ssh 路径)”,找不到时为“自动(未找到 ssh)”;“选择…”选一个文件作为草稿,下拉菜单可回到自动;保存的程序缺失或不可执行时在行下说明。“SSH 配置文件”只显示 Core 读取的 ~/.ssh/config 路径,不存在时注明。“自动重连时长”可选“自动(1 分钟)”、不自动重连、15 秒到 1 小时,保存过的其他值也列出。“反向转发”默认“自动(不允许)”,可选允许或不允许,ⓘ 说明主机上的所有用户都能连接反向转发的端口、每条规则仍会确认。“关闭工作区”卡片里“关闭时的远端进程”可选“每次询问”(默认)、“结束”和“保留在远端”,关闭对话框勾选“记住我的选择”后只能在这里改回;“常驻会话的空闲超时”只读显示 Core 报告的远端服务超时(10 分钟),ⓘ 说明断线且没人保留的会话多久后由主机结束。“保存位置”显示偏好目录下的 remote/preferences.json,还没有文件时注明修改后才创建。修改只是草稿:侧栏和底部显示未应用数量,“应用”或“好”经 Core 的 remote.editPreferences 写入(程序先于时长),写入后重新读取显示;Core 拒绝相对路径、不存在、不可执行的程序或超出 0–3600 秒的时长时在页面说明原因并保留草稿,不写文件;文件期间被改过时重新读取并请用户再次应用;文件损坏时说明路径、不提供编辑,此时连接、测试连接、读取有效设置和导入 SSH 主机都失败并说明原因,不用未经用户选择的程序启动 OpenSSH。选中的 SSH 程序用于连接、测试连接、有效设置和 SSH 配置导入(WSL 经 wsl.exe 启动,不使用它)。日志只记 remote_preferences_settings_load/save 等操作名和 Core 错误码,不记路径。运行 settingswindow 的 TestRemoteWorkspace* 6 个测试、remoteconn 的 preferences_test.go、internal/core 的 TestRemotePreferences*,以及 TestVisualRemoteWorkspace 无头截图(中英文、深浅色,自动值、草稿和关闭时保留远端进程三种状态)。真实 SSH 主机上关闭后保留、重连接回和结束保留进程的整机验收,以及保留进程的输出重新接回终端和运行窗口(后续阶段),仍待完成。", + "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 和提交窗口说明要打开仓库顶层文件夹,不显示变更也不记为失败。工作树列表、锁定、解锁、删除在主机上执行,复制路径复制主机路径;打开、在新窗口打开、在文件浏览器中显示和新建工作树被拒绝并提示。受信任的远程工作区里运行、调试、当前文件运行、测试、构建任务和插件语言服务器都不在本机启动,都记为拒绝并提示,运行、测试和构建工具窗口说明暂不可用。状态栏前端显示连接名和心跳往返时间;连续两次心跳无响应显示“无响应”,第三次结束会话并按 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、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 无头截图;在 Windows 运行 TestCoreRefusesUnadaptedCommandsAndAClosedSessionDetachesTheBinding,验证 Linux 主机路径能通过绑定校验。真实 SSH 主机上的整机验收(包括终端里 vim、top 等全屏程序与窗口缩放,主机上 git checkout 等大批量修改后的监听,以及大仓库上的搜索)仍待完成。远程工作区左侧多出“端口”工具窗口(本机工作区没有,关闭工作区后消失):窗口打开时每 3 秒经 ports.listening 读取主机上正在监听的端口和会话的转发,窗口关闭或未显示时停止读取;同一端口在 0.0.0.0 与 :: 上监听只显示一行;远端端口带上主机监听的 IP 地址,多个地址时显示第一个和其余数量,悬停提示列出全部,地址或网址过长被截断时悬停提示给出全文;列出远端端口、本机地址、进程(名称与 PID,读不到时为“未知”)、来源(监听发现、手动添加)和状态。默认不自动转发任何端口,打开窗口和发现新端口都不转发;行尾“转发”把端口转发到主机上对应族的回环地址,本机在 127.0.0.1 的同号端口监听,该端口被本机其他程序占用时改用空闲端口,本机地址用警告色显示并在提示里说明原端口。右键“转发到指定本机端口…”和已转发行的“更改本机端口…”打开对话框输入 1–65535 的本机端口,非法输入就地说明且不转发;改到另一个端口时先停止原转发再在新端口转发,选择在工作区打开期间保留,停止后再转发仍用该端口。顶部输入端口、主机:端口或网址(http、https、ws、wss,省略端口时按协议默认端口)可手动添加并转发,由 Core 的 remote.parseForwardAddress 解析;格式不对就地说明,网址里带用户名或密码时拒绝并说明,输入框保留原文、日志不记输入内容;同一目标再次添加不重复。网址行按输入的样子显示,转发到主机上提供该端口的回环地址;在浏览器打开和复制本机地址把主机部分换成本机地址并保留路径和查询,ws/wss 网址不提供在浏览器打开;浏览器打不开时提示网址,日志只记失败、不记网址。主机回环地址以外的目标先询问(S28),确认后才带 AllowNonLoopback 转发,取消记为拒绝。已转发行可在浏览器打开、复制本机地址、停止;手动添加且已停止、主机上也没有在监听的行可移除;窗口标题栏可全部停止,标题栏的 ⓘ 说明转发对本机其他程序可见(S30);会话转发数达到 Core 上限时说明上限;状态栏显示已转发数量,点击打开端口窗口;会话结束时转发随之结束,重连后不自动恢复。日志只记 remote.ports.forward/localPort/move/stop/status 等动作和失败操作名,不含主机、地址或进程名。运行 remote_ports_test.go 的 12 个测试、internal/core 的 TestRemoteSessionCommandsOfAnUnknownSession 与 TestRemoteParseForwardAddressReadsPortsAndURLs,以及 TestVisualRemotePorts 无头截图。手动添加的端口和本机端口选择只在工作区打开期间保留,关闭后不保存(需 Core 存储,后续阶段)。端口窗口标题栏的“+”打开“添加转发规则”:方向默认“主机端口 → 另一台服务器”,由主机自己连接目标,数据不经过本机;主机端口可留空由主机选择,目标接受端口、主机:端口或网址(由 Core 的 remote.parseForwardAddress 解析,网址里带用户名或密码时拒绝)。规则默认只在主机的回环地址 127.0.0.1 上监听;勾选“监听主机的全部网卡”时显示警告,每次添加都再次询问、不记住,列表里的监听地址用警告色显示并在悬停提示里说明;目标不是主机自身的回环地址时先询问(S28)。“主机端口 → 本机(反向转发)”只在 设置 › 工具 › 远程工作区 的“反向转发”允许时提供(默认自动,即不允许,对话框说明在哪里开启),每条都询问,主机只在回环地址监听,本机只连接回环地址上的端口。主机端口被占用、主机不允许监听(如 1024 以下)、远端服务不支持、达到会话转发上限(与本机转发合计)、反向转发未被允许分别说明原因,主机端口不是 1–65535 时就地说明,对话框保留输入。端口窗口的“转发规则”一节列出主机监听地址、转到的目标(反向转发为“本机 地址”)、连接数(有失败时注明失败数)和状态,每行可停止,标题栏的全部停止同样停止规则;规则随会话结束而停止,重连后不自动恢复,关闭工作区后也不保存。日志只记 remote.ports.addRule/ruleHost/ruleReverse/ruleConfirm/stopRule 等动作和失败的操作名,不含地址、网址或进程名。运行 remote_port_rules_test.go 的 5 个测试、settingswindow 的 TestRemoteWorkspaceReverseForwardingIsAppliedAndRestored,以及 TestVisualRemotePorts 的转发规则列表、添加对话框和全部网卡询问截图。远程 Git 的 AskPass 转交(推送、拉取时的凭据询问)、从上级目录开始的仓库、打开或新建远程工作树尚未支持。Windows 上“远程开发”窗口在已保存的连接之后以“WSL”标题列出本机安装的 WSL 发行版(Core 的 remote.listWslDistributions,每次打开窗口读取一次;搜索时不列出,标题可折叠;macOS 和没有 WSL 的 Windows 不显示这一组)。选中发行版后右侧说明经本机 wsl.exe 打开、不保存任何信息,可填写 Linux 用户(留空为发行版默认用户),地址显示为 wsl:[用户@]发行版。“连接”经 remote.connect 的 wsl 参数启动,不经 OpenSSH、没有询问,步骤从“启动发行版”开始,不显示读取配置和身份验证;发行版没有安装或没能启动、本机找不到 wsl.exe 时分别说明,不显示 SSH 的排查提示,也没有“编辑连接”;Core 拒绝的用户名或发行版名就地说明。连接后与 SSH 相同:选择文件夹、信任询问、工作区、心跳与重连;窗口标题为“文件夹 [WSL: 发行版]”,状态栏为“WSL: 发行版”(SSH 工作区的“SSH”也由同一参数给出),列表和概览显示已打开该发行版的窗口数。发行版不写入已保存的连接,打开过的文件夹不记入最近文件夹。日志只有 remote.wsl.select、remote.connect 等动作,不含发行版名、用户名或主机路径。运行 remote_wsl_test.go 的 3 个测试、internal/core 的 TestRemoteConnectSendsWSLAloneAndCoreRefusesItByField 与 TestRemoteListWSLDistributionsIsUnavailableOutsideWindows,以及 TestVisualRemoteConnections 的 WSL 截图;真实 Windows 上的 WSL 验收(wsl.exe 的错误输出、--exec 的二进制透传、结束 wsl.exe 后 Linux 进程是否退出、未知用户)仍待完成。打开“设置 › 工具 › 远程工作区”:页面只读取、不创建任何文件。“SSH 程序”默认“自动(Core 在 PATH 上找到的 ssh 路径)”,找不到时为“自动(未找到 ssh)”;“选择…”选一个文件作为草稿,下拉菜单可回到自动;保存的程序缺失或不可执行时在行下说明。“SSH 配置文件”只显示 Core 读取的 ~/.ssh/config 路径,不存在时注明。“自动重连时长”可选“自动(1 分钟)”、不自动重连、15 秒到 1 小时,保存过的其他值也列出。“反向转发”默认“自动(不允许)”,可选允许或不允许,ⓘ 说明主机上的所有用户都能连接反向转发的端口、每条规则仍会确认。“关闭工作区”卡片里“关闭时的远端进程”可选“每次询问”(默认)、“结束”和“保留在远端”,关闭对话框勾选“记住我的选择”后只能在这里改回;“常驻会话的空闲超时”只读显示 Core 报告的远端服务超时(10 分钟),ⓘ 说明断线且没人保留的会话多久后由主机结束。“保存位置”显示偏好目录下的 remote/preferences.json,还没有文件时注明修改后才创建。修改只是草稿:侧栏和底部显示未应用数量,“应用”或“好”经 Core 的 remote.editPreferences 写入(程序先于时长),写入后重新读取显示;Core 拒绝相对路径、不存在、不可执行的程序或超出 0–3600 秒的时长时在页面说明原因并保留草稿,不写文件;文件期间被改过时重新读取并请用户再次应用;文件损坏时说明路径、不提供编辑,此时连接、测试连接、读取有效设置和导入 SSH 主机都失败并说明原因,不用未经用户选择的程序启动 OpenSSH。选中的 SSH 程序用于连接、测试连接、有效设置和 SSH 配置导入(WSL 经 wsl.exe 启动,不使用它)。日志只记 remote_preferences_settings_load/save 等操作名和 Core 错误码,不记路径。运行 settingswindow 的 TestRemoteWorkspace* 6 个测试、remoteconn 的 preferences_test.go、internal/core 的 TestRemotePreferences*,以及 TestVisualRemoteWorkspace 无头截图(中英文、深浅色,自动值、草稿和关闭时保留远端进程三种状态)。真实 SSH 主机上关闭后保留、重连接回和结束保留进程的整机验收,以及保留进程的输出重新接回终端和运行窗口(后续阶段),仍待完成。“远程开发”窗口在 WSL 发行版之后以“容器”标题列出本机 Docker 和 Podman 正在运行的容器(Core 的 remote.listContainers,每次打开窗口读取一次,两个引擎在同一个后台任务里依次读取,一个超时或报错时跳过它并记一次 remote_containers_list 失败,另一个照常列出;搜索时不列出,标题可折叠;两个引擎都没有时不显示这一组)。每行显示容器名和“引擎 · 镜像”,已有窗口打开它时显示绿点。选中容器后右侧显示引擎标签、地址 引擎:[用户@]容器、镜像与引擎给出的状态,说明经本机引擎进入正在运行的容器、不启动不创建不改动容器、不挂载目录、不保存任何信息,可填写容器内用户(用户名、uid 或 用户:组,留空为镜像默认用户)。“连接”经 remote.connect 的 container 参数进入,不经 OpenSSH、没有询问、不发送 SSH 偏好,步骤从“进入容器”开始;容器已停止或暂停、引擎没有应答时说明这几种可能,找不到引擎命令行时说明需要安装哪个引擎,引擎输出只显示在步骤下方,不显示 SSH 的排查提示,也没有“编辑连接”;Core 拒绝的用户或容器名就地说明。连接后与 SSH 相同:选择文件夹、信任询问(信任记录包含容器)、工作区、心跳与重连;窗口标题为“文件夹 [容器: 容器名]”,状态栏为“容器: 容器名”,列表和概览按引擎和容器名显示已打开的窗口数。按容器名连接,所以同名重建的容器仍能接上;容器不写入已保存的连接,打开过的文件夹不记入最近文件夹。日志只有 remote.container.select、remote.connect 等动作,不含容器名、镜像、状态或用户名。测试替换的内核不运行本机的 docker 或 podman。运行 remote_container_test.go 的 4 个测试、internal/core 的 TestRemoteConnectSendsAContainerAloneAndCoreRefusesItByField 与 TestRemoteListContainersNamesTheSessionAndTheEngine,以及 TestVisualRemoteConnections 的容器截图;真实 Docker、Podman 与 Windows 上的整机验收仍待完成。“远程开发”窗口列表工具栏和空白页的“从 devcontainer.json 打开…”打开“在 Dev Container 中打开”页(窗口标题为“远程开发 › 在 Dev Container 中打开”):说明用官方 Dev Container CLI 按本机文件夹的 devcontainer.json 构建并启动容器、构建会运行文件夹的 Dockerfile、features 和命令所以文件夹必须受信任、Lithe 不额外挂载目录也不额外加参数。“选择文件夹…”打开系统文件夹选择,也可输入路径后按回车;相对路径、不存在的路径就地说明。读取文件夹时经 Core 的 remote.devcontainerConfigs 按规范顺序列出 .devcontainer/devcontainer.json、.devcontainer.json 和 .devcontainer 下一层文件夹里的配置,配置有 name 时显示“名称(路径)”,默认选第一个;没有配置时说明并且不能构建。容器引擎可选 Docker 或 Podman。同时读取文件夹的信任:未受信任时说明并把按钮换成“信任并构建”,先以与打开受信任项目相同的方式写入本机信任记录(记一次 workspace.trust.grant),再构建;读取信任失败时说明原因、不能构建。“构建并打开”经 remote.devcontainerUp 运行 CLI(带 projectCodeAllowed),CLI 的输出逐行显示在“构建日志”里(Core 已隐藏敏感信息,最多保留最近 5000 行,Core 截断时在下方说明),只显示、不写入 Lithe 的日志;构建期间左侧列表、配置、引擎和文件夹都不能改,底部显示“正在构建 dev container…”和“停止”。“停止”取消这次构建,日志保留并说明已经启动的容器会继续运行,不记失败;“取消”和关闭窗口也会先停止构建。找不到 devcontainer CLI 时说明用 npm 安装,CLI 报告失败时显示它的输出,超过一小时、结果里没有容器或工作区文件夹、文件夹不受信任分别说明,各记一次 remote_devcontainer_up 失败。成功后选中 CLI 返回的容器(重新读取容器列表,显示镜像),以 CLI 返回的 remoteUser 为容器内用户,按容器连接并直接打开 CLI 返回的工作区文件夹(与容器入口相同的信任询问、工作区、心跳与重连)。日志只有 remote.devcontainer.open/choose/build/stop、remote.connect 等动作,不含文件夹、配置名、容器名、用户名或 CLI 输出。测试替换的内核不运行本机的 devcontainer、docker 或 podman。运行 remote_devcontainer_test.go 的 5 个测试、internal/core 的 TestRemoteDevcontainer*,以及 TestVisualRemoteConnections 的 devcontainer 截图;装有 Dev Container CLI 的真实 Docker、Podman 上的整机验收仍待完成。在 SSH 主机或 WSL 发行版的文件夹选择里,标题栏的“主机上的容器”在文件夹的位置列出那台主机上 Docker 和 Podman 正在运行的容器(经浏览会话的 remote.listContainers 依次读取两个引擎,在远端服务的环境里运行,所以列出的容器就是能进入的;主机没有引擎命令行时说明没有找到 Docker 或 Podman,引擎报错时显示它的输出、不写日志),每行显示容器名、“引擎 · 镜像”和状态,可填写容器内用户(留空为镜像默认用户)。“进入容器”或双击一行结束浏览会话,重新连接主机并经主机上的引擎 exec 进入容器(OpenSSH 会再次询问它要问的内容;步骤与主机相同,地址显示为“主机 › 引擎:[用户@]容器”),随后在容器里选择文件夹;“返回文件夹”回到主机的文件夹。主机连不上或容器已停止、暂停、引擎没有应答时用同一段文字说明并点名引擎,具体原因在诊断输出里;没有“编辑连接”,“重试”进入同一台主机上的同一个容器。工作区身份为“已保存连接或发行版的身份/引擎:[用户@]容器”,窗口名为“容器名(主机名)”,不写入已保存的连接,打开过的文件夹不记入最近文件夹;信任记录包含主机与容器。Core 同样只进正在运行的容器,不提权、不改容器、不挂载(S32)。主机上不支持从 devcontainer.json 构建(devcontainer up 只在本机运行)。日志只有 remote.browse.containers/folders、remote.browse.container.enter、remote.connect 等动作和 remote_host_containers_list 失败名,不含主机、容器名、镜像、用户名或主机路径。运行 remote_host_containers_test.go 的 3 个测试和 TestVisualRemoteConnections 的主机容器截图;真实 SSH 主机与 Windows WSL 上的容器验收仍待完成。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -151,5 +163,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 写入同一份偏好文档。进程名称和命令只在对话框里显示,不写日志。" + "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 参数。未受信任的文件夹由桌面端先写本机信任记录再构建。" }