-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathconsts.py
More file actions
78 lines (58 loc) · 2 KB
/
Copy pathconsts.py
File metadata and controls
78 lines (58 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Constants for AI guardrails hooks management.
Currently supports:
- Cursor
To add a new IDE (e.g., Claude Code):
1. Add new value to AIIDEType enum
2. Create _get_<ide>_hooks_dir() function with platform-specific paths
3. Add entry to IDE_CONFIGS dict with IDE-specific hook event names
4. Unhide --ide option in commands (install, uninstall, status)
"""
import platform
from enum import Enum
from pathlib import Path
from typing import NamedTuple
class AIIDEType(str, Enum):
"""Supported AI IDE types."""
CURSOR = 'cursor'
class IDEConfig(NamedTuple):
"""Configuration for an AI IDE."""
name: str
hooks_dir: Path
repo_hooks_subdir: str # Subdirectory in repo for hooks (e.g., '.cursor')
hooks_file_name: str
hook_events: list[str] # List of supported hook event names for this IDE
def _get_cursor_hooks_dir() -> Path:
"""Get Cursor hooks directory based on platform."""
if platform.system() == 'Darwin':
return Path.home() / '.cursor'
if platform.system() == 'Windows':
return Path.home() / 'AppData' / 'Roaming' / 'Cursor'
# Linux
return Path.home() / '.config' / 'Cursor'
# IDE-specific configurations
IDE_CONFIGS: dict[AIIDEType, IDEConfig] = {
AIIDEType.CURSOR: IDEConfig(
name='Cursor',
hooks_dir=_get_cursor_hooks_dir(),
repo_hooks_subdir='.cursor',
hooks_file_name='hooks.json',
hook_events=['beforeSubmitPrompt', 'beforeReadFile', 'beforeMCPExecution'],
),
}
# Default IDE
DEFAULT_IDE = AIIDEType.CURSOR
# Command used in hooks
CYCODE_SCAN_PROMPT_COMMAND = 'cycode ai-guardrails scan'
def get_hooks_config(ide: AIIDEType) -> dict:
"""Get the hooks configuration for a specific IDE.
Args:
ide: The AI IDE type
Returns:
Dict with hooks configuration for the specified IDE
"""
config = IDE_CONFIGS[ide]
hooks = {event: [{'command': CYCODE_SCAN_PROMPT_COMMAND}] for event in config.hook_events}
return {
'version': 1,
'hooks': hooks,
}