fix(non-interactive-env): respect Windows command shell

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-13 20:07:46 +09:00
parent cab20568da
commit fef1d4530b
2 changed files with 73 additions and 4 deletions
@@ -1,7 +1,7 @@
import type { PluginInput } from "@opencode-ai/plugin"
import { HOOK_NAME, NON_INTERACTIVE_ENV, SHELL_COMMAND_PATTERNS } from "./constants"
import { log, buildEnvPrefix } from "../../shared"
import { detectShellType } from "../../shared/shell-env"
import { detectShellType, type ShellType } from "../../shared/shell-env"
export * from "./constants"
export * from "./detector"
@@ -20,6 +20,29 @@ function detectBannedCommand(command: string): string | undefined {
return undefined
}
function detectCommandShellType(): ShellType {
if (process.platform === "win32" && process.env.SHELL) {
const shellName = process.env.SHELL.replace(/\\/g, "/").split("/").pop()?.toLowerCase()
if (shellName === "cmd" || shellName === "cmd.exe") {
return "cmd"
}
if (
shellName === "powershell" ||
shellName === "powershell.exe" ||
shellName === "pwsh" ||
shellName === "pwsh.exe"
) {
return "powershell"
}
}
if (process.platform === "win32" && !process.env.SHELL && !process.env.MSYSTEM) {
return "cmd"
}
return detectShellType()
}
export function createNonInteractiveEnvHook(_ctx: PluginInput) {
return {
"tool.execute.before": async (
@@ -53,7 +76,7 @@ export function createNonInteractiveEnvHook(_ctx: PluginInput) {
// The env vars (GIT_EDITOR=:, EDITOR=:, etc.) must ALWAYS be injected
// for git commands to prevent interactive prompts.
const shellType = detectShellType()
const shellType = detectCommandShellType()
const envPrefix = buildEnvPrefix(NON_INTERACTIVE_ENV, shellType)
// Check if the command already starts with the prefix to avoid stacking.