Terminals: one active client per terminal; keystrokes skip the request queue

Several clients drawing one terminal (machine terminal or chat terminal
command) no longer interfere. The server tracks, per terminal, the
connections drawing it, most recently active first: the active client
(the opener, then whoever last typed or focused it) owns the PTY size and
is the only one whose emulator's automatic query answers reach the
process; other clients' answers are acknowledged and dropped, and their
sizes recorded but not applied. When the active connection closes the next
most recent client's size is applied.

Protocol (backwards compatible; all new fields optional):
- terminal_input / chat_shell_input: reply (emulator answer), cols/rows
  (the typist's size, applied before the input).
- terminal_resize / chat_shell_resize: activate (the client focused it).

Latency: PipelinesClient sends terminal_input, terminal_resize,
chat_shell_input and chat_shell_resize at once rather than behind the
previous request's reply. The server reads those onto a per-connection
terminal lane handled in order beside the ordinary request loop, and
terminal_open (up to 5 s waiting for su) now runs off the read loop.

Client: ChatShellTerminalSession routes what the emulator emits while
drawing output to onReply and reports focus through activate();
ChatShellInputPipe keeps answers and typing in separate requests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 23:37:16 +00:00
parent 5ab1ec9e00
commit c3458d8a7f
28 changed files with 1229 additions and 87 deletions
+7 -1
View File
@@ -65,7 +65,8 @@ const (
// ChatShellRunRequest names one session and either a new command or a run.
// OperationID is the optional retry identity of chat_shell_share's prompt.
// Cols and Rows size a new run's terminal (chat_shell_run) or resize a running
// one (chat_shell_resize); Data is chat_shell_input's typed text; After is
// one (chat_shell_resize) and may accompany typed chat_shell_input (the size
// its client draws at); Data is chat_shell_input's typed text; After is
// chat_shell_run_output's resume offset.
type ChatShellRunRequest struct {
SessionID string `json:"session_id"`
@@ -78,6 +79,11 @@ type ChatShellRunRequest struct {
After int64 `json:"after,omitempty"`
// RunIDs names the runs of chat_shell_dismiss and chat_shell_restore.
RunIDs []string `json:"run_ids,omitempty"`
// Reply marks chat_shell_input as an automatic answer of the client's
// emulator; Activate marks chat_shell_resize as the client focusing the
// terminal (see ChatShellInput and ChatShellResize).
Reply bool `json:"reply,omitempty"`
Activate bool `json:"activate,omitempty"`
}
// ChatShellRunRecord is one operator command and what it produced. Output is