import { runInstallMergeDriver } from "./install-merge-driver-cmd.js";
import { runLearningsOverflow, } from "./learnings-overflow-cmd.js";
import { runMergeLearnings, } from "./merge-learnings-cmd.js";
/**
 * Gate commands skip the root npm update check.
 *
 * `merge-learnings` especially: git runs it inline during every merge of the
 * ledger, so a network update check would stall the merge and pollute the
 * driver's output.
 */
export const GATE_COMMAND_NAMES = [
    "check-learnings-budget",
    "file-upstream",
    "learnings-overflow",
    "merge-learnings",
    "install-merge-driver",
];
/**
 * Register the bounded learnings-budget check.
 * @param program - Commander program
 * @param dependencies - Gate runners
 */
function addCheckLearningsBudgetCommand(program, dependencies) {
    program
        .command("check-learnings-budget")
        .description("Fail if the project learnings file exceeds its hard budget (missing file passes)")
        .argument("[path]", "Learnings file to check (default: resolved from .lisa.config.json)")
        .action(async (targetPath) => {
        const code = await dependencies.runCheckLearningsBudget(targetPath);
        if (code !== 0)
            process.exitCode = code;
    });
}
/**
 * Register the public upstream-filing projection.
 * @param program - Commander program
 * @param dependencies - Gate runners
 */
function addFileUpstreamCommand(program, dependencies) {
    program
        .command("file-upstream")
        .description("Project a public upstream filing document from allowlisted fields only")
        .option("--input <file>", "JSON filing event (default: read stdin)")
        .action(async (options) => {
        const code = await dependencies.runFileUpstream(options);
        if (code !== 0)
            process.exitCode = code;
    });
}
/**
 * Register the overflow inspect/drain handle the gardener uses.
 *
 * Not injectable: the drain removes entries from the only durable copy of a
 * budget-dropped capture, so a caller must never be able to stub it away.
 * @param program - Commander program
 */
function addLearningsOverflowCommand(program) {
    program
        .command("learnings-overflow")
        .description("List or drain learnings the ledger had no budget to accept (JSON output)")
        .option("--drain <ids...>", "Entry ids to remove once they have a durable home elsewhere")
        .action(async (options) => {
        const code = await runLearningsOverflow(options);
        if (code !== 0)
            process.exitCode = code;
    });
}
/**
 * Register the project-learnings union merge driver.
 *
 * Invoked by git, not by humans: the argument names map to git's `%O %A %B %P`
 * placeholders and the exit code carries the merge verdict.
 * @param program - Commander program
 */
function addMergeLearningsCommand(program) {
    program
        .command("merge-learnings")
        .description("Git merge driver: union the project learnings ledger by entry id")
        .option("--base <file>", "Merge-base version (git %O)")
        .option("--ours <file>", "Our version; receives the result (git %A)")
        .option("--theirs <file>", "Their version (git %B)")
        .option("--path <path>", "Real pathname for diagnostics (git %P)")
        .action(async (options) => {
        const code = await runMergeLearnings(options);
        if (code !== 0)
            process.exitCode = code;
    });
}
/**
 * Register the machine-local merge-driver installer.
 * @param program - Commander program
 */
function addInstallMergeDriverCommand(program) {
    program
        .command("install-merge-driver")
        .description("Register the project learnings union merge driver in local git config")
        .argument("[path]", "Project directory (default: current directory)")
        .action(async (targetPath) => {
        const code = await runInstallMergeDriver(targetPath);
        if (code !== 0)
            process.exitCode = code;
    });
}
/**
 * Register all non-project gate commands.
 * @param program - Commander program
 * @param dependencies - Gate runners
 */
export function addGateCommands(program, dependencies) {
    addCheckLearningsBudgetCommand(program, dependencies);
    addFileUpstreamCommand(program, dependencies);
    addLearningsOverflowCommand(program);
    addMergeLearningsCommand(program);
    addInstallMergeDriverCommand(program);
}
//# sourceMappingURL=gate-commands.js.map