"use strict";
/**
 * `vyuh-dxkit explore api-surface` — exported symbols with no
 * internal callers (likely public API or CLI entry points).
 *
 * Reads per-pack exportDetection reliability from the canonical
 * registry helper. Packs declared 'unreliable' (today: ruby) are
 * excluded with an explanatory note.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.runApiSurface = runApiSurface;
const languages_1 = require("../../languages");
const queries_1 = require("../queries");
const format_1 = require("../format");
const DEFAULT_LIMIT = 25;
function runApiSurface(graph, _positionals, values) {
    const limit = parseLimit(values.limit, DEFAULT_LIMIT);
    const declarations = (0, languages_1.allExportDetectionDeclarations)();
    const unreliablePacks = declarations
        .filter((d) => d.reliability === 'unreliable')
        .map((d) => ({ pack: d.pack, strategy: d.strategy }));
    const packsExcluded = unreliablePacks.map((u) => u.pack);
    const results = (0, queries_1.apiSurfaceQuery)(graph, packsExcluded, limit);
    if (values.json) {
        (0, format_1.printJson)((0, format_1.envelope)('explore.api-surface', { limit, excluded: unreliablePacks }, graph, results));
        return;
    }
    const sections = [];
    sections.push((0, format_1.markdownHeader)('API surface', 'exported symbols with no internal callers', graph));
    if (unreliablePacks.length > 0) {
        sections.push(`*Excluded packs* (export detection unreliable): ` +
            unreliablePacks.map((u) => `**${u.pack}** (${u.strategy})`).join('; '));
    }
    if (results.length === 0) {
        sections.push('No exported symbols without internal callers found. Either the codebase has no public API surface graphify could detect, or every exported symbol has at least one internal caller.');
        (0, format_1.printMarkdown)(...sections);
        return;
    }
    sections.push((0, format_1.markdownTable)(['Path', 'Symbol', 'Kind', 'Pack'], results.map((r) => ({
        Path: r.line ? `${r.sourceFile}:${r.line}` : r.sourceFile,
        Symbol: r.symbol,
        Kind: r.kind,
        Pack: r.pack,
    }))));
    sections.push('These are likely public API or CLI entry points. Verify before deleting — a missing internal caller can mean "external consumer only" rather than "dead code." Future releases will add a dedicated dead-code analyzer with stronger heuristics.');
    sections.push((0, format_1.markdownFooter)('Drill into one: `vyuh-dxkit explore file <path>`.'));
    (0, format_1.printMarkdown)(...sections);
}
function parseLimit(raw, defaultValue) {
    if (!raw)
        return defaultValue;
    const n = parseInt(raw, 10);
    if (isNaN(n) || n < 1)
        return defaultValue;
    return Math.min(n, 1000);
}
//# sourceMappingURL=api-surface.js.map