Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(cli): keep the login-shell PATH probe off the terminal

AdityaUmale126b7e642e3c
diff --git a/server/env-path.test.ts b/server/env-path.test.ts
index 113c912ef9..ebce88ccbb 100644
--- a/server/env-path.test.ts
+++ b/server/env-path.test.ts
@@ -112,6 +112,30 @@ describe("augmentedPath", () => {
}
});
+ posixIt("runs the login-shell probe in its own session, so an interactive shell cannot take over the terminal", async () => {
+ const shell = join(homedir(), "fake-login-shell");
+ const rcOnlyBin = join(homedir(), "rc-only", "bin");
+ // Answers only when it leads its own process group, as a detached (setsid) child does; an attached one shares the server's.
+ writeFileSync(shell, `#!/bin/sh\n[ "$(ps -o pgid= -p $$ | tr -d ' ')" = "$$" ] && printf '__OMB_PATH__%s' '${rcOnlyBin}'\n`);
+ chmodSync(shell, 0o755);
+
+ const saved = { SHELL: process.env.SHELL, VITEST: process.env.VITEST };
+ try {
+ process.env.SHELL = shell;
+ delete process.env.VITEST;
+ resetPathCacheForTests();
+
+ augmentedPath();
+ await vi.waitFor(() => expect(augmentedPath().split(delimiter)).toContain(rcOnlyBin));
+ } finally {
+ if (saved.SHELL === undefined) delete process.env.SHELL;
+ else process.env.SHELL = saved.SHELL;
+ if (saved.VITEST === undefined) delete process.env.VITEST;
+ else process.env.VITEST = saved.VITEST;
+ resetPathCacheForTests();
+ }
+ });
+
posixIt("keeps the login-shell PATH in the same order after a rescan", async () => {
const knownBin = join(homedir(), ".local", "bin");
mkdirSync(knownBin, { recursive: true });
diff --git a/server/env-path.ts b/server/env-path.ts
index 6cbddad446..d686803938 100644
--- a/server/env-path.ts
+++ b/server/env-path.ts
@@ -1,6 +1,6 @@
// A macOS app launched from Finder inherits a bare PATH (no ~/.local/bin, /opt/homebrew/bin or nvm/volta/asdf shims),
// so every agent CLI spawn goes through augmentedPath().
-import { execFile } from "node:child_process";
+import { spawn } from "node:child_process";
import { closeSync, existsSync, openSync, readFileSync, readSync, statSync, readdirSync } from "node:fs";
import { homedir } from "node:os";
import { basename, delimiter, dirname, extname, join } from "node:path";
@@ -137,18 +137,24 @@ function mergePaths(parts: string[]): string {
function probeLoginShellPath(): void {
const shell = process.env.SHELL || "/bin/zsh";
// -l -i: nvm and friends live in .zshrc/.bashrc, which only interactive shells read; a marker isolates $PATH from rc noise.
- execFile(
- shell,
- ["-l", "-i", "-c", 'printf "__OMB_PATH__%s" "$PATH"'],
- { timeout: 5000 },
- (err, stdout) => {
- if (err || !stdout) return;
- const m = /__OMB_PATH__([^\n]*)/.exec(stdout);
- if (!m || !m[1]) return;
- loginShellPath = m[1];
- cached = buildPath();
- },
- );
+ // detached: an interactive shell makes its job the terminal's foreground, which stops `openmausbot setup` and its sign-in CLI (SIGTTOU).
+ const child = spawn(shell, ["-l", "-i", "-c", 'printf "__OMB_PATH__%s" "$PATH"'], {
+ detached: true,
+ stdio: ["ignore", "pipe", "ignore"],
+ timeout: 5000,
+ });
+ let stdout = "";
+ child.stdout.setEncoding("utf8").on("data", (chunk: string) => {
+ stdout += chunk;
+ });
+ child.on("error", () => {});
+ child.on("close", (code) => {
+ if (code !== 0 || !stdout) return;
+ const m = /__OMB_PATH__([^\n]*)/.exec(stdout);
+ if (!m || !m[1]) return;
+ loginShellPath = m[1];
+ cached = buildPath();
+ });
}
export function resetPathCacheForTests(): void {