Skip to content

About

AI-powered task queue for OpenCode agents — schedule, retry, and manage batch jobs with SQLite

Resources

Stars

16 stars

Watchers

0 watching

Forks

Repository files navigation

SuperTask

Autonomous Task Control Plane for OpenCode — Queue it. Schedule it. Stream it. Recover it.

npm version MIT License

English | 简体中文

SuperTask is a local Autonomous Task Control Plane for OpenCode agents. It turns one-off opencode run invocations into durable, observable, event-driven operations with a persistent SQLite WAL queue, cron/delayed/recurring scheduling, exponential-backoff retries, global batch serialization, real-time SSE log streaming, 12 native OpenCode tools, and a three-pane local Web Dashboard.

OpenCode can run an Agent now. SuperTask makes sure long-running and recurring Agent workflows keep moving after the terminal closes, survive crashes or reboots, stay within concurrency and dependency rules, and expose completed steps, tokens, tool calls, and reproducible commands within each run's bounded 65,536-character log tail.

Why SuperTask?

If you need to... Use
Run one Agent once opencode run
Run a few fixed commands at fixed times cron, launchd, systemd, or GitHub Actions
Restart a long-running process on a schedule PM2 cron_restart
Manage changing Agent jobs with durable state, retries, priorities, and history SuperTask

SuperTask is not another wrapper around cron. Scheduled work becomes an ordinary durable queue task, so manual and scheduled jobs follow the same concurrency, retry, cancellation, dependency, and history rules.

What You Get

Capability What it means
Durable SQLite WAL queue Tasks and every run survive process and machine restarts; indexed dispatch reaches sub-millisecond latency even at 10K tasks / 50K runs
OpenCode 1.x & 2.4.3+ ready Runtime version detection with 2.x --standalone, --title=<name>, -- prompt delimiter, -m provider/model#variant, and api agent.list/model.list (enabled filtering)
Event-driven zero-idle wake GatewayEventBus + /api/internal/wake wake Workers immediately on enqueue/retry/trigger (~33 ms p50 launch instead of waiting for poll intervals)
Three schedule types Cron, run-once delay, and fixed recurring interval with maxInstances limits and instant manual trigger
Automatic & batch recovery Retry budgets, exponential backoff, dead-letter convergence, order-independent batch cancel/retry, and one-click clone
Controlled execution Global concurrency, priority ordering, same-project dependencies, and global batch serialization
Safe process handling Per-run UUID gated-v3-token-guardian, Unix process-group drain proof, and kernel recheck on exit
Real-time observability Live SSE log streaming (/api/runs/:id/stream & supertask logs --follow), OpenCode 2.4.3 step/token/cost/tool-error parser, Session resume, and exact reproducible command
Three-pane Control Plane UI Project sidebar with 7-day metrics & Gateway pulse, single-row topbar, non-modal Inspector drawer, batch actions, and backup-first DB maintenance on 127.0.0.1

Three-Minute Quick Start

1. Install one exact version

VERSION="$(npm view opencode-supertask dist-tags.latest)"
npm install -g "opencode-supertask@$VERSION"
opencode plugin "opencode-supertask@$VERSION" --global --force

OpenCode 2.x (tested through v2.4.3) uses opencode plugin add "opencode-supertask@$VERSION" instead of the last line. SuperTask detects the OpenCode major version at runtime and supports both 1.x (1.2.20+) and 2.x; supertask upgrade keeps a single pinned plugin entry in either config format.

Pinning the exact version keeps the OpenCode plugin, global CLI, and Gateway on the same build. Do not replace it with a bare package name or @latest in opencode.json.

2. Restart OpenCode and start the Gateway

supertask install   # recommended: PM2 startup, crash recovery, and log rotation

For foreground development instead:

supertask gateway

The plugin never installs global services during OpenCode startup. PM2 setup only happens when you explicitly run supertask install.

3. Ask OpenCode to create a task

