MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / buildCliPath

Function buildCliPath

src/workspaces/spawn-env.ts:114–140  ·  view source on GitHub ↗
(env: NodeJS.ProcessEnv = process.env)

Source from the content-addressed store, hash-verified

112 * for `/agents` availability probes and for the actual PTY spawn env.
113 */
114export 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
142function shouldStrip(name: string): boolean {
143 if (STRIP_EXACT.has(name)) return true;

Callers 3

spawn-env.spec.tsFile · 0.85
buildSpawnEnvFunction · 0.85
detectAgentsFunction · 0.85

Calls 3

hasMethod · 0.65
addMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected