import { GrepOnlyBackend } from './grep-only.js';
import { CodeGraphBackend } from './codegraph.js';
import { GitNexusBackend } from './gitnexus.js';
export { GrepOnlyBackend, CodeGraphBackend, GitNexusBackend };
/**
 * Select a backend by name, or auto-pick a sensible default.
 *
 * `auto` semantics (engines 6.21.x onward):
 *   - GitNexus available → GitNexus. Richest, empirically validated
 *     across twenty + idle_meta cases. Slightly heavier index step
 *     than CodeGraph but produces better cluster quality for behavior
 *     extraction (#27 substrate).
 *   - CodeGraph + sqlite3 available → CodeGraph as fallback. Recent
 *     CodeGraph CLI releases (≥0.7) changed the edges-table schema
 *     (`source`/`target` cols replacing `from_id`/`to_id`); our
 *     queries don't yet handle the new shape, so it errors loudly on
 *     fresh databases. GitNexus is the better default.
 *   - Otherwise → grep-only (always works, no external tools).
 */
export function selectBackend(name = 'auto') {
    if (name === 'codegraph') {
        if (!CodeGraphBackend.isAvailable()) {
            throw new Error('CodeGraph backend requested but not available. Install with `npm i -g @colbymchenry/codegraph` and ensure sqlite3 is on PATH.');
        }
        return new CodeGraphBackend();
    }
    if (name === 'gitnexus') {
        if (!GitNexusBackend.isAvailable()) {
            throw new Error('GitNexus backend requested but not available. Install with `npm i -g gitnexus`.');
        }
        return new GitNexusBackend();
    }
    if (name === 'grep-only') {
        return new GrepOnlyBackend();
    }
    // auto — prefer GitNexus (richest + Leiden clustering), with the
    // unique-name fix (engines 6.25.9) that disambiguates run-dir paths
    // in the registry. Falls back to grep-only when GitNexus is unavailable.
    if (GitNexusBackend.isAvailable()) {
        return new GitNexusBackend();
    }
    return new GrepOnlyBackend();
}
//# sourceMappingURL=index.js.map