Skip to content

Commit 678967f

Browse files
committed
CM-58022-review
1 parent f7a2b30 commit 678967f

File tree

20 files changed

+113
-90
lines changed

20 files changed

+113
-90
lines changed

cycode/cli/apps/ai_guardrails/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import typer
22

33
from cycode.cli.apps.ai_guardrails.install_command import install_command
4+
from cycode.cli.apps.ai_guardrails.scan.scan_command import scan_command
45
from cycode.cli.apps.ai_guardrails.status_command import status_command
56
from cycode.cli.apps.ai_guardrails.uninstall_command import uninstall_command
67

@@ -9,3 +10,8 @@
910
app.command(name='install', short_help='Install AI guardrails hooks for supported IDEs.')(install_command)
1011
app.command(name='uninstall', short_help='Remove AI guardrails hooks from supported IDEs.')(uninstall_command)
1112
app.command(name='status', short_help='Show AI guardrails hook installation status.')(status_command)
13+
app.command(
14+
hidden=True,
15+
name='scan',
16+
short_help='Scan content from AI IDE hooks for secrets (reads JSON from stdin).',
17+
)(scan_command)
File renamed without changes.
File renamed without changes.

cycode/cli/apps/scan/prompt/handlers.py renamed to cycode/cli/apps/ai_guardrails/scan/handlers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
import typer
1515

