cyril_core/hooks/
builtins.rs1use std::path::PathBuf;
2
3use async_trait::async_trait;
4
5use super::types::*;
6
7#[derive(Debug)]
9pub struct PathValidationHook {
10 pub allowed_root: PathBuf,
11}
12
13#[async_trait(?Send)]
14impl Hook for PathValidationHook {
15 fn name(&self) -> &str {
16 "path-validation"
17 }
18
19 fn timing(&self) -> HookTiming {
20 HookTiming::Before
21 }
22
23 fn target(&self) -> HookTarget {
24 HookTarget::FsWrite
25 }
26
27 async fn run(&self, ctx: &HookContext) -> HookResult {
28 if let Some(path) = &ctx.path {
29 if !path.starts_with(&self.allowed_root) {
30 return HookResult::Blocked {
31 reason: format!(
32 "Write blocked: {} is outside project root {}",
33 path.display(),
34 self.allowed_root.display()
35 ),
36 };
37 }
38 }
39 HookResult::Continue
40 }
41}