From 3d29214c29f95642018c96884b014825ba22ad12 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Thu, 4 Dec 2025 23:11:59 +0900 Subject: [PATCH] refactor: move grep blocking from hook to config --- src/hooks/grep-blocker.ts | 18 ++++++++++++++++++ src/index.ts | 8 ++++---- 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/hooks/grep-blocker.ts diff --git a/src/hooks/grep-blocker.ts b/src/hooks/grep-blocker.ts new file mode 100644 index 0000000..53db0da --- /dev/null +++ b/src/hooks/grep-blocker.ts @@ -0,0 +1,18 @@ +import type { PluginInput } from "@opencode-ai/plugin" + +const BLOCKED_MESSAGE = + "Error: [BLOCKED] grep has no timeout and can freeze the system. " + + "It is permanently disabled. Use 'safe_grep' instead." + +export function createGrepBlocker(_ctx: PluginInput) { + return { + "tool.execute.before": async ( + input: { tool: string; sessionID: string; callID: string }, + _output: { args: unknown } + ) => { + if (input.tool === "grep") { + throw new Error(BLOCKED_MESSAGE) + } + }, + } +} diff --git a/src/index.ts b/src/index.ts index 73863a6..053a267 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,6 +22,10 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { ...config.agent, ...builtinAgents, } + config.tools = { + ...config.tools, + grep: false, + } }, event: async (input) => { @@ -99,10 +103,6 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { }, "tool.execute.before": async (input, _output) => { - if (input.tool === "grep") { - throw new Error(`[BLOCKED] grep has no timeout and can freeze the system. It is permanently disabled. Use 'safe-grep' instead.`) - } - if (input.sessionID === mainSessionID) { updateTerminalTitle({ sessionId: input.sessionID,