feat(opencode)!: run the hooks as OpenCode 2 plugins #168
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/opencode-v2-plugins"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
On OpenCode 2, an agent writes a shell script and no shell check
follows. It can also edit a tracked file in the main checkout on its
main branch, and nothing refuses it. OpenCode 2 runs no plugin in
OpenCode 1's shape: it reads only a module's default export, and logs
both of our plugins as failed to load. Everyone who moves to OpenCode 2
loses both hooks without noticing. Fixes #134.
Two alternatives were set aside. A dual export in each file would keep
1.x support, but it rests on a form I could not verify here. Separate
V2 files would leave V2 logging the V1 files as failed. You chose to
support V2 only.
What changed
Breaking change: the OpenCode hooks now run on OpenCode 2.x only. A
repository still on 1.x must upgrade OpenCode to keep them.
Both plugins default-export an OpenCode 2 definition:
write,editorpatchandappends its report to the tool's output, which the agent reads in the
same turn.
guard's reason.
A shared module,
.opencode/lib/hook-event.js, hands the unchangedshared hooks the event in the form they already read:
apply_patchfor
patchandfilePathforpath. It also gives them each path asOpenCode 2 resolves it:
~becomes the home directory, and patch linesand header paths are trimmed. Without this, the security review showed
that
~/…paths, indented patch headers or extra spaces before a pathlet an edit of the main checkout through.
The plugins import nothing from
@opencode/plugin, so the change addsno dependency. The validator pins the V2 lines and requires the module.
The README says the hooks were written against 2.1.4's plugin API and
have not yet run in OpenCode, and lists Node.js as needed to maintain
the source.
How to verify
You need Node.js and
jq. From a fresh checkout of the branch, runbash tests/agent-config/opencode-plugins.sh. It loads each plugin theway OpenCode 2 does, from its default export. It uses stub hooks that
record the event they get, and expects 14 passing cases, among them:
patharrives asfilePath, and apatchasapply_patchwith itspatchText;~/repo/f.sharrives as/home/user/repo/f.sh;~path and a pathholding a carriage return arrive as OpenCode reads them;
skipped after a failed call.
On
mainthe area fails at its first case, because the plugins haveno default export.
To see the real thing, put the branch's
.opencode/in a repository,start OpenCode 2 there in the main checkout on
main, and ask it toedit a tracked file. The edit should be refused with "main-checkout
guard: … stays as it was".
The README's Maintenance checks pass on
941ccce, with 315agent-configuration tests and 55 shell files clean. Four rounds of
change and security review closed every finding. I could not run the
plugins inside an OpenCode session, because it needs a model provider.
Their behavior there rests on the 2.1.4 package's types and bundled
runtime, which I read but did not run. That package was installed in
the session scratchpad with
--ignore-scripts. The behavioral evalsdid not run either.
Considerations
The README's Maintenance
prettier --checkstill covers Markdown only.The plugins' JavaScript passes Prettier, but nothing enforces it there;
that is the same open decision as on #164.
941cccef49to0fa031286f