#!/usr/bin/env node /** * Cursor hook adapter — `code-audit cursor-hook`. * * Reads Cursor's postToolUse stdin JSON (native or Claude Code compat) and * runs a scoped audit on edited files. Blocks edits with critical violations. * * Phase 0 verification (2026-07-20): * - Source: cursor.com/docs/hooks + cursor.com/docs/reference/third-party-hooks * - postToolUse with Write matcher IS BLOCKING: exit 2 blocks the action * - additional_context is injected into the conversation after the tool result * - afterFileEdit EXISTS but is observation-only ("No output fields defined") * - Cursor natively reads .claude/settings.json hooks (PostToolUse→postToolUse) * - Tool name mapping: Edit→Write, Bash→Shell * - Dual response format support: both Claude nested format and Cursor flat format * * Input formats (both accepted): * Cursor native: { tool_name, tool_input, tool_output, tool_use_id, cwd, ... } * Claude Code compat: { tool_name, tool_input, tool_output, session_id, cwd, ... } * (CLAUDE_PROJECT_DIR env var set in Claude Code compat mode) * * Exit codes: * 0 — no critical violations found * 2 — critical violations found (blocks the action, additional_context injected) * 1 — internal error (adapter crash, not violation-related) */ import type { HookAuditOutput } from './core.js'; export interface CursorPostToolUse { tool_name?: string; tool_input?: Record; tool_output?: unknown; tool_use_id?: string; toolName?: string; toolInput?: Record; toolOutput?: unknown; session_id?: string; transcript_path?: string; cwd?: string; } export interface CursorHookResult { exitCode: number; stdout: string; stderr: string; } /** * Detect whether this is a Write/Edit tool invocation we should audit. */ export declare function isWriteOrEdit(event: CursorPostToolUse): boolean; /** * Extract the edited file path from tool_input. * Cursor Write: tool_input.file_path * Claude Code Edit: tool_input.file_path */ export declare function extractFilePath(event: CursorPostToolUse): string | null; /** * Build the additional_context string for violations. */ export declare function formatViolationContext(output: HookAuditOutput): { context: string; isBlocking: boolean; }; /** * Process a Cursor postToolUse event and return the hook result. * Extracted from main() for testability — tests inject a mock audit function. */ export declare function processCursorEvent(rawStdin: string, auditFn?: (filePaths: string[], projectRoot: string) => Promise): Promise; /** * CLI entry point — reads stdin, processes, writes result, exits. * Exported so the CLI can call it explicitly after importing. */ export declare function main(): Promise; //# sourceMappingURL=cursor.d.ts.map