Conversation
The V2 setup registered neither tools nor commands with OpenCode: - Tools: `ptyTools` was exported but never passed to `ctx.tool.transform`, so no `pty_*` tool ever reached OpenCode. Issue shekohex#55 explicitly asked to "register PTY tools through the V2 tool transform/registration surface". - Commands: `registerV2Commands` called `draft.update(name, cb)`, but OpenCode v2's CommandEditor exposes `add(definition)` only. The guard `typeof draft.update === 'function'` therefore always short-circuited and the slash commands never appeared in the "/" menu. Adapts the V1 tool definitions ({ description, args, execute }) to V2 Tool.Info ({ name, input, description, execute }), registers them through ctx.tool.transform, and switches commands to draft.add() with an execute handler. Tests now assert real registration (mocking add()) instead of mere module-level existence.
opencode v2's Tool.Info expects a JSON Schema for `input` (see the plugins docs), not a Zod schema. Convert the V1 Zod args via Zod v4's `toJSONSchema` instead of passing the Zod object through.
Owner
|
CI needs fixing, overall looks good. Would be nice if you can post a small video of it. |
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.
Problem
The V2 entry point (
src/v2/index.ts) registers neither tools nor slash commands with OpenCode — silently, without any error:ptyTools(src/v2/tools.ts) is exported but never passed toctx.tool.transform, sopty_spawn/pty_write/pty_read/pty_list/pty_killnever reach OpenCode. Issue Plan OpenCode V2 plugin API support #55 explicitly listed "Register PTY tools through the V2 tool transform/registration surface" as part of the port.registerV2Commandscallsdraft.update(name, cb), but OpenCode v2'sCommandEditoronly exposesadd(definition). The guardtypeof draft.update === 'function'therefore always short-circuits, andpty-open-background-spy/pty-show-server-urlnever appear in the/menu.The existing tests did not catch this because they mocked a draft that happened to implement
update, and only asserted module-level existence ofptyTools.Fix
src/v2/tools.ts: addregisterV2Tools(draft), adapting the V1 tool definitions ({ description, args, execute }) to V2Tool.Info({ name, input, description, execute }). TheargsZod shape is converted to a JSON Schema via Zod v4'stoJSONSchema, matching the plugins documentation.src/v2/commands.ts:registerV2Commandsnow usesdraft.add({ name, description, execute }).src/v2/index.ts:setupcallsctx.tool.transform(registerV2Tools)in addition to the command transform.src/v2/types.ts: remove the non-existentupdatedraft method; addCommandDefinition,ToolInfoV2andToolDraft.add()(which is what OpenCode actually provides), for both tools and commands.Verification
bun run typecheck— cleanbun test test/v2.test.ts test/opencode-v2-live.test.ts— 11 pass / 0 failbun run lint— clean@opencode-ai/plugin@0.0.0-beta-19271): all fivepty_*tools are visible to the agent, both slash commands appear in the/menu, and/pty-open-background-spystarts the web UI with live sessions.Refs #55.