/**
 * Hooks System Type Definitions
 *
 * Provides comprehensive TypeScript types for the Wave Code hooks system,
 * enabling automated actions at specific workflow points.
 */
// Hook execution errors (non-blocking)
export class HookExecutionError extends Error {
    constructor(hookCommand, originalError, context) {
        super(`Hook execution failed: ${hookCommand} - ${originalError.message}`);
        this.hookCommand = hookCommand;
        this.originalError = originalError;
        this.context = context;
        this.name = "HookExecutionError";
    }
}
// Configuration validation errors (blocking)
export class HookConfigurationError extends Error {
    constructor(configPath, validationErrors) {
        super(`Hook configuration error in ${configPath}: ${validationErrors.join(", ")}`);
        this.configPath = configPath;
        this.validationErrors = validationErrors;
        this.name = "HookConfigurationError";
    }
}
// Type guards for runtime validation
export function isValidHookEvent(event) {
    return [
        "PreToolUse",
        "PostToolUse",
        "UserPromptSubmit",
        "Stop",
        "SubagentStop",
        "PermissionRequest",
        "WorktreeCreate",
    ].includes(event);
}
export function isValidHookCommand(cmd) {
    if (typeof cmd !== "object" ||
        cmd === null ||
        !("type" in cmd) ||
        cmd.type !== "command" ||
        !("command" in cmd) ||
        typeof cmd.command !== "string" ||
        cmd.command.length === 0) {
        return false;
    }
    const hookCmd = cmd;
    if ("async" in hookCmd && typeof hookCmd.async !== "boolean") {
        return false;
    }
    if ("timeout" in hookCmd && typeof hookCmd.timeout !== "number") {
        return false;
    }
    return true;
}
export function isValidHookEventConfig(config) {
    if (typeof config !== "object" || config === null)
        return false;
    const cfg = config;
    // Validate hooks array
    if (!Array.isArray(cfg.hooks) || cfg.hooks.length === 0)
        return false;
    if (!cfg.hooks.every(isValidHookCommand))
        return false;
    // Validate optional matcher
    if ("matcher" in cfg && typeof cfg.matcher !== "string")
        return false;
    return true;
}
