Repository navigation
feat(desktop): 远程端口窗口记住标签、没停的转发和规则,重连或重新打开后恢复转发 (#2231) - #2297
Merged
Merged
Conversation
xiaoyumuxi
marked this pull request as ready for review
November 22, 2026 03:33
1 task done
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
在这个 PR 之前,远程工作区的“端口”窗口只在工作区开着的时候记得用户的操作,主要有三个问题:
Issue #2231 §8 要求端口窗口像 VS Code 的“端口”视图一样,重连后转发能接着用,标签也不丢。
存储和校验已在 Lithe-IDEA/Lithe-core-rust#163 中完成,提供
remote.portRecords、remote.editPortRecords和remote.restoreForwards三个命令,已包含在当前固定的 Core 修订中。本 PR 在桌面端完成剩下的读写、界面和恢复。改动 / Changes
端口记录的读写(新文件)
desktop/internal/core/remote_port_records.go:Core 客户端新增三个命令和对应的类型,包括记录、行、规则、编辑、存储位置和恢复结果。desktop/internal/remoteconn/ports.go:只负责文件读写。remote/ports.json),再用configfile读出字节交给 Core。ErrConflict。parse_failed、超出大小、编码不对)返回ErrDamaged;ErrUnavailable;desktop/internal/workbench/remote_port_records.go:端口窗口的同步逻辑。内存里保留当前状态:标签、本机端口、没停的转发和规则。
ports.written是 Core 上次报告的记录。recordEdits()比较两者,每个不同的行或规则生成一条编辑,所以只写变化的部分,不会覆盖另一个窗口同时写入的其他行。冲突时重读后重试,最多 3 次。同一时间只跑一次读写(
recordsBusy)。结束时,只有期间又改过(recordsRevision变了)或接上了新会话(recordsAttach)才再同步一次,所以 Core 规范化后的内容不会引起循环写入。每次接上会话(打开工作区、断线重连)时:
remote.restoreForwards。刚打开的工作区把读到的记录并入窗口(只补窗口里还没有的);重连时以窗口的内存状态为准。
转发没能恢复时,那一行标为失败,显示 Core 给出的原因,并忘掉“没停”的状态。窗口顶部显示有几条没恢复。其余转发照常恢复。
文件损坏时,窗口说明无法读取,之后的修改只留在内存里,文件的字节保持原样,从不覆盖。
端口窗口
remote_ports_view.go:remote_ports.go:remote_port_rules.go、remote_port_rules_view.go:规则启动成功后会被记住。没在运行的规则也会列出,状态为“未运行”,行尾有两个按钮:app.go:远程工作区内核接口新增上述三个命令。remote_workspace.go:接上会话时设置recordsAttach并开始同步。安全约束(与 #2231 S27–S30 一致)
文案、矩阵和文档
shared/i18n/features/remote-ports.json:desktop/internal/i18n/shared.generated.go。shared/platform-feature-matrix/features/remote-workspace.json:.agents/notes/implemented/feature/2026-11-22-remote-ports-remembered-records.md:写明存储归属、按差异写入、每次接上会话都恢复、损坏不覆盖、规则不自动启动,以及被否决的备选方案。.agents/notes/proposed/architecture/2026-10-24-remote-development-workspace-host.md:端口一段改为 T1/T2 转发、标签和规则会被记住并恢复。docs/assets/remote-ports/:重新生成全部截图;新增“编辑标签”“标签列”“重新打开后”三个场景,各有浅色英文和深色中文两张;README 同步更新。测试
remote_port_records_test.go:remoteconn/ports_test.go:core/remote_session_test.go:三个新命令对未知会话返回connection_closed。TestRemotePortsStartTheForwardsLeftRunningAgainAfterAReconnect:重连后转发自动恢复。原来的预期是转发全部消失。remote_port_rules_test.go:停止的规则不再从列表里消失,而是被记住;重连后规则不会自动启动。不在本 PR 范围内 / Out of scope
截图 / Screenshots
所有截图都由
TestVisualRemotePorts生成,1200×960,左边浅色英文,右边深色中文。“编辑标签”对话框:
端口和规则的“标签”列:
关闭并重新打开工作区后的端口窗口:
端口列表(新增“标签”列)和规则列表:
类型专属:feat
多平台对齐
platform-specific),理由:范围检查 / Scope checks
功能矩阵 / Feature matrix
shared/platform-feature-matrix/features/remote-workspace.json:pending。./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh,validated 221 platform capabilities。.artifacts/下生成的矩阵视图。插件归属 / Plugin ownership
develop-lithe第三节的自查命令,结果为空。UI 验证 / UI evidence
TestVisualRemotePorts,共 10 个场景,1200×960,覆盖浅色英文和深色中文。label、labels、remembered。docs/assets/remote-ports/。统一日志系统 / Structured logging
performed记录remote.ports.label、remote.ports.ruleStart、remote.ports.ruleForget;remote_port_records、remote_port_restore和 Core 错误码;remote_port_label/invalid_label。// log-exempt:。loggedAny检查。界面文案 / i18n
shared/i18n/features/remote-ports.json中补齐中英文,并已重新生成desktop/internal/i18n/shared.generated.go。node scripts/i18n/verify-app-language-localization.mjs和node scripts/i18n/generate-i18n.mjs --check,都通过。逻辑归属 / Logic placement
性能与内存 / Performance and memory
设置 / Settings
N/A:没有改设置页。“编辑标签”只编辑这一行的标签,不是设置项。
插件契约 / Plugin contract
N/A:没有改插件契约、能力版本、插件函数协议或宿主方法。
发行包与资源 / Bundle and resources
新增的运行时文件是本机偏好目录下的
remote/ports.json:已运行
zsh scripts/desktop/verify/verify-runtime-bundle-immutability.sh,通过。[N/A] 没有新的下载、解压或生成资源,也不是编译缓存,不需要写进
docs/ci-builds.md。无用代码与重构 / Dead code and refactoring
验证 / Verification
scripts/desktop/desktop-go.sh vet ./internal/workbench/ ./internal/remoteconn/ ./internal/core/scripts/desktop/desktop-go.sh test -count=1 ./internal/workbench/ ./internal/remoteconn/ ./internal/core/2e4be2c)后:scripts/desktop/desktop-go.sh test -count=1 -run 'TestRemote|TestPortRecords|TestDamagedPortRecords' ./internal/workbench/ ./internal/remoteconn/ ./internal/core/LITHE_VISUAL_OUTPUT_DIR=… scripts/desktop/desktop-go.sh test -count=1 -tags vivahead,lithevisual -run TestVisualRemotePorts ./internal/workbench/gofmt -l desktop/internal/./scripts/agent-notes/verify-agent-notes.shbash scripts/platform-feature-matrix/verify-platform-feature-matrix.shnode scripts/i18n/generate-i18n.mjs --check、node scripts/i18n/verify-app-language-localization.mjszsh scripts/desktop/verify/verify-runtime-bundle-immutability.shdevelop-lithe第三节)未能执行的检查和原因:
提交前确认 / Final checks
main(5b72074c9)创建,提交前已 merge 最新main;目标分支mainbuild.example、db.internal等占位主机