/** * PI adapter for pi-yaml-hooks — top-level orchestrator. * * Loads hooks.yaml via `core/load-hooks.ts`, constructs the core runtime via * `createHooksRuntime`, and forwards every relevant PI event into the * runtime's `tool.execute.before` / `tool.execute.after` / `event` dispatch * surface. * * file.changed is synthesized from `tool_result` events for the PI built-in * `write` and `edit` tools so that YAML-defined `file.changed` hooks fire on * file mutations. * * Windows guardrail: the bash executor depends on a POSIX bash on PATH. On * win32 we emit one warning and register nothing. * * Extracted from `adapter.ts` as part of the P0/P1 refactor; the public * `registerAdapter` symbol (and `registerPhase1Adapter` alias) are re-exported * through `./adapter.ts` so existing callers keep working. */ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { getPiHooksLogger } from "../core/logger.js"; import type { HookHostKind } from "../core/host-profile.js"; import { isStaleSessionBoundError } from "./host-adapter.js"; import { evictLruEntries, touchLruEntry } from "./runtime-registry.js"; /** * Register the PI adapter on the given extension API. * * Installs: * - `tool_call` → runtime `tool.execute.before` (+ block-tool response) * - `tool_result` → Phase 1 snapshot-hook + runtime `tool.execute.after` * - `agent_end` / `agent_settled` (PI), `session_stop`-armed `agent_end` (OMP) * → runtime `session.idle` (when idle + no pending messages) * - `session_start`→ runtime `session.created` (on new/startup) * - `session_shutdown` / `session_before_switch` * → Phase 1 worker flush + runtime `session.deleted` * (lossy compat shim: PI emits these on /new, /resume, * /fork too — we cannot distinguish them by source event, * but PI tags each with a `reason` field which we * forward verbatim on the envelope so hook authors can * tell graceful shutdowns from session-replacement) */ export declare function registerAdapter(pi: ExtensionAPI, hostKind?: HookHostKind): void; /** Backwards-compat alias for the Phase 1 export name. */ export declare const registerPhase1Adapter: typeof registerAdapter; /** * Test-only re-export of the production LRU helpers. Tests verify the * eviction policy via these functions; production code uses the same * implementations inline (see `runtime-registry.ts`). * * Also exposes `isStaleSessionBoundError` so unit tests can pin known * SDK-emitted error messages against the regex (P2-9). */ export declare const __testing__: { touchLruEntry: typeof touchLruEntry; evictLruEntries: typeof evictLruEntries; isStaleSessionBoundError: typeof isStaleSessionBoundError; rememberToolCallSession: typeof rememberToolCallSession; lookupToolCallSession: typeof lookupToolCallSession; }; type ToolCallSessionMap = Map; declare function rememberToolCallSession(entries: ToolCallSessionMap, toolCallId: string, sessionId: string, now?: number): void; declare function lookupToolCallSession(entries: ToolCallSessionMap, toolCallId: string, now?: number): string | undefined; export declare function reportDispatchFailure(logger: ReturnType, context: { cwd: string; event: string; sessionId?: string; details?: Record; }, error: unknown): void; export {};