Repository navigation
Conversation
OpenCode V2 requires a plugin's default export to have an `id` plus a
`setup` (or `effect`) function. This package only exported the V1
`{ id, server }` shape, so it failed to load on V2 with:
Plugin must export a default definition with an id and an effect or
setup function.
V2 also renamed or restructured every server endpoint this plugin
uses (session creation/messages/prompt, the permission reply
endpoint, and the SSE event stream), so a V2 `setup()` cannot just
call the existing V1 `server()` body unchanged.
This adds a `createV2Backend`/`createV1Backend` pair implementing a
shared `SlackAgentBackend` interface, and ports `handleMessage`,
`syncAssistantMessagesSinceCursor`, and `handleCommand` to it instead
of calling `pluginClient` directly. The package now default-exports
both a V2 `setup()` and the original V1 `server()`, following
OpenCode's documented dual-support pattern, so it keeps working on V1
hosts.
Known gaps on V2 (see README "OpenCode V2" section):
- Replying to the agent's `question` tool from Slack is not supported;
the V2 plugin API has no reachable way to answer it.
- Plan/todo updates render as a generic tool-progress line instead of
a formatted checklist (V2 removed the `todo.updated` event).
- `!agent`/`@agent` overrides switch the session's agent going
forward instead of applying to one message only.
Also:
- Added a `slack_test_prompt` debug tool that exercises session
creation, prompting, and turn-event handling without a Slack
connection, for verifying this plugin against a real server.
- Removed the unused `better-sqlite3` dependency (not referenced
anywhere in `src/`); its native build fails under newer Node
versions and was blocking `npm install` for development.
Fixes leecoder#13
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #13.
opencode-slack-agentfails to load on OpenCode V2 with:V2 requires the default export to have an
idplussetup()(oreffect()). Thispackage only exported the V1
{ id, server() }shape.V2 also renamed or restructured every server endpoint this plugin calls (session
creation, session messages, prompt, the permission-reply endpoint, and the SSE event
stream shape), confirmed against a live OpenCode
2.2.5server's/openapi.jsonandthe
@opencode/plugin/@opencode/clienttype definitions. Asetup()that justre-ran the existing V1
server()body unchanged would not have worked.What changed
SlackAgentBackendinterface with two implementations:createV1Backend(client)— wraps the V1PluginInput["client"]SDK, sameendpoints the plugin already called.
createV2Backend(ctx)— wraps a V2setup(ctx)context:ctx.session.create/.context/.prompt/.switchAgent/.switchModel,ctx.event.subscribe()'sgranular
session.tool.*/session.reasoning.*/permission.askedlifecycleevents (replacing V1's single flat
message.part.updatedevent), andctx.permission.reply.handleMessage,syncAssistantMessagesSinceCursor, andhandleCommandtocall
backend.*instead ofpluginClient.*directly, so the Slack-facing behavior(formatting, session store, slash commands, background-task polling) is unchanged
and shared between both backends.
src/v2-adapter.tsholds the pure V2-message-shape → legacy-shape mapping, unittested in isolation (
bun test).pattern:
{ ...Plugin.define({ id, setup }), server }.slack_test_promptdebug tool (alongside the existingslack_status) thatruns
handleMessagewithout a Slack connection, so this plugin can be verifiedagainst a real server without a Slack workspace.
better-sqlite3dependency (not referenced anywhere insrc/).Its native build failed under newer Node versions and was blocking
npm install/bun installfor local development; this was pre-existing and unrelated to the V2fix, but unblocking installs was necessary to work on this PR at all.
Known gaps on V2 (documented in README's new "OpenCode V2" section)
questiontool replies are not forwarded. The V2 plugin context has noctx.session.form.*(confirmed against theSessionDomaintype, which onlyPicks a specific method list that excludesform), which is what would be neededto answer the agent's
questiontool from outside. Forwarding the question toSlack still works; the bot now tells the user to answer in the OpenCode session
directly instead of silently dropping the Slack reply.
todo.updatedevent; thetodotool now surfaces through the same generictool-call lifecycle as any other tool, so it renders as a plain 🔧 progress line.
!agent/@agentoverrides become sticky for the session (ctx.session.switchAgentchanges the session's default going forward) instead of applying to only the one
message, because V2 has no per-message agent override on
session.prompt.Testing
bun test— unit tests for the V2 message-shape mapping (src/v2-adapter.ts),written before the implementation (red, then green).
npx tsc --noEmitandnpm run build— clean.2.2.5server (opencode serve) in ascratch project, with this branch loaded as a local plugin path:
GET /api/pluginshows this plugin"status": "active", confirmed side-by-sidein the same response against the unpatched
opencode-slack-agent@latestnpmpackage, which shows the exact reported
"status": "failed"with the exactreported error message.
slack_test_promptdebug tool through a real session/prompt.Plugin logs confirm the full path executed against the live V2 server: session
created via
ctx.session.create, prompt sent viactx.session.prompt, turnevents subscribed via
ctx.event.subscribe, idle detected, and the assistant'sfinal message correctly fetched and mapped back via
ctx.session.context+mapSessionMessageToLegacyShape.This is a draft because the known gaps above (especially
questiontool replies)have not been exercised against a real Slack workspace, only against the OpenCode
server directly. I'd like feedback on the
question-tool gap in particular beforemerging — happy to adjust the approach if there's a plugin-reachable API for it I
missed.
Summary by cubic
Fixes the plugin failing to load on OpenCode V2 by adding V2 API support alongside the existing V1 path. The default export now includes both a V2
setup()and the original V1server(), so the package works on both host versions.SlackAgentBackendinterface withcreateV1Backend(wraps the V1 SDK client) andcreateV2Backend(wraps the V2setup(ctx)context), and ports message handling, session syncing, and commands to use it. Slack-facing behavior (formatting, session store, slash commands, background-task polling) is unchanged and shared.src/v2-adapter.ts, unit tested withbun test.slack_test_promptdebug tool that exercises the full session/prompt/turn-event path without a Slack connection, for verifying against a real server.better-sqlite3dependency, which was blocking installs under newer Node versions.testscript (bun test) topackage.json.Known gaps on V2
questiontool is not supported; the V2 plugin API has no reachable way to answer it, so the bot tells the user to answer in the OpenCode session.todo.updatedevent).!agent/@agentoverrides switch the session's agent going forward instead of applying to a single message.Written for commit c4451aa. Summary will update on new commits.