Skip to content

Commit e784265

Browse files
committed
fix(agent): drop the worker's edit tools so OpenCode always writes the solution
1 parent 9cfe21c commit e784265

4 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The plugin's runtime behaviour lives in the markdown files below plus the bundle
1818
| Surface | File | Role |
1919
| --------- | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2020
| Skill | `skills/opencode-delegate/SKILL.md` | Model picking, brief template, review-after-return rules |
21-
| Agent | `agents/opencode-worker.md` | Supervisor (`model: haiku`, `background: true`, inherits all tools incl. MCP): the only caller of MCP `delegate`; verifies git changes and tests, iterates at most twice, reports |
21+
| Agent | `agents/opencode-worker.md` | Supervisor (`model: haiku`, `background: true`, no edit tools: Read/Grep/Glob/Bash/ToolSearch plus MCP `delegate`/`list_models`/`list_sessions`): the only caller of MCP `delegate`; never writes the solution itself; verifies git changes and tests, iterates at most twice, then rejects |
2222
| Command | `commands/opencode.md` | `/opencode <model> -- <task>`: splits on `--`, spawns `opencode-worker` |
2323
| Hook | `scripts/route-to-opencode.sh`, `scripts/guard-main-thread-mcp.sh`, `plugin-hooks/hooks.json` | PreToolUse `Agent\|Task`: rewrites only built-in subagent calls (general-purpose, claude, Explore, Plan, claude-code-guide, statusline-setup) to `opencode-worker` on Haiku (Explore/Plan/claude-code-guide forced read-only); custom, plugin, reviewer and SDD agents never routed; pass-through guards: `OPENCODE_DELEGATE_ROUTE=off`, missing opencode, `[no-opencode]`, no `jq`. Second PreToolUse entry (`guard-main-thread-mcp.sh`) denies this plugin's MCP `delegate`/`delegate_async` when the input has no `agent_id` (main thread); calls from `opencode-worker` pass |
2424
| MCP | `plugin.json` `mcpServers`, `src/index.ts`, `dist/index.js` | `opencode` MCP server (stdio, `bun ${CLAUDE_PLUGIN_ROOT}/dist/index.js`) exposing `delegate`, `delegate_async`, `task_result`, `task_list`, `task_cancel`, `list_models`, `list_sessions` to the worker (the main thread never calls them); its `instructions` (always in the system prompt) make spawning the background worker the default for implementation |

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ claude ▸ reads git diff, runs tests, reports which model did what and a verdic
1414
| Surface | File | Role |
1515
| ------- | ------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
1616
| Skill | `skills/opencode-delegate/SKILL.md` | Model picking, brief template, review-after-return rules |
17-
| Agent | `agents/opencode-worker.md` | Supervisor (`model: haiku`, `background: true`, all tools): calls MCP `delegate`, verifies, iterates |
17+
| Agent | `agents/opencode-worker.md` | Supervisor (`model: haiku`, `background: true`, no edit tools): calls MCP `delegate`, verifies, iterates |
1818
| Command | `commands/opencode.md` | `/opencode <model> -- <task>`: splits on `--`, spawns `opencode-worker` |
1919
| Hook | `scripts/route-to-opencode.sh` | PreToolUse hook (`plugin-hooks/hooks.json`): reroutes built-in subagent calls to `opencode-worker` |
2020
| Hook | `scripts/guard-main-thread-mcp.sh` | PreToolUse hook (`plugin-hooks/hooks.json`): denies `delegate`/`delegate_async` calls from the main thread |

‎agents/opencode-worker.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
22
name: opencode-worker
33
description: Delegates one scoped task to a model running in OpenCode (Grok, Kimi, GLM, Qwen, DeepSeek, …) through the MCP `delegate` tool, then verifies the result and reports back. Use proactively for self-contained implementation work (new code, multi-file edits, tests, refactors, boilerplate) and broad read-only exploration, when the user or caller asks for an OpenCode model, when fanning a task out to several OpenCode models in parallel from a workflow, or when a cheap or fast outside model should do grunt work under Claude's supervision. Also receives Claude Code's built-in subagent calls, which the plugin's PreToolUse hook routes here automatically. Put the model name (e.g. "grok 4.7", "kimi k3"), if any, and the task in the prompt.
4+
tools: Read, Grep, Glob, Bash, ToolSearch, mcp__plugin_opencode-delegate_opencode__delegate, mcp__plugin_opencode-delegate_opencode__list_models, mcp__plugin_opencode-delegate_opencode__list_sessions
45
model: haiku
56
background: true
67
---
78

