diff --git a/src/infra/local-tui-processes.test.ts b/src/infra/local-tui-processes.test.ts index 5f17fb60e9ac..ae4ed8f1fe86 100644 --- a/src/infra/local-tui-processes.test.ts +++ b/src/infra/local-tui-processes.test.ts @@ -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", diff --git a/src/infra/local-tui-processes.ts b/src/infra/local-tui-processes.ts index 17b79d07b755..c3476f9575cb 100644 --- a/src/infra/local-tui-processes.ts +++ b/src/infra/local-tui-processes.ts @@ -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) {