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
remote update: hand the running server over instead of asking to stop it
RoversX12418a8f8605
diff --git a/thinkterm-update/src/lib.rs b/thinkterm-update/src/lib.rsindex 9b63afc1..3e0c69a6 100644--- a/thinkterm-update/src/lib.rs+++ b/thinkterm-update/src/lib.rs@@ -309,6 +309,17 @@ pub fn install_command(variant: &str, version: &str) -> String {)}+/// The command that upgrades a running mux server on the host in place:+/// the freshly installed binary takes the running server's panes over and+/// the running server exits, so nothing in its sessions ends. Exits 0 once+/// the new server owns everything, and 1 with the reason on stderr when+/// the running server cannot hand over (a build from before the feature)+/// or the takeover failed and the running server carried on.+pub fn takeover_command() -> String {+ "export PATH=\"$HOME/.local/bin:$PATH\"; thinkterm-mux-server --daemonize --takeover"+ .to_string()+}+/// Run `install.sh` on this machine for the install the manifest describes,/// asking it for release `tag`. The script is fetched fresh and fed to `sh`/// on stdin, exactly as the documented `curl | sh` does, so there is one@@ -465,6 +476,13 @@ mod tests {assert_eq!(without.sha256(), None);}+ #[test]+ fn the_takeover_command_runs_the_installed_server_in_place() {+ let cmd = takeover_command();+ assert!(cmd.starts_with("export PATH=\"$HOME/.local/bin:$PATH\";"), "{cmd}");+ assert!(cmd.ends_with("thinkterm-mux-server --daemonize --takeover"), "{cmd}");+ }+#[test]fn install_command_names_variant_and_version() {let cmd = install_command("server", "0.2.0");diff --git a/wezterm-client/src/remote_update.rs b/wezterm-client/src/remote_update.rsindex 3da60a67..243b0769 100644--- a/wezterm-client/src/remote_update.rs+++ b/wezterm-client/src/remote_update.rs@@ -15,8 +15,10 @@//! - pick "the latest release". The server has to match *this* client, which//! may not be the latest; a development build has no release to match at//! all and is told so.-//! - keep sessions alive across the restart. That needs the server to hand-//! its ptys to its successor, which it cannot do yet.+//! - end sessions to get the new version running, when it can help it. A+//! server that can hand over (`thinkterm-mux-server --takeover`) is asked+//! to; only when it cannot, or the person turned that off, does the old+//! question come: stop the server, ending every session, or leave it.use crate::client::IncompatibleVersionError;use anyhow::Context;@@ -24,8 +26,22 @@ use config::SshDomain;use mux::connui::ConnectionUI;use portable_pty::Child as _;use std::io::Read;+use std::sync::atomic::{AtomicBool, Ordering};use wezterm_ssh::Session;+static KEEP_SESSIONS: AtomicBool = AtomicBool::new(true);++/// Whether a remote update hands the running server's sessions to the new+/// version (the default) or asks to stop the server. The GUI sets it from+/// its settings; a headless client keeps the default.+pub fn set_keep_sessions_on_update(keep: bool) {+ KEEP_SESSIONS.store(keep, Ordering::SeqCst);+}++pub fn keep_sessions_on_update() -> bool {+ KEEP_SESSIONS.load(Ordering::SeqCst)+}+#[derive(Debug, PartialEq, Eq)]pub enum RemoteUpdateOutcome {/// Nothing was changed on the host: the person said no, or the client is@@ -130,6 +146,28 @@ pub fn offer_remote_update(anyhow::bail!("the installer on {host} failed");}+ // The installed server can take the running one over, sessions and+ // all; the running server has to be new enough to hand over, and the+ // person may have turned this off.+ if keep_sessions_on_update() {+ ui.output_str(&format!(+ "\nHanding the sessions of the running mux server on {host} to {local}...\n"+ ));+ match run_and_relay(&session, ui, &thinkterm_update::takeover_command()) {+ Ok(true) => {+ ui.output_str("Handed over; reconnecting.\n");+ return Ok(RemoteUpdateOutcome::Updated { restarted: true });+ }+ Ok(false) => ui.output_str(&format!(+ "\nThe running server on {host} could not hand over (its output is above; \+ a server from before the handoff feature cannot). The old way remains.\n"+ )),+ Err(err) => ui.output_str(&format!(+ "\nCould not run the takeover on {host}: {err:#}. The old way remains.\n"+ )),+ }+ }+// The install is done whatever happens to this question: a UI that has// gone away by now leaves the old server running, which is the safe// answer, not a failure.diff --git a/wezterm-gui/i18n/en-US.ftl b/wezterm-gui/i18n/en-US.ftlindex 57da2321..29d54c45 100644--- a/wezterm-gui/i18n/en-US.ftl+++ b/wezterm-gui/i18n/en-US.ftl@@ -108,6 +108,8 @@ settings-remote-drop-destination-description = Where files dropped onto a remotesettings-notifications-heading = Notificationssettings-notification-sounds = Notification Soundssettings-notification-sounds-description = Play a short sound when a thread finishes or starts waiting on you.+settings-remote-update-keep-sessions = Keep sessions when updating a remote server+settings-remote-update-keep-sessions-description = The running server hands its panes to the new version instead of stopping; nothing running in them ends.settings-terminal-heading = Terminal configurationsettings-default-shell = Default Shellsettings-default-shell-description = The program a new terminal runs. Takes effect the next time you open one.@@ -523,6 +525,9 @@ settings-status-window-restore-on = Main window frame restore enabled for new masettings-status-notification-sounds-on = Notification sounds enabled.settings-status-notification-sounds-off = Notification sounds turned off.settings-status-notification-sounds-error = Could not save the notification sound setting: { $error }+settings-status-remote-update-keep-sessions-on = Remote updates will hand sessions over to the new version.+settings-status-remote-update-keep-sessions-off = Remote updates will ask before stopping the server.+settings-status-remote-update-keep-sessions-error = Could not save the remote update setting: { $error }settings-status-window-restore-off = Main window frame restore disabled for new macOS windows.settings-status-window-restore-error = Unable to save window restore setting: { $error }settings-status-renderer = Main window renderer set to { $renderer }; restart ThinkTerm to apply it.diff --git a/wezterm-gui/i18n/fr-FR.ftl b/wezterm-gui/i18n/fr-FR.ftlindex 7c25f16f..6442ec18 100644--- a/wezterm-gui/i18n/fr-FR.ftl+++ b/wezterm-gui/i18n/fr-FR.ftl@@ -108,6 +108,8 @@ settings-remote-drop-destination-description = Emplacement d’envoi des fichiersettings-notifications-heading = Notificationssettings-notification-sounds = Sons de notificationsettings-notification-sounds-description = Émettre un son bref lorsqu’une session se termine ou attend une réponse.+settings-remote-update-keep-sessions = Conserver les sessions lors de la mise à jour d’un serveur distant+settings-remote-update-keep-sessions-description = Le serveur en cours transmet ses panneaux à la nouvelle version au lieu de s’arrêter ; rien de ce qui y tourne ne s’interrompt.settings-terminal-heading = Configuration du terminalsettings-default-shell = Shell par défautsettings-default-shell-description = Le programme lancé par un nouveau terminal. Prend effet à la prochaine ouverture.@@ -523,6 +525,9 @@ settings-status-window-restore-on = Restauration de la taille et position activsettings-status-notification-sounds-on = Sons de notification activés.settings-status-notification-sounds-off = Sons de notification désactivés.settings-status-notification-sounds-error = Impossible d’enregistrer le réglage des sons de notification : { $error }+settings-status-remote-update-keep-sessions-on = Les mises à jour distantes transmettront les sessions à la nouvelle version.+settings-status-remote-update-keep-sessions-off = Les mises à jour distantes demanderont avant d’arrêter le serveur.+settings-status-remote-update-keep-sessions-error = Impossible d’enregistrer le réglage de mise à jour distante : { $error }settings-status-window-restore-off = Restauration de la taille et position désactivée pour les nouvelles fenêtres macOS.settings-status-window-restore-error = Impossible d’enregistrer la restauration de fenêtre : { $error }settings-status-renderer = Moteur de rendu principal défini sur { $renderer } ; redémarrez ThinkTerm pour l’appliquer.diff --git a/wezterm-gui/i18n/ja-JP.ftl b/wezterm-gui/i18n/ja-JP.ftlindex 9b3ba7ea..d700c087 100644--- a/wezterm-gui/i18n/ja-JP.ftl+++ b/wezterm-gui/i18n/ja-JP.ftl@@ -105,6 +105,8 @@ settings-remote-drop-destination-description = リモートターミナルへドsettings-notifications-heading = 通知settings-notification-sounds = 通知音settings-notification-sounds-description = スレッドが完了したとき、または入力待ちになったときに短い音を鳴らします。+settings-remote-update-keep-sessions = リモートサーバー更新時にセッションを維持+settings-remote-update-keep-sessions-description = 実行中のサーバーは停止せず、ペインを新しいバージョンに引き継ぎます。実行中の処理は中断されません。settings-terminal-heading = ターミナル設定settings-default-shell = 既定のシェルsettings-default-shell-description = 新しいターミナルで実行するプログラムです。次に開いたときから有効になります。@@ -514,6 +516,9 @@ settings-status-window-restore-on = 新しい macOS ウィンドウで位置とsettings-status-notification-sounds-on = 通知音を有効にしました。settings-status-notification-sounds-off = 通知音を無効にしました。settings-status-notification-sounds-error = 通知音の設定を保存できませんでした: { $error }+settings-status-remote-update-keep-sessions-on = リモート更新時にセッションを新しいバージョンへ引き継ぎます。+settings-status-remote-update-keep-sessions-off = リモート更新時はサーバーを停止する前に確認します。+settings-status-remote-update-keep-sessions-error = リモート更新の設定を保存できませんでした: { $error }settings-status-window-restore-off = 新しい macOS ウィンドウで位置とサイズの復元を無効にしました。settings-status-window-restore-error = ウィンドウ復元設定を保存できません:{ $error }settings-status-renderer = メインウィンドウのレンダラーを { $renderer } に設定しました。ThinkTerm の再起動後に適用されます。diff --git a/wezterm-gui/i18n/zh-CN.ftl b/wezterm-gui/i18n/zh-CN.ftlindex bacc9413..0bf8e09e 100644--- a/wezterm-gui/i18n/zh-CN.ftl+++ b/wezterm-gui/i18n/zh-CN.ftl@@ -105,6 +105,8 @@ settings-remote-drop-destination-description = 拖到远程终端的文件上传settings-notifications-heading = 通知settings-notification-sounds = 提示音settings-notification-sounds-description = Thread 完成或等待你输入时播放提示音。+settings-remote-update-keep-sessions = 更新远端 server 时保留会话+settings-remote-update-keep-sessions-description = 运行中的 server 把 pane 交给新版本而不是停掉,里面跑的程序不会中断。settings-terminal-heading = 终端配置settings-default-shell = 默认 Shellsettings-default-shell-description = 新开终端运行的程序,下次打开时生效。@@ -514,6 +516,9 @@ settings-status-window-restore-on = 已为新的 macOS 窗口启用主窗口位settings-status-notification-sounds-on = 已开启提示音。settings-status-notification-sounds-off = 已关闭提示音。settings-status-notification-sounds-error = 无法保存提示音设置:{ $error }+settings-status-remote-update-keep-sessions-on = 已开启:更新远端时会把会话交给新版本。+settings-status-remote-update-keep-sessions-off = 已关闭:更新远端时会先询问是否停止 server。+settings-status-remote-update-keep-sessions-error = 无法保存远端更新设置:{ $error }settings-status-window-restore-off = 已为新的 macOS 窗口关闭主窗口位置与大小恢复。settings-status-window-restore-error = 无法保存窗口恢复设置:{ $error }settings-status-renderer = 主窗口渲染器已设为 { $renderer };重启 ThinkTerm 后生效。diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rsindex 9cbb86e8..29d8f7f2 100644--- a/wezterm-gui/src/main.rs+++ b/wezterm-gui/src/main.rs@@ -1221,6 +1221,9 @@ fn run_terminal_gui(opts: StartCommand, default_domain_name: Option<String>) ->wezterm_client::domain::set_thinkterm_frontend_recovery_sink(crate::frontend::request_thinkterm_frontend_recovery,);+ wezterm_client::remote_update::set_keep_sessions_on_update(+ crate::native_settings::remote_update_keeps_sessions(),+ );let config = config::configuration();let need_builder = !opts.prog.is_empty() || opts.cwd.is_some();diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rsindex 87a7cb3c..13b9b212 100644--- a/wezterm-gui/src/native_settings.rs+++ b/wezterm-gui/src/native_settings.rs@@ -362,6 +362,9 @@ pub(crate) struct NativeWorkspaceSettings {/// Play a short sound when a thread you are not watching finishes, or when/// one starts waiting on you.pub(crate) notification_sounds_enabled: bool,+ /// Updating a remote mux server hands its sessions to the new version+ /// instead of stopping it; off, the update asks whether to stop it.+ pub(crate) remote_update_keeps_sessions: bool,}impl Default for NativeWorkspaceSettings {@@ -371,6 +374,7 @@ impl Default for NativeWorkspaceSettings {remote_download_directory: String::new(),remote_drop_destination: String::new(),notification_sounds_enabled: true,+ remote_update_keeps_sessions: true,}}}@@ -908,6 +912,10 @@ pub(crate) fn notification_sounds_enabled() -> bool {load().workspaces.notification_sounds_enabled}+pub(crate) fn remote_update_keeps_sessions() -> bool {+ load().workspaces.remote_update_keeps_sessions+}+pub(crate) fn bottom_quote_interval_minutes(settings: &ThinkTermNativeSettings) -> u32 {settings.terminaldiff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rsindex eb0a4cf9..708ad6cb 100644--- a/wezterm-gui/src/settings_window.rs+++ b/wezterm-gui/src/settings_window.rs@@ -721,6 +721,7 @@ enum SettingsAction {ToggleImportField(ImportFieldId),ToggleMainWindowFrameRestore,ToggleNotificationSounds,+ ToggleRemoteUpdateKeepsSessions,/// Turn one right-sidebar panel on or off.ToggleRightSidebarPanel(crate::termwindow::RightSidebarMode),ToggleAgentDetails(&'static str),@@ -3564,6 +3565,27 @@ impl SettingsWindow {}}}+ SettingsAction::ToggleRemoteUpdateKeepsSessions => {+ self.ui.open_dropdown = None;+ let enabled = !self.native_settings.workspaces.remote_update_keeps_sessions;+ self.native_settings.workspaces.remote_update_keeps_sessions = enabled;+ wezterm_client::remote_update::set_keep_sessions_on_update(enabled);+ match crate::native_settings::save(&self.native_settings) {+ Ok(()) => {+ self.status = crate::i18n::tr(if enabled {+ "settings-status-remote-update-keep-sessions-on"+ } else {+ "settings-status-remote-update-keep-sessions-off"+ });+ }+ Err(err) => {+ self.status = settings_tr(+ "settings-status-remote-update-keep-sessions-error",+ &[("error", format!("{err:#}"))],+ );+ }+ }+ }SettingsAction::ToggleMainRendererMenu => {self.ui.open_dropdown =if self.ui.open_dropdown == Some(SettingsDropdown::MainRenderer) {@@ -7786,9 +7808,25 @@ impl SettingsWindow {)?;}+ // One choice: what updating a remote server does to its sessions.+ let toggle_card_y = card_y + card_height + gap;+ let toggle_card_height = self.settings_card_height(1);+ self.paint_group_card(layers, x, toggle_card_y, max_width, toggle_card_height)?;+ self.paint_toggle_setting_row(+ layers,+ row_x,+ toggle_card_y + self.settings_card_top_padding(),+ row_width,+ &crate::i18n::tr("settings-remote-update-keep-sessions"),+ &crate::i18n::tr("settings-remote-update-keep-sessions-description"),+ self.native_settings.workspaces.remote_update_keeps_sessions,+ SettingsAction::ToggleRemoteUpdateKeepsSessions,+ true,+ )?;+// Under the facts: what an install would do here, or why this page// cannot do one, and the outcome of the install just run.- let note_y = card_y + card_height + gap;+ let note_y = toggle_card_y + toggle_card_height + gap;let line_step = self.metrics.cell_size.height as f32 + self.ui_px(6.0);let mut notes: Vec<(String, LinearRgba)> = Vec::new();match &self.ui.update_install {