Skip to content

feat: add OpenCode user-level plugin to install command#198

Open
imkarrer wants to merge 4 commits intotirth8205:mainfrom
imkarrer:feature/opencode-plugin
Open

feat: add OpenCode user-level plugin to install command#198
imkarrer wants to merge 4 commits intotirth8205:mainfrom
imkarrer:feature/opencode-plugin

Conversation

@imkarrer
Copy link
Copy Markdown

@imkarrer imkarrer commented Apr 9, 2026

Summary

  • Adds a user-level OpenCode plugin (~/.config/opencode/plugins/crg-plugin.ts) that mirrors all three Claude Code hook behaviors: auto-update graph after file edits, show graph status on session start, and detect changes before git commits
  • Plugin uses Bun's $ shell API and fails gracefully with try/catch since it's user-level and runs for all projects
  • Installed automatically when running install/init with --platform opencode or --platform all, unless --no-hooks is passed

Related Issues & PRs

Changes

code_review_graph/skills.py

  • _opencode_plugin_content() — returns TypeScript plugin source as a string, hooking into file.edited, session.created, and tool.execute.before events
  • install_opencode_plugin() — writes ~/.config/opencode/plugins/crg-plugin.ts, creating directories as needed

code_review_graph/cli.py

  • Calls install_opencode_plugin() in _handle_init() when target is all or opencode, gated by --no-hooks
  • Added logger module-level variable for consistent logging

tests/test_skills.py

  • 16 new tests across 2 test classes:
    • TestOpenCodePluginContent (8 tests): plugin content validation, event hooks, try/catch coverage, TypeScript structure
    • TestInstallOpenCodePlugin (8 tests): file creation, directory creation, overwrite behavior, idempotency, file integrity

Plugin Behaviors

OpenCode Event Behavior
file.edited Runs code-review-graph update --skip-flows
session.created Runs code-review-graph status and logs output
tool.execute.before (when command matches git commit) Runs code-review-graph detect-changes --brief and logs output

Testing

All 45 tests pass (29 existing + 16 new). Ruff and mypy clean.

Checklist (per CONTRIBUTING.md)

  • Feature branch: feature/opencode-plugin
  • Tests added for new functionality (16 new tests)
  • All tests pass: uv run pytest tests/test_skills.py (45/45)
  • Linting passes: ruff check with rules E, F, I, N, W
  • Type checking passes: mypy --ignore-missing-imports --no-strict-optional
  • Line length ≤ 100 characters
  • Python 3.10+ compatible

Isaac Karrer added 2 commits April 9, 2026 15:30
Install a TypeScript plugin (~/.config/opencode/plugins/crg-plugin.ts)
that mirrors the three Claude Code hook behaviors:

1. file.edited: auto-update graph via code-review-graph update --skip-flows
2. session.created: show graph status via code-review-graph status
3. tool.execute.before: detect changes before git commit commands

The plugin uses Bun's shell API and fails gracefully with try/catch
since it's user-level and runs for all projects. Installed when running
install/init with --platform opencode or --platform all, unless
--no-hooks is passed.

New functions in skills.py:
- _opencode_plugin_content(): returns TypeScript plugin source
- install_opencode_plugin(): writes plugin file, creates directories

16 new tests covering plugin content, event handlers, installation,
idempotency, and file integrity.
Use PLATFORMS['opencode']['detect']() guard for consistency with MCP
config install behavior. Currently detect() always returns True for
OpenCode, but this ensures the pattern stays consistent if that changes.
@tirth8205
Copy link
Copy Markdown
Owner

The OpenCode plugin is well-implemented. The TypeScript plugin correctly hooks into file.edited, session.created, and tool.execute.before events, uses try/catch throughout for graceful failure, and the install_opencode_plugin() function is idempotent (overwrites the file since the plugin is self-contained). The 16 tests in TestOpenCodePluginContent and TestInstallOpenCodePlugin provide thorough coverage.

The branch has merge conflicts with main (in code_review_graph/skills.py — the same file was modified by recently merged PRs). Please rebase onto main and resolve the conflicts. The OpenCode plugin section is appended at the end of skills.py, so this should be a clean resolution.

Once rebased, this is ready to merge.

@tirth8205
Copy link
Copy Markdown
Owner

Skipping auto-merge: after #142 (platform target filters) landed on main, this branch now conflicts on code_review_graph/cli.py, code_review_graph/skills.py, and tests/test_skills.py. Please rebase and resolve — the conflict is in the platform dict and install CLI glue.

# Conflicts:
#	code_review_graph/cli.py
#	code_review_graph/skills.py
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.

[request] Support for OpenCode

2 participants