Files
paseo/packages/server/src/utils/string-command-shell.ts
T
Mohamed BoudraandGitHub 08a0d0c28d Fix worktree setup scripts losing PATH (#1908)
* fix(worktree): preserve PATH for lifecycle scripts

Lifecycle command strings were running through login shells, which could rewrite PATH before setup commands saw the daemon environment. Use the shared stable script-shell helper without login startup files, and route related project-authored command strings through it.

* fix(worktree): ignore Bash startup env hook

Project command strings should not source shell startup hooks before they see Paseo's supplied environment. Strip BASH_ENV from lifecycle, loop verify, and ACP string-command shells and pin the behavior in setup tests.

* fix(worktree): resolve Bash through PATH

* fix(worktree): preserve Windows cmd command strings

* test(acp): expect Windows cmd terminal strings
2026-07-06 20:34:42 +08:00

55 lines
1.3 KiB
TypeScript

export interface BuildStringCommandShellInvocationOptions {
command: string;
platform?: NodeJS.Platform;
windowsShell?: "powershell" | "cmd";
}
export interface StringCommandShellInvocation {
shell: string;
args: string[];
}
export function createStringCommandShellEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
const sanitized = { ...env };
delete sanitized.BASH_ENV;
return sanitized;
}
export function createStringCommandShellEnvOverlay(): Record<string, string | undefined> {
return { BASH_ENV: undefined };
}
export function buildStringCommandShellInvocation(
options: BuildStringCommandShellInvocationOptions,
): StringCommandShellInvocation {
const platform = options.platform ?? process.platform;
// Project-authored command strings use a stable script shell. The caller supplies
// the environment; shell startup files should not rewrite it behind our back.
if (platform === "win32") {
if (options.windowsShell === "cmd") {
return {
shell: "cmd.exe",
args: ["/c", options.command],
};
}
return {
shell: "powershell",
args: [
"-NoProfile",
"-NonInteractive",
"-ExecutionPolicy",
"Bypass",
"-Command",
options.command,
],
};
}
return {
shell: "bash",
args: ["-c", options.command],
};
}