Repository navigation
feat(desktop): 远程工作区的终端在主机上运行 (#2231) - #2273
Merged
Merged
Conversation
远程工作区的终端工具窗口改为经 remote.runTerminal 在主机上运行主机账户的登录 shell, 工作目录是打开终端的主机文件夹,标签页以连接名命名;输入按 32 KiB 分块经 terminal.write 发送,主机忙时退避重试,尺寸经 terminal.resize 发送;关闭标签取消请求, Core 随即关闭主机终端。连接断开时终端结束并让工作区重连,重连后按回车在新会话上启动。 - core:RemoteRunTerminal、RemoteTerminalWrite、RemoteTerminalResize 与资源标签 - termview:Config.Open 让程序在别处启动,不加本机 shell 参数和提示符集成 - workbench:远程终端、拖入文件粘贴主机路径(POSIX 引号)、隐藏本机 Shell 菜单、 关闭图片粘贴;远程工作区打开时像本地项目一样建好第一个终端 - 修复 #1799 引入的“在终端中运行所选内容”会清空终端列表并在隐藏终端中运行的问题 - i18n、功能矩阵、无头截图同步更新
xiaoyumuxi
marked this pull request as ready for review
November 21, 2026 09:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
#2271 合入后,远程工作区可以打开、编辑和保存主机上的文件,但终端工具窗口仍只显示“远程工作区暂不支持此功能”,因为本机的 shell 看不到主机上的项目。本 PR 让远程工作区的终端经工作区的会话在主机上运行主机账户的登录 shell,工作目录是主机上的项目文件夹;输入、窗口尺寸、退出状态和连接断开都按本地终端的方式处理。
改动 / Changes
Core 客户端(新文件
desktop/internal/core/remote_terminal.go)RemoteRunTerminal:调用 Core 已有的remote.runTerminal(带事件的请求),把terminal.started和terminal.output(base64)事件交给回调,请求结束时返回退出码或信号(RemoteTerminalExit)。取消请求时 Core 向主机发terminal.close。RemoteTerminalWrite/RemoteTerminalResize:经remote.hostRequest发送terminal.write/terminal.resize;主机回BUSY(错误详情里的remoteCode)时RemoteTerminalWrite返回busy=true,由调用方退避重试。RemoteResourceLabel/NewRemoteResourceLabel:主机资源标签按 Core 的上限截断(种类 64、名称 256 个字符)。remoteHostCode读取错误详情里的主机错误码。附单测。termview(
view.go、session.go)Config.Open func(cols, rows int) (Shell, error):让程序在本机之外启动(比如远程工作区的主机);设置了Open时视图不加本机 shell 参数和提示符集成(PromptToken),直接以 plain 方式启动。Shell接口(原shell改为别名),Config.Open返回的实现要满足同样的约定。open_test.go:TestOpenStartsTheProgramElsewhere。远程终端(新文件
desktop/internal/workbench/remote_terminal.go)remoteTerminalHost.start实现Config.Open:经工作区当前会话启动remote.runTerminal,工作目录是打开终端的主机文件夹(不在项目里时用工作区的主机文件夹),环境变量和资源标签(terminal+ 标签名)随请求发送;不带参数,不读本机 Shell 设置。remoteShell实现termview.Shell:Write返回 false,与本机 shell 的积压上限一样由 termview 处理;主机因其他原因拒绝输入或尺寸时丢弃这次输入,每个终端只记一次失败。connection_closed)时终端结束,并让工作区按会话丢失处理(loseRemote,与心跳一致,按退避重连);其他失败只结束该终端。未连接时按回车说明工作区未连接,重连后按回车在新会话上运行。remoteLogError),后台失败走已有的app.background.operation_failed。remoteTerminalTitle)。pasteRemoteTerminalPaths):粘贴主机路径并按 POSIX shell 加引号;工作区文件夹之外的本机文件不粘贴,并提示原因。工作台接线
terminals.go:终端新增host(连接名)和closeHost;远程工作区只拒绝插件终端(它会在本机运行),普通终端走主机;远程终端不使用 Shell 菜单选中的程序和 Terminal 设置的程序;关闭标签和关闭项目时endHost()取消主机请求。shell_view.go:远程工作区里终端工具窗口不再显示“暂不支持”,正常显示终端。editor_view.go:删除终端工具窗口里远程工作区的“暂不支持”分支;远程工作区不显示本机 Shell 选择菜单。terminal_drop.go:远程终端的拖放改走pasteRemoteTerminalPaths。remote_workspace.go:打开远程工作区时像本地项目一样建好第一个终端(openTerminals);文件头注释更新为当前阶段。app.go:Kernel接口新增RemoteRunTerminal、RemoteTerminalWrite、RemoteTerminalResize。顺带修复:“在终端中运行所选内容”(
commands.go)openTerminals(p),它会清空当前终端列表、在隐藏的终端里运行所选内容,工具窗口也不打开。改为openToolWindow(itemTerminal):保留已有终端,在新建并显示的终端里运行。回归测试terminal_commands_test.go:TestRunSelectionRunsInANewShownTerminal。文案(
shared/i18n/features/remote-connections.json,已生成shared.generated.go)desktop.remote.terminal.notConnected、desktop.remote.terminal.tabNumber({name}、{number})、desktop.remote.terminal.dropOutside。测试与截图
remote_terminal_test.go(9 个测试):TestRemoteWorkspaceTerminalRunsOnTheHost:终端经工作区会话在主机文件夹启动,标签名、无 Shell 菜单、输入输出、关闭标签取消请求;日志没有主机和主目录。TestRemoteWorkspaceTerminalEndsWithTheConnection:连接断开时终端结束、工作区重连,重连后按回车在新会话上启动。TestRemoteWorkspaceTerminalShowsWhyItDidNotStart:启动失败显示原因,日志只有命令和错误码。TestRemoteWorkspaceTerminalTakesTheHostPathsOfDroppedFiles:拖放粘贴主机路径与 POSIX 引号,文件夹外的文件被拒。TestRemoteShell*(5 个):尺寸先于输入、32 KiB 分块与顺序、BUSY 退避、输入上限、输出丢弃最旧、退出码与信号、未连接提示。remote_workspace_test.go:拒绝场景里的“终端”改为“插件终端”。remote_workspace_visual_test.go:新增terminal场景(冲突解决后打开终端,清掉保存失败的通知);opened、menu、file、conflict因横幅文案变化重新生成。remote-workspace.json:能力改为“远程连接、远程路径工作区、主机文件编辑与主机终端”,补证据路径、验证说明和说明。不在本 PR 范围内 / Out of scope
remote.runWatch)、Git 与搜索走主机:后续 PR。类型专属:feat
多平台对齐
改动都在 Viva 共用代码里,两端同一份实现;Windows 实机未验证,矩阵 Windows 验证状态保持
pending。范围检查 / Scope checks
功能矩阵 / Feature matrix
shared/platform-feature-matrix/features/remote-workspace.json:两端的实现状态和验证状态、证据路径、owner、验证动作都如实填写;没有运行验证的保持pending./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh;改了平台实现路径的,还运行了./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD.artifacts/下生成的矩阵视图插件归属 / Plugin ownership
develop-lithe第三节“插件归属与宿主零依赖”的自查命令,结果为空shared/i18n/;插件的构建步骤、资源路径和补丁没有写进docs/ci-builds.md、Agent Note 或 SkillUI 验证 / UI evidence
desktop/下运行LITHE_VISUAL_OUTPUT_DIR=<仓库>/docs/assets/remote-workspace ../scripts/desktop/desktop-go.sh test -tags vivahead,lithevisual ./internal/workbench -run '^TestVisualRemoteWorkspace$' -count=1;提交 553b28b;场景 browse / opened / menu / file / conflict / terminal;浅色 en-US 与深色 zh-CN;1200×760terminal是新场景);其余场景只有横幅文案变化,改动前截图见 feat(desktop): 远程工作区的编辑器经会话打开、保存和比对主机上的文件 (#2231) #2271。原生窗口整机验收未做主机上的终端(浅色 en-US / 深色 zh-CN):标签页以连接名命名,没有本机 Shell 菜单;命令输出由测试内核返回。
横幅文案更新后的远程工作区:
统一日志系统 / Structured logging
terminalFailed,错误先经remoteLogError只留命令和错误码),主机拒绝输入或尺寸、输出丢弃走已有的app.background.operation_failed(remote_terminal_input/remote_terminal_resize/remote_terminal_output);没有print、直接写 stderr 或手写事件 IDremoteLogError),测试断言日志里没有主机和主目录界面文案 / i18n
shared/i18n/补齐中英词条,运行node scripts/i18n/generate-i18n.mjs并提交生成结果,没有手改生成文件;Viva 代码通过desktop/internal/i18n/的接口读取shared/i18n/node scripts/i18n/verify-app-language-localization.mjs和node scripts/i18n/generate-i18n.mjs --check,没有放宽脚本或扩大豁免名单逻辑归属 / Logic placement
remote.runTerminal/remote.hostRequest实现(Core 已合入,本 PR 不改 Core);桌面端只做请求转发、缓冲和呈现性能与内存 / Performance and memory
Config.Open在窗口线程外运行设置 / Settings
N/A:没有新增或修改设置项;远程终端只是不读本机的 Terminal Shell 设置。
插件契约 / Plugin contract
N/A:没有改插件契约、能力版本、插件函数协议或宿主方法。
发行包与资源 / Bundle and resources
./scripts/desktop/verify/verify-runtime-bundle-immutability.sh:没有新增资源路径无用代码与重构 / Dead code and refactoring
editor_view.go不再使用的 i18n 引用验证 / Verification
gofmt -l+../scripts/desktop/desktop-go.sh vet ./internal/workbench ./internal/core ./internal/termview(含-tags vivahead,lithevisual)../scripts/desktop/desktop-go.sh test ./internal/workbench ./internal/core ./internal/termview ./internal/i18n -count=1(变基到 d9969f0 之后)../scripts/desktop/desktop-go.sh test ./internal/workbench -run 'Remote|RunSelection' -count=1(34 个测试)TestVisualRemoteWorkspace无头截图(6 个场景 × 2 种外观),逐张查看node scripts/i18n/generate-i18n.mjs --check、node scripts/i18n/verify-app-language-localization.mjs./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh、verify-platform-feature-matrix-change.sh origin/main HEAD./scripts/desktop/verify/verify-runtime-bundle-immutability.sh.agents/skills/write-stable-tests/scripts/verify-test-stability.shtest-stability-macos.sh(workbench / core / termview 中名称含 Remote 或 Terminal 的 99 个测试,另加TestOpenStartsTheProgramElsewhere、TestRunSelectionRunsInANewShownTerminal,单测试计时)TestRunSelectionRunsInANewShownTerminal300 ms;同一轮里名称恰好匹配的既有测试最长 1.64 s,低于 15 s 上限未能执行的检查和原因:
提交前确认 / Final checks
main创建;目标分支:feat、fix、docs 为main,release 以发布流程要求为准.build/、target/、dist/、.artifacts/等产物,没有凭据、个人路径和未脱敏的日志或截图