Skip to content

Commit 7fd52e2

Browse files
committed
refactor(non-interactive-env): use args.env instead of command prepending
🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
1 parent 08481c0 commit 7fd52e2

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

src/hooks/non-interactive-env/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
export const HOOK_NAME = "non-interactive-env"
22

3-
export const NULL_DEVICE = process.platform === "win32" ? "NUL" : "/dev/null"
4-
53
export const NON_INTERACTIVE_ENV: Record<string, string> = {
64
CI: "true",
75
DEBIAN_FRONTEND: "noninteractive",

src/hooks/non-interactive-env/index.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import 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"
33
import { log } from "../../shared"
44

55
export * from "./constants"
66
export * 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-
168
export 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

Comments
 (0)