/**
 * Enhanced Debug Logger for Grok CLI
 *
 * Provides comprehensive debugging capabilities:
 * - Verbose API call logging with full request/response dumps
 * - Detailed timing for each operation step
 * - Tool call tracing with full context
 * - Structured JSON output for analysis
 *
 * Activation:
 * - --debug flag on CLI
 * - DEBUG=true or DEBUG=1 environment variable
 * - DEBUG=codebuddy for component-specific debug
 *
 * Environment Variables:
 * - DEBUG=true|1|codebuddy: Enable debug mode
 * - DEBUG_LEVEL=verbose|normal|minimal: Debug verbosity
 * - DEBUG_OUTPUT=console|file|both: Output destination
 * - DEBUG_FILE=path: Custom debug log file path
 * - DEBUG_JSON=true: Force JSON format for all output
 * - DEBUG_TIMING=true: Enable detailed timing measurements
 * - DEBUG_API=true: Log full API requests/responses
 * - DEBUG_TOOLS=true: Log tool call details
 * - DEBUG_PROMPTS=true: Dump system/user prompts
 */
import { LogContext } from './logger.js';
export type DebugLevel = 'verbose' | 'normal' | 'minimal';
export type DebugOutput = 'console' | 'file' | 'both';
export interface DebugConfig {
    enabled: boolean;
    level: DebugLevel;
    output: DebugOutput;
    filePath?: string;
    jsonFormat: boolean;
    timing: boolean;
    api: boolean;
    tools: boolean;
    prompts: boolean;
}
export interface TimingEntry {
    label: string;
    startTime: number;
    endTime?: number;
    durationMs?: number;
    metadata?: Record<string, unknown>;
}
export interface APICallLog {
    timestamp: string;
    requestId: string;
    method: string;
    endpoint: string;
    model: string;
    messages: Array<{
        role: string;
        contentPreview: string;
        contentLength: number;
        hasToolCalls?: boolean;
    }>;
    tools?: Array<{
        name: string;
        description: string;
    }>;
    options?: Record<string, unknown>;
    response?: {
        status: string;
        contentPreview: string;
        contentLength: number;
        toolCalls?: Array<{
            id: string;
            name: string;
            argumentsPreview: string;
        }>;
        usage?: {
            promptTokens: number;
            completionTokens: number;
            totalTokens: number;
        };
    };
    error?: {
        name: string;
        message: string;
        stack?: string;
    };
    durationMs: number;
}
export interface ToolCallLog {
    timestamp: string;
    callId: string;
    toolName: string;
    arguments: Record<string, unknown>;
    argumentsRaw: string;
    result?: {
        success: boolean;
        output?: string;
        outputLength?: number;
        error?: string;
    };
    durationMs: number;
    roundNumber: number;
}
export interface PromptDump {
    timestamp: string;
    type: 'system' | 'user' | 'assistant' | 'tool';
    content: string;
    contentLength: number;
    tokenEstimate?: number;
    metadata?: Record<string, unknown>;
}
export interface ContextSnapshot {
    timestamp: string;
    label: string;
    conversationLength: number;
    contextLength: number;
    systemPromptLength: number;
    activeTools: string[];
    model?: string;
    tokenCount?: number;
    snapshot: {
        conversationPreview?: Array<{
            type: string;
            preview: string;
        }>;
        contextPreview?: string;
        systemPromptPreview?: string;
    };
}
export interface StackTraceEntry {
    timestamp: string;
    label: string;
    stack: string;
    errorName?: string;
    errorMessage?: string;
    metadata?: Record<string, unknown>;
}
/**
 * Enhanced Debug Logger class
 */
