"use strict";
/**
 * Path Normalization Helpers
 *
 * Functions for normalizing and matching file paths in AI responses.
 * AI models may return paths in different formats than expected.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizePathForComparison = normalizePathForComparison;
exports.findMatchingFilePath = findMatchingFilePath;
exports.getLanguageFromPath = getLanguageFromPath;
/**
 * Normalize a file path for comparison purposes.
 * Handles common variations: ./src/file.ts, src/file.ts, /src/file.ts
 */
function normalizePathForComparison(path) {
    return path
        .replace(/^\.\//, '') // Remove leading ./
        .replace(/^\//, '') // Remove leading /
        .replace(/\\/g, '/'); // Normalize Windows backslashes
}
/**
 * Find a matching file path from expected paths, handling path format variations.
 * AI responses may use different path formats than what we sent.
 */
function findMatchingFilePath(responsePath, expectedPaths) {
    // Exact match first
    if (expectedPaths.includes(responsePath))
        return responsePath;
    // Normalized match
    const normalized = normalizePathForComparison(responsePath);
    for (const expected of expectedPaths) {
        if (normalizePathForComparison(expected) === normalized) {
            console.log(`[AI Validation] Path fuzzy matched: "${responsePath}" -> "${expected}"`);
            return expected;
        }
    }
    // Basename match (only if unique) - handles cases like "file.ts" matching "src/api/file.ts"
    const basename = responsePath.split('/').pop() || responsePath;
    const matches = expectedPaths.filter(p => (p.split('/').pop() || p) === basename);
    if (matches.length === 1) {
        console.log(`[AI Validation] Path basename matched: "${responsePath}" -> "${matches[0]}"`);
        return matches[0];
    }
    return null;
}
/**
 * Get language identifier from file path extension
 */
function getLanguageFromPath(path) {
    const ext = path.split('.').pop()?.toLowerCase();
    const langMap = {
        ts: 'typescript',
        tsx: 'tsx',
        js: 'javascript',
        jsx: 'jsx',
        py: 'python',
        rb: 'ruby',
        go: 'go',
        java: 'java',
        php: 'php',
        cs: 'csharp',
        json: 'json',
        yaml: 'yaml',
        yml: 'yaml',
    };
    return langMap[ext || ''] || ext || 'text';
}
//# sourceMappingURL=path-helpers.js.map