Repository navigation
feat(remote): remember a remote workspace's ports and restore its forwards (Refs 1lck/Lithe-IDEA#2231) - #163
Merged
Merged
Conversation
…wards (Refs 1lck/Lithe-IDEA#2231) Add remote.portRecords, remote.editPortRecords and remote.restoreForwards. The ports page keeps added ports (a URL keeps its scheme and path, never its query or fragment), labels, chosen local ports, the local forwards left running with their S28 confirmation, and host/reverse rules, keyed like workspace trust by the connection target and the host real path. Rules never record allInterfaces and never start on their own. Trust and port records now share sessions::workspace_key.
Keep remote.restoreForwards and the remote programs commands in the list of commands that are not hot.
xiaoyumuxi
marked this pull request as ready for review
November 22, 2026 01:16
This was referenced Nov 22, 2026
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
1lck/Lithe-IDEA#2231(远程开发完整设计)§8 端口页 #46:远程工作区关闭或断线后,端口页还记得用户手动设置的内容,下次连到同一个工作区时显示回来,并把用户没停的本地转发重新开起来。本 PR 是 Core 部分;桌面端(端口页读写记录、重连后恢复)等桌面 Draft #2290 合入后另开 PR。
类型
remote.portRecords、remote.editPortRecords、remote.restoreForwards三个命令;不新增错误码,不新增日志事件改动说明
记录规则(新文件
crates/remote/src/client/port_records.rs与port_records/tests.rs)Target:各跳 + 主机账号)和工作区在主机上的真实路径分开记,和工作区信任的键完全一样,换主机、账号、容器或文件夹都看不到。PortRecord)记:端口所在地址host(主机自己的回环地址不写,localhost、127.0.0.1、::1、0.0.0.0、::都算这一行;其余是规范形式的 IP 或小写主机名)、port、用户添加时输入的地址added、label、用户选的本机端口localPort、用户开着没停的本地转发目标forwardTarget、confirmedTarget。added { host, scheme?, path? }要和remote.parseForwardAddress读回的结果完全一致,并且属于同一行;路径去掉?查询和#片段,因为里面可能带访问令牌(例如 Jupyter 的?token=),完整地址只留在页面内存里。forwardTarget必须指向这一行自己的地址。confirmedTarget是 S28 里用户对“目标不在主机回环地址”的确认:只有带forwardTarget且目标不是回环时才保留,停掉转发就一起忘掉。Rule)是在主机上监听的转发,host(主机侧,targetHost+targetPort)或reverse(反向,localPort),都可带listenPort和label;只差标签的两条算同一条。没有allInterfaces字段(S27):监听全部网卡每次启动都要问,永远不记;文档里出现这个字段按未知字段拒绝。命令(新文件
crates/workspace/src/port_records.rs,接线在command.rs、dispatcher/remote.rs、request_trace.rs)remote.portRecords { document, sessionId, workspace }→{ records: { ports, rules }, workspace: 真实路径, storage: { relativePath: "remote/ports.json", maximumBytes: 262144 } }。remote.editPortRecords { document, sessionId, workspace, port | removePort | rule | removeRule }→{ changed, document: string|null, records }。一次只做一个改动,一个都没有或多于一个按invalid_request、details.field为change拒绝;这个检查在连接主机之前。没有变化时document为null,客户端不能因此创建文件。最近改过的工作区排在最前面。remote.restoreForwards { document, sessionId, workspace }→{ forwards: [{ host?, port, forward, created } | { host?, port, error }] }:按行的顺序,把带forwardTarget的每一行像remote.startForward一样重新启动,本机端口用localPort(没有就用port),allowNonLoopbackTarget用记下来的confirmedTarget。一个失败(例如没确认过的非回环目标返回forward_target_not_confirmed)不影响其他行;已经在跑的返回created: false;会话已经结束时整条命令返回connection_closed。规则从不这样启动。parse_failed(details.field),请求不对是invalid_request(details.field),工作区不存在是workspace_not_found,会话不存在是connection_closed,主机返回的真实路径不规范是parse_failed。remote.restoreForwards不是高频请求,已加进request_trace的非高频测试列表。和信任共用的键(
workspace/src/sessions.rs、workspace/src/trust.rs、remote/src/client/trust.rs、forward_set.rs、workspace/src/forwards.rs)trust.rs里的resolve改成sessions::workspace_key,信任和端口记录都用它取(Target, 真实路径)。工作区路径不是绝对路径时的错误信息从信任专用的措辞改为 “Invalid remote workspace path”,错误码和details不变,没有测试或文档依赖原来的文字。Target::validate改为pub(crate),端口记录拒绝的目标和信任一样。forward_set.rs新增canonical_target,端口记录和转发用同一套地址规范化(通配地址变回环、IP 规范形式、主机名小写)。workspace/src/forwards.rs的open、forward_error改为pub(crate),恢复转发时复用。存储与日志
remote/ports.json,和远程设置、已保存的连接放在一起;不放主机上、工作区里或安装包里。客户端按原字节保留、发布前校验、原子写入、保存后重读,和toolchains/remote-trust.json一样。不含任何密钥,查询和片段不落盘;Core 不记录其中的任何地址(S30)。属于用户设置资源,不影响代码签名,也不影响 Sparkle 增量更新。契约文档(
contracts/rust-core-api.md)remote.restoreForwards。验证
cargo fmt -p lithe-remote -p lithe-workspace -p lithe-corecargo clippy -p lithe-remote -p lithe-workspace -p lithe-core --all-targets --all-features -- -D warnings:无警告cargo test -p lithe-remote client:::123 个通过,其中新增port_records单元测试 13 个:不同目标/路径互不可见、行按端口和地址分开、URL 去掉查询和片段、地址必须能读回、确认只在非回环目标上保留、转发目标必须是行自己的地址、空行删除、只差标签的规则算同一条、规则不记全部网卡、最近改的排前面并按大小淘汰最旧的、每个工作区的上限、目标和路径按信任规则检查、拒绝编辑不会写出的文档cargo test -p lithe-workspace:59 个通过cargo test -p lithe-core:890 个通过;新增remote_port_records_key_the_real_path_and_restore_running_forwards,经过分发器验证:storage形状、经符号链接读写按真实路径记、兄弟目录看不到、添加的网址不保存令牌、重复编辑返回null文档、恢复时回环目标的转发启动、未确认的非回环目标返回forward_target_not_confirmed、确认过的启动、规则不启动(连接上只有 2 个转发)、再次恢复全部created: false、删除行和规则、parse_failed、没有改动或两个改动报change、规则带allInterfaces被拒、相对路径、工作区不存在、会话不存在命令表测试(
protocol::command,检查rust-core-api.md命令表和解析器一致):通过合入 Core main
ac80382(327a63d),带入 feat(remote): keep or end host programs when a connection closes (Refs 1lck/Lithe-IDEA#2231) #160(常驻会话、远端程序)和 feat(execution): plan run configurations of a remote workspace on the host (Refs 1lck/Lithe-IDEA#2231) #161(远程运行配置)。冲突只有一处:request_trace.rs测试里“不算热路径”的命令表,remote.restoreForwards和remote.runningPrograms、remote.endPrograms都保留。合并后cargo fmt --check通过,cargo clippy -p lithe-workspace -p lithe-core -p lithe-remote --all-targets --all-features -- -D warnings没有警告,cargo test -p lithe-workspace -p lithe-core -p lithe-remote全部通过(lithe-core892 个)。