export declare class DebugLogger {
    private config;
    private fileStream?;
    private timings;
    private apiLogs;
    private toolLogs;
    private promptDumps;
    private requestCounter;
    private sessionStartTime;
    constructor(config?: Partial<DebugConfig>);
    /**
     * Initialize file logging for debug output
     */
    private initializeFileLogging;
    /**
     * Log debug mode banner
     */
    private logDebugBanner;
    /**
     * Check if debug is enabled
     */
    isEnabled(): boolean;
    /**
     * Enable or disable debug mode
     */
    setEnabled(enabled: boolean): void;
    /**
     * Update debug configuration
     */
    updateConfig(config: Partial<DebugConfig>): void;
    /**
     * Write to file stream
     */
    private writeToFile;
    /**
     * Format and output debug message
     */
    private output;
    /**
     * Start a timing measurement
     */
    startTiming(label: string, metadata?: Record<string, unknown>): void;
    /**
     * End a timing measurement and return duration
     */
    endTiming(label: string, additionalMetadata?: Record<string, unknown>): number | undefined;
    /**
     * Create a timing wrapper for async functions
     */
    timeAsync<T>(label: string, fn: () => Promise<T>, metadata?: Record<string, unknown>): Promise<T>;
    /**
     * Get all timing entries
     */
    getTimings(): TimingEntry[];
    /**
     * Log an API request
     */
    logAPIRequest(method: string, endpoint: string, model: string, messages: Array<{
        role: string;
        content: string | null;
        tool_calls?: unknown[];
    }>, tools?: Array<{
        function: {
            name: string;
            description: string;
        };
    }>, options?: Record<string, unknown>): string;
    /**
     * Log an API response
     */
    logAPIResponse(requestId: string, status: string, content: string | null, toolCalls?: Array<{
        id: string;
        function: {
            name: string;
            arguments: string;
        };
    }>, usage?: {
        prompt_tokens: number;
        completion_tokens: number;
        total_tokens: number;
    }, durationMs?: number): void;
    /**
     * Log an API error
     */
    logAPIError(requestId: string, error: Error, durationMs?: number): void;
    /**
     * Log a tool call
     */
    logToolCall(callId: string, toolName: string, argumentsRaw: string, roundNumber: number): void;
    /**
     * Log a tool result
     */
    logToolResult(callId: string, success: boolean, output?: string, error?: string, durationMs?: number): void;
    /**
     * Dump a prompt for analysis
     */
    dumpPrompt(type: PromptDump['type'], content: string, metadata?: Record<string, unknown>): void;
    /**
     * Log a debug message
     */
    debug(message: string, context?: LogContext): void;
    /**
     * Log verbose debug message (only in verbose mode)
     */
    verbose(message: string, context?: LogContext): void;
    /**
     * Log a trace message with stack
     */
    trace(message: string, context?: LogContext): void;
    /**
     * Get debug session summary
     */
    getSessionSummary(): {
        sessionDuration: number;
        apiCallCount: number;
        totalApiDuration: number;
        avgApiDuration: number;
        toolCallCount: number;
        totalToolDuration: number;
        avgToolDuration: number;
        toolSuccessRate: number;
        timingEntries: number;
    };
    /**
     * Format session summary for display
     */
    formatSessionSummary(): string;
    /**
     * Export all debug data as JSON
     */
    exportAsJSON(): string;
    /**
     * Clear all logs
     */
    clear(): void;
    private contextSnapshots;
    private stackTraces;
    /**
     * Capture a context snapshot
     */
    captureContext(label: string, context: {
        conversationHistory?: Array<{
            type: string;
            content: string;
        }>;
        currentContext?: string;
        systemPrompt?: string;
        activeTools?: string[];
        model?: string;
        tokenCount?: number;
    }): void;
    /**
     * Get context snapshots
     */
    getContextSnapshots(): ContextSnapshot[];
    /**
     * Capture a detailed stack trace with context
     */
    captureStackTrace(label: string, error?: Error, metadata?: Record<string, unknown>): void;
    /**
     * Get stack traces
     */
    getStackTraces(): StackTraceEntry[];
    /**
     * Clean and format a stack trace
     */
    private cleanStackTrace;
    /**
     * Get a specific API log by request ID
     */
    getAPILog(requestId: string): APICallLog | undefined;
    /**
     * Get API logs for replay
     */
    getAPILogs(): APICallLog[];
    /**
     * Get tool logs
     */
    getToolLogs(): ToolCallLog[];
    /**
     * Get a tool call by ID
     */
    getToolLog(callId: string): ToolCallLog | undefined;
    /**
     * Close file stream
     */
    close(): void;
    private truncate;
    private summarizeArgs;
    private get promptDumpts();
}
/**
 * Get the global DebugLogger instance
 */
