diff --git a/.agents/notes/implemented/feature/2026-11-22-remote-host-files-outside-workspace.md b/.agents/notes/implemented/feature/2026-11-22-remote-host-files-outside-workspace.md new file mode 100644 index 000000000..9cbada5b2 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-11-22-remote-host-files-outside-workspace.md @@ -0,0 +1,67 @@ +# Agent 笔记:远程工作区按路径打开主机上的文件——工作区外只读 + +状态:已实现 + +## 先说结论 + +远程工作区状态栏连接菜单里的“打开主机上的文件…”从窗口顶部弹出路径框(对标 Zed 的 Open File 提示),输入 `~/` 或 `/` 开头的主机路径,边输入边经 `remote.readDir` 列出那一层的文件夹和文件。工作区文件夹里的文件照常可以编辑;文件夹以外的文件以只读方式打开(设计 S25),不能切换为可编辑,保存和新建都被拒绝。文件夹以外的文件用 Core 已有的占位路径表示(占位根旁的 `.lithe-remote-host/<主机路径>`),桌面端不另造一套路径。 + +## 问题 + +Issue #2231 的 R0 要求能打开工作区文件夹以外的主机文件(例如 `~/.bashrc`、`/etc/hosts`),用户定为“对标 Zed”。需要回答: + +- 从哪里打开:项目树只列工作区文件夹,Search Everywhere 只搜工作区; +- 这些文件在本机怎样表示:编辑器、标签页、状态栏都以本机路径为键,而远程工作区的本机根是一个不能读写的空占位目录; +- 能不能编辑:文件夹外的文件不在信任范围内,也不在主机监听范围内,改了别人看不到冲突。 + +## 决策 + +### 单独的路径弹窗,不挤进 Search Everywhere + +- 入口是状态栏连接菜单的“打开主机上的文件…”,没有会话时不可用。弹窗挂在窗口顶部,和 Search Everywhere 的位置一致,路径框默认 `~/`。 +- 列表显示路径最后一个“/”之前的文件夹,按其后的文字不分大小写筛选名称开头,文件夹在前;只有输入以“.”开头时才列隐藏条目。上下键移动,Tab 补全,回车进入文件夹或打开文件,没有匹配时回车按输入的路径打开,Esc 关闭。 +- 不用 Search Everywhere 的原因:它的第一个字符 `/` 已经被“操作”页签占用,主机路径正好都以 `/` 开头,混在一起会让 `/etc` 变成搜操作。 + +### 文件夹外的文件用 Core 的占位路径,只读打开 + +- 本机路径一律由 `remoteplaceholder.LocalPath` 求出:工作区内的在占位根下,工作区外的在占位根旁的 `.lithe-remote-host` 下。Git 返回的工作区外路径本来就用这个规则(见 `remoteplaceholder.Outside`),文件打开沿用它,所以标签页、Git 差异里同一个主机文件只有一个本机键。 +- `document.hostOutside` 标记文件夹外的文档:打开时 `SetReadOnly(true)`,“切换只读”被拒绝并提示原因;`remoteDocuments.save/create` 对这类路径返回 `errRemoteReadOnly`,不发任何写请求。这是 S25 的落地:信任只覆盖工作区文件夹,文件夹外的文件不该因为打开了工作区就能改。 +- 状态栏导航路径显示 `~` 开头的主机路径(不暴露占位目录),复制路径菜单不提供“复制相对路径”,因为它不在项目里。 +- 主机监听只覆盖工作区文件夹,文件夹外的文件不会收到变化通知;它们和其他文档一样在重连和关闭前与主机比对,没有编辑时重新载入。 + +### 远程工作区不提供“在文件浏览器中显示” + +占位路径在本机不存在,标签页右键、Search Everywhere 结果和 Git 变更里的“在 Finder/资源管理器中显示”在远程工作区里总是失败(ENOTDIR)。这是这次顺手修掉的既有问题:远程工作区里直接不显示这一项,而不是点了报错。 + +## 正确与错误示例 + +正确:新功能要用主机上工作区外的路径时,经 `remoteplaceholder.LocalPath(p.root, remoteRoot, host)` 换成本机键,再判断 `p.remoteOutsideDocument(path)` 决定能否写。 + +错误:在桌面端拼 `filepath.Join(os.TempDir(), host)` 之类的本机路径,或者从占位路径里截字符串还原主机路径——前者会让同一个主机文件出现两个键,后者在 Windows 上会把 `\` 和盘符混进主机路径。 + +## 考虑过的备选方案 + +- 在 Search Everywhere 里加“主机文件”页签:被否,`/` 前缀冲突,而且它按项目索引搜索,不适合逐层浏览。 +- 文件夹外的文件也允许编辑并带版本保存:被否,S25 要求信任边界之外只读;以后真有需要,应当由用户把那个文件夹作为另一个远程工作区打开并单独信任。 +- 打开文件夹外的文件时扩大主机监听:被否,监听整个主目录或根目录代价太大,比对已经能在重连和关闭前发现变化。 + +## 后果 + +- 收益:工作区外的主机文件和 Git 返回的工作区外路径共用同一个本机键;信任边界之外不会被写;不用为它扩大主机监听。 +- 代价:工作区外的文件只能看不能改,确实要改时需要把那个文件夹另开为远程工作区;主机上对它的修改要等重连或关闭标签前比对才发现。 +- 列出文件夹每次都是一次 `remote.readDir` 往返,深层路径边输入边列出,网络慢时列表会短暂显示“正在加载”。 + +## 验证 + +- `desktop/internal/workbench/remote_host_files_test.go` 的 `TestRemoteOpenFileOnHost`:列表筛选、隐藏条目、进入文件夹、Tab 补全、工作区内可编辑、工作区外只读且保存/新建被拒、状态栏主机路径、非绝对路径提示、日志不含主机和路径。 +- `desktop/internal/remoteplaceholder` 的 `TestHostAndLocalPathsMapBothWays` 覆盖 `Outside`。 +- `TestVisualRemoteWorkspace` 的 `host-file`、`host-file-readonly` 无头截图(`docs/assets/remote-workspace/`)。 +- 真实 SSH 主机上的整机验收和 Windows 上的验证尚未完成。 + +```bash +scripts/desktop/desktop-go.sh test ./internal/remoteplaceholder ./internal/workbench -run 'TestRemoteOpenFileOnHost|TestHostAndLocalPathsMapBothWays' -count=1 +``` + +## 适用范围 + +`desktop/internal/workbench/remote_host_files.go`、`remote_host_files_view.go`、`remote_documents.go` 中的 `writable`/`errRemoteReadOnly`、`documents.go` 的 `hostOutside`,以及 `desktop/internal/remoteplaceholder` 的 `Outside`。以后远程工作区里任何打开主机文件的入口(例如远程运行输出里的路径链接)都要经 `remoteplaceholder.LocalPath` 求本机键、按 `hostOutside` 决定只读,不要另开一条可写路径。 diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 087d84514..575a0aea9 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1651,6 +1651,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.document.failed": "the host could not read or write it", "desktop.remote.document.notFound": "the file no longer exists on the host", "desktop.remote.document.permissionDenied": "the host account has no permission to access it", + "desktop.remote.document.readOnly": "the file is outside the workspace folder and opens read-only", "desktop.remote.document.timedOut": "the host did not answer in time", "desktop.remote.document.tooLargeToSave": "This file exceeds the {limit} the host takes in one save. Your edits remain open.", "desktop.remote.edit": "Edit", @@ -1693,6 +1694,13 @@ 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.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", + "desktop.remote.hostFile.readOnly": "Files outside the remote workspace folder open read-only.", + "desktop.remote.hostFile.readOnlyNote": "Files in the workspace folder open for editing; other files on the host open read-only.", + "desktop.remote.hostFile.title": "Open File on Host", + "desktop.remote.hostFile.unrepresentable": "This path has a name with “\\” in it, which cannot be opened on Windows", "desktop.remote.hostHelp": "A host name, an IP address, or a Host alias from ~/.ssh/config. OpenSSH applies its configuration as usual: a field left empty here does not override it.", "desktop.remote.hostKey.fingerprint": "Fingerprint", "desktop.remote.hostKey.hint": "Compare the fingerprint with the one your administrator gave you. Trusting adds the key to ~/.ssh/known_hosts.", @@ -1931,6 +1939,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.status.disconnected": "{kind}: {name} · Disconnected", "desktop.remote.status.label": "Remote Connection", "desktop.remote.status.latency": "{kind}: {name} · {ms} ms", + "desktop.remote.status.openHostFile": "Open File on Host…", "desktop.remote.status.reconnect": "Reconnect", "desktop.remote.status.reconnecting": "{kind}: {name} · Reconnecting…", "desktop.remote.status.unresponsive": "{kind}: {name} · Not responding", @@ -5474,6 +5483,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.document.failed": "主机无法读取或写入这个文件", "desktop.remote.document.notFound": "主机上已没有这个文件", "desktop.remote.document.permissionDenied": "主机账户没有访问这个文件的权限", + "desktop.remote.document.readOnly": "该文件在工作区文件夹以外,只能以只读方式打开", "desktop.remote.document.timedOut": "主机没有及时响应", "desktop.remote.document.tooLargeToSave": "文件超过主机单次保存上限 {limit},编辑内容仍保留。", "desktop.remote.edit": "编辑", @@ -5516,6 +5526,13 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.host": "主机", "desktop.remote.host.cores": "{count} 核", "desktop.remote.host.diskOf": "共 {total}", + "desktop.remote.hostFile.empty": "没有匹配的文件或文件夹", + "desktop.remote.hostFile.pathHint": "请输入以 / 或 ~/ 开头的路径", + "desktop.remote.hostFile.placeholder": "主机上的路径,例如 ~/notes.txt 或 /etc/hosts", + "desktop.remote.hostFile.readOnly": "远程工作区文件夹以外的文件只能以只读方式打开。", + "desktop.remote.hostFile.readOnlyNote": "工作区文件夹里的文件可以编辑,主机上的其他文件以只读方式打开。", + "desktop.remote.hostFile.title": "打开主机上的文件", + "desktop.remote.hostFile.unrepresentable": "这个路径里有含“\\”的名称,在 Windows 上无法打开", "desktop.remote.hostHelp": "主机名、IP 地址或 ~/.ssh/config 里的 Host 别名。OpenSSH 照常读取它的配置;这里留空的字段不会覆盖配置里的值。", "desktop.remote.hostKey.fingerprint": "指纹", "desktop.remote.hostKey.hint": "请与管理员提供的指纹核对。信任后,密钥会加入 ~/.ssh/known_hosts。", @@ -5754,6 +5771,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.status.disconnected": "{kind}: {name} · 已断开", "desktop.remote.status.label": "远程连接", "desktop.remote.status.latency": "{kind}: {name} · {ms} 毫秒", + "desktop.remote.status.openHostFile": "打开主机上的文件…", "desktop.remote.status.reconnect": "重新连接", "desktop.remote.status.reconnecting": "{kind}: {name} · 正在重新连接…", "desktop.remote.status.unresponsive": "{kind}: {name} · 无响应", diff --git a/desktop/internal/remoteplaceholder/remoteplaceholder.go b/desktop/internal/remoteplaceholder/remoteplaceholder.go index 1b6d1d9bb..7415e7f06 100644 --- a/desktop/internal/remoteplaceholder/remoteplaceholder.go +++ b/desktop/internal/remoteplaceholder/remoteplaceholder.go @@ -153,6 +153,13 @@ func HostPath(root, remoteRoot, local string) (string, bool) { return "", false } +// Outside says whether local stands for a host path outside the workspace whose local root is +// root: one below root's sibling (HostSuffix), not below root itself. +func Outside(root, local string) bool { + _, ok := below(root+HostSuffix, local) + return ok +} + // LocalPath is the path that stands for host, an absolute host path, in the same workspace: the // inverse of HostPath. ok is false for a path that is not absolute, and on Windows for one with a // name holding "\", which would name another path there. diff --git a/desktop/internal/remoteplaceholder/remoteplaceholder_test.go b/desktop/internal/remoteplaceholder/remoteplaceholder_test.go index 5cc751d02..a7bdf7c87 100644 --- a/desktop/internal/remoteplaceholder/remoteplaceholder_test.go +++ b/desktop/internal/remoteplaceholder/remoteplaceholder_test.go @@ -126,6 +126,13 @@ func TestHostAndLocalPathsMapBothWays(t *testing.T) { if !ok || host != tc.host { t.Errorf("HostPath(%q) = %q, %v; want %q", tc.local, host, ok, tc.host) } + // Only the paths below the sibling stand for host files outside the workspace. + if outside, want := Outside(root, tc.local), strings.HasPrefix(tc.local, sibling); outside != want { + t.Errorf("Outside(%q) = %v; want %v", tc.local, outside, want) + } + } + if Outside(root, root+"x") || Outside(root, filepath.Dir(root)) { + t.Error("Outside took a path that names no host path") } if local, ok := LocalPath(Root(anchor, "c1", "/"), "/", "/etc/hosts"); !ok || local != filepath.Join(Root(anchor, "c1", "/"), "etc", "hosts") { t.Errorf("LocalPath below the host's root = %q, %v", local, ok) diff --git a/desktop/internal/workbench/documents.go b/desktop/internal/workbench/documents.go index def6e8103..bd23c450d 100644 --- a/desktop/internal/workbench/documents.go +++ b/desktop/internal/workbench/documents.go @@ -18,6 +18,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/editorview" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteplaceholder" "github.com/1lck/Lithe-IDEA/desktop/internal/winpath" "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" @@ -136,6 +137,9 @@ type document struct { // watched, saved or synchronized with a language server, and the host keeps no // copy once it closes. virtual bool + // hostOutside marks a remote workspace's file outside its host folder, which opens + // read-only and stays so (remote_host_files.go, S25). + hostOutside bool // encoding is the id of the text encoding the file is read and written in; "" is plain // UTF-8. hasBOM says a byte order mark leads the file. diskBytes are the bytes the file // held when it was last read or written, kept only for a document whose bytes differ from @@ -279,9 +283,9 @@ func (a *App) openFile(p *project, path string) { return } if p.remote != nil { - // A remote workspace edits the files of its host folder; the viewers still read this - // computer's files. - if _, ok := remoteHostPathBelow(p.root, p.remote.binding.RemoteRoot(), path); !ok && a.refuseRemote(p, "open_file") { + // A remote workspace edits the files of its host folder and shows other host files + // read-only (remote_host_files.go); the viewers still read this computer's files. + if _, ok := remoteplaceholder.HostPath(p.root, p.remote.binding.RemoteRoot(), path); !ok && a.refuseRemote(p, "open_file") { return } if _, ok := viewerKindOf(path); ok && a.refuseRemote(p, "open_viewer") { @@ -546,7 +550,7 @@ func (a *App) placeDocumentAs(p *project, path, name string, content editorview. return } p.docs.next = id - d := &document{id: id, path: path, name: name, languageID: languageID, grammar: grammar, virtual: virtual} + d := &document{id: id, path: path, name: name, languageID: languageID, grammar: grammar, virtual: virtual, hostOutside: !virtual && p.remoteOutsideDocument(path)} d.view = editorview.New(editorview.Config{ Label: name, Content: content, @@ -558,7 +562,7 @@ func (a *App) placeDocumentAs(p *project, path, name string, content editorview. a.mirrorDocumentEdit(p, d, edit) }, }) - d.view.SetReadOnly(virtual) + d.view.SetReadOnly(virtual || d.hostOutside) d.view.SetVimExit(func(cmd string) bool { return a.vimExit(p, d, cmd) }) setupFolding(d) d.breakpointText = d.view.TextSnapshot() diff --git a/desktop/internal/workbench/editor_view.go b/desktop/internal/workbench/editor_view.go index cc5e6fa7b..0868a1e3c 100644 --- a/desktop/internal/workbench/editor_view.go +++ b/desktop/internal/workbench/editor_view.go @@ -484,6 +484,11 @@ func (a *App) onKey(event gfx.KeyEvent) gfx.EventResult { return result } } + if p := a.project; p != nil && p.remote != nil && p.remote.hostFiles.open { + if result := a.remoteHostFilesKey(p, event); result.Handled { + return result + } + } if event.Release { return gfx.EventResult{} } diff --git a/desktop/internal/workbench/gitreview_actions.go b/desktop/internal/workbench/gitreview_actions.go index 5058ac8c2..5a48811d6 100644 --- a/desktop/internal/workbench/gitreview_actions.go +++ b/desktop/internal/workbench/gitreview_actions.go @@ -81,7 +81,8 @@ func (a *App) changeMenuItems(c ui.C, p *project, change core.GitChange) func(*u c.After(func() { a.openTreeRemoval(p, []string{rel}) }) } menu.Separator() - if !deleted && menu.Item(revealLabel(lang)).Clicked() { + // The placeholder path of a remote workspace's file is nothing the file manager can show. + if !deleted && p.remote == nil && menu.Item(revealLabel(lang)).Clicked() { c.After(func() { a.performed("git.change.reveal", surfaceContextMenu) a.revealPath(full) diff --git a/desktop/internal/workbench/remote_documents.go b/desktop/internal/workbench/remote_documents.go index 8aa6f9955..dd64e55fc 100644 --- a/desktop/internal/workbench/remote_documents.go +++ b/desktop/internal/workbench/remote_documents.go @@ -6,22 +6,21 @@ import ( "encoding/json" "errors" "io/fs" - "path" - "path/filepath" "strconv" - "strings" "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/documentio" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteplaceholder" ) // The editor of a remote workspace reads and writes its files on the host (#2231, R0 step 3). // A document keeps the placeholder path the Project tool window shows; each read and write -// translates it to the host path below the workspace's folder and goes over the workspace's -// current session. Nothing is read from or written to the placeholder, and a path outside the -// workspace's folder is refused. +// translates it to the host path (remoteplaceholder.HostPath) and goes over the workspace's +// current session. Nothing is read from or written to the placeholder. A host file outside the +// workspace's folder, which Open File on Host opens (remote_host_files.go), is only read: a save +// or a create of one is refused (S25), and any other path is refused outright. // // A read asks the host what the path is first (remote.stat), because the host server opens a path // before it checks what it is, and a named pipe would block it. Like a local file, a link, a @@ -64,8 +63,11 @@ var ( errRemoteTimedOut = errors.New("the host did not answer in time") // errRemoteFileFailed: the host could not read or write the file for another reason. errRemoteFileFailed = errors.New("the host could not read or write the file") - // errRemoteOutsideFolder is the cause of a refused path outside the workspace's folder. + // errRemoteOutsideFolder is the cause of a refused path that names no host path. errRemoteOutsideFolder = errors.New("the path is outside the remote workspace's folder") + // errRemoteReadOnly: the file is on the host outside the workspace's folder, which the editor + // does not write (S25). + errRemoteReadOnly = errors.New("the host file is outside the remote workspace's folder and opens read-only") // errRemoteSaveTooLarge: the file is larger than the host takes in one save // (remoteDocumentWriteLimit), which is less than a local file saves. errRemoteSaveTooLarge = errors.New("the file is larger than the host takes in one save") @@ -146,7 +148,7 @@ func (a *App) remoteDocuments(p *project) *remoteDocuments { // read returns the bytes of the host file of local, a path below the workspace's placeholder. // A file larger than limit, or than Core reads, is errTooLarge. func (r *remoteDocuments) read(ctx context.Context, local string, limit int64) ([]byte, error) { - host, session, err := r.target(local) + host, session, _, err := r.target(local) if err != nil { return nil, err } @@ -161,7 +163,7 @@ func (r *remoteDocuments) save(ctx context.Context, local string, data, expected if len(data) > remoteDocumentWriteLimit { return &remoteFileError{reason: errRemoteSaveTooLarge} } - host, session, err := r.target(local) + host, session, err := r.writable(local) if err != nil { return err } @@ -184,23 +186,34 @@ func (r *remoteDocuments) create(ctx context.Context, local string, data []byte) if len(data) > remoteDocumentWriteLimit { return &remoteFileError{reason: errRemoteSaveTooLarge} } - host, session, err := r.target(local) + host, session, err := r.writable(local) if err != nil { return err } return r.write(ctx, session, host, data, nil) } -// target is the host path of local and the session to reach it over. -func (r *remoteDocuments) target(local string) (host, session string, err error) { - host, ok := remoteHostPathBelow(r.binding.LocalRoot(), r.binding.RemoteRoot(), local) +// target is the host path of local and the session to reach it over; outside says the path is +// outside the workspace's folder. +func (r *remoteDocuments) target(local string) (host, session string, outside bool, err error) { + root := r.binding.LocalRoot() + host, ok := remoteplaceholder.HostPath(root, r.binding.RemoteRoot(), local) if !ok { - return "", "", &remoteFileError{reason: errRemoteFileFailed, cause: errRemoteOutsideFolder} + return "", "", false, &remoteFileError{reason: errRemoteFileFailed, cause: errRemoteOutsideFolder} } if session = r.binding.SessionID(); session == "" { - return "", "", &remoteFileError{reason: errRemoteDisconnected} + return "", "", false, &remoteFileError{reason: errRemoteDisconnected} } - return host, session, nil + return host, session, remoteplaceholder.Outside(root, local), nil +} + +// writable is target for a write, which only a path in the workspace's folder takes. +func (r *remoteDocuments) writable(local string) (host, session string, err error) { + host, session, outside, err := r.target(local) + if err == nil && outside { + return "", "", &remoteFileError{reason: errRemoteReadOnly} + } + return host, session, err } // readHost reads the host file host over session and returns the version its bytes were read at. @@ -300,19 +313,6 @@ func remoteFailureCode(err *core.Error) string { return details.RemoteCode } -// remoteHostPathBelow is the host path of full in the host folder remoteRoot, which localRoot -// stands for; the root itself is the host folder. ok is false for a path outside localRoot. -func remoteHostPathBelow(localRoot, remoteRoot, full string) (string, bool) { - rel, err := filepath.Rel(localRoot, full) - if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) { - return "", false - } - if rel == "." { - return remoteRoot, true - } - return path.Join(remoteRoot, filepath.ToSlash(rel)), true -} - // remoteDocumentReason is the words for err when a host file could not be read or written for a // reason only a remote workspace has, or that the system would name in a local one. ok is false // for the editor's own reasons, which read the same for both. @@ -333,6 +333,8 @@ func (a *App) remoteDocumentReason(err error) (string, bool) { return i18n.Shared(lang, "desktop.remote.document.permissionDenied"), true case errors.Is(remoteErr.reason, errTooLarge): return a.text.Editor.TooLarge, true + case errors.Is(remoteErr.reason, errRemoteReadOnly): + return i18n.Shared(lang, "desktop.remote.document.readOnly"), true case errors.Is(remoteErr.reason, errRemoteSaveTooLarge): limit := strconv.Itoa(remoteDocumentWriteLimit>>20) + " MiB" return i18n.SharedFormat(lang, "desktop.remote.document.tooLargeToSave", map[string]string{"limit": limit}), true diff --git a/desktop/internal/workbench/remote_host_files.go b/desktop/internal/workbench/remote_host_files.go new file mode 100644 index 000000000..d7b7cc37a --- /dev/null +++ b/desktop/internal/workbench/remote_host_files.go @@ -0,0 +1,266 @@ +package workbench + +import ( + "context" + "path" + "strings" + + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteplaceholder" + "github.com/vivaui/viva/ui" +) + +// Open File on Host, in the menu of a remote workspace's connection, opens a file of the host by +// its path, as Zed's path prompt does in a remote project (#2231, R0, §7.3). The field takes an +// absolute host path or one under ~, the account's home directory. Below it are the entries of +// the folder the text names up to its last "/" whose names start with what follows, ignoring +// case, folders first; hidden entries show once that rest starts with ".". Choosing a folder +// enters it and choosing a file opens it. Enter with no entry shown opens the path as typed, and +// the editor says why when it cannot. +// +// A file in the workspace's folder opens as every file of the project does. A file outside it +// opens read-only (S25): the user opened and trusted the folder, not the rest of the host, so +// the editor never writes there. Its document lives below the placeholder Core maps host paths +// outside the workspace to (remoteplaceholder.HostSuffix); the host watch covers only the +// folder, so a change to such a file is found when the connection opens again and before its +// tab closes. Host paths, names and what the user typed are never logged. + +// remoteHostFilesQueryID names the path field, so the popup can give it the keyboard. +var remoteHostFilesQueryID = tree.ID(shellPage, "remote-host-files-query") + +// remoteHostEntry is an entry of the folder the popup lists. +type remoteHostEntry struct { + name string + folder bool +} + +// remoteHostFiles is the popup's state (remoteProject.hostFiles). +type remoteHostFiles struct { + open, focus bool + query ui.Field + list ui.ListState + // head is the text up to its last "/" that dir was listed for over session, dir the host + // folder it names ("" when the text names none), and entries its folders, then its other + // entries. A new session lists the folder again. + head string + session string + dir string + entries []remoteHostEntry + skipped uint32 + loading bool + // listing counts the listings, so that only the latest applies. + listing uint64 + // readErr is why dir could not be listed, or that the text names no host folder. + readErr string + // rowsFor is the text rows were chosen for; rows are the indexes of the entries shown, and + // selected the row Enter chooses. + rowsFor string + rows []int + selected int + scrolledTo int +} + +// openRemoteHostFiles shows the popup over p's window with the home directory typed, or the +// host's root when the host did not report one. +func (a *App) openRemoteHostFiles(p *project, surface actionSurface) { + r := p.remote + if r == nil || r.closed { + return + } + a.performed("remote.workspace.openHostFile", surface) + f := &r.hostFiles + start := "/" + if path.IsAbs(r.home) { + start = "~/" + } + f.open, f.focus = true, true + // The first paint lists the folder the text names. + f.head = "\x00" + f.query.SetText(start) +} + +// closeRemoteHostFiles hides the popup; a listing still running is dropped. +func (p *project) closeRemoteHostFiles() { + if p.remote == nil { + return + } + f := &p.remote.hostFiles + f.open, f.focus, f.loading = false, false, false + f.listing++ + f.entries, f.rows, f.head, f.session, f.dir, f.rowsFor, f.readErr, f.skipped = nil, nil, "", "", "", "", "", 0 + f.list = ui.ListState{} + f.query.SetText("") +} + +// splitRemoteHostQuery cuts text at its last "/": head names the folder and prefix starts the +// names shown. ok is false for text without a "/". +func splitRemoteHostQuery(text string) (head, prefix string, ok bool) { + at := strings.LastIndexByte(text, '/') + if at < 0 { + return "", "", false + } + return text[:at+1], text[at+1:], true +} + +// syncRemoteHostFiles lists the folder the text names when it changed, and chooses the rows for +// the text. It runs on each paint of the popup. +func (a *App) syncRemoteHostFiles(p *project) { + r := p.remote + f := &r.hostFiles + text := f.query.Text() + head, _, ok := splitRemoteHostQuery(strings.TrimLeft(text, " ")) + if !ok { + head = "" + } + if session := r.binding.SessionID(); head != f.head || session != f.session { + f.head, f.session = head, session + f.entries, f.skipped, f.readErr, f.dir, f.loading, f.rowsFor = nil, 0, "", "", false, "\x00" + f.listing++ + dir, valid := "", false + if head != "" { + dir, valid = remoteFolderPath(head, r.home) + } + if !valid { + f.readErr = i18n.Shared(a.language(), "desktop.remote.hostFile.pathHint") + } else { + a.listRemoteHostFolder(p, dir) + } + } + if f.rowsFor != text { + f.rowsFor = text + _, prefix, _ := splitRemoteHostQuery(text) + f.rows = remoteHostRows(f.entries, prefix) + f.selected, f.scrolledTo = 0, -1 + } +} + +// listRemoteHostFolder lists dir, an absolute clean host path, over the workspace's session. +func (a *App) listRemoteHostFolder(p *project, dir string) { + r := p.remote + f := &r.hostFiles + f.dir = dir + session := f.session + if session == "" { + f.readErr = i18n.Shared(a.language(), "desktop.remote.document.disconnected") + return + } + f.loading = true + listing, kernel, lost := f.listing, a.kernel, a.remoteSessionLost(p) + a.background(p, remoteReadDirTimeout, func(ctx context.Context) func(*App) { + directory, err := kernel.RemoteReadDir(ctx, session, dir) + return func(a *App) { + if r.closed || !f.open || f.listing != listing { + // log-exempt: 用户取消:弹窗已关闭或路径已改,不再应用列出结果。 + return + } + f.loading, f.rowsFor = false, "\x00" + if err != nil { + a.operationFailed("remote_read_dir", remoteLogError(err)) + if remoteConnectionClosed(err) { + lost(session) + f.readErr = i18n.Shared(a.language(), "desktop.remote.document.disconnected") + return + } + f.readErr = remoteReadDirFailureText(a.language(), err) + return + } + f.entries = nil + for _, name := range remoteEntryNames(directory, true) { + f.entries = append(f.entries, remoteHostEntry{name: name, folder: true}) + } + for _, name := range remoteEntryNames(directory, false) { + f.entries = append(f.entries, remoteHostEntry{name: name}) + } + f.skipped = directory.SkippedNonUTF8 + } + }) +} + +// remoteHostRows are the indexes of the entries whose names start with prefix, ignoring case. +// A hidden entry shows only when prefix starts with ".". +func remoteHostRows(entries []remoteHostEntry, prefix string) []int { + lower, hidden := strings.ToLower(prefix), strings.HasPrefix(prefix, ".") + rows := make([]int, 0, len(entries)) + for i, entry := range entries { + if strings.HasPrefix(entry.name, ".") && !hidden { + continue + } + if strings.HasPrefix(strings.ToLower(entry.name), lower) { + rows = append(rows, i) + } + } + return rows +} + +// chooseRemoteHostRow enters the folder of row, or opens its file. +func (a *App) chooseRemoteHostRow(p *project, row int, surface actionSurface) { + f := &p.remote.hostFiles + if row < 0 || row >= len(f.rows) { + return + } + entry := f.entries[f.rows[row]] + if entry.folder { + a.performed("remote.workspace.openHostFile.enter", surface) + f.query.SetText(f.head + entry.name + "/") + f.focus = true + return + } + a.openRemoteHostFile(p, path.Join(f.dir, entry.name), surface) +} + +// completeRemoteHostRow puts the name of row after the folder in the field, a folder with its +// "/", so the next paint lists it. +func (p *project) completeRemoteHostRow(row int) { + f := &p.remote.hostFiles + if row < 0 || row >= len(f.rows) { + return + } + entry := f.entries[f.rows[row]] + text := f.head + entry.name + if entry.folder { + text += "/" + } + f.query.SetText(text) +} + +// submitRemoteHostFiles is Enter: the selected row, or the path as typed when no row shows. +func (a *App) submitRemoteHostFiles(p *project, surface actionSurface) { + f := &p.remote.hostFiles + if f.selected >= 0 && f.selected < len(f.rows) { + a.chooseRemoteHostRow(p, f.selected, surface) + return + } + text := strings.TrimLeft(f.query.Text(), " ") + if text == "" || strings.HasSuffix(text, "/") { + return + } + host, ok := remoteFolderPath(text, p.remote.home) + if !ok { + a.operationRejected("remote_open_host_file", "path_not_absolute") + f.readErr = i18n.Shared(a.language(), "desktop.remote.hostFile.pathHint") + return + } + a.openRemoteHostFile(p, host, surface) +} + +// openRemoteHostFile closes the popup and opens host, an absolute clean host path, in the editor: +// read-only when it lies outside the workspace's folder. +func (a *App) openRemoteHostFile(p *project, host string, surface actionSurface) { + r := p.remote + local, ok := remoteplaceholder.LocalPath(p.root, r.binding.RemoteRoot(), host) + if !ok { + // A name holding "\" cannot be named on Windows. + a.operationRejected("remote_open_host_file", "path_unrepresentable") + r.hostFiles.readErr = i18n.Shared(a.language(), "desktop.remote.hostFile.unrepresentable") + return + } + a.performed("remote.workspace.openHostFile.open", surface) + p.closeRemoteHostFiles() + a.openFile(p, local) +} + +// remoteOutsideDocument says whether path names a host file outside p's remote folder: one the +// editor shows read-only. +func (p *project) remoteOutsideDocument(path string) bool { + return p.remote != nil && remoteplaceholder.Outside(p.root, path) +} diff --git a/desktop/internal/workbench/remote_host_files_test.go b/desktop/internal/workbench/remote_host_files_test.go new file mode 100644 index 000000000..8ad386158 --- /dev/null +++ b/desktop/internal/workbench/remote_host_files_test.go @@ -0,0 +1,161 @@ +package workbench + +import ( + "context" + "errors" + "os" + "path/filepath" + "slices" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteplaceholder" + "github.com/vivaui/viva/gfx" +) + +// remoteHostRowNames are the names of the rows Open File on Host shows, a folder's with its "/". +func remoteHostRowNames(f *remoteHostFiles) []string { + names := make([]string, 0, len(f.rows)) + for _, at := range f.rows { + entry := f.entries[at] + name := entry.name + if entry.folder { + name += "/" + } + names = append(names, name) + } + return names +} + +// openHostFilesFromMenu opens Open File on Host from the connection's menu and waits for the +// listing of the folder its field names. +func (h *harness) openHostFilesFromMenu(t *testing.T, p *project) *remoteHostFiles { + t.Helper() + lang := h.app.language() + h.clickFront(i18n.Shared(lang, "desktop.remote.status.label")) + h.settle() + h.clickFront(i18n.Shared(lang, "desktop.remote.status.openHostFile")) + f := &p.remote.hostFiles + h.awaitHostListing(t, f) + return f +} + +// awaitHostListing waits for the popup's listing to finish and paints its rows. +func (h *harness) awaitHostListing(t *testing.T, f *remoteHostFiles) { + t.Helper() + h.redraw() + h.await("the host folder's listing", func() bool { return f.open && !f.loading }) + h.settle() +} + +// Open File on Host lists the folder its field names, filtering by what follows the last "/", +// folders first and hidden entries only once "." is typed. Enter enters a folder and opens a +// file. A file in the workspace's folder opens for editing; one outside it opens read-only, +// stays so, cannot be saved, and the status bar names its host path. A path that is not +// absolute says what to type. Neither the host nor its paths are logged. +func TestRemoteOpenFileOnHost(t *testing.T) { + h, k, _, logger := remoteWorkspaceHarness(t) + lang := h.app.language() + k.put(remoteTestReadme, "# Project\n") + k.put(remoteTestHome+"/notes.txt", "host notes\n") + p := h.openRemoteTestProject(t) + + f := h.openHostFilesFromMenu(t, p) + if got := f.query.Text(); got != "~/" { + t.Fatalf("the field starts with %q, want the home directory", got) + } + if got, want := remoteHostRowNames(f), []string{"linked/", "project/", "notes.txt"}; !slices.Equal(got, want) { + t.Fatalf("rows %q, want the home folder's entries without hidden ones, folders first", got) + } + if !h.shows(i18n.Shared(lang, "desktop.remote.hostFile.readOnlyNote")) { + t.Fatal("the popup does not say files outside the folder open read-only") + } + h.typeText(".") + if got := remoteHostRowNames(f); !slices.Equal(got, []string{".cache/"}) { + t.Fatalf("rows %q for \".\", want the hidden folder", got) + } + f.query.SetText("~/PRO") + h.redraw() + if got := remoteHostRowNames(f); !slices.Equal(got, []string{"project/"}) { + t.Fatalf("rows %q for \"PRO\", want the folder whose name starts with it, ignoring case", got) + } + + h.key(gfx.KeyEnter) + h.awaitHostListing(t, f) + if got := f.query.Text(); got != "~/project/" || f.dir != remoteTestHome+"/project" { + t.Fatalf("field %q: Enter did not enter the folder", got) + } + if got := remoteHostRowNames(f); !slices.Equal(got, []string{"src/", "README.md"}) { + t.Fatalf("rows %q, want the project folder's entries", got) + } + h.typeText("R") + h.key(gfx.KeyTab) + h.redraw() + if got := f.query.Text(); got != "~/project/README.md" { + t.Fatalf("field %q: Tab did not complete the name", got) + } + h.key(gfx.KeyEnter) + inside := filepath.Join(p.root, "README.md") + awaitDocumentState(t, h, func() bool { return p.docs.byPath(inside) != nil }) + h.settle() + if f.open { + t.Fatal("opening a file did not close the popup") + } + if d := p.docs.byPath(inside); d.hostOutside || d.view.ReadOnly() { + t.Fatal("a file of the workspace's folder opened read-only") + } + + f = h.openHostFilesFromMenu(t, p) + h.typeText("notes") + h.key(gfx.KeyEnter) + outside := filepath.Join(p.root+remoteplaceholder.HostSuffix, "home", "dev", "notes.txt") + awaitDocumentState(t, h, func() bool { _, opening := p.docs.opening[outside]; return p.docs.byPath(outside) != nil && !opening }) + h.settle() + d := p.docs.byPath(outside) + if text, _ := d.view.Text(); string(text) != "host notes\n" { + t.Fatalf("opened %q, want the host file's text", text) + } + if !d.hostOutside || !d.view.ReadOnly() { + t.Fatal("a host file outside the workspace's folder opened editable") + } + h.app.toggleReadOnly(d) + if !d.view.ReadOnly() || !h.notified(i18n.Shared(lang, "desktop.remote.hostFile.readOnly")) { + t.Fatal("the file outside the folder could be made editable") + } + if crumbs := h.app.statusFileCrumbs(p, d.path, d.name); crumbs.name != "~/notes.txt" || crumbs.rel != "" { + t.Fatalf("the status bar names the file %+v, want its host path under ~", crumbs) + } + docs := h.app.remoteDocuments(p) + var refused *remoteFileError + if err := docs.save(context.Background(), outside, []byte("changed"), []byte("host notes\n")); !errors.As(err, &refused) || !errors.Is(refused.reason, errRemoteReadOnly) { + t.Fatalf("saving the file outside the folder ended with %v, want it refused", err) + } + if err := docs.create(context.Background(), outside+".new", []byte("new")); !errors.As(err, &refused) || !errors.Is(refused.reason, errRemoteReadOnly) { + t.Fatalf("creating a file outside the folder ended with %v, want it refused", err) + } + if got, _ := k.file(remoteTestHome + "/notes.txt"); got != "host notes\n" { + t.Fatalf("host file %q: the file outside the folder was written", got) + } + if _, ok := k.file(remoteTestHome + "/notes.txt.new"); ok { + t.Fatal("a file outside the folder was created on the host") + } + if _, err := os.Lstat(outside); err == nil { + t.Fatal("the file was read from or written below the placeholder") + } + + f = h.openHostFilesFromMenu(t, p) + f.query.SetText("notes.txt") + h.redraw() + h.key(gfx.KeyEnter) + if !f.open || f.readErr != i18n.Shared(lang, "desktop.remote.hostFile.pathHint") { + t.Fatalf("a path that is not absolute shows %q, want what to type", f.readErr) + } + h.key(gfx.KeyEscape) + h.redraw() + if f.open { + t.Fatal("Escape did not close the popup") + } + if event := loggedAny(t, logger, remoteTestHost, remoteTestHome, "notes", "README"); event != "" { + t.Fatalf("logged the host or its paths: %s", event) + } +} diff --git a/desktop/internal/workbench/remote_host_files_view.go b/desktop/internal/workbench/remote_host_files_view.go new file mode 100644 index 000000000..20049b67c --- /dev/null +++ b/desktop/internal/workbench/remote_host_files_view.go @@ -0,0 +1,148 @@ +package workbench + +import ( + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/ui" +) + +// remoteHostFilesRowHeight is the height of a row of the popup's list. +const remoteHostFilesRowHeight = 28 + +// remoteHostFilesPopup declares Open File on Host (remote_host_files.go) while it is open: it +// hangs from the top of the window as Search Everywhere does, and a press outside closes it. +func (a *App) remoteHostFilesPopup(c ui.C) { + p := a.project + if p == nil || p.remote == nil || !p.remote.hostFiles.open { + return + } + f := &p.remote.hostFiles + a.syncRemoteHostFiles(p) + if f.focus { + c.Canvas().RequestFocus(remoteHostFilesQueryID) + f.focus = false + } + language := a.language() + bounds := c.Bounds() + width := min(float32(640), max(0, bounds.Width-32)) + height := min(float32(420), max(120, bounds.Height-100)) - 16 + var anchor ui.Box + ui.Stack(c.Part("remote-host-files-anchor")).Fill().Children(func() { + anchor = ui.Row(c).Absolute().Left((bounds.Width - width) / 2).Top(84).Width(width).Height(1) + }) + closed := ui.PopoverWith(c.Part("remote-host-files"), anchor, ui.PopoverSpec{ + Width: width, Offset: 1, Align: ui.Start, KeepOpenOnAnchor: true, + }, &f.open, func() { + ui.Column(c).FillWidth().Height(height).Gap(8).Children(func() { + ui.Row(c).FillWidth().Items(ui.Center).Gap(8).Children(func() { + ui.Text(c, i18n.Shared(language, "desktop.remote.hostFile.title")).Bold().Shrink(0) + ui.Text(c, p.remote.remoteLocation()).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis().Shrink(1).MinWidth(0) + }) + ui.TextFieldID(c, remoteHostFilesQueryID, &f.query, i18n.Shared(language, "desktop.remote.hostFile.title"), + i18n.Shared(language, "desktop.remote.hostFile.placeholder")).Icon(icons.FolderOpen) + a.remoteHostFilesList(c, p) + if text := remoteSkippedText(language, f.skipped); text != "" { + ui.Text(c, text).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis() + } + ui.Paragraph(c, i18n.Shared(language, "desktop.remote.hostFile.readOnlyNote"), 2).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) + }) + }) + if closed { + p.closeRemoteHostFiles() + } +} + +// remoteHostFilesList declares the entries shown, or why there are none. +func (a *App) remoteHostFilesList(c ui.C, p *project) { + f := &p.remote.hostFiles + language := a.language() + if f.loading || f.readErr != "" || len(f.rows) == 0 { + text := i18n.Shared(language, "desktop.remote.hostFile.empty") + color := a.colors.Subtle + switch { + case f.loading: + text = i18n.Shared(language, "native.loading") + case f.readErr != "": + text, color = f.readErr, a.theme.Danger + } + ui.Column(c.Part("remote-host-files-empty")).FillWidth().Grow(1).MinHeight(0).Pad(12).Children(func() { + ui.Paragraph(c, text, 3).FontSize(a.theme.Metrics.FontSizeS).Color(color) + }) + return + } + f.list.Label = func(row int) string { + if row < 0 || row >= len(f.rows) { + return "" + } + return f.entries[f.rows[row]].name + } + // The list learns its row count when it is declared, so a selection made before is applied + // on the next paint; only a selection that moved scrolls the list. + if f.selected != f.list.Selected() { + f.list.Select(f.selected) + } + if f.selected != f.scrolledTo { + f.scrolledTo = f.selected + f.list.ScrollIntoView(f.selected) + } + chosen := -1 + ui.List(c.Part("remote-host-files-rows"), &f.list, len(f.rows), func(row ui.ListRow) { + rc := row.C + entry := f.entries[f.rows[row.Index]] + icon := icons.File + if entry.folder { + icon = icons.Folder + } + row.Element.FillWidth().Height(remoteHostFilesRowHeight).PadX(10).Gap(8).Items(ui.Center).Hover(ui.Look{}.Background(a.colors.Hover)).Children(func() { + ui.Icon(rc, icon).Size(15, 15).Shrink(0).Color(a.colors.Subtle) + name := entry.name + if entry.folder { + name += "/" + } + ui.Text(rc, name).Ellipsis().Grow(1).Shrink(1).MinWidth(0) + }) + if row.Element.Clicked() { + chosen = row.Index + } + }).Scrollbars().Label(i18n.Shared(language, "desktop.remote.hostFile.title")).FillWidth().Grow(1).MinHeight(0) + if chosen >= 0 { + f.selected = chosen + c.After(func() { a.chooseRemoteHostRow(p, chosen, surfaceButton) }) + return + } + if f.list.Changed() { + f.selected = max(f.list.Selected(), 0) + } +} + +// remoteHostFilesKey moves the selection with the arrows, chooses with Enter and completes the +// selected name with Tab while the keyboard is in the popup's field. A plain key typed in a text +// field is the field's, so the popup cannot declare these as shortcuts. +func (a *App) remoteHostFilesKey(p *project, event gfx.KeyEvent) gfx.EventResult { + if event.Release || event.Target != remoteHostFilesQueryID || event.Modifiers != 0 { + return gfx.EventResult{} + } + if input := a.root.TextInput(app.TextInputContext{ID: remoteHostFilesQueryID}); input != nil && input.Editor != nil { + if _, composing := input.Editor.Composition(); composing { + return gfx.EventResult{} + } + } + f := &p.remote.hostFiles + switch event.Key { + case gfx.KeyUp: + f.selected = max(0, f.selected-1) + case gfx.KeyDown: + f.selected = min(max(0, len(f.rows)-1), f.selected+1) + case gfx.KeyTab: + p.completeRemoteHostRow(f.selected) + case gfx.KeyEnter: + a.submitRemoteHostFiles(p, surfaceShortcut) + case gfx.KeyEscape: + p.closeRemoteHostFiles() + default: + return gfx.EventResult{} + } + return gfx.EventResult{Handled: true, Repaint: true} +} diff --git a/desktop/internal/workbench/remote_status_view.go b/desktop/internal/workbench/remote_status_view.go index 0782c7884..3d6eb0a26 100644 --- a/desktop/internal/workbench/remote_status_view.go +++ b/desktop/internal/workbench/remote_status_view.go @@ -81,8 +81,8 @@ func (a *App) remoteStatus(c ui.C) { } // remoteStatusMenu declares the open menu of the connection above anchor: the host folder, why -// connecting again failed, Reconnect while there is no session, Disconnect, which closes the -// workspace, and the Remote Development window. +// connecting again failed, Reconnect while there is no session, Open File on Host while there +// is one, Disconnect, which closes the workspace, and the Remote Development window. func (a *App) remoteStatusMenu(c ui.C, p *project, anchor ui.Box) { r := p.remote if !r.menuOpen { @@ -104,6 +104,9 @@ func (a *App) remoteStatusMenu(c ui.C, p *project, anchor ui.Box) { c.After(func() { a.reconnectRemoteByUser(surfaceMenu) }) } } + if menu.Item(i18n.Shared(language, "desktop.remote.status.openHostFile")).Icon(icons.FolderOpen).Disabled(r.session == "").Clicked() { + c.After(func() { a.openRemoteHostFiles(p, surfaceMenu) }) + } if menu.Item(i18n.Shared(language, "desktop.remote.status.disconnect")).Icon(icons.X).Clicked() { c.After(func() { a.performed("remote.workspace.disconnect", surfaceMenu) diff --git a/desktop/internal/workbench/remote_workspace.go b/desktop/internal/workbench/remote_workspace.go index f0fcbded4..2bbc17d8b 100644 --- a/desktop/internal/workbench/remote_workspace.go +++ b/desktop/internal/workbench/remote_workspace.go @@ -118,6 +118,8 @@ type remoteProject struct { watchNotified bool // ports is the Ports tool window's state (remote_ports.go). ports remotePorts + // hostFiles is Open File on Host's state (remote_host_files.go). + hostFiles remoteHostFiles // closed is set once the project closes; nothing of the workspace runs afterwards. closed bool } @@ -508,6 +510,7 @@ func (a *App) closeRemoteWorkspace(p *project) { r.closed = true r.stopRemoteTimer() r.ports.reset() + p.closeRemoteHostFiles() a.stopRemoteWatch(p) if r.reconnecting != nil { r.reconnecting.cancel() diff --git a/desktop/internal/workbench/remote_workspace_visual_test.go b/desktop/internal/workbench/remote_workspace_visual_test.go index 801cae795..3b4b82c7e 100644 --- a/desktop/internal/workbench/remote_workspace_visual_test.go +++ b/desktop/internal/workbench/remote_workspace_visual_test.go @@ -164,6 +164,19 @@ func TestVisualRemoteWorkspace(t *testing.T) { shot("everywhere") h.app.closeEverywhere(p) + // Open File on Host lists the host's home folder, and a file outside the workspace's + // folder opens read-only, the status bar naming its host path. + kernel.put(remoteTestHome+"/notes.txt", "Notes kept outside the project.\n") + h.app.openRemoteHostFiles(p, surfaceMenu) + h.awaitHostListing(t, &p.remote.hostFiles) + shot("host-file") + p.remote.hostFiles.query.SetText("~/notes.txt") + h.redraw() + h.app.submitRemoteHostFiles(p, surfaceShortcut) + outside := filepath.Join(p.root+remoteplaceholder.HostSuffix, "home", "dev", "notes.txt") + awaitDocumentState(t, h, func() bool { _, opening := p.docs.opening[outside]; return p.docs.byPath(outside) != nil && !opening }) + shot("host-file-readonly") + // Trusting the folder starts Git on the host; a repository that starts above the folder // leaves the Commit tool window empty and says why. kernel.set(func(k *remoteHostKernel) { k.git.repository = "above" }) diff --git a/desktop/internal/workbench/root.go b/desktop/internal/workbench/root.go index 5eee9e04f..37e186569 100644 --- a/desktop/internal/workbench/root.go +++ b/desktop/internal/workbench/root.go @@ -310,6 +310,7 @@ func (a *App) overlays(c ui.C) { a.remoteView(c) if a.project != nil { a.everywherePopup(c) + a.remoteHostFilesPopup(c) a.navigationPopup(c) a.semanticPopups(c) } diff --git a/desktop/internal/workbench/search_everywhere_view.go b/desktop/internal/workbench/search_everywhere_view.go index 3a18fb4aa..51a785604 100644 --- a/desktop/internal/workbench/search_everywhere_view.go +++ b/desktop/internal/workbench/search_everywhere_view.go @@ -495,7 +495,8 @@ func (a *App) searchResultMenu(c ui.C, target ui.Box, p *project, result core.Wo a.openSearchResult(p, result) }) } - if menu.Item(revealLabel(language)).Clicked() { + // The placeholder path of a remote workspace's file is nothing the file manager can show. + if p.remote == nil && menu.Item(revealLabel(language)).Clicked() { c.After(func() { a.performed(surface+".reveal", surfaceContextMenu) a.revealPath(full) diff --git a/desktop/internal/workbench/status_items.go b/desktop/internal/workbench/status_items.go index 6ead604cb..14edc290e 100644 --- a/desktop/internal/workbench/status_items.go +++ b/desktop/internal/workbench/status_items.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/1lck/Lithe-IDEA/desktop/internal/editorview" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" ) // This file holds what the status bar's editor items do when they are clicked: switch the @@ -53,10 +54,16 @@ func (a *App) toggleLineEnding(d *document) { } // toggleReadOnly locks or unlocks the document against changes. Virtual documents are read-only -// by their nature and keep that. +// by their nature and keep that, and so does a host file outside a remote workspace's folder, +// which the editor never writes (S25). func (a *App) toggleReadOnly(d *document) { if d == nil || d.virtual { return } + if d.hostOutside { + a.operationRejected("toggle_read_only", "remote_outside_folder") + a.notifyInfo(i18n.Shared(a.language(), "desktop.remote.hostFile.readOnly")) + return + } d.view.SetReadOnly(!d.view.ReadOnly()) } diff --git a/desktop/internal/workbench/status_path.go b/desktop/internal/workbench/status_path.go index 941117185..f4843312f 100644 --- a/desktop/internal/workbench/status_path.go +++ b/desktop/internal/workbench/status_path.go @@ -35,10 +35,12 @@ type statusPath struct { // only when the focus moves. focus gfx.ID // root and file are the last absolute path made relative to the project. rel is what it - // gave, and inside says whether the file lies in the project. A paint that names the same - // file reuses them instead of allocating the relative path again. - root, file, rel string - inside bool + // gave, and inside says whether the file lies in the project. host is the host path, under + // ~ when it is below the home directory, of a remote workspace's file outside its folder, + // and "" for any other file. A paint that names the same file reuses them instead of + // allocating the relative path again. + root, file, rel, host string + inside bool // valueOf is the project name and crumbs of the last path the bar drew, and value is the // accessible value made from them. valueOf statusValueKey @@ -109,18 +111,26 @@ func (a *App) statusPathCrumbs(p *project) statusCrumbs { } // statusFileCrumbs names the file at the absolute path file. A file in the project is named by -// its path in the project. A file outside it, such as a scratch file or a document a plugin -// provides, is named by its name alone. name is the name a document shows in its tab; when it is -// empty, the last element of the path is used. +// its path in the project. A host file outside a remote workspace's folder is named by its host +// path, so the user sees which file of the host the read-only tab holds. Any other file outside +// the project, such as a scratch file or a document a plugin provides, is named by its name +// alone. name is the name a document shows in its tab; when it is empty, the last element of +// the path is used. func (a *App) statusFileCrumbs(p *project, file, name string) statusCrumbs { s := &a.statusPath if s.root != p.root || s.file != file { - s.root, s.file = p.root, file + s.root, s.file, s.host = p.root, file, "" s.rel, s.inside = projectRelative(p.root, file) + if !s.inside && p.remoteOutsideDocument(file) { + s.host = remoteHomeRelative(p.remoteHostPath(file), p.remote.home) + } } if s.inside { return statusCrumbs{rel: s.rel} } + if s.host != "" { + return statusCrumbs{name: s.host} + } if name == "" { name = filepath.Base(file) } diff --git a/desktop/internal/workbench/tab_menu.go b/desktop/internal/workbench/tab_menu.go index 97c79f5a8..be78f02dd 100644 --- a/desktop/internal/workbench/tab_menu.go +++ b/desktop/internal/workbench/tab_menu.go @@ -75,14 +75,16 @@ func (a *App) tabMenuItems(c ui.C, group string, t shownTab, tabs []shownTab) fu } menu.Separator() path := d.path - a.copyPathMenu(c, menu, path, true, "editor.tabs") - if menu.Item(revealLabel(language)).Clicked() { + _, inside := projectRelative(p.root, path) + // A file outside the project has no path relative to it, and the placeholder path of a + // remote workspace's file is nothing the file manager can show. + a.copyPathMenu(c, menu, path, inside, "editor.tabs") + if p.remote == nil && menu.Item(revealLabel(language)).Clicked() { c.After(func() { a.performed("editor.tabs.reveal", surfaceContextMenu) a.revealPath(path) }) } - _, inside := projectRelative(p.root, path) if _, ok := a.kernel.(localHistoryKernel); ok && !p.standalone && inside && menu.Item(i18n.Shared(language, "desktop.history.show")).Clicked() { c.After(func() { a.performed("localHistory.show", surfaceContextMenu) diff --git a/docs/assets/remote-workspace/README.md b/docs/assets/remote-workspace/README.md index 5f10abd9c..494140740 100644 --- a/docs/assets/remote-workspace/README.md +++ b/docs/assets/remote-workspace/README.md @@ -1,16 +1,18 @@ # 远程工作区(#2231)无头测试截图 -来自生产 Viva Page 的无头渲染。主机由测试替换的内核模拟:连接直接成功,主目录 `/home/dev` 下有 `linked`、`project`、`.cache` 三个文件夹和一个无法读取的条目,项目树的目录列表、心跳、主机上的 `README.md` 和 `NOTES.md`、终端的输出和搜索索引也由它返回。测试不启动 OpenSSH,也不上传远端服务。截图覆盖深色与浅色主题、中文与英文界面,用于确认: +来自生产 Viva Page 的无头渲染。主机由测试替换的内核模拟:连接直接成功,主目录 `/home/dev` 下有 `linked`、`project`、`.cache` 三个文件夹和一个无法读取的条目,项目树的目录列表、心跳、主机上的 `README.md`、`NOTES.md` 和主目录里的 `notes.txt`、终端的输出和搜索索引也由它返回。测试不启动 OpenSSH,也不上传远端服务。截图覆盖深色与浅色主题、中文与英文界面,用于确认: - 连接后“远程开发”窗口改为主机的文件夹选择:顶部是连接名和 `用户@主机`,路径框可以输入 `~` 或 `/` 开头的路径,无法读取的条目在列表下方说明数量,底部显示将打开的主机路径; - “打开”从未决定过的文件夹时先询问是否信任:显示连接名和主机文件夹,说明安全模式只读取文件夹,底部是“返回”“以安全模式打开”“信任并打开”; - “以安全模式打开”后远程工作区在新标签页打开:项目树列出主机目录,编辑器上方说明工作区处于安全模式、可以浏览、编辑、保存和搜索主机上的文件,信任文件夹后才能用 Git,右侧是“信任项目…”,空白编辑区提示 Search Everywhere 和 Find in Files,状态栏前端显示 `SSH: 连接名 · 往返时间`; -- 点状态栏的连接项弹出菜单:主机位置、“断开并关闭”和“远程开发…”; +- 点状态栏的连接项弹出菜单:主机位置、“打开主机上的文件…”、“断开并关闭”和“远程开发…”; - 在项目树打开 `README.md`:编辑器显示主机上的内容,Markdown 预览照常; - 主机上的文件被别人改过后再保存:保存被拒绝,通知说明文件在外部被修改,编辑器上方出现“保留编辑器版本 / 加载磁盘版本”,主机上的内容不被覆盖; - 打开终端工具窗口:终端在主机的文件夹里运行主机的登录 shell,标签页以连接名命名,没有本机 Shell 选择菜单;截图里的命令输出由测试内核返回; - Find in Files 搜索 `host`:结果来自主机上的 `NOTES.md` 和 `README.md`,带行列号和匹配数; - Search Everywhere 搜索 `notes`:所有页签都可用(不再只有“操作”),列出主机上的文件名 `NOTES.md` 和它里面匹配的一行; +- “打开主机上的文件…”从窗口顶部弹出路径框,默认 `~/`,列出主目录里的文件夹和文件(文件夹在前、隐藏条目不列),无法读取的条目说明数量,底部说明工作区文件夹以外的文件只读; +- 打开工作区文件夹以外的 `~/notes.txt`:编辑器只读(状态栏是锁),没有预览和编辑按钮,状态栏导航路径显示主机路径 `~/notes.txt`; - 信任文件夹后 Git 在主机上运行;文件夹位于从上级目录开始的仓库内时,提交工具窗口不显示变更,说明要打开仓库的顶层文件夹。 截图不代表 macOS/Windows 原生窗口验收,也不代表真实 SSH 主机上的整机验收。 @@ -26,6 +28,8 @@ | 主机上的终端 | [浅色英文](remote-workspace-terminal-light-en-US.png) | [深色中文](remote-workspace-terminal-dark-zh-CN.png) | | 在主机的文件夹里搜索 | [浅色英文](remote-workspace-search-light-en-US.png) | [深色中文](remote-workspace-search-dark-zh-CN.png) | | Search Everywhere 搜索主机 | [浅色英文](remote-workspace-everywhere-light-en-US.png) | [深色中文](remote-workspace-everywhere-dark-zh-CN.png) | +| 按路径打开主机上的文件 | [浅色英文](remote-workspace-host-file-light-en-US.png) | [深色中文](remote-workspace-host-file-dark-zh-CN.png) | +| 工作区以外的文件只读 | [浅色英文](remote-workspace-host-file-readonly-light-en-US.png) | [深色中文](remote-workspace-host-file-readonly-dark-zh-CN.png) | | 仓库从上级目录开始 | [浅色英文](remote-workspace-git-above-light-en-US.png) | [深色中文](remote-workspace-git-above-dark-zh-CN.png) | 复验:从仓库根目录设置绝对路径 `LITHE_VISUAL_OUTPUT_DIR="$(pwd)/docs/assets/remote-workspace"`,在 `desktop/` 下通过 diff --git a/docs/assets/remote-workspace/remote-workspace-host-file-dark-zh-CN.png b/docs/assets/remote-workspace/remote-workspace-host-file-dark-zh-CN.png new file mode 100644 index 000000000..577452574 Binary files /dev/null and b/docs/assets/remote-workspace/remote-workspace-host-file-dark-zh-CN.png differ diff --git a/docs/assets/remote-workspace/remote-workspace-host-file-light-en-US.png b/docs/assets/remote-workspace/remote-workspace-host-file-light-en-US.png new file mode 100644 index 000000000..4307023cd Binary files /dev/null and b/docs/assets/remote-workspace/remote-workspace-host-file-light-en-US.png differ diff --git a/docs/assets/remote-workspace/remote-workspace-host-file-readonly-dark-zh-CN.png b/docs/assets/remote-workspace/remote-workspace-host-file-readonly-dark-zh-CN.png new file mode 100644 index 000000000..276a2bbd4 Binary files /dev/null and b/docs/assets/remote-workspace/remote-workspace-host-file-readonly-dark-zh-CN.png differ diff --git a/docs/assets/remote-workspace/remote-workspace-host-file-readonly-light-en-US.png b/docs/assets/remote-workspace/remote-workspace-host-file-readonly-light-en-US.png new file mode 100644 index 000000000..8d9a083bc Binary files /dev/null and b/docs/assets/remote-workspace/remote-workspace-host-file-readonly-light-en-US.png differ diff --git a/docs/assets/remote-workspace/remote-workspace-menu-dark-zh-CN.png b/docs/assets/remote-workspace/remote-workspace-menu-dark-zh-CN.png index 493dc2923..a76b558f1 100644 Binary files a/docs/assets/remote-workspace/remote-workspace-menu-dark-zh-CN.png and b/docs/assets/remote-workspace/remote-workspace-menu-dark-zh-CN.png differ diff --git a/docs/assets/remote-workspace/remote-workspace-menu-light-en-US.png b/docs/assets/remote-workspace/remote-workspace-menu-light-en-US.png index 90dd6cc87..e9ecfe12a 100644 Binary files a/docs/assets/remote-workspace/remote-workspace-menu-light-en-US.png and b/docs/assets/remote-workspace/remote-workspace-menu-light-en-US.png differ diff --git a/shared/i18n/features/remote-connections.json b/shared/i18n/features/remote-connections.json index ff53092c4..f1b6129e3 100644 --- a/shared/i18n/features/remote-connections.json +++ b/shared/i18n/features/remote-connections.json @@ -953,6 +953,69 @@ "desktop" ] }, + { + "id": "desktop.remote.status.openHostFile", + "description": "Status bar item of a remote workspace: menu item that opens a file of the host by its path", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostFile.title", + "description": "Title and accessible name of the popup that opens a file of a remote workspace's host by its path", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostFile.placeholder", + "description": "Placeholder of the path field of Open File on Host", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostFile.pathHint", + "description": "Open File on Host: the typed text names no host path", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostFile.unrepresentable", + "description": "Open File on Host: the file's path holds a backslash, which Windows cannot name", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostFile.empty", + "description": "Open File on Host: no entry of the folder matches what was typed", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostFile.readOnlyNote", + "description": "Open File on Host: note below the list that files outside the workspace's folder open read-only", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.hostFile.readOnly", + "description": "Notification when the user tries to make a remote host file outside the workspace's folder editable", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.document.readOnly", + "description": "Reason a file of a remote workspace could not be saved, after “Could not save {name}: ”: it is outside the workspace's folder and opens read-only", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.remote.workspace.title", "description": "Window title and task switcher name of a remote workspace; {kind} is how it is reached, SSH or WSL", @@ -2782,6 +2845,15 @@ "desktop.remote.status.disconnected": "{kind}: {name} · Disconnected", "desktop.remote.status.reconnect": "Reconnect", "desktop.remote.status.disconnect": "Disconnect and Close", + "desktop.remote.status.openHostFile": "Open File on Host…", + "desktop.remote.hostFile.title": "Open File on Host", + "desktop.remote.hostFile.placeholder": "A host path, such as ~/notes.txt or /etc/hosts", + "desktop.remote.hostFile.pathHint": "Type a path that starts with / or ~/", + "desktop.remote.hostFile.unrepresentable": "This path has a name with “\\” in it, which cannot be opened on Windows", + "desktop.remote.hostFile.empty": "No matching files or folders", + "desktop.remote.hostFile.readOnlyNote": "Files in the workspace folder open for editing; other files on the host open read-only.", + "desktop.remote.hostFile.readOnly": "Files outside the remote workspace folder open read-only.", + "desktop.remote.document.readOnly": "the file is outside the workspace folder and opens read-only", "desktop.remote.workspace.title": "{folder} [{kind}: {connection}]", "desktop.remote.titleWith": "Remote Development › {crumb}", "desktop.remote.newConnection": "New Connection", @@ -3124,6 +3196,15 @@ "desktop.remote.status.disconnected": "{kind}: {name} · 已断开", "desktop.remote.status.reconnect": "重新连接", "desktop.remote.status.disconnect": "断开并关闭", + "desktop.remote.status.openHostFile": "打开主机上的文件…", + "desktop.remote.hostFile.title": "打开主机上的文件", + "desktop.remote.hostFile.placeholder": "主机上的路径,例如 ~/notes.txt 或 /etc/hosts", + "desktop.remote.hostFile.pathHint": "请输入以 / 或 ~/ 开头的路径", + "desktop.remote.hostFile.unrepresentable": "这个路径里有含“\\”的名称,在 Windows 上无法打开", + "desktop.remote.hostFile.empty": "没有匹配的文件或文件夹", + "desktop.remote.hostFile.readOnlyNote": "工作区文件夹里的文件可以编辑,主机上的其他文件以只读方式打开。", + "desktop.remote.hostFile.readOnly": "远程工作区文件夹以外的文件只能以只读方式打开。", + "desktop.remote.document.readOnly": "该文件在工作区文件夹以外,只能以只读方式打开", "desktop.remote.workspace.title": "{folder} [{kind}: {connection}]", "desktop.remote.titleWith": "远程开发 › {crumb}", "desktop.remote.newConnection": "新建连接", diff --git a/shared/platform-feature-matrix/features/remote-workspace.json b/shared/platform-feature-matrix/features/remote-workspace.json index 7031d3545..60e207a3a 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 发行版)、远程路径工作区、主机文件编辑与监听、按路径打开主机上的文件(工作区外只读)、主机终端、主机搜索与替换、远程信任与主机 Git、端口转发(含主机侧转发规则与反向转发)、远程工作区设置(SSH 程序、断线重连与关闭时的远端进程)、关闭确认与保留远端进程", "macos": { "implementationStatus": "partial", "verificationStatus": "pending", @@ -20,6 +20,9 @@ "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", @@ -56,14 +59,14 @@ "desktop/internal/remoteconn/preferences_test.go", "desktop/internal/settingswindow/remote_workspace_view_test.go", "desktop/internal/settingswindow/remote_workspace_visual_test.go", + "desktop/internal/workbench/remote_port_rules.go", + "desktop/internal/workbench/remote_port_rules_view.go", + "desktop/internal/workbench/remote_port_rules_test.go", "desktop/internal/workbench/remote_close.go", "desktop/internal/workbench/remote_close_test.go", "desktop/internal/workbench/remote_close_visual_test.go", "desktop/internal/remoteconn/kept.go", - "desktop/internal/remoteconn/kept_test.go", - "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/remoteconn/kept_test.go" ] }, "windows": { @@ -80,6 +83,8 @@ "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,14 +107,14 @@ "desktop/internal/workbench/remote_preferences.go", "desktop/internal/settingswindow/remote_preferences_state.go", "desktop/internal/settingswindow/remote_workspace_view.go", - "desktop/internal/workbench/remote_close.go", - "desktop/internal/remoteconn/kept.go", "desktop/internal/workbench/remote_port_rules.go", - "desktop/internal/workbench/remote_port_rules_view.go" + "desktop/internal/workbench/remote_port_rules_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 等查看器、文件夹外的文件、本地历史和插件终端都被拒绝并提示,不回退到本机。打开“终端”工具窗口:经会话的 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 个测试、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 主机上关闭后保留、重连接回和结束保留进程的整机验收,以及保留进程的输出重新接回终端和运行窗口(后续阶段),仍待完成。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": {