MCPcopy Index your code
hub / github.com/AI45Lab/Code / fire_pre_tool_use

Method fire_pre_tool_use

core/src/agent/hook_runtime.rs:12–39  ·  view source on GitHub ↗

Fire PreToolUse hook event before tool execution. Returns the HookResult which may block the tool call.

(
        &self,
        session_id: &str,
        tool_name: &str,
        args: &serde_json::Value,
        recent_tools: Vec<String>,
    )

Source from the content-addressed store, hash-verified

10 /// Fire PreToolUse hook event before tool execution.
11 /// Returns the HookResult which may block the tool call.
12 pub(super) async fn fire_pre_tool_use(
13 &self,
14 session_id: &str,
15 tool_name: &str,
16 args: &serde_json::Value,
17 recent_tools: Vec<String>,
18 ) -> Option<HookResult> {
19 if let Some(he) = &self.config.hook_engine {
20 // Convert null args to empty object so JS callbacks don't get null.input errors
21 let safe_args = if args.is_null() {
22 serde_json::Value::Object(Default::default())
23 } else {
24 args.clone()
25 };
26 let event = HookEvent::PreToolUse(PreToolUseEvent {
27 session_id: session_id.to_string(),
28 tool: tool_name.to_string(),
29 args: safe_args,
30 working_directory: self.tool_context.workspace.to_string_lossy().to_string(),
31 recent_tools,
32 });
33 let result = he.fire(&event).await;
34 if result.is_block() {
35 return Some(result);
36 }
37 }
38 None
39 }
40
41 /// Fire PostToolUse hook event after tool execution (fire-and-forget).
42 pub(super) async fn fire_post_tool_use(

Callers 1

decide_tool_gateMethod · 0.80

Calls 3

cloneMethod · 0.45
fireMethod · 0.45
is_blockMethod · 0.45

Tested by

no test coverage detected