fix: restore OpenCode plugin support for v2 events#257
Conversation
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Accepted. The remote plugin archived-session cleanup now uses sessionKey(p.info.id) as well, preventing stale entries from key mismatches.
Background
Recent OpenCode versions emit newer plugin events such as
session.next.*,permission.v2.*, andquestion.v2.*. The existing CodeIsland OpenCode plugin only mapped the older event names and also still used CommonJSrequire()inside an ESM plugin module, which can prevent the plugin from loading in newer OpenCode runtimes.Behavior Before The Fix
requireis unavailable in the ESM execution path.Behavior After The Fix
session.next.*events into existing session lifecycle, prompt, tool, compaction, and completion hook events.permission.v2.*andquestion.v2.*events into the existing permission/question UI flow while preserving compatibility with older OpenCode event names.Unit Test / Verification List
node --check Sources/CodeIsland/Resources/codeisland-opencode.jsnode --check Sources/CodeIsland/Resources/codeisland-opencode-remote.jsswift build -c release --arch arm64