Skip to content

fix: restore OpenCode plugin support for v2 events#257

Open
x22x22 wants to merge 2 commits into
wxtsky:mainfrom
x22x22:fix/opencode-v2-plugin-events
Open

fix: restore OpenCode plugin support for v2 events#257
x22x22 wants to merge 2 commits into
wxtsky:mainfrom
x22x22:fix/opencode-v2-plugin-events

Conversation

@x22x22

@x22x22 x22x22 commented Jul 10, 2026

Copy link
Copy Markdown

Background

Recent OpenCode versions emit newer plugin events such as session.next.*, permission.v2.*, and question.v2.*. The existing CodeIsland OpenCode plugin only mapped the older event names and also still used CommonJS require() inside an ESM plugin module, which can prevent the plugin from loading in newer OpenCode runtimes.

Behavior Before The Fix

  • OpenCode sessions could fail to appear or update in the CodeIsland notch panel.
  • Tool activity, permission prompts, and question prompts from newer OpenCode events were not mapped into CodeIsland hook events.
  • The local OpenCode plugin could fail during plugin loading because require is unavailable in the ESM execution path.
  • Installed OpenCode plugins using older CodeIsland plugin versions were not forced to refresh to the fixed implementation.

Behavior After The Fix

  • CodeIsland maps newer OpenCode session.next.* events into existing session lifecycle, prompt, tool, compaction, and completion hook events.
  • CodeIsland maps permission.v2.* and question.v2.* events into the existing permission/question UI flow while preserving compatibility with older OpenCode event names.
  • The local OpenCode plugin uses ESM imports only, so it loads correctly in newer OpenCode plugin runtimes.
  • Local and remote OpenCode plugin version markers are bumped so installed plugins are automatically repaired/reinstalled from the updated app bundle.

Unit Test / Verification List

  • node --check Sources/CodeIsland/Resources/codeisland-opencode.js
  • node --check Sources/CodeIsland/Resources/codeisland-opencode-remote.js
  • swift build -c release --arch arm64

Copilot AI review requested due to automatic review settings July 10, 2026 06:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates CodeIsland’s bundled OpenCode plugins to recognize newer OpenCode v2 event names and ensures the local plugin loads correctly as ESM. It also bumps plugin version strings so CodeIsland will auto-repair/update installed plugin files.

Changes:

  • Add handling for new OpenCode event families (session.next.*, permission.v2.*, question.v2.*) in both local and remote plugins.
  • Convert the local plugin away from require() to ESM imports.
  • Bump local and remote OpenCode plugin version markers in Swift installers to trigger reinstallation/repair.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
Sources/CodeIsland/Resources/codeisland-opencode.js Adds support for new OpenCode v2 events and migrates implementation to ESM imports.
Sources/CodeIsland/Resources/codeisland-opencode-remote.js Extends remote event forwarding to handle the same new OpenCode v2 events.
Sources/CodeIsland/RemoteInstaller.swift Bumps the remote plugin version string to force remote plugin refresh.
Sources/CodeIsland/ConfigInstaller.swift Bumps the local plugin version string to force local plugin refresh.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return base(islandSessionId(p.info.id), { hook_event_name: "SessionStart", cwd });
}
if (t === "session.deleted" && p.info) {
sessions.delete(p.info.id); sessionCwd.delete(p.info.id);

@x22x22 x22x22 Jul 10, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted. This makes sessionCwd cleanup consistent with the key used when storing cwd entries, without changing the intended behavior. I updated the deletion to use sessionKey(p.info.id) and verified the change.

if (p.info.directory) sessionCwd.set(p.info.id, p.info.directory);
if (p.info.directory || p.info.location?.directory) setCwd(p.info.id, p.info.directory || p.info.location?.directory);
if (p.info.time?.archived) {
sessions.delete(p.info.id); sessionCwd.delete(p.info.id);

@x22x22 x22x22 Jul 10, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted. The archived-session cleanup path should use the same key normalization as the write path to avoid stale cwd entries. I updated it and verified the change.

}
if (t === "session.deleted" && p.info) {
sessions.delete(p.info.id);
sessionCwd.delete(p.info.id);

@x22x22 x22x22 Jul 10, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted. The remote plugin now also deletes sessionCwd entries with sessionKey(p.info.id), matching the setCwd behavior. Verified as part of the update.

if (p.info.directory || p.info.location?.directory) setCwd(p.info.id, p.info.directory || p.info.location?.directory);
if (p.info.time?.archived) {
sessions.delete(p.info.id);
sessionCwd.delete(p.info.id);

@x22x22 x22x22 Jul 10, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted. The remote plugin archived-session cleanup now uses sessionKey(p.info.id) as well, preventing stale entries from key mismatches.

@x22x22 x22x22 changed the title fix: support new OpenCode plugin events fix: restore OpenCode plugin support for v2 events Jul 10, 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.

2 participants