Create a SuperTask named "Review API errors".
Use the build agent in this project, retry twice, and run it now.

OpenCode receives 12 native supertask_* plugin tools (add, next, status, retry, cancel, edit, clone, list, get, logs, schedule, upgrade). The current project directory is locked to OpenCode's tool context rather than trusted from model input, and runtime execution transitions (start/done/fail) remain exclusively owned by the Gateway.

4. Watch it run

supertask status
supertask list --limit 10
supertask ui

The Dashboard opens at http://127.0.0.1:4680.

How It Works

flowchart LR
    A[OpenCode 12 tools / CLI / Dashboard] --> B[SQLite WAL + Indexed Queue]
    A -. "/api/internal/wake" .-> E[GatewayEventBus]
    B --> C[Single Gateway]
    C --> D[Worker + Guardian]
    C --> F[Scheduler]
    C --> G[Watchdog]
    E --> D
    D --> H[opencode run 1.x / 2.x]
    H --> I[Run History + Live SSE Stream]
Loading

The single Gateway owns running and normal execution outcomes (done / failed / automatic retry). Clients create, edit, cancel, retry, and inspect work (and run abandon is an explicit operator escape hatch for legacy NULL-protocol runs); run records use running | done | failed. Writes trigger best-effort internal wakeups so Workers dispatch without polling delay, while Dashboard and supertask logs --follow stream live updates over SSE.

Measured Performance (10K Tasks / 50K Runs, ~229 MB SQLite DB)

Benchmarked on the same 10K-task / 50K-run on-disk SQLite database before and after the 0009 index + GatewayEventBus + CLI code-splitting refactor:

Operation / Metric Baseline Current (p50) Improvement
TaskService.next(excludedBatchIds=2) 5,158–6,974 ms 0.067 ms 77,000x+
TaskService.claimNext() (immediate tx) 5,157.94 ms 0.336 ms 15,351x
TaskRunService.listMeta({ limit: 50 }) 188.46 ms 0.224 ms 841x
TaskService.list({ activeExecution }) 51.70 ms 0.076 ms 680x
Dashboard SSR GET / (homepage HTML) 268.1 KB 83.6 KB (Sprite + shared menu + split i18n) -68.8% HTML
Dashboard SSR GET /runs 188.46 ms (634.9 KB) 4.94 ms (105.6 KB) 38.2x (-83.4% HTML)
TaskService.dashboardOverview() (cache hit) ~50 ms cold aggregate ~0.04 ms (single-snapshot cache) 1,000x+ warm hit
initDb() DB reopen (PRAGMA user_version fast-path) 24.70 ms 0.429 ms 57.6x
Enqueue → OpenCode launch (pollIntervalMs=1000) ~500 ms avg / 1,000 ms worst 33 ms (zero poll wait) ~15x end-to-end
CLI bundle (dist/cli/index.js) & --version 992.3 KB / 28.9 ms 181.1 KB / 17.6 ms -81.7% size / -39% startup

Use It Your Way

Natural language in OpenCode

Run a security review with agent build, model provider/model, and variant high.

Every weekday at 9:00, create a report task for this project.

Show failed tasks in this project and retry the recoverable ones.

Check whether batch "release" is running in another project.

Available plugin tools (12 total; start/done/fail are intentionally not exposed, and supertask_clone clears dependsOn by default unless explicitly passed):

supertask_add       supertask_edit      supertask_clone    supertask_cancel
supertask_retry     supertask_logs      supertask_list     supertask_get
supertask_next      supertask_status    supertask_schedule supertask_upgrade

CLI

# Queue work (supports --prompt-file for long Markdown prompts)
supertask add --name "Security review" --agent build \
  --model openai/gpt-5.6-sol --variant xhigh \
  --prompt-file ./prompts/security-review.md \
  --importance 5 --urgency 4 --max-retries 2 \
  --retry-backoff 30s --timeout 30min

