Repository navigation
fix(opencode): load bundled skills on OpenCode v2 and run v2 prompt context concurrently - #7582
Conversation
The v2 entrypoint called draft.source() on the skill editor, which the OpenCode v2 plugin API does not have (the editor exposes list/get/add/ update/remove). It was also unreachable: the host batches plugin setup, so the MCP transform callback had not run yet and `registered` was still false when the skill transform was gated on it. The bundled skills were never loaded. Read the bundled SKILL.md files at setup and add them through the public editor in a transform registered at setup time, reading the MCP decision inside the callback. A missing directory or unparsable skill is logged and skipped so it cannot throw into setup and disable the plugin. Co-authored-by: stefanielizeth73-art <240744009+stefanielizeth73-art@users.noreply.github.com>
prepareV2Prompt awaited the session-start injection before starting recall, so the first prompt of each v2 session waited for both round trips back to back while the prompt hook held the message. The v1 chat.message path already runs them together. Start both at once, keep each failure logged on its own, and keep the session block before the recall block.
There was a problem hiding this comment.
🟡 Changes recommended
Skill registration checks only IDs, so a project skill with the same name but a different ID can be duplicated instead of preserved as an override.
1 open issue
What changed in this PR
This PR fixes bundled skill loading in the OpenCode v2 integration and reduces prompt latency by running session-context retrieval and memory recall concurrently, leaving the v1 path unchanged.
Changes:
- Loads bundled skills through the public skill editor, with deferred MCP enablement checks and contained file-loading failures.
- Runs both prompt-context requests concurrently while preserving block order and separate error logging.
- Adds regression tests and bumps the plugin version to
0.5.26.
| File | Description |
|---|---|
examples/opencode-plugin/tests/v2-plugin.test.mjs |
Tests public skill registration, deferred transforms, missing skills, and prompt concurrency. |
examples/opencode-plugin/package.json |
Bumps the package version from 0.5.25 to 0.5.26. |
examples/opencode-plugin/lib/v2-plugin.mjs |
Implements bundled skill loading and concurrent prompt-context retrieval. |
Review effort: Balanced
ZaynJarvis
left a comment
There was a problem hiding this comment.
The fix uses the public OpenCode v2 SkillEditor contract, preserves disabled/same-name behavior, and keeps session context before recall while starting both requests concurrently. After syncing generated shared files, the full OpenCode suite passes locally (60/60) and the syntax check passes. No issues found.
ZaynJarvis
left a comment
There was a problem hiding this comment.
The v2 compatibility path is close, but the current skill dedupe only checks the bundled ID. A project skill with the same name and a different ID is then duplicated instead of overriding the bundled skill. Please dedupe against both existing IDs and names and add the regression case.
OpenCode v2 keys skills by ID only, and a directory skill's ID comes from
its folder while its name comes from frontmatter. A project skill such as
{ id: "project-memory", name: "openviking-memory" } passed the ID-only
check, so the bundled skill of the same name was listed next to it.
Skip bundled skills whose ID or name is already in the editor.
|
@ZaynJarvis Fixed in db1d7a8. Confirmed against the OpenCode source: a directory skill's ID comes from its folder name and its name from the frontmatter, and the host keys skills by ID only. So a project skill with the same name and a different ID was listed next to the bundled one. The transform now collects the IDs and names from |
ZaynJarvis
left a comment
There was a problem hiding this comment.
The same-name override case now deduplicates against both IDs and names, with a regression test. Full plugin tests pass locally (61/61), and syntax checks pass.
…ontext concurrently (volcengine#7582) * fix(opencode): register bundled skills through the v2 skill editor The v2 entrypoint called draft.source() on the skill editor, which the OpenCode v2 plugin API does not have (the editor exposes list/get/add/ update/remove). It was also unreachable: the host batches plugin setup, so the MCP transform callback had not run yet and `registered` was still false when the skill transform was gated on it. The bundled skills were never loaded. Read the bundled SKILL.md files at setup and add them through the public editor in a transform registered at setup time, reading the MCP decision inside the callback. A missing directory or unparsable skill is logged and skipped so it cannot throw into setup and disable the plugin. Co-authored-by: stefanielizeth73-art <240744009+stefanielizeth73-art@users.noreply.github.com> * fix(opencode): run v2 session context and recall concurrently prepareV2Prompt awaited the session-start injection before starting recall, so the first prompt of each v2 session waited for both round trips back to back while the prompt hook held the message. The v1 chat.message path already runs them together. Start both at once, keep each failure logged on its own, and keep the session block before the recall block. * fix(opencode): let same-name user skills override bundled skills OpenCode v2 keys skills by ID only, and a directory skill's ID comes from its folder while its name comes from frontmatter. A project skill such as { id: "project-memory", name: "openviking-memory" } passed the ID-only check, so the bundled skill of the same name was listed next to it. Skip bundled skills whose ID or name is already in the editor. --------- Co-authored-by: stefanielizeth73-art <240744009+stefanielizeth73-art@users.noreply.github.com> (cherry picked from commit 297847c)

Description
Two small OpenCode v2 fixes in
examples/opencode-plugin/lib/v2-plugin.mjs, as two independently revertable commits.1. The bundled skills never load on OpenCode v2. #5525 added skill registration to the v2 entrypoint as
ctx.skill.transform((draft) => draft.source({ type: "directory", path })), gated on aregisteredflag set inside the MCP transform callback. Both parts are broken. First, the host wraps plugin setup inState.batch: inside a batch a transform is recorded but not run, so the MCP callback has not executed whenregisteredis checked and the skill transform is never registered. That is why the skills are silently missing. Second, even if it ran, the public OpenCode v2SkillEditoronly haslist/get/add/update/remove, andsource()does not exist. The host disables the whole plugin, MCP server included, when a transform throws. The unit test mock exposed a fakesource(), so CI could not catch either problem.The fix reads the bundled
skills/*/SKILL.mdfiles at setup withnode:fs/promisesand adds each one through the public editor (add({ id, name, description, path, content })). The skill transform is registered unconditionally at setup, and the callback reads the MCP decision each time the host runs it. A skill whose id already exists in the editor is left alone. A missing skills directory or an unparsableSKILL.mdis logged through the existing hook-error logger and skipped, so it cannot throw into setup or the transform. The frontmatter reader handles only the two shapes the bundled skills use (a plain scalar and a folded>block), and no dependency is added.2. The v2 prompt hook awaits session-start injection and recall one after the other. Since #5341,
prepareV2PromptawaitedbuildSessionContextbefore it startedbuildRelevantMemories, so the first prompt of each v2 session waited for both round trips back to back while the prompt hook held the message. #5149 already made the v1chat.messagepath run them concurrently, but the v2 path kept the serial form. Both calls now start together. Each failure is still logged under its own hook name, and the block order is unchanged: session context first, recall second.Human Involvement
Related Issue
Supersedes #5915, which identified the broken v2 skill registration and is credited as co-author of the first commit, and takes over the parallelisation part of #5496, which identified the serial wait in the v2 prompt hook. Related: #5900.
Type of Change
Changes Made
startV2Plugin: register the skill transform at setup, read the MCP-enabled decision inside the callback, and add the bundled skills via the publicSkillEditor.add.loadBundledSkills: read the bundledSKILL.mdfiles without a new dependency. A missing directory or an unparsable skill logs a WARN and is skipped.prepareV2Prompt: run session-start injection and recall withPromise.all, keeping per-call error logging and block order.add, a deferred transform replay with MCP enabled and disabled, a missing skills directory still registering MCP and hooks, and both prompt calls starting before either resolves with block order preserved.@openviking/opencode-pluginversion 0.5.25 → 0.5.26.Deliberately left out: the
yamldependency and the installernpm installstep from #5915. The two bundled frontmatter shapes are parsed directly, and the plugin keeps installing without npm. Also left out is the context-hook prefetch with a persisted ledger and the newrecallWaitMsoption from #5496. Parallelising the two calls removes the extra v2-only wait and matches v1, without new storage or options.Testing
node --test tests/*.test.mjsinexamples/opencode-plugin(clean env, Node 26): 60/60 pass.npm run checkpasses.check-plugin-version-bumps.sh origin/mainpasses. With the previousv2-plugin.mjs, 8 of the 12 tests inv2-plugin.test.mjsfail (draft.source is not a function, plus the deferred-replay cases). The new concurrency test fails against the serialprepareV2Prompt. This was not exercised in a real OpenCode v2 process: the local OpenCode is v1, so host behaviour (batched setup, transform replay order,addon a duplicate id) comes from reading the upstream host source, not from a run.Checklist
Screenshots (if applicable)
Additional Notes
The bundled skills are only added when the OpenViking MCP server is registered, same as before. In hook-only mode, or when the user disabled the
openvikingMCP entry, no skills are added.