From f60c711769195145fae6ec9ae25d70cca2088598 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 3 Sep 2026 13:17:23 +0000 Subject: [PATCH] fix(sidebar): the rail hands the cursor back to the person's pane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bare `chief` opened the company with the cursor in the sidebar rail instead of in the pane the operator types into, so their first keystrokes went to furniture. Both rail-mint sites split without `-d` on purpose: every write that follows names a WINDOW, and tmux resolves a window target to its active pane, so the new rail has to be active while it is tagged and resized. Each frame now ENDS with `select-pane -l` at that window — the last pane, which a split makes the pane that was active before it, even when the split targeted some other pane. Pinned by argv tests at both sites (which fail if the selection is dropped or moved ahead of the tag) and by two real-tmux tests that ask the server which pane is active after the frame runs. Both real tests were run as controls with the selection removed and reproduce the operator's report exactly. Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 4 + DECISIONS.md | 1 + .../crates/chief-cli/src/actuate/interpret.rs | 14 ++ .../chief-cli/src/actuate/interpret/tests.rs | 118 +++++++++++++++++ apps/chiefd/crates/chief-cli/src/attach.rs | 124 +++++++++++++++++- 5 files changed, 257 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e2a92..c3356e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +- **fix(sidebar): the rail is built with the cursor and hands it straight back.** A bare `chief` opened the company with the cursor in the sidebar instead of in the person's pane, so the first thing the operator typed went to furniture. Both rail-mint sites — the attach frame (`attach.rs::rail_mint_argv`) and the actuator's repair batch (`actuate/interpret.rs`) — run `split-window` with no `-d`, which is deliberate: every write that follows names a WINDOW, and tmux resolves a window target to its active pane, so the new rail must be active while it is tagged and resized. The frame therefore ends, and only ends, with `select-pane -l` at that window: the last pane, which a split makes the pane that was active before it — measured on tmux 3.7c, and true even when the split targeted some other pane, so the cursor returns to the operator and never to the split target. + + Pinned at both sites by an argv test that fails if the selection is dropped or moved ahead of the tag, and by two REAL-tmux tests that ask the server which pane is active after the frame runs (`a_real_rail_mint_leaves_the_person_pane_active`, `real_rail_repair_leaves_the_person_pane_active_and_not_the_rail`). Both were run as controls with the selection removed and both fail there, reporting the rail as the active pane — which is the operator's report reproduced exactly. + - **chore(deps): the three open dependabot branches land as one batch, with the lockfile they never carried.** The npm minor-and-patch group (`@typescript-eslint/*` 8.67.0 to 8.68.0, `eslint` 10.9.0 to 10.9.1, `@types/react-dom` 19.2.4 to 19.2.5, `typebox` 1.3.16 to 1.3.18), `jsdom` 29.0.2 to 30.0.1, and `eslint-plugin-simple-import-sort` 12.1.1 to 14.0.0 are merged together on one branch, because three separate merges of the same lockfile serialize into three conflicts that say nothing. **Dependabot edited only the manifests.** Every one of its three commits touches `package.json` files and no `bun.lock`, and every CI job installs with `--frozen-lockfile` — so each of those branches was individually unmergeable and would have failed at the install step before running one test. The lockfile is regenerated once here, over all three bumps at the same time, and the frozen install is verified against it. **The instrument was checked against the lockfile, not remembered.** `eslint --version` reports 10.9.1 in the tree that lints, which is the check that separates a real lint result from a confident answer given by the wrong binary. diff --git a/DECISIONS.md b/DECISIONS.md index 30df4ab..11e58ca 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -111,3 +111,4 @@ - 2026-08-25 — CI has ONE tier. Every workspace member gates; there is no non-gating tier and no quarantine, so a suite is either run and required to pass or it does not exist. A suite that cannot hold the bar is fixed or deleted. Pinned by `excluded-suites-are-runnable.test.mjs`, which is what stops a suite excluded from the ordinary shards from quietly running nowhere. - 2026-08-25 — The licence is Apache-2.0, single: not MIT, not MIT/Apache dual, not source-available, and with a DCO rather than a CLA. The Rust dependency licence allowlist is permissive-only and names no denials. `apps/web` ships MARKED as a non-working example rather than deleted — it is the only worked example of the second host the daemon/client split exists for, so deleting the broken app destroys the reference implementation of the hardest part of the architecture. Relicensing costs nothing today with one rights holder and needs unanimous consent the moment there is a second contributor. Enforced by the LICENSE and NOTICE files and by `apps/chiefd/deny.toml`; there is no test, and this is the one entry that does not name one, deliberately — the decision is about a legal instrument, not about code behaviour. - 2026-08-25 — CHANGELOG.md and DECISIONS.md start FRESH in the public tree, and the private ledger is archived rather than published. Those two files had grown to about 16,800 lines of internal narrative — detailed incident write-ups, named hosts, and roughly thirty-six leaked machine names — written for the people who were in the room. The rejected alternative was a mass rewording of shipped entries through the `doc-append-only` guard's per-entry exception registry, which would have taught every future contributor that an append-only file may be reworded when the reason seems good enough. That is a repeal of the rule, not an exception to it. The same philosophy as the `plans/` ruling, applied to the same kind of content: the history is kept, and it is kept private. What still BINDS the code is carried forward as new dated entries below; `CLAUDE.md` and `AGENTS.md` already carry the organization model, the operator wake lease and the placement rule, and duplicating them here would create two sources for one rule. The guard treats this as a ONE-TIME reset, detected by the first line of this entry and of the changelog's, so ordinary append-only resumes from the very next commit with no exception left behind to rot. +- 2026-09-03 — The sidebar rail is furniture and never takes the operator's cursor. It is minted active on purpose — the tag and the resize that follow the split name a WINDOW, which tmux resolves to the active pane — so every mint frame ends with `select-pane -l`, restoring the pane that was active before the split. The rejected alternative was `split-window -d`, which cannot work without a second tmux invocation to name the pane the split has not reported yet, and a rail that is observable untagged is the gap that once put two rails in one window. Pinned by `the_rail_frame_hands_the_cursor_back_after_every_other_write` and `a_real_rail_mint_leaves_the_person_pane_active` (`attach.rs`) and by `a_repaired_rail_gives_the_cursor_back_after_it_is_tagged` and `real_rail_repair_leaves_the_person_pane_active_and_not_the_rail` (`actuate/interpret/tests.rs`). diff --git a/apps/chiefd/crates/chief-cli/src/actuate/interpret.rs b/apps/chiefd/crates/chief-cli/src/actuate/interpret.rs index e42bb0a..5040006 100644 --- a/apps/chiefd/crates/chief-cli/src/actuate/interpret.rs +++ b/apps/chiefd/crates/chief-cli/src/actuate/interpret.rs @@ -659,6 +659,20 @@ fn repair_session_rails_with( window.clone(), tags::SIDEBAR.into(), "1".into(), + ";".into(), + // AND THE CURSOR GOES BACK, LAST. A repair + // pass that mints a missing rail must not + // leave the operator typing into furniture. + // `-l` is the window's last pane, which a + // split makes the pane that was active before + // it — not the split target. It follows the + // tag because the tag resolves a WINDOW target + // to the active pane, which must still be the + // new rail. + "select-pane".into(), + "-l".into(), + "-t".into(), + window.clone(), ], }, ) diff --git a/apps/chiefd/crates/chief-cli/src/actuate/interpret/tests.rs b/apps/chiefd/crates/chief-cli/src/actuate/interpret/tests.rs index 859b044..5658d73 100644 --- a/apps/chiefd/crates/chief-cli/src/actuate/interpret/tests.rs +++ b/apps/chiefd/crates/chief-cli/src/actuate/interpret/tests.rs @@ -245,6 +245,14 @@ fn missing_sidebar_is_repaired_with_bare_chief_in_the_company_directory() { "@2", "@organization_sidebar", "1", + ";", + // And the batch ends by handing the cursor back to the pane the + // split took it from, so a repair never moves the operator into + // the sidebar. It is last because the tag above names a WINDOW. + "select-pane", + "-l", + "-t", + "@2", ], "the current sidebar verb takes no company argument and resolves the company from cwd, \ and the pane is tagged in the same command sequence that creates it" @@ -310,6 +318,55 @@ fn a_repaired_rail_is_never_observable_before_it_carries_its_tag() { ); } +/// A REPAIR PASS DOES NOT TAKE THE CURSOR AWAY FROM THE PERSON. +/// +/// The mint batch has no `-d`, so the new rail is active for the tag that +/// follows it. The batch therefore ends by giving the cursor back with +/// `select-pane -l` — the window's last pane, which the split makes the pane +/// that was active before it. Without it, a rail repaired under an operator +/// who is typing moves them into the sidebar mid-sentence. +#[test] +fn a_repaired_rail_gives_the_cursor_back_after_it_is_tagged() { + let scripted = ScriptedTmux::new([ + ScriptedReply::ok("@1\t%1\t1\n@2\t%2"), + ScriptedReply::ok(""), + ScriptedReply::ok(""), + ScriptedReply::ok("%9"), + ScriptedReply::ok(""), + ]) + .recording_viewport_authority(); + let exec = executor(scripted); + + repair_session_rails_with( + &exec, + &socket(), + "cobalt-session", + "/data/cobalt", + std::path::Path::new("/opt/chief/bin/chief"), + ) + .expect("the missing rail is repaired"); + + let calls = exec.tmux_host().runner().calls(); + let split = calls + .iter() + .find(|call| call.first().is_some_and(|verb| verb == "split-window")) + .expect("the mint batch"); + let commands: Vec<&[String]> = split.split(|arg| arg == ";").collect(); + assert_eq!( + commands.last().expect("the batch is not empty"), + &["select-pane".to_owned(), "-l".to_owned(), "-t".to_owned(), "@2".to_owned()], + "the batch ends by restoring the pane the split took the cursor from: {split:?}" + ); + let tag = commands + .iter() + .position(|command| command.iter().any(|arg| arg == "@organization_sidebar")) + .expect("the tag"); + assert!( + tag < commands.len() - 1, + "the tag names a WINDOW, so it must land while the rail is still active: {split:?}" + ); +} + #[test] fn failed_sidebar_split_still_refreshes_after_the_epoch_fence() { let scripted = ScriptedTmux::new([ @@ -1233,6 +1290,67 @@ fn real_viewport_repair_never_publishes_a_one_column_rail() { assert_eq!(remembered, "31", "viewport repair never writes the sidebar preference"); } +/// THE OPERATOR KEEPS THE CURSOR, PROVED AGAINST A REAL TMUX SERVER. +/// +/// The argv tests above pin the frame; only tmux can answer what the frame +/// DOES. A real window that is missing its rail is repaired here, and the pane +/// left active afterwards must be the person's pane and not the rail tmux made +/// active when it split. `remain-on-exit` keeps the rail pane after its +/// stand-in program exits, so the question this test asks stays askable. +#[test] +fn real_rail_repair_leaves_the_person_pane_active_and_not_the_rail() { + let raw = SystemTmuxRunner::default(); + let socket = Socket(format!("chiefd-rail-cursor-{}", std::process::id())); + let session = format!("chiefd-rail-cursor-{}", std::process::id()); + real_tmux_ok( + &raw, + &socket, + &["new-session", "-d", "-s", &session, "-x", "240", "-y", "56", "sleep", "120"], + ); + real_tmux_ok( + &raw, + &socket, + &["set-option", "-w", "-t", &session, "@organization_window_id", "executive"], + ); + real_tmux_ok(&raw, &socket, &["set-option", "-t", &session, "@organization_id", "cobalt"]); + real_tmux_ok(&raw, &socket, &["set-option", "-w", "-t", &session, "remain-on-exit", "on"]); + let person = real_tmux_ok(&raw, &socket, &["list-panes", "-t", &session, "-F", "#{pane_id}"]) + .trim() + .to_owned(); + + let exec = RealHostExecutor::new( + TmuxHost::new(raw, RecordingWaiter::default()), + ProcReader::default(), + ); + let repaired = repair_session_rails_with( + &exec, + &socket, + &session, + "/tmp", + std::path::Path::new("/bin/false"), + ); + let panes = real_tmux_ok( + exec.tmux_host().runner(), + &socket, + &[ + "list-panes", + "-t", + &session, + "-F", + "#{pane_id}\t#{pane_active}\t#{@organization_sidebar}", + ], + ); + real_tmux_ok(exec.tmux_host().runner(), &socket, &["kill-server"]); + + assert_eq!(repaired.expect("the rail is repaired"), 1, "one rail was missing: {panes}"); + let rows: Vec> = panes.lines().map(|line| line.split('\t').collect()).collect(); + assert_eq!(rows.len(), 2, "the person pane and its new rail: {panes}"); + let active: Vec<&str> = rows.iter().filter(|row| row[1] == "1").map(|row| row[0]).collect(); + assert_eq!(active, vec![person.as_str()], "the operator is left in their own pane: {panes}"); + let rail = rows.iter().find(|row| row[0] != person).expect("the minted rail"); + assert_eq!(rail[2], "1", "and the rail it did not move to is tagged: {panes}"); +} + /// A browser-like attached client must not publish tmux's proportional split. /// /// The old test accepted that bad frame and only checked that a later repair diff --git a/apps/chiefd/crates/chief-cli/src/attach.rs b/apps/chiefd/crates/chief-cli/src/attach.rs index 45d6910..0ac84db 100644 --- a/apps/chiefd/crates/chief-cli/src/attach.rs +++ b/apps/chiefd/crates/chief-cli/src/attach.rs @@ -760,9 +760,9 @@ fn viewport_manifest_survey( /// `split-window` starts the rail process, so a tag or resize sent in a later /// tmux invocation is already too late: the rail client can draw the transient /// PTY it received at birth. Tmux redraws after a command sequence, so stamp -/// the shared width, split at that width, tag the active new pane, and repeat -/// the exact pane width in ONE queue. The operator can then see only the final -/// frame. +/// the shared width, split at that width, tag the active new pane, repeat the +/// exact pane width, and hand the cursor back to the pane the operator was in +/// — all in ONE queue. The operator can then see only the final frame. fn rail_mint_argv( _session: &str, window: &str, @@ -800,6 +800,20 @@ fn rail_mint_argv( columns.to_string(), "-t".to_owned(), window.to_owned(), + ";".to_owned(), + // THE CURSOR GOES BACK, AND IT GOES BACK LAST. The rail is furniture; + // the person is the product. `split-window` left the rail active, so + // without this the operator opens their company typing into the + // sidebar. `-l` is the window's LAST pane, which after a split is the + // pane that was active before it — measured on tmux 3.7c, and true + // even when the split targeted some other pane. It is the final + // command of the frame on purpose: the tag and the resize above + // resolve a WINDOW target to its active pane, so a selection moved + // ahead of either would write them to the wrong pane. + "select-pane".to_owned(), + "-l".to_owned(), + "-t".to_owned(), + window.to_owned(), ] } @@ -3120,7 +3134,7 @@ mod tests { columns, ); let commands: Vec<&[String]> = argv.split(|arg| arg == ";").collect(); - assert_eq!(commands.len(), 3, "all writes belong to one tmux invocation: {argv:?}"); + assert_eq!(commands.len(), 4, "all writes belong to one tmux invocation: {argv:?}"); let mut rail_columns = None; let mut rail_tagged = false; @@ -3146,6 +3160,9 @@ mod tests { .flatten(); rail_columns = width; } + // The rail is built and then handed back; see the frame's + // own test below for why this one is last. + Some("select-pane") => {} other => panic!("unexpected simulated tmux command {other:?}: {command:?}"), } } @@ -3162,6 +3179,52 @@ mod tests { } } + /// THE OPERATOR LANDS ON THE PERSON, NOT ON THE FURNITURE. + /// + /// `split-window` has no `-d`, so the rail is the active pane the moment it + /// exists — which is what the tag and the resize above need, and which + /// also means a bare `chief` used to open with the cursor in the sidebar + /// instead of in the pane the operator types into. The frame gives it back + /// with `select-pane -l`: the window's last pane, which a split makes the + /// pane that was active before it. It must be the LAST command of the + /// frame — every write before it names a WINDOW, which tmux resolves to + /// the active pane, so a selection moved earlier would tag and resize the + /// wrong pane. + #[test] + fn the_rail_frame_hands_the_cursor_back_after_every_other_write() { + let argv = rail_mint_argv( + "org-acme_", + "@7", + Path::new("/tmp/acme"), + Path::new("/usr/bin/chief"), + 26, + ); + let commands: Vec<&[String]> = argv.split(|arg| arg == ";").collect(); + let last = commands.last().expect("the frame is not empty"); + assert_eq!( + last, + &["select-pane".to_owned(), "-l".to_owned(), "-t".to_owned(), "@7".to_owned()], + "the frame ends by restoring the pane the split took the cursor from: {argv:?}" + ); + assert_eq!( + commands + .iter() + .filter(|command| command.first().is_some_and(|v| v == "select-pane")) + .count(), + 1, + "exactly one selection, and it is that one: {argv:?}" + ); + // Both window-targeted writes still run while the rail is active. + let selection = commands.len() - 1; + for verb in ["split-window", "set-option", "resize-pane"] { + let at = commands + .iter() + .position(|command| command.first().is_some_and(|first| first == verb)) + .unwrap_or_else(|| panic!("the frame still carries {verb}: {argv:?}")); + assert!(at < selection, "{verb} must run before the cursor moves off the rail"); + } + } + #[test] fn viewport_hook_is_ordered_and_quotes_static_authority() { let surveyed = @@ -4441,6 +4504,59 @@ mod tests { let _ = tmux::run(&socket, &["kill-server"]); } + /// A REAL ATTACH LEAVES THE CURSOR ON THE PERSON. + /// + /// This is the operator's own report: a bare `chief` opened the company + /// with the cursor in the sidebar rather than in the pane they type into. + /// The argv test above pins the frame; only tmux can say what the frame + /// leaves active, so the mint frame is run here against a real server. + /// `remain-on-exit` keeps the rail pane after its stand-in program exits. + #[test] + fn a_real_rail_mint_leaves_the_person_pane_active() { + if !require_tmux() { + return; + } + let socket = unique_socket("attach-rail-cursor"); + let session = "org-attach-cursor_"; + start_session(&socket, session, &["-x", "240", "-y", "56", "sleep", "120"]); + assert!( + tmux::run(&socket, &["set-option", "-w", "-t", session, "remain-on-exit", "on"]).ok() + ); + let person = tmux::run(&socket, &["list-panes", "-t", session, "-F", "#{pane_id}"]) + .stdout + .trim() + .to_owned(); + let window = tmux::run(&socket, &["display-message", "-p", "-t", session, "#{window_id}"]) + .stdout + .trim() + .to_owned(); + + let argv = rail_mint_argv(session, &window, Path::new("/tmp"), Path::new("/bin/false"), 26); + let refs: Vec<&str> = argv.iter().map(String::as_str).collect(); + let minted = tmux::run(&socket, &refs); + assert!(minted.ok(), "the mint frame ran: {}", minted.diagnostic()); + + let panes = tmux::run( + &socket, + &[ + "list-panes", + "-t", + session, + "-F", + &format!("#{{pane_id}}\t#{{pane_active}}\t#{{{}}}", trust::tags::SIDEBAR), + ], + ) + .stdout; + let _ = tmux::run(&socket, &["kill-server"]); + + let rows: Vec> = panes.lines().map(|line| line.split('\t').collect()).collect(); + assert_eq!(rows.len(), 2, "the person pane and its new rail: {panes}"); + let active: Vec<&str> = rows.iter().filter(|row| row[1] == "1").map(|row| row[0]).collect(); + assert_eq!(active, vec![person.as_str()], "the operator keeps their own pane: {panes}"); + let rail = rows.iter().find(|row| row[0] != person).expect("the minted rail"); + assert_eq!(rail[2], "1", "and the rail it did not move to is tagged: {panes}"); + } + #[test] fn attach_rail_mint_refuses_after_the_captured_company_epoch_is_replaced() { if !require_tmux() {