refactor: move grep blocking from hook to config
This commit is contained in:
18
src/hooks/grep-blocker.ts
Normal file
18
src/hooks/grep-blocker.ts
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,10 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
|||||||
...config.agent,
|
...config.agent,
|
||||||
...builtinAgents,
|
...builtinAgents,
|
||||||
}
|
}
|
||||||
|
config.tools = {
|
||||||
|
...config.tools,
|
||||||
|
grep: false,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
event: async (input) => {
|
event: async (input) => {
|
||||||
@@ -99,10 +103,6 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
"tool.execute.before": async (input, _output) => {
|
"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) {
|
if (input.sessionID === mainSessionID) {
|
||||||
updateTerminalTitle({
|
updateTerminalTitle({
|
||||||
sessionId: input.sessionID,
|
sessionId: input.sessionID,
|
||||||
|
|||||||
Reference in New Issue
Block a user