opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[FEATURE]: Background Tasks Manager

Open avillagran opened this issue 10 months ago โ€ข 5 comments

Feature hasn't been suggested before.

  • [x] I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

โœจ Key Features

๐Ÿ”ง Core Task Manager (packages/opencode/src/task/)

  • TaskManager with full lifecycle operations:
    • โœ… create() - Spawn new background processes
    • ๐Ÿ“‹ list() - Get all running tasks
    • ๐Ÿ” get() - Retrieve specific task info
    • โšก kill() - Terminate processes
    • ๐Ÿ“– read() - Read task output (full or partial)
    • ๐Ÿ“œ tail() - Stream recent output
    • โŒจ๏ธ input() - Send input to running processes
    • ๐Ÿ”„ adopt() - Migrate foreground processes to background
  • Persistence Layer (.opencode/tasks/{taskId}.json):
    • ๐Ÿ’พ Tasks survive session restarts
    • ๐Ÿ”Œ Auto-reconnect to running processes by PID
    • ๐Ÿ“Š State tracking and recovery
  • Event Bus System:
    • ๐ŸŽ‰ task:created - New task spawned
    • ๐Ÿ“ task:output - Output received
    • โœ”๏ธ task:completed - Task finished
    • โŒ task:killed - Task terminated

๐Ÿค– Process Query Tool (packages/opencode/src/tool/process-query.ts)

New LLM tool that enables Claude to:

  • ๐Ÿ“‹ List all background tasks
  • โœ… Check task status
  • ๐Ÿ“– Read full or partial output
  • ๐Ÿ” Search for patterns in task logs
  • ๐ŸŽฏ Resolve tasks by ID, "last" keyword, or description match

๐ŸŽจ User Interface Components

Background Tasks Modal (ctrl+p > "Background tasks"):

  • ๐Ÿ“Š View all running background tasks
  • ๐Ÿ“ˆ Real-time output streaming
  • โšก Kill tasks directly from UI
  • ๐Ÿ”„ Auto-refresh with live updates

Process Controls:

  • ๐Ÿ”ต [bg] button - Migrate running processes to background
  • ๐Ÿ”ด [kill] button - Terminate running processes
  • ๐ŸŽฎ Available for both Bash commands and shell commands (! prefix)

๐Ÿ› ๏ธ Enhanced Bash Tool

  • โœ… run_in_background parameter for spawning background tasks
  • ๐Ÿ”„ Foreground process registry for tracking
  • ๐ŸŽฏ Support for process migration while running
  • ๐Ÿงน Optimized latency with fire-and-forget persistence

๐Ÿ“Š Implementation Stats

  • Files Changed: 20 files
  • Lines Added: ~4,878 lines
  • Test Coverage: 46 comprehensive tests
    • 29 tests for TaskManager core
    • 17 tests for foreground process management

๐ŸŽฌ Demo

(https://x.com/avillagran/status/2013709707563708491/video/1)

๐Ÿ” Technical Details

Architecture:

  1. Task Layer - Process management and lifecycle
  2. Persistence Layer - State storage and recovery
  3. Transport Layer - RPC handlers for TUI communication
  4. UI Layer - React components for user interaction

Key Design Decisions:

  • ๐Ÿš€ Fire-and-forget persistence to minimize migration latency
  • ๐Ÿ”„ PID-based reconnection for session recovery
  • ๐ŸŽฏ Unified interface for both foreground and background processes
  • ๐Ÿ“ Clean logging using Log utility instead of console

๐Ÿงช Testing

Comprehensive test suite covering:

  • โœ… Task creation and lifecycle
  • โœ… Output streaming and reading
  • โœ… Process termination
  • โœ… Session recovery
  • โœ… Foreground to background migration
  • โœ… Error handling and edge cases

๐Ÿ“š Use Cases

  • ๐Ÿ—๏ธ Long-running builds (webpack, vite, etc.)
  • ๐Ÿงช Test watchers and development servers
  • ๐Ÿ“ฆ Package installations
  • ๐Ÿ” Log monitoring and analysis
  • ๐Ÿค– Any command that needs to run while working on other tasks

avillagran avatar Jan 20 '26 22:01 avillagran

This issue might be a duplicate of existing issues. Please check:

  • #9462: Support background tool execution

Feel free to ignore if none of these address your specific case.

github-actions[bot] avatar Jan 20 '26 23:01 github-actions[bot]

anthropic claude code just created https://code.claude.com/docs/en/interactive-mode#task-list and this may be a new model for how to proceed. Not sure if this is the same intent but worth a look.

DarickBrokaw avatar Jan 23 '26 16:01 DarickBrokaw

Agree, oh-my-opencode implemented it as part of plugin. As it is framework-level feature, it should be supported directly by official codebase.

XiaoLiuAI avatar Feb 10 '26 08:02 XiaoLiuAI

To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

github-actions[bot] avatar Apr 12 '26 03:04 github-actions[bot]

Came across this โ€” I have a skill that solves the dev server side of things: https://github.com/workdocyeye/server-manager

start-server runs the command in background via cmd /c redirection, keeps track of ports/PIDs in a JSON file, and you can tail/grep the logs afterward. Tested on Next.js, Streamlit, Flask, and a few Go servers on Windows.

Not the full task manager described here, but enough to keep dev servers from blocking the terminal while you work on other things.

workdocyeye avatar Apr 25 '26 01:04 workdocyeye