Skip to content

feat(harness): add opencode hook bridge plugin and dialect - #1365

Open
ptone wants to merge 2 commits into
mainfrom
scion/opencode-hook-bridge
Open

feat(harness): add opencode hook bridge plugin and dialect#1365
ptone wants to merge 2 commits into
mainfrom
scion/opencode-hook-bridge

Conversation

@ptone

@ptone ptone commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Plugin (harnesses/opencode/home/.config/opencode/plugins/scion-bridge.js): ESM module that subscribes to OpenCode lifecycle events (session, tool, message, permission, error) and pipes JSON payloads to sciontool hook --dialect=opencode. Uses node:child_process.execSync (no bun dependency). All calls are best-effort with try/catch.
  • Dialect (harnesses/opencode/dialect.yaml): Data-driven mapping from 8 OpenCode plugin events to normalized Scion events (session-start, session-end, agent-end, tool-start, tool-end, model-end, notification, prompt-submit).
  • Config update (harnesses/opencode/config.yaml): Upgrades max_turns to yes and max_model_calls to partial (message.updated proxies model-end; no model-start hook available).

Event Coverage

Scion Event OpenCode Hook Status
session-start session.created Mapped
session-end session.error Mapped (error path)
agent-end session.idle Mapped
tool-start tool.execute.before Mapped
tool-end tool.execute.after Mapped
model-end message.updated Mapped (proxy)
notification permission.asked Mapped
prompt-submit permission.replied Mapped
agent-start No OpenCode hook
subagent-end No OpenCode subagent concept
response-complete No direct equivalent
model-start No model invocation start hook

Test plan

  • YAML validation: python3 -c "import yaml; yaml.safe_load(open('harnesses/opencode/dialect.yaml'))"
  • YAML validation: python3 -c "import yaml; yaml.safe_load(open('harnesses/opencode/config.yaml'))"
  • JS syntax validation: node --check with .mjs extension or node -e fallback
  • Verify dialect loads via LoadMappingDialect / DiscoverMappingDialect
  • Integration test: pipe sample JSON payloads through sciontool hook --dialect=opencode

Scion Agent (hh-dev) added 2 commits August 29, 2026 14:37
Add a Scion hook bridge for the OpenCode harness, enabling hook-based
event visibility (status, logging, hub, limits, telemetry) for OpenCode
agents.

Three changes:
- Plugin (scion-bridge.js): ESM module loaded by OpenCode at startup.
  Subscribes to session, tool, message, permission, and error events,
  piping each as JSON to `sciontool hook --dialect=opencode`. Uses
  node child_process.execSync (no bun dependency). All calls are
  best-effort with try/catch to never crash the plugin.
- Dialect (dialect.yaml): Data-driven mapping from OpenCode plugin
  event names to normalized Scion events. Covers 8 of 12 non-internal
  scion events; unmapped: agent-start, subagent-end, response-complete,
  model-start (no OpenCode hooks available).
- Config update: max_turns upgraded to "yes", max_model_calls to
  "partial" (message.updated proxies model-end; no model-start hook).
Address R1 review findings on PR #1365:
- R1 (Required): Add 500ms debounce to message.updated handler to prevent
  per-chunk firing during streaming, which caused execSync blocking and
  inflated model-end counts
- O2 (Optional): Add conditional debug logging (SCION_HOOK_DEBUG) to
  catch block instead of silently swallowing errors
- O3 (Optional): Add comment documenting field name assumptions and
  opencode plugin API version basis
- O1 (Optional): Skipped — Go test changes deferred as follow-up to
  avoid CI risk from unrelated build issues
ptone pushed a commit that referenced this pull request Aug 29, 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.

1 participant