forked from code-yeongyu/oh-my-openagent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodex-process.ts
More file actions
41 lines (35 loc) · 1.15 KB
/
Copy pathcodex-process.ts
File metadata and controls
41 lines (35 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { spawn } from "../../../omo-opencode/src/shared/bun-spawn-shim"
import type { RunCommand } from "./types"
const WINDOWS_CMD_SHIM_COMMANDS = new Set(["codex", "npm", "npx"])
export type RunCommandInvocation = {
readonly command: string
readonly args: readonly string[]
}
export function resolveRunCommandInvocation(
command: string,
args: readonly string[],
platform: NodeJS.Platform = process.platform,
): RunCommandInvocation {
if (platform !== "win32" || !WINDOWS_CMD_SHIM_COMMANDS.has(command.toLowerCase())) {
return { command, args: [...args] }
}
return {
command: "cmd.exe",
args: ["/d", "/s", "/c", `${command}.cmd`, ...args],
}
}
export const defaultRunCommand: RunCommand = async (command, args, options) => {
const invocation = resolveRunCommandInvocation(command, args)
const proc = spawn({
cmd: [invocation.command, ...invocation.args],
cwd: options.cwd,
env: options.env,
stdin: "ignore",
stdout: "inherit",
stderr: "inherit",
})
const code = await proc.exited
if (code !== 0) {
throw new Error(`${command} ${args.join(" ")} failed in ${options.cwd} with exit code ${code}`)
}
}