refactor(hooks): rename interactive-bash-blocker to non-interactive-env

- Replace regex-based command blocking with environment configuration
- Add cross-platform null device support (NUL for Windows, /dev/null for Unix)
- Wrap all bash commands with non-interactive environment variables
- Only block TUI programs that require full PTY
- Update schema, README docs, and all imports/exports

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2025-12-14 22:34:55 +09:00
parent 5dd4d97c94
commit 192e8adf18
11 changed files with 1169 additions and 277 deletions

View File

@@ -0,0 +1,40 @@
import type { PluginInput } from "@opencode-ai/plugin"
import { HOOK_NAME, NULL_DEVICE, NON_INTERACTIVE_ENV } from "./constants"
import { log } from "../../shared"
export * from "./constants"
export * from "./types"
function wrapWithNonInteractiveEnv(command: string): string {
const envPrefix = Object.entries(NON_INTERACTIVE_ENV)
.map(([key, value]) => `${key}=${value}`)
.join(" ")
return `${envPrefix} ${command} < ${NULL_DEVICE} 2>&1 || ${envPrefix} ${command} 2>&1`
}
export function createNonInteractiveEnvHook(_ctx: PluginInput) {
return {
"tool.execute.before": async (
input: { tool: string; sessionID: string; callID: string },
output: { args: Record<string, unknown> }
): Promise<void> => {
if (input.tool.toLowerCase() !== "bash") {
return
}
const command = output.args.command as string | undefined
if (!command) {
return
}
output.args.command = wrapWithNonInteractiveEnv(command)
log(`[${HOOK_NAME}] Wrapped command with non-interactive environment`, {
sessionID: input.sessionID,
original: command,
wrapped: output.args.command,
})
},
}
}