fix(update): recognize bare TUI launches

This commit is contained in:
Dallin Romney
2026-08-20 21:25:29 -07:00
parent 79279f8701
commit dc2df01fe2
2 changed files with 26 additions and 9 deletions
+14
View File
@@ -23,6 +23,9 @@ describe("local TUI processes", () => {
" 501 110 Thu Aug 20 19:00:00 2026 openclaw --profile work tui --local",
" 501 111 Thu Aug 20 19:00:00 2026 /usr/bin/node /usr/lib/node_modules/openclaw/openclaw.mjs --no-color terminal",
" 501 112 Thu Aug 20 19:00:00 2026 openclaw --profile=work chat",
" 501 114 Thu Aug 20 19:00:00 2026 openclaw",
" 501 115 Thu Aug 20 19:00:00 2026 openclaw --profile work",
" 501 116 Thu Aug 20 19:00:00 2026 /usr/bin/node /usr/lib/node_modules/openclaw/openclaw.mjs --no-color",
" 502 113 Thu Aug 20 19:00:00 2026 openclaw tui",
" 501 999 Thu Aug 20 19:00:00 2026 openclaw tui",
].join("\n"),
@@ -67,6 +70,17 @@ describe("local TUI processes", () => {
command: "openclaw --profile=work chat",
startTime: "Thu Aug 20 19:00:00 2026",
},
{ pid: 114, command: "openclaw", startTime: "Thu Aug 20 19:00:00 2026" },
{
pid: 115,
command: "openclaw --profile work",
startTime: "Thu Aug 20 19:00:00 2026",
},
{
pid: 116,
command: "/usr/bin/node /usr/lib/node_modules/openclaw/openclaw.mjs --no-color",
startTime: "Thu Aug 20 19:00:00 2026",
},
]);
expect(spawnSync).toHaveBeenCalledWith("ps", ["-axo", "uid=,pid=,lstart=,command="], {
encoding: "utf8",
+12 -9
View File
@@ -49,6 +49,10 @@ function normalizeExecutableName(value: string | undefined): string {
);
}
function isLocalTuiSubcommand(command: string | null | undefined): boolean {
return command === undefined || (command !== null && LOCAL_TUI_SUBCOMMANDS.has(command));
}
function isLocalTuiCommand(command: string, platform: NodeJS.Platform): boolean {
const argv =
platform === "win32" ? parseCmdScriptCommandLine(command) : tokenizeCommandLine(command);
@@ -57,22 +61,21 @@ function isLocalTuiCommand(command: string, platform: NodeJS.Platform): boolean
return true;
}
if (executable === "openclaw") {
return LOCAL_TUI_SUBCOMMANDS.has(resolveOpenClawCommand(argv.slice(1)) ?? "");
return isLocalTuiSubcommand(resolveOpenClawCommand(argv.slice(1)));
}
return (
executable === "node" &&
normalizeExecutableName(argv[1]) === "openclaw.mjs" &&
LOCAL_TUI_SUBCOMMANDS.has(resolveOpenClawCommand(argv.slice(2)) ?? "")
isLocalTuiSubcommand(resolveOpenClawCommand(argv.slice(2)))
);
}
function resolveOpenClawCommand(args: readonly string[]): string | undefined {
return (
getCommandPositionalsWithRootOptions(["node", "openclaw", ...args], {
commandPath: [],
maxPositionals: 1,
})?.[0] ?? undefined
);
function resolveOpenClawCommand(args: readonly string[]): string | null | undefined {
const positionals = getCommandPositionalsWithRootOptions(["node", "openclaw", ...args], {
commandPath: [],
maxPositionals: 1,
});
return positionals === null ? null : positionals[0];
}
function parseLocalTuiProcessLine(line: string, currentUid: number, currentPid = process.pid) {