import { spawn } from "node:child_process"; import { DoomTelemetryOptions } from "@agimon-ai/doompi-telemetry"; import "@agimon-ai/doompi-config/types"; import "@deepseek-ai/cordis"; import "@earendil-works/pi-coding-agent"; //#region src/constants/hooks.d.ts declare const HOOK_EVENT: { readonly sessionStart: 'SessionStart'; readonly preToolUse: 'PreToolUse'; readonly postToolUse: 'PostToolUse'; readonly stop: 'Stop'; readonly sessionEnd: 'SessionEnd'; }; //#endregion //#region src/types/hooks.d.ts /** * The hook document contract and the ports that run it. * * Every name here is written in Claude Code's vocabulary, because that is what * `.doom/hooks.yaml` and plugin `hooks.json` files are authored against. The * translation onto Pi's lifecycle happens at the adapter boundary. */ /** Registry event names. Each is used twice per dispatch, so drift would be silent. */ type HookEventName = (typeof HOOK_EVENT)[keyof typeof HOOK_EVENT]; interface HookCommand { command: string; /** Seconds before the hook is terminated. Defaults to DEFAULT_HOOK_TIMEOUT_SECONDS. */ timeout?: number; } /** What one registry row declares for the `pi` frontend. */ interface RegistryBinding { matcher?: string; command: string; timeout?: number; skipInSubagent?: boolean; order?: number; } /** A registry row plus the group membership used to include or drop it. */ interface RegistryEntry extends RegistryBinding { event: string; order: number; /** Declaration order across every source, used as the sort tiebreaker. */ position: number; groupId: string; core: boolean; /** Root of the config that declared the group, exported as CLAUDE_PLUGIN_ROOT. */ baseDirectory: string; } interface RegistryGroup { core?: boolean; hooks?: Array<{ event: string; pi?: RegistryBinding; }>; } interface RegistryDocument { groups?: Record; } /** One `.doom/hooks.yaml` as read from disk, before it is parsed. */ interface HookDocumentSource { baseDirectory: string; text: string; } /** One `.doom/hooks.yaml` after parsing, tagged with the root that declared it. */ interface ParsedRegistrySource { baseDirectory: string; document: RegistryDocument; } interface PluginHookGroup { matcher?: string; hooks?: HookCommand[]; } interface PluginHookConfig { hooks?: Record; } /** A parsed plugin config plus the root exported to its commands. */ interface PluginHookDocument { pluginRoot: string; config: PluginHookConfig; } /** A hook command paired with the config root it runs against. */ interface ResolvedHook { hook: HookCommand; root: string; } /** The JSON a hook may write on stdout to steer or block the call it observed. */ interface HookDecision { decision?: string; reason?: string; hookSpecificOutput?: { permissionDecision?: string; reason?: string; additionalContext?: string; }; } type HookFailureReason = 'spawn_failed' | 'non_zero_exit' | 'timeout' | 'invalid_json' | 'registry_read' | 'plugin_config'; interface HookFailure { command: string; message: string; reason: HookFailureReason; } interface HookOutcome { decision?: HookDecision; failure?: HookFailure; } /** * The tool fields a payload is built from, named without importing Pi. * * Pi's ToolCallEvent and ToolResultEvent both satisfy this structurally, so the * adapter forwards them unchanged and the payload builder stays host-neutral. */ interface HookToolEvent { readonly type: string; readonly toolName: string; readonly input: unknown; readonly content?: readonly unknown[]; readonly isError?: boolean; } /** The JSON document handed to a hook on stdin. */ type HookPayload = Record; interface HookRunOptions { repoRoot: string; /** Exported as CLAUDE_PLUGIN_ROOT so a hook can reach its own scripts. */ pluginRoot?: string; } /** Runs one hook command and reports what it decided or how it failed. */ interface HookRunner { run(hook: HookCommand, payload: HookPayload, options: HookRunOptions): Promise; } /** Registry rows for this repository, or the failure that emptied them. */ interface RegistryRead { entries: RegistryEntry[]; failure?: HookFailure; } /** Plugin configs that could be read, and one failure per config that could not. */ interface PluginDocumentRead { documents: PluginHookDocument[]; failures: HookFailure[]; } /** Where a plugin declares its hooks. Mirrors the harness state entry. */ interface PluginHookSourceRef { readonly pluginRoot: string; readonly configPath: string; } /** Reads the hook documents a session runs from. */ interface HookDocumentReader { registry(repoRoot: string): Promise; plugins(sources: readonly PluginHookSourceRef[]): Promise; } //#endregion //#region src/services/hookDecisions/index.d.ts declare function decisionsFrom(outcomes: ReadonlyArray): HookDecision[]; declare function failuresFrom(outcomes: ReadonlyArray): HookFailure[]; /** Both spellings a hook may use to refuse the call it observed. */ declare function isDenied(decision: HookDecision | undefined): boolean; declare function decisionReason(decision: HookDecision | undefined): string | undefined; /** Context a hook wants added to the conversation rather than used to block. */ declare function additionalContextsFrom(decisions: ReadonlyArray): string[]; /** What a post-tool hook has to say, whichever field it said it in. */ declare function toolResultMessages(decisions: ReadonlyArray): string[]; /** * A guardrail that never ran looks exactly like one that passed, so the agent is * told which checks were missed and what its options are. */ declare function hookFailureMessage(failures: ReadonlyArray): string; //#endregion //#region src/constants/telemetry.d.ts declare const HOOK_TELEMETRY_EVENT: { readonly hookFailed: 'doom_pi_hook.failed'; readonly hookRegistryReadFailed: 'doom_pi_hook.registry_read_failed'; }; //#endregion //#region src/types/telemetry.d.ts /** Telemetry events this package reports, and the port that records them. */ type HookTelemetryEventName = (typeof HOOK_TELEMETRY_EVENT)[keyof typeof HOOK_TELEMETRY_EVENT]; type HookTelemetryAttributes = Record; /** * A hook that never ran is indistinguishable from one that passed, which is why * both a failed run and an unreadable registry are worth reporting rather than * swallowing. */ interface HookTelemetry { recordError(event: HookTelemetryEventName, error: unknown, attributes?: HookTelemetryAttributes): Promise; recordWarning(event: HookTelemetryEventName, error: unknown, attributes?: HookTelemetryAttributes): Promise; } //#endregion //#region src/services/hookDocuments/index.d.ts interface HookDocumentReaderOptions { telemetry?: HookTelemetry; /** Where the global `.doom` directory lives. Defaults to the user's home. */ homeDirectory?: string; readFile?: (filePath: string) => Promise; warn?: (message: string) => void; } /** * Reads `.doom/hooks.yaml` from the global config directory and the repository, * and the plugin hook configs the harness resolved. * * Every file is re-read on every dispatch: it costs almost nothing and keeps an * in-place rewrite visible, which an mtime check would miss when two writes land * inside the same filesystem timestamp granularity. Both caches are keyed on * contents instead, so parsing — the expensive half — is what they skip. */ declare function createHookDocumentReader(options?: HookDocumentReaderOptions): HookDocumentReader; //#endregion //#region src/services/hookPayload/index.d.ts /** The payload shape a Claude Code session hook is written against. */ declare function toolHookPayload(event: HookToolEvent, hookEventName: string, repoRoot: string, sessionId: string): HookPayload; /** Session lifecycle hooks observe no tool, so they only need where and who. */ declare function sessionHookPayload(sessionId: string, repoRoot: string): HookPayload; //#endregion //#region src/services/hookRegistry/index.d.ts /** Which rows a dispatch keeps, once the session's selection is known. */ interface RegistrySelection { event: string; toolName?: string; /** Selected group ids, or undefined for "every group", the standalone default. */ allowedGroups?: readonly string[]; inSubagent: boolean; } /** * Identity of a set of registry sources, for callers that cache the parse. * * Keyed on contents rather than mtime, so it stays correct for an in-place * rewrite and needs no invalidation hook. Reading both files is cheap; parsing * is what a cache built on this skips. */ declare function registryCacheKey(sources: ReadonlyArray): string; /** * Flattens parsed registry documents into sorted rows, keeping only bindings * that declare a `pi` frontend. * * A later source replaces the group of the same id outright rather than merging * into it, so a repository that redefines a group owns it completely. */ declare function registryEntries(sources: ReadonlyArray): RegistryEntry[]; /** * The rows one dispatch runs. * * Group selection changes when /mode switches mid-session, so inclusion is * applied per call rather than being baked into a cached parse. Core groups * always load; the rest are gated by the layers the harness resolved. */ declare function selectRegistryHooks(entries: ReadonlyArray, selection: RegistrySelection): ResolvedHook[]; //#endregion //#region src/services/hookRunner/index.d.ts interface BashHookRunnerOptions { telemetry?: HookTelemetry; env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform; spawn?: typeof spawn; warn?: (message: string) => void; } /** * Runs advisory hook commands through bash and reports what each one decided. * * A hook is a command the repository owns, so it is spawned in its own process * group and terminated as one: a hook that starts a server and stalls should * not leave the server behind when the timeout fires. */ declare function createBashHookRunner(options?: BashHookRunnerOptions): HookRunner; //#endregion //#region src/services/hookRuntime/type.d.ts interface HookExtensionOptions { telemetry?: HookTelemetry; runner?: HookRunner; documents?: HookDocumentReader; } //#endregion //#region src/services/hookTelemetry/index.d.ts interface HookTelemetryOptions { cwd?: string; workspaceRoot?: string; env?: NodeJS.ProcessEnv; telemetryFactory?: NonNullable; warn?: (message: string) => void; } declare function createHookTelemetry(options?: HookTelemetryOptions): HookTelemetry; //#endregion //#region src/services/pluginHooks/index.d.ts /** * The plugin hooks one dispatch runs. * * Plugin configs are the Claude Code `hooks.json` shape verbatim: an event name * maps to groups, each with an optional matcher and a list of commands. Order * follows the declaration order of the plugins the harness resolved. */ declare function selectPluginHooks(documents: ReadonlyArray, eventName: string, toolName?: string): ResolvedHook[]; //#endregion //#region src/services/toolNames/index.d.ts /** The Claude name a hook matcher expects for a tool Pi just ran. */ declare function toClaudeToolName(tool: string): string; /** Whether a matcher, if the row declares one, accepts the tool that fired. */ declare function matchesTool(matcher: string | undefined, toolName: string | undefined): boolean; //#endregion export { HookDocumentReader as A, ParsedRegistrySource as B, decisionsFrom as C, toolResultMessages as D, isDenied as E, HookOutcome as F, PluginHookSourceRef as G, PluginHookConfig as H, HookPayload as I, RegistryEntry as J, RegistryBinding as K, HookRunOptions as L, HookEventName as M, HookFailure as N, HookCommand as O, HookFailureReason as P, HOOK_EVENT as Q, HookRunner as R, decisionReason as S, hookFailureMessage as T, PluginHookDocument as U, PluginDocumentRead as V, PluginHookGroup as W, RegistryRead as X, RegistryGroup as Y, ResolvedHook as Z, HookTelemetry as _, createHookTelemetry as a, HOOK_TELEMETRY_EVENT as b, createBashHookRunner as c, registryEntries as d, selectRegistryHooks as f, createHookDocumentReader as g, HookDocumentReaderOptions as h, HookTelemetryOptions as i, HookDocumentSource as j, HookDecision as k, RegistrySelection as l, toolHookPayload as m, toClaudeToolName as n, HookExtensionOptions as o, sessionHookPayload as p, RegistryDocument as q, selectPluginHooks as r, BashHookRunnerOptions as s, matchesTool as t, registryCacheKey as u, HookTelemetryAttributes as v, failuresFrom as w, additionalContextsFrom as x, HookTelemetryEventName as y, HookToolEvent as z }; //# sourceMappingURL=index-LpLV04fM.d.mts.map