committed by
Peter Steinberger
parent
6bcb89cf38
commit
d9f2ee40f7
77
src/entry.ts
77
src/entry.ts
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
import { spawnSync } from "node:child_process";
|
||||
import process from "node:process";
|
||||
|
||||
import { applyCliProfileEnv, parseCliProfileArgs } from "./cli/profile.js";
|
||||
import { spawnWithSignalForwarding } from "./process/spawn-with-signal-forwarding.js";
|
||||
|
||||
if (process.argv.includes("--no-color")) {
|
||||
process.env.NO_COLOR = "1";
|
||||
@@ -16,41 +16,56 @@ function hasExperimentalWarningSuppressed(nodeOptions: string): boolean {
|
||||
return nodeOptions.includes(EXPERIMENTAL_WARNING_FLAG) || nodeOptions.includes("--no-warnings");
|
||||
}
|
||||
|
||||
function ensureExperimentalWarningSuppressed(): void {
|
||||
if (process.env.CLAWDBOT_NODE_OPTIONS_READY === "1") return;
|
||||
function ensureExperimentalWarningSuppressed(): boolean {
|
||||
if (process.env.CLAWDBOT_NODE_OPTIONS_READY === "1") return false;
|
||||
const nodeOptions = process.env.NODE_OPTIONS ?? "";
|
||||
if (hasExperimentalWarningSuppressed(nodeOptions)) return;
|
||||
if (hasExperimentalWarningSuppressed(nodeOptions)) return false;
|
||||
|
||||
process.env.CLAWDBOT_NODE_OPTIONS_READY = "1";
|
||||
process.env.NODE_OPTIONS = `${nodeOptions} ${EXPERIMENTAL_WARNING_FLAG}`.trim();
|
||||
const result = spawnSync(process.execPath, [...process.execArgv, ...process.argv.slice(1)], {
|
||||
stdio: "inherit",
|
||||
env: process.env,
|
||||
|
||||
const { child } = spawnWithSignalForwarding(
|
||||
process.execPath,
|
||||
[...process.execArgv, ...process.argv.slice(1)],
|
||||
{
|
||||
stdio: "inherit",
|
||||
env: process.env,
|
||||
},
|
||||
);
|
||||
|
||||
child.on("exit", (code, signal) => {
|
||||
if (signal) {
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
process.exit(code ?? 1);
|
||||
});
|
||||
if (result.signal) process.exit(1);
|
||||
process.exit(result.status ?? 1);
|
||||
|
||||
// Parent must not continue running the CLI.
|
||||
return true;
|
||||
}
|
||||
|
||||
ensureExperimentalWarningSuppressed();
|
||||
if (!ensureExperimentalWarningSuppressed()) {
|
||||
const parsed = parseCliProfileArgs(process.argv);
|
||||
if (!parsed.ok) {
|
||||
// Keep it simple; Commander will handle rich help/errors after we strip flags.
|
||||
console.error(`[clawdbot] ${parsed.error}`);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const parsed = parseCliProfileArgs(process.argv);
|
||||
if (!parsed.ok) {
|
||||
// Keep it simple; Commander will handle rich help/errors after we strip flags.
|
||||
console.error(`[clawdbot] ${parsed.error}`);
|
||||
process.exit(2);
|
||||
if (parsed.profile) {
|
||||
applyCliProfileEnv({ profile: parsed.profile });
|
||||
// Keep Commander and ad-hoc argv checks consistent.
|
||||
process.argv = parsed.argv;
|
||||
}
|
||||
|
||||
import("./cli/run-main.js")
|
||||
.then(({ runCli }) => runCli(process.argv))
|
||||
.catch((error) => {
|
||||
console.error(
|
||||
"[clawdbot] Failed to start CLI:",
|
||||
error instanceof Error ? (error.stack ?? error.message) : error,
|
||||
);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
}
|
||||
|
||||
if (parsed.profile) {
|
||||
applyCliProfileEnv({ profile: parsed.profile });
|
||||
// Keep Commander and ad-hoc argv checks consistent.
|
||||
process.argv = parsed.argv;
|
||||
}
|
||||
|
||||
import("./cli/run-main.js")
|
||||
.then(({ runCli }) => runCli(process.argv))
|
||||
.catch((error) => {
|
||||
console.error(
|
||||
"[clawdbot] Failed to start CLI:",
|
||||
error instanceof Error ? (error.stack ?? error.message) : error,
|
||||
);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user