Skip to content

Commit 07ad14e

Browse files
committed
feat(remote): remote workspace preferences: SSH program and reconnect limit (Refs 1lck/Lithe-IDEA#2231)
1 parent 5c163e9 commit 07ad14e

14 files changed

Lines changed: 1016 additions & 17 deletions

File tree

‎rust/contracts/rust-core-api.md‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,8 @@ or removing a command fails until the table changes in the same commit.
828828
| `remote.sshConfigHosts` | List the Host aliases of the user's SSH configuration for an import |
829829
| `remote.mottyHosts` | List the SSH hosts saved in Motty for an import |
830830
| `remote.listWslDistributions` | List the WSL distributions installed on this Windows machine |
831+
| `remote.preferences` | Read the remote workspace settings and what each automatic value resolves to |
832+
| `remote.editPreferences` | Set the SSH program or the reconnect limit, or make one automatic again |
831833
| `git.historyRewritePreview` | Review undo, message edit, squash, or drop with complete messages, eligibility, and an immutable checkout expectation |
832834
| `git.remotes` | Return configured fetch remote names and URLs |
833835
| `git.tags` | Return tag names, tag object IDs, target IDs, dates, and annotations |
@@ -5698,6 +5700,12 @@ Every field becomes an allowlisted SSH option; options that run a local
56985700
command, such as `ProxyCommand`, are only read from the user's own SSH
56995701
configuration.
57005702

5703+
`remote.probe`, `remote.connect`, `remote.effectiveSettings` and
5704+
`remote.sshConfigHosts` also take an optional `preferences`: the text of the
5705+
remote preferences document (see "Remote workspace preferences"), `null` or
5706+
absent when it does not exist. Its SSH program is the OpenSSH client they
5707+
start; a damaged document is `parse_failed` before anything starts.
5708+
57015709
Core runs the system `ssh` with the probe of
57025710
[`remote-workspace-protocol-v1`](remote-workspace-protocol-v1.md)'s bootstrap
57035711
and relays every OpenSSH question through the same AskPass transport as Git.
@@ -5917,6 +5925,62 @@ its redacted message for display; it is never logged. Cancellation and the
59175925
bound are `cancelled` and `timed_out`. Nothing is saved: the window lists
59185926
the distributions each time it opens.
59195927

5928+
#### Remote workspace preferences
5929+
5930+
The settings page "Tools › Remote Workspace" edits two values that apply to
5931+
every connection. Native clients keep them in one machine-local document,
5932+
read it, and publish the `document` an edit returns atomically, as for the
5933+
saved connections; Core validates the document, applies every edit and
5934+
tells what each automatic value resolves to.
5935+
5936+
`remote.preferences` accepts `{ document: string|null, homeDirectory? }`
5937+
and returns `{ preferences, ssh, reconnect, storage, sshConfig? }`:
5938+
5939+
- `preferences` is `{ sshProgram, reconnectLimitSeconds }`, the stored
5940+
values; `null` is automatic.
5941+
- `ssh` is `{ source, path, status }`, the OpenSSH client every connection
5942+
starts. `source` is `setting` for a stored program and `automatic`
5943+
otherwise, which is the first executable `ssh` (`ssh.exe` on Windows) in an
5944+
absolute directory of Core's `PATH`. `path` is that program, or `null` when
5945+
automatic finds none; then the system looks `ssh` up when it starts.
5946+
`status` is `found`, `missing` or `notExecutable`; a stored program that
5947+
disappeared is reported, not refused, so the page can show it.
5948+
- `reconnect` is `{ source, limitSeconds, delaysMilliseconds }`: how long a
5949+
workspace whose connection dropped keeps reconnecting (automatic: 60
5950+
seconds) and the pauses before each attempt. Pauses start at one second,
5951+
double up to 30 seconds and add up to the limit; the last one is shortened
5952+
to fit. A limit of 0 never reconnects, so the list is empty. Clients wait
5953+
these pauses and decide nothing else about the schedule.
5954+
- `storage` is `{ relativePath: "remote/preferences.json", maximumBytes:
5955+
16384 }`.
5956+
- `sshConfig` is `{ path, exists }` for `.ssh/config` below `homeDirectory`,
5957+
returned only with one, for the page to show and open. A relative home is
5958+
`invalid_request` with `{ field: "homeDirectory", reason: "relative" }`.
5959+
5960+
`remote.editPreferences` accepts `{ document }` with exactly one of:
5961+
5962+
- `sshProgram: { path: string|null }` stores the trimmed absolute path of an
5963+
existing executable file, or makes the program automatic with `null`.
5964+
- `reconnectLimit: { seconds: number|null }` stores 0 to 3600 seconds, or
5965+
makes the limit automatic with `null`.
5966+
5967+
The result is `{ changed, document: string|null }`; an unchanged edit
5968+
returns a `null` document and must not create a source. Neither or both
5969+
fields is `invalid_request` with `{ field: "operation", reason: "invalid"
5970+
}`; a refused value is `invalid_request` with `{ field, reason }`, where
5971+
`field` is `sshProgram` or `reconnectLimitSeconds` and `reason` is
5972+
`invalid` (empty, surrounding spaces or control characters), `tooLong`
5973+
(over 4096 bytes), `relative`, `missing`, `notExecutable` or `outOfRange`.
5974+
5975+
A document of more than 16 KiB, that cannot be decoded, has unknown fields
5976+
or another version than 1, or holds a value an edit would refuse other than
5977+
a missing or not executable program is `parse_failed` with the same
5978+
`details`. The document omits automatic values.
5979+
5980+
Native clients keep the document below their platform user-preference
5981+
directory, never on a host, in a workspace or in an installed package. This
5982+
user-settings resource does not affect code signatures or update deltas.
5983+
59205984
#### Remote connections that stay open
59215985

59225986
`remote.connect` takes `{ connection, servers: [{ target, path, sha256 }],

‎rust/crates/core/src/protocol/command.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,11 @@ pub enum RemoteCommand {
10401040
/// Lists the WSL distributions installed on this Windows machine
10411041
/// (`remote.listWslDistributions`).
10421042
ListWslDistributions,
1043+
/// Reads the remote workspace preferences and what each automatic value
1044+
/// resolves to (`remote.preferences`).
1045+
Preferences,
1046+
/// Changes one remote workspace preference (`remote.editPreferences`).
1047+
EditPreferences,
10431048
}
10441049

10451050
#[derive(Debug, Clone)]
@@ -1620,6 +1625,8 @@ impl CoreCommand {
16201625
"remote.listWslDistributions" => {
16211626
Some(Self::Remote(RemoteCommand::ListWslDistributions))
16221627
}
1628+
"remote.preferences" => Some(Self::Remote(RemoteCommand::Preferences)),
1629+
"remote.editPreferences" => Some(Self::Remote(RemoteCommand::EditPreferences)),
16231630
"git.historyRewritePreview" => Some(Self::Git(GitCommand::HistoryRewritePreview)),
16241631
"git.remotes" => Some(Self::Git(GitCommand::Remotes)),
16251632
"git.tags" => Some(Self::Git(GitCommand::Tags)),

‎rust/crates/core/src/runtime/dispatcher/remote.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,18 @@ pub(super) fn dispatch(command: RemoteCommand, id: Option<String>, payload: Valu
269269
"Invalid Motty hosts request",
270270
lithe_workspace::motty::hosts,
271271
),
272+
RemoteCommand::Preferences => answer(
273+
id,
274+
payload,
275+
"Invalid remote preferences request",
276+
lithe_workspace::preferences::read,
277+
),
278+
RemoteCommand::EditPreferences => answer(
279+
id,
280+
payload,
281+
"Invalid remote preferences request",
282+
lithe_workspace::preferences::edit,
283+
),
272284
RemoteCommand::Disconnect => {
273285
match serde_json::from_value::<lithe_workspace::sessions::DisconnectRequest>(payload) {
274286
Ok(request) => CoreResponse::success(

‎rust/crates/core/src/tests/remote_sessions.rs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,36 @@ fn connection_window_helpers_answer_through_the_dispatcher() {
13251325
let details: Value = serde_json::from_str(both["error"]["details"].as_str().unwrap()).unwrap();
13261326
assert_eq!(details, json!({"field": "wsl", "reason": "invalid"}));
13271327

1328+
// The settings page reads automatic values and stores an edit; a damaged
1329+
// document stops the SSH commands before OpenSSH starts.
1330+
let preferences = call("remote.preferences", json!({"document": null}));
1331+
assert_eq!(
1332+
preferences["data"]["reconnect"]["delaysMilliseconds"],
1333+
json!([1000, 2000, 4000, 8000, 16000, 29000]),
1334+
"{preferences}"
1335+
);
1336+
let edited = call(
1337+
"remote.editPreferences",
1338+
json!({"document": null, "reconnectLimit": {"seconds": 3}}),
1339+
);
1340+
assert_eq!(edited["data"]["changed"], true, "{edited}");
1341+
let stored = call(
1342+
"remote.preferences",
1343+
json!({"document": edited["data"]["document"]}),
1344+
);
1345+
assert_eq!(
1346+
stored["data"]["reconnect"],
1347+
json!({"source": "setting", "limitSeconds": 3, "delaysMilliseconds": [1000, 2000]}),
1348+
"{stored}"
1349+
);
1350+
let damaged = call(
1351+
"remote.effectiveSettings",
1352+
json!({"connection": {"host": "devbox"}, "preferences": "{\"version\":9}"}),
1353+
);
1354+
assert_eq!(damaged["error"]["code"], "parse_failed", "{damaged}");
1355+
13281356
for (command, payload) in [
1357+
("remote.editPreferences", json!({"document": null})),
13291358
(
13301359
"remote.connect",
13311360
json!({"wsl": {"distribution": "Ubuntu", "program": "C:\\x.exe"},

‎rust/crates/remote/src/client/mod.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
//! database, read only, for an import.
3030
//! - [`prompt`] tells what an OpenSSH question asks for, so the window can
3131
//! show a host key, password, passphrase or code form.
32+
//! - [`preferences`] keeps the settings page's machine-local values: the
33+
//! OpenSSH client to start and how long a lost session is reconnected.
3234
//!
3335
//! The transport layer deliberately knows nothing about files or processes.
3436
//! Supporting a new kind of remote means adding a hop, not new capabilities.
@@ -47,6 +49,7 @@ pub mod forward_set;
4749
pub mod launch;
4850
#[cfg(feature = "motty")]
4951
pub mod motty;
52+
pub mod preferences;
5053
pub mod prompt;
5154
pub mod session;
5255
pub mod ssh_config;

0 commit comments

Comments
 (0)