[PR #2483] Process Tools for Interactive CLI commands #10323

Open
opened 2026-02-16 18:14:57 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/2483

State: open
Merged: No


Summary

This PR introduces background process handling capabilities to the bash tool, allowing OpenCode to manage interactive and long-running processes without blocking the conversation flow. Processes that produce no output within a configurable timeout are automatically backgrounded and can be interacted with using a new suite of process management tools.

Problem Solved

Previously, running interactive commands (like python, node REPLs) or long-running processes (like npm run dev, development servers) would block the bash tool until a timeout occurs. This made it impossible for the AI to effectively work with development workflows that involve servers, watchers, or interactive tools.

Implementation Details

Enhanced Bash Tool

  • Added outputTimeout parameter (default: 3 seconds) to detect non-responsive processes
  • Processes with no output are automatically backgrounded and tracked
  • Returns a unique process ID for future interaction
  • Includes buffer memory warnings in all bash command responses

New Process Management Tools

  1. process_list - View all background processes with runtime and memory stats
  2. process_stream - Read output with stream-like semantics (read/peek/tail/reset)
  3. process_interact - Send input or signals to background processes
  4. process_trim - Manage memory by trimming output buffers

Memory Management

  • Soft limit: 100MB (warning issued)
  • Hard limit: 200MB (auto-trim to 1MB)
  • Buffer warnings appear in bash command metadata to prompt proactive management

Technical Approach

  • Uses Promise.race() for non-blocking timeout detection
  • Global Map tracks all running processes
  • Stream-like API with read cursors prevents duplicate output
  • Automatic cleanup on process termination

Use Cases

  • Development servers: npm run dev, python -m http.server
  • Interactive REPLs: python, node, psql
  • Build watchers: webpack --watch, tsc --watch
  • Long-running processes: database clients, log tails

Testing

Includes a test file demonstrating process lifecycle management and output capture.

Breaking Changes

None. The feature is fully backward compatible - existing bash commands work exactly as before, with the added benefit of automatic backgrounding when appropriate.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/2483 **State:** open **Merged:** No --- ### Summary This PR introduces background process handling capabilities to the bash tool, allowing OpenCode to manage interactive and long-running processes without blocking the conversation flow. Processes that produce no output within a configurable timeout are automatically backgrounded and can be interacted with using a new suite of process management tools. ### Problem Solved Previously, running interactive commands (like `python`, `node` REPLs) or long-running processes (like `npm run dev`, development servers) would block the bash tool until a timeout occurs. This made it impossible for the AI to effectively work with development workflows that involve servers, watchers, or interactive tools. ### Implementation Details #### Enhanced Bash Tool - Added `outputTimeout` parameter (default: 3 seconds) to detect non-responsive processes - Processes with no output are automatically backgrounded and tracked - Returns a unique process ID for future interaction - Includes buffer memory warnings in all bash command responses #### New Process Management Tools 1. **`process_list`** - View all background processes with runtime and memory stats 2. **`process_stream`** - Read output with stream-like semantics (read/peek/tail/reset) 3. **`process_interact`** - Send input or signals to background processes 4. **`process_trim`** - Manage memory by trimming output buffers #### Memory Management - Soft limit: 100MB (warning issued) - Hard limit: 200MB (auto-trim to 1MB) - Buffer warnings appear in bash command metadata to prompt proactive management ### Technical Approach - Uses `Promise.race()` for non-blocking timeout detection - Global `Map` tracks all running processes - Stream-like API with read cursors prevents duplicate output - Automatic cleanup on process termination ### Use Cases - Development servers: `npm run dev`, `python -m http.server` - Interactive REPLs: `python`, `node`, `psql` - Build watchers: `webpack --watch`, `tsc --watch` - Long-running processes: database clients, log tails ### Testing Includes a test file demonstrating process lifecycle management and output capture. ### Breaking Changes None. The feature is fully backward compatible - existing bash commands work exactly as before, with the added benefit of automatic backgrounding when appropriate.
yindo added the pull-request label 2026-02-16 18:14:57 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10323