Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.
TypeScript agent-teamagentic-aiai-agentsai-assistantclaude-codecodexcursorelectrongrokgrok-bot-alternativelinuxlocal-firstmacosmcpmulti-agentopenclaw-alternativeopencodewindows
Find CLIs in their install folders even when PATH lacks them (#24)
Eduardo Machado0e48d2aa1aa1
diff --git a/src/core/engines/detect.ts b/src/core/engines/detect.tsindex 029cd50..746b90f 100644--- a/src/core/engines/detect.ts+++ b/src/core/engines/detect.ts@@ -5,7 +5,7 @@ import { homedir } from 'node:os'import { join } from 'node:path'import { L } from '../../shared/lang'import type { EngineId, EngineStatus } from '../../shared/types'-import { executableNames, isWin, pathDirs, spawnable } from '../platform'+import { executableNames, isWin, pathDirs, spawnable, withInstallDirs } from '../platform'import { userProvider } from './claude'import { codexEnv, userCodexProvider } from './codex'import { opencodeMajor } from './opencode-v2'@@ -23,13 +23,17 @@ function run(bin: string, args: string[], timeout = 15_000, env: NodeJS.ProcessE// Apps opened from Finder get a minimal PATH. Borrow the one from the user's// login shell so `claude` and `codex` are found where the terminal finds them.-// Windows hands every app the user's full PATH already.+// Windows hands every app the user's full PATH already. Either way, the folders+// the CLIs install themselves into are added when the installer left them out.export async function adoptLoginShellPath(): Promise<void> {- if (isWin) return- const shell = process.env['SHELL'] || '/bin/zsh'- const { code, stdout } = await run(shell, ['-ilc', 'printf "__PATH__%s" "$PATH"'], 10_000)- const path = stdout.split('__PATH__').pop()?.trim()- if (code === 0 && path) process.env['PATH'] = path+ if (!isWin) {+ const shell = process.env['SHELL'] || '/bin/zsh'+ const { code, stdout } = await run(shell, ['-ilc', 'printf "__PATH__%s" "$PATH"'], 10_000)+ const path = stdout.split('__PATH__').pop()?.trim()+ if (code === 0 && path) process.env['PATH'] = path+ }+ // (process.env is case-insensitive on Windows, so PATH is also Path there.)+ process.env['PATH'] = withInstallDirs(process.env['PATH'] ?? '')}async function which(cmd: string): Promise<string | undefined> {@@ -176,6 +180,8 @@ export async function detectGemini(): Promise<{ status: EngineStatus; models: st}export async function detectEngines(codexHome: string): Promise<{ engines: Record<EngineId, EngineStatus>; listed: Partial<Record<EngineId, string[]>> }> {+ // A CLI installed while the app is open may have created its folder just now.+ process.env['PATH'] = withInstallDirs(process.env['PATH'] ?? '')const [claude, codex, opencode, pi, gemini] = await Promise.all([detectClaude(), detectCodex(codexHome), detectOpenCode(), detectPi(), detectGemini()])return { engines: { claude, codex, opencode: opencode.status, pi: pi.status, gemini: gemini.status }, listed: { opencode: opencode.models, pi: pi.models, gemini: gemini.models } }}diff --git a/src/core/platform.ts b/src/core/platform.tsindex 72cfbbd..7991103 100644--- a/src/core/platform.ts+++ b/src/core/platform.ts@@ -116,6 +116,17 @@ export function executableNames(cmd: string): string[] {export const pathDirs = (): string[] => (process.env['PATH'] ?? process.env['Path'] ?? '').split(delimiter).filter(Boolean)+// Where the CLIs' own installers put them, even when they didn't manage to add+// the folder to PATH (Claude Code's native installer on Windows says so and moves+// on). Each one that exists and isn't on the PATH yet is appended to it.+export function withInstallDirs(path: string, os: Os = osOf(), home = homedir(), env: NodeJS.ProcessEnv = process.env, exists: (p: string) => boolean = existsSync): string {+ const dirs = [join(home, '.local', 'bin'), ...(os === 'windows' ? [env['APPDATA'] && join(env['APPDATA'], 'npm')] : [])].filter((d): d is string => !!d)+ const have = path.split(delimiter).filter(Boolean)+ const same = (a: string, b: string): boolean => (os === 'windows' ? a.replace(/[\\/]+$/, '').toLowerCase() === b.replace(/[\\/]+$/, '').toLowerCase() : a.replace(/\/+$/, '') === b.replace(/\/+$/, ''))+ const missing = dirs.filter((d) => exists(d) && !have.some((h) => same(h, d)))+ return [...have, ...missing].join(delimiter)+}+// cmd.exe's special characters, escaped with ^ (the approach of cross-spawn).const META = /([()\][%!^"`<>&|;, *?])/gdiff --git a/test/platform.test.ts b/test/platform.test.tsindex c78c9ff..80fc1fe 100644--- a/test/platform.test.ts+++ b/test/platform.test.ts@@ -1,10 +1,10 @@import { execFileSync, spawnSync } from 'node:child_process'import { chmodSync, mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'-import { join } from 'node:path'+import { delimiter, join } from 'node:path'import { describe, expect, it } from 'vitest'import { dockerProblem, ownedBack } from '../src/core/computer'-import { autostartEntry, autostartFile, chromeCandidates, executableNames, fallbackPath, findChrome, gitRoot, loginShell, onPath, osOf, shellCommand, spawnable, systemName, terminalCommand, userAgentPlatform } from '../src/core/platform'+import { autostartEntry, autostartFile, chromeCandidates, executableNames, fallbackPath, findChrome, gitRoot, loginShell, onPath, osOf, shellCommand, spawnable, systemName, terminalCommand, userAgentPlatform, withInstallDirs } from '../src/core/platform'import { shortcut } from '../src/shared/types'const win = process.platform === 'win32'@@ -220,3 +220,24 @@ describe('the shell for an agent on this computer', () => {expect(execFileSync(sh.file, sh.args, { env: sh.env, encoding: 'utf8' }).trim()).toMatch(/^(UCRT64|MINGW64)$/)})})++describe('folders the CLIs install into', () => {+ const home = join('/h', 'eduar')+ const local = join(home, '.local', 'bin')+ const npm = join('/h', 'eduar', 'AppData', 'Roaming', 'npm')+ const env = { APPDATA: join('/h', 'eduar', 'AppData', 'Roaming') }++ it('adds ~/.local/bin when the installer left it off the PATH (Claude Code on Windows)', () => {+ expect(withInstallDirs(['/a', '/b'].join(delimiter), 'windows', home, env, (p) => p === local)).toBe(['/a', '/b', local].join(delimiter))+ })++ it('adds the npm global folder on Windows, and only folders that exist', () => {+ expect(withInstallDirs('/a', 'windows', home, env, (p) => p === npm)).toBe(['/a', npm].join(delimiter))+ expect(withInstallDirs('/a', 'windows', home, env, () => false)).toBe('/a')+ })++ it("doesn't repeat a folder already there, whatever its case or trailing slash on Windows", () => {+ expect(withInstallDirs([local.toUpperCase() + '/'].join(delimiter), 'windows', home, env, (p) => p === local)).toBe(local.toUpperCase() + '/')+ expect(withInstallDirs(local, 'mac', home, env, () => true)).toBe(local)+ })+})