Skip to content

Fix: emit OpenCode 2 plugin and drop stale config entry - #3792

Closed
kianhuat wants to merge 1 commit into
Graphify-Labs:v8from
kianhuat:fix/opencode-v2-plugin
Closed

kianhuat wants to merge 1 commit into
Graphify-Labs:v8from
kianhuat:fix/opencode-v2-plugin

Conversation

@kianhuat

Copy link
Copy Markdown

What does this PR do?

Fixes #3732.

OpenCode 2 does not run V1 plugin implementations. graphify install --platform opencode still wrote the V1 shape:

export const GraphifyPlugin = async ({ directory }) => ({
  "tool.execute.before": async (input, output) => { /* ... */ },
})

so the installed plugin fails to load with:

Plugin must export a default definition with an id and an effect or setup function.

OpenCode 2 requires a default export with an id and a setup(ctx) function, registers hooks on the owning domain (ctx.tool.hook("execute.before", ...)), names the command tool shell (not bash), and exposes the location as ctx.location.directory.

The V1 installer also registered the plugin in .opencode/opencode.json under the plugin key as a bare relative path:

{ "plugin": [".opencode/plugins/graphify.js"] }

OpenCode 2 treats a bare specifier as an npm package spec, tries to install it, and fails:

NpmInstallFailedError (cause: Error: Could not read package.json: Error: ENOTDIR: not a directory, open '.../.opencode/plugins/graphify.js/package.json')

OpenCode 2 already auto-discovers direct .js/.ts files under .opencode/plugins/, so no config entry is needed.

Changes

  • Port _OPENCODE_PLUGIN_JS to the V2 API: default export + setup(ctx), ctx.tool.hook("execute.before", ...), shell tool, ctx.location.directory.
  • Stop writing the .opencode/opencode.json entry; remove any legacy plugin/plugins entry on install and uninstall.
  • Update tests and the graphify --help description.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

How was this tested?

uv run --frozen python -m pytest tests/test_install.py tests/test_install_strings.py tests/test_install_references.py -q
# 131 passed, 1 skipped

uv run --frozen ruff check graphify/install.py graphify/__main__.py tests/test_install.py
# All checks passed!

Manual, on OpenCode 2.0.15:

graphify install --platform opencode      # from a project dir
opencode plugin list
# ID        VERSION  SOURCE
# graphify  local    .../.opencode/plugins/graphify.js

opencode api get /api/plugin              # graphify: active, 0 failed plugins

The shell reminder still fires: a shell command returned the [graphify] reminder line when graphify-out/graph.json existed.

Graphify-specific checklist

  • I added or updated tests for behavior changes.
  • I updated documentation or confirmed that no documentation is needed. (No docs reference the plugin internals; the CLI help text was updated.)
  • I updated generated skill artifacts when changing their source fragments. (N/A — the plugin template is not embedded in skill artifacts.)
  • I considered compatibility across supported Python versions.
  • I confirmed that no API keys, generated graph data, or local-only files are included.

OpenCode 2 does not run V1 plugin implementations. It requires a default export with an id and a setup(ctx) function and registers hooks on the owning domain, and it names the command tool 'shell'. graphify install --platform opencode still wrote the V1 GraphifyPlugin / "tool.execute.before" shape, so the plugin failed to load with: Plugin must export a default definition with an id and an effect or setup function.

The V1 installer also registered the plugin in .opencode/opencode.json under the 'plugin' key as a bare relative path (.opencode/plugins/graphify.js). OpenCode 2 treats a bare specifier as an npm package, tries to install it, and fails (NpmInstallFailedError: ENOTDIR .../graphify.js/package.json). OpenCode 2 already auto-discovers .opencode/plugins/, so no config entry is needed.

- Port _OPENCODE_PLUGIN_JS to the V2 API (default export + setup(ctx), ctx.tool.hook("execute.before", ...), shell tool, ctx.location.directory).

- Stop writing the config entry; remove any legacy plugin/plugins entry on install and uninstall.

- Update tests and the CLI help text.

@graphify-labs graphify-labs Bot 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.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

Migrates the OpenCode plugin from the V1 tool.execute.before map to the V2 API, default-exporting a definition with an id and setup(ctx) that registers the hook via ctx.tool.hook("execute.before") and matches both the V2 shell and legacy bash tool names. Drops config registration entirely since OpenCode 2 auto-discovers .opencode/plugins/, and _install_opencode_plugin now strips any stale V1 plugin/plugins entry (via _drop_opencode_plugin_config_entry) so the bare relative path can't be misread as an npm package spec and fail to load. Updates the CLI help text to say "shell hook plugin" and adjusts tests accordingly.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 555 functions depend on the 328 functions this change touches.

Health — this change adds coupling hotspots:

  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 125 callees
  • new: install() — 13 callers, 11 callees
  • new: codebuddy_install() — 20 callers, 5 callees
  • new: gemini_install() — 11 callers, 7 callees
  • new: claude_install() — 19 callers, 4 callees
  • new: _copy_skill_file() — 12 callers, 6 callees
  • new: claude_uninstall() — 17 callers, 4 callees
  • …and 15 more — each is listed as a finding

Verification — 555 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 555 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

31 of 300 test file(s) selected (10%) via static blast radius.

  • tests/test_affected_cli.py — impact
  • tests/test_agents_platform.py — impact
  • tests/test_atomic_version_stamp.py — impact
  • tests/test_claude_md.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_devin.py — impact
  • tests/test_explain_cli.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_gemini_hook.py — impact
  • tests/test_global_add_tag_inference.py — impact
  • tests/test_god_nodes_cli.py — impact
  • tests/test_hollow_chunks_arm_shrink_guard.py — impact
  • tests/test_home_sandbox.py — impact
  • tests/test_hook_strict.py — impact
  • tests/test_incomplete_build_guard.py — impact
  • tests/test_install.py — impact, changed-test
  • tests/test_install_references.py — impact
  • tests/test_install_strings.py — impact
  • tests/test_install_version_warning.py — impact
  • tests/test_merge_chunks_validation.py — impact
  • tests/test_multigraph_diagnostics.py — impact
  • tests/test_no_dedup_flag.py — impact
  • tests/test_path_cli.py — impact
  • tests/test_query_cli.py — impact
  • tests/test_query_induced_edges.py — impact
  • tests/test_read_hook.py — impact
  • tests/test_replace_or_append_section.py — impact
  • tests/test_search_hook.py — impact
  • tests/test_skill_version_warning.py — impact
  • tests/test_uninstall_scope.py — impact
  • tests/test_unverified_semantic_shrink.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

· 23 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Thanks @kianhuat. The OpenCode 2 plugin loading for #3732 already landed via #3554/#4039 (shipped in 0.9.84), and that version keeps a v1 server() entrypoint so one plugin works on both OpenCode 1 and 2. This PR drops v1 entirely, which would regress OpenCode 1 users, and is written against the pre-#4039 base so it no longer rebases. Closing as superseded.

@safishamsi safishamsi closed this Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenCode V2: installer emits a V1 plugin (fails to load) and registers it under the V1 "plugin" key

2 participants