# Schedule, edit, or trigger templates
supertask template add --name "Weekday report" --agent build \
  --model openai/gpt-5.6-sol --variant high \
  --prompt "Summarize important project changes" \
  --type cron --cron "0 9 * * 1-5"
supertask template edit --id 1 --cron "30 9 * * 1-5"
supertask template trigger --id 1

# Search, inspect, stream logs, clone, and recover
supertask status
supertask list --search "security" --agent build --all --limit 20
supertask logs --id 42 --tail 100 --follow
supertask clone --id 42 --name "Security review (re-run)"
supertask retry --id 42
supertask cancel --id 42

Interactive terminals render compact human-readable output, while non-TTY pipes and explicit --json return machine-parseable JSON for non-streaming commands (supertask logs --follow streams raw log lines continuously). Run supertask --help or supertask <command> --help for the complete command surface (auto, en, and zh-CN).

Dashboard

The three-pane Control Plane Dashboard supports Chinese (zh-CN), English (en), and Spanish (es) via a single-file locale registry (src/web/locales/), light and dark themes, live SSE updates (/api/events & /api/runs/:id/stream), and four focused views:

Page Purpose
Task Queue Left project sidebar (7-day metrics, Gateway pulse & language/theme controls), single-row topbar with server-side search, segmented status filter strip, multi-select batch retry/cancel/delete, one-click clone, and non-modal right Inspector drawer
Scheduled Tasks Create/edit cron, delayed, and recurring templates; run one immediately without bypassing the queue
Execution Logs Lightweight /runs list with on-demand /api/runs/:id/log expansion, live SSE streaming for active runs, OpenCode 2.4.3 step/token/cost/tool-error breakdown, Session resume, and exact historical command
System Status Active vs. saved config card with embedded 4-component health grid, concurrency controls, and backup-first transactional database maintenance

The project picker reads the selected directory's real OpenCode catalog (agent list / models --verbose on 1.x; api agent.list / api model.list filtering disabled models on 2.x with 30s caching), so forms offer only locally available models, each model's declared variants, and directly runnable Agents. Leaving variant at its default omits --variant and follows the Agent/model configuration.

Platform Integration (HTTP / SSE / Webhook)

