feat(opencode): migrate adapters to native V2 frontmatter #242

Merged
claudiomaradonna merged 3 commits from opencode-adapters-v2 into main 2026-11-21 20:27:10 +01:00
Collaborator

Why

The source's OpenCode support describes its seven agent adapters in the
deprecated OpenCode 1 frontmatter (permission: maps with V1 action
names), which OpenCode 2 still translates; the three implementer
adapters are identical except for their names, and no document tells a
project how to give them a model and a reasoning-effort variant, so
execute-plan's "one effort up" retry silently restarts an identical
agent; and execute-plan denied OpenCode sessions the implementer
continuation the client's subagent tool supports. A README sentence
also still claimed the two OpenCode hooks had never run in OpenCode
itself. A 2026-11-21 review of the OpenCode implementation reported
these.

What changed

The adapters now declare the native OpenCode 2 permissions: list: a
catch-all deny rule first, then one allow rule per action, bash
renamed to shell, edit covering edit, write and patch, and
external_directory kept explicit. The effective grant per role is
unchanged — the migration is syntactic — and the validator pins the new
block as exact text, rejects a file that mixes the V1 and V2 formats,
and keeps catching the tamperings it caught before, one new case
included.

docs/workflows/actions.md § Subagent models now says how a project
tunes the adapters — model: provider/model in the frontmatter, a
catalogue reasoning variant after #, an unknown variant a
model-resolution error — and what it gets untuned: an escalated attempt
restarts the same model at the same effort. The README points there.

execute-plan names OpenCode beside Claude Code and Codex for
continuing a reported implementer, by calling the subagent tool again
with that implementer's child sessionID; the workflows page mirrors
it.

The README § Hooks and settings now states what has been observed: the
hooks target OpenCode's 2.1.4 plugin API and run in 2.x only, the tests
exercise the plugins against stubs, and both hooks ran in OpenCode 2.3.2
in a session at this source — the guard refused an edit in a main
checkout, the shell check appended its report to a file tool's output.

How to verify

Base 65c0138, branch opencode-adapters-v2 at f491863. From a
fresh checkout, bash tests/verify-agent-config.sh prints
all 333 agent configuration tests passed; on the base the same
command passes with its own 332 tests.

The rewritten guards use names the branch adds, so they fail on the
base's code:

git worktree add --detach /tmp/base-code 65c0138
cd /tmp/base-code
git checkout opencode-adapters-v2 -- tests/agent-config/lib.sh \
  tests/agent-config/reviewer-adapters.sh
bash tests/agent-config/reviewer-adapters.sh

The two OpenCode cases print not ok — missing the new
permissions block and mixing diagnostics — while the same file on the
branch prints ok. Run and reported from this session.

Live enforcement, run here on OpenCode v2.3.2 (model
Qwen3.8-Flash-Next): seed a scratch git repository with the branch's
.opencode/agents/ and a stub AGENTS.md, then from it run
opencode run --auto --agent security-reviewer "List every tool you can call, one per line". Observed: exactly glob, grep, read, shell, skill; the advisor adds webfetch and websearch; implementer-low
has edit and write and no web tools; and asking the reviewer to
write a file under --auto returned NO_WRITE_TOOL with no file
created — had OpenCode ignored the block, the permissive default plus
--auto would have written it.

The README passage, before: "…they run in 2.x only, and the tests
exercise the plugins against stubs of the hooks, so they have not yet
run in OpenCode itself." After: "…they run in 2.x only; the tests
exercise the plugins against stubs of the hooks, and both hooks ran in
OpenCode 2.3.2 in a session at this source: the guard refused an edit
in a main checkout on its main branch, and the shell check appended its
report to the output of a file tool that had just written a shell
script."

Checks run on the tip, all passing: 333 agent-configuration tests,
46 work-folder check tests, scripts/verify-agent-config.sh valid
(state=template), shell check 51 files clean, prettier --check '**/*.md' clean, git diff --check main clean. Not run: the
behavioral evals, billed and maintainer-run only; they exercise the
unchanged Claude and Codex paths.

Considerations

The validator pins the block as exact text on purpose: a project that
widens its own adapters must update the pin, and the tamper tests keep
an unaccompanied widening loud. Live verification is one OpenCode 2.3.2
session at this source; the plugins' per-location loading in worktree
sessions and their patch branch remain unprobed live, as the
README's scope clause says. The adapters ship with no model: for
portability — the tiers become real only when the project tunes them,
which the guide now spells out.

