Skip to content

Commit 61740e5

Browse files
committed
feat(non-interactive-env): add banned command detection using SHELL_COMMAND_PATTERNS
- Detect and warn about interactive commands (vim, nano, less, etc.) - Filter out descriptive entries with parentheses from pattern matching 🤖 GENERATED WITH ASSISTANCE OF OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
1 parent 8495be6 commit 61740e5

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
import type { PluginInput } from "@opencode-ai/plugin"
2-
import { HOOK_NAME, NON_INTERACTIVE_ENV } from "./constants"
2+
import { HOOK_NAME, NON_INTERACTIVE_ENV, SHELL_COMMAND_PATTERNS } from "./constants"
33
import { log } from "../../shared"
44

55
export * from "./constants"
66
export * from "./types"
77

8+
const BANNED_COMMAND_PATTERNS = SHELL_COMMAND_PATTERNS.banned
9+
.filter((cmd) => !cmd.includes("("))
10+
.map((cmd) => new RegExp(`\\b${cmd}\\b`))
11+
12+
function detectBannedCommand(command: string): string | undefined {
13+
for (let i = 0; i < BANNED_COMMAND_PATTERNS.length; i++) {
14+
if (BANNED_COMMAND_PATTERNS[i].test(command)) {
15+
return SHELL_COMMAND_PATTERNS.banned[i]
16+
}
17+
}
18+
return undefined
19+
}
20+
821
export function createNonInteractiveEnvHook(_ctx: PluginInput) {
922
return {
1023
"tool.execute.before": async (
1124
input: { tool: string; sessionID: string; callID: string },
12-
output: { args: Record<string, unknown> }
25+
output: { args: Record<string, unknown>; message?: string }
1326
): Promise<void> => {
1427
if (input.tool.toLowerCase() !== "bash") {
1528
return
@@ -25,6 +38,11 @@ export function createNonInteractiveEnvHook(_ctx: PluginInput) {
2538
...NON_INTERACTIVE_ENV,
2639
}
2740

41+
const bannedCmd = detectBannedCommand(command)
42+
if (bannedCmd) {
43+
output.message = `⚠️ Warning: '${bannedCmd}' is an interactive command that may hang in non-interactive environments.`
44+
}
45+
2846
log(`[${HOOK_NAME}] Set non-interactive environment variables`, {
2947
sessionID: input.sessionID,
3048
env: NON_INTERACTIVE_ENV,

0 commit comments

Comments
 (0)