8-
You supervise a model that runs in OpenCode. You do not write the solution yourself unless the delegated model fails twice. You are the only caller of the MCP `delegate` tool: the main thread never calls it.
9+
You supervise a model that runs in OpenCode. You never write the solution yourself: you have no edit tools, and you do not change files through Bash. You are the only caller of the MCP `delegate` tool: the main thread never calls it.
910

1011
Routed prompts come from Claude Code's built-in subagents and were written for a Claude agent, not for the OpenCode model: forward the task including any "Routed from the ... subagent" note, and apply the mode rules below. A "Read-only task (routed from ...)" prefix means read-only mode.
1112

@@ -18,14 +19,14 @@ Routed prompts come from Claude Code's built-in subagents and were written for a
1819
- An optional `session_id` to continue.
1920
3. **Gather context** quickly (Read, Grep, Glob): the relevant files, the conventions, and the test/build commands.
2021
4. **Write a self-contained brief**: goal, context and paths, constraints, acceptance criteria, and a short report of the changes at the end. The model cannot see your conversation. Tell it not to commit unless the task says so.
21-
5. **Delegate** with the opencode MCP `delegate` tool (named `mcp__plugin_opencode-delegate_opencode__delegate` or `mcp__opencode__delegate`). If the result is an ambiguous-model error, pick the best candidate that fits the instructions; if the instructions name a provider, choose that provider.
22+
5. **Delegate** with the opencode MCP `delegate` tool (`mcp__plugin_opencode-delegate_opencode__delegate`). If the result is an ambiguous-model error, pick the best candidate that fits the instructions; if the instructions name a provider, choose that provider.
2223
6. **Verify**: read the git changes it reports and run the tests or build. Skip the test run for read-only tasks.
23-
7. **Iterate** at most twice. Call `delegate` again with the same `session_id` and give concrete feedback on what is wrong. A "timed out" result is not a failed attempt: do not retry it; report the `session_id` so the caller can continue the run.
24+
7. **Iterate** at most twice. Call `delegate` again with the same `session_id` and give concrete feedback on what is wrong. A "timed out" result is not a failed attempt: do not retry it; report the `session_id` so the caller can continue the run. If the result is still wrong after two iterations, stop and report reject with the `session_id`.
2425
8. **Report** to your caller in under 200 words:
2526
- the model used (or "opencode default") and the `session_id`
2627
- the files changed
2728
- the verification you ran and its result
2829
- your verdict: accept, accept with notes, or reject, with the reasons
2930
- any remaining issues
3031

31-
Keep your own edits minimal. The point is to get the work done by the delegated model and to check it.
32+
Bash is for reading state and running tests or builds only. The point is to get the work done by the delegated model and to check it.

‎test/package.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ describe("npm package", () => {
6161
expect(frontmatter).toMatch(/^background: true$/m);
6262
});
6363

64+
// The worker supervises; OpenCode writes. Without edit tools it has no direct way to spend Claude tokens writing the solution (Bash stays, for tests).
65+
test("opencode-worker has no edit tools", () => {
66+
const md = readFileSync(join(root, "agents/opencode-worker.md"), "utf8");
67+
const tools = /^tools: (.*)$/m.exec(md.split(/^---$/m)[1] ?? "")?.[1] ?? "";
68+
const mcp = "mcp__plugin_opencode-delegate_opencode__";
69+
expect(tools.split(/,\s*/)).toEqual([
70+
"Read",
71+
"Grep",
72+
"Glob",
73+
"Bash",
74+
"ToolSearch",
75+
`${mcp}delegate`,
76+
`${mcp}list_models`,
77+
`${mcp}list_sessions`,
78+
]);
79+
});
80+
6481
test("versions are in sync across manifests", () => {
6582
const v = readJson("package.json").version;
6683
expect(readJson(".claude-plugin/plugin.json").version).toBe(v);

0 commit comments

Comments
 (0)