Files
OmniRoute/src/shared/services/cliRuntimeHealthcheckPath.ts
Diego Rodrigues de Sa e Souza 1c116e0501 fix(cli): merge node bin dir into CLI healthcheck PATH for codex detection (#8036) (#8156)
checkRunnable() built the healthcheck spawn's minimalEnv.PATH from the
caller's PATH only, never merging in this Node's own bin dir the way
locateCommand's known-path search already does. npm-installed CLIs like
codex are `#!/usr/bin/env node` shebang scripts, so when the server is
launched with a minimal PATH (systemd/docker/PM2/Electron) lacking
node's dir, the healthcheck spawn fails even though the binary was
correctly located, and the tool shows as undetected.

Extracted the merge into a new buildHealthcheckPath() helper
(cliRuntimeHealthcheckPath.ts) to keep cliRuntime.ts within its frozen
file-size ceiling.
2026-07-22 11:27:45 -03:00

19 lines
826 B
TypeScript

import path from "path";
/**
* #8036: npm-installed CLIs (e.g. codex) are `#!/usr/bin/env node` shebang
* scripts — running them needs `node` resolvable on the child's PATH. A
* minimal launcher PATH (systemd/docker/PM2/Electron) may omit this Node's
* own bin dir even though the binary was correctly LOCATED via the
* PATH-independent known-path search (cliRuntime.ts's getKnownToolPaths()
* already merges it in for locating). Merge it into the healthcheck spawn's
* PATH too so the shebang can always resolve its interpreter.
*/
export const buildHealthcheckPath = (callerPath: string, nodeBinDir: string): string => {
const entries = callerPath.split(path.delimiter);
if (entries.includes(nodeBinDir)) {
return callerPath;
}
return [callerPath, nodeBinDir].filter(Boolean).join(path.delimiter);
};