// engine/resilience-detector/helpers.ts — Shared filesystem helpers (SPEC-034)
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { glob } from 'glob';
export async function safeGlob(projectPath, pattern) {
    try {
        return await glob(pattern, { cwd: projectPath, nodir: true });
    }
    catch {
        return [];
    }
}
export async function hasGlobMatches(projectPath, patterns) {
    for (const pattern of patterns) {
        const matches = await safeGlob(projectPath, pattern);
        if (matches.length > 0) {
            return true;
        }
    }
    return false;
}
export async function readEnvContent(projectPath) {
    const envFiles = ['.env', '.env.example', '.env.local.example', '.env.production'];
    const contents = [];
    for (const f of envFiles) {
        try {
            const c = await readFile(join(projectPath, f), 'utf-8');
            contents.push(c);
        }
        catch {
            // ignore missing files
        }
    }
    return contents.join('\n');
}
export async function readSourceContent(projectPath) {
    const patterns = [
        'src/**/*.ts',
        'src/**/*.js',
        'app/**/*.ts',
        'app/**/*.py',
        'main.go',
        'cmd/**/*.go',
    ];
    const files = [];
    for (const pattern of patterns) {
        const matches = await safeGlob(projectPath, pattern);
        files.push(...matches.slice(0, 20));
    }
    const contents = [];
    for (const f of files.slice(0, 20)) {
        try {
            const c = await readFile(join(projectPath, f), 'utf-8');
            contents.push(c);
        }
        catch {
            // ignore
        }
    }
    return contents.join('\n');
}
//# sourceMappingURL=helpers.js.map