Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

codec,mux: report the server's distro in the version handshake (codec 63)

RoversXb062bdb7bb85
diff --git a/codec/src/lib.rs b/codec/src/lib.rs
index 0b42342d..893f3d90 100644
--- a/codec/src/lib.rs
+++ b/codec/src/lib.rs
@@ -487,7 +487,7 @@ macro_rules! pdu {
/// cold-start delivery and for `thinkterm cli agent list`.
/// 62: Projects carry an archived state in the shared ThinkTerm tree
/// (TtProject.archived_at, TreeOp::SetProjectArchived).
-pub const CODEC_VERSION: usize = 62;
+pub const CODEC_VERSION: usize = 63;
// Defines the Pdu enum.
// Each struct has an explicit identifying number.
@@ -568,6 +568,8 @@ pdu! {
AgentStatusChanged: 80,
GetAgentStatuses: 81,
GetAgentStatusesResponse: 82,
+ GetServerOsRelease: 83,
+ GetServerOsReleaseResponse: 84,
}
impl Pdu {
@@ -715,6 +717,24 @@ pub struct GetCodecVersionResponse {
pub config_file_path: Option<PathBuf>,
}
+/// What the server is running on, asked for separately.
+///
+/// Deliberately its own request rather than another field on
+/// `GetCodecVersionResponse`: varbincode is positional, so any field added to
+/// that struct makes it undecodable by a peer built against a different
+/// version -- and that is the one message whose whole job is to report a
+/// version mismatch in the first place. Its shape has to stay frozen or a
+/// skewed pair gets "failed to fill whole buffer" instead of being told which
+/// versions they are.
+#[derive(Deserialize, Serialize, PartialEq, Debug)]
+pub struct GetServerOsRelease {}
+
+#[derive(Deserialize, Serialize, PartialEq, Debug)]
+pub struct GetServerOsReleaseResponse {
+ /// The `ID=` from the server's own `/etc/os-release`, when it has one.
+ pub os_release_id: Option<String>,
+}
+
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct Ping {}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
@@ -2108,7 +2128,7 @@ mod test {
// The exact assertion is the tripwire: whoever bumps the codec must
// come here, confirm the round-trips still cover the new version,
// and advance it deliberately.
- assert_eq!(CODEC_VERSION, 62);
+ assert_eq!(CODEC_VERSION, 63);
use thinkterm_proto::{AgentEvidence, AgentState, AgentStatus};
fn round_trip(pdu: Pdu) {
diff --git a/mux/src/ssh.rs b/mux/src/ssh.rs
index 603f7abb..9ada5654 100644
--- a/mux/src/ssh.rs
+++ b/mux/src/ssh.rs
@@ -284,7 +284,7 @@ pub fn ssh_domain_to_ssh_config(ssh_dom: &SshDomain) -> anyhow::Result<ConfigMap
}
/// Parse the `ID=` value out of `/etc/os-release` contents (e.g. "ubuntu").
-fn parse_os_release_id(text: &str) -> Option<String> {
+pub fn parse_os_release_id(text: &str) -> Option<String> {
for line in text.lines() {
if let Some(rest) = line.trim().strip_prefix("ID=") {
let value = rest.trim().trim_matches('"').to_string();
diff --git a/wezterm-client/src/client.rs b/wezterm-client/src/client.rs
index f73de5ae..b307e0dc 100644
--- a/wezterm-client/src/client.rs
+++ b/wezterm-client/src/client.rs
@@ -184,6 +184,8 @@ pub struct Client {
connection_phase: Arc<AtomicU8>,
resume_reconnect_tx: std::sync::mpsc::Sender<()>,
remote_server_id: Arc<RwLock<Option<String>>>,
+ /// The distro id the server reported when we shook hands, if any.
+ remote_os_release: Arc<RwLock<Option<String>>>,
/// Process-unique identity of the currently attached transport. A
/// reconnect gets a fresh value so queued unilateral messages from the
/// superseded reader cannot be mistaken for current server state.
@@ -229,6 +231,11 @@ impl Client {
self.remote_server_id.read().unwrap().clone()
}
+ /// What the server said it is running on, once the handshake completed.
+ pub fn remote_os_release(&self) -> Option<String> {
+ self.remote_os_release.read().unwrap().clone()
+ }
+
pub fn connection_generation(&self) -> u64 {
self.connection_generation.load(Ordering::Acquire)
}
@@ -1623,6 +1630,7 @@ impl Client {
let reader_connection_phase = Arc::clone(&connection_phase);
let (resume_reconnect_tx, resume_reconnect_rx) = channel::<()>();
let remote_server_id = Arc::new(RwLock::new(None));
+ let remote_os_release = Arc::new(RwLock::new(None));
let connection_generation = Arc::new(AtomicU64::new(0));
let reader_connection_generation = Arc::clone(&connection_generation);
let fatal_connection_error = Arc::new(Mutex::new(None));
@@ -1930,6 +1938,7 @@ impl Client {
connection_phase,
resume_reconnect_tx,
remote_server_id,
+ remote_os_release,
connection_generation,
fatal_connection_error,
}
@@ -1997,6 +2006,19 @@ impl Client {
),
}
*self.remote_server_id.write().unwrap() = Some(info.server_id.clone());
+ // Best effort, and its own request: see GetServerOsRelease for
+ // why this cannot ride the version response. A server that
+ // does not answer simply leaves the distro unknown.
+ if let Ok(Pdu::GetServerOsReleaseResponse(os)) = self
+ .send_bootstrap_pdu(Pdu::GetServerOsRelease(GetServerOsRelease {}))
+ .or(async {
+ smol::Timer::after(Duration::from_secs(10)).await;
+ Err(Timeout).context("Timeout")
+ })
+ .await
+ {
+ *self.remote_os_release.write().unwrap() = os.os_release_id;
+ }
self.mark_registration_complete()?;
Ok(info)
}
diff --git a/wezterm-client/src/domain.rs b/wezterm-client/src/domain.rs
index b607ebbe..26c261d4 100644
--- a/wezterm-client/src/domain.rs
+++ b/wezterm-client/src/domain.rs
@@ -1897,6 +1897,13 @@ impl ClientDomain {
}
}
+ /// The distro id the remote mux reported at handshake. `None` until the
+ /// domain is attached, or when the server is not on a machine with an
+ /// `/etc/os-release`.
+ pub fn remote_os_release(&self) -> Option<String> {
+ self.inner()?.client.remote_os_release()
+ }
+
fn inner(&self) -> Option<Arc<ClientInner>> {
self.inner.lock().unwrap().as_ref().map(Arc::clone)
}
diff --git a/wezterm-mux-server-impl/src/sessionhandler.rs b/wezterm-mux-server-impl/src/sessionhandler.rs
index 4f5b26c1..f85a9d75 100644
--- a/wezterm-mux-server-impl/src/sessionhandler.rs
+++ b/wezterm-mux-server-impl/src/sessionhandler.rs
@@ -16,10 +16,23 @@ use mux::{
};
use promise::spawn::spawn_into_main_thread;
use std::collections::HashMap;
-use std::sync::{Arc, Mutex};
+use std::sync::{Arc, Mutex, OnceLock};
use std::time::Instant;
use termwiz::surface::SequenceNo;
use url::Url;
+
+/// This machine's distro id, read once. Clients ask for it in the version
+/// handshake so that a host reached through the mux can show the right logo
+/// without anyone opening a second connection to go and look.
+fn local_os_release_id() -> &'static Option<String> {
+ static ID: OnceLock<Option<String>> = OnceLock::new();
+ ID.get_or_init(|| {
+ std::fs::read_to_string("/etc/os-release")
+ .ok()
+ .as_deref()
+ .and_then(mux::ssh::parse_os_release_id)
+ })
+}
use wezterm_term::color::ColorPalette;
use wezterm_term::terminal::Alert;
use wezterm_term::StableRowIndex;
@@ -1540,6 +1553,14 @@ impl SessionHandler {
}
}
+ Pdu::GetServerOsRelease(_) => {
+ send_response(Ok(Pdu::GetServerOsReleaseResponse(
+ GetServerOsReleaseResponse {
+ os_release_id: local_os_release_id().clone(),
+ },
+ )))
+ }
+
Pdu::GetTlsCreds(_) => {
catch(
move || {
@@ -1660,6 +1681,7 @@ impl SessionHandler {
| Pdu::NotifyAlert { .. }
| Pdu::SpawnResponse { .. }
| Pdu::GetPaneRenderChangesResponse { .. }
+ | Pdu::GetServerOsReleaseResponse { .. }
| Pdu::UnitResponse { .. }
| Pdu::LivenessResponse { .. }
| Pdu::GetPaneDirectionResponse { .. }