cycode 3.17.1.dev9__py3-none-any.whl → 3.17.1.dev11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cycode/__init__.py +1 -1
- cycode/cli/apps/ai_guardrails/scan/scan_command.py +4 -4
- cycode/cli/apps/ai_guardrails/scan/utils.py +17 -0
- cycode/cli/apps/ai_guardrails/session_start_command.py +2 -2
- cycode/cli/files_collector/sca/maven/restore_gradle_dependencies.py +18 -4
- {cycode-3.17.1.dev9.dist-info → cycode-3.17.1.dev11.dist-info}/METADATA +1 -1
- {cycode-3.17.1.dev9.dist-info → cycode-3.17.1.dev11.dist-info}/RECORD +10 -10
- {cycode-3.17.1.dev9.dist-info → cycode-3.17.1.dev11.dist-info}/WHEEL +0 -0
- {cycode-3.17.1.dev9.dist-info → cycode-3.17.1.dev11.dist-info}/entry_points.txt +0 -0
- {cycode-3.17.1.dev9.dist-info → cycode-3.17.1.dev11.dist-info}/licenses/LICENCE +0 -0
cycode/__init__.py
CHANGED
|
@@ -5,4 +5,4 @@ import time as _time
|
|
|
5
5
|
# end-to-end scan duration from the moment the user actually triggered it.
|
|
6
6
|
_BOOT_WALL: float = _time.time()
|
|
7
7
|
|
|
8
|
-
__version__ = '3.17.1.
|
|
8
|
+
__version__ = '3.17.1.dev11' # DON'T TOUCH. Placeholder. Will be filled automatically on poetry build from Git Tag
|
|
@@ -7,7 +7,6 @@ The handlers in ``handlers.py`` are agent-agnostic (they return
|
|
|
7
7
|
``HookDecision``); ``IDE.build_hook_response`` is the per-IDE translation step.
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
-
import sys
|
|
11
10
|
from typing import Annotated, Optional, Union
|
|
12
11
|
|
|
13
12
|
import click
|
|
@@ -18,7 +17,7 @@ from cycode.cli.apps.ai_guardrails.ides.base import HookDecision
|
|
|
18
17
|
from cycode.cli.apps.ai_guardrails.scan.handlers import get_handler_for_event
|
|
19
18
|
from cycode.cli.apps.ai_guardrails.scan.policy import load_policy
|
|
20
19
|
from cycode.cli.apps.ai_guardrails.scan.types import AiHookEventType
|
|
21
|
-
from cycode.cli.apps.ai_guardrails.scan.utils import output_json, safe_json_parse
|
|
20
|
+
from cycode.cli.apps.ai_guardrails.scan.utils import output_json, read_stdin_text, safe_json_parse
|
|
22
21
|
from cycode.cli.exceptions.custom_exceptions import HttpUnauthorizedError
|
|
23
22
|
from cycode.cli.utils.get_api_client import get_ai_security_manager_client, get_scan_cycode_client
|
|
24
23
|
from cycode.logger import get_logger
|
|
@@ -91,7 +90,7 @@ def scan_command(
|
|
|
91
90
|
"""
|
|
92
91
|
ide_integration = get_ide(ide)
|
|
93
92
|
|
|
94
|
-
stdin_data =
|
|
93
|
+
stdin_data = read_stdin_text().strip()
|
|
95
94
|
payload = safe_json_parse(stdin_data)
|
|
96
95
|
|
|
97
96
|
if not payload:
|
|
@@ -113,7 +112,8 @@ def scan_command(
|
|
|
113
112
|
event_name = unified_payload.event_name
|
|
114
113
|
logger.debug('Processing AI guardrails hook', extra={'event_name': event_name, 'ide': ide_integration.name})
|
|
115
114
|
|
|
116
|
-
|
|
115
|
+
# `or` (not a .get default) - Cursor sends workspace_roots=[] when no folder is open.
|
|
116
|
+
workspace_roots = payload.get('workspace_roots') or ['.']
|
|
117
117
|
policy = load_policy(workspace_roots[0])
|
|
118
118
|
|
|
119
119
|
try:
|
|
@@ -6,11 +6,28 @@ Includes JSON parsing, path matching, and text handling utilities.
|
|
|
6
6
|
|
|
7
7
|
import json
|
|
8
8
|
import os
|
|
9
|
+
import sys
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
|
|
11
12
|
from cycode.cli.apps.ai_guardrails.scan.policy import get_policy_value
|
|
12
13
|
|
|
13
14
|
|
|
15
|
+
def read_stdin_text() -> str:
|
|
16
|
+
"""Read the hook payload from stdin as UTF-8 text.
|
|
17
|
+
|
|
18
|
+
Reads bytes and decodes with utf-8-sig: hook payloads are UTF-8 JSON, but on Windows
|
|
19
|
+
Python decodes piped stdin with the ANSI code page (mojibake for non-ASCII prompts),
|
|
20
|
+
and Cursor on Windows prefixes the payload with a UTF-8 BOM - the -sig codec strips it.
|
|
21
|
+
"""
|
|
22
|
+
buffer = getattr(sys.stdin, 'buffer', None)
|
|
23
|
+
if buffer is not None:
|
|
24
|
+
return buffer.read().decode('utf-8-sig', errors='replace')
|
|
25
|
+
# No .buffer (tests mocking sys.stdin with StringIO, exotic streams) - text-mode fallback.
|
|
26
|
+
# lstrip the BOM here too: an already-decoded stream leaves it as U+FEFF, which json.loads
|
|
27
|
+
# rejects (and .strip() doesn't remove - it is not whitespace).
|
|
28
|
+
return sys.stdin.read().lstrip('\ufeff')
|
|
29
|
+
|
|
30
|
+
|
|
14
31
|
def safe_json_parse(s: str) -> dict:
|
|
15
32
|
"""Parse JSON string, returning empty dict on failure."""
|
|
16
33
|
try:
|
|
@@ -7,7 +7,7 @@ import typer
|
|
|
7
7
|
|
|
8
8
|
from cycode.cli.apps.ai_guardrails.ides import DEFAULT_IDE_NAME, get_ide
|
|
9
9
|
from cycode.cli.apps.ai_guardrails.ides.base import IDE
|
|
10
|
-
from cycode.cli.apps.ai_guardrails.scan.utils import safe_json_parse
|
|
10
|
+
from cycode.cli.apps.ai_guardrails.scan.utils import read_stdin_text, safe_json_parse
|
|
11
11
|
from cycode.cli.apps.auth.auth_common import get_authorization_info
|
|
12
12
|
from cycode.cli.apps.auth.auth_manager import AuthManager
|
|
13
13
|
from cycode.cli.exceptions.handle_auth_errors import handle_auth_exception
|
|
@@ -78,7 +78,7 @@ def session_start_command(
|
|
|
78
78
|
logger.debug('No stdin payload (TTY), skipping session initialization')
|
|
79
79
|
return
|
|
80
80
|
|
|
81
|
-
stdin_data =
|
|
81
|
+
stdin_data = read_stdin_text().strip()
|
|
82
82
|
payload = safe_json_parse(stdin_data)
|
|
83
83
|
if not payload:
|
|
84
84
|
logger.debug('Empty or invalid stdin payload, skipping session initialization')
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import platform
|
|
2
3
|
import re
|
|
3
4
|
from typing import Optional
|
|
4
5
|
|
|
@@ -12,19 +13,32 @@ from cycode.cli.utils.shell_executor import shell
|
|
|
12
13
|
BUILD_GRADLE_FILE_NAME = 'build.gradle'
|
|
13
14
|
BUILD_GRADLE_KTS_FILE_NAME = 'build.gradle.kts'
|
|
14
15
|
BUILD_GRADLE_DEP_TREE_FILE_NAME = 'gradle-dependencies-generated.txt'
|
|
15
|
-
BUILD_GRADLE_ALL_PROJECTS_COMMAND = ['gradle', 'projects']
|
|
16
16
|
ALL_PROJECTS_REGEX = r"[+-]{3} Project '(.*?)'"
|
|
17
17
|
|
|
18
|
+
GRADLE_EXECUTABLE = 'gradle'
|
|
19
|
+
GRADLEW_FILE_NAME = 'gradlew'
|
|
20
|
+
GRADLEW_BAT_FILE_NAME = 'gradlew.bat'
|
|
21
|
+
|
|
18
22
|
|
|
19
23
|
class RestoreGradleDependencies(BaseRestoreDependencies):
|
|
20
24
|
def __init__(
|
|
21
25
|
self, ctx: typer.Context, is_git_diff: bool, command_timeout: int, projects: Optional[set[str]] = None
|
|
22
26
|
) -> None:
|
|
23
27
|
super().__init__(ctx, is_git_diff, command_timeout, create_output_file_manually=True)
|
|
28
|
+
self.gradle_executable = self._resolve_gradle_executable()
|
|
24
29
|
if projects is None:
|
|
25
30
|
projects = set()
|
|
26
31
|
self.projects = self.get_all_projects() if self.is_gradle_sub_projects() else projects
|
|
27
32
|
|
|
33
|
+
def _resolve_gradle_executable(self) -> str:
|
|
34
|
+
scan_root = get_path_from_context(self.ctx)
|
|
35
|
+
if scan_root:
|
|
36
|
+
wrapper_name = GRADLEW_BAT_FILE_NAME if platform.system() == 'Windows' else GRADLEW_FILE_NAME
|
|
37
|
+
wrapper_path = os.path.join(scan_root, wrapper_name)
|
|
38
|
+
if os.path.isfile(wrapper_path):
|
|
39
|
+
return wrapper_path
|
|
40
|
+
return GRADLE_EXECUTABLE
|
|
41
|
+
|
|
28
42
|
def is_gradle_sub_projects(self) -> bool:
|
|
29
43
|
return self.ctx.obj.get('gradle_all_sub_projects', False)
|
|
30
44
|
|
|
@@ -35,7 +49,7 @@ class RestoreGradleDependencies(BaseRestoreDependencies):
|
|
|
35
49
|
return (
|
|
36
50
|
self.get_commands_for_sub_projects(manifest_file_path)
|
|
37
51
|
if self.is_gradle_sub_projects()
|
|
38
|
-
else [[
|
|
52
|
+
else [[self.gradle_executable, 'dependencies', '-b', manifest_file_path, '-q', '--console', 'plain']]
|
|
39
53
|
)
|
|
40
54
|
|
|
41
55
|
def get_lock_file_name(self) -> str:
|
|
@@ -49,7 +63,7 @@ class RestoreGradleDependencies(BaseRestoreDependencies):
|
|
|
49
63
|
|
|
50
64
|
def get_all_projects(self) -> set[str]:
|
|
51
65
|
output = shell(
|
|
52
|
-
command=
|
|
66
|
+
command=[self.gradle_executable, 'projects'],
|
|
53
67
|
timeout=self.command_timeout,
|
|
54
68
|
working_directory=get_path_from_context(self.ctx),
|
|
55
69
|
)
|
|
@@ -62,7 +76,7 @@ class RestoreGradleDependencies(BaseRestoreDependencies):
|
|
|
62
76
|
project_name = os.path.basename(os.path.dirname(manifest_file_path))
|
|
63
77
|
project_name = f':{project_name}'
|
|
64
78
|
return (
|
|
65
|
-
[[
|
|
79
|
+
[[self.gradle_executable, f'{project_name}:dependencies', '-q', '--console', 'plain']]
|
|
66
80
|
if project_name in self.projects
|
|
67
81
|
else []
|
|
68
82
|
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
cycode/__init__.py,sha256
|
|
1
|
+
cycode/__init__.py,sha256=k7ISKxt7Zq0midoKI7MS5A1C4yMJFd04wzOnraP_G-8,397
|
|
2
2
|
cycode/__main__.py,sha256=Z3bD5yrA7yPvAChcADQrqCaZd0ChGI1gdiwALwbWJ6U,104
|
|
3
3
|
cycode/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
cycode/cli/app.py,sha256=AlR2durAEbsa47PDfIj7JtMvJDWA_Dq6wPtVuMJYSCs,10250
|
|
@@ -20,10 +20,10 @@ cycode/cli/apps/ai_guardrails/scan/consts.py,sha256=drAslw6vW3kxmbCs2qPCUbUPR7PJ
|
|
|
20
20
|
cycode/cli/apps/ai_guardrails/scan/handlers.py,sha256=pf5PrUIVnGLEEE6QKPny9at5V6Ms5u2IEtFP72hKgqA,15523
|
|
21
21
|
cycode/cli/apps/ai_guardrails/scan/payload.py,sha256=pvT3UUqNMvdK3EVzzPjy4JMlOrF-WgxZ3fHN2AtN5eA,1126
|
|
22
22
|
cycode/cli/apps/ai_guardrails/scan/policy.py,sha256=BZoNNdDQ9tqnfwhB4X1-bDtudaOQc_gXizm3IVwa28o,3351
|
|
23
|
-
cycode/cli/apps/ai_guardrails/scan/scan_command.py,sha256
|
|
23
|
+
cycode/cli/apps/ai_guardrails/scan/scan_command.py,sha256=uiBCDGcshqgvwkdqrlwNbaGZQnjpAvuTZ9T7UI09YJY,6178
|
|
24
24
|
cycode/cli/apps/ai_guardrails/scan/types.py,sha256=lDttkYFBfOkdMEEaRbq1IT2QTK0R-7Ht3T8vZdyB3b4,1038
|
|
25
|
-
cycode/cli/apps/ai_guardrails/scan/utils.py,sha256=
|
|
26
|
-
cycode/cli/apps/ai_guardrails/session_start_command.py,sha256=
|
|
25
|
+
cycode/cli/apps/ai_guardrails/scan/utils.py,sha256=QzR_zmivDYwg2-F8g4bFfsycHhNo-pPuJly0P_l0gm8,2879
|
|
26
|
+
cycode/cli/apps/ai_guardrails/session_start_command.py,sha256=_N7dDi2bv7IykvB7xtCFFZgP0YmvT8-jxeSywBM57Os,3700
|
|
27
27
|
cycode/cli/apps/ai_guardrails/status_command.py,sha256=Uqss68TEPCYPXpLix6Bh-4J3g-khxWsAqlIGYH5x4bQ,3203
|
|
28
28
|
cycode/cli/apps/ai_guardrails/uninstall_command.py,sha256=dOmePfZmlHAPy2zEJM1yMtSuDqvzDwtqgmLKYK-T9PI,2698
|
|
29
29
|
cycode/cli/apps/ai_remediation/__init__.py,sha256=8vYthY9RQeJqEni3AIF5sryz8n-XJQ6VNqG4aEFBAdY,553
|
|
@@ -117,7 +117,7 @@ cycode/cli/files_collector/sca/base_restore_dependencies.py,sha256=hCQyjQW5hPhBw
|
|
|
117
117
|
cycode/cli/files_collector/sca/go/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
118
118
|
cycode/cli/files_collector/sca/go/restore_go_dependencies.py,sha256=LXUjslfdHO3umz36WtQyRpKa_fVaRgEjewVkZ0QvnYU,1899
|
|
119
119
|
cycode/cli/files_collector/sca/maven/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
120
|
-
cycode/cli/files_collector/sca/maven/restore_gradle_dependencies.py,sha256=
|
|
120
|
+
cycode/cli/files_collector/sca/maven/restore_gradle_dependencies.py,sha256=2W5Y8yrSIV7o4rCUtNsqO2YFImvcY5TnabzTbStiaBo,3261
|
|
121
121
|
cycode/cli/files_collector/sca/maven/restore_maven_dependencies.py,sha256=zObNN8n6yUriNVB3ZdvAkoKXXrMvzU9Lpd5lNhVo_so,4003
|
|
122
122
|
cycode/cli/files_collector/sca/npm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
123
123
|
cycode/cli/files_collector/sca/npm/restore_bun_dependencies.py,sha256=HI0X_19wCM6B_vRpX6uD12dXsQbU6LCcLQdobPZDgAs,4580
|
|
@@ -209,8 +209,8 @@ cycode/cyclient/report_client.py,sha256=Scq30NeJPzgXv0hPLO1U05AdE9i_2iu6cIrSKpEJ
|
|
|
209
209
|
cycode/cyclient/scan_client.py,sha256=6TK5FQkfrvV7PHqRnUzEn1PBNd2oPYVamvIixcUfe3c,16755
|
|
210
210
|
cycode/cyclient/scan_config_base.py,sha256=mXsPZGYCtp85rv5GIige40yQZXuRcEKUW-VQJ0vgFzk,1201
|
|
211
211
|
cycode/logger.py,sha256=EfZGRK6VC5rE_LAjIcRrHFiQCueylCDXoG6bvGkrIME,2111
|
|
212
|
-
cycode-3.17.1.
|
|
213
|
-
cycode-3.17.1.
|
|
214
|
-
cycode-3.17.1.
|
|
215
|
-
cycode-3.17.1.
|
|
216
|
-
cycode-3.17.1.
|
|
212
|
+
cycode-3.17.1.dev11.dist-info/METADATA,sha256=93Wnk0yD_pEVXMMurI30p2g0IByo6L9jAD0eU006Tnk,89247
|
|
213
|
+
cycode-3.17.1.dev11.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
214
|
+
cycode-3.17.1.dev11.dist-info/entry_points.txt,sha256=iDcVJM8ByLElVgvBgtYxDjw1kT7O8Mo0LcWZIT5L3Ig,45
|
|
215
|
+
cycode-3.17.1.dev11.dist-info/licenses/LICENCE,sha256=2Wx4N6mD_4xB7-E3hPkZ3MPhpJy__k_I8MaCSO-PDRo,1068
|
|
216
|
+
cycode-3.17.1.dev11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|