Skip to content

Port plugin + tests to OpenCode 2.x plugin API - #1

Merged
abogartz merged 1 commit into
mainfrom
v2-port
Oct 17, 2026
Merged

abogartz merged 1 commit into
mainfrom
v2-port

Conversation

@abogartz

Copy link
Copy Markdown
Owner

Summary

Port the plugin and its test suite from the OpenCode 1.x (V1) function-export plugin API to the OpenCode 2.x plugin API.

OpenCode >= 2.0 dropped the V1 function-export style and requires a default export of the shape { id, setup(ctx) }. All plugin behavior is preserved; only the registration surface changed.

Changes

  • Plugin entry (src/index.ts): default export { id, setup(ctx) }.
    • Tools register via ctx.tool.transform (JSON Schema, returning { content }).
    • execute.before / execute.after via ctx.tool.hook.
    • System digest via session.hook("context").
    • Memory-first injection via session.hook("prompt").
    • Compaction rollup via session.hook("compaction").
    • /repo-init via the commands-dir mirror.
    • Live repo root from ctx.location.directory.
  • Business logic unchanged: the decoupled helper modules still own the actual work, so the V2 surface stays thin.
  • Tests: new test/harness.ts provides a fake V2 ctx so the suite drives the new surface directly; existing tests updated accordingly.

Test plan

  • bun test — 74 pass, 4 skip, 0 fail (323 assertions, 78 tests across 11 files)
  • bunx tsc --noEmit -p tsconfig.json — clean

OpenCode >= 2.0 dropped the V1 function-export plugin API and requires a default export { id, setup(ctx) }. The plugin now registers tools via ctx.tool.transform (JSON Schema, returning { content }); execute.before/after via ctx.tool.hook; system digest via session.hook("context"), memory-first injection via session.hook("prompt"), compaction rollup via session.hook("compaction"); /repo-init via the commands-dir mirror; live root from ctx.location.directory. Business logic stays in the decoupled helper modules. Tests drive the V2 surface through a new test/harness.ts fake ctx (74 pass; typecheck clean).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant