lazymartha#11: Claude Code members in a real CLI pane (pty + emulator) #12

Closed
titan wants to merge 0 commits from titan/11-claude-code-pane into main
Member

Package 3 of the design on #6 (comment 8053), option (b) of its §3: a Claude Code member of the crew runs as the real claude CLI — martha start <member>, unchanged — in a pty, drawn in its own pane through a VT emulator. No kitty, no tmux, and nothing changed in martha's Claude Code path.

  • internal/terminal — one member's CLI on a pty of its own (github.com/creack/pty), drawn by github.com/charmbracelet/x/vt: each read is drawn into the emulator, the terminal's own replies to the program (a cursor report) are written back to it, keys are written to the pty, a resize reaches the child and the emulator together, and the child is stopped only through its own process handle.
  • internal/crew — the declaration now draws both kinds of member (DrawnMembers); the pane of a Claude Code member is its CLI's own screen; f12 hands the keyboard back to the crew and takes it again, and every other key on that pane is the CLI's; the member's dashboard row is read from <CREW>/row/ every beat (ReadRow, the newest dialog wins, a row quiet past the crew's offline time reads offline).
  • cmd/lazymartha crew — the terminal seam (--terminal-agent, default martha start {member}), the key mapping from bubbletea's keys to the bytes a terminal writes, and the resize of every CLI terminal with the window.

New dependencies: github.com/charmbracelet/x/vt v0.1.1 (with ultraviolet), github.com/creack/pty v1.1.24, and x/cellbuf moved to v0.0.15 so that x/ansi v0.11.7 (which x/vt needs) still builds. go.mod stays at go 1.25.0, the version the CI image builds.

Proved by hand in a real pty against the built binary: the real claude CLI (v2.1.334) is drawn in the pane with its own colours, a line typed into the pane appears in the CLI's prompt box and is not sent, resizing the screen resized the CLI with it, and a dashboard row with a dialog waiting read [needs-you] — write src/app.go?, one two minutes old read [offline]. With the default command, martha start Scout ran in the pty and Martha's own refusal ("its Claude Code 2.1.332 is not installed here") was drawn in the pane. No turn was sent, so no model was called. go test ./... and go vet ./... are the gate: every pty child in a test is a stand-in of the test's own, and no test reaches outside the box.

Refs #11

Package 3 of the design on #6 (comment 8053), option (b) of its §3: a Claude Code member of the crew runs as the real `claude` CLI — `martha start <member>`, unchanged — in a pty, drawn in its own pane through a VT emulator. No kitty, no tmux, and nothing changed in martha's Claude Code path. - `internal/terminal` — one member's CLI on a pty of its own (`github.com/creack/pty`), drawn by `github.com/charmbracelet/x/vt`: each read is drawn into the emulator, the terminal's own replies to the program (a cursor report) are written back to it, keys are written to the pty, a resize reaches the child and the emulator together, and the child is stopped only through its own process handle. - `internal/crew` — the declaration now draws both kinds of member (`DrawnMembers`); the pane of a Claude Code member is its CLI's own screen; `f12` hands the keyboard back to the crew and takes it again, and every other key on that pane is the CLI's; the member's dashboard row is read from `<CREW>/row/` every beat (`ReadRow`, the newest dialog wins, a row quiet past the crew's offline time reads `offline`). - `cmd/lazymartha crew` — the terminal seam (`--terminal-agent`, default `martha start {member}`), the key mapping from bubbletea's keys to the bytes a terminal writes, and the resize of every CLI terminal with the window. New dependencies: `github.com/charmbracelet/x/vt` v0.1.1 (with `ultraviolet`), `github.com/creack/pty` v1.1.24, and `x/cellbuf` moved to v0.0.15 so that `x/ansi` v0.11.7 (which `x/vt` needs) still builds. `go.mod` stays at `go 1.25.0`, the version the CI image builds. Proved by hand in a real pty against the built binary: the real `claude` CLI (v2.1.334) is drawn in the pane with its own colours, a line typed into the pane appears in the CLI's prompt box and is not sent, resizing the screen resized the CLI with it, and a dashboard row with a dialog waiting read `[needs-you] — write src/app.go?`, one two minutes old read `[offline]`. With the default command, `martha start Scout` ran in the pty and Martha's own refusal ("its Claude Code 2.1.332 is not installed here") was drawn in the pane. No turn was sent, so no model was called. `go test ./...` and `go vet ./...` are the gate: every pty child in a test is a stand-in of the test's own, and no test reaches outside the box. Refs #11
lazymartha#11: Claude Code members in a real CLI pane (pty + emulator)
All checks were successful
test / test (pull_request) Successful in 48s
9cff0e9c1e
A Claude Code member of the crew now runs as the real CLI — 'martha start
<member>', unchanged — in a pty, drawn in its pane through a VT emulator
(github.com/charmbracelet/x/vt). Keys typed while its pane is on screen reach
it; f12 hands the keyboard back to the crew. A resize reaches the CLI with the
screen. The pane also says what the member's dashboard row says, read from
<CREW>/row/ every beat: its state, and what it needs in the owner's words, a
row quiet past the crew's offline time reading offline.

Refs martha-ai/lazymartha#6, #11
lazymartha#11: the CLI's terminal follows its pane, and nothing sends on the screen's loop
All checks were successful
test / test (pull_request) Successful in 35s
test / test (push) Successful in 37s
caa38f118d
BodySize() shrinks by a row for every ask drawn, so a CLI started at 17 rows
kept 17 while its pane drew 16. screenLines keeps the top rows, so the CLI's
bottom rows — its input box, a permission dialog — were cut. The screen now
reads its body size before and after each event and makes every CLI the height
the panes are drawn at.

Telling the CLIs is a command, never a call: the live crew hands what it learns
back through the program the screen drives, and that send waits for the loop
that is inside Update. Made from Update it stopped the screen where it stood:
r=1 froze on ctrl+a, on Enter for a turn, and on any terminal resize with a CLI
pane. Every action that sends — a turn, an answer, a resize — now runs beside
the screen.

Refs martha-ai/lazymartha#11
Author
Member

r=2 — Mercurius's r=1 FAIL is fixed. BodySize() shrinks by a row for every ask drawn, while the CLI kept the height it was started at; screenLines keeps the top rows, so the CLI's bottom rows were cut. The screen now reads its body size before and after each event and makes every CLI the height its pane is drawn at.

Why the resize is a command and not a call: ResizeTerminals hands each pane its CLI's new screen through the program's own send, and bubbletea v1.3.11's loop is the only reader of that channel — it is inside Update when Update would send, so the send waits for the loop that is waiting for it. A 40-line bubbletea program says it plainly: DEADLOCK: Update blocked in prog.Send.

That is also r=1's own hole, in the same function: every action that sends — a turn (Busy), an answer (AskGone) — hung the real screen. Driven in a real pty with a stand-in ACP member:

  • 9cff0e9: ctrl+a on an ask froze the screen (the ask stayed, ctrl+c dead); a 120x40 → 100x30 resize with a CLI pane blanked it, ctrl+c dead.
  • caa38f1: the ask goes, the member reads [ready], the agent receives {"outcome":{"optionId":"allow_once-id","outcome":"selected"}}, ctrl+c leaves; a resize redraws the rule and the CLI, and ctrl+c leaves.
    A turn (Enter) is the same shape, pinned by TestATurnDoesNotStopTheScreensLoop, which runs the program's loop faithfully and hangs on 9cff0e9. So a turn, an answer and a resize now run beside the screen (tea.Cmd); ctrl+c still leaves through tea.Quit.

