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:
@@ -9,27 +9,34 @@ import (
|
||||
)
|
||||
|
||||
// chatShellSharePrompt is the ordinary prompt chat_shell_share queues: the
|
||||
// command, where it ran, how it ended and a bounded tail of its output. It is
|
||||
// the only path by which an operator command reaches the agent.
|
||||
// command, where it ran, how it ended and a bounded tail of the plain-text
|
||||
// rendering of its output (no terminal escape sequences). It is the only path
|
||||
// by which an operator command reaches the agent.
|
||||
func chatShellSharePrompt(record protocol.ChatShellRunRecord) string {
|
||||
output := chatShellRecordTail(record, protocol.ChatShellRunShareOutput)
|
||||
text := record.Text
|
||||
if text == "" {
|
||||
text = chatShellPlainText(record.Output)
|
||||
}
|
||||
shown := text
|
||||
if len(shown) > protocol.ChatShellRunShareOutput {
|
||||
shown = shown[runeStartAfter([]byte(shown), len(shown)-protocol.ChatShellRunShareOutput):]
|
||||
}
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "I ran this shell command in %s:\n\n", record.Directory)
|
||||
fence := chatShellFence(record.Command)
|
||||
fmt.Fprintf(&b, "%ssh\n$ %s\n%s\n\n", fence, record.Command, fence)
|
||||
fmt.Fprintf(&b, "%s.\n\n", chatShellOutcome(record))
|
||||
if output.Output == "" {
|
||||
if strings.TrimSpace(shown) == "" {
|
||||
b.WriteString("It printed no output.")
|
||||
return b.String()
|
||||
}
|
||||
if output.OutputStart > 0 {
|
||||
fmt.Fprintf(&b, "Output (the last %s of %s):\n\n", chatShellBytes(int64(len(output.Output))), chatShellBytes(output.OutputBytes))
|
||||
if len(shown) < len(text) || record.OutputStart > 0 {
|
||||
fmt.Fprintf(&b, "Output (the last %s of the %s it wrote, as plain text):\n\n", chatShellBytes(int64(len(shown))), chatShellBytes(record.OutputBytes))
|
||||
} else {
|
||||
b.WriteString("Output:\n\n")
|
||||
}
|
||||
fence = chatShellFence(output.Output)
|
||||
text := strings.TrimRight(output.Output, "\n")
|
||||
fmt.Fprintf(&b, "%stext\n%s\n%s", fence, text, fence)
|
||||
fence = chatShellFence(shown)
|
||||
fmt.Fprintf(&b, "%stext\n%s\n%s", fence, strings.TrimRight(shown, "\n"), fence)
|
||||
return b.String()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user