## Why The source's OpenCode support describes its seven agent adapters in the deprecated OpenCode 1 frontmatter (`permission:` maps with V1 action names), which OpenCode 2 still translates; the three implementer adapters are identical except for their names, and no document tells a project how to give them a model and a reasoning-effort variant, so execute-plan's "one effort up" retry silently restarts an identical agent; and `execute-plan` denied OpenCode sessions the implementer continuation the client's `subagent` tool supports. A README sentence also still claimed the two OpenCode hooks had never run in OpenCode itself. A 2026-11-21 review of the OpenCode implementation reported these. ## What changed The adapters now declare the native OpenCode 2 `permissions:` list: a catch-all deny rule first, then one allow rule per action, `bash` renamed to `shell`, `edit` covering edit, write and patch, and `external_directory` kept explicit. The effective grant per role is unchanged — the migration is syntactic — and the validator pins the new block as exact text, rejects a file that mixes the V1 and V2 formats, and keeps catching the tamperings it caught before, one new case included. `docs/workflows/actions.md` § Subagent models now says how a project tunes the adapters — `model: provider/model` in the frontmatter, a catalogue reasoning variant after `#`, an unknown variant a model-resolution error — and what it gets untuned: an escalated attempt restarts the same model at the same effort. The README points there. `execute-plan` names OpenCode beside Claude Code and Codex for continuing a reported implementer, by calling the `subagent` tool again with that implementer's child `sessionID`; the workflows page mirrors it. The README § Hooks and settings now states what has been observed: the hooks target OpenCode's 2.1.4 plugin API and run in 2.x only, the tests exercise the plugins against stubs, and both hooks ran in OpenCode 2.3.2 in a session at this source — the guard refused an edit in a main checkout, the shell check appended its report to a file tool's output. ## How to verify Base `65c0138`, branch `opencode-adapters-v2` at `f491863`. From a fresh checkout, `bash tests/verify-agent-config.sh` prints `all 333 agent configuration tests passed`; on the base the same command passes with its own 332 tests. The rewritten guards use names the branch adds, so they fail on the base's code: ```bash git worktree add --detach /tmp/base-code 65c0138 cd /tmp/base-code git checkout opencode-adapters-v2 -- tests/agent-config/lib.sh \ tests/agent-config/reviewer-adapters.sh bash tests/agent-config/reviewer-adapters.sh ``` The two OpenCode cases print `not ok` — missing the new `permissions block` and mixing diagnostics — while the same file on the branch prints `ok`. Run and reported from this session. Live enforcement, run here on OpenCode v2.3.2 (model `Qwen3.8-Flash-Next`): seed a scratch git repository with the branch's `.opencode/agents/` and a stub `AGENTS.md`, then from it run `opencode run --auto --agent security-reviewer "List every tool you can call, one per line"`. Observed: exactly `glob, grep, read, shell, skill`; the advisor adds `webfetch` and `websearch`; `implementer-low` has `edit` and `write` and no web tools; and asking the reviewer to write a file under `--auto` returned `NO_WRITE_TOOL` with no file created — had OpenCode ignored the block, the permissive default plus `--auto` would have written it. The README passage, before: "…they run in 2.x only, and the tests exercise the plugins against stubs of the hooks, so they have not yet run in OpenCode itself." After: "…they run in 2.x only; the tests exercise the plugins against stubs of the hooks, and both hooks ran in OpenCode 2.3.2 in a session at this source: the guard refused an edit in a main checkout on its main branch, and the shell check appended its report to the output of a file tool that had just written a shell script." Checks run on the tip, all passing: 333 agent-configuration tests, 46 work-folder check tests, `scripts/verify-agent-config.sh` valid (`state=template`), shell check 51 files clean, `prettier --check '**/*.md'` clean, `git diff --check main` clean. Not run: the behavioral evals, billed and maintainer-run only; they exercise the unchanged Claude and Codex paths. ## Considerations The validator pins the block as exact text on purpose: a project that widens its own adapters must update the pin, and the tamper tests keep an unaccompanied widening loud. Live verification is one OpenCode 2.3.2 session at this source; the plugins' per-location loading in worktree sessions and their `patch` branch remain unprobed live, as the README's scope clause says. The adapters ship with no `model:` for portability — the tiers become real only when the project tunes them, which the guide now spells out.
OpenCode 2 still translates the adapters' V1 permission: map, now
deprecated, and a file mixing the two formats silently loses its V1
fields. State each adapter's grants in the native rules list instead:
a catch-all deny, then one allow per action with resource "*", bash
renamed to shell, edit covering edit, write, and patch, and
external_directory kept explicit so the grants match the V1 map one
for one.

The validator pins the new block as exact text and rejects a file
holding both a V1 permission: line and a V2 permissions: line. The
fixtures generate the new block, and the tampering cases gain or mix
rules through it, so a widened adapter still fails validation.
OpenCode's `subagent` tool starts another turn for a child session
when called again with its `sessionID`, so an OpenCode session can
continue the implementer that reported, as Claude Code and Codex
sessions do. The skill named only the latter two, which left OpenCode
sessions briefing a fresh implementer for every step.

Names the client and its mechanism in the skill's step 3, and mirrors
the client pair in the workflow document's subagent paragraph.
docs: document OpenCode tuning and verified hooks
All checks were successful
Maintenance / checks (pull_request) Successful in 6m9s
Maintenance / checks (push) Successful in 5m39s
f49186336e
The review found the implementer tiers nominal on OpenCode: no document
said how to give the adapters models and reasoning effort, so the
"one effort up" escalation restarted the session's model at the same
effort. Subagent models in docs/workflows/actions.md now holds the
per-adapter tuning procedure and states that no-op; the README adds the
one pointing sentence. The README hooks paragraph still claimed the
plugins had never run in OpenCode; the 2026-11-21 probes saw both hooks
act in OpenCode 2.3.2, so it now reports what was verified.

Applies drafts/subagent-models-tuning.md and
drafts/readme-hooks-opencode.md (task T3, proves G2 and G4).
Sign in to join this conversation.
No description provided.