Notify the agent when any command it runs in a task terminal finishes

This commit is contained in:
Ian Gulliver
2026-10-22 20:40:42 -07:00
parent fa0e521402
commit 101dace80e
3 changed files with 7 additions and 7 deletions
+4 -4
View File
@@ -110,7 +110,8 @@ func (m *Manager) terminalTypeTool(l *live) mcp.Tool {
"When the input line still holds unsent text after keys, text is refused, so that it isn't joined onto someone else's command: clear it with ctrl-u first, or set append to add to it on purpose. " +
"Replies from this tool and terminal_read end with the shell's current input line when zsh is at its prompt. " +
"The human sees everything you type and its output. " +
"To hand the human a command to run (one needing their password, say), type it without the newline and tell them to press Enter in the Terminal tab. In a zsh terminal, the reply then says byre will message you when the shell next returns to its prompt, with the exit status and output, starting a turn if you are idle, so end your turn rather than asking whether they ran it. " +
"In a zsh terminal, whenever a call leaves a command running or a line unsent, the reply says byre will message you when the shell next returns to its prompt, with the exit status and the output since the reply, starting a turn if you are idle: so after starting a long command, end your turn rather than polling it. " +
"To hand the human a command to run (one needing their password, say), type it without the newline and tell them to press Enter in the Terminal tab, then end your turn rather than asking whether they ran it. " +
"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",
@@ -156,7 +157,6 @@ func (m *Manager) terminalTypeTool(l *live) mcp.Tool {
keys += b
}
term.CancelWake()
startLine, _ := term.InputLine()
sent := keys
out := ""
if keys != "" || args.Text == "" {
@@ -188,7 +188,7 @@ func (m *Manager) terminalTypeTool(l *live) mcp.Tool {
}
return out, nil
}
if term.WakeOnPrompt(m.wakeOnPrompt(l), !submitted && (startLine != "" || args.Text != "")) {
if term.WakeOnPrompt(m.wakeOnPrompt(l)) {
out += "\n[byre messages you when the shell is next back at its prompt]"
}
return out, nil
@@ -198,7 +198,7 @@ func (m *Manager) terminalTypeTool(l *live) mcp.Tool {
func (m *Manager) wakeOnPrompt(l *live) func(string, []byte) {
return func(exit string, out []byte) {
text := fmt.Sprintf("The line you left unsent in the terminal was run, and the shell is back at its prompt with exit status %s (130 means it was canceled with Ctrl-C). The terminal's output since you typed it:\n\n%s", exit, terminal.Text(out))
text := fmt.Sprintf("The terminal you last typed into is back at its prompt: the command there finished with exit status %s (130 means it was canceled with Ctrl-C). The terminal's output since your last terminal_type reply:\n\n%s", exit, terminal.Text(out))
_, _, err := m.Message(context.Background(), l.id, "byre", text, "", "", "")
if err != nil {
slog.Error("wake agent on terminal prompt", "session", l.id, "task", l.taskID, "err", err)