-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathstatus_command.py
More file actions
98 lines (80 loc) · 3.46 KB
/
status_command.py
File metadata and controls
98 lines (80 loc) · 3.46 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""Status command for AI guardrails hooks."""
import os
from pathlib import Path
from typing import Annotated, Optional
import typer
from rich.table import Table
from cycode.cli.apps.ai_guardrails.command_utils import console, validate_and_parse_ide, validate_scope
from cycode.cli.apps.ai_guardrails.consts import IDE_CONFIGS, AIIDEType
from cycode.cli.apps.ai_guardrails.hooks_manager import get_hooks_status
def status_command(
ctx: typer.Context,
scope: Annotated[
str,
typer.Option(
'--scope',
'-s',
help='Check scope: "user", "repo", or "all" for both.',
),
] = 'all',
ide: Annotated[
str,
typer.Option(
'--ide',
help='IDE to check status for (e.g., "cursor", "claude-code", or "all" for all IDEs). Defaults to cursor.',
),
] = AIIDEType.CURSOR.value,
repo_path: Annotated[
Optional[Path],
typer.Option(
'--repo-path',
help='Repository path for repo-scoped status (defaults to current directory).',
exists=True,
file_okay=False,
dir_okay=True,
resolve_path=True,
),
] = None,
) -> None:
"""Show AI guardrails hook installation status.
Displays the current status of Cycode AI guardrails hooks for the specified IDE.
Examples:
cycode ai-guardrails status # Show both user and repo status
cycode ai-guardrails status --scope user # Show only user-level status
cycode ai-guardrails status --scope repo # Show only repo-level status
cycode ai-guardrails status --ide cursor # Check status for Cursor IDE
cycode ai-guardrails status --ide all # Check status for all supported IDEs
"""
# Validate inputs (status allows 'all' scope)
validate_scope(scope, allowed_scopes=('user', 'repo', 'all'))
if repo_path is None:
repo_path = Path(os.getcwd())
ide_type = validate_and_parse_ide(ide)
ides_to_check: list[AIIDEType] = list(AIIDEType) if ide_type is None else [ide_type]
scopes_to_check = ['user', 'repo'] if scope == 'all' else [scope]
for current_ide in ides_to_check:
ide_name = IDE_CONFIGS[current_ide].name
console.print()
console.print(f'[bold cyan]═══ {ide_name} ═══[/]')
for check_scope in scopes_to_check:
status = get_hooks_status(check_scope, repo_path if check_scope == 'repo' else None, ide=current_ide)
console.print()
console.print(f'[bold]{check_scope.upper()} SCOPE[/]')
console.print(f'Path: {status["hooks_path"]}')
if not status['file_exists']:
console.print('[dim]No hooks file found[/]')
continue
if status['cycode_installed']:
console.print('[green]✓ Cycode AI guardrails: INSTALLED[/]')
else:
console.print('[yellow]○ Cycode AI guardrails: NOT INSTALLED[/]')
# Show hook details
table = Table(show_header=True, header_style='bold')
table.add_column('Hook Event')
table.add_column('Cycode Enabled')
table.add_column('Total Hooks')
for event, info in status['hooks'].items():
enabled = '[green]Yes[/]' if info['enabled'] else '[dim]No[/]'
table.add_row(event, enabled, str(info['total_entries']))
console.print(table)
console.print()