Skip to content

About

Thread Goal for OpenCode: a plugin that drives one session, one line of work, until the objective is reached.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

opencode-thread-goal

An OpenCode plugin for long-running, unattended agent work:

Plugin What it does
thread-goal Thread Goal — one session, one line of work, driven until the objective is reached. Replaces OpenCode's built-in /goal.

The plugin declares its id in the plugin itself:

Directory Plugin id
plugins/thread-goal opencode-thread-goal

The id matches the npm package name, which is the convention for community plugins: the opencode. namespace is reserved for OpenCode's built-in plugins, and the id is what opencode.json matches against when a plugin is disabled ("plugins": ["-opencode-thread-goal"]).

Ported from MiniMax Code (MIT). No binary patching, no fork of the OpenCode runtime — this is an ordinary OpenCode v2 plugin.


Requirements

OpenCode 2.2.1 or newer. The plugin uses plugin APIs that arrived in that release (ctx.session.hook("experimental.idle")), and it refuses to load on an older host with a readable message instead of failing later on a missing hook. The floor is declared once, in plugins/thread-goal/host-version.ts, and bun scripts/check-manifest.ts fails when the manifests disagree with it.

Install

opencode plugin add github:iniaki662/opencode-thread-goal

That installs the plugin and adds it to ~/.config/opencode/opencode.json. It replaces OpenCode's built-in /goal, so add "plugins": ["-opencode.goal"] to the same file so the built-in goal plugin does not compete for the command.

To install from a clone instead:

git clone https://github.com/iniaki662/opencode-thread-goal.git
cd opencode-thread-goal
bash scripts/install.sh

install.sh copies the plugin into ~/.config/opencode/plugins/thread-goal/ and adds "plugins": ["-opencode.goal"] to ~/.config/opencode/opencode.json.

Which version you get

The specifier decides how the plugin updates itself:

Specifier Behaviour
opencode-thread-goal pinned to the version installed at install time
opencode-thread-goal@latest, a range updated at startup and every 24 hours; a new version that fails to load is rolled back to the previous one
github:iniaki662/opencode-thread-goal follows the default branch, same update rule
an exact version or commit pinned permanently

The plugin itself declares the plugin API it is written against as an optional peer dependency ("@opencode/plugin": "^2.2.1 || ^0.0.0-dev"): OpenCode provides the SDK at runtime, so an install does not pull a second copy of it.

To disable the plugin later, list its id with a leading - (the id, not the directory name):

{ "plugins": ["-opencode-thread-goal"] }

Inside a session:

/goal create a hello.txt under /tmp/demo and verify its contents

thread-goal

Replaces OpenCode's built-in /goal with a different semantic model.

built-in opencode.goal thread-goal
Terminal state decided by a separate judge model call (session.generate) every round the agent itself (update_goal), the host settles it
Round limit 50 none
Stall limit 3 3 consecutive rounds to reach blocked
Wait limit 30 minutes, then paused none (waits as long as the provider allows)
Process restart goal comes back paused goal survives, the new process takes it over
Failure handling any failure pauses classified: usage_limited / blocked (safety) / paused (infra, retryable)
States — six states (active, complete, blocked, usage_limited, paused, aborted)

Two guardrails are kept on purpose:

  • blocked needs three consecutive rounds with the same blocking condition — one bad round is not a block;
  • a no-progress circuit breaker (same reply fingerprint, or N rounds without a tool call) stops a line that is spinning.

The plugin reads the cross-process quota-wait record (see shared/quota-wait.ts), so a goal that is waiting for a provider quota shows waiting for quota (resumes at HH:MM) rather than idle — and does not double-start work when the quota wake-up message arrives. Any provider plugin may write that record; the format is a small documented contract under shared/.

Migration from the built-in goal

If you used OpenCode's built-in goal plugin, its active goals stay in the built-in plugin's storage namespace. Move them across:

bun scripts/migrate-goal.ts            # preview
bun scripts/migrate-goal.ts --apply    # write

The script is idempotent and backs up what it touched.


Repository layout

opencode-thread-goal/
├── plugins/
│   └── thread-goal/        the Thread Goal plugin
├── shared/                 modules with a single source of truth
│   ├── quota-text.ts       quota wall wording
│   └── quota-wait.ts       cross-process quota wait state
└── scripts/
    ├── install.sh          deploy the plugin into ~/.config/opencode/plugins/
    ├── check-manifest.ts   check the version declarations agree
    ├── sync-shared.ts      sync shared/ into the plugin directory
    ├── migrate-goal.ts     move goal state into the thread-goal namespace
    ├── prune-goal-states.ts drop orphaned and terminal goal entries
    └── test-*.ts, e2e-*.ts the test suites

The goal state lives in OpenCode's plugin storage, in a namespace derived from the plugin id (plugin:<utf16be-hex of the id>:).

Development

bun install                                # once
bun scripts/test-thread-goal.ts            # pure-logic unit tests (110 assertions)
bun scripts/check-manifest.ts              # version declaration drift check
bun scripts/sync-shared.ts --check         # shared-module drift check
bun scripts/test-quota-wait-thread-goal.ts # end-to-end against a live server
bun scripts/e2e-thread-goal.ts             # end-to-end goal loop

shared/ is the single source of truth for the modules the plugin needs (quota text, quota-wait state). The plugin directory holds a byte-identical copy — a plugin cannot import across directories, because a plugin failing to load takes the whole plugin down with it. scripts/sync-shared.ts keeps the copies in sync.

CI runs the pure-logic tests, the manifest check and the drift check on every push.


License

MIT — see LICENSE.

Ported from MiniMax Code (MiniMax-AI/minimax-code, MIT).

About

Thread Goal for OpenCode: a plugin that drives one session, one line of work, until the objective is reached.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages