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
Free codec of native-only async and compression dependencies
RoversXbcf0f527da9c
diff --git a/Cargo.lock b/Cargo.lockindex 8b2112de..535066fb 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -856,14 +856,15 @@ dependencies = ["anyhow","base91","config",+ "futures-lite","leb128","log","metrics","mux","portable-pty","rangeset",+ "ruzstd","serde",- "smol","termwiz 0.24.0","thiserror 1.0.69","varbincode",@@ -2267,9 +2268,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"dependencies = ["cfg-if",+ "js-sys","libc","r-efi","wasip2",+ "wasm-bindgen",][[package]]@@ -5458,6 +5461,15 @@ version = "1.0.22"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"+[[package]]+name = "ruzstd"+version = "0.8.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a7c1c839d570d835527c9a5e4db7cb2198683a988cb9d7293fc8674e6bd58fc8"+dependencies = [+ "twox-hash",+]+[[package]]name = "ryu"version = "1.0.20"@@ -7093,6 +7105,12 @@ version = "0.2.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"+[[package]]+name = "twox-hash"+version = "2.1.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8464ec13c3691491391d9fce00f6416c9a48e46972f72d7865688be2080192c9"+[[package]]name = "type-map"version = "0.5.1"@@ -7483,6 +7501,14 @@ dependencies = ["unicode-ident",]+[[package]]+name = "wasm-probe"+version = "0.1.0"+dependencies = [+ "termwiz 0.24.0",+ "wezterm-term",+]+[[package]]name = "wayland-backend"version = "0.3.11"diff --git a/Cargo.toml b/Cargo.tomlindex f943fdc9..5b2b6d67 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -197,6 +197,7 @@ reqwest = "0.12"resize = "0.5"resvg = { version = "0.45.1", default-features = false }rstest = "0.21"+ruzstd = "0.8"rusqlite = "0.32"serde = {version="1.0", default-features=false, features = ["derive"]}serde-funcs = { path = "lua-api-crates/serde-funcs" }diff --git a/codec/Cargo.toml b/codec/Cargo.tomlindex 01db1d7a..62bd061f 100644--- a/codec/Cargo.toml+++ b/codec/Cargo.toml@@ -17,12 +17,23 @@ mux.workspace = trueportable-pty = { workspace = true, features = ["serde_support"]}rangeset.workspace = trueserde = {workspace=true, features = ["rc", "derive"]}-smol.workspace = true+futures-lite.workspace = truetermwiz.workspace = truethiserror.workspace = truevarbincode.workspace = truewezterm-term = { workspace=true, features=["use_serde"] }++# zstd binds the C library, which does not build for wasm. There the crate+# decompresses with the pure-Rust ruzstd and never compresses -- legal because+# is_compressed is a unilateral per-PDU choice by the sender.+[target.'cfg(not(target_family = "wasm"))'.dependencies]zstd.workspace = true+[target.'cfg(target_family = "wasm")'.dependencies]+ruzstd.workspace = true+[dev-dependencies]base91.workspace = true+# The native test suite proves ruzstd can decode zstd's output, which is the+# wasm client's receive path.+ruzstd.workspace = truediff --git a/codec/src/lib.rs b/codec/src/lib.rsindex 5a4ce206..79b55c8c 100644--- a/codec/src/lib.rs+++ b/codec/src/lib.rs@@ -21,8 +21,11 @@ use mux::window::WindowId;use portable_pty::CommandBuilder;use rangeset::*;use serde::{Deserialize, Serialize};-use smol::io::AsyncWriteExt;-use smol::prelude::*;+// smol's io/prelude are pure re-exports of these futures-lite modules, so+// this is the same set of traits -- minus smol's runtime (async-io, polling),+// which does not build for wasm and which nothing in this crate uses.+use futures_lite::io::AsyncWriteExt;+use futures_lite::prelude::*;use std::collections::HashMap;use std::convert::TryInto;use std::io::Cursor;@@ -292,6 +295,7 @@ pub struct DecodedPdu {}/// If the serialized size is larger than this, then we'll consider compressing it+#[cfg(not(target_family = "wasm"))]const COMPRESS_THRESH: usize = 32;fn serialize<T: serde::Serialize>(t: &T) -> Result<(Vec<u8>, bool), Error> {@@ -299,27 +303,38 @@ fn serialize<T: serde::Serialize>(t: &T) -> Result<(Vec<u8>, bool), Error> {let mut encode = varbincode::Serializer::new(&mut uncompressed);t.serialize(&mut encode)?;- if uncompressed.len() <= COMPRESS_THRESH {- return Ok((uncompressed, false));+ // No zstd on wasm, so a wasm sender never compresses. The receiving side+ // handles both forms regardless, and the outbound traffic of a thin+ // client is mostly keystrokes, so there is nothing worth compressing.+ #[cfg(target_family = "wasm")]+ {+ Ok((uncompressed, false))}- // It's a little heavy; let's try compressing it- let mut compressed = Vec::new();- let mut compress = zstd::Encoder::new(&mut compressed, zstd::DEFAULT_COMPRESSION_LEVEL)?;- let mut encode = varbincode::Serializer::new(&mut compress);- t.serialize(&mut encode)?;- drop(encode);- compress.finish()?;- log::debug!(- "serialized+compress len {} vs {}",- compressed.len(),- uncompressed.len()- );+ #[cfg(not(target_family = "wasm"))]+ {+ if uncompressed.len() <= COMPRESS_THRESH {+ return Ok((uncompressed, false));+ }+ // It's a little heavy; let's try compressing it+ let mut compressed = Vec::new();+ let mut compress = zstd::Encoder::new(&mut compressed, zstd::DEFAULT_COMPRESSION_LEVEL)?;+ let mut encode = varbincode::Serializer::new(&mut compress);+ t.serialize(&mut encode)?;+ drop(encode);+ compress.finish()?;++ log::debug!(+ "serialized+compress len {} vs {}",+ compressed.len(),+ uncompressed.len()+ );- if compressed.len() < uncompressed.len() {- Ok((compressed, true))- } else {- Ok((uncompressed, false))+ if compressed.len() < uncompressed.len() {+ Ok((compressed, true))+ } else {+ Ok((uncompressed, false))+ }}}@@ -328,7 +343,13 @@ fn deserialize<T: serde::de::DeserializeOwned, R: std::io::Read>(is_compressed: bool,) -> Result<T, Error> {if is_compressed {+ #[cfg(not(target_family = "wasm"))]let mut decompress = zstd::Decoder::new(r)?;+ // The pure-Rust decoder stands in where the zstd C library cannot+ // build; it also implements std::io::Read, so the shape is identical.+ #[cfg(target_family = "wasm")]+ let mut decompress = ruzstd::decoding::StreamingDecoder::new(r)+ .map_err(|e| anyhow::anyhow!("ruzstd: {e}"))?;let mut decode = varbincode::Deserializer::new(&mut decompress);serde::Deserialize::deserialize(&mut decode).map_err(Into::into)} else {@@ -1507,6 +1528,37 @@ pub struct GetImageCellResponse {mod test {use super::*;+ /// First coverage of the compressed path: every pre-existing test payload+ /// sits under COMPRESS_THRESH and never touches zstd.+ #[test]+ fn compressed_serialize_round_trips() {+ let payload: Vec<u8> = std::iter::repeat(b"thinkterm ".as_slice())+ .take(100)+ .flatten()+ .copied()+ .collect();+ let (bytes, is_compressed) = serialize(&payload).unwrap();+ assert!(is_compressed, "1000 repetitive bytes must compress");+ let back: Vec<u8> = deserialize(bytes.as_slice(), is_compressed).unwrap();+ assert_eq!(back, payload);+ }++ /// The wasm client's receive path: a native server compresses with the+ /// zstd C library, the wasm side decodes with pure-Rust ruzstd. Proven+ /// here on native, where both libraries are available.+ #[test]+ fn ruzstd_decodes_zstd_output() {+ let payload: Vec<u8> = (0u32..500).flat_map(|v| v.to_le_bytes()).collect();+ let (bytes, is_compressed) = serialize(&payload).unwrap();+ assert!(is_compressed);++ let mut decompress =+ ruzstd::decoding::StreamingDecoder::new(bytes.as_slice()).expect("ruzstd frame");+ let mut decode = varbincode::Deserializer::new(&mut decompress);+ let back: Vec<u8> = serde::Deserialize::deserialize(&mut decode).unwrap();+ assert_eq!(back, payload);+ }+#[test]fn test_frame() {let mut encoded = Vec::new();