(env: NodeJS.ProcessEnv = process.env)
| 112 | * for `/agents` availability probes and for the actual PTY spawn env. |
| 113 | */ |
| 114 | export function buildCliPath(env: NodeJS.ProcessEnv = process.env): string { |
| 115 | const path = env['PATH'] ?? env['Path'] ?? ''; |
| 116 | if (process.platform === 'win32') return path; |
| 117 | |
| 118 | const home = env['HOME'] ?? homedir(); |
| 119 | const pathEntries = path.split(delimiter); |
| 120 | const candidates = [ |
| 121 | ...(env['OPENALICE_EXTRA_AGENT_PATH'] ?? '').split(delimiter), |
| 122 | ...pathEntries, |
| 123 | env['PNPM_HOME'], |
| 124 | ...POSIX_USER_BIN_DIRS.map((p) => join(home, p)), |
| 125 | ...POSIX_SYSTEM_BIN_DIRS, |
| 126 | ]; |
| 127 | |
| 128 | const seen = new Set<string>(); |
| 129 | const out: string[] = []; |
| 130 | for (const raw of candidates) { |
| 131 | const dir = raw?.trim(); |
| 132 | if (!dir || seen.has(dir)) continue; |
| 133 | seen.add(dir); |
| 134 | // Keep existing PATH entries even if the directory is currently missing: |
| 135 | // they came from the host and may be intentional. For inferred fallbacks, |
| 136 | // include only real directories to avoid bloating every spawned shell. |
| 137 | if (pathEntries.includes(dir) || existsSync(dir)) out.push(dir); |
| 138 | } |
| 139 | return out.join(delimiter); |
| 140 | } |
| 141 | |
| 142 | function shouldStrip(name: string): boolean { |
| 143 | if (STRIP_EXACT.has(name)) return true; |
no test coverage detected