From 7fd52e27ce03ab17e286a88939fe5d66f8c04117 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 15 Dec 2025 08:54:33 +0900 Subject: [PATCH] refactor(non-interactive-env): use args.env instead of command prepending MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) --- src/hooks/non-interactive-env/constants.ts | 2 -- src/hooks/non-interactive-env/index.ts | 20 +++++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/hooks/non-interactive-env/constants.ts b/src/hooks/non-interactive-env/constants.ts index 88a1fee..a0696d0 100644 --- a/src/hooks/non-interactive-env/constants.ts +++ b/src/hooks/non-interactive-env/constants.ts @@ -1,7 +1,5 @@ export const HOOK_NAME = "non-interactive-env" -export const NULL_DEVICE = process.platform === "win32" ? "NUL" : "/dev/null" - export const NON_INTERACTIVE_ENV: Record = { CI: "true", DEBIAN_FRONTEND: "noninteractive", diff --git a/src/hooks/non-interactive-env/index.ts b/src/hooks/non-interactive-env/index.ts index 830fa6f..9144823 100644 --- a/src/hooks/non-interactive-env/index.ts +++ b/src/hooks/non-interactive-env/index.ts @@ -1,18 +1,10 @@ import type { PluginInput } from "@opencode-ai/plugin" -import { HOOK_NAME, NULL_DEVICE, NON_INTERACTIVE_ENV } from "./constants" +import { HOOK_NAME, 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 ( @@ -28,12 +20,14 @@ export function createNonInteractiveEnvHook(_ctx: PluginInput) { return } - output.args.command = wrapWithNonInteractiveEnv(command) + output.args.env = { + ...(output.args.env as Record | undefined), + ...NON_INTERACTIVE_ENV, + } - log(`[${HOOK_NAME}] Wrapped command with non-interactive environment`, { + log(`[${HOOK_NAME}] Set non-interactive environment variables`, { sessionID: input.sessionID, - original: command, - wrapped: output.args.command, + env: NON_INTERACTIVE_ENV, }) }, }