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.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
codec: MoveTab and DefaultPalette PDUs (codec 71)
RoversX82c5346d0c3e
diff --git a/codec/src/lib.rs b/codec/src/lib.rsindex 26c07083..61017ee3 100644--- a/codec/src/lib.rs+++ b/codec/src/lib.rs@@ -576,7 +576,7 @@ macro_rules! pdu {/// 67: Web tokens: the credential a browser presents at the server's web/// port is minted, listed and revoked over the mux connection/// (WebTokenMint/List/Revoke), the way TLS credentials are obtained.-pub const CODEC_VERSION: usize = 69;+pub const CODEC_VERSION: usize = 71;// Defines the Pdu enum.// Each struct has an explicit identifying number.@@ -668,6 +668,8 @@ pdu! {GetWebServerStatus: 91,SetWebServer: 92,WebServerStatus: 93,+ DefaultPalette: 94,+ MoveTab: 95,}impl Pdu {@@ -707,7 +709,8 @@ impl Pdu {| Self::SpawnV2(_)| Self::SpawnPaneInStack(_)| Self::ActivatePaneInStack(_)- | Self::MovePaneToStack(_) => true,+ | Self::MovePaneToStack(_)+ | Self::MoveTab(_) => true,_ => false,}}@@ -1139,6 +1142,15 @@ pub struct SetPalette {/// Server-to-client state of the palette override owned by the application/// running in the pane. `None` means that the client must render using its own/// configured palette; `Some` is authoritative until a later reset.+/// Server-to-client push of the palette the server's own configuration+/// resolves to (`color_scheme`/`colors`). Clients that render with their own+/// configuration may ignore it; the browser client uses it as its base+/// palette, under any per-browser override.+#[derive(Deserialize, Serialize, PartialEq, Debug)]+pub struct DefaultPalette {+ pub palette: ColorPalette,+}+#[derive(Deserialize, Serialize, PartialEq, Debug)]pub struct SetApplicationPalette {pub pane_id: PaneId,@@ -1498,6 +1510,15 @@ pub struct Resize {pub size: TerminalSize,}+/// Put a tab at `index` among its window's tabs; the active tab stays+/// active. Answered with `UnitResponse`.+#[derive(Deserialize, Serialize, PartialEq, Debug)]+pub struct MoveTab {+ pub window_id: WindowId,+ pub tab_id: TabId,+ pub index: usize,+}+#[derive(Deserialize, Serialize, PartialEq, Debug)]pub struct SetPaneZoomed {pub containing_tab_id: TabId,@@ -2420,7 +2441,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, 69);+ assert_eq!(CODEC_VERSION, 71);use thinkterm_proto::{AgentEvidence, AgentState, AgentStatus};fn round_trip(pdu: Pdu) {@@ -2644,6 +2665,25 @@ mod test {}}+ #[test]+ fn default_palette_round_trip() {+ let mut palette = ColorPalette::default();+ palette.background = wezterm_term::color::SrgbaTuple(0.1, 0.2, 0.3, 1.0).into();+ let mut encoded = Vec::new();+ Pdu::DefaultPalette(DefaultPalette {+ palette: palette.clone(),+ })+ .encode(&mut encoded, 0x44)+ .unwrap();+ assert_eq!(+ Pdu::decode(encoded.as_slice()).unwrap(),+ DecodedPdu {+ serial: 0x44,+ pdu: Pdu::DefaultPalette(DefaultPalette { palette }),+ }+ );+ }+#[test]fn focused_pane_palette_round_trip() {let mut encoded = Vec::new();diff --git a/wezterm-client/src/client.rs b/wezterm-client/src/client.rsindex 9f2d0fe8..8b83b5f9 100644--- a/wezterm-client/src/client.rs+++ b/wezterm-client/src/client.rs@@ -605,6 +605,11 @@ fn process_unilateral(.detach();return Ok(());}+ // A GUI client renders from its own configuration; the server's+ // resolved palette is only for clients that have none of their own.+ Pdu::DefaultPalette(_) => {+ return Ok(());+ }Pdu::TabResized(_) | Pdu::TabAddedToWindow(_) => {log::trace!("resync due to {:?}", decoded.pdu);promise::spawn::spawn_into_main_thread(async move {@@ -2298,6 +2303,7 @@ impl Client {rpc!(mouse_event, SendMouseEvent, UnitResponse);rpc!(resize, Resize, UnitResponse);rpc!(set_zoomed, SetPaneZoomed, UnitResponse);+ rpc!(move_tab, MoveTab, UnitResponse);rpc!(activate_pane_direction, ActivatePaneDirection, UnitResponse);rpc!(get_pane_render_changes,diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rsindex af43c680..c975cf69 100644--- a/wezterm-gui/src/frontend.rs+++ b/wezterm-gui/src/frontend.rs@@ -312,7 +312,7 @@ impl GuiFrontEnd {MuxNotification::TabResized(_) => {}// Server-side only: a GUI mux owns no ThinkTerm tree. The// remote tree arrives as a pushed PDU, not as a notification.- MuxNotification::ThinkTermTreeChanged => {}+ MuxNotification::ThinkTermTreeChanged | MuxNotification::DefaultPaletteChanged => {}MuxNotification::ThinkTermSessionChanged => {}MuxNotification::FrontendLeaseChanged(_) => {}MuxNotification::FrontendAccessChanged(_) => {}diff --git a/wezterm-mux-server-impl/src/dispatch.rs b/wezterm-mux-server-impl/src/dispatch.rsindex 6b36dca6..c7b753a7 100644--- a/wezterm-mux-server-impl/src/dispatch.rs+++ b/wezterm-mux-server-impl/src/dispatch.rs@@ -702,6 +702,9 @@ fn item_for_notification(n: MuxNotification) -> Option<Item> {MuxNotification::FrontendAccessChanged(state) => write(Pdu::FrontendAccessState(crate::sessionhandler::codec_access_state(state),)),+ MuxNotification::DefaultPaletteChanged => write(Pdu::DefaultPalette(codec::DefaultPalette {+ palette: crate::sessionhandler::configured_default_palette(),+ })),MuxNotification::PaneAdded(_)| MuxNotification::SaveToDownloads { .. }| MuxNotification::WindowRemoved(_)diff --git a/wezterm-mux-server-impl/src/sessionhandler.rs b/wezterm-mux-server-impl/src/sessionhandler.rsindex 5070196c..66478891 100644--- a/wezterm-mux-server-impl/src/sessionhandler.rs+++ b/wezterm-mux-server-impl/src/sessionhandler.rs@@ -24,6 +24,14 @@ 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.+/// The palette the server's `color_scheme`/`colors` resolve to, or the+/// built-in default when the configuration names neither.+pub fn configured_default_palette() -> ColorPalette {+ // `resolved_palette`, as every local pane uses: the named scheme+ // with the `colors` overlay on it, or the overlay alone.+ ColorPalette::from(config::configuration().resolved_palette.clone())+}+fn local_os_release_id() -> &'static Option<String> {static ID: OnceLock<Option<String>> = OnceLock::new();ID.get_or_init(|| {@@ -943,6 +951,7 @@ fn requires_existing_frontend_access(pdu: &Pdu) -> bool {| Pdu::ActivatePaneInStack(_)| Pdu::MovePaneToStack(_)| Pdu::MovePaneToNewTab(_)+ | Pdu::MoveTab(_)| Pdu::AdjustPaneSize(_))}@@ -1044,6 +1053,7 @@ fn web_peer_may_send(pdu: &Pdu) -> bool {| Pdu::RenameWorkspace(_)| Pdu::SetFocusedPane(_)| Pdu::MovePaneToNewTab(_)+ | Pdu::MoveTab(_)| Pdu::ActivatePaneDirection(_)| Pdu::GetPaneDirection(_)| Pdu::AdjustPaneSize(_)@@ -1112,6 +1122,18 @@ impl SessionHandler {/// never going to come, and sat behind "Restoring terminal state"./// Queued behind the registration's acknowledgement on the same/// channel, so it arrives after it.+ /// The palette the server's own configuration resolves to. Browsers use+ /// it as their base palette; a GUI client renders from its own config and+ /// ignores the push.+ fn push_default_palette(&self) {+ let _ = self.to_write_tx.send(DecodedPdu {+ serial: 0,+ pdu: Pdu::DefaultPalette(codec::DefaultPalette {+ palette: configured_default_palette(),+ }),+ });+ }+fn push_frontend_state(&self) {let mux = Mux::get();let mut pdus = vec![Pdu::FrontendAccessState(codec_access_state(@@ -1337,6 +1359,7 @@ impl SessionHandler {}if !is_proxy {self.push_frontend_state();+ self.push_default_palette();}}Pdu::SetFocusedPane(SetFocusedPane {@@ -2042,6 +2065,39 @@ impl SessionHandler {.detach();}+ Pdu::MoveTab(MoveTab { window_id, tab_id, index }) => {+ spawn_into_main_thread(async move {+ catch(+ move || {+ let mux = Mux::get();+ let mut window = mux+ .get_window_mut(window_id)+ .ok_or_else(|| anyhow!("no such window {window_id}"))?;+ let from = window+ .idx_by_id(tab_id)+ .ok_or_else(|| anyhow!("tab {tab_id} is not in window {window_id}"))?;+ let index = index.min(window.len().saturating_sub(1));+ let active = window.get_active().map(|tab| tab.tab_id());+ if from != index {+ let tab = window.remove_by_idx(from);+ window.insert(index, &tab);+ if let Some(active) = active.and_then(|id| window.idx_by_id(id)) {+ window.set_active_without_saving(active);+ }+ }+ drop(window);+ // A reorder is a topology change to the mirrors:+ // `TabAddedToWindow` is what reaches them and+ // has them list the window again.+ mux.notify(mux::MuxNotification::TabAddedToWindow { tab_id, window_id });+ Ok(Pdu::UnitResponse(UnitResponse {}))+ },+ send_response,+ )+ })+ .detach();+ }+Pdu::MovePaneToNewTab(request) => {let client_id = self.client_id.clone();spawn_into_main_thread(async move {@@ -2491,6 +2547,7 @@ impl SessionHandler {| Pdu::GetAgentStatusesResponse { .. }| Pdu::ListPanesResponse { .. }| Pdu::SetApplicationPalette { .. }+ | Pdu::DefaultPalette { .. }| Pdu::SetClipboard { .. }| Pdu::NotifyAlert { .. }| Pdu::SpawnResponse { .. }@@ -2944,7 +3001,11 @@ mod tests {let names: Vec<(u64, &str)> = sent.iter().map(|d| (d.serial, d.pdu.pdu_name())).collect();assert_eq!(names,- vec![(7, "UnitResponse"), (0, "FrontendAccessState")],+ vec![+ (7, "UnitResponse"),+ (0, "FrontendAccessState"),+ (0, "DefaultPalette")+ ],"the acknowledgement first, then the state; no tabs, so no viewports");}