Overview
Terminal capabilities allow agents to execute shell commands in the client’s environment. Terminals are created, monitored, and eventually released through a series of client methods.Advertising Terminal Support
Declare terminal support during initialization:Terminal Lifecycle
- Create: Agent calls
createTerminalto start a command - Monitor: Agent calls
terminalOutputto get current output - Wait: Agent calls
waitForTerminalExitto wait for completion - Kill (optional): Agent calls
killTerminalto terminate the command - Release: Agent calls
releaseTerminalto free resources
createTerminal()
Creates a new terminal to execute a command.Method Signature
string
The session creating the terminal.
string
The command to execute (e.g.,
"npm", "git").string[]
Command arguments (e.g.,
["install", "lodash"]).string
Working directory for the command (absolute path).
Record<string, string>
Additional environment variables.
string
required
Unique identifier for this terminal.
Basic Implementation
terminalOutput()
Gets the current output and exit status of a terminal.Method Signature
string
The session ID.
string
The terminal ID.
string
required
The terminal output (combined stdout/stderr).
ExitStatus
Exit status if the command has completed:
{ type: "exit_code", code: number }{ type: "signal", signal: string }
Implementation
waitForTerminalExit()
Waits for a terminal command to exit and returns its exit status.Method Signature
string
The session ID.
string
The terminal ID.
ExitStatus
required
The exit status:
{ type: "exit_code", code: number }{ type: "signal", signal: string }
Implementation
killTerminal()
Kills a terminal command without releasing the terminal.Method Signature
string
The session ID.
string
The terminal ID.
object
Returns an empty object
{} or void on success.Implementation
The terminal remains valid after killing, allowing you to get final output with
terminalOutput(). Call releaseTerminal() when done.releaseTerminal()
Releases a terminal and frees all associated resources.Method Signature
string
The session ID.
string
The terminal ID to release.
object
Returns an empty object
{} or void on success.