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
Fix three defects a review of this branch found
RoversXc688b91b43dd
diff --git a/wezterm-gui/src/termwindow/remote_files.rs b/wezterm-gui/src/termwindow/remote_files.rsindex 527296d1..cd4d8d86 100644--- a/wezterm-gui/src/termwindow/remote_files.rs+++ b/wezterm-gui/src/termwindow/remote_files.rs@@ -3675,7 +3675,9 @@ mod tests {let landed = destination.file_name().and_then(|n| n.to_str()).unwrap();assert!(crate::termwindow::remote_walk::DownloadNameRules::host().accepts(landed),- "{hostile:?} landed as {landed:?}, which this host refuses"+ "{:?} landed as {:?}, which this host refuses",+ hostile,+ landed);}// Names this host cannot store are rewritten rather than refused: the@@ -3687,7 +3689,9 @@ mod tests {let landed = destination.file_name().and_then(|n| n.to_str()).unwrap();assert!(crate::termwindow::remote_walk::DownloadNameRules::host().accepts(landed),- "{reserved:?} landed as {landed:?}, which this host refuses"+ "{:?} landed as {:?}, which this host refuses",+ reserved,+ landed);if cfg!(unix) {assert_eq!(landed, reserved, "unix has no quarrel with this name");diff --git a/wezterm-gui/src/termwindow/remote_walk.rs b/wezterm-gui/src/termwindow/remote_walk.rsindex af599f7a..c86fdb9f 100644--- a/wezterm-gui/src/termwindow/remote_walk.rs+++ b/wezterm-gui/src/termwindow/remote_walk.rs@@ -194,26 +194,19 @@ fn windows_download_name(name: &str) -> Cow<'_, str> {.map(|ch| if windows_reserved_char(ch) { '_' } else { ch }).collect();trim_trailing_dots_and_spaces(&mut out);+ // Length before the device check, not after. The limit counts UTF-16+ // units, so the cut walks characters rather than slicing bytes, and the+ // trim has to run again because the cut can expose a dot or a space --+ // which is exactly how the stem changes underneath: `CON` followed by+ // 252 spaces is not a device name until the cut and the trim have taken+ // the spaces away, and then it is.+ cut_to_255_utf16_units(&mut out);if windows_reserved_stem(&out) {out.insert(0, '_');- }- // The limit counts UTF-16 units, so the cut has to be found by walking- // characters rather than by slicing bytes. Trimming again afterwards- // because the cut can expose a dot or a space; the stem cannot become- // reserved this way, since cutting the end leaves a stem shorter than- // itself only when the stem was already over the limit.- if out.encode_utf16().count() > 255 {- let mut units = 0usize;- let mut end = out.len();- for (index, ch) in out.char_indices() {- if units + ch.len_utf16() > 255 {- end = index;- break;- }- units += ch.len_utf16();- }- out.truncate(end);- trim_trailing_dots_and_spaces(&mut out);+ // The prefix can put it back over the limit. Cutting again is safe+ // to do once: the stem now begins with `_`, so no amount of taking+ // from the end can make it a device name a second time.+ cut_to_255_utf16_units(&mut out);}if out.is_empty() {out.push_str("download");@@ -221,6 +214,23 @@ fn windows_download_name(name: &str) -> Cow<'_, str> {Cow::Owned(out)}+fn cut_to_255_utf16_units(name: &mut String) {+ if name.encode_utf16().count() <= 255 {+ return;+ }+ let mut units = 0usize;+ let mut end = name.len();+ for (index, ch) in name.char_indices() {+ if units + ch.len_utf16() > 255 {+ end = index;+ break;+ }+ units += ch.len_utf16();+ }+ name.truncate(end);+ trim_trailing_dots_and_spaces(name);+}+/// Walk `root` into a flat, parents-first plan.////// Refusals are total: a listing that comes back truncated, a tree over the@@ -672,6 +682,10 @@ mod tests {let long = "a".repeat(300);let long_tail = format!("{}.", "b".repeat(255));let wide = "😀".repeat(200);+ // Over the limit, and what the cut leaves behind once its trailing+ // spaces go is a device name again.+ let device_after_cut = format!("CON{}abc", " ".repeat(252));+ let port_after_cut = format!("COM1{}x", " ".repeat(300));for name in ["report:2024.txt","a<b>c|d?e*f\"g",@@ -694,11 +708,15 @@ mod tests {&long,&long_tail,&wide,+ &device_after_cut,+ &port_after_cut,] {let sanitized = DownloadNameRules::Windows.sanitize(name);assert!(DownloadNameRules::Windows.accepts(&sanitized),- "sanitize({name:?}) produced {sanitized:?}, which is still refused"+ "sanitize({:?}) produced {:?}, which is still refused",+ name,+ sanitized);}// A name that is already fine is handed back untouched, not copied.diff --git a/wezterm-mux-server-impl/src/sessionhandler.rs b/wezterm-mux-server-impl/src/sessionhandler.rsindex e1a29a10..a20e4a0d 100644--- a/wezterm-mux-server-impl/src/sessionhandler.rs+++ b/wezterm-mux-server-impl/src/sessionhandler.rs@@ -2935,7 +2935,8 @@ mod web_server_address_tests {] {assert!(super::web_server_to_start(Some(good)).is_ok(),- "{good:?} should be a listenable address"+ "{:?} should be a listenable address",+ good);}for bad in [@@ -2951,7 +2952,9 @@ mod web_server_address_tests {let err = super::web_server_to_start(Some(bad)).unwrap_err().to_string();assert!(err.contains("address:port"),- "{bad:?} was accepted, or refused for another reason: {err}"+ "{:?} was accepted, or refused for another reason: {}",+ bad,+ err);}}diff --git a/wezterm-mux-server-impl/src/web_auth.rs b/wezterm-mux-server-impl/src/web_auth.rsindex f03cb4e3..dff63782 100644--- a/wezterm-mux-server-impl/src/web_auth.rs+++ b/wezterm-mux-server-impl/src/web_auth.rs@@ -8,7 +8,6 @@//! nothing, and revoking a token drops the connections it admitted on the//! spot.-use anyhow::Context;use base64::Engine;use codec::WebTokenInfo;use serde::{Deserialize, Serialize};diff --git a/wezterm-mux-server-impl/src/web_http.rs b/wezterm-mux-server-impl/src/web_http.rsindex 291620e9..f9727032 100644--- a/wezterm-mux-server-impl/src/web_http.rs+++ b/wezterm-mux-server-impl/src/web_http.rs@@ -1057,11 +1057,15 @@ mod tests {let head = String::from_utf8(response_head(status, reason, &[], body_len)).unwrap();assert!(head.contains("\r\nContent-Security-Policy: frame-ancestors 'none'\r\n"),- "{status} carries no frame-ancestors: {head:?}"+ "{} carries no frame-ancestors: {:?}",+ status,+ head);assert!(head.contains("\r\nX-Frame-Options: DENY\r\n"),- "{status} carries no X-Frame-Options: {head:?}"+ "{} carries no X-Frame-Options: {:?}",+ status,+ head);}}diff --git a/wezterm-open-url/src/lib.rs b/wezterm-open-url/src/lib.rsindex 8cf8120e..21306e8d 100644--- a/wezterm-open-url/src/lib.rs+++ b/wezterm-open-url/src/lib.rs@@ -348,11 +348,12 @@ pub fn reveal_path(path: &std::path::Path) {let path = path.to_path_buf();std::thread::spawn(move || {+ let explorer = system_explorer();// `canonicalize` fails when the item is gone; open the folder that// would have held it rather than nothing. Never the item itself.let Ok(full) = std::fs::canonicalize(&path) else {if let Some(parent) = path.parent() {- let _ = std::process::Command::new("explorer.exe").arg(parent).spawn();+ let _ = std::process::Command::new(&explorer).arg(parent).spawn();}return;};@@ -363,12 +364,27 @@ pub fn reveal_path(path: &std::path::Path) {// Its exit status says nothing -- Explorer returns 1 even when it// worked -- so nothing here may branch on it. In particular there is// no falling back to `shell_execute`, which is what ran the file.- let _ = std::process::Command::new("explorer.exe")+ let _ = std::process::Command::new(&explorer).raw_arg(select_argument(&full.to_string_lossy())).spawn();});}+/// Explorer, by absolute path.+///+/// `Command::new("explorer.exe")` searches for the name, and that search+/// reaches the directory of the *running executable* before System32. An+/// `explorer.exe` dropped beside ThinkTerm -- a portable zip unpacked under+/// Downloads, a per-user install, a build tree -- would therefore run as the+/// user the first time anyone revealed a file. That is precisely the+/// arbitrary execution this function exists to remove, and it must not come+/// back in through the name lookup.+#[cfg(windows)]+fn system_explorer() -> PathBuf {+ let root = std::env::var_os("SystemRoot").unwrap_or_else(|| r"C:\Windows".into());+ Path::new(&root).join("explorer.exe")+}+/// The `/select,` argument for a full path.////// `canonicalize` hands back a verbatim path, which Explorer does not@@ -402,6 +418,19 @@ mod tests {// Never canonicalized, so never prefixed: unchanged.assert_eq!(super::select_argument(r"C:\x.txt"), r#"/select,"C:\x.txt""#);}++ /// Named absolutely, because the search for a bare `explorer.exe` looks+ /// in the running executable's own directory before System32.+ #[test]+ fn explorer_is_named_absolutely() {+ let explorer = super::system_explorer();+ assert!(explorer.is_absolute(), "{}", explorer.display());+ assert_eq!(+ explorer.file_name().and_then(|n| n.to_str()),+ Some("explorer.exe")+ );+ assert!(explorer.is_file(), "{} is not there", explorer.display());+ }}#[cfg(target_os = "macos")]