Coverage for src / moai_adk / core / git / event_detector.py: 38.89%
18 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-20 20:52 +0900
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-20 20:52 +0900
1"""
2Event Detector - Identify risky operations.
4SPEC: .moai/specs/SPEC-CHECKPOINT-EVENT-001/spec.md
5"""
7from pathlib import Path
10class EventDetector:
11 """Detect potentially risky operations."""
13 CRITICAL_FILES = {
14 "CLAUDE.md",
15 "config.json",
16 ".moai/config/config.json",
17 }
19 CRITICAL_DIRS = {
20 ".moai/memory",
21 }
23 def is_risky_deletion(self, deleted_files: list[str]) -> bool:
24 """
25 Detect large-scale file deletions.
27 SPEC requirement: deleting 10 or more files counts as risky.
29 Args:
30 deleted_files: Files slated for deletion.
32 Returns:
33 True when 10 or more files are deleted, otherwise False.
34 """
35 return len(deleted_files) >= 10
37 def is_risky_refactoring(self, renamed_files: list[tuple[str, str]]) -> bool:
38 """
39 Detect large-scale refactoring.
41 SPEC requirement: renaming 10 or more files counts as risky.
43 Args:
44 renamed_files: List of (old_name, new_name) pairs.
46 Returns:
47 True when 10 or more files are renamed, otherwise False.
48 """
49 return len(renamed_files) >= 10
51 def is_critical_file(self, file_path: Path) -> bool:
52 """
53 Determine whether the file is critical.
55 SPEC requirement: modifying CLAUDE.md, config.json, or .moai/memory/*.md is risky.
57 Args:
58 file_path: File path to inspect.
60 Returns:
61 True when the file is critical, otherwise False.
62 """
63 # Check whether the file name is in the critical list
64 if file_path.name in self.CRITICAL_FILES:
65 return True
67 # Convert to string for further checks
68 path_str = str(file_path)
70 # Detect .moai/config/config.json paths
71 if ".moai/config/config.json" in path_str or ".moai\\config.json" in path_str:
72 return True
74 # Detect files inside the .moai/memory/ directory
75 for critical_dir in self.CRITICAL_DIRS:
76 if critical_dir in path_str or critical_dir.replace("/", "\\") in path_str:
77 return True
79 return False