(
&self,
hook_id: String,
event_type: String,
matcher: Option<&Bound<'_, PyDict>>,
config: Option<&Bound<'_, PyDict>>,
handler: Option<pyo3::Py<pyo3::Py
| 2840 | /// ``{"action": "continue"}`` allows execution to proceed. |
| 2841 | #[pyo3(signature = (hook_id, event_type, matcher=None, config=None, handler=None))] |
| 2842 | fn register_hook( |
| 2843 | &self, |
| 2844 | hook_id: String, |
| 2845 | event_type: String, |
| 2846 | matcher: Option<&Bound<'_, PyDict>>, |
| 2847 | config: Option<&Bound<'_, PyDict>>, |
| 2848 | handler: Option<pyo3::Py<pyo3::PyAny>>, |
| 2849 | ) -> PyResult<()> { |
| 2850 | let rust_event_type = py_parse_hook_event_type(&event_type)?; |
| 2851 | let mut hook = RustHook::new(&hook_id, rust_event_type); |
| 2852 | |
| 2853 | if let Some(m) = matcher { |
| 2854 | let mut rust_matcher = RustHookMatcher::new(); |
| 2855 | if let Some(tool) = m.get_item("tool")? { |
| 2856 | rust_matcher = rust_matcher.with_tool(tool.extract::<String>()?); |
| 2857 | } |
| 2858 | if let Some(path) = m.get_item("path_pattern")? { |
| 2859 | rust_matcher = rust_matcher.with_path(path.extract::<String>()?); |
| 2860 | } |
| 2861 | if let Some(cmd) = m.get_item("command_pattern")? { |
| 2862 | rust_matcher = rust_matcher.with_command(cmd.extract::<String>()?); |
| 2863 | } |
| 2864 | if let Some(sid) = m.get_item("session_id")? { |
| 2865 | rust_matcher = rust_matcher.with_session(sid.extract::<String>()?); |
| 2866 | } |
| 2867 | if let Some(skill) = m.get_item("skill")? { |
| 2868 | rust_matcher = rust_matcher.with_skill(skill.extract::<String>()?); |
| 2869 | } |
| 2870 | hook = hook.with_matcher(rust_matcher); |
| 2871 | } |
| 2872 | |
| 2873 | if let Some(c) = config { |
| 2874 | let priority = c |
| 2875 | .get_item("priority")? |
| 2876 | .map(|v| v.extract::<i32>()) |
| 2877 | .transpose()? |
| 2878 | .unwrap_or(100); |
| 2879 | let timeout_ms = c |
| 2880 | .get_item("timeout_ms")? |
| 2881 | .map(|v| v.extract::<u64>()) |
| 2882 | .transpose()? |
| 2883 | .unwrap_or(30000); |
| 2884 | let async_execution = c |
| 2885 | .get_item("async_execution")? |
| 2886 | .map(|v| v.extract::<bool>()) |
| 2887 | .transpose()? |
| 2888 | .unwrap_or(false); |
| 2889 | let max_retries = c |
| 2890 | .get_item("max_retries")? |
| 2891 | .map(|v| v.extract::<u32>()) |
| 2892 | .transpose()? |
| 2893 | .unwrap_or(0); |
| 2894 | hook = hook.with_config(RustHookConfig { |
| 2895 | priority, |
| 2896 | timeout_ms, |
| 2897 | async_execution, |
| 2898 | max_retries, |
| 2899 | }); |
nothing calls this directly
no test coverage detected