From e0eef75a13894721596cf266f2243f50921868f6 Mon Sep 17 00:00:00 2001 From: Simon Klee Date: Wed, 18 Nov 2026 14:20:38 +0100 Subject: [PATCH] fix(cli-rs): reserve no row for a slot claim before its first tree A TypeScript plugin's slot claim showed a one-row placeholder until the JS host sent its first tree. A claim that draws nothing, such as the anomaly.internal plugin's app claims that only add key bindings, so lifted the session column a row per claim for a few frames as the plugin loaded, then dropped it back. TS draws a slot's claim in the frame that mounts it, so a slot mount whose key has shown nothing now reserves nothing; transcript parts keep their one row. A hidden root also reports no rows as the height its key had, so a remount does not reserve the rows of the placeholder it replaced. --- .../cli-rs/crates/plugin/src/pipe/guest.rs | 8 ++-- packages/cli-rs/crates/plugin/src/pipe/mod.rs | 4 +- packages/cli-rs/crates/plugin/src/surface.rs | 3 +- .../crates/tui/tests/all/plugin_compat.rs | 48 +++++++++++++++++++ 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/packages/cli-rs/crates/plugin/src/pipe/guest.rs b/packages/cli-rs/crates/plugin/src/pipe/guest.rs index 07be28816d7..94ef2f0f846 100644 --- a/packages/cli-rs/crates/plugin/src/pipe/guest.rs +++ b/packages/cli-rs/crates/plugin/src/pipe/guest.rs @@ -1373,7 +1373,7 @@ impl surface::Viewer for Viewer { let mut mounts = self.mounts.borrow_mut(); let mount = mounts.get_mut(id)?; mount.shown = true; - let height = self.heights.borrow().get(&id.key).copied().unwrap_or(1); + let height = self.heights.borrow().get(&id.key).copied().unwrap_or(0); return Some(Viewed { node: Some(placeholder(height)), memo: Some(0), stand_in: true }); } // The height it was laid out at, not the input's, which stands in the screen's before a solve (review carbon-7). @@ -1451,7 +1451,7 @@ impl surface::Viewer for Viewer { } if !mount.shown { mount.shown = true; - let height = self.heights.borrow().get(&id.key).copied().unwrap_or(1); + let height = self.heights.borrow().get(&id.key).copied().unwrap_or(u16::from(viewing.input.slot.is_none())); let _ = host; return Some(Viewed { node: Some(placeholder(height)), memo: Some(0), stand_in: true }); } @@ -1731,7 +1731,9 @@ fn digest(part: &opencode_plugin_abi::claim::Part) -> u64 { hashing.0.finish() } -/// What a mount shows before the JS host's first tree: the rows its key had, or one (review F1). +/// What a mount shows before the JS host's first tree: the rows its key had, else one for a transcript part (review F1) +/// and none for a slot. TS draws a slot's claim in the frame that mounts it, and a claim that draws nothing there, such +/// as one that only adds key bindings, would otherwise push the slot's neighbours by a row until its tree arrives. fn placeholder(height: u16) -> v2::Node { let layout = opencode_plugin_abi::Layout { height: Some(opencode_plugin_abi::Width::Cells(height)), diff --git a/packages/cli-rs/crates/plugin/src/pipe/mod.rs b/packages/cli-rs/crates/plugin/src/pipe/mod.rs index b8ffc4358af..cb3ce5bc8e1 100644 --- a/packages/cli-rs/crates/plugin/src/pipe/mod.rs +++ b/packages/cli-rs/crates/plugin/src/pipe/mod.rs @@ -7,8 +7,8 @@ //! plugin, as on the other carriers. //! - **Trees** are revisions of a mount ([`proto::Revision`]): a generation (the mount's), a base, a new revision and a //! layout epoch. A mount has at most one tree in flight: the host adopts or refuses it, says so, and the JS host -//! sends the next. A surface shows a whole adopted revision, a placeholder that keeps the room its key had, or the -//! fallback; never part of one. +//! sends the next. A surface shows a whole adopted revision, a placeholder that keeps the room its key had (none for +//! a slot's first mount), or the fallback; never part of one. //! - **Reads** are snapshots the host pushes for what the plugin watches, before the event that may read them. //! - **Hold:** a command that declares it holds the keys typed after it until its handler returned, or 50 ms. //! - **Supervision** ([`child`]): bounded queues, a hang rule on acknowledgements, a memory budget, cleanup of the diff --git a/packages/cli-rs/crates/plugin/src/surface.rs b/packages/cli-rs/crates/plugin/src/surface.rs index 5280dd4c25f..64f35194e1e 100644 --- a/packages/cli-rs/crates/plugin/src/surface.rs +++ b/packages/cli-rs/crates/plugin/src/surface.rs @@ -1055,7 +1055,8 @@ impl Surface { release: &mut release, kept: &kept, held: 0, - laid: self.laid.get().then(|| self.root.rect().height as u16), + // A hidden root takes no rows; its rect keeps the height of the last solve that showed it. + laid: self.laid.get().then(|| if self.root.is_visible() { self.root.rect().height as u16 } else { 0 }), }; let viewed = self.viewer.view(host, viewing); *self.viewed.borrow_mut() = input; diff --git a/packages/cli-rs/crates/tui/tests/all/plugin_compat.rs b/packages/cli-rs/crates/tui/tests/all/plugin_compat.rs index d364c8c19c3..3b0f48ebe37 100644 --- a/packages/cli-rs/crates/tui/tests/all/plugin_compat.rs +++ b/packages/cli-rs/crates/tui/tests/all/plugin_compat.rs @@ -276,6 +276,54 @@ fn a_batch_of_a_closed_mount_moves_nothing_where_the_activations_would() { assert_eq!(focus("pf.new").as_deref(), Some("same"), "the new mount's own focus did not apply"); } +// Expected (open-jump): a slot claim that draws nothing, here one that only adds a key binding as the `anomaly.internal` +// plugin's `app` claim does, moves no row while the JS host loads it, on Home and on a session: TS draws it in the +// frame that mounts it. The placeholder of a slot mount whose key had shown nothing took a row until the first tree +// came, which lifted the prompt and its footer a row for each such claim for some frames, then dropped them back. +#[test] +fn a_slot_claim_that_draws_nothing_moves_no_row_while_it_loads() { + let Some(config) = config() else { return }; + let footer = |screen: &str| screen.lines().position(|line| line.contains("ctrl+p commands")); + for route in [Route::Home, support::session_route("ses_a")] { + let root = opencode_util::temp::tempdir().unwrap(); + let plugin = root.path().join("config/plugins/keys"); + std::fs::create_dir_all(&plugin).unwrap(); + std::fs::write(plugin.join("tui.ts"), KEYS).unwrap(); + let server = support::Fake::new(|seen| support::base(seen, support::DIRECTORY)); + let deps = Deps { route: route.clone(), ..support::deps(Arc::new(server)) }; + let harness = support::mount(80, 24, deps); + let settled = footer(&harness.wait_for("ctrl+p commands")); + let external = + External { config_dir: root.path().join("config"), cwd: root.path().to_path_buf(), dev: Vec::new() }; + external_with(&harness.tui, external, Some(config.clone())); + let pipe = Pipe { harness, root }; + let (app, tui) = (&pipe.harness.app, &pipe.harness.tui); + pipe.active("example.keys"); + let frames = std::cell::RefCell::new(Vec::new()); + let registered = || tui.keymap.commands().iter().any(|command| command.id == "keys.toggle"); + pipe.harness.wait("the claim drew", || { + app.advance(Duration::from_millis(1)); + frames.borrow_mut().push(app.text()); + registered() && pipe.scripts().idle() + }); + pipe.settle(); + frames.borrow_mut().push(app.text()); + for frame in frames.borrow().iter() { + assert_eq!(footer(frame), settled, "{route:?}: a frame moved the prompt's footer:\n{frame}"); + assert!(!frame.lines().any(|line| line.trim() == "…"), "{route:?}: a placeholder row showed:\n{frame}"); + } + } +} + +/// The probe of the open-jump row: an `app` slot claim that draws nothing and adds the command `keys.toggle`. +const KEYS: &str = r#"export default { id: "example.keys", setup(api) { + api.ui.slot({ append: "app", render: () => { + api.keymap.layer(() => ({ commands: [{ id: "keys.toggle", title: "Toggle keys", run() {} }] })) + return null + } }) +} } +"#; + /// The TUI with the raw carrier plugin `example.` of `source`, active. fn raw(config: Config, name: &str, source: &str) -> Pipe { let root = opencode_util::temp::tempdir().unwrap();