oc-goalGoal mode (Codex-style thread goals) plugin for opencode
0
316
近 7 天 12
34.0
生态多维模型
1 个月前
2026-07-20
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["oc-goal@0.1.1"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["oc-goal@0.1.1"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D oc-goalopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
oc-goal
Adds Goal Mode to opencode, modeled after OpenAI Codex's thread goals (/goal).
Set a goal, and the agent automatically starts a new turn after every turn ends, keeping up the work until the objective is verifiably complete, the token budget is exhausted, or you pause it manually.
How it works (aligned with Codex)
- State machine:
active→complete(declared by the model) /blocked(same blocker for 3 consecutive goal turns) /paused(user pause or Esc interrupt) /budget_limited(token budget exhausted) /usage_limited(API rate limit). Anything other thanactivestops automatic continuation. - Loop engine: listens for the
session.statusidle event → if the goal is still active, automatically starts a new turn with a hidden synthetic message. The message contains the objective, token usage/remaining, and the Completion audit + Blocked audit instructions (ported from Codex'scontinuation.md). - Model tools:
create_goal/get_goal/update_goal(update only acceptscomplete/blocked; pause/resume/budget are controlled by the user or system, same as Codex). - Budget accounting: incrementally accumulates
(input - cache.read) + output + reasoningper assistant message; crossing the budget flips status tobudget_limitedand injects a one-time wrap-up notice (soft stop, the turn is not hard-killed). - Loop safety: turn errors →
blocked; API rate limits →usage_limited; Esc interrupt →paused. - State is persisted to
~/.local/share/opencode/oc-goal/<project-id>.jsonand survives restarts and compaction (the goal is injected into the compaction summary context).
Installation
Add the plugin to your global ~/.config/opencode/opencode.json (or a project-level opencode.json) — opencode installs it automatically, no manual download needed:
{
"plugin": ["oc-goal"]
}
Alternative (from source): clone this repo, run npm install, then reference the file directly:
{
"plugin": ["file:///absolute/path/oc-goal/src/index.ts"]
}
You can also copy or symlink src/index.ts to ~/.config/opencode/plugins/goal.ts (make sure @opencode-ai/plugin is resolvable).
Usage
/goal <objective> Set a goal and start working on it immediately (replaces any existing goal)
/goal Show current goal status (status also works)
/goal pause Pause automatic continuation
/goal resume Resume (from paused/blocked/usage_limited)
/goal budget 500000 Set a token budget
/goal budget none Remove the budget
/goal clear Clear the goal
While a goal is active:
- After every turn, the agent automatically continues until the model calls
update_goalto declarecomplete(requires passing the completion audit) orblocked(requires the same blocker for 3 consecutive turns). - Pressing Esc to interrupt any turn automatically pauses the goal; use
/goal resumeto continue. - When the budget is exhausted, continuation stops automatically and you're prompted to raise it with
/goal budget <n>and then/goal resume.
Development
npm run typecheck