Skip to main content

Module hooks

Module hooks 

Source
Expand description

Platform hook adapter layer.

Each supported AI coding client (Claude Code, Cursor, Zed, …) expects lifecycle hooks to speak its own JSON dialect on stdin/stdout. This module defines the PlatformAdapter trait every client implementation conforms to, plus the get_platform_adapter dispatcher that the CLI uses to look up the right adapter by name in the difflore-hook shim time.

The CLI’s job is thin: read stdin, hand it to the adapter, get a normalised HookEvent, run DiffLore logic, hand the HookResult back to the adapter to get platform-specific JSON, write to stdout. Any per-platform quirk lives inside the adapter — the CLI stays platform-agnostic.

Modules§

claude_code
Claude Code hook adapter.
cursor
Cursor hook adapter.
gemini_cli
Gemini CLI hook adapter.
session_banner
Since-last-session banner.
types
Platform-agnostic hook event + result types.
windsurf
Windsurf hook adapter.

Traits§

PlatformAdapter
Contract every platform adapter implements. The trait is object-safe on purpose so get_platform_adapter can return a Box<dyn PlatformAdapter> and the dispatch site doesn’t need to know the concrete type at compile time. That makes adding a new client (say Cursor) a pure module-level addition — no changes to the CLI dispatch loop beyond the get_platform_adapter match arm.

Functions§

default_classify_error
Default error classifier shared by every adapter. Kept as a free function (not an inherent method) so unit tests don’t need to construct a concrete adapter to exercise it.
get_platform_adapter
Dispatch by client name. Unknown names fall through to the Claude Code adapter as the pragmatic default — almost every DiffLore user today is on Claude Code, and a wrong-but-compatible parse fails loudly (via parse_stdin) while a panic would kill the user’s whole assistant session.