Repository navigation
fix(ai-hook): support OpenCode v2 plugin lifecycle #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7a3774f
fix(ai-hook): support OpenCode v2 plugin lifecycle
WilliamWang1721 3b05a80
Merge branch 'main' into fix/opencode-v2-hook
WilliamWang1721 82445a5
Merge upstream main into fix/opencode-v2-hook
WilliamWang1721 0349cc0
Merge upstream main into fix/opencode-v2-hook
WilliamWang1721 fde173e
Merge upstream main into fix/opencode-v2-hook
WilliamWang1721 372770f
Merge upstream main into fix/opencode-v2-hook
WilliamWang1721 7702696
Merge branch 'main' into fix/opencode-v2-hook
WilliamWang1721 dbf325f
Merge branch 'main' into fix/opencode-v2-hook
WilliamWang1721 3a1c67c
Merge branch 'main' into fix/opencode-v2-hook
WilliamWang1721 bf479d8
Merge upstream main into fix/opencode-v2-hook
WilliamWang1721 c7846af
Merge upstream main into fix/opencode-v2-hook
WilliamWang1721 4ee0204
Merge upstream main into fix/opencode-v2-hook
WilliamWang1721 d130b28
Merge upstream main into fix/opencode-v2-hook
WilliamWang1721 7f75edf
docs(ai-hook): record OpenCode V2 lifecycle
WilliamWang1721 241ede0
Merge remote-tracking branch 'origin/main' into fix/opencode-v2-hook
WilliamWang1721 efe96db
Merge upstream main into fix/opencode-v2-hook
WilliamWang1721 a6d8f76
Merge branch 'main' into fix/opencode-v2-hook
Kuddev 2629291
Merge branch 'main' into fix/opencode-v2-hook
WilliamWang1721 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: OpenCode notification bridge | ||
|
|
||
| on: | ||
| push: | ||
| paths: | ||
| - nebula_app/res/hooks/opencode.js | ||
| - scripts/tests/opencode-notification-bridge.test.mjs | ||
| - .github/workflows/opencode-bridge.yml | ||
| pull_request: | ||
| paths: | ||
| - nebula_app/res/hooks/opencode.js | ||
| - scripts/tests/opencode-notification-bridge.test.mjs | ||
| - .github/workflows/opencode-bridge.yml | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| bridge: | ||
| name: OpenCode bridge (${{ matrix.os }}) | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-24.04, windows-2022, macos-14] | ||
| runs-on: ${{ matrix.os }} | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
| - uses: oven-sh/setup-bun@v2 | ||
| with: | ||
| # Match the runtime used by OpenCode v2.0.18. | ||
| bun-version: '1.4.2' | ||
| - name: Node bridge regression tests | ||
| run: node --test scripts/tests/opencode-notification-bridge.test.mjs | ||
| - name: Bun bridge regression tests | ||
| run: bun test scripts/tests/opencode-notification-bridge.test.mjs |
63 changes: 63 additions & 0 deletions
63
architecture/notes/nebula_app/ai_hook/2026-09-28-opencode-v2-plugin-lifecycle.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # OpenCode V2 notification lifecycle | ||
|
|
||
| ## Status | ||
|
|
||
| Proposed in PR #298; maintainer review pending. | ||
|
|
||
| ## Context | ||
|
|
||
| The generated OpenCode hook must keep the existing V1 server entrypoint while | ||
| supporting V2's default plugin definition and async event subscription. Both paths | ||
| must feed the same Pebrel notification reducer and helper protocol. A V2 plugin | ||
| may be unloaded while its event stream or helper delivery is still pending. | ||
|
|
||
| ## Evidence | ||
|
|
||
| - OpenCode v2.0.18 validates a default plugin definition with an `id` and an | ||
| `effect` or `setup` entrypoint: [loader](https://github.com/anomalyco/opencode/blob/v2.0.18/packages/core/src/plugin/module.ts). | ||
| - V2's Promise plugin event domain reuses the generated client Event API. In | ||
| v2.0.18, `event.subscribe` takes one optional request-options argument; it has | ||
| no query argument: [plugin event type](https://github.com/anomalyco/opencode/blob/v2.0.18/packages/plugin/src/promise/event.ts), | ||
| [generated event client](https://github.com/anomalyco/opencode/blob/v2.0.18/packages/client/src/promise/generated/client.ts#L1660). | ||
| - The bridge's regression suite exercises the installed ESM export, V1 and V2 | ||
| event mapping, cleanup, and helper argument delivery. | ||
|
|
||
| ## Decision | ||
|
|
||
| Keep one default object with `id`, the V1 `server` entrypoint, and the V2 `setup` | ||
| entrypoint. `setup` subscribes with | ||
| `ctx.event.subscribe({ signal: controller.signal })`, translates only the required | ||
| V2 lifecycle events, and forwards them through the existing reducer. Its cleanup | ||
| aborts the subscription and helper process and waits for queued delivery to end. | ||
|
|
||
| ## Rejected alternatives | ||
|
|
||
| - Separate V1 and V2 hook files would duplicate lifecycle mapping and risk two | ||
| active bridge instances. | ||
| - Passing a query and request options separately does not match the pinned V2 | ||
| event API; other generated client operations use that two-argument shape, but | ||
| `event.subscribe` does not. | ||
| - Replacing the reducer with V2-specific notification state would create a | ||
| second authority for session lifecycle and ordering. | ||
|
|
||
| ## Consequences | ||
|
|
||
| V1 and V2 remain adapters over the same notification payload and process helper. | ||
| V2 cleanup owns both the stream and any pending helper work. When OpenCode changes | ||
| its plugin export or event schema, the generated hook and focused bridge workflow | ||
| must be checked against that release before widening the supported version range. | ||
|
|
||
| ## Validation | ||
|
|
||
| The Node/Bun workflow runs the focused bridge suite on Linux, Windows, and macOS. | ||
| The suite covers the installed module and cleanup contract; it does not claim a | ||
| full OpenCode UI or SSH end-to-end run. | ||
|
|
||
| ## Supersedes | ||
|
|
||
| None. | ||
|
|
||
| ## Revisit when | ||
|
|
||
| Revisit if V1 support is dropped, the pinned V2 event API changes, or the Pebrel | ||
| helper protocol no longer owns notification delivery and ordering. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.