Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(env-path): keep the login-shell PATH order stable across rescans
RGB-loop796db90e0c36
diff --git a/server/env-path.test.ts b/server/env-path.test.tsindex 792e2132e9..113c912ef9 100644--- a/server/env-path.test.ts+++ b/server/env-path.test.ts@@ -112,6 +112,39 @@ describe("augmentedPath", () => {}});+ posixIt("keeps the login-shell PATH in the same order after a rescan", async () => {+ const knownBin = join(homedir(), ".local", "bin");+ mkdirSync(knownBin, { recursive: true });+ const shell = join(homedir(), "fake-login-shell");+ const rcOnlyBin = join(homedir(), "rc-only", "bin");+ writeFileSync(shell, `#!/bin/sh\nprintf '__OMB_PATH__%s' '${rcOnlyBin}'\n`);+ chmodSync(shell, 0o755);++ const saved = { PATH: process.env.PATH, SHELL: process.env.SHELL, VITEST: process.env.VITEST };+ const restore = (key: keyof typeof saved) => {+ if (saved[key] === undefined) delete process.env[key];+ else process.env[key] = saved[key];+ };+ try {+ process.env.PATH = join(homedir(), "bare-path");+ process.env.SHELL = shell;+ delete process.env.VITEST;+ resetPathCacheForTests();++ augmentedPath();+ await vi.waitFor(() => expect(augmentedPath().split(delimiter)).toContain(rcOnlyBin));+ const afterProbe = augmentedPath();++ resetPathCache();+ expect(augmentedPath()).toBe(afterProbe);+ } finally {+ restore("PATH");+ restore("SHELL");+ restore("VITEST");+ resetPathCacheForTests();+ }+ });+posixIt("keeps a sealed fixture off machine-wide install dirs and the login shell (#2035)", async () => {// Real directories on this machine: Homebrew's codex lives in one of them.const machineDirs = ["/opt/homebrew/bin", "/usr/local/bin"].filter((dir) => existsSync(dir));diff --git a/server/env-path.ts b/server/env-path.tsindex 304dc0f5a2..6cbddad446 100644--- a/server/env-path.ts+++ b/server/env-path.ts@@ -109,17 +109,7 @@ export function homeProgramDirs(home: string): string[] {}export function augmentedPath(): string {- if (cached === null) {- const fallback = fallbackDirs.filter((d) => existsSync(d));- cached = mergePaths([- ...registeredDirs.filter((d) => existsSync(d)),- ...(process.env.OMB_EXTRA_PATH ? process.env.OMB_EXTRA_PATH.split(delimiter) : []),- ...(process.env.PATH ? process.env.PATH.split(delimiter) : []),- // Keep the last login-shell result while a rescan re-probes, or rc-only CLIs vanish for the response that triggered it.- ...(loginShellPath ? loginShellPath.split(delimiter) : []),- ...(process.platform === "win32" ? windowsKnownDirs() : knownDirs()).filter((d) => existsSync(d)),- ].filter((d) => !fallback.includes(d)).concat(fallback).filter(serverMayRunFrom));- }+ if (cached === null) cached = buildPath();// The login shell reads its rc files from HOME, which a boxed bot can write.if (!probed && !process.env.VITEST && !sealedFixture() && process.platform !== "win32" && !homeProgramsDistrusted()) {probed = true;@@ -128,6 +118,18 @@ export function augmentedPath(): string {return cached;}+function buildPath(): string {+ const fallback = fallbackDirs.filter((d) => existsSync(d));+ return mergePaths([+ ...registeredDirs.filter((d) => existsSync(d)),+ ...(process.env.OMB_EXTRA_PATH ? process.env.OMB_EXTRA_PATH.split(delimiter) : []),+ ...(process.env.PATH ? process.env.PATH.split(delimiter) : []),+ // Keep the last login-shell result while a rescan re-probes, or rc-only CLIs vanish for the response that triggered it.+ ...(loginShellPath ? loginShellPath.split(delimiter) : []),+ ...(process.platform === "win32" ? windowsKnownDirs() : knownDirs()).filter((d) => existsSync(d)),+ ].filter((d) => !fallback.includes(d)).concat(fallback).filter(serverMayRunFrom));+}+function mergePaths(parts: string[]): string {return [...new Set(parts.filter(Boolean))].join(delimiter);}@@ -144,9 +146,7 @@ function probeLoginShellPath(): void {const m = /__OMB_PATH__([^\n]*)/.exec(stdout);if (!m || !m[1]) return;loginShellPath = m[1];- // Fallback dirs stay last, behind what the person's shell adds.- const fallback = fallbackDirs.filter((d) => existsSync(d));- cached = mergePaths([...(cached ?? "").split(delimiter).filter((d) => !fallback.includes(d)), ...m[1].split(delimiter), ...fallback].filter(serverMayRunFrom));+ cached = buildPath();},);}