import { N as NavigationContextOptions } from '../../navigation-context-BE1KHJ_8.js'; import { a as GuardrailRuleData } from '../../guardrail-hooks-slK-z0Dz.js'; /** * Claude Code Hook Protocol — parse stdin JSON input and emit hook response JSON. * * Implements the protocol defined at https://code.claude.com/docs/en/hooks * for SessionStart, UserPromptSubmit, and PreToolUse hook events. */ type HookEventName = "SessionStart" | "UserPromptSubmit" | "PreToolUse"; interface SessionStartInput { hookEventName: "SessionStart"; session_id?: string; type?: "new" | "resume" | "clear" | "compact"; } interface UserPromptSubmitInput { hookEventName: "UserPromptSubmit"; session_id?: string; prompt?: string; } interface PreToolUseInput { hookEventName: "PreToolUse"; session_id?: string; tool_name?: string; tool_input?: { file_path?: string; path?: string; command?: string; content?: string; [key: string]: unknown; }; } type HookInput = SessionStartInput | UserPromptSubmitInput | PreToolUseInput; type PermissionDecision = "allow" | "deny" | "ask"; interface HookOutput { /** Hook-specific output envelope. */ hookSpecificOutput?: { hookEventName: HookEventName; /** Additional context injected into the session. */ additionalContext?: string; /** Permission decision for PreToolUse hooks. */ permissionDecision?: PermissionDecision; /** Reason for the permission decision. */ permissionDecisionReason?: string; }; } /** * Parse hook input from a raw JSON string (typically from stdin). * Throws on invalid JSON but not on missing fields — callers handle defaults. */ declare function parseHookInput(raw: string): HookInput; /** * Read all of stdin and parse as hook input JSON. */ declare function readHookInput(): Promise; /** * Emit a hook response as JSON to stdout. */ declare function emitHookOutput(output: HookOutput): void; /** * Build a response that injects additional context into the session. */ declare function buildContextResponse(eventName: HookEventName, additionalContext: string): HookOutput; /** * Build a deny response for PreToolUse hooks. */ declare function buildDenyResponse(reason: string): HookOutput; /** * Build an allow response (empty output = allow by default). */ declare function buildAllowResponse(): HookOutput; /** * Cache Store — read/write `.claude/cache/` directory. * * Stores navigation-index.json and metadata for graph cache invalidation. * Uses atomic write (write-to-temp + rename) for concurrent-access safety. */ interface CacheEntry { data: T; /** ISO timestamp of when the cache was written. */ writtenAt: string; /** Hash of source inputs used for invalidation. */ sourceHash: string; } interface CacheStoreOptions { /** Absolute path to the `.claude/cache/` directory. */ cacheDir: string; } interface CacheStore { read(key: string): Promise | null>; write(key: string, data: T, sourceHash: string): Promise; /** * Check if a cache entry is fresh by comparing its sourceHash. * Returns the cached data if fresh, null if stale or missing. */ readIfFresh(key: string, currentHash: string): Promise; /** Get the mtime of a file (for invalidation checks). */ getFileMtime(filePath: string): Promise; } declare function createCacheStore(options: CacheStoreOptions): CacheStore; /** * Compute a simple hash string from an array of file mtimes and content strings. * Not cryptographic — used only for cache invalidation. */ declare function computeSourceHash(inputs: Array): string; /** * Latency utilities — timeout wrapper, graph build exclusion, degrade policy. * * Mirrors the Promise-sharing pattern from analyzer-bridge.ts for concurrent * graph build exclusion. */ declare class TimeoutError extends Error { constructor(ms: number); } /** * Race a promise against a timeout. Resolves with the promise result or * rejects with TimeoutError. */ declare function withTimeout(promise: Promise, timeoutMs: number): Promise; /** * Creates an exclusive async lock that ensures only one invocation runs at a * time. Subsequent callers await the same Promise (analyzer-bridge pattern). */ declare function createExclusiveLock(): { run: (fn: () => Promise) => Promise; }; interface DegradeResult { value: T; degraded: boolean; reason?: string; } /** * Attempt an operation with timeout; if it fails or times out, return the * fallback value with `degraded: true`. */ declare function withDegrade(operation: () => Promise, fallback: T, timeoutMs: number): Promise>; /** * Artifact Resolver — reverse-lookup path to artifact_id using navigation-index. * * Uses glob matching from guardrail-hooks.ts to match file paths against * artifact path_patterns defined in the navigation index. */ /** Minimal shape of a navigation-index artifact node. */ interface NavigationArtifact { properties?: { type?: string; authority?: string; manual_edit?: string; [key: string]: unknown; }; files?: { path_patterns?: string[]; [key: string]: unknown; }; agents?: { owners?: string[]; editors?: string[]; [key: string]: unknown; }; routes?: { regenerate?: string; [key: string]: unknown; }; relations?: { derived_artifacts?: string[]; [key: string]: unknown; }; } interface ArtifactMatch { artifactId: string; artifact: NavigationArtifact; /** The glob pattern that matched. */ matchedPattern: string; } /** * Resolve a file path to its artifact(s) in the navigation index. * Returns all matching artifacts (a file may belong to multiple artifacts). */ declare function resolvePathToArtifacts(filePath: string, navigationIndex: Record): ArtifactMatch[]; /** * Check if a file path targets a protected artifact (generated or manual_edit: forbidden). */ declare function isProtectedArtifact(match: ArtifactMatch): { protected: boolean; reason: string; }; /** * Get all artifact entries from a navigation index as a flat list. */ declare function listArtifacts(navigationIndex: Record): Array<{ id: string; artifact: NavigationArtifact; }>; /** * Ensure Navigation Index — cache warm / invalidation. * * Checks cache freshness via source file mtime comparison. If stale, * calls buildNavigationContext() and writes to .claude/cache/. * If fresh, returns cached data immediately. * * This is the performance-critical path for SessionStart hooks. */ interface EnsureNavigationIndexOptions { /** Absolute path to .claude/cache/ directory. */ cacheDir: string; /** Paths to source files whose mtime drives cache invalidation. */ sourceFiles: string[]; /** Options for buildNavigationContext() when cache is stale. */ navigationOptions: NavigationContextOptions; } interface NavigationIndexResult { navigationIndex: Record; /** Whether the result was loaded from cache (true) or freshly built (false). */ fromCache: boolean; } /** * Ensure the navigation index is available and fresh. Returns the index * data, building + caching if necessary. */ declare function ensureNavigationIndex(options: EnsureNavigationIndexOptions): Promise; /** * File Suggestion Handler — artifact-aware @ completion for Claude Code. * * Reads stdin prefix, filters navigation-index artifacts, and emits NDJSON * candidates sorted by relevance score. */ interface FileSuggestionCandidate { label: string; path: string; kind: "artifact" | "file"; /** Artifact ID this file/pattern belongs to. */ artifact?: string; /** Authority of the artifact (canonical, generated, etc.). */ authority?: string; /** Manual edit policy for the artifact. */ manual_edit?: string; /** Relevance score (higher = more relevant). */ score: number; } interface FileSuggestionOptions { /** The navigation index to search. */ navigationIndex: Record; /** Maximum number of candidates to return. */ maxCandidates?: number; } /** * Generate file suggestion candidates from the navigation index. * Filters by prefix if provided, then returns NDJSON-formatted candidates. */ declare function generateCandidates(prefix: string, options: FileSuggestionOptions): FileSuggestionCandidate[]; /** * Format candidates as NDJSON (one JSON object per line). */ declare function formatNdjson(candidates: FileSuggestionCandidate[]): string; /** * Main handler for file-suggestion bin script. * Reads prefix from stdin, returns NDJSON candidates to stdout. */ declare function handleFileSuggestion(navigationIndex: Record, stdinData: string): Promise; /** * SessionStart Hook Handler — cache warm + navigation-index summary injection. * * Executed on session new/resume/clear/compact events. Warms the navigation-index * cache and returns a rendered summary as additionalContext. * * Latency constraint: NO AST analysis or ContextPack generation. */ interface SessionStartHandlerConfig { /** Absolute path to .claude/cache/ directory. */ cacheDir: string; /** Source files for cache invalidation (component.yaml, agent-contracts.yaml, etc.). */ sourceFiles: string[]; /** Options for buildNavigationContext(). */ navigationOptions: EnsureNavigationIndexOptions["navigationOptions"]; } /** * Create a SessionStart hook handler. */ declare function createSessionStartHandler(config: SessionStartHandlerConfig): (_input: SessionStartInput) => Promise; /** * UserPromptSubmit Hook Handler — navigation-index summary injection. * * Executed after prompt submission, before Claude processes it. Provides a * compact navigation-index summary so the LLM can pick candidates and delegate * deep exploration to `analyzer.getContextMap` (Level 2). * * ContextPack is NOT pre-injected by default (#206 Phase D). */ interface UserPromptSubmitHandlerConfig { /** Absolute path to the project root. */ projectRoot: string; /** Absolute path to .claude/cache/ directory. */ cacheDir: string; /** Source files for cache invalidation. */ sourceFiles: string[]; /** Options for buildNavigationContext(). */ navigationOptions: EnsureNavigationIndexOptions["navigationOptions"]; } /** * Create a UserPromptSubmit hook handler. */ declare function createUserPromptSubmitHandler(config: UserPromptSubmitHandlerConfig): (input: UserPromptSubmitInput) => Promise; /** * PreToolUse Hook Handler — artifact guardrail + DSL guardrail enforcement. * * Executed before tool use (Edit, Write, Bash, etc.). Checks: * 1. Edit/Write tools: file path → artifact reverse lookup → deny if protected * 2. Bash tool: apply DSL guardrail rules via GuardrailHooks */ interface PreToolUseHandlerConfig { /** Navigation index for artifact resolution. */ navigationIndex: Record; /** DSL guardrail rules for Bash command evaluation. */ guardrailRules?: GuardrailRuleData; } /** * Create a PreToolUse hook handler. */ declare function createPreToolUseHandler(config: PreToolUseHandlerConfig): (input: PreToolUseInput) => Promise; export { type ArtifactMatch, type CacheEntry, type CacheStore, type CacheStoreOptions, type DegradeResult, type EnsureNavigationIndexOptions, type FileSuggestionCandidate, type FileSuggestionOptions, type HookEventName, type HookInput, type HookOutput, type NavigationArtifact, type NavigationIndexResult, type PermissionDecision, type PreToolUseHandlerConfig, type PreToolUseInput, type SessionStartHandlerConfig, type SessionStartInput, TimeoutError, type UserPromptSubmitHandlerConfig, type UserPromptSubmitInput, buildAllowResponse, buildContextResponse, buildDenyResponse, computeSourceHash, createCacheStore, createExclusiveLock, createPreToolUseHandler, createSessionStartHandler, createUserPromptSubmitHandler, emitHookOutput, ensureNavigationIndex, formatNdjson, generateCandidates, handleFileSuggestion, isProtectedArtifact, listArtifacts, parseHookInput, readHookInput, resolvePathToArtifacts, withDegrade, withTimeout };