SuperTask can also run as a decoupled scheduling engine behind an upper-layer AI platform (such as multi-tenant Agent OS deployments) through a single HTTP/SSE/Webhook contract — no direct SQLite reads, CLI subprocesses, or config file parsing required:

  • Optional Bearer Auth: Set SUPERTASK_API_TOKEN to enforce Authorization: Bearer <token> on all /api/* endpoints (including SSE streams) and SSR Dashboard pages (/, /templates, /runs, /system), while GET /health (exposing maxConcurrency) and /assets/* remain public. Leave it unset for direct local browser access to the Dashboard; CLI logs --follow and internal wake calls verify /health against the local ready gateway_lock (with redirect: 'error' and canonical dbPath check) before attaching the token.
  • Workspace-Scoped APIs: GET /api/templates?cwd=&enabled=&limit=&offset=&page=, GET /api/tasks?cwd=..., GET /api/stats?cwd=..., GET /api/runs/by-session/:sessionId?cwd=... (indexed via 0011, returning runStatus & taskStatus), GET /api/events?cwd=... (strictly fail-closed per-workspace SSE isolation), and GET /api/runs/:id/stream.
  • Opaque metadata: Attach up to 16 KB of caller-defined JSON metadata (e.g., tenant/app/owner identifiers) to tasks and templates; scheduled and manually triggered runs inherit template metadata automatically.
  • Lifecycle Webhooks: Set SUPERTASK_WEBHOOK_URL (and optionally SUPERTASK_WEBHOOK_SECRET for HMAC-SHA256 X-SuperTask-Signature) to receive asynchronous Gateway notifications on task.done, task.failed, task.dead_letter (including budget exhaustion and dependency cascades), and task.cancelled, with redirect: 'error', OpenCode 2.4.3 tool_use error summaries, and graceful shutdown draining. Gateway & OpenCode server secrets are stripped from all spawned child environments (src/core/env-sanitize.ts).
  • Persistent OpenCode 2.x Server Runner (Opt-in): Set SUPERTASK_RUNNER=opencode-server together with OPENCODE_URL, OPENCODE_PASSWORD (or OPENCODE_SERVER_PASSWORD), and optional SUPERTASK_DEFAULT_MODEL to execute tasks directly against a running OpenCode 2.x HTTP/SSE server (v2.0.32–v2.4.x) with zero cold-start overhead, subagent permission/form interception, and fail-closed Watchdog interrupt recovery. Default remains opencode-cli.

Reliability Without Hand-Waving

  • SQLite BEGIN IMMEDIATE protects the single-Gateway lock and global batch serialization.
  • Candidate selection and the running transition happen in one immediate transaction, so concurrent edits cannot alter a claimed task.
  • Each managed run has a unique launcher identity and an isolated Unix process group.
  • A run settles only after the launcher proves the entire process group drained.
  • Process containment ends at that group: descendants that deliberately call setsid() or start as detached daemons must manage their own lifecycle.
  • Shutdown and cancellation fail closed when process ownership cannot be proven.
  • supertask doctor verifies OpenCode, the effective pinned plugin, cache, CLI, Gateway package, ready lock, SQLite, Dashboard, and PM2 environment.
  • Database clear and restore are transactional, backup-first, WAL-consistent, and reject active work.

The detailed guarantees and recovery rules live in Architecture and Operations and Troubleshooting.

Upgrade and Diagnose

supertask upgrade          # update only when versions or components have drifted
supertask upgrade --force  # reinstall the current version, refresh environment, restart
supertask doctor
supertask doctor --smoke --smoke-agent build --smoke-model provider/model --smoke-variant high

When every component already matches npm latest, normal upgrade is a no-op and does not restart the Gateway. Smoke diagnostics make one real model call; ordinary doctor does not.

Requirements

  • OpenCode
  • Bun 1.1.45 or newer
  • Node.js/npm for the documented install and upgrade flow
  • macOS or Linux for Gateway task execution

Windows Worker execution remains disabled until OS Job Object containment can provide equivalent managed-process isolation and a recoverable drain proof. Queue execution does not require PM2 when the Gateway runs in the foreground.

Install From Source

git clone https://github.com/vbgate/opencode-supertask.git
cd opencode-supertask
bun install
bun run build

Point OpenCode at the built plugin file:

{
  "plugin": [
    "file:///home/user/src/opencode-supertask/dist/plugin/supertask.js"
  ]
}

Then restart OpenCode and run bun run gateway from the repository.

AI-Friendly by Design

  • Tool descriptions include scheduling, retries, global batches, dependencies, and project-scope semantics.
  • Plugin tools use the OpenCode context directory and reject a model-supplied working directory.
  • CLI commands render concise localized output on a TTY while preserving machine-parseable JSON for non-TTY pipes and explicit --json.
  • AGENTS.md records architecture invariants, testing rules, release rules, and unsafe shortcuts for coding agents.
  • Commands record the exact executable, arguments, model, variant, Agent, and working directory for reproducible diagnosis.

Documentation

Development

bun install --frozen-lockfile
bun run typecheck
bun run typecheck:tests
bun run lint
bun run build
bun test
bun run test:coverage
bun run test:browser
bun run package:smoke
bun scripts/opencode-compat-smoke.ts

GitHub Actions CI is intentionally disabled (.github/workflows/ci.yml has been removed; publish.yml is a release-only artifact publisher triggered by GitHub Release or manual workflow_dispatch). Run the full local verification suite—including scripts/launcher-ipc-smoke.ts on the minimum supported Bun 1.1.45 runtime—before cutting a release.

License

MIT

About

AI-powered task queue for OpenCode agents — schedule, retry, and manage batch jobs with SQLite

Resources

Stars

16 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages