Files
openclaw/src/cli/respawn-policy.ts
Vincent Koc 5af1fe1bd0 fix(tui): prevent orphaned terminal sessions (#77662)
* fix(tui): prevent orphaned terminal sessions

* fix(doctor): repair heartbeat-poisoned main sessions

* fix(tui): preserve startup tls respawn

* fix: harden tui and doctor recovery paths
2026-05-05 16:34:18 -07:00

59 lines
1.6 KiB
TypeScript

import { resolveCliArgvInvocation } from "./argv-invocation.js";
import { getCommandPositionalsWithRootOptions } from "./argv.js";
const GATEWAY_RUN_BOOLEAN_FLAGS = [
"--allow-unconfigured",
"--claude-cli-logs",
"--cli-backend-logs",
"--compact",
"--dev",
"--force",
"--raw-stream",
"--reset",
"--tailscale-reset-on-exit",
"--verbose",
] as const;
const GATEWAY_RUN_VALUE_FLAGS = [
"--auth",
"--bind",
"--password",
"--password-file",
"--port",
"--raw-stream-path",
"--tailscale",
"--token",
"--ws-log",
] as const;
const INTERACTIVE_TTY_COMMANDS = new Set(["tui", "terminal", "chat"]);
function isForegroundGatewayRunArgv(argv: string[]): boolean {
const positionals = getCommandPositionalsWithRootOptions(argv, {
commandPath: ["gateway"],
booleanFlags: GATEWAY_RUN_BOOLEAN_FLAGS,
valueFlags: GATEWAY_RUN_VALUE_FLAGS,
});
if (!positionals) {
return false;
}
return positionals.length === 0 || (positionals.length === 1 && positionals[0] === "run");
}
export function shouldSkipRespawnForArgv(argv: string[]): boolean {
const invocation = resolveCliArgvInvocation(argv);
return (
invocation.hasHelpOrVersion ||
(invocation.primary !== null && INTERACTIVE_TTY_COMMANDS.has(invocation.primary)) ||
(invocation.primary === "gateway" && isForegroundGatewayRunArgv(argv))
);
}
export function shouldSkipStartupEnvironmentRespawnForArgv(argv: string[]): boolean {
const invocation = resolveCliArgvInvocation(argv);
return (
invocation.hasHelpOrVersion ||
(invocation.primary === "gateway" && isForegroundGatewayRunArgv(argv))
);
}