Skip to content

fix(opencode): dual v1+v2 plugin + absolute file:// registration - #3896

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

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

Conversation

@coder-zhw

Copy link
Copy Markdown

What does this PR do?

graphify opencode install writes .opencode/plugins/graphify.js using only the v1 plugin API, so OpenCode v2 refuses to load it:

failed to load plugin <path> : Plugin must export a default definition with an id and
an effect or setup function (cause: SchemaError(Missing key at ["default"]))

The installer also registers the plugin in .opencode/opencode.json under the bare relative path ".opencode/plugins/graphify.js". OpenCode v2 resolves a bare specifier as an npm package spec and fails:

NpmInstallFailedError (cause: Error: Could not read package.json:
  ENOENT .../.opencode/plugins/graphify.js/package.json)

So on v2 the integration is dead on arrival — one error or the other fires from the directory you open OpenCode in.

Fixes both in one file:

  • Port _OPENCODE_PLUGIN_JS to a single dual entrypoint: a v2 default export ({ id, setup }) that prepends the reminder via ctx.shell.hook("create.before", event), plus the v1 named export ("tool.execute.before") kept alongside, so the same file still loads on v1. The v2 path walks up from the hook's event.cwd so the reminder also fires when the first command runs from a subdirectory.
  • Register the plugin by its resolved file:// URI (the form the Kilo installer already uses) instead of a bare relative path. Uninstall drops both the URI form and any legacy bare relative entry, so an old opencode.json cannot keep tripping v2's npm-spec resolution.

Refs #3554, #3732. Note: this overlaps #3819 (dual entrypoint) and #3792 (drop the stale config entry); this PR does both, keeps v1 compatibility, and registers the plugin explicitly rather than relying on auto-discovery.

Type of change

  • Bug fix

Verification & Invariants

The invariant: graphify opencode install must produce a plugin that loads and injects on both OpenCode v1 and v2, from any project directory, without leaving a config entry that v2 misparses.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant (both error strings above, reproduced on OpenCode 2.0.18, macOS).
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

How was this tested?

$ uv run pytest tests/test_install.py tests/test_install_strings.py -q
118 passed

# Regression tests fail on pre-fix (verified by stashing graphify/install.py):
$ uv run pytest tests/test_install.py -q -k "v2_default or absolute_file_uri or legacy_relative"
3 failed   # export default missing; entry was ".opencode/plugins/graphify.js"; NpmInstallFailedError

$ uv run ruff check graphify/install.py tests/test_install.py
All checks passed
$ uv run pyright graphify/install.py
0 errors

# Generated plugin validated:
$ python -c "from graphify.install import _OPENCODE_PLUGIN_JS as j; open('t.js','w').write(j)" && node --check t.js

End-to-end on OpenCode 2.0.18 (macOS): the plugin loads with no errors, and the reminder is injected into the first shell command — observed in the spawned process args:

message="spawning process" command=/bin/zsh args=["-c","echo \"[graphify] knowledge graph at
graphify-out/. ...\" ; echo FINAL_OK"] cwd=<project>

Also verified that both v2 hook shapes fire on 2.0.18 (ctx.shell.hook("create.before") in this PR; ctx.tool.hook("execute.before") used by #3792/#3819) and that a file:// entry, unlike a bare relative path, loads clean.

Pre-existing failures (unrelated): tests/ has ~19 failures in test_skillgen.py / test_solidity_extractor.py / test_vbnet_extractor.py that reproduce unchanged on a clean v8 checkout in this environment; none touch the opencode install path.

Graphify-specific checklist

`graphify opencode install` writes `.opencode/plugins/graphify.js` with only
the v1 plugin API, so OpenCode v2 refuses to load it:

    failed to load plugin <path> : Plugin must export a default definition with
    an id and an effect or setup function (Missing key at ["default"])

The installer also registers the plugin in `.opencode/opencode.json` under the
bare relative path ".opencode/plugins/graphify.js". OpenCode v2 resolves a bare
specifier as an npm package and fails:

    NpmInstallFailedError (cause: Could not read package.json: ENOENT ...)

Fix both, in one file:

- Port `_OPENCODE_PLUGIN_JS` to a single dual entrypoint: a v2 default export
  ({ id, setup }) that prepends the reminder via ctx.shell.hook("create.before"),
  plus the v1 named export ("tool.execute.before") kept alongside so the same
  file still loads on v1. The v2 path walks up from the hook cwd so the reminder
  also fires when the first command runs from a subdirectory.
- Register the plugin by its resolved file:// URI (the form the Kilo installer
  already uses) rather than a bare relative path. Uninstall drops both the URI
  form and any legacy bare relative entry, so an old config cannot keep tripping
  v2's npm-spec resolution.

Tests: the existing opencode install tests stay green; add regression coverage
for the v2 default export, the absolute file:// registration, and legacy-entry
cleanup on uninstall. The reminder policy is unchanged (Graphify-Labs#1413 backtick/$()-free,
Graphify-Labs#1646 ';' separator).

Verified end-to-end on OpenCode 2.0.18 (macOS): the plugin loads with no errors
and the reminder is injected into the first shell command (observed in the
spawned /bin/zsh args).

Refs Graphify-Labs#3554, Graphify-Labs#3732.

Co-Authored-By: Hermes Agent <[email protected]>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @coder-zhw. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

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

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.


Graphify review — findings

Makes the OpenCode plugin load on both OpenCode v1 and v2: the generated graphify.js now exports a v2 default definition ({ id, setup }) that rewrites the first bash command via ctx.shell.hook("create.before") alongside the existing v1 GraphifyPlugin named export, with the reminder string shared as REMINDER and graph detection walking up to 5 parent dirs. Registers the plugin in opencode.json as an absolute file:// URI instead of a bare relative path, since v2 mis-resolves the relative form as an npm package spec and fails. Extends uninstall to drop both the new file:// entry and legacy relative .opencode/plugins/graphify.js entries while preserving unrelated plugins.

Worth a look

  • OpenCode install leaves legacy relative plugin entry in config — graphify/install.py:1528 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Uninstall drops any plugin entry ending in 'plugins/graphify.js', including unrelated third-party plugins — graphify/install.py:1552 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 548 functions depend on the 316 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 — 548 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: 467 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

31 of 304 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 @coder-zhw. The dual v1+v2 plugin with location-keyed registration already shipped in 0.9.84 (via #3554/#4039). 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.

2 participants