Skip to main content

rusty_hooks/hook/
payload.rs

1use serde::Deserialize;
2
3#[derive(Debug, Deserialize)]
4pub struct Payload {
5    tool_name: Option<String>,
6    tool_input: Option<ToolInput>,
7    cwd: Option<String>,
8}
9
10impl Payload {
11    pub fn tool_name(&self) -> Option<&str> {
12        self.tool_name.as_deref()
13    }
14
15    pub fn tool_input(&self) -> Option<&ToolInput> {
16        self.tool_input.as_ref()
17    }
18
19    pub fn cwd(&self) -> Option<&str> {
20        self.cwd.as_deref()
21    }
22}
23
24#[derive(Debug, Deserialize)]
25pub struct ToolInput {
26    file_path: Option<String>,
27    pub content: Option<String>,
28    pub new_string: Option<String>,
29    pub old_string: Option<String>,
30    #[serde(default)]
31    pub replace_all: bool,
32}
33
34impl ToolInput {
35    /// Returns `Some(&str)` only if `file_path` is present and non-blank.
36    pub fn file_path(&self) -> Option<&str> {
37        self.file_path.as_deref().filter(|s| !s.trim().is_empty())
38    }
39}