import { readdirSync, readFileSync } from 'node:fs';
import { basename, join } from 'node:path';
import { loadPiPolicyProfiles } from '@amaster.ai/pi-shared/settings';
export function loadPolicyDir(dirPath) {
    const result = {};
    let entries;
    try {
        entries = readdirSync(dirPath);
    }
    catch {
        return result;
    }
    for (const entry of entries) {
        if (!entry.endsWith('.json'))
            continue;
        const profileName = basename(entry, '.json');
        try {
            const raw = readFileSync(join(dirPath, entry), 'utf-8');
            const parsed = JSON.parse(raw);
            if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
                result[profileName] = parsed;
            }
        }
        catch {
            // skip malformed files
        }
    }
    return result;
}
export function loadFilePolicies(cwd, configDir) {
    return loadPiPolicyProfiles({
        cwd,
        ...(configDir !== undefined ? { configDir } : {}),
    });
}
//# sourceMappingURL=policy-loader.js.map