Skip to content

feat: add OpenCode V2 plugin adapter - #9

Open
Mirr0ch1 wants to merge 1 commit into
sdwolf4103:mainfrom
Mirr0ch1:feat/opencode-v2
Open

Mirr0ch1 wants to merge 1 commit into
sdwolf4103:mainfrom
Mirr0ch1:feat/opencode-v2

Conversation

@Mirr0ch1

@Mirr0ch1 Mirr0ch1 commented Oct 20, 2026 •

Copy link
Copy Markdown

Summary

OpenCode V2 replaced the V1 plugin API. The current package fails to load on V2 with:

Plugin must export a default definition with an id and an effect or setup function.
(Missing key at ["default"]["effect"], Missing key at ["default"]["setup"])

This PR adds a V2 adapter while keeping the existing V1 implementation working from the same package.

What changed

  • Extracted host-agnostic memory behavior into src/runtime.ts.
  • src/plugin.ts is now the V1 adapter (same hooks and behavior as before).
  • Added src/plugin-v2.ts using Plugin.define({ id, setup }).
  • Ported the /memory TUI command to the V2 keymap/dialog APIs in src/tui-plugin.ts; the legacy TUI implementation remains in src/tui-plugin-v1.ts.
  • Added tui.ts beside index.ts so V2 discovers the TUI entrypoint for local directory plugins. Published packages expose the same module through exports["./tui"].
  • index.ts exports both shapes: setup for V2 and server for V1.
  • Kept the on-disk memory format and storage paths unchanged, so existing workspace memory and session state keep working.

V2 hook mapping

V1 V2
experimental.chat.system.transform ctx.session.hook("context"), pushing text system parts
tool.execute.after ctx.tool.hook("execute.after")
experimental.session.compacting ctx.session.hook("compaction")
event (session.compacted) ctx.event.subscribe() (session.compaction.ended)

V2 behavior notes

  • Compaction prompt: V2 has no field for replacing the compaction prompt. The plugin keeps OpenCode's prompt and appends its memory rules and numbered [M#] refs as a system part. Memory extraction is equivalent and still makes no extra LLM call.
  • Todos: V2 has no session todo read API. The plugin records todowrite snapshots in session state and renders them during compaction.
  • Tool names and inputs: V2 uses shell instead of bash, path instead of filePath, and metadata.exit for command status. All are handled.
  • Sub-agents: still skipped via session.parentID.

Verification

  • npm run typecheck
  • npm run build
  • npm run check:package-integrity
  • npm test: 548 passing, including 11 new V2 adapter/TUI tests
  • Live OpenCode 2.1.1: GET /api/plugin reports working-memory with state.status: active
  • End-to-end with a local OpenAI-compatible mock provider: the actual agent-loop system prompt contains the seeded workspace memory text
  • TUI startup log: working-memory-tui reaches stage=setup and registers the /memory slash command

Compatibility

  • OpenCode V2 uses setup(ctx).
  • OpenCode V1 >= 1.18.29 supports the object entrypoint and uses server(input, options).
  • Older V1 releases can import the ./server export directly.
  • Existing memory data under ~/.local/share/opencode-working-memory/ is reused as-is.

The package version is bumped to 1.7.0; happy to drop that if you prefer to handle the release separately.

- extract host-agnostic memory behavior into src/runtime.ts
- add src/plugin-v2.ts using session/tool hooks and event subscription
- port /memory TUI command to the V2 keymap and dialog APIs
- export dual entrypoint: setup() for V2, server() for V1
- keep the existing on-disk memory format and storage paths
- track V2 todowrite snapshots for compaction context
@Mirr0ch1 Mirr0ch1 changed the title feat: add OpenCode V2 plugin adapter feat: add OpenCode V2 adapter and CodeBuddy memory bridge Oct 20, 2026
@Mirr0ch1 Mirr0ch1 changed the title feat: add OpenCode V2 adapter and CodeBuddy memory bridge feat: add OpenCode V2 plugin adapter Oct 21, 2026
@Mirr0ch1

Copy link
Copy Markdown
Author

Follow-up for reviewers: #10 builds on this branch and adds the CodeBuddy Code memory bridge. Please merge this PR first; #10 will then reduce to the bridge diff.

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