Run chat shell commands in a pseudo-terminal with typed input and resize

Commands start in a PTY (creack/pty; macOS and Linux) of the client's size
with TERM=xterm-256color in their own session. chat_shell_input writes typed
UTF-8 text in order through a bounded queue; chat_shell_resize sets the size.
Output stays the raw terminal stream with byte offsets as sequence numbers,
chat_shell_run_output resumes from an offset, and a plain-text rendering is
persisted for Copy output and Send to agent. Input is never stored or logged.
This commit is contained in:
2026-11-09 19:57:46 +00:00
parent 8ca5a1fdda
commit 355b722a1d
20 changed files with 865 additions and 54 deletions
+4 -4
View File
@@ -44,7 +44,7 @@ func testShellRunner(t *testing.T, ctx context.Context) (*chatShellRunner, *shel
func TestChatShellStopKillsAfterGrace(t *testing.T) {
runner, frames := testShellRunner(t, context.Background())
run, err := runner.Start(context.Background(), "ses_1", t.TempDir(), `trap "" INT; echo ready; while :; do sleep 0.05; done`)
run, err := runner.Start(context.Background(), "ses_1", t.TempDir(), `trap "" INT; echo ready; while :; do sleep 0.05; done`, 0, 0)
if err != nil {
t.Fatal(err)
}
@@ -65,7 +65,7 @@ func TestChatShellStopKillsAfterGrace(t *testing.T) {
func TestChatShellRetainsBoundedTail(t *testing.T) {
runner, frames := testShellRunner(t, context.Background())
total := protocol.ChatShellRunRetained + 200_000
run, err := runner.Start(context.Background(), "ses_1", t.TempDir(), `head -c 1248576 /dev/zero | tr '\0' a; printf END`)
run, err := runner.Start(context.Background(), "ses_1", t.TempDir(), `head -c 1248576 /dev/zero | tr '\0' a; printf END`, 0, 0)
if err != nil {
t.Fatal(err)
}
@@ -93,7 +93,7 @@ func TestChatShellRetainsBoundedTail(t *testing.T) {
func TestChatShellShutdownAndRestartInterrupt(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
runner, frames := testShellRunner(t, ctx)
run, err := runner.Start(context.Background(), "ses_1", t.TempDir(), "sleep 30")
run, err := runner.Start(context.Background(), "ses_1", t.TempDir(), "sleep 30", 0, 0)
if err != nil {
t.Fatal(err)
}
@@ -102,7 +102,7 @@ func TestChatShellShutdownAndRestartInterrupt(t *testing.T) {
if final := frames.final(run.ID); final == nil || final.Status != protocol.ChatShellRunInterrupted {
t.Fatalf("shutdown final = %+v", final)
}
if _, err := runner.Start(context.Background(), "ses_1", t.TempDir(), "true"); err == nil {
if _, err := runner.Start(context.Background(), "ses_1", t.TempDir(), "true", 0, 0); err == nil {
t.Fatal("a stopping server started a command")
}
// A record a crashed process left running is interrupted on start.