The terminal learns where one command ends, and can be dragged wider

"The last command and its output" was not something the panel could honestly
offer. sendToChat took the last forty rows of the screen buffer, hard-wrapped at
the terminal's width with no way to tell a wrap from a newline -- its own comment
said so. So bash and zsh are given the OSC 133 markers VS Code and WezTerm use,
and Copy, Send and an Auto toggle are built on those.

The integration is written by the PTY command string itself, with printf. sshd
runs that string through $SHELL -c, so it can case on the shell's own name and
needs no probe, no second channel and no writable home. Passing it through the
environment does not work -- every distribution ships AcceptEnv LANG LC_*, so
anything else is dropped silently -- and feeding `source ...` in as keystrokes
races a slow .zshrc, echoes into the scrollback and lands in shell history.

Nothing needs hiding, which is the point of choosing it: the setup runs before
the shell exists and never writes to the PTY's input side, so there is nothing
to echo and no fan-out gate to build.

Two things were wrong in the first version and both were found by running it
against real shells rather than the fake one. bash: the DEBUG trap fires before
every simple command *including each one inside PROMPT_COMMAND*, so $? read from
there is whatever ran a moment ago -- every command reported success. The status
is captured in the trap now, which also removes the two-entry PROMPT_COMMAND
dance entirely. zsh: $ZDOTDIR is already ours by the time .zshenv runs, so the
shims were sourcing themselves and none of the user's configuration loaded; the
original is passed on the exec line.

Parsing is server-side. The `behind` path resets the terminal and replays a
truncated scrollback, so a client parser routinely sees a finish with no start;
two tabs share one shell and can disagree; and what comes out of this ends up
inside a prompt, so deriving it here leaves nothing to disbelieve. The bytes are
fanned out unchanged -- xterm consumes an OSC it has no handler for.

Output is bounded head and tail, 48KB and 16KB: a build that fails ten megabytes
in has the invocation at the top and the error at the bottom. Carriage returns
collapse to the last state of each line, which is the difference between a
usable prompt and two megabytes of spinner. The fence is sized to its content,
because output containing three backticks would otherwise break out and read as
prose.

Any shell that is not bash or zsh starts exactly as it did before. The buttons
then scrape the screen and say so, and Auto is disabled rather than degraded:
forty arbitrary lines on every message is worse than nothing.

Also a generic [data-resize] handle, keyboard included, persisted the way the
theme is. The inspector and sidebar can have it whenever they want it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jaroslav Beneš
2026-08-02 17:28:38 +02:00
parent fc02eb5538
commit 6bbd398707
17 changed files with 1734 additions and 43 deletions
+26 -2
View File
@@ -142,8 +142,14 @@ async def test_a_project_directory_becomes_a_cd_before_the_shell(shell_host):
await session.close()
async def test_no_project_directory_means_the_plain_login_shell(shell_host):
session = await _open(shell_host)
async def test_no_project_directory_and_no_integration_is_the_plain_login_shell(shell_host):
"""The original behaviour, kept reachable and kept tested.
Switching integration off has to give back *exactly* what was there before,
byte for byte -- including the None that means "whatever the account logs
in with". A fallback that is nearly the old behaviour is not a fallback.
"""
session = await _open(shell_host, integrate=False)
viewer = session.attach()
await _read_until(viewer, b"READY")
@@ -151,6 +157,24 @@ async def test_no_project_directory_means_the_plain_login_shell(shell_host):
await session.close()
async def test_an_unknown_shell_falls_through_to_the_plain_login_shell(shell_host):
"""With integration on the command is no longer None -- but every branch
that does not recognise the shell ends in the same `exec` that was there
before, because a terminal that works without markers is worth more than
markers that break a terminal."""
session = await _open(shell_host)
viewer = session.attach()
await _read_until(viewer, b"READY")
command = shell_host["seen"]["command"]
assert "case ${SHELL##*/} in" in command
assert command.rstrip().endswith("exec ${SHELL:-/bin/sh} -l")
# Every step is silenced, so a full /tmp or a read-only home costs the
# markers and nothing else.
assert "2>/dev/null" in command
await session.close()
async def test_a_single_quote_in_the_directory_cannot_end_the_quoting(shell_host):
session = await _open(shell_host, project_dir="/tmp/it's here; rm -rf /")
viewer = session.attach()