Skip to content

fix(opencode): use current plugin hook API - #949

Open
logan683 wants to merge 2 commits into
tirth8205:stagingfrom
logan683:fix/opencode-plugin-api
Open

logan683 wants to merge 2 commits into
tirth8205:stagingfrom
logan683:fix/opencode-plugin-api

Conversation

@logan683

@logan683 logan683 commented Sep 1, 2026

Copy link
Copy Markdown

Pull Request

Linked issue

Closes #947

What & why

OpenCode's current plugin API calls a plugin factory with its context and expects the factory to
return a hooks object. The generated CRG plugin instead called the removed app.on(...) API, so
OpenCode failed to load it on every startup and none of its three behaviors registered.

This change:

  • routes file.edited and session.created through OpenCode's generic event hook;
  • returns the named tool.execute.before hook and reads the current
    input.tool / output.args.command arguments;
  • invokes each CRG command as a literal Bun shell template, removing the unused dynamic-command
    helper that would have escaped a whole command as one executable name;
  • passes OpenCode's active directory through --repo on every command, so a global plugin cannot
    update or query the process cwd or another repository;
  • preserves graceful failure behavior and the existing console-visible status/pre-commit output;
  • adds a regression test that forbids app.on( and pins the returned-hooks shape.

console.log status remains user-visible console output; this PR does not claim or add model-context
injection.

Because the plugin now loads for the first time, its existing per-file update behavior and awaited
pre-commit analysis are also live for the first time. Debouncing updates and bounding pre-commit
latency are follow-up hardening work, not changes to this compatibility fix; the anchored
git commit matcher is likewise preserved from the existing generator.

How it was tested

uv run pytest tests/test_skills.py -k OpenCodePlugin -q
18 passed, 193 deselected

uv run pytest tests/test_skills.py -q -k "not test_post_tool_use_command_handles_large_stdin_payload"
208 passed, 1 skipped, 1 deselected

uv run --with "ruff>=0.3,<1" ruff check code_review_graph/
All checks passed!

uv run --with "mypy>=1.10,<3" mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
Success: no issues found in 72 source files

Runtime checks on OpenCode 1.18.25:

  • imported the generated TypeScript with Bun and invoked all three hooks; observed exactly
    status, update --skip-flows, and detect-changes --brief;
  • regenerated the user plugin from the patched installer and started a fresh OpenCode/Qwen session;
    no app.on is not a function load error occurred;
  • replaced CRG on PATH with a status canary and confirmed the status line appears in the
    opencode run console;
  • captured that canary's real arguments and confirmed OpenCode 1.18.25 supplies the active directory
    as status --repo <active-directory>.

The full suite on Windows reported 2,914 passed, 60 failed, 21 skipped, 2 xpassed. The failures are
outside the touched OpenCode generator/tests and are Windows/environment cases (path separator
expectations, unavailable symlink privilege, WSL /bin/bash, and file-mode behavior). The focused
OpenCode suite, package lint, type check, and live client checks are green.

Checklist

  • Tests added for new functionality
  • All tests pass: uv run pytest tests/ --tb=short -q — Windows/environment failures disclosed above
  • Linting passes: uv run ruff check code_review_graph/
  • Type checking passes: uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
  • Lines are at most 100 characters
  • Docs updated where behavior changed (CHANGELOG.md and generator docstring/comments)

@tirth8205

Copy link
Copy Markdown
Owner

Blocked pending a released OpenCode run: passing generated-string tests does not establish that the returned hooks are discovered or invoked. Install the plugin, open two repositories, then trigger a session, file edits and a commit in each; verify the active directory, single refresh invocation and bounded completion of the awaited update and pre-commit commands. The local 18-test result establishes template output only.

@tirth8205
tirth8205 changed the base branch from main to staging September 15, 2026 13:10
@tirth8205

tirth8205 commented Sep 15, 2026

Copy link
Copy Markdown
Owner

This no longer merges into staging. Conflicts in CHANGELOG.md.

git fetch origin && git merge origin/staging
# resolve, then
uv run pytest tests/ -q
uv run ruff check code_review_graph/
uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
git push

When resolving:

  • Rebase or merge origin/staging into fix/opencode-plugin-api and resolve the CHANGELOG.md [Unreleased] conflict (keep both staging's entries and the PR's 6-line OpenCode fix entry).
  • After the conflict is resolved, gates (pytest on 3.13, ruff, mypy) and edge-case coverage of the new OpenCode plugin generator (_opencode_plugin_content) still need to be assessed; they were not evaluated in this run.

A large integration branch landed on staging today, which is why this drifted.

PRs now target staging, not main. Yours was retargeted already, so nothing to do there.

@tirth8205

Copy link
Copy Markdown
Owner

This no longer merges into staging. The one conflict is CHANGELOG.md, and the branch is 224 commits behind.

All of it is prose, so taking staging's text and re-applying your lines on top should be the whole job.

git fetch origin
git merge origin/staging
# resolve, then
uv run pytest tests/ -q
uv run ruff check code_review_graph/
uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
git push

I have not reviewed the change itself yet. That comes once it merges and the checks run against the merged state, since staging has moved a long way and the result is what matters.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase Branch no longer merges into staging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: opencode plugin template uses removed app.on API — fails on every startup

2 participants