import * as Effect from 'effect/Effect'; import type * as Runtime from 'effect/Runtime'; import * as Schema from 'effect/Schema'; import * as Stdio from 'effect/Stdio'; import { HookControlledExit, HookHandlerError, HookInputDecodeError, HookOutputEncodeError, HookStdinReadError, HookStdoutWriteError } from '../Errors.js'; import { HookContext } from './Context.js'; import { HookEnvelope } from './Envelope.js'; declare const HookProcessOutput_base: Schema.Class; readonly stderr: Schema.optional; readonly exitCode: Schema.Number; }>, {}>; /** * A complete, runnable hook definition. * * Produced by each event's `define(config)` factory. Passed to * `Hook.runMain(hook)`, `Hook.dispatch({...})`, or the test helpers in * `Testing`. * * @category Models * @since 0.1.0 */ export declare class HookProcessOutput extends HookProcessOutput_base { } export declare const processOutput: (options: { readonly exitCode?: number; readonly stdout?: string; readonly stderr?: string; }) => HookProcessOutput; export declare const stderrExit: (stderr: string, exitCode?: number) => HookProcessOutput; export declare const rawStdout: (stdout: string) => HookProcessOutput; export interface HookDefinition { readonly event: string; readonly inputSchema: Schema.Codec; readonly outputSchema: Schema.Codec; readonly handler: (input: In) => Effect.Effect; } /** * Dispatch map for `Hook.dispatch` — keys are hook event names and values * are complete `HookDefinition`s for that event. * * The inner type parameters are intentionally `any` so a single map may * hold definitions for different events (each with its own narrow input * and output type). Per-entry type safety is preserved at the * construction site because each event's `define(config)` factory * returns a precisely-typed `HookDefinition` before it lands in the * dispatch map. * * @category Models * @since 0.1.0 */ export type DispatchMap = Readonly>>; /** * The union of every error the runner can produce internally. * * @internal */ type RunnerError = HookStdinReadError | HookInputDecodeError | HookHandlerError | HookOutputEncodeError | HookStdoutWriteError | HookControlledExit; /** * Build the Effect program that executes one hook invocation end-to-end. * * Pure Effect form of the runner, exposed primarily for testing. * Production code should use `runMain`. * * @category Runner * @since 0.1.0 */ export declare const runHookProgram: (hook: HookDefinition) => Effect.Effect; /** * Build the Effect program that reads stdin, peeks `hook_event_name`, * and dispatches to the matching handler in the map. If no handler is * registered for the event, the program succeeds with no output. * * @category Runner * @since 0.1.0 */ export declare const runDispatchProgram: (hooks: DispatchMap) => Effect.Effect; /** * Custom teardown that maps the runner's typed errors to Claude Code's * hook exit-code convention: * * - `0` success * - handler-authored `HookProcessOutput` exits use their requested code * - `2` for `HookInputDecodeError` (Claude Code interprets exit 2 per * event: blocking/denying for gate events such as PreToolUse, * PermissionRequest, and ConfigChange; feedback-only or ignored for * several observability events) * - `1` non-blocking runner error (stdin read, handler crash, encode, write) * - `130` fiber interruption (SIGINT-style) * * @category Runner * @since 0.1.0 */ export declare const hookTeardown: Runtime.Teardown; /** * Run a single-event hook definition as the main program of the current * process. * * @category Runner * @since 0.1.0 * @example * ```ts * import * as Effect from 'effect/Effect' * import { Hook } from 'effect-claudecode' * * const hook = Hook.PreToolUse.define({ * handler: (input) => Effect.succeed(Hook.PreToolUse.allow()) * }) * * Hook.runMain(hook) * ``` */ export declare const runMain: (hook: HookDefinition) => void; /** * Run a multi-event dispatch script as the main program of the current * process. The map's keys are hook event names and values are * `HookDefinition`s produced by each event's `define()` factory. * * @category Runner * @since 0.1.0 * @example * ```ts * import * as Effect from 'effect/Effect' * import { Hook } from 'effect-claudecode' * * Hook.dispatch({ * PreToolUse: Hook.PreToolUse.define({ * handler: () => Effect.succeed(Hook.PreToolUse.allow()) * }), * PostToolUse: Hook.PostToolUse.define({ * handler: () => Effect.succeed(Hook.PostToolUse.passthrough()) * }) * }) * ``` */ export declare const dispatch: (hooks: DispatchMap) => void; export {}; //# sourceMappingURL=Runner.d.ts.map