Repository navigation
feat(remote): 保存 SSH 连接,并把连接规则集中到 remote 包(#2231) - #145
Merged
Merged
Conversation
- 新增 lithe_remote::client::connections:SshConnection 的字段、规范化、逐字段检查和转成 SshHop 的规则都在这里;新增 proxyJump;拒绝时给出 { field, reason }。
- 新增已保存连接文档(remote/connections.json,版本 1,最多 128 项、每项最多 10 个最近文件夹),以及 remote.connections / remote.editConnections(save / remove / rememberFolder 三选一)。
- probe 和 connect 改用同一份 SshConnection;端口 0、超时 0 等越界值不再按默认值处理,而是拒绝并指出字段。
This was referenced Nov 21, 2026
xiaoyumuxi
marked this pull request as ready for review
November 21, 2026 03:50
xiaoyumuxi
added a commit
that referenced
this pull request
Nov 21, 2026
七个文件冲突,都是两边各自在同一列表末尾追加条目,按并集保留: - protocol::ErrorCode 与 application-boundary.md:保留 forward_target_not_confirmed、forward_limit_reached,再加 main 的 remote_server_invalid;connection_closed 用本分支补全的说明。 - RemoteCommand、命令名映射、分发器与 rust-core-api.md 方法表:remote.startForward、remote.stopForward、remote.forwards 之后接 remote.connections、remote.editConnections。 - workspace lib.rs:connections 与 forwards 两个模块都保留。 - sessions.rs 的 import:同时引入 ArtifactError 与 ForwardSet。 端口转发经已有连接的服务端协议完成,不另起 ssh 进程,与 #148 的环境变量白名单不交叉。
This was referenced Nov 21, 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(远程开发完整设计),R0 的“连接窗口:已保存的连接”(设计 §3.1,S08–S10、S12、S15)。桌面端连接窗口会在后续 PR 中接入这两个命令。
类型
remote.connections/remote.editConnections),连接字段规则集中到crates/remote改动说明
连接规则移到
lithe_remote::client::connections(crates/remote/src/client/connections.rs)SshConnection、Authentication和“连接转成SshHop”原来写在crates/workspace/src/probe.rs,现在移到 remote 包,remote.probe和remote.connect都用这一份。workspace 的probe::ssh_hop只剩一行:规范化、检查,再把拒绝转成invalid_request。新增
proxyJump字段:none,或逗号分隔的[user@]host[:port];不写时沿用用户 SSH 配置里的跳板机。校验复用 transport 里已有的ProxyJump白名单(新增pub(crate) fn is_jumps和is_ssh_user,原逻辑不变)。规范化:文本字段去掉首尾空白,空的可选字段删除;只有
privateKey认证保留identityFile。逐字段检查,拒绝时返回
{ field, reason },reason是required、invalid、tooLong、duplicate、full、unknown之一,客户端可以把每条拒绝翻译后显示在对应字段旁边:host._-:%,不能以-开头(不含@,用户名有自己的字段;不含/,ssh://URI 不能夹带用户或端口)portuser._-,以字母、数字或_开头identityFileprivateKey时必填,最多 1024 字节,无控制字符;含空格时加引号交给 OpenSSHproxyJumpconnectTimeoutSecondskeepAliveSeconds每个字段只会变成白名单内的 SSH 选项;
ProxyCommand这类会运行本地命令的选项只能写在用户自己的~/.ssh/config里。生成的 hop 还会交给TransportChain的白名单再检查一次,二者不一致时拒绝而不是启动 ssh。已保存连接文档与两个命令
remote/connections.json放在平台用户偏好目录下(和toolchains/remote-trust.json一样由客户端读取、原子写入),格式为{ version: 1, connections: [{ id, name, connection, recentFolders? }] }。remote.connections { document }返回{ connections, storage: { relativePath, maximumBytes } }。remote.editConnections { document, save | remove | rememberFolder },三者必须恰好一个,否则invalid_request(field: "operation"):save { id?, name, connection }:不带id时新增,id 由 Core 生成(128 位随机数的十六进制,最多重抽 16 次);带id时原位替换,未知 id 为unknown。名称去掉首尾空白后 1–128 个字符、无控制字符,与其他连接名称不区分大小写地比较也不能重复。替换后host、port、user或proxyJump变了,就清空最近文件夹,因为最近文件夹属于目标,不属于名称。remove { id }:不存在的 id 不改动。rememberFolder { id, path }:path必须是规范化的主机绝对路径(复用 trust 的host_path),移到最前、去重,只留 10 个。{ changed, document: string|null, connections, id? };没有变化时document为null,客户端不得创建文件。请求里不能带密码:password是未知字段,会被拒绝。parse_failed;请求错误或修改被拒,返回invalid_request。两者的details都是 JSON{ field, reason }。行为变化
remote.probe和remote.connect原来把port: 0、connectTimeoutSeconds: 0当作“用默认值”,现在按越界拒绝并指出字段;新增的上限(超时 600 秒、保活 3600 秒、各字段 1024 字节)同样适用。桌面端目前还没有调用这两个命令,不受影响。不在
crates/remote里的改动包结构要求远程代码都在 remote 包;以下几处是命令入口和文档,只做接线:
crates/workspace/src/connections.rs:两个命令的请求结构(deny_unknown_fields)和错误码转换,和trust.rs的做法一致;新 id 复用sessions::nonce。crates/workspace/src/probe.rs、sessions.rs:删掉搬走的类型,改为引用 remote 包。crates/core/src/protocol/command.rs、runtime/dispatcher/remote.rs:注册两个命令。rust/contracts/rust-core-api.md:命令表、remote.probe的字段表和新的“Saved connections”一节。本 PR 不改插件契约、能力版本或插件函数协议,不需要更新协议更新记录,也不需要运行
sdk-e2e.mjs。测试
crates/remote/src/client/connections/tests.rs12 项:私钥只提供所选密钥、其他认证方式的 SSH 选项、跳板机和带空格的私钥路径、规范化、逐字段拒绝(含ProxyCommand注入和以-开头的主机)、文档往返、名称只差大小写和未知 id、最近文件夹跟随目标、删除保持顺序、id 重抽、128 项上限(满表时仍可编辑已有项)、存储文档按同样规则检查。crates/workspace/src/connections/tests.rs6 项:空文档返回存储位置、保存返回要写入的文档和 32 位十六进制 id、无变化时document为null、必须恰好一个操作、损坏的文档是parse_failed而错误请求是invalid_request、请求里带密码或未知字段被拒。crates/workspace/src/probe/tests.rs:搬到 remote 包的 hop 测试删除,改为一项验证ssh_hop把拒绝转成带{ field, reason }的invalid_request。lithe-core的命令文档表测试覆盖两个新命令。验证
scripts/rust-core/verify-rust-core-comments.shcargo fmt --all --checkcargo clippy -p lithe-remote -p lithe-workspace -p lithe-core --all-targets -- -D warningscargo test -p lithe-remote -p lithe-workspace -p lithe-core未能执行的检查: Windows 本地没有运行;改动不含
cfg平台分支,依靠 CI。后续
remote.probe,认证提问沿用 Git 的窗口)、入口;文档由桌面端写到用户偏好目录。