"use strict";
/**
 * `vyuh-dxkit explore hot-files` — files most depended on.
 *
 * Pure pipeline: parse args → call hotFilesQuery → format output.
 * No graph traversal in here (CLAUDE.md Rule 12 enforces);
 * everything goes through src/explore/queries.ts.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.runHotFiles = runHotFiles;
const queries_1 = require("../queries");
const format_1 = require("../format");
const DEFAULT_LIMIT = 20;
function runHotFiles(graph, _positionals, values) {
    const limit = parseLimit(values.limit, DEFAULT_LIMIT);
    const results = (0, queries_1.hotFilesQuery)(graph, limit);
    if (values.json) {
        (0, format_1.printJson)((0, format_1.envelope)('explore.hot-files', { limit }, graph, results));
        return;
    }
    // Markdown: header, table, footer hint.
    const rows = results.map((r) => ({
        Path: r.sourceFile,
        'Calls in': r.callsIn,
        'Imports in': r.importsIn,
        'Calls out': r.callsOut,
        Community: r.communityLabel
            ? `${r.communityId} (${r.communityLabel})`
            : r.communityId !== undefined
                ? String(r.communityId)
                : '',
    }));
    const headers = ['Path', 'Calls in', 'Imports in', 'Calls out', 'Community'];
    if (results.length === 0) {
        (0, format_1.printMarkdown)((0, format_1.markdownHeader)('Hot files', "what's central?", graph), 'No files found in the graph. Either the repo has no inbound call edges, or the graph artifact is empty.');
        return;
    }
    (0, format_1.printMarkdown)((0, format_1.markdownHeader)('Hot files', "what's central?", graph), (0, format_1.markdownTable)(headers, rows), explainResults(results), (0, format_1.markdownFooter)('Drill into one: `vyuh-dxkit explore file <path>`.'));
}
/**
 * One-line interpretation hint below the table. A file with high
 * "calls in" + low "calls out" is foundational infrastructure;
 * inverting that signals a coordinator / orchestrator.
 */
function explainResults(results) {
    if (results.length === 0)
        return '';
    const top = results[0];
    const ratio = top.callsOut > 0 ? top.callsIn / top.callsOut : top.callsIn;
    if (ratio >= 3) {
        return `A file with high "calls in" + low "calls out" is foundational infrastructure. \`${top.sourceFile}\` looks like one.`;
    }
    return 'A file with high "calls in" + low "calls out" is foundational infrastructure.';
}
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); // sanity cap
}
//# sourceMappingURL=hot-files.js.map