Skip to content

docs: hooks-v2 master implementation plan (28 events, cross-9-repo research)#354

Open
quangdang46 wants to merge 11 commits into
masterfrom
discuss/hooks
Open

docs: hooks-v2 master implementation plan (28 events, cross-9-repo research)#354
quangdang46 wants to merge 11 commits into
masterfrom
discuss/hooks

Conversation

@quangdang46
Copy link
Copy Markdown
Owner

Hooks v2 — Master Implementation Plan

Summary

Comprehensive implementation plan for jcode hooks v2, expanding from the current 7 HookEvent variants to full parity with Claude Code (27 events), OpenCode plugin system (14+ events), and Codex CLI (10 events).

Research Scope

All 9 reference repos researched and cross-referenced:

  1. claude-code — 27-event source of truth
  2. opencode — plugin event system + session lifecycle
  3. codex — Rust hook engine (FuturesUnordered dispatch, HookResult tri-state)
  4. oh-my-openagent — 5-tier composition, HTTP hooks
  5. oh-my-claudecode — 11 hooks, kill-switch env vars
  6. oh-my-codex — dual-layer config, plugin timeout, trust model
  7. oh-my-pi — 26+ events, RCU dispatch
  8. pi-agent-rust — ~30 typed events, bitmap O(1) fast path
  9. codebuff — PrintModeEvent (documented as low relevance)

Plan Contents

  • 2724 lines across 12 major sections
  • 28 events in 7 categories (Core Tool, Session, Permission, Agent, Compaction, Task, File)
  • Full TypeScript + Rust type definitions (HookInput with 40+ fields, Builder pattern)
  • TOML config spec with examples for every event
  • Module code for all 6 hooks files
  • 4 handler types (Command, HTTP, Agent, Plugin)
  • Integration points in 8+ source files
  • CLI commands (list, enable, disable, logs, check)
  • Test plan (unit + integration + e2e)
  • Cross-repo reference matrix
  • Migration path in 4 phases

Status

📋 Plan only — implementation pending.

This PR establishes the baseline document. Implementation will start in subsequent PRs.

Comprehensive 2724-line plan covering 28 hook events across 7 categories,
based on research across 9 reference repos (claude-code, opencode, codex,
oh-my-openagent, oh-my-claudecode, oh-my-codex, oh-my-pi, pi-agent-rust,
codebuff). Includes full TypeScript+Rust type definitions, TOML config
spec, module-by-module code, CLI commands, test plan, migration path.
- New crate: crates/jcode-hooks/ (7,445 lines)
  - types.rs: HookInput/HookOutput/HookResult/AggregatedDecision/HookMetrics
  - config.rs: HookEvent (28+1 variants), 4 handler types, 3-layer TOML loader
  - dispatch.rs: Parallel dispatch with FuturesUnordered + Semaphore
  - execute.rs: Command/Http/Agent/Plugin execution with exit code protocol
  - registry.rs: HookRegistry with matcher-based filtering
  - matcher.rs: Pattern matching (Exact/Multi/Regex/Wildcard)
  - cli.rs: CLI commands (list/enable/disable/test/metrics)
  - tests.rs: 186 unit tests

- Integration points wired (28 events):
  - PreToolUse, PostToolUse, PostToolUseFailure, ToolError
  - UserPromptSubmit, UserPromptExpansion
  - SessionStart, SessionEnd, SessionUpdated, SessionDiff, SessionError, SessionIdle
  - PermissionRequest, PermissionDenied, PermissionAsked, PermissionReplied
  - AgentStart, AgentEnd, SubagentStart, SubagentStop
  - Stop
  - PreCompact, PostCompact, AutoCompactionControl
  - Setup, TaskCreated, TaskCompleted
  - FileChanged

- Features:
  - Parallel dispatch via FuturesUnordered + Semaphore
  - Deny > Ask > Allow precedence chain
  - Kill-switch env vars (DISABLE_JCODE_HOOKS, JCODE_SKIP_HOOKS, JCODE_SKIP_EVENT_*)
  - Per-handler timeout (1-300s)
  - Exit code protocol (0=continue, 1=fail, 2=block)
  - Metrics collection

Tests: 186/186 passing
Build: cargo check passes with zero errors

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@quangdang46 quangdang46 marked this pull request as ready for review June 5, 2026 01:18
quangdang46 and others added 9 commits June 5, 2026 08:22
- cargo fmt on all hooks and integration files
- Fix clippy: derive Default for HooksConfig instead of manual impl
- Fix clippy: doc_overindented_list_items in dispatch.rs
- Fix clippy: needless_borrow in registry.rs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Fix redundant closure in client_lifecycle.rs
- Gate Mutex import behind dcp feature flag

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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