Skip to content

feat(extensions): project OpenCode tool hooks statically#1679

Merged
limityan merged 1 commit into
GCWing:mainfrom
limityan:yanzhn/opencode-tool-hooks-help
Jul 23, 2026
Merged

feat(extensions): project OpenCode tool hooks statically#1679
limityan merged 1 commit into
GCWing:mainfrom
limityan:yanzhn/opencode-tool-hooks-help

Conversation

@limityan

@limityan limityan commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

This revision narrows PR1 to a runtime-free, production-consumed Hook projection slice:

  • Add five ecosystem-neutral Rust values for Hook contribution identity, Hook point, declared data risks, incomplete safety facts, and the resulting static declaration.
  • Reuse the existing OpenCode managed-package read path to inspect fixed .js / .ts package bytes with a workspace-pinned OXC parse-only profile.
  • Read only static top-level properties from the exported plugin return object. Map tool.execute.before and tool.execute.after to typed declarations; report other real OpenCode Hook properties as projection-only.
  • Emit explicit, stable diagnostics for unavailable Hook execution and AST parse failure. User-facing messages use OpenCode event names and natural-language risk descriptions.

Architecture and ownership

  • product-domains owns only ecosystem-neutral facts. It has no OpenCode, runtime, worker, process, UI, or adapter dependency.
  • opencode-adapter owns OpenCode syntax and semantic translation. OXC only extracts syntax-safe static property names; it does not execute TypeScript or interpret OpenCode behavior.
  • The existing PluginHostAdapter::read_plugins projection is the only production consumer. There is no test-only consumer used to justify public APIs.
  • Parse failure is fail-closed for Hook projection through opencode.hook_projection_parse_failed; ordinary payload strings, dynamic keys, and spread contents are not guessed as Hook declarations.
  • Stable diagnostic codes and audit correlation identities remain separate from user messages. This PR adds no log sink or metric backend.

The previous external-sources resolver, ordering/override/terminal-decision API, reverse crate dependency, and cross-layer test have been removed. Public Hook contracts are limited to the five types consumed by the read projection.

Scope boundary

This pull request does not add:

  • Node, Bun, or any other Hook runtime;
  • module loading, workers, processes, handler registration, activation, dispatch, cancellation, or lifecycle ownership;
  • Hook ordering, conflict resolution, enable/disable policy, persistence, or telemetry wiring;
  • a TypeScript bridge, Tool Pipeline integration, targets, Desktop/Web/TUI/CLI UI, settings, or commands.

tool remains handled by the existing custom-tool projection. OpenCode event-bus event types remain payloads of the top-level event Hook and are not treated as Hook property names.

Performance and compatibility

  • Parsing occurs once per managed package load, not on each read or dispatch.
  • Inputs retain the existing limits of 64 files, 1 MiB per file, and 16 MiB per package.
  • The oxc-parse workspace alias uses the already locked OXC version with default features disabled; the OpenCode adapter dependency graph does not pull transformer, codegen, or semantic features.
  • Single-line expression bodies, block return objects, unsupported real Hooks, ordinary event-name string references, event-bus false positives, and parser failure are covered by managed-package integration tests.

CI root cause fixed

The previous Frontend Build failure came from core-boundary violations: an external-sources production dependency on the OpenCode adapter, a cross-layer test consumer, an unexpected public adapter module, and excess public resolver APIs. The final file set removes those paths and updates the public API budget/self-tests for the production read-projection consumer.

Validation

  • cargo test -p bitfun-opencode-adapter: 90 passed.
  • cargo test -p bitfun-product-domains: passed with the Hook target correctly feature-gated.
  • cargo test -p bitfun-product-domains --features external-sources --test external_hook_contribution_contracts: 3 passed.
  • node --test scripts/check-core-boundaries.test.mjs: 16 passed.
  • node scripts/check-core-boundaries.mjs: passed.
  • pnpm run check:repo-hygiene: passed.
  • cargo check -p bitfun-core --features product-full: passed; four pre-existing MCP deprecation warnings remain.
  • cargo check --workspace: reaches the Desktop build script and is blocked only because the local worktree does not contain the generated src/mobile-web/dist resource.
  • git diff --check: passed.
  • Independent adversarial product review: READY, no P0/P1/P2 findings.
  • Independent adversarial architecture review on final commit e6c17b29b: READY, no P0/P1/P2 findings.

Follow-up boundary

Hook runtime selection, worker/process ownership, handler invocation, ordering, cancellation, recovery, UI, logs, and metrics remain a separate follow-up design and implementation. This PR does not pre-implement or imply those runtime decisions.

@limityan
limityan force-pushed the yanzhn/opencode-tool-hooks-help branch 5 times, most recently from d1d0dea to 2b9f8e0 Compare July 22, 2026 17:24
@limityan
limityan marked this pull request as draft July 23, 2026 00:15
@limityan
limityan force-pushed the yanzhn/opencode-tool-hooks-help branch from 2b9f8e0 to 11f2cee Compare July 23, 2026 02:22
@limityan limityan changed the title feat(extensions): add reviewed OpenCode tool hooks feat(extensions): define hook contribution contracts Jul 23, 2026
@limityan
limityan force-pushed the yanzhn/opencode-tool-hooks-help branch from 11f2cee to e6c17b2 Compare July 23, 2026 04:28
@limityan limityan changed the title feat(extensions): define hook contribution contracts feat(extensions): project OpenCode tool hooks statically Jul 23, 2026
@limityan
limityan marked this pull request as ready for review July 23, 2026 04:48
@limityan
limityan merged commit 367a5a1 into GCWing:main Jul 23, 2026
5 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.

1 participant