Skip to content

feat(remote): remote workspace preferences: SSH program and reconnect limit (Refs 1lck/Lithe-IDEA#2231) - #158

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

xiaoyumuxi merged 1 commit into
mainfrom
feat/2231-remote-preferences

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

关联 Issue

1lck/Lithe-IDEA#2231(远程开发完整设计)§10 R0:设置 › 工具 › 远程工作区页需要的值,由 Core 校验、解析并告诉界面每个“自动”实际取什么值。本 PR 是 Core 部分,桌面端的设置页和接入另开 PR。

类型

  • feat:新增 remote.preferences 和 remote.editPreferences(远程工作区设置:SSH 程序、自动重连最长时间);remote.probe、remote.connect、remote.effectiveSettings、remote.sshConfigHosts 新增可选 preferences,用设置里的 SSH 程序启动 OpenSSH

改动说明

设置文档规则(新文件 crates/remote/src/client/preferences.rs)

  • 文档是 remote/preferences.json,最大 16 KiB,版本 1,拒绝未知字段;只写用户改过的值,“自动”的值不写,所以全自动时文档是 {"version": 1}。
  • sshProgram:绝对路径,去掉首尾空白,不能有控制字符,最长 4096 字节。改设置时要求文件存在且可执行(Unix 看执行位),不满足就按字段拒绝(missing、notExecutable、relative、invalid、tooLong)。已保存的程序后来被删掉不算文档损坏,读取时报告 status: "missing",让设置页显示出来。
  • 自动的 SSH 程序:在 PATH 中只看绝对路径的目录,取第一个可执行的 ssh(Windows 上是 ssh.exe);一个都没有时用 ssh,交给系统去找,和以前一样。
  • reconnectLimitSeconds:0 到 3600 秒,自动是 60 秒。重连间隔从 1 秒开始翻倍,最长 30 秒,最后一次缩短,让总和正好等于上限;默认的 60 秒是 1、2、4、8、16、29 秒,0 表示不自动重连。这套重连节奏原来写在桌面端(6 次、1 秒起翻倍、最长 30 秒),现在由 Core 给出,客户端只按 delaysMilliseconds 等待。

命令(新文件 crates/workspace/src/preferences.rs,接线在 command.rs、dispatcher/remote.rs)

  • remote.preferences { document, homeDirectory? } 返回:
    • preferences:保存的值,null 表示自动;
    • ssh { source, path, status }:实际使用的 SSH 程序及来源(setting / automatic);
    • reconnect { source, limitSeconds, delaysMilliseconds };
    • storage:文档的位置和大小上限;
    • sshConfig { path, exists }:给了 homeDirectory 才返回,供设置页显示和打开 ~/.ssh/config。相对路径的主目录按 { field: "homeDirectory", reason: "relative" } 拒绝。
  • remote.editPreferences { document } 一次只改一个值:sshProgram: { path|null } 或 reconnectLimit: { seconds|null },null 恢复自动。两个都给或都不给,按 { field: "operation", reason: "invalid" } 拒绝。返回 { changed, document|null },没有变化时 document 为 null,客户端不创建文件。
  • 文档解析不了是 parse_failed,编辑被拒是 invalid_request;两者都带 { field, reason } 的 details,和已保存的连接一致。

使用 SSH 程序的四个命令(probe.rs、sessions.rs、ssh_configuration.rs)

  • 请求新增可选的 preferences,就是文档的文本。不传等于全自动,旧客户端不受影响。
  • 启动 OpenSSH 前先解析文档:文档损坏时直接返回 parse_failed,不会启动 OpenSSH。WSL 连接不使用这个字段。
  • 测试用的替身程序仍然优先(ssh_program(stand_in, document)),原来的测试不需要改。

契约文档(contracts/rust-core-api.md)

  • 命令表新增两行。新增 “Remote workspace preferences” 一节,写明字段、自动值的解析、重连节奏、拒绝原因和存放位置:只放在平台用户偏好目录,不放在主机、工作区或安装包里,不影响代码签名和增量更新。
  • 在 remote.probe 的连接说明后补充:四个命令都可以带 preferences。

验证

  • cargo fmt --all
  • cargo clippy -p lithe-remote -p lithe-workspace -p lithe-core --all-targets --all-features -- -D warnings:无警告
  • cargo test -p lithe-remote --all-features:全部通过(新增 6 个 preferences 测试:默认值、文档拒绝、程序消失只报告、PATH 查找、编辑往返、重连节奏)
  • cargo test -p lithe-workspace --lib:58 个通过(新增 5 个:读取、损坏文档、发布与无变化、按字段拒绝、替身优先)
  • cargo test -p lithe-core:888 个通过;connection_window_helpers_answer_through_the_dispatcher 补充了经过分发器的读取、编辑,以及文档损坏时 remote.effectiveSettings 在启动 OpenSSH 前返回 parse_failed

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