diff --git a/app/src/components/AgentTerminal.tsx b/app/src/components/AgentTerminal.tsx index 10318bd..87916c2 100644 --- a/app/src/components/AgentTerminal.tsx +++ b/app/src/components/AgentTerminal.tsx @@ -219,13 +219,18 @@ export function AgentTerminal({ )} + {/* Sized region + an absolutely-filled xterm mount. The absolute inset-0 + child always has an explicit box equal to its parent, so `fit()` never + measures a stale/percentage-collapsed height — the terminal tracks the + panel as it expands. */}
+ className={cn("relative", maximized || fill ? "flex-1 min-h-0" : "h-[560px]")} + > +
+
) } diff --git a/castle-api/src/castle_api/pty_session.py b/castle-api/src/castle_api/pty_session.py index 172bf41..a69a432 100644 --- a/castle-api/src/castle_api/pty_session.py +++ b/castle-api/src/castle_api/pty_session.py @@ -32,6 +32,20 @@ def _set_winsize(fd: int, rows: int, cols: int) -> None: fcntl.ioctl(fd, termios.TIOCSWINSZ, winsize) +def _acquire_controlling_tty() -> None: + """Child-side setup (preexec), run after the pty slave is dup'd to fd 0/1/2. + + ``setsid()`` starts a new session (own process group, so cleanup can + ``killpg`` the whole tree). ``TIOCSCTTY`` then makes the slave our + *controlling terminal* — without it the kernel has no foreground process + group to deliver ``SIGWINCH`` to, so a later winsize change (a browser resize) + is silently dropped and the app never reflows. This is what makes live resize + work, not just the initial size. + """ + os.setsid() + fcntl.ioctl(0, termios.TIOCSCTTY, 0) + + @dataclass class PtySession: """A child process attached to a pty master. @@ -77,7 +91,9 @@ class PtySession: stderr=slave_fd, cwd=str(cwd) if cwd else None, env=proc_env, - start_new_session=True, # own session/group → controlling tty + killpg + # setsid + TIOCSCTTY in the child: own session/group (for killpg) AND + # the slave as controlling tty (for SIGWINCH resize delivery). + preexec_fn=_acquire_controlling_tty, close_fds=True, ) os.close(slave_fd) # parent keeps only the master