Add a new agent tool process for managing background exec sessions. This tool allows agents to run long-running commands in the background and interact with them asynchronously.
As an AI agent, I want to start a command in the background so that I can run long-running tasks without blocking the conversation.
Acceptance Criteria:
- Agent can execute
execute_commandwithbackground: trueparameter - Command returns immediately with a
sessionIdandstatus: "running" - Process continues running after tool returns
As an AI agent, I want a foreground exec call to yield into a background session when it runs too long, so that the loop can continue without restarting the command.
Acceptance Criteria:
- Foreground
execwaits only untilyieldMs(or the default yield window) - If the command finishes within that window, it returns the normal foreground result
- If the command is still running after that window, the same process is kept alive and
execreturnsstatus: "running"with asessionId - The yielded session is manageable through
process
As an AI agent, I want to poll the output of a background command so that I can monitor its progress.
Acceptance Criteria:
processtool withaction: "poll"returns recent output- Output is truncated to last N characters (configurable, default 500)
- Returns current status: "running", "done", "error", or "killed"
As an AI agent, I want to read the full output of a completed command so that I can analyze the results.
Acceptance Criteria:
processtool withaction: "log"supports pagination viaoffsetandlimit- Large outputs are automatically offloaded to files
- Agent can use file tools to read offloaded content
As an AI agent, I want to send input to a running background process so that I can interact with interactive commands.
Acceptance Criteria:
processtool withaction: "write"sends data to stdin- Optional
eof: truecloses stdin
As an AI agent, I want to list, kill, and clean up background sessions so that I can manage resources.
Acceptance Criteria:
action: "list"shows all sessions for current agentaction: "kill"terminates a running sessionaction: "clear"clears output buffer/fileaction: "remove"completely removes a session
- Sessions are isolated by
conversationId(agent-scoped) - Session IDs are cryptographically random (nanoid)
- No cross-agent session access
- Sessions are in-memory only (lost on restart)
- Automatic TTL cleanup (default 30 minutes inactivity)
- Maximum runtime limit (default 30 minutes)
- Large outputs offloaded to files (>10KB threshold)
interface ExecToolsConfig {
backgroundMs: number // Default yield window (10000)
timeoutSec: number // Max runtime (1800)
cleanupMs: number // Session TTL (1800000)
maxOutputChars: number // Poll output limit (500)
}Environment variables:
PI_BASH_YIELD_MSPI_BASH_MAX_OUTPUT_CHARSOPENCLAW_BASH_PENDING_MAX_OUTPUT_CHARS(compatibility)PI_BASH_JOB_TTL_MS
- PTY/terminal emulation (not needed - pipe mode is sufficient)
- Cross-agent session sharing
- Persistent sessions across restarts
- Real-time streaming output (poll-based only)
| Question | Decision |
|---|---|
| PTY or pipe mode? | Pipe mode (agent-controlled) |
| Offload large outputs? | Yes, >10KB threshold |
| Always show process tool? | Yes, always visible |
| Default poll output size? | 500 characters |
Enables agents to:
- Run long-running builds/tests without blocking
- Monitor server processes
- Handle interactive CLI tools
- Better resource management for complex workflows