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:
@@ -0,0 +1,43 @@
|
||||
package protocol
|
||||
|
||||
// Interactive operator shell commands. On macOS and Linux every chat_shell_run
|
||||
// runs inside a pseudo-terminal (ChatShellRunRecord.Terminal): the command sees
|
||||
// a TTY of the requested size with TERM=xterm-256color, its output is the raw
|
||||
// terminal stream (escape sequences included) and any authenticated client
|
||||
// watching the chat may type into it until it ends. Other platforms keep
|
||||
// plain pipes and refuse input.
|
||||
const (
|
||||
// ChatShellInput writes Data to a running terminal command's input. The
|
||||
// body is ChatShellRunRequest (session_id, run_id, data). Data is the
|
||||
// UTF-8 text of what was typed or pasted, control characters included
|
||||
// (Ctrl-C is "\u0003", Enter is "\r", arrow keys are their escape
|
||||
// sequences); the bytes written are exactly its UTF-8 encoding. Input is
|
||||
// never persisted or logged; the reply carries no body.
|
||||
ChatShellInput = "chat_shell_input"
|
||||
// ChatShellResize sets a running terminal command's size (cols, rows); the
|
||||
// process receives SIGWINCH. The last resize from any client wins. The
|
||||
// reply echoes the run.
|
||||
ChatShellResize = "chat_shell_resize"
|
||||
)
|
||||
|
||||
// Bounds of interactive terminals.
|
||||
const (
|
||||
// ChatShellInputLimit bounds the UTF-8 bytes of one chat_shell_input.
|
||||
// Clients split a longer paste into several requests.
|
||||
ChatShellInputLimit = 16 << 10
|
||||
// ChatShellInputQueue bounds the input requests waiting for the command
|
||||
// to read them; beyond it chat_shell_input is refused.
|
||||
ChatShellInputQueue = 64
|
||||
// Terminal sizes are clamped to these bounds; a run started without a
|
||||
// size gets the defaults.
|
||||
ChatShellTerminalMinCols = 20
|
||||
ChatShellTerminalMaxCols = 500
|
||||
ChatShellTerminalMinRows = 4
|
||||
ChatShellTerminalMaxRows = 200
|
||||
ChatShellTerminalDefaultCols = 100
|
||||
ChatShellTerminalDefaultRows = 30
|
||||
)
|
||||
|
||||
// ChatShellTerminalUnsupported is the refusal of chat_shell_input and
|
||||
// chat_shell_resize on a server or run without a pseudo-terminal.
|
||||
const ChatShellTerminalUnsupported = "interactive terminals are not supported on this server"
|
||||
Reference in New Issue
Block a user