refactor(non-interactive-env): use args.env instead of command prepending
🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
export const HOOK_NAME = "non-interactive-env"
|
export const HOOK_NAME = "non-interactive-env"
|
||||||
|
|
||||||
export const NULL_DEVICE = process.platform === "win32" ? "NUL" : "/dev/null"
|
|
||||||
|
|
||||||
export const NON_INTERACTIVE_ENV: Record<string, string> = {
|
export const NON_INTERACTIVE_ENV: Record<string, string> = {
|
||||||
CI: "true",
|
CI: "true",
|
||||||
DEBIAN_FRONTEND: "noninteractive",
|
DEBIAN_FRONTEND: "noninteractive",
|
||||||
|
|||||||
@@ -1,18 +1,10 @@
|
|||||||
import type { PluginInput } from "@opencode-ai/plugin"
|
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"
|
import { log } from "../../shared"
|
||||||
|
|
||||||
export * from "./constants"
|
export * from "./constants"
|
||||||
export * from "./types"
|
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) {
|
export function createNonInteractiveEnvHook(_ctx: PluginInput) {
|
||||||
return {
|
return {
|
||||||
"tool.execute.before": async (
|
"tool.execute.before": async (
|
||||||
@@ -28,12 +20,14 @@ export function createNonInteractiveEnvHook(_ctx: PluginInput) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
output.args.command = wrapWithNonInteractiveEnv(command)
|
output.args.env = {
|
||||||
|
...(output.args.env as Record<string, string> | undefined),
|
||||||
|
...NON_INTERACTIVE_ENV,
|
||||||
|
}
|
||||||
|
|
||||||
log(`[${HOOK_NAME}] Wrapped command with non-interactive environment`, {
|
log(`[${HOOK_NAME}] Set non-interactive environment variables`, {
|
||||||
sessionID: input.sessionID,
|
sessionID: input.sessionID,
|
||||||
original: command,
|
env: NON_INTERACTIVE_ENV,
|
||||||
wrapped: output.args.command,
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user