The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
hn 0.1.30: hn with no terminal watches the desk's agents and never resizes them (#1342)
lingrd81ebbc52b341
diff --git a/cli/src/lib/terminalStreamManager.spec.ts b/cli/src/lib/terminalStreamManager.spec.tsindex 93f6b1602..5af84afd5 100644--- a/cli/src/lib/terminalStreamManager.spec.ts+++ b/cli/src/lib/terminalStreamManager.spec.ts@@ -867,6 +867,119 @@ describe('TerminalStreamManager', () => {expect(ready?.payload).not.toHaveProperty('heldBy')})+ // hn with no terminal (its server, kept for the sessions a closed window left) reads every pane of the desk. On+ // 2026-10-14 it reopened first after each daemon restart, took the terminals at its 80x24 layout and left the+ // window the person was using watching a shrunken agent until they typed. It opens with `watch: true` now.+ describe('a watch-only open', () => {+ let readOnlyOpens: boolean[]+ beforeEach(() => {+ readOnlyOpens = []+ terminals = {+ openStream: async (_session: RegisteredSession, _size: unknown, nextSink: TerminalStreamSink, readOnly?: boolean) => {+ sink = nextSink+ readOnlyOpens.push(readOnly === true)+ return { state: 'succeeded' as const, value: stream }+ },+ } as unknown as TerminalBackendCoordinator+ manager = newManager()+ })++ const ready = (connId: string) => sent.findLast((frame) => frame.connId === connId && frame.type === 'terminal_ready')!++ it('watches a terminal nobody holds: tmux attaches read-only, so the agent keeps its size, and nothing is typed', async () => {+ await manager.handleFrame('hn-headless', 'terminal_open', {+ requestId: 'open-1', protocolVersion: 3, agentId: 'agent-1', cols: 37, rows: 22, takeover: false, watch: true,+ client: { kind: 'tui', name: 'Mac Auto terminal' },+ })+ expect(ready('hn-headless').payload.readOnly).toBe(true)+ expect(ready('hn-headless').payload).not.toHaveProperty('heldBy')+ expect(readOnlyOpens).toEqual([true])+ const streamId = ready('hn-headless').payload.streamId as string+ await manager.handleFrame('hn-headless', 'terminal_resize', { streamId, resizeSeq: 1, cols: 30, rows: 10 })+ expect(sent.at(-1)?.payload.code).toBe('VIEW_ONLY')+ expect(stream.sizes).toEqual([])+ })++ it('is not anyone holding it: a window that reconnects politely beside it takes the terminal, and is told of no holder', async () => {+ // After a daemon restart, each in turn: hn with no terminal is back first, then a window with a person in it+ // (hn's, the desktop's, the phone's) reconnects the way it always does after its first open, without the key.+ for (const [connId, kind] of [['hn-window', 'tui'], ['desktop-1', 'desktop'], ['phone-1', 'phone']] as const) {+ await manager.closeConnection('hn-headless')+ await manager.handleFrame('hn-headless', 'terminal_open', {+ requestId: 'open-headless', protocolVersion: 3, agentId: 'agent-1', cols: 37, rows: 22, takeover: false, watch: true,+ client: { kind: 'tui', name: 'Mac Auto terminal' },+ })+ expect(ready('hn-headless').payload.readOnly).toBe(true)+ sent.length = 0+ readOnlyOpens.length = 0+ await manager.handleFrame(connId, 'terminal_open', {+ requestId: `open-${connId}`, protocolVersion: 3, agentId: 'agent-1', cols: 99, rows: 55, takeover: false,+ client: { kind, name: connId },+ })+ expect(ready(connId).payload.readOnly).toBe(false)+ expect(ready(connId).payload).not.toHaveProperty('heldBy')+ // tmux attaches it as the controller, at its own size.+ expect(readOnlyOpens).toEqual([false])+ // The watcher goes as any does when a terminal changes hands, and opens again on the new size.+ expect(sent.find((frame) => frame.connId === 'hn-headless' && frame.type === 'terminal_closed')?.payload)+ .toMatchObject({ code: 'TERMINAL_TAKEN_OVER', takenBy: { kind, name: connId } })+ await manager.closeConnection(connId)+ }+ })++ it('leaves the window beside it typing and resizing', async () => {+ await manager.handleFrame('hn-headless', 'terminal_open', {+ requestId: 'open-1', protocolVersion: 3, agentId: 'agent-1', cols: 37, rows: 22, takeover: false, watch: true,+ })+ await manager.handleFrame('desktop-1', 'terminal_open', {+ requestId: 'open-2', protocolVersion: 3, agentId: 'agent-1', cols: 120, rows: 40, takeover: false,+ })+ const streamId = ready('desktop-1').payload.streamId as string+ await manager.handleFrame('desktop-1', 'terminal_resize', { streamId, resizeSeq: 1, cols: 100, rows: 30 })+ expect(stream.sizes).toEqual([{ cols: 100, rows: 30 }])+ await manager.handleBinary('desktop-1', { kind: TerminalBinaryKind.input, streamId, seq: 0, compressed: false, bytes: Buffer.from('ok') })+ expect(Buffer.from(stream.writes[0]).toString()).toBe('ok')+ })++ it('leaves a client already driving the terminal alone, and a polite open beside both still watches that client', async () => {+ await manager.handleFrame('desktop-1', 'terminal_open', {+ requestId: 'open-1', protocolVersion: 3, agentId: 'agent-1', cols: 120, rows: 40,+ client: { kind: 'desktop', name: 'MacBookPro2021.local' },+ })+ await manager.handleFrame('hn-headless', 'terminal_open', {+ requestId: 'open-2', protocolVersion: 3, agentId: 'agent-1', cols: 37, rows: 22, takeover: false, watch: true,+ client: { kind: 'tui', name: 'Mac Auto terminal' },+ })+ expect(sent.some((frame) => frame.connId === 'desktop-1' && frame.type === 'terminal_closed')).toBe(false)+ expect(ready('hn-headless').payload).toMatchObject({ readOnly: true, heldBy: { kind: 'desktop', name: 'MacBookPro2021.local' } })+ // The phone's pager guess, beside the desktop and the watch-only stream: the desktop's, named as it.+ await manager.handleFrame('phone-1', 'terminal_open', {+ requestId: 'open-3', protocolVersion: 3, agentId: 'agent-1', cols: 40, rows: 20, takeover: false,+ client: { kind: 'phone', name: 'iPhone 15' },+ })+ expect(ready('phone-1').payload).toMatchObject({ readOnly: true, heldBy: { kind: 'desktop', name: 'MacBookPro2021.local' } })+ expect(readOnlyOpens).toEqual([false, true, true])+ })++ it('is closed by a takeover like any watcher, so it opens again on the size the new holder gave the pane', async () => {+ await manager.handleFrame('hn-headless', 'terminal_open', {+ requestId: 'open-1', protocolVersion: 3, agentId: 'agent-1', cols: 37, rows: 22, takeover: false, watch: true,+ })+ await manager.handleFrame('phone-1', 'terminal_open', {+ requestId: 'open-2', protocolVersion: 3, agentId: 'agent-1', cols: 40, rows: 20,+ client: { kind: 'phone', name: 'iPhone 15' },+ })+ expect(sent.find((frame) => frame.connId === 'hn-headless' && frame.type === 'terminal_closed')?.payload)+ .toMatchObject({ code: 'TERMINAL_TAKEN_OVER', takenBy: { kind: 'phone', name: 'iPhone 15' } })+ expect(ready('phone-1').payload.readOnly).toBe(false)+ })++ it('is advertised, so a client can tell a daemon that would ignore the key', async () => {+ await manager.handleFrame('web-1', 'terminal_capabilities', { requestId: 'r1' })+ expect((sent.at(-1)?.payload.features as Record<string, unknown>).watchOnly).toBe(true)+ })+ })+it('falls back to what the daemon can say about a silent winner, and says nothing over a bad claim', async () => {manager = newManager({describeClient: (connId) => connId === 'local-2' ? { kind: 'desktop', name: 'This Mac' } : null,diff --git a/cli/src/lib/terminalStreamManager.ts b/cli/src/lib/terminalStreamManager.tsindex 81027844b..1686a99e9 100644--- a/cli/src/lib/terminalStreamManager.ts+++ b/cli/src/lib/terminalStreamManager.ts@@ -118,6 +118,9 @@ interface ActiveStream {/** A stream opened as a WATCHER: it renders, but it never took the control lease and its input is* refused. See the `takeover: false` branch of `open()`. */watching: boolean+ /** A watcher by its own ask (`watch: true` on open): a client with no person in front of it — hn+ * with no terminal — reading the pane. It holds nothing, so no other open is answered as if it did. */+ watchOnly: booleanagentId: stringengineId: stringplacementKey: string@@ -395,6 +398,9 @@ export class TerminalStreamManager {// client has to see this before relying on it: a CLI that predates it ignores the key and// takes the terminal over like any other open, which is the one thing the key is for.noTakeover: !this.deps.readOnly,+ // `terminal_open` honours `watch: true`: always a watcher, even of a terminal nobody holds,+ // and never counted as holding it when another client opens politely. See `open()`.+ watchOnly: !this.deps.readOnly,},engines: terminalEngineCapabilities(this.deps.streamingAvailable),})@@ -451,6 +457,12 @@ export class TerminalStreamManager {// it, and the client asks again, without the key, once a person actually lands there. Absent// (every older client) is the takeover it has always been.const takeover = payload.takeover !== false+ // `watch: true` is a client nobody sits at — hn with no terminal, holding the sessions a closed+ // window left — reading a pane for the commands it answers. It never takes the terminal, nor its+ // size: before this it opened like any other on every reconnect, and when it came first after a+ // daemon restart the agent was resized to its 80x24 layout and the window the person was looking+ // at could only watch until they typed (2026-10-14). A daemon that predates the key ignores it.+ const watchOnly = payload.watch === true// Older clients have one owner per connection. A pooled relay supplies a stable identity// for each attached view; this partitions leases, not authentication or stream access.const viewId = typeof payload.viewId === 'string' && payload.viewId.length > 0 && payload.viewId.length <= 128@@ -469,10 +481,14 @@ export class TerminalStreamManager {// its output, and only typing is withheld until a person asks for it. So the open succeeds as// a WATCHER: tmux attaches read-only (no control lease, no resize, no input), the incumbent// keeps the terminal, and the client is told which it got by `readOnly` on `terminal_ready`.- const watching = !this.deps.readOnly && !takeover && incumbents.length > 0+ //+ // A watch-only stream is not anyone holding it: a window reconnecting politely beside one is+ // answered as it would be alone, not made to watch a terminal nobody drives.+ const holders = incumbents.filter((state) => !state.watchOnly)+ const watching = !this.deps.readOnly && (watchOnly || (!takeover && holders.length > 0))// Who a watcher is watching, named on its banner — "MacBook Pro is using this terminal" — as// `takenBy` names the winner on the incumbent's. Read now, before any stream below moves.- const heldBy = watching ? this.holderOf(incumbents, reservedPlacement) : undefined+ const heldBy = watching ? this.holderOf(holders, reservedPlacement) : undefined// A terminal is single-controller. A later client explicitly wins the lease and the incumbent// receives a targeted close notification; it must not be broadcast to other clients. The// notification names the winner when it can (`takenBy`), so the incumbent's banner can too.@@ -547,6 +563,7 @@ export class TerminalStreamManager {...(client ? { client } : {}),streamId,watching,+ watchOnly: watching && watchOnly,agentId: session.agentId,engineId: session.engine,placementKey,@@ -599,7 +616,8 @@ export class TerminalStreamManager {await this.closeStream(state, 'backend disconnected', false)return}- this.diagnostic(state, 'opened', { cols: size.cols, rows: size.rows, compression: state.compression })+ // Whether it holds the terminal: who resized an agent is read from here.+ this.diagnostic(state, 'opened', { cols: size.cols, rows: size.rows, compression: state.compression, watching, ...(watchOnly ? { watchOnly } : {}) })await this.sendKeyframe(state, 'open')})}diff --git a/cli/src/localWsServer.spec.ts b/cli/src/localWsServer.spec.tsindex 0c9865c6e..fdccad422 100644--- a/cli/src/localWsServer.spec.ts+++ b/cli/src/localWsServer.spec.ts@@ -745,6 +745,8 @@ describe('local CLI WebSocket', () => {ws.send(JSON.stringify({ type: 'machine_select', payload: { machineId, localProtocolVersion: 1 } }))await connected+ // hn with no terminal reading a pane is no one's focus.+ ws.send(JSON.stringify({ type: 'terminal_open', payload: { agentId: 'agent-watched', watch: true } }))// Opening a terminal still counts: that is all an older app build sends.ws.send(JSON.stringify({ type: 'terminal_open', payload: { agentId: 'agent-opened' } }))// And a window that MOVED without opening anything now says so — which is every click on a pane@@ -759,7 +761,7 @@ describe('local CLI WebSocket', () => {])// Consumed locally: it describes a hand at this desk, and the machine has no use for an unknown// frame type arriving on every pane click.- expect(backend.frames.map((frame) => frame.type)).toEqual(['terminal_open', 'terminal_open'])+ expect(backend.frames.map((frame) => frame.type)).toEqual(['terminal_open', 'terminal_open', 'terminal_open'])ws.close()})diff --git a/cli/src/localWsServer.ts b/cli/src/localWsServer.tsindex b9ac0a051..1fc76b680 100644--- a/cli/src/localWsServer.ts+++ b/cli/src/localWsServer.ts@@ -734,7 +734,9 @@ export function attachLocalWsServer(server: http.Server, options: LocalWsServerO}// Compatibility for windows that never report selection. A modern window restores every// terminal on reconnect; their attachment order is not the pane the person selected.- if (parsed?.type === 'terminal_open' && !explicitFocusClients.size && typeof agentId === 'string' && agentId) {+ // (A watch-only open is hn with no terminal reading a pane: nobody is in front of it.)+ if (parsed?.type === 'terminal_open' && !explicitFocusClients.size && typeof agentId === 'string' && agentId+ && (parsed.payload as Record<string, unknown>).watch !== true) {options.onAppFocus?.(boundMachineId, agentId)}}diff --git a/tui/Cargo.lock b/tui/Cargo.lockindex 1ed9ea161..19db9b55c 100644--- a/tui/Cargo.lock+++ b/tui/Cargo.lock@@ -654,7 +654,7 @@ dependencies = [[[package]]name = "harness-tui"-version = "0.1.29"+version = "0.1.30"dependencies = ["alacritty_terminal","base64",diff --git a/tui/Cargo.toml b/tui/Cargo.tomlindex 60ccbde7d..75e5eac81 100644--- a/tui/Cargo.toml+++ b/tui/Cargo.toml@@ -1,6 +1,6 @@[package]name = "harness-tui"-version = "0.1.29"+version = "0.1.30"edition = "2024"[dependencies]diff --git a/tui/src/app.rs b/tui/src/app.rsindex ee6589947..60e5e8dd7 100644--- a/tui/src/app.rs+++ b/tui/src/app.rs@@ -223,6 +223,25 @@ pub fn state_dir() -> std::path::PathBuf {/// The agent a reply is about (`agentId`).fn agent_id_of(reply: &Value) -> Option<String> { reply.get("agentId").and_then(Value::as_str).map(str::to_string) }+/// `terminal_open` for a pane of [size]. [takeover]: take the keyboard from any other window.+/// hn with no terminal ([headless]) has no one to give the keyboard or the size to: it opens as a+/// watcher (`watch`), which the machine never counts as holding the terminal — otherwise, first+/// back after a daemon restart, it took every agent of the desk at its 80x24 layout and left the+/// window in use watching until someone typed. A command it runs that types still takes over.+fn open_request(agent_id: &str, (cols, rows): (u16, u16), host: &str, takeover: bool, headless: bool) -> Value {+ let mut request = json!({+ "protocolVersion": 3,+ "agentId": agent_id,+ "cols": cols,+ "rows": rows,+ "compression": ["zlib", "none"],+ "client": { "kind": "tui", "name": format!("{host} terminal") },+ "takeover": takeover,+ });+ if headless && !takeover { request["watch"] = json!(true) }+ request+}+/// Seconds since the epoch.pub fn epoch_secs() -> i64 { std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_secs() as i64).unwrap_or(0) }@@ -1892,7 +1911,8 @@ impl App {/// A user asks for control of this TUI: reclaim every available pane across its tabs and/// sessions without moving focus. Reconnects and ownership notifications never call this.pub fn take_control(&mut self) {- if self.read_only() { return }+ // (hn with no terminal has no user to ask for it: it takes only a pane it types into.)+ if self.read_only() || self.headless { return }let mut ids: Vec<u64> = self.tabs.iter().chain(self.sessions.iter().filter(|s| !s.mirror.as_ref().is_some_and(|m| m.readonly)).flat_map(|s| s.tabs.iter())).flat_map(Tab::panes).collect();@@ -1926,6 +1946,11 @@ impl App {}let Some(pane) = self.panes.get_mut(&pane_id) else { return };if pane.opening { return }+ // hn with no terminal takes a terminal exactly when it has something to type into it (a+ // command's send-keys, the first line of a shell it made). Whatever else asks — a retry+ // while a harness starts, a view another window replaced, a pane a command brought forward —+ // it watches: no one is there to give the keyboard to, and every window with a person keeps it.+ let takeover = if self.headless { !pane.queued.is_empty() } else { takeover };// Do not send an open before machine_select has succeeded: its reply could otherwise// be discarded by the selecting link, leaving this pane waiting for 45 seconds.let Some(link) = self.links.get(&pane.machine_id).and_then(|s| s.link.clone())@@ -1935,7 +1960,9 @@ impl App {};let (cols, rows) = content.unwrap_or((pane.cols, pane.rows));// The remote terminal follows the actual tile, including narrow or short split panes.- let (cols, rows) = pane::stream_size(cols, rows);+ // hn with no terminal has no tile anyone sees: what it takes (a command typing into a pane,+ // a shell it made) keeps the size the far pane already has, once a keyframe said it.+ let (cols, rows) = if self.headless && pane.far_sized { (pane.cols, pane.rows) } else { pane::stream_size(cols, rows) };pane.opening = true;pane.want = (cols, rows);if !matches!(pane.phase, Phase::Watching(_)) || takeover { pane.phase = Phase::Connecting(if takeover { "Taking over…".into() } else { "Opening…".into() }) }@@ -1947,17 +1974,9 @@ impl App {// recognised by this token and not allowed to overwrite the current state.pane.open_token += 1;let token = pane.open_token;- let host = self.fleet.local_machine_name();+ let request = open_request(&agent_id, (cols, rows), &self.fleet.local_machine_name(), takeover, self.headless);self.spawn(async move {- link.request("terminal_open", json!({- "protocolVersion": 3,- "agentId": agent_id,- "cols": cols,- "rows": rows,- "compression": ["zlib", "none"],- "client": { "kind": "tui", "name": format!("{host} terminal") },- "takeover": takeover,- }), Duration::from_secs(45)).await+ link.request("terminal_open", request, Duration::from_secs(45)).await}, move |app, reply| app.opened(pane_id, &machine_id, token, (cols, rows), reply));}@@ -1990,8 +2009,9 @@ impl App {let retake = takeover_requested && pane.read_only;let queued = if retake { Vec::new() } else { std::mem::take(&mut pane.queued) };let read_only = pane.read_only;- // The tile changed size while this was opening: tell the far pane now.- if !read_only && pane.want != asked {+ // The tile changed size while this was opening: tell the far pane now. (hn with no+ // terminal has no tile: it keeps the size it asked for, the far pane's own.)+ if !read_only && !self.headless && pane.want != asked {pane.resize_seq += 1;let (seq, want) = (pane.resize_seq, pane.want);if let (Some(stream), Some(link)) = (stream, self.links.get(machine_id).and_then(|s| s.link.clone())) {@@ -2210,7 +2230,8 @@ impl App {if pane.want == want { continue }pane.want = want;let Some(stream) = pane.stream else { continue };- if pane.read_only { continue }+ // hn with no terminal sizes no agent: its 80x24 layout is nobody's screen.+ if pane.read_only || headless { continue }pane.resize_seq += 1;let seq = pane.resize_seq;if let Some(link) = self.links.get(&pane.machine_id).and_then(|s| s.link.clone()) {@@ -4065,6 +4086,9 @@ impl App {/// A pane you come to (a click, a key, the bar) that another window has the keyboard of is/// yours at once — as typing in it would make it — not "Take control" first.pub fn take_if_watching(&mut self, pane: u64) {+ // hn with no terminal: no one came to it (a script's select-window), and a takeover would+ // size the agent to its 80x24 layout under the window someone is using.+ if self.headless { return }let Some(p) = self.panes.get(&pane) else { return };if matches!(p.phase, Phase::Watching(_)) && !p.read_only && !p.opening { self.open_stream(pane, true) }}@@ -7107,6 +7131,67 @@ mod recovery_tests {}}+ #[test]+ fn hn_with_no_terminal_opens_a_pane_only_to_watch_it() {+ let open = |takeover, headless| open_request("agent-1", (37, 22), "Mac Auto", takeover, headless);+ // Back after a daemon restart, beside the window in use: it must not take the agent at its 80x24 layout.+ assert_eq!(open(false, true)["watch"], json!(true));+ assert_eq!(open(false, true)["takeover"], json!(false));+ // A window with a person in it opens as it always has, and so does a command that types.+ for (takeover, headless) in [(false, false), (true, false), (true, true)] {+ assert!(open(takeover, headless).get("watch").is_none(), "{takeover} {headless}");+ }+ assert_eq!(open(true, false)["client"], json!({ "kind": "tui", "name": "Mac Auto terminal" }));+ assert_eq!((open(true, false)["cols"].clone(), open(true, false)["rows"].clone()), (json!(37), json!(22)));+ }++ /// hn with no terminal (kept for the desk after its last window closed) took the desk's agents+ /// at its 80x24 layout on 2026-10-14. It sizes none now, and takes a pane only to type into it.+ #[tokio::test]+ async fn hn_with_no_terminal_takes_a_pane_only_to_type_and_never_sizes_one() {+ let mut app = fixture();+ app.headless = true;+ app.tabs[0].root = Some(Node::new(1, 80, 23));+ app.tabs[0].focus = Some(1);+ // The far pane is the size the window in use gave it; this layout would make it 80x24.+ { let p = app.panes.get_mut(&1).unwrap(); p.want = (1, 1); p.keyframe(99, 55, b""); }+ app.fit_panes();+ assert_eq!(app.panes[&1].resize_seq, 0);+ // Asked to take every pane, or one again, with nothing to type: it watches.+ app.take_control();+ assert!(!app.panes[&1].opening);+ app.open_stream(1, true);+ assert!(matches!(&app.panes[&1].phase, Phase::Connecting(s) if s == "Opening…"));+ assert_eq!(app.panes[&1].want, (99, 55));+ // A command types into it while that open is in flight: taken once the open answers.+ crate::input::send_to_pane(&mut app, 1, b"y\r".to_vec());+ assert!(app.panes[&1].takeover_pending);+ // With something to type it takes the pane, at the size the far pane already has.+ app.panes.get_mut(&1).unwrap().opening = false;+ app.open_stream(1, false);+ assert!(matches!(&app.panes[&1].phase, Phase::Connecting(s) if s == "Taking over…"));+ assert_eq!(app.panes[&1].want, (99, 55));+ app.links["test-peer"].link.as_ref().unwrap().close();+ }++ #[tokio::test]+ async fn hn_with_no_terminal_takes_no_pane_it_is_brought_to() {+ let mut app = fixture();+ let pane = app.panes.get_mut(&1).unwrap();+ // Taken over (`takenBy`), watching until someone comes to it.+ pane.phase = Phase::Watching("Mac Auto terminal".into());+ pane.read_only = false;+ app.headless = true;+ app.take_if_watching(1);+ assert!(!app.panes[&1].opening);+ assert_eq!(app.panes[&1].open_token, 7);+ // A window with a terminal takes it at once, as it always has.+ app.headless = false;+ app.take_if_watching(1);+ assert!(app.panes[&1].opening);+ app.links["test-peer"].link.as_ref().unwrap().close();+ }+#[tokio::test]async fn pane_waits_for_machine_selection_before_opening() {let mut app = fixture();diff --git a/tui/src/input.rs b/tui/src/input.rsindex 13ccdaaa9..64a5d2dcb 100644--- a/tui/src/input.rs+++ b/tui/src/input.rs@@ -268,6 +268,8 @@ pub fn send_to_pane(app: &mut App, focus: u64, bytes: Vec<u8>) {let Some(pane) = app.panes.get_mut(&focus) else { return };if pane.read_only || matches!(pane.phase, Phase::Watching(_)) || pane.stream.is_none() {pane.queued.push(bytes);+ // hn with no terminal takes only this pane, once its open in flight answers if there is one.+ if app.headless && pane.opening { pane.takeover_pending = true }app.take_control();// A popup has no tab, so its own stream still needs to be opened here.if app.panes.get(&focus).is_some_and(|p| !p.opening) { app.open_stream(focus, true) }@@ -1537,10 +1539,14 @@ fn shell_placed(app: &mut App, machine: String, placement: Placement, reply: Reslet new_window = matches!(&placement, Placement::Fill(_));app.open_agent(&machine, id, placement);let (session, _, pane) = app.find_pane_anywhere(&machine, id).ok_or("create pane failed: target window or pane disappeared")?;+ let typing = !typed.is_empty();if let Some(p) = app.panes.get_mut(&pane) {p.queued.extend(typed);p.start_command = reply.pointer("/agent/startCommand").and_then(serde_json::Value::as_str).map(str::to_string);+ // hn with no terminal opened it to watch (there was nothing to type yet): now there is.+ if app.headless && typing && p.opening { p.takeover_pending = true }}+ if app.headless && typing && app.panes.get(&pane).is_some_and(|p| !p.opening && p.read_only) { app.open_stream(pane, true) }crate::os_welcome::shell_created(app, pane);// A new session's first pane may belong to a session not currently in front.let (back, before) = (app.session_id, app.swap_back);diff --git a/tui/src/pane.rs b/tui/src/pane.rsindex 98749b510..0c22174a7 100644--- a/tui/src/pane.rs+++ b/tui/src/pane.rs@@ -83,6 +83,8 @@ pub struct Pane {/// The far pane's size — what the grid is.pub cols: u16,pub rows: u16,+ /// Whether [cols]/[rows] came from the far pane (a keyframe), not from this side's guess.+ pub far_sized: bool,/// What we last asked the far pane to be.pub want: (u16, u16),pub input_seq: u64,@@ -470,6 +472,7 @@ impl Pane {input_off: false,opening: false,takeover_pending: false,+ far_sized: false,read_only: false,last_alive: Instant::now(),dirty: true,@@ -532,6 +535,7 @@ impl Pane {pub fn keyframe(&mut self, cols: u16, rows: u16, bytes: &[u8]) {self.cols = cols.max(1);self.rows = rows.max(1);+ self.far_sized = true;self.term = Term::new(config(), &Size(self.cols, self.rows), self.listener.clone());self.parser = Processor::new();self.in_screen_title = false;