Skip to content

feat: add OpenCode v2 plugin entrypoint (V2 compatible) - #41

Closed
scienceguy wants to merge 1 commit into
Mte90:masterfrom
scienceguy:master
Closed

scienceguy wants to merge 1 commit into
Mte90:masterfrom
scienceguy:master

Conversation

@scienceguy

Copy link
Copy Markdown

Summary

This PR adds OpenCode v2 compatibility to the auto-resume plugin by providing a V2 entrypoint (dist/v2.js) that wraps the existing V1 plugin factory.

Changes

  • New file: src/index-v2.ts - V2 plugin wrapper with { id, setup } schema
  • Updated: package.json - exports field and build script for V2 output
  • Build output: dist/v2.js - V2-compatible bundle

Technical Details

The V2 wrapper adapts the V1 function-form plugin (AutoResumePlugin(ctx, options)) to the V2 object-form schema ({ id, setup }). It shims the V1 context API:

V1 API V2 Shim
ctx.client.session.prompt() ctx.session.prompt()
ctx.client.session.messages() ctx.session.context()
ctx.client.session.abort() ctx.session.interrupt()
ctx.client.session.list() SQLite fallback (session_v2 table)
ctx.client.tool.ids() ctx.tool.list().map(t => t.id)
ctx.client.app.log() Console + RPC fallback
ctx.client.provider.get() ctx.provider.list() filter
ctx.client.config.get() Minimal empty config
ctx.event.subscribe() Direct passthrough

Hook registrations:

  • tool.execute.before → ctx.tool.hook('execute.before')
  • tool.execute.after → ctx.tool.hook('execute.after')
  • chat.message → ctx.session.hook('prompt')
  • event → ctx.event.subscribe() async iteration
  • config → Called on setup

Usage

In opencode.json:

{
  "plugins": [
    { "package": "opencode-auto-resume/v2", "options": { "chunkTimeoutMs": 180000, "debug": false } }
  ]
}

Or auto-discovered from .opencode/plugins/auto-resume/index.js pointing to the V2 entrypoint.

Testing

  • Built successfully with bun run build
  • Verified loading in OpenCode v2.0.18 (Android/Termux)
  • Session discovery, event subscription, and hook registration all functional

Closes #33 (OpenCode 2.x: fails to load — V1 entrypoint, no V2 setup(ctx))

…ility

- Add src/index-v2.ts with V2 {id, setup} schema
- Adapt V1 function-form plugin to V2 context API
- Export via package.json exports field (./v2)
- Build outputs to dist/v2.js
- Shim V1 client.session.*, client.tool.ids, client.app.log, etc. to V2 equivalents
- Register V1 hooks (tool.execute.before/after, chat.message, event) to V2 hook domains
@Mte90

Mte90 commented Oct 5, 2026

Copy link
Copy Markdown
Owner

This is the 3rd PR to add v2 support to this plugin, we are focusing on #37

@Mte90 Mte90 closed this Oct 5, 2026
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.

OpenCode 2.x: fails to load — V1 entrypoint, no V2 setup(ctx)

2 participants