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:
40
src/hooks/non-interactive-env/index.ts
Normal file
40
src/hooks/non-interactive-env/index.ts
Normal 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,
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user