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:
@@ -20,10 +20,15 @@ const (
|
||||
// oldest first, without output. The body is optional.
|
||||
TerminalList = "terminal_list"
|
||||
// TerminalInput writes Data (UTF-8, control characters included, at most
|
||||
// ChatShellInputLimit bytes) to a running terminal. No reply body.
|
||||
// ChatShellInputLimit bytes) to a running terminal. No reply body. Reply
|
||||
// marks an automatic answer of the client's emulator, which reaches the
|
||||
// terminal only from its active client; typed input may carry the size
|
||||
// (cols, rows) the client draws at (as chat_shell_input).
|
||||
TerminalInput = "terminal_input"
|
||||
// TerminalResize sets a running terminal's size (cols, rows); the reply
|
||||
// echoes the terminal.
|
||||
// TerminalResize reports the size (cols, rows) a client draws a running
|
||||
// terminal at; the terminal takes its active client's size, and Activate
|
||||
// makes the sender active (as chat_shell_resize). The opener of a
|
||||
// terminal is its first active client. The reply echoes the terminal.
|
||||
TerminalResize = "terminal_resize"
|
||||
// TerminalOutput reads one terminal with its retained output from the
|
||||
// absolute byte After on (all of it when After precedes the retained
|
||||
@@ -68,6 +73,9 @@ type TerminalRequest struct {
|
||||
Rows int `json:"rows,omitempty"`
|
||||
Data string `json:"data,omitempty"`
|
||||
After int64 `json:"after,omitempty"`
|
||||
// Reply (terminal_input) and Activate (terminal_resize): see above.
|
||||
Reply bool `json:"reply,omitempty"`
|
||||
Activate bool `json:"activate,omitempty"`
|
||||
}
|
||||
|
||||
// TerminalRecord is one terminal. Output and OutputStart are set only on
|
||||
|
||||
Reference in New Issue
Block a user