Skip to content

feat(remote): 连接窗口的地址解析、搜索、导入、ssh -G 生效值和连接阶段(#2231) - #154

Merged
xiaoyumuxi merged 1 commit into
mainfrom
feat/2231-remote-import-effective-settings
Nov 21, 2026
Merged

xiaoyumuxi merged 1 commit into
mainfrom
feat/2231-remote-import-effective-settings

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

关联 Issue

1lck/Lithe-IDEA#2231(远程开发完整设计):远程开发窗口重设计的剩余功能,参照 Motty 的“新建主机”。这个 PR 补上窗口需要的 Core 能力:快速连接地址解析、列表搜索、从 Motty 和 ~/.ssh/config 导入、ssh -G 实际生效值及来源、最近连接时间、连接步骤事件,以及按类型区分的认证询问(主机密钥、密码、密钥口令、验证码)。桌面端只负责显示。

类型

  • feat:新增 remote.parseAddress、remote.effectiveSettings、remote.sshConfigHosts、remote.mottyHosts;remote.connections 新增 query;remote.editConnections 新增 import 和 markConnected;remote.connect 新增 remoteStage 事件;authentication 事件新增 kind、keyType、fingerprint

改动说明

连接文档与列表(crates/remote/src/client/connections.rs、crates/workspace/src/connections.rs)

  • parse_address:解析 [ssh://][user@]host[:port],IPv6 写成 [地址]。拆出的字段按 remote.probe 的规则检查,不合规时返回 { field: host|user|port, reason }。不解析域名,也不发起连接。
  • remote.connections 新增可选的 query(最多 256 个字符):
    • 按空白拆成多个词;名称、分组和 [user@]host[:port] 包含所有词(不分大小写)的条目才留在 sections 里;
    • 没有条目剩下的分区会被去掉;
    • connections 仍返回完整列表。
  • 条目新增 lastConnectedAt(Unix 秒)。换主机、端口、用户或跳板时,和最近文件夹一起清除。文档仍为 version 1,未设置时不写这个字段。
  • remote.editConnections 新增两种操作,每次请求仍然只能带一种操作:
    • markConnected: { id }:记录当前时间;id 不存在时返回 reason: "unknown"。
    • import: { entries, fills }:
      • 按顺序添加条目,每条按 save 的规则检查;
      • 重名(不分大小写)时自动加 (2)… (256) 后缀,所以导入不会覆盖已有条目;
      • fills 只给缺颜色或缺分组的已有条目补上;
      • 任何一条被拒,整个列表保持原样;
      • 结果带 ids。

ssh -G 实际生效值(crates/remote/src/client/ssh_config.rs、crates/workspace/src/ssh_configuration.rs)

  • remote.effectiveSettings 对同一个连接运行两次 ssh -G,一次读配置文件,一次带 -F none 不读,比较两次的结果。
  • 逐项给出 hostName、port、user、identityFiles、proxyJump、connectTimeoutSeconds 和 keepAliveSeconds,每项都是 { value, source },source 是 connection、sshConfig 或 default。
  • 命令行 -o 的优先级高于配置文件,而连接超时和保活间隔总是由命令行传入,所以这两项的来源只会是 connection 或 default。
  • remote.sshConfigHosts 读取 ~/.ssh/config 和它 Include 的文件:
    • 读取限制:只读家目录内的文件,最多 64 个文件、每个 1 MiB、嵌套 16 层;
    • 每个 Host 名只列一次(不分大小写),最多 256 个;
    • 每项给出状态:importable、exists(带已有条目的 id 和名称)、pattern、invalid 或 unreadable;
    • 每项还给出解析结果和 usedAsJumpBy,即哪些主机把它当作跳板。
  • 安全措施:
    • 配置里的 Match exec 仍然会执行命令,所以 ssh -G 使用和 remote.probe 相同的受限环境与允许列表选项;
    • 单次运行上限 10 秒,整次导入上限 30 秒,可以取消;
    • 失败诊断经过脱敏。

Motty 导入(crates/remote/src/client/motty.rs、crates/workspace/src/motty.rs)

  • 以只读方式打开 <平台用户配置目录>/motty/config.db,只支持格式 28;Motty 正在写入时最多等 500 ms。
  • 从不打开 vault,所以密码和密钥都不会被读取。
  • 每个主机给出:
    • 状态:importable、partial、exists 或 unsupported;
    • 导入后保存的连接;
    • 逐项设置的去向:lithe 字段写明会导入到哪里,没导入的写原因:secret、noSetting、protocol、command、kerberos、extraKey 或 invalid。
  • 颜色映射到最接近的连接颜色,分组按 Motty 的顺序。
  • 数据库缺失、无法读取、过大(超过 64 MiB 或 4096 条记录)或格式不支持时,作为结果返回 unavailable,导入页据此说明原因。

连接步骤与询问分类(crates/remote/src/client/launch.rs、prompt.rs,以及 crates/workspace/src/sessions.rs、probe.rs)

  • remote.connect 依次发出 remoteStage 事件:
    • authenticated:远端 shell 输出第一行;
    • platformChecked:shell 报告了平台;
    • uploading { sentBytes, totalBytes }:开始发送和之后每 256 KiB 各一次;
    • installed { uploaded }:服务端已就位。
  • 阶段由辅助线程产生,经 mpsc 交回请求线程发出,因为 execution_events::emit 是线程本地的。
  • 认证询问按 OpenSSH 的英文措辞分为 hostKey、password、passphrase、code 和 other。主机密钥询问还带 keyType 和 fingerprint,各最多 128 个字符。remote.probe 和 remote.connect 共用同一套分类。

依赖

  • lithe-remote 新增 motty 特性,依赖 rusqlite 0.32(bundled)。
  • 选 bundled 是因为 Windows 没有系统自带的 SQLite 库。
  • 只有桌面端 Core(lithe-workspace)打开这个特性。宿主服务端(server 特性)不带 SQLite:cargo tree -p lithe-remote --no-default-features --features server -e normal | grep rusqlite 没有输出。
  • 桌面端 Go 代码没有链接 SQLite,不会有符号冲突。

范围说明

主要改动在 crates/remote。另外有三处必要的接线:

  • crates/workspace:命令实现,以及把事件交回请求线程的部分;
  • crates/core:protocol/command.rs 中的命令名、runtime/dispatcher/remote.rs 中的分发(新增 answer 辅助函数),以及 tests/remote_sessions.rs 中的调度测试;
  • rust/contracts/rust-core-api.md:命令表、事件表,以及 Remote connections、Saved connections(新增 Connection window helpers 小节)和 Remote connections that stay open 三节。

remote/Cargo.toml 的 test-features 加上了 motty,沿用已有的 CI 机制,没有新增 CI 步骤。

验证

  • cargo test -p lithe-remote --features server,motty:全部通过(单元测试 141 个,集成测试套件全部通过)。新增 motty、ssh_config、prompt、地址解析、搜索、导入、markConnected 的测试,tests/server.rs 断言了连接阶段的顺序。
  • cargo test -p lithe-workspace:47 个通过。用假 ssh 脚本覆盖来源判断、失败诊断脱敏、缺少客户端、Include 顺序、跳板反查和 256 个上限。
  • cargo test -p lithe-core:887 个通过,包括新增的 connection_window_helpers_answer_through_the_dispatcher 和契约命令表检查。
  • cargo clippy -p lithe-remote -p lithe-workspace -p lithe-core --all-targets --all-features -D warnings:通过。lithe-remote --target x86_64-pc-windows-msvc 也通过。带 motty 的 Windows 交叉检查在 macOS 上做不了,因为 bundled SQLite 需要 Windows SDK 头文件;桌面端 Windows Core 在 Windows runner 上用 MinGW 原生编译。
  • cargo fmt --all --check、scripts/rust-core/verify-rust-core-comments.sh:通过。
  • 测试只使用虚构的主机、用户和指纹。

桌面端 Draft PR 会先固定到本分支的 commit,本 PR 合入后再换成 main 上的 commit。

- remote.parseAddress:把快速连接输入的 [ssh://][user@]host[:port](IPv6 写成 [地址])拆成表单字段,按 remote.probe 的规则检查,出错时指出 host/user/port 哪一项。
- remote.connections 新增可选 query:名称、分组和 [user@]host[:port] 都包含每个词(不分大小写)的条目才留在 sections 里。
- remote.editConnections 新增 import(批量添加,重名自动加 " (2)" 后缀,fills 只给缺颜色/分组的已有条目补上)和 markConnected(记录 lastConnectedAt,换目标时与最近文件夹一起清除)。
- remote.effectiveSettings:用 ssh -G 分别带和不带配置文件(-F none)各跑一次,给出主机名、端口、用户、密钥、跳板、连接超时、保活间隔的实际值和来源(connection/sshConfig/default)。
- remote.sshConfigHosts:读取 ~/.ssh/config 及其 Include(只读家目录内,最多 64 个文件、每个 1 MiB、16 层),列出每个 Host 名(最多 256 个),给出状态(importable/exists/pattern/invalid/unreadable)、解析结果和被谁当作跳板。
- remote.mottyHosts:只读打开 Motty 的 config.db(格式 28),不打开 vault;逐项列出每个主机会导入哪些设置、哪些不导入及原因;数据库不存在或格式不支持时作为结果返回。
- remote.connect 新增 remoteStage 事件(authenticated/platformChecked/uploading/installed);认证询问新增 kind(hostKey/password/passphrase/code/other),主机密钥询问带 keyType 和 fingerprint。
- ssh -G 使用与 remote.probe 相同的受限环境、允许列表选项和 10 秒上限(导入整体 30 秒),可取消,诊断输出已脱敏。
- lithe-remote 新增 motty 特性(rusqlite bundled),只有桌面端 Core 打开,宿主服务端不带 SQLite。
- 更新契约 rust-core-api.md 和测试。
@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 21, 2026 07:55
@xiaoyumuxi
xiaoyumuxi merged commit 72ad095 into main Nov 21, 2026
5 of 7 checks passed
xiaoyumuxi added a commit that referenced this pull request Nov 22, 2026
…e-IDEA#2231) (#170)

#154 给 lithe-remote 加了 motty(bundled rusqlite),lithe-workspace 默认
打开它。从那以后,“Lint for Windows” 在 Linux runner 上编译 SQLite 的 C
源码时找不到 MSVC 的 lib.exe,所有 PR 的 Rust Core / Linux 和 gate 都失败。

- 这个步骤加 LIBSQLITE3_SYS_USE_PKG_CONFIG=1:libsqlite3-sys 只复制预生成
  绑定、输出链接指令,不编译 C 源码。clippy 不链接,检查结果不变。
- 步骤停摆期间漏进来的告警:ssh_configuration 测试里只给 Unix 测试用的
  Directory::write、lines、DEFAULTS 加 #[cfg(unix)]。
- CONTRIBUTING 的本地 Windows clippy 命令同样加上这个变量。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant