/**
 * Rules detector — reports whether the composed instructions file exists in
 * the version home. Uses the active rules preset name as the detected
 * "resource name" so the diff stays meaningful (one preset = one synced
 * name, mirroring what getAvailableResources surfaces under `memory`).
 */
import * as fs from 'fs';
import * as path from 'path';
import { AGENTS, agentConfigDirName } from '../../agents.js';
import { capableAgents } from '../../capabilities.js';
import { getActiveRulesPreset } from '../../state.js';
import { lazyAgentMap } from '../writers/lazy-map.js';
function buildRulesDetector(agent) {
    return {
        kind: 'rules',
        agent,
        list({ version, versionHome }) {
            const cap = AGENTS[agent].capabilities.rules;
            if (cap === false)
                return [];
            const agentDir = path.join(versionHome, agentConfigDirName(agent));
            const instrFile = path.join(agentDir, cap.file);
            if (!fs.existsSync(instrFile))
                return [];
            return [getActiveRulesPreset(agent, version)];
        },
    };
}
export const rulesDetectors = lazyAgentMap(() => {
    const m = {};
    for (const agent of capableAgents('rules'))
        m[agent] = buildRulesDetector(agent);
    return m;
});
