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.

Replace CommandBuilder with CommandSpec on the wire; codec v60

RoversXa3ce3d46fd05
diff --git a/Cargo.lock b/Cargo.lock
index d9adf55f..6589bf31 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -860,7 +860,6 @@ dependencies = [
"leb128",
"log",
"metrics",
- "portable-pty",
"rangeset",
"ruzstd",
"serde",
diff --git a/codec/Cargo.toml b/codec/Cargo.toml
index c2fa35fd..6895851b 100644
--- a/codec/Cargo.toml
+++ b/codec/Cargo.toml
@@ -12,7 +12,6 @@ anyhow.workspace = true
leb128.workspace = true
log.workspace = true
metrics.workspace = true
-portable-pty = { workspace = true, features = ["serde_support"]}
rangeset.workspace = true
thinkterm-proto.workspace = true
serde = {workspace=true, features = ["rc", "derive"]}
diff --git a/codec/src/lib.rs b/codec/src/lib.rs
index f1793053..d3f07994 100644
--- a/codec/src/lib.rs
+++ b/codec/src/lib.rs
@@ -13,10 +13,9 @@
use anyhow::{Context as _, Error, bail};
use thinkterm_proto::{
- ClientId, ClientInfo, PaneDirection, PaneId, PaneNode, RenderableDimensions,
+ ClientId, ClientInfo, CommandSpec, PaneDirection, PaneId, PaneNode, RenderableDimensions,
ScrollbackEraseMode, SerdeUrl, SplitRequest, StableCursorPosition, TabId, WindowId,
};
-use portable_pty::CommandBuilder;
use rangeset::*;
use serde::{Deserialize, Serialize};
// smol's io/prelude are pure re-exports of these futures-lite modules, so
@@ -480,7 +479,10 @@ macro_rules! pdu {
/// 56: Pane entries carry that state too, so a renderer knows it on arrival.
/// 57: Frontends publish and follow a shared per-tab scroll position.
/// 58: Connection-wide A/B access modes and atomic geometry-bearing claims.
-pub const CODEC_VERSION: usize = 59;
+/// 60: Spawn PDUs carry a portable CommandSpec instead of CommandBuilder;
+/// argv, env and cwd travel as byte strings rather than OsString, and
+/// the umask field exists on every platform instead of only unix.
+pub const CODEC_VERSION: usize = 60;
// Defines the Pdu enum.
// Each struct has an explicit identifying number.
@@ -737,7 +739,7 @@ pub struct ListPanesResponse {
pub struct SplitPane {
pub pane_id: PaneId,
pub split_request: SplitRequest,
- pub command: Option<CommandBuilder>,
+ pub command: Option<CommandSpec>,
pub command_dir: Option<String>,
pub domain: thinkterm_proto::SpawnTabDomain,
/// Instead of spawning a command, move the specified
@@ -750,7 +752,7 @@ pub struct SplitPane {
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct SpawnPaneInStack {
pub pane_id: PaneId,
- pub command: Option<CommandBuilder>,
+ pub command: Option<CommandSpec>,
pub command_dir: Option<String>,
pub domain: thinkterm_proto::SpawnTabDomain,
}
@@ -789,7 +791,7 @@ pub struct SpawnV2 {
pub domain: thinkterm_proto::SpawnTabDomain,
/// If None, create a new window for this new tab
pub window_id: Option<WindowId>,
- pub command: Option<CommandBuilder>,
+ pub command: Option<CommandSpec>,
pub command_dir: Option<String>,
pub size: TerminalSize,
pub workspace: String,
@@ -1800,6 +1802,67 @@ mod test {
}
}
+ /// All three spawn-class PDUs, populated with a CommandSpec that
+ /// exercises every field: non-utf8 argv bytes, base and explicit env
+ /// entries, a cwd, a umask and a lowered tty flag. Pure codec -- no pty
+ /// dependency -- which also proves the crate is self-contained.
+ #[test]
+ fn spawn_pdus_round_trip_at_version_60() {
+ use thinkterm_proto::{EnvVar, SpawnTabDomain};
+
+ let spec = CommandSpec {
+ args: vec![b"htop".to_vec(), vec![0x66, 0x80, 0x6f]],
+ env: vec![
+ EnvVar {
+ key: b"PATH".to_vec(),
+ value: b"/usr/bin".to_vec(),
+ is_from_base_env: true,
+ },
+ EnvVar {
+ key: b"FOO".to_vec(),
+ value: b"bar".to_vec(),
+ is_from_base_env: false,
+ },
+ ],
+ cwd: Some(b"/tmp".to_vec()),
+ umask: Some(0o022),
+ controlling_tty: false,
+ };
+
+ let pdus = [
+ Pdu::SpawnV2(SpawnV2 {
+ domain: SpawnTabDomain::DefaultDomain,
+ window_id: Some(1),
+ command: Some(spec.clone()),
+ command_dir: None,
+ size: TerminalSize::default(),
+ workspace: "default".to_string(),
+ }),
+ Pdu::SplitPane(SplitPane {
+ pane_id: 2,
+ split_request: SplitRequest::default(),
+ command: Some(spec.clone()),
+ command_dir: Some("/home".to_string()),
+ domain: SpawnTabDomain::CurrentPaneDomain,
+ move_pane_id: None,
+ }),
+ Pdu::SpawnPaneInStack(SpawnPaneInStack {
+ pane_id: 3,
+ command: None,
+ command_dir: None,
+ domain: SpawnTabDomain::DomainName("dom".to_string()),
+ }),
+ ];
+
+ for pdu in pdus {
+ let mut encoded = Vec::new();
+ pdu.encode(&mut encoded, 0x11).unwrap();
+ let decoded = Pdu::decode(encoded.as_slice()).unwrap();
+ assert_eq!(decoded.pdu, pdu);
+ assert_eq!(decoded.serial, 0x11);
+ }
+ }
+
#[test]
fn test_pdu_ping() {
let mut encoded = Vec::new();
@@ -1903,8 +1966,8 @@ mod test {
}
#[test]
- fn thinkterm_session_viewport_and_landing_protocol_round_trip_at_version_59() {
- assert_eq!(CODEC_VERSION, 59);
+ fn thinkterm_session_viewport_and_landing_protocol_round_trip_at_version_60() {
+ assert_eq!(CODEC_VERSION, 60);
let size = TerminalSize {
rows: 40,
cols: 132,
diff --git a/mux/src/command_spec.rs b/mux/src/command_spec.rs
index 76b4d06e..fece0b12 100644
--- a/mux/src/command_spec.rs
+++ b/mux/src/command_spec.rs
@@ -1,6 +1,6 @@
use portable_pty::CommandBuilder;
use std::ffi::{OsStr, OsString};
-use thinkterm_proto::{CommandSpec, EnvVar};
+pub use thinkterm_proto::{CommandSpec, EnvVar};
/// Free-standing conversions rather than `From` impls: both types are
/// foreign here. `CommandSpec` belongs to thinkterm-proto, which must stay
diff --git a/wezterm-client/src/domain.rs b/wezterm-client/src/domain.rs
index e789b544..3cc44c5b 100644
--- a/wezterm-client/src/domain.rs
+++ b/wezterm-client/src/domain.rs
@@ -6,6 +6,7 @@ use codec::{ListPanesResponse, SpawnV2, SplitPane};
use config::keyassignment::SpawnTabDomain;
use config::{SshDomain, TlsDomainClient, UnixDomain};
use mux::connui::{ConnectionUI, ConnectionUIParams};
+use mux::command_spec::{CommandSpec, CommandSpecExt};
use mux::domain::{Domain, DomainId, DomainState, SplitSource, alloc_domain_id};
use mux::pane::{Pane, PaneId};
use mux::tab::{SplitRequest, Tab, TabId};
@@ -3082,7 +3083,7 @@ impl Domain for ClientDomain {
.client
.spawn_pane_in_stack(codec::SpawnPaneInStack {
pane_id: pane.remote_pane_id,
- command,
+ command: command.as_ref().map(CommandSpec::from_command_builder),
command_dir,
domain: SpawnTabDomain::CurrentPaneDomain,
})
@@ -3277,7 +3278,7 @@ impl Domain for ClientDomain {
domain: SpawnTabDomain::DefaultDomain,
window_id: inner.local_to_remote_window(window),
size,
- command,
+ command: command.as_ref().map(CommandSpec::from_command_builder),
command_dir,
workspace,
})
@@ -3406,7 +3407,7 @@ impl Domain for ClientDomain {
domain: SpawnTabDomain::CurrentPaneDomain,
pane_id: target_remote_pane_id,
split_request,
- command,
+ command: command.as_ref().map(CommandSpec::from_command_builder),
command_dir,
move_pane_id,
})
diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs
index 9c559895..77a5b471 100644
--- a/wezterm-gui/src/main.rs
+++ b/wezterm-gui/src/main.rs
@@ -1007,7 +1007,9 @@ impl Publish {
.spawn_v2(codec::SpawnV2 {
domain,
window_id,
- command,
+ command: command
+ .as_ref()
+ .map(mux::command_spec::CommandSpecExt::from_command_builder),
command_dir: None,
size: config.initial_size(0, None),
workspace: workspace.unwrap_or(
diff --git a/wezterm-mux-server-impl/src/sessionhandler.rs b/wezterm-mux-server-impl/src/sessionhandler.rs
index cb0acb34..f663a131 100644
--- a/wezterm-mux-server-impl/src/sessionhandler.rs
+++ b/wezterm-mux-server-impl/src/sessionhandler.rs
@@ -4,6 +4,7 @@ use codec::*;
use config::keyassignment::SpawnTabDomain;
use config::TermConfig;
use mux::client::ClientId;
+use mux::command_spec::CommandSpecExt;
use mux::domain::SplitSource;
use mux::pane::{CachePolicy, Pane, PaneId};
use mux::renderable::{RenderableDimensions, StableCursorPosition};
@@ -1799,7 +1800,7 @@ async fn spawn_pane_in_stack(request: SpawnPaneInStack) -> anyhow::Result<Pdu> {
.spawn_pane_in_stack(
request.pane_id,
request.domain,
- request.command,
+ request.command.map(|c| c.into_command_builder()),
request.command_dir,
size,
)
@@ -1826,7 +1827,7 @@ async fn split_pane(split: SplitPane) -> anyhow::Result<Pdu> {
SplitSource::MovePane(move_pane_id)
} else {
SplitSource::Spawn {
- command: split.command,
+ command: split.command.map(|c| c.into_command_builder()),
command_dir: split.command_dir,
}
};
@@ -1854,7 +1855,7 @@ async fn domain_spawn_v2(spawn: SpawnV2) -> anyhow::Result<Pdu> {
.spawn_tab_or_window(
spawn.window_id,
spawn.domain,
- spawn.command,
+ spawn.command.map(|c| c.into_command_builder()),
spawn.command_dir,
spawn.size,
None, // optional current pane_id
diff --git a/wezterm/src/cli/spawn_command.rs b/wezterm/src/cli/spawn_command.rs
index 0d1b5aa7..3848531e 100644
--- a/wezterm/src/cli/spawn_command.rs
+++ b/wezterm/src/cli/spawn_command.rs
@@ -3,6 +3,7 @@ use clap::{Parser, ValueHint};
use config::keyassignment::SpawnTabDomain;
use config::ConfigHandle;
use mux::pane::PaneId;
+use mux::command_spec::{CommandSpec, CommandSpecExt};
use mux::window::WindowId;
use portable_pty::cmdbuilder::CommandBuilder;
use std::ffi::OsString;
@@ -110,7 +111,7 @@ impl SpawnCommand {
None
} else {
let builder = CommandBuilder::from_argv(self.prog);
- Some(builder)
+ Some(CommandSpec::from_command_builder(&builder))
},
command_dir: resolve_relative_cwd(self.cwd)?,
size,
diff --git a/wezterm/src/cli/split_pane.rs b/wezterm/src/cli/split_pane.rs
index 2bd7a472..04428ce1 100644
--- a/wezterm/src/cli/split_pane.rs
+++ b/wezterm/src/cli/split_pane.rs
@@ -1,6 +1,7 @@
use crate::cli::resolve_relative_cwd;
use clap::{Parser, ValueHint};
use mux::pane::PaneId;
+use mux::command_spec::{CommandSpec, CommandSpecExt};
use mux::tab::{SplitDirection, SplitRequest, SplitSize};
use portable_pty::cmdbuilder::CommandBuilder;
use std::ffi::OsString;
@@ -101,7 +102,7 @@ impl SplitPane {
None
} else {
let builder = CommandBuilder::from_argv(self.prog);
- Some(builder)
+ Some(CommandSpec::from_command_builder(&builder))
},
command_dir: resolve_relative_cwd(self.cwd)?,
move_pane_id: self.move_pane_id,