Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mux/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ base64 = "0.22"
libc = "0.2"
tungstenite = { version = "0.24", default-features = false, features = ["handshake"] }
uds_windows = "1.2"
regex = "1"

[profile.release]
lto = "thin"
Expand Down
62 changes: 62 additions & 0 deletions mux/bindings/conformance/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,68 @@
"timeout_ms": 10000
}
]
},
{
"name": "implemented-verbs-json",
"steps": [
Comment on lines +139 to +141

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding a requires field for backward compatibility.

All eight commands in this fixture (run, wait-for, send-key, copy, ids, notify, list-agents, report-agent) are new in protocol v6. Without a requires field, the fixture will fail hard against older servers instead of skipping gracefully. The existing move-tab-same-position fixture sets "requires": { "commands": ["move-tab"] } for the same reason.

♻️ Suggested addition
     {
       "name": "implemented-verbs-json",
+      "requires": { "commands": ["run", "wait-for", "send-key", "copy", "ids", "notify", "list-agents", "report-agent"] },
       "steps": [
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
"name": "implemented-verbs-json",
"steps": [
{
"name": "implemented-verbs-json",
"requires": { "commands": ["run", "wait-for", "send-key", "copy", "ids", "notify", "list-agents", "report-agent"] },
"steps": [
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@mux/bindings/conformance/fixtures.json` around lines 139 - 141, Add a
requires field to the implemented-verbs-json fixture so it skips gracefully on
older servers. Update the fixture definition in fixtures.json to reference the
new protocol v6 command set using the same pattern as move-tab-same-position,
ensuring the fixture is gated by the relevant commands for run, wait-for,
send-key, copy, ids, notify, list-agents, and report-agent.

{
"type": "command",
"request": { "id": 1, "cmd": "run", "command": "printf 'cmux-run-marker\\n'; cat", "name": "conf-run", "cols": 80, "rows": 24 },
"expect": { "id": 1, "ok": true },
"match": "partial",
"bind": { "surface0": "data.surface" }
},
{
"type": "wait_contains",
"request": { "id": 2, "cmd": "copy", "surface": "$surface0", "mode": "screen" },
"path": "data.text",
"contains": "cmux-run-marker",
"timeout_ms": 10000
},
{
"type": "command",
"request": { "id": 3, "cmd": "wait-for", "surface": "$surface0", "pattern": "cmux-run-marker", "timeout_ms": 5000 },
"expect": { "id": 3, "ok": true, "data": { "matched": true } },
"match": "partial"
},
{
"type": "command",
"request": { "id": 4, "cmd": "ids", "kind": "surface" },
"expect": { "id": 4, "ok": true },
"match": "partial"
},
{
"type": "command",
"request": { "id": 5, "cmd": "notify", "title": "Build", "body": "ok", "level": "info", "surface": "$surface0" },
"expect": { "id": 5, "ok": true },
"match": "partial"
},
{
"type": "command",
"request": { "id": 6, "cmd": "report-agent", "surface": "$surface0", "state": "working", "source": "socket", "session": "conf" },
"expect": { "id": 6, "ok": true, "data": { "state": "working", "source": "socket", "session": "conf" } },
"match": "partial"
},
{
"type": "command",
"request": { "id": 7, "cmd": "list-agents", "surface": "$surface0", "state": "working" },
"expect": { "id": 7, "ok": true, "data": { "agents": [ { "surface": "$surface0", "state": "working", "source": "socket", "session": "conf" } ] } },
"match": "partial"
},
{
"type": "command",
"request": { "id": 8, "cmd": "send-key", "surface": "$surface0", "keys": ["h", "i", "enter"] },
"expect": { "id": 8, "ok": true, "data": {} },
"match": "partial"
},
{
"type": "wait_contains",
"request": { "id": 9, "cmd": "copy", "surface": "$surface0", "mode": "scrollback" },
"path": "data.text",
"contains": "hi",
"timeout_ms": 10000
}
]
}
]
}
8 changes: 8 additions & 0 deletions mux/bindings/conformance/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ def dispatch(client: CmuxClient, cmd: str, params: Dict[str, Any]) -> Any:
"move-tab": client.move_tab,
"move-workspace": client.move_workspace,
"scroll-surface": client.scroll_surface,
"wait-for": lambda **kw: client._request("wait-for", **kw),
"run": lambda **kw: client._request("run", **kw),
"send-key": lambda **kw: client._request("send-key", **kw),
"copy": lambda **kw: client._request("copy", **kw),
"ids": lambda **kw: client._request("ids", **kw),
"notify": lambda **kw: client._request("notify", **kw),
"list-agents": lambda **kw: client._request("list-agents", **kw),
"report-agent": lambda **kw: client._request("report-agent", **kw),
}
if cmd not in mapping:
raise FixtureFailure(f"unsupported fixture command {cmd}")
Expand Down
149 changes: 148 additions & 1 deletion mux/crates/ghostty-vt/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,132 @@ impl std::ops::BitOr for Mods {
}
}

fn physical_key_for_char(c: char) -> sys::GhosttyKey {
match c.to_ascii_lowercase() {
'a' => sys::GHOSTTY_KEY_A,
'b' => sys::GHOSTTY_KEY_B,
'c' => sys::GHOSTTY_KEY_C,
'd' => sys::GHOSTTY_KEY_D,
'e' => sys::GHOSTTY_KEY_E,
'f' => sys::GHOSTTY_KEY_F,
'g' => sys::GHOSTTY_KEY_G,
'h' => sys::GHOSTTY_KEY_H,
'i' => sys::GHOSTTY_KEY_I,
'j' => sys::GHOSTTY_KEY_J,
'k' => sys::GHOSTTY_KEY_K,
'l' => sys::GHOSTTY_KEY_L,
'm' => sys::GHOSTTY_KEY_M,
'n' => sys::GHOSTTY_KEY_N,
'o' => sys::GHOSTTY_KEY_O,
'p' => sys::GHOSTTY_KEY_P,
'q' => sys::GHOSTTY_KEY_Q,
'r' => sys::GHOSTTY_KEY_R,
's' => sys::GHOSTTY_KEY_S,
't' => sys::GHOSTTY_KEY_T,
'u' => sys::GHOSTTY_KEY_U,
'v' => sys::GHOSTTY_KEY_V,
'w' => sys::GHOSTTY_KEY_W,
'x' => sys::GHOSTTY_KEY_X,
'y' => sys::GHOSTTY_KEY_Y,
'z' => sys::GHOSTTY_KEY_Z,
'0' => sys::GHOSTTY_KEY_DIGIT_0,
'1' => sys::GHOSTTY_KEY_DIGIT_1,
'2' => sys::GHOSTTY_KEY_DIGIT_2,
'3' => sys::GHOSTTY_KEY_DIGIT_3,
'4' => sys::GHOSTTY_KEY_DIGIT_4,
'5' => sys::GHOSTTY_KEY_DIGIT_5,
'6' => sys::GHOSTTY_KEY_DIGIT_6,
'7' => sys::GHOSTTY_KEY_DIGIT_7,
'8' => sys::GHOSTTY_KEY_DIGIT_8,
'9' => sys::GHOSTTY_KEY_DIGIT_9,
' ' => sys::GHOSTTY_KEY_SPACE,
'`' => sys::GHOSTTY_KEY_BACKQUOTE,
'\\' => sys::GHOSTTY_KEY_BACKSLASH,
'[' => sys::GHOSTTY_KEY_BRACKET_LEFT,
']' => sys::GHOSTTY_KEY_BRACKET_RIGHT,
',' => sys::GHOSTTY_KEY_COMMA,
'=' => sys::GHOSTTY_KEY_EQUAL,
'-' => sys::GHOSTTY_KEY_MINUS,
'.' => sys::GHOSTTY_KEY_PERIOD,
'\'' => sys::GHOSTTY_KEY_QUOTE,
';' => sys::GHOSTTY_KEY_SEMICOLON,
'/' => sys::GHOSTTY_KEY_SLASH,
_ => sys::GHOSTTY_KEY_UNIDENTIFIED,
}
}

/// Parse a lower-case socket/CLI key chord into a Ghostty encoder input.
pub fn key_input_from_chord(chord: &str) -> Option<KeyInput> {
let mut mods = Mods::default();
let mut key_name = None;
for part in chord.split('+') {
match part {
"ctrl" | "control" => mods = mods | Mods::CTRL,
"alt" | "option" => mods = mods | Mods::ALT,
"shift" => mods = mods | Mods::SHIFT,
"" => return None,
other => {
if key_name.is_some() {
return None;
}
key_name = Some(other);
}
}
}
let key_name = key_name?;
let mut input = KeyInput { mods, action: Some(KeyAction::Press), ..Default::default() };
match key_name {
"enter" | "return" => input.key = sys::GHOSTTY_KEY_ENTER,
"tab" => input.key = sys::GHOSTTY_KEY_TAB,
"backtab" => {
input.key = sys::GHOSTTY_KEY_TAB;
input.mods = input.mods | Mods::SHIFT;
}
"escape" | "esc" => input.key = sys::GHOSTTY_KEY_ESCAPE,
"backspace" => input.key = sys::GHOSTTY_KEY_BACKSPACE,
"delete" => input.key = sys::GHOSTTY_KEY_DELETE,
"insert" => input.key = sys::GHOSTTY_KEY_INSERT,
"up" => input.key = sys::GHOSTTY_KEY_ARROW_UP,
"down" => input.key = sys::GHOSTTY_KEY_ARROW_DOWN,
"left" => input.key = sys::GHOSTTY_KEY_ARROW_LEFT,
"right" => input.key = sys::GHOSTTY_KEY_ARROW_RIGHT,
"home" => input.key = sys::GHOSTTY_KEY_HOME,
"end" => input.key = sys::GHOSTTY_KEY_END,
"pageup" => input.key = sys::GHOSTTY_KEY_PAGE_UP,
"pagedown" => input.key = sys::GHOSTTY_KEY_PAGE_DOWN,
"space" => {
input.key = sys::GHOSTTY_KEY_SPACE;
input.unshifted_codepoint = ' ' as u32;
if !mods.contains(Mods::CTRL) {
input.utf8 = " ".to_string();
}
}
name if name.len() == 1 => {
let c = name.chars().next()?;
input.key = physical_key_for_char(c);
if input.key == sys::GHOSTTY_KEY_UNIDENTIFIED {
return None;
}
input.unshifted_codepoint = c.to_ascii_lowercase() as u32;
if !mods.contains(Mods::CTRL) {
input.utf8 = c.to_string();
if mods.contains(Mods::SHIFT) {
input.consumed_mods = Mods::SHIFT;
}
}
}
Comment on lines +138 to +151

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

set -euo pipefail

printf '\n== key.rs relevant section ==\n'
sed -n '100,220p' mux/crates/ghostty-vt/src/key.rs

printf '\n== tests in key.rs / nearby ==\n'
rg -n "send-key|ctrl\\+c|enter|up|invalid chord|shift\\+" mux/crates/ghostty-vt/src -n

printf '\n== all references to consumed_mods / unshifted_codepoint / utf8 ==\n'
rg -n "consumed_mods|unshifted_codepoint|utf8 =" mux/crates/ghostty-vt/src

printf '\n== physical_key_for_char definition ==\n'
rg -n "fn physical_key_for_char|physical_key_for_char\\(" mux/crates/ghostty-vt/src -n

Repository: manaflow-ai/cmux

Length of output: 7853


🏁 Script executed:

set -euo pipefail

printf '\n== physical_key_for_char ==\n'
sed -n '1,90p' mux/crates/ghostty-vt/src/key.rs

printf '\n== tests section ==\n'
sed -n '260,360p' mux/crates/ghostty-vt/src/key.rs

printf '\n== encoder-side semantics in Rust wrapper ==\n'
sed -n '200,250p' mux/crates/ghostty-vt/src/key.rs

printf '\n== search for keyboard protocol docs/comments in repo ==\n'
rg -n "unshifted_codepoint|consumed_mods|shift.*utf8|SHIFT.*utf8|GhosttyKeyEvent|kitty keyboard protocol|keyboard protocol" mux ghostty -g '!**/target/**'

Repository: manaflow-ai/cmux

Length of output: 25215


🏁 Script executed:

set -euo pipefail

printf '\n== mux-tui key parser ==\n'
sed -n '70,120p' mux/crates/mux-tui/src/keys.rs

printf '\n== key_encode.zig: shift / utf8 handling ==\n'
sed -n '730,770p' ghostty/src/input/key_encode.zig
sed -n '1490,1565p' ghostty/src/input/key_encode.zig
sed -n '2010,2055p' ghostty/src/input/key_encode.zig
sed -n '2160,2285p' ghostty/src/input/key_encode.zig

printf '\n== key.zig event semantics ==\n'
sed -n '1,120p' ghostty/src/input/key.zig

Repository: manaflow-ai/cmux

Length of output: 16589


🏁 Script executed:

set -euo pipefail

printf '\n== key_input_from_chord definition and docs ==\n'
rg -n -A4 -B4 "fn key_input_from_chord|send-key|chord" mux/crates/ghostty-vt/src/key.rs mux/crates/mux-tui/src/keys.rs mux/spec/commands.md ghostty/include/ghostty/vt/key.h ghostty/include/ghostty/vt/README.md

printf '\n== any docs/examples mentioning shift+a or shifted symbols ==\n'
rg -n "shift\\+a|shift\\+1|shift\\+,|shift\\+<|shift\\+letter|shifted symbol|shifted" mux ghostty -g '!**/target/**'

Repository: manaflow-ai/cmux

Length of output: 5642


Shifted single-character chords need shifted UTF-8.
shift+a hits this branch with c = 'a', so it currently emits "a" while also marking SHIFT as consumed. That drops the shift for letters; utf8 should be "A" there, with unshifted_codepoint staying a. The same parser in mux/crates/mux-tui/src/keys.rs has the same behavior. Shifted symbols like shift+1 and shift+, still need explicit mapping if send-key is expected to support them. Add coverage for shift+a and one shifted symbol.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@mux/crates/ghostty-vt/src/key.rs` around lines 138 - 151, The
single-character chord handling in the key parsing path is emitting unshifted
UTF-8 for shifted letters, so `shift+a` is treated like plain `a` while `SHIFT`
is consumed. Update the single-character branch in `physical_key_for_char`
handling so letters preserve shifted output in `input.utf8` when `Mods::SHIFT`
is present, while keeping `input.unshifted_codepoint` lowercase and only
consuming shift where appropriate. Apply the same fix in the matching parser in
`keys.rs`, and add tests covering `shift+a` plus one shifted symbol case to
confirm the behavior.

name if name.starts_with('f') => {
let n = name[1..].parse::<u32>().ok()?;
if !(1..=24).contains(&n) {
return None;
}
input.key = sys::GHOSTTY_KEY_F1 + (n as sys::GhosttyKey - 1);
}
_ => return None,
}
Some(input)
}

/// A single key event to encode.
#[derive(Debug, Clone, Default)]
pub struct KeyInput {
Expand Down Expand Up @@ -151,7 +277,28 @@ impl Drop for KeyEncoder {
#[cfg(test)]
mod tests {
use super::*;
use crate::Callbacks;
use crate::{Callbacks, Terminal};

#[test]
fn chord_parser_encodes_common_keys() {
let term = Terminal::new(80, 24, 100, Callbacks::default()).unwrap();
let mut encoder = KeyEncoder::new().unwrap();
encoder.sync_from_terminal(&term);

let mut out = Vec::new();
encoder.encode(&key_input_from_chord("ctrl+c").unwrap(), &mut out).unwrap();
assert_eq!(out, vec![0x03]);

out.clear();
encoder.encode(&key_input_from_chord("enter").unwrap(), &mut out).unwrap();
assert_eq!(out, b"\r");

out.clear();
encoder.encode(&key_input_from_chord("up").unwrap(), &mut out).unwrap();
assert!(!out.is_empty());

assert!(key_input_from_chord("not-a-key").is_none());
}

#[test]
fn encodes_ctrl_c() {
Expand Down
2 changes: 1 addition & 1 deletion mux/crates/ghostty-vt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod terminal;
/// Raw bindings, re-exported for key/mode constants.
pub use ghostty_vt_sys as sys;

pub use key::{KeyAction, KeyEncoder, KeyInput, Mods};
pub use key::{key_input_from_chord, KeyAction, KeyEncoder, KeyInput, Mods};
pub use render::{Cell, ColorSpec, CursorInfo, CursorShape, Dirty, RenderState};
pub use terminal::{Callbacks, NotifyFn, PtyWriteFn, Rgb, Screen, Scrollbar, Terminal};

Expand Down
1 change: 1 addition & 0 deletions mux/crates/mux-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ serde_json.workspace = true
anyhow.workspace = true
base64.workspace = true
libc.workspace = true
regex.workspace = true

[target.'cfg(windows)'.dependencies]
uds_windows.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion mux/crates/mux-core/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub(crate) fn new_surface(
let capture_scale = capture_scale_for(pixel_w, pixel_h, capture_options);
let capture_pixels = scaled_pixels(pixel_w, pixel_h, capture_scale);
Arc::new(Surface::Browser(BrowserSurface {
meta: SurfaceMeta { id, name: Mutex::new(None) },
meta: SurfaceMeta { id, name: Mutex::new(None), selection: Mutex::new(None) },
session: Mutex::new(None),
state: Mutex::new(BrowserState {
latest_frame: None,
Expand Down
5 changes: 4 additions & 1 deletion mux/crates/mux-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ pub use layout::{
SplitEdge, SplitResize,
};
pub use model::{Node, Pane, Screen, State, Workspace};
pub use mux::{Mux, MuxEvent};
pub use mux::{
AgentRecord, AgentSource, AgentState, Mux, MuxEvent, NotificationEvent, NotificationLevel,
RunPlacement, SurfaceNotification,
};
pub use short_id::assign_short_ids;
pub use surface::{
AttachFrame, AttachStream, BrowserAttachState, BrowserFrame, BrowserFrameStream, BrowserSource,
Expand Down
Loading
Loading