var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
    if (typeof path === "string" && /^\.\.?\//.test(path)) {
        return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
            return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
        });
    }
    return path;
};
import { existsSync, readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { pathToFileURL } from "node:url";
import { INTERNAL_INTERCOM_BROKER_ARG, importInternalIntercomBroker } from "./internal-intercom-broker.js";
const APP_NAME = "atomic";
process.title = APP_NAME;
process.env.ATOMIC_CODING_AGENT = "true";
process.emitWarning = (() => { });
const args = process.argv.slice(2);
function readVersion() {
    try {
        const packageJsonPath = join(dirname(process.execPath), "package.json");
        const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
        return typeof pkg.version === "string" ? pkg.version : "0.0.0";
    }
    catch {
        return "0.0.0";
    }
}
if (args[0] === INTERNAL_INTERCOM_BROKER_ARG) {
    if (args.length !== 2) {
        console.error(`Atomic startup error: ${INTERNAL_INTERCOM_BROKER_ARG} requires exactly one broker module path`);
        process.exit(1);
    }
    void importInternalIntercomBroker(args[1]).catch((error) => {
        console.error(`Atomic startup error: ${error.message}`);
        process.exit(1);
    });
}
else {
    if (args[0] === "--version" || args[0] === "-v") {
        console.log(readVersion());
        process.exit(0);
    }
    const appPath = join(dirname(process.execPath), "app.js");
    if (!existsSync(appPath)) {
        console.error(`Atomic startup error: missing app bundle at ${appPath}`);
        process.exit(1);
    }
    void import(__rewriteRelativeImportExtension(pathToFileURL(appPath).href));
}
//# sourceMappingURL=split-loader.js.map