Description:"Read your task's terminal: the shell in this task's worktree that the human uses from the Terminal tab, and that terminal_type types into. "+
"Returns its recent output as plain text, escape sequences removed, at most the last 64 KiB. "+
"Full-screen programs (vim, top, less) come out garbled, since this is the output stream, not a picture of the screen.",
Description:"Type into your task's terminal: the shell in this task's worktree that the human uses from the Terminal tab, starting it when none is running and waiting for its prompt before typing. "+
"text goes to the shell exactly as keystrokes, so end a command with \"\\n\" to run it, and send control characters for keys (\"\\u0003\" is Ctrl-C). "+
"The human sees everything you type and its output. "+
"Returns the output that followed, as terminal_read does, once the terminal has been quiet for half a second or after 10 seconds; read the rest of a longer command's output with terminal_read.",
InputSchema:json.RawMessage(`{
"type": "object",
"properties": {
"text": {"type": "string", "description": "The keystrokes to send."}
// One byte per write: a program that stops reading blocks a write, and the PTY can't be given a deadline, so this keeps what arrives after we give up to one byte.
fori:=0;i<len(text)&&!stop.Load();i++{
err:=term.Write([]byte{text[i]})
iferr!=nil{
written<-err
return
}
typed.Add(1)
}
written<-nil
}()
result:=func()string{
res:=terminal.Text(got)
exit,exited:=term.ExitStatus()
ifexited{
res+="\n[shell ended: "+exit+"]"
}
ifn:=typed.Load();n<int64(len(text)){
res+=fmt.Sprintf("\n[only %d of %d bytes were typed: the terminal stopped reading input]",n,len(text))