Skip to content

fix(opencode): load bundled skills on OpenCode v2 and run v2 prompt context concurrently - #7582

Merged
t0saki merged 3 commits into
volcengine:mainfrom
t0saki:fix/opencode-v2-skills-and-prompt
Nov 13, 2026
Merged

t0saki merged 3 commits into
volcengine:mainfrom
t0saki:fix/opencode-v2-skills-and-prompt

Conversation

@t0saki

@t0saki t0saki commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

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 a registered flag set inside the MCP transform callback. Both parts are broken. First, the host wraps plugin setup in State.batch: inside a batch a transform is recorded but not run, so the MCP callback has not executed when registered is checked and the skill transform is never registered. That is why the skills are silently missing. Second, even if it ran, the public OpenCode v2 SkillEditor only has list/get/add/update/remove, and source() does not exist. The host disables the whole plugin, MCP server included, when a transform throws. The unit test mock exposed a fake source(), so CI could not catch either problem.

The fix reads the bundled skills/*/SKILL.md files at setup with node:fs/promises and 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 unparsable SKILL.md is 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, prepareV2Prompt awaited buildSessionContext before it started buildRelevantMemories, 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 v1 chat.message path 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

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

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

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • startV2Plugin: register the skill transform at setup, read the MCP-enabled decision inside the callback, and add the bundled skills via the public SkillEditor.add.
  • loadBundledSkills: read the bundled SKILL.md files without a new dependency. A missing directory or an unparsable skill logs a WARN and is skipped.
  • prepareV2Prompt: run session-start injection and recall with Promise.all, keeping per-call error logging and block order.
  • Tests: the skill editor mock now exposes only the public contract. New cases cover registering the bundled skills via 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-plugin version 0.5.25 → 0.5.26.

Deliberately left out: the yaml dependency and the installer npm install step 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 new recallWaitMs option from #5496. Parallelising the two calls removes the extra v2-only wait and matches v1, without new storage or options.

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

node --test tests/*.test.mjs in examples/opencode-plugin (clean env, Node 26): 60/60 pass. npm run check passes. check-plugin-version-bumps.sh origin/main passes. With the previous v2-plugin.mjs, 8 of the 12 tests in v2-plugin.test.mjs fail (draft.source is not a function, plus the deferred-replay cases). The new concurrency test fails against the serial prepareV2Prompt. This was not exercised in a real OpenCode v2 process: the local OpenCode is v1, so host behaviour (batched setup, transform replay order, add on a duplicate id) comes from reading the upstream host source, not from a run.

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

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 openviking MCP entry, no skills are added.

t0saki and others added 2 commits November 13, 2026 16:42
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.
@t0saki
t0saki marked this pull request as ready for review November 13, 2026 10:26
Copilot AI balanced review requested due to automatic review settings November 13, 2026 10:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 ZaynJarvis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ZaynJarvis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@t0saki

t0saki commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

@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 editor.list() and skips any bundled skill whose ID or name is already taken. A new registration test covers a same-name/different-ID skill and a same-ID/different-name skill; it fails on the previous commit.

@ZaynJarvis ZaynJarvis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@t0saki
t0saki merged commit 297847c into volcengine:main Nov 13, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Nov 13, 2026
oliver-mee pushed a commit to oliver-mee/OpenViking that referenced this pull request Nov 18, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants