fix(cli): respect platform shell for --on-complete

This commit is contained in:
孔祥俊
2026-03-27 11:11:58 +08:00
parent 1c9f4148d0
commit 661737b95a
4 changed files with 156 additions and 3 deletions
+21 -2
View File
@@ -1,5 +1,5 @@
import { spawnWithWindowsHide } from "../../shared/spawn-with-windows-hide"
import { log } from "../../shared"
import { detectShellType, log } from "../../shared"
async function readOutput(
stream: ReadableStream<Uint8Array> | undefined,
@@ -20,6 +20,24 @@ async function readOutput(
}
}
function resolveHookShellCommand(command: string): string[] {
const shellType = detectShellType()
switch (shellType) {
case "powershell": {
const powershellExecutable = process.platform === "win32" ? "powershell.exe" : "pwsh"
return [powershellExecutable, "-NoProfile", "-Command", command]
}
case "cmd":
return [process.env.ComSpec || "cmd.exe", "/d", "/s", "/c", command]
case "csh":
return ["csh", "-c", command]
case "unix":
default:
return ["sh", "-c", command]
}
}
export async function executeOnCompleteHook(options: {
command: string
sessionId: string
@@ -37,7 +55,8 @@ export async function executeOnCompleteHook(options: {
log("Running on-complete hook", { command: trimmedCommand })
try {
const proc = spawnWithWindowsHide(["sh", "-c", trimmedCommand], {
const shellCommand = resolveHookShellCommand(trimmedCommand)
const proc = spawnWithWindowsHide(shellCommand, {
env: {
...process.env,
SESSION_ID: sessionId,