Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ or removing a command fails until the table changes in the same commit.
| `remote.sshConfigHosts` | List the Host aliases of the user's SSH configuration for an import |
| `remote.mottyHosts` | List the SSH hosts saved in Motty for an import |
| `remote.listWslDistributions` | List the WSL distributions installed on this Windows machine |
| `remote.preferences` | Read the remote workspace settings and what each automatic value resolves to |
| `remote.editPreferences` | Set the SSH program or the reconnect limit, or make one automatic again |
| `git.historyRewritePreview` | Review undo, message edit, squash, or drop with complete messages, eligibility, and an immutable checkout expectation |
| `git.remotes` | Return configured fetch remote names and URLs |
| `git.tags` | Return tag names, tag object IDs, target IDs, dates, and annotations |
Expand Down Expand Up @@ -5698,6 +5700,12 @@ Every field becomes an allowlisted SSH option; options that run a local
command, such as `ProxyCommand`, are only read from the user's own SSH
configuration.

`remote.probe`, `remote.connect`, `remote.effectiveSettings` and
`remote.sshConfigHosts` also take an optional `preferences`: the text of the
remote preferences document (see "Remote workspace preferences"), `null` or
absent when it does not exist. Its SSH program is the OpenSSH client they
start; a damaged document is `parse_failed` before anything starts.

Core runs the system `ssh` with the probe of
[`remote-workspace-protocol-v1`](remote-workspace-protocol-v1.md)'s bootstrap
and relays every OpenSSH question through the same AskPass transport as Git.
Expand Down Expand Up @@ -5917,6 +5925,62 @@ its redacted message for display; it is never logged. Cancellation and the
bound are `cancelled` and `timed_out`. Nothing is saved: the window lists
the distributions each time it opens.

#### Remote workspace preferences

The settings page "Tools › Remote Workspace" edits two values that apply to
every connection. Native clients keep them in one machine-local document,
read it, and publish the `document` an edit returns atomically, as for the
saved connections; Core validates the document, applies every edit and
tells what each automatic value resolves to.

`remote.preferences` accepts `{ document: string|null, homeDirectory? }`
and returns `{ preferences, ssh, reconnect, storage, sshConfig? }`:

- `preferences` is `{ sshProgram, reconnectLimitSeconds }`, the stored
values; `null` is automatic.
- `ssh` is `{ source, path, status }`, the OpenSSH client every connection
starts. `source` is `setting` for a stored program and `automatic`
otherwise, which is the first executable `ssh` (`ssh.exe` on Windows) in an
absolute directory of Core's `PATH`. `path` is that program, or `null` when
automatic finds none; then the system looks `ssh` up when it starts.
`status` is `found`, `missing` or `notExecutable`; a stored program that
disappeared is reported, not refused, so the page can show it.
- `reconnect` is `{ source, limitSeconds, delaysMilliseconds }`: how long a
workspace whose connection dropped keeps reconnecting (automatic: 60
seconds) and the pauses before each attempt. Pauses start at one second,
double up to 30 seconds and add up to the limit; the last one is shortened
to fit. A limit of 0 never reconnects, so the list is empty. Clients wait
these pauses and decide nothing else about the schedule.
- `storage` is `{ relativePath: "remote/preferences.json", maximumBytes:
16384 }`.
- `sshConfig` is `{ path, exists }` for `.ssh/config` below `homeDirectory`,
returned only with one, for the page to show and open. A relative home is
`invalid_request` with `{ field: "homeDirectory", reason: "relative" }`.

`remote.editPreferences` accepts `{ document }` with exactly one of:

- `sshProgram: { path: string|null }` stores the trimmed absolute path of an
existing executable file, or makes the program automatic with `null`.
- `reconnectLimit: { seconds: number|null }` stores 0 to 3600 seconds, or
makes the limit automatic with `null`.

The result is `{ changed, document: string|null }`; an unchanged edit
returns a `null` document and must not create a source. Neither or both
fields is `invalid_request` with `{ field: "operation", reason: "invalid"
}`; a refused value is `invalid_request` with `{ field, reason }`, where
`field` is `sshProgram` or `reconnectLimitSeconds` and `reason` is
`invalid` (empty, surrounding spaces or control characters), `tooLong`
(over 4096 bytes), `relative`, `missing`, `notExecutable` or `outOfRange`.

A document of more than 16 KiB, that cannot be decoded, has unknown fields
or another version than 1, or holds a value an edit would refuse other than
a missing or not executable program is `parse_failed` with the same
`details`. The document omits automatic values.

