import { DiffToolHttpServer } from "./http_server.js";
import { DiffReviewProtocolClient, parseDiffToolLaunchEnvironment } from "./protocol_client.js";
export { DiffToolHttpServer } from "./http_server.js";
export { createBuiltInDiffToolConfig } from "./launcher.js";
export { DiffReviewProtocolClient, DiffReviewProtocolClientError, DiffToolLaunchEnvironmentError, parseDiffToolLaunchEnvironment, } from "./protocol_client.js";
export async function runBuiltInDiffToolCommand(options = {}) {
    const launchEnvironment = parseDiffToolLaunchEnvironment(options.env);
    const client = new DiffReviewProtocolClient(launchEnvironment);
    const server = new DiffToolHttpServer({ client, codeTheme: launchEnvironment.codeTheme });
    let started;
    let shuttingDown = false;
    const requestShutdown = async () => {
        if (shuttingDown) {
            return;
        }
        shuttingDown = true;
        await server.cancel();
    };
    const onSigInt = () => {
        void requestShutdown();
    };
    const onSigTerm = () => {
        void requestShutdown();
    };
    process.on("SIGINT", onSigInt);
    process.on("SIGTERM", onSigTerm);
    try {
        started = await server.start();
        const log = options.log ?? ((message) => console.log(message));
        log(`tau diff tool listening at ${started.url}`);
        log(`open the url above in a browser to continue the review`);
        await server.waitUntilClosed();
    }
    finally {
        process.off("SIGINT", onSigInt);
        process.off("SIGTERM", onSigTerm);
        if (!shuttingDown) {
            await server.close();
        }
    }
}
//# sourceMappingURL=index.js.map