16-
from cycode.cli.apps.scan.code_scanner import _get_scan_documents_thread_func
17-
from cycode.cli.apps.scan.prompt.payload import AIHookPayload
18-
from cycode.cli.apps.scan.prompt.policy import get_policy_value
19-
from cycode.cli.apps.scan.prompt.response_builders import get_response_builder
20-
from cycode.cli.apps.scan.prompt.types import AiHookEventType, AIHookOutcome, BlockReason
21-
from cycode.cli.apps.scan.prompt.utils import (
16+
from cycode.cli.apps.ai_guardrails.scan.payload import AIHookPayload
17+
from cycode.cli.apps.ai_guardrails.scan.policy import get_policy_value
18+
from cycode.cli.apps.ai_guardrails.scan.response_builders import get_response_builder
19+
from cycode.cli.apps.ai_guardrails.scan.types import AiHookEventType, AIHookOutcome, BlockReason
20+
from cycode.cli.apps.ai_guardrails.scan.utils import (
2221
is_denied_path,
2322
truncate_utf8,
2423
)
24+
from cycode.cli.apps.scan.code_scanner import _get_scan_documents_thread_func
2525
from cycode.cli.apps.scan.scan_parameters import get_scan_parameters
2626
from cycode.cli.models import Document
2727
from cycode.cli.utils.progress_bar import DummyProgressBar, ScanProgressBarSection

cycode/cli/apps/scan/prompt/payload.py renamed to cycode/cli/apps/ai_guardrails/scan/payload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dataclasses import dataclass
44
from typing import Optional
55

6-
from cycode.cli.apps.scan.prompt.types import CURSOR_EVENT_MAPPING
6+
from cycode.cli.apps.ai_guardrails.scan.types import CURSOR_EVENT_MAPPING
77

88

99
@dataclass

cycode/cli/apps/scan/prompt/policy.py renamed to cycode/cli/apps/ai_guardrails/scan/policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import yaml
1515

16-
from cycode.cli.apps.scan.prompt.consts import DEFAULT_POLICY, POLICY_FILE_NAME
16+
from cycode.cli.apps.ai_guardrails.scan.consts import DEFAULT_POLICY, POLICY_FILE_NAME
1717

1818

1919
def deep_merge(base: dict, override: dict) -> dict:
File renamed without changes.

cycode/cli/apps/scan/prompt/prompt_command.py renamed to cycode/cli/apps/ai_guardrails/scan/scan_command.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""
2-
Prompt scan command for AI guardrails.
2+
Scan command for AI guardrails.
33
44
This command handles AI IDE hooks by reading JSON from stdin and outputting
5-
a JSON response to stdout.
5+
a JSON response to stdout. It scans prompts, file reads, and MCP tool calls
6+
for secrets before they are sent to AI models.
67
78
Supports multiple IDEs with different hook event types. The specific hook events
89
supported depend on the IDE being used (e.g., Cursor supports beforeSubmitPrompt,
@@ -15,12 +16,12 @@
1516
import click
1617
import typer
1718

18-
from cycode.cli.apps.scan.prompt.handlers import get_handler_for_event
19-
from cycode.cli.apps.scan.prompt.payload import AIHookPayload
20-
from cycode.cli.apps.scan.prompt.policy import load_policy
21-
from cycode.cli.apps.scan.prompt.response_builders import get_response_builder
22-
from cycode.cli.apps.scan.prompt.types import AiHookEventType
23-
from cycode.cli.apps.scan.prompt.utils import output_json, safe_json_parse
19+
from cycode.cli.apps.ai_guardrails.scan.handlers import get_handler_for_event
20+
from cycode.cli.apps.ai_guardrails.scan.payload import AIHookPayload
21+
from cycode.cli.apps.ai_guardrails.scan.policy import load_policy
22+
from cycode.cli.apps.ai_guardrails.scan.response_builders import get_response_builder
23+
from cycode.cli.apps.ai_guardrails.scan.types import AiHookEventType
24+
from cycode.cli.apps.ai_guardrails.scan.utils import output_json, safe_json_parse
2425
from cycode.cli.exceptions.custom_exceptions import HttpUnauthorizedError
2526
from cycode.cli.utils.get_api_client import get_ai_security_manager_client, get_scan_cycode_client
2627
from cycode.cli.utils.sentry import add_breadcrumb
@@ -59,7 +60,7 @@ def _initialize_clients(ctx: typer.Context) -> None:
5960
ctx.obj['ai_security_client'] = ai_security_client
6061

6162

62-
def prompt_command(
63+
def scan_command(
6364
ctx: typer.Context,
6465
ide: Annotated[
6566
str,
@@ -70,7 +71,7 @@ def prompt_command(
7071
),
7172
] = 'cursor',
7273
) -> None:
73-
"""Handle AI guardrails hooks from supported IDEs.
74+
"""Scan content from AI IDE hooks for secrets.
7475
7576
This command reads a JSON payload from stdin containing hook event data
7677
and outputs a JSON response to stdout indicating whether to allow or block the action.
@@ -80,9 +81,9 @@ def prompt_command(
8081
file access, and tool executions.
8182
8283
Example usage (from IDE hooks configuration):
83-
{ "command": "cycode scan prompt" }
84+
{ "command": "cycode ai-guardrails scan" }
8485
"""
85-
add_breadcrumb('prompt')
86+
add_breadcrumb('ai-guardrails-scan')
8687

8788
stdin_data = sys.stdin.read().strip()
8889
payload = safe_json_parse(stdin_data)

cycode/cli/apps/scan/prompt/types.py renamed to cycode/cli/apps/ai_guardrails/scan/types.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"""Type definitions for AI guardrails."""
22

3-
from enum import Enum
3+
import sys
44

5+
if sys.version_info >= (3, 11):
6+
from enum import StrEnum
7+
else:
8+
from enum import Enum
59

6-
class StrEnum(str, Enum):
7-
def __str__(self) -> str:
8-
return self.value
10+
class StrEnum(str, Enum):
11+
def __str__(self) -> str:
12+
return self.value
913

1014

1115
class AiHookEventType(StrEnum):

cycode/cli/apps/scan/prompt/utils.py renamed to cycode/cli/apps/ai_guardrails/scan/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
from pathlib import Path
1010

11-
from cycode.cli.apps.scan.prompt.policy import get_policy_value
11+
from cycode.cli.apps.ai_guardrails.scan.policy import get_policy_value
1212

1313

1414
def safe_json_parse(s: str) -> dict:

0 commit comments

Comments
 (0)