fix(opencode): migrate hooks plugin to V2 API and stop duplicate registrations

OpenCode 2.x only runs V2 plugin definitions ({ id, setup(ctx) }); the V1
function-export form failed schema validation at load with
"PluginModule.LoadError: Plugin must export a default definition with an id
and an effect or setup function".

- Rewrite .opencode/plugins/ecc-hooks.ts as a native V2 plugin: V1 hook keys
  now register on their V2 domains (ctx.tool.hook execute.before/after,
  ctx.shell.hook create.before, ctx.permission.hook evaluate,
  ctx.session.hook compaction, ctx.event.subscribe for file/session/todo
  events, ctx.tool.transform for custom tools). Windows-safe: replaces Bun
  dollar-shell and grep with child_process.spawn + fs; every callback is
  try/catch wrapped and every domain registration is guarded so a missing
  capability degrades instead of crashing setup.
- Stop registering the same plugin id three times: OpenCode scans root-level
  plugin files AND loads the directory through index.ts, so the directory
  form of the plugin config produced two red "Duplicate plugin ID:
  ecc-hooks" entries in the TUI panel. Config now points directly at
  ./plugins/ecc-hooks.ts and plugins/index.ts becomes an inert distinct-id
  stub (kept on disk because install/uninstall plans and consent safety
  tests reference it).
- Document the failure modes and the /api/plugin plus "opencode plugin list"
  diagnostic playbook in TROUBLESHOOTING.md; align .opencode/README.md.

Verified: hook-consent, opencode-hook-consent-safety, install-lifecycle,
install-executor, harness-adapter-compliance tests pass (197 assertions);
check-hooks-schema-keys, validate-install-manifests, validate-hooks and
unicode-safety CI validators pass.
This commit is contained in:
MohammadAminDHM committed 2026-11-03 16:58:51 +03:30
1 parent b38be6a7f6
commit 03cfca273b
6 files changed
+717 -628

No files matched your search

File diff suppressed because it is too large. Load diff
+23 -8
View File
@@ -1,12 +1,27 @@
/**
* ECC Plugins for OpenCode
* ECC plugins directory entry for OpenCode 2.x.
*
* This module exports all ECC plugins for OpenCode integration.
* Plugins provide hook-based automation that mirrors Claude Code's hook system
* while taking advantage of OpenCode's more sophisticated 20+ event types.
* This file is intentionally inert in normal installs. OpenCode 2.x loads
* every root-level `.ts` file in a plugins directory AND the directory
* itself through this entry point, so re-exporting the real plugin from
* here would register the id `ecc-hooks` twice and OpenCode would mark the
* extra entries `failed: Duplicate plugin ID` (shown in red in the TUI
* plugins panel).
*
* The configuration in `.opencode/opencode.json` therefore points directly
* at `./plugins/ecc-hooks.ts`. This stub keeps:
* - the file present for the installer/uninstall plan (`ecc repair`), and
* - a distinct id so a stray directory load can never collide with or
* shadow the real hooks plugin, and never throws the V2 schema error
* ("Plugin must export a default definition with an id and an effect or
* setup function") that a plain non-plugin module would cause.
*
* Do not add hook logic here; it belongs in `ecc-hooks.ts` only.
*/
export { ECCHooksPlugin, default } from "./ecc-hooks.ts"
// Re-export for named imports
export * from "./ecc-hooks.ts"
export default {
id: "ecc-hooks-entry",
setup() {
return () => {}
},
}