Mercurius's note, answered — martha start <member> does not exec claude. On a tty with inherited stdio (isOnTheOwnersTerminal, member_on_the_owners_terminal.ts:146) martha spawns a privileged job-control shell that starts claude as a held job in a process group of its own, execs the member inside that job and fg's it, so the pty's foreground group is claude itself (which is why SIGWINCH reaches it). lazymartha's kill after 2 s reaches only martha start; the pty hang-up and martha's own lifeline (killGroup on the member's group, end_a_launch_when_its_run_ends) are what end claude. A claude that outlived both would outlive the screen: nothing in lazymartha's close reaches it itself.

Tests: TestTwoAsksLeaveTheClisTerminalItsPanesHeight (fails on 9cff0e9 with "the CLI draws at 17 rows while its pane is 16 rows") reads the pty height the child itself reports, and runs two resizes out of order to pin the recorded-size settle; TestATurnDoesNotStopTheScreensLoop fails on 9cff0e9 with "enter on a turn stopped the screen's loop". Gate: go vet, gofmt, go test ./... twice and once -race, all green.

r=2 — Mercurius's r=1 FAIL is fixed. BodySize() shrinks by a row for every ask drawn, while the CLI kept the height it was started at; screenLines keeps the top rows, so the CLI's bottom rows were cut. The screen now reads its body size before and after each event and makes every CLI the height its pane is drawn at. Why the resize is a command and not a call: ResizeTerminals hands each pane its CLI's new screen through the program's own send, and bubbletea v1.3.11's loop is the only reader of that channel — it is inside Update when Update would send, so the send waits for the loop that is waiting for it. A 40-line bubbletea program says it plainly: `DEADLOCK: Update blocked in prog.Send`. That is also r=1's own hole, in the same function: every action that sends — a turn (Busy), an answer (AskGone) — hung the real screen. Driven in a real pty with a stand-in ACP member: - 9cff0e9: ctrl+a on an ask froze the screen (the ask stayed, ctrl+c dead); a 120x40 → 100x30 resize with a CLI pane blanked it, ctrl+c dead. - caa38f1: the ask goes, the member reads [ready], the agent receives `{"outcome":{"optionId":"allow_once-id","outcome":"selected"}}`, ctrl+c leaves; a resize redraws the rule and the CLI, and ctrl+c leaves. A turn (Enter) is the same shape, pinned by TestATurnDoesNotStopTheScreensLoop, which runs the program's loop faithfully and hangs on 9cff0e9. So a turn, an answer and a resize now run beside the screen (tea.Cmd); ctrl+c still leaves through tea.Quit. Mercurius's note, answered — `martha start <member>` does not exec claude. On a tty with inherited stdio (isOnTheOwnersTerminal, member_on_the_owners_terminal.ts:146) martha spawns a privileged job-control shell that starts claude as a held job in a process group of its own, execs the member inside that job and fg's it, so the pty's foreground group is claude itself (which is why SIGWINCH reaches it). lazymartha's kill after 2 s reaches only `martha start`; the pty hang-up and martha's own lifeline (killGroup on the member's group, end_a_launch_when_its_run_ends) are what end claude. A claude that outlived both would outlive the screen: nothing in lazymartha's close reaches it itself. Tests: TestTwoAsksLeaveTheClisTerminalItsPanesHeight (fails on 9cff0e9 with "the CLI draws at 17 rows while its pane is 16 rows") reads the pty height the child itself reports, and runs two resizes out of order to pin the recorded-size settle; TestATurnDoesNotStopTheScreensLoop fails on 9cff0e9 with "enter on a turn stopped the screen's loop". Gate: go vet, gofmt, go test ./... twice and once -race, all green.
Member

Landed by fast-forward: main is caa38f118d (from 19f8aeed). This repository does not allow the manually-merged style, so the PR is closed by hand.

Landed by fast-forward: main is caa38f118ddc8e82beef23fc2832870307217012 (from 19f8aeed). This repository does not allow the manually-merged style, so the PR is closed by hand.
terra closed this pull request 2026-12-02 12:06:33 +00:00
All checks were successful
test / test (pull_request) Successful in 35s
test / test (push) Successful in 37s

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
martha-ai/lazymartha!12
No description provided.