export declare function getDebugLogger(): DebugLogger;
/**
 * Create a new DebugLogger instance with custom config
 */
export declare function createDebugLogger(config?: Partial<DebugConfig>): DebugLogger;
/**
 * Reset the global DebugLogger instance (for testing)
 */
export declare function resetDebugLogger(): void;
/**
 * Quick debug check - returns true if debug mode is enabled
 */
export declare function isDebugEnabled(): boolean;
export declare const debugLogger: {
    isEnabled: () => boolean;
    setEnabled: (enabled: boolean) => void;
    updateConfig: (config: Partial<DebugConfig>) => void;
    debug: (message: string, context?: LogContext) => void;
    verbose: (message: string, context?: LogContext) => void;
    trace: (message: string, context?: LogContext) => void;
    startTiming: (label: string, metadata?: Record<string, unknown>) => void;
    endTiming: (label: string, metadata?: Record<string, unknown>) => number | undefined;
    timeAsync: <T>(label: string, fn: () => Promise<T>, metadata?: Record<string, unknown>) => Promise<T>;
    getTimings: () => TimingEntry[];
    logAPIRequest: (method: string, endpoint: string, model: string, messages: {
        role: string;
        content: string | null;
        tool_calls?: unknown[];
    }[], tools?: {
        function: {
            name: string;
            description: string;
        };
    }[] | undefined, options?: Record<string, unknown> | undefined) => string;
    logAPIResponse: (requestId: string, status: string, content: string | null, toolCalls?: {
        id: string;
        function: {
            name: string;
            arguments: string;
        };
    }[] | undefined, usage?: {
        prompt_tokens: number;
        completion_tokens: number;
        total_tokens: number;
    } | undefined, durationMs?: number | undefined) => void;
    logAPIError: (requestId: string, error: Error, durationMs?: number | undefined) => void;
    getAPILog: (requestId: string) => APICallLog | undefined;
    getAPILogs: () => APICallLog[];
    logToolCall: (callId: string, toolName: string, argumentsRaw: string, roundNumber: number) => void;
    logToolResult: (callId: string, success: boolean, output?: string | undefined, error?: string | undefined, durationMs?: number | undefined) => void;
    getToolLog: (callId: string) => ToolCallLog | undefined;
    getToolLogs: () => ToolCallLog[];
    dumpPrompt: (type: "user" | "assistant" | "system" | "tool", content: string, metadata?: Record<string, unknown> | undefined) => void;
    captureContext: (label: string, context: {
        conversationHistory?: Array<{
            type: string;
            content: string;
        }>;
        currentContext?: string;
        systemPrompt?: string;
        activeTools?: string[];
        model?: string;
        tokenCount?: number;
    }) => void;
    getContextSnapshots: () => ContextSnapshot[];
    captureStackTrace: (label: string, error?: Error | undefined, metadata?: Record<string, unknown> | undefined) => void;
    getStackTraces: () => StackTraceEntry[];
    getSessionSummary: () => {
        sessionDuration: number;
        apiCallCount: number;
        totalApiDuration: number;
        avgApiDuration: number;
        toolCallCount: number;
        totalToolDuration: number;
        avgToolDuration: number;
        toolSuccessRate: number;
        timingEntries: number;
    };
    formatSessionSummary: () => string;
    exportAsJSON: () => string;
    clear: () => void;
    close: () => void;
};
