11import type { PluginInput } from "@opencode-ai/plugin"
2- import { HOOK_NAME , NULL_DEVICE , NON_INTERACTIVE_ENV } from "./constants"
2+ import { HOOK_NAME , NON_INTERACTIVE_ENV } from "./constants"
33import { log } from "../../shared"
44
55export * from "./constants"
66export * from "./types"
77
8- function wrapWithNonInteractiveEnv ( command : string ) : string {
9- const envPrefix = Object . entries ( NON_INTERACTIVE_ENV )
10- . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
11- . join ( " " )
12-
13- return `${ envPrefix } ${ command } < ${ NULL_DEVICE } 2>&1 || ${ envPrefix } ${ command } 2>&1`
14- }
15-
168export function createNonInteractiveEnvHook ( _ctx : PluginInput ) {
179 return {
1810 "tool.execute.before" : async (
@@ -28,12 +20,14 @@ export function createNonInteractiveEnvHook(_ctx: PluginInput) {
2820 return
2921 }
3022
31- output . args . command = wrapWithNonInteractiveEnv ( command )
23+ output . args . env = {
24+ ...( output . args . env as Record < string , string > | undefined ) ,
25+ ...NON_INTERACTIVE_ENV ,
26+ }
3227
33- log ( `[${ HOOK_NAME } ] Wrapped command with non-interactive environment` , {
28+ log ( `[${ HOOK_NAME } ] Set non-interactive environment variables ` , {
3429 sessionID : input . sessionID ,
35- original : command ,
36- wrapped : output . args . command ,
30+ env : NON_INTERACTIVE_ENV ,
3731 } )
3832 } ,
3933 }
0 commit comments