Native clients keep the document below their platform user-preference
directory, never on a host, in a workspace or in an installed package. This
user-settings resource does not affect code signatures or update deltas.

#### Remote connections that stay open

`remote.connect` takes `{ connection, servers: [{ target, path, sha256 }],
Expand Down
7 changes: 7 additions & 0 deletions rust/crates/core/src/protocol/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,11 @@ pub enum RemoteCommand {
/// Lists the WSL distributions installed on this Windows machine
/// (`remote.listWslDistributions`).
ListWslDistributions,
/// Reads the remote workspace preferences and what each automatic value
/// resolves to (`remote.preferences`).
Preferences,
/// Changes one remote workspace preference (`remote.editPreferences`).
EditPreferences,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -1620,6 +1625,8 @@ impl CoreCommand {
"remote.listWslDistributions" => {
Some(Self::Remote(RemoteCommand::ListWslDistributions))
}
"remote.preferences" => Some(Self::Remote(RemoteCommand::Preferences)),
"remote.editPreferences" => Some(Self::Remote(RemoteCommand::EditPreferences)),
"git.historyRewritePreview" => Some(Self::Git(GitCommand::HistoryRewritePreview)),
"git.remotes" => Some(Self::Git(GitCommand::Remotes)),
"git.tags" => Some(Self::Git(GitCommand::Tags)),
Expand Down
12 changes: 12 additions & 0 deletions rust/crates/core/src/runtime/dispatcher/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ pub(super) fn dispatch(command: RemoteCommand, id: Option<String>, payload: Valu
"Invalid Motty hosts request",
lithe_workspace::motty::hosts,
),
RemoteCommand::Preferences => answer(
id,
payload,
"Invalid remote preferences request",
lithe_workspace::preferences::read,
),
RemoteCommand::EditPreferences => answer(
id,
payload,
"Invalid remote preferences request",
lithe_workspace::preferences::edit,
),
RemoteCommand::Disconnect => {
match serde_json::from_value::<lithe_workspace::sessions::DisconnectRequest>(payload) {
Ok(request) => CoreResponse::success(
Expand Down
29 changes: 29 additions & 0 deletions rust/crates/core/src/tests/remote_sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,36 @@ fn connection_window_helpers_answer_through_the_dispatcher() {
let details: Value = serde_json::from_str(both["error"]["details"].as_str().unwrap()).unwrap();
assert_eq!(details, json!({"field": "wsl", "reason": "invalid"}));

// The settings page reads automatic values and stores an edit; a damaged
// document stops the SSH commands before OpenSSH starts.
let preferences = call("remote.preferences", json!({"document": null}));
assert_eq!(
preferences["data"]["reconnect"]["delaysMilliseconds"],
json!([1000, 2000, 4000, 8000, 16000, 29000]),
"{preferences}"
);
let edited = call(
"remote.editPreferences",
json!({"document": null, "reconnectLimit": {"seconds": 3}}),
);
assert_eq!(edited["data"]["changed"], true, "{edited}");
let stored = call(
"remote.preferences",
json!({"document": edited["data"]["document"]}),
);
assert_eq!(
stored["data"]["reconnect"],
json!({"source": "setting", "limitSeconds": 3, "delaysMilliseconds": [1000, 2000]}),
"{stored}"
);
let damaged = call(
"remote.effectiveSettings",
json!({"connection": {"host": "devbox"}, "preferences": "{\"version\":9}"}),
);
assert_eq!(damaged["error"]["code"], "parse_failed", "{damaged}");

for (command, payload) in [
("remote.editPreferences", json!({"document": null})),
(
"remote.connect",
json!({"wsl": {"distribution": "Ubuntu", "program": "C:\\x.exe"},
Expand Down
3 changes: 3 additions & 0 deletions rust/crates/remote/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
//! database, read only, for an import.
//! - [`prompt`] tells what an OpenSSH question asks for, so the window can
//! show a host key, password, passphrase or code form.
//! - [`preferences`] keeps the settings page's machine-local values: the
//! OpenSSH client to start and how long a lost session is reconnected.
//!
//! The transport layer deliberately knows nothing about files or processes.
//! Supporting a new kind of remote means adding a hop, not new capabilities.
Expand All @@ -47,6 +49,7 @@ pub mod forward_set;
pub mod launch;
#[cfg(feature = "motty")]
pub mod motty;
pub mod preferences;
pub mod prompt;
pub mod session;
pub mod ssh_config;
Expand Down
Loading
Loading