Repository navigation
mux: implement the 8 proposed protocol-6 commands (wait-for, run, send-key, copy, ids, notify, list-agents, report-agent) #7584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 -nRepository: 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.zigRepository: 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. 🤖 Prompt for AI Agents |
||
| 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 { | ||
|
|
@@ -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() { | ||
|
|
||
There was a problem hiding this comment.
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
requiresfield 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 arequiresfield, the fixture will fail hard against older servers instead of skipping gracefully. The existingmove-tab-same-positionfixture 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
🤖 Prompt for AI Agents