MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / mergeLoginShellPath

Function mergeLoginShellPath

packages/kaos/src/login-shell-path.ts:92–113  ·  view source on GitHub ↗
(
  currentPath: string | undefined,
  loginShellPath: string,
)

Source from the content-addressed store, hash-verified

90 * commands from arbitrary workspace directories.
91 */
92export function mergeLoginShellPath(
93 currentPath: string | undefined,
94 loginShellPath: string,
95): string {
96 const current = currentPath ?? '';
97 const seen = new Set(current.split(':').filter((entry) => entry.length > 0));
98 const additions: string[] = [];
99 for (const entry of loginShellPath.split(':')) {
100 // The probe only runs on POSIX (win32 bails before merging), so a
101 // leading slash is a sufficient absoluteness test. Empty components
102 // fail it too.
103 if (!entry.startsWith('/') || seen.has(entry)) continue;
104 seen.add(entry);
105 additions.push(entry);
106 }
107 if (additions.length === 0) return current;
108 // `undefined` means "no PATH at all", so the additions stand alone; ''
109 // is a real (cwd-only) PATH whose empty component must survive as a
110 // leading colon.
111 if (currentPath === undefined) return additions.join(':');
112 return `${current}:${additions.join(':')}`;
113}
114
115/** Probe the login shell and merge its PATH into `deps.env['PATH']`. */
116export async function applyLoginShellPath(deps: LoginShellPathDeps): Promise<void> {

Callers 2

applyLoginShellPathFunction · 0.85

Calls 3

hasMethod · 0.65
addMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected