Skip to content

feat: opencode plugin bridge for Copilot CLI hooks#972

Merged
magicpro97 merged 10 commits into
mainfrom
feat/opencode-plugin
Jun 9, 2026
Merged

feat: opencode plugin bridge for Copilot CLI hooks#972
magicpro97 merged 10 commits into
mainfrom
feat/opencode-plugin

Conversation

@magicpro97

Copy link
Copy Markdown
Owner

Summary

Bridge plugin that maps 9 Copilot CLI hook events to opencode's plugin system via Python subprocess.

Changes

  • opencode-plugin/copilot-tools-bridge.ts — TypeScript Plugin for opencode that translates 9 hook events (tool.execute.before/after, event, chat.message, tool.use, doom_loop, session.start/stop, task) to Python rule evaluation via hook_runner.py
  • opencode-plugin/install.py — Installs bridge plugin to ~/.config/opencode/plugins/ and registers MCP server
  • tests/test_opencode_bridge.py — 18 tests covering hook runner JSON compat, session lifecycle, error handling, install idempotency (all pass)

Architecture

  • Plugin uses Bun.spawn + Blob.stream() stdin for Python subprocess (avoids shell escaping)
  • Fail-open: every subprocess call wrapped in try/catch
  • tool.execute.before can block tool use via throwing
  • chat.message parts mutable for briefing injection (synthetic parts)
  • HMAC-signed marker files shared between Copilot CLI and rules

Testing

  • python3 tests/test_quality_gates.py — 429/429 passed
  • python3 tests/test_opencode_bridge.py — 18/18 passed

…s to opencode hooks

- Bridge plugin (copilot-tools-bridge.ts) maps tool.execute.before/after,
  event, chat.message, tool.use, doom_loop, session.start/stop, task to
  Copilot CLI Python rules via hook_runner.py subprocess
- Install script (install.py) deploys plugin + MCP server to opencode config
- 18 tests covering hook runner JSON compat, session lifecycle, error handling,
  install idempotency
Copilot AI review requested due to automatic review settings June 8, 2026 16:22

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.

Pull request overview

This PR adds an opencode plugin + installer that bridges opencode plugin events to this repo’s Copilot CLI hook runner (hooks/hook_runner.py) via a Python subprocess, plus a dedicated test suite intended to validate compatibility and installation.

Changes:

  • Added a Bun/TypeScript opencode plugin that calls hook_runner.py for pre/post tool hooks, chat prompts, and session lifecycle signals.
  • Added a Python installer that copies the plugin into ~/.config/opencode/plugins/ and registers this repo’s MCP server in opencode.jsonc.
  • Added a new Python test file to validate hook JSON compatibility and installer behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 11 comments.

File Description
opencode-plugin/copilot-tools-bridge.ts Implements the opencode → Copilot hooks bridge by spawning hook_runner.py and translating selected events/payloads.
opencode-plugin/install.py Installs the plugin and updates opencode MCP configuration.
tests/test_opencode_bridge.py Adds tests for bridge JSON compatibility and installer/MCP configuration behavior.

Comment thread opencode-plugin/copilot-tools-bridge.ts
Comment thread opencode-plugin/copilot-tools-bridge.ts Outdated
Comment thread opencode-plugin/copilot-tools-bridge.ts
Comment thread opencode-plugin/install.py
Comment thread opencode-plugin/install.py
Comment thread opencode-plugin/install.py
Comment thread tests/test_opencode_bridge.py Outdated
Comment thread tests/test_opencode_bridge.py Outdated
Comment thread tests/test_opencode_bridge.py Outdated
Comment thread tests/test_opencode_bridge.py Outdated
@magicpro97 magicpro97 force-pushed the feat/opencode-plugin branch from cb3a4db to 4b1b7e2 Compare June 8, 2026 16:45
@magicpro97

Copy link
Copy Markdown
Owner Author

✅ All 11 review comments addressed:

copilot-tools-bridge.ts:

  • Use os.homedir() as fallback for process.env.HOME
  • Added session.start and session.stop explicit hooks
  • Added tool.use passthrough
  • Guarded output.parts initialization before push

install.py:

  • Removed unused shutil import
  • Added Windows UTF-8 sys.stdout.reconfigure() guard
  • Used sys.executable instead of hardcoded python3 for MCP command
  • Fixed JSONC parsing (string-aware comment stripping avoids corrupting URLs)

test_opencode_bridge.py:

  • All install tests now run in temp XDG_CONFIG_HOME sandbox (via TestInstallSandboxed)
  • _run_install() accepts env override for sandbox isolation
  • Reinstall test calls install twice and checks for "already configured"
  • Removed direct writes to real ~/.config/opencode/

CI is fully green across all 9 platforms/versions. Please re-review.

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

Comment thread tests/test_opencode_bridge.py Outdated
Comment thread tests/test_opencode_bridge.py
Comment thread tests/test_opencode_bridge.py Outdated
Comment thread opencode-plugin/install.py Outdated
Comment thread opencode-plugin/install.py Outdated
Comment thread opencode-plugin/copilot-tools-bridge.ts
Comment thread tests/test_platform_compat.py Outdated
…tform paths, safe config write, accurate docstrings

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

Comment thread opencode-plugin/copilot-tools-bridge.ts
Comment thread opencode-plugin/copilot-tools-bridge.ts
Comment thread tests/test_opencode_bridge.py
Comment thread tests/test_opencode_bridge.py Outdated
Comment thread tests/test_opencode_bridge.py
Comment thread tests/test_opencode_bridge.py Outdated
- callHookRunner(): add 15s AbortSignal.timeout to prevent hanging
- Add explicit task hook handler for opencode task events
- test_opencode_bridge: register atexit cleanup for isolated HOME
- Replace hard-coded /tmp paths with tempfile.gettempdir()
- Add task and tool.use to hook export assertion test

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread opencode-plugin/install.py
Comment thread opencode-plugin/install.py
Comment thread opencode-plugin/copilot-tools-bridge.ts
- install_mcp(): return False when MCP entry already exists to prevent unnecessary config write
- --remove: remove empty-mcp cleanup branch that rewrote config when no mcp section existed
- task handler: add throw e + return to actually block deny decisions
- Sync local installed plugin
@magicpro97

Copy link
Copy Markdown
Owner Author

/copilot-review

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread opencode-plugin/install.py Outdated
Comment thread opencode-plugin/install.py
Comment thread tests/test_opencode_bridge.py Outdated
Comment thread tests/test_opencode_bridge.py
- _strip_jsonc(): replace regex with string-aware trailing comma removal
- Remove unused re import
- install_mcp(): use setdefault for mcp + type guard for non-dict values
- Remove unused _SANDBOX_ENV global
- test_plugin_matches_source: compare sha256 hash of full content
- Add hashlib import
@magicpro97

Copy link
Copy Markdown
Owner Author

/copilot-review

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread opencode-plugin/install.py Outdated
Comment thread opencode-plugin/install.py Outdated
Comment thread opencode-plugin/install.py Outdated
Comment thread opencode-plugin/install.py Outdated
Comment thread tests/test_opencode_bridge.py Outdated
- XDG_CONFIG_HOME: guard against empty string (Path('') → CWD)
- Extract _get_mcp() helper for non-dict type guard
- show_status()/remove_all(): use _get_mcp() to avoid crash on non-dict mcp
- load_config(): warn on OSError instead of silent fallback
- test_session_start_returns_context: accept JSON or text status output
@magicpro97

Copy link
Copy Markdown
Owner Author

@copilot review please

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown

@copilot review please

Re-reviewed the latest branch state: the previously raised bridge/install/test issues appear addressed, and targeted validation is green (tests/test_opencode_bridge.py and tests/test_quality_gates.py pass). I don’t see additional changes needed from my side right now.

@magicpro97 magicpro97 merged commit b89999e into main Jun 9, 2026
35 checks passed
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.

3 participants