recce-nightly 1.10.0.20250625__py3-none-any.whl → 1.30.0.20251221__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.

Potentially problematic release.


This version of recce-nightly might be problematic. Click here for more details.

Files changed (229) hide show
  1. recce/VERSION +1 -1
  2. recce/__init__.py +5 -0
  3. recce/adapter/dbt_adapter/__init__.py +343 -245
  4. recce/apis/check_api.py +20 -14
  5. recce/apis/check_events_api.py +353 -0
  6. recce/apis/check_func.py +5 -5
  7. recce/apis/run_func.py +32 -3
  8. recce/artifact.py +76 -3
  9. recce/cli.py +705 -82
  10. recce/config.py +2 -2
  11. recce/connect_to_cloud.py +1 -1
  12. recce/core.py +3 -3
  13. recce/data/404/index.html +2 -0
  14. recce/data/404.html +2 -22
  15. recce/data/__next.@lineage.!KHNsb3Qp.__PAGE__.txt +7 -0
  16. recce/data/__next.@lineage.!KHNsb3Qp.txt +4 -0
  17. recce/data/__next.__PAGE__.txt +6 -0
  18. recce/data/__next._full.txt +32 -0
  19. recce/data/__next._head.txt +8 -0
  20. recce/data/__next._index.txt +14 -0
  21. recce/data/__next._tree.txt +8 -0
  22. recce/data/_next/static/chunks/025a7e3e3f9f40ae.js +1 -0
  23. recce/data/_next/static/chunks/0ce56d67ef5779ca.js +4 -0
  24. recce/data/_next/static/chunks/1a6a78780155dac7.js +48 -0
  25. recce/data/_next/static/chunks/1de8485918b9182a.css +2 -0
  26. recce/data/_next/static/chunks/1e4b1b50d1e34993.js +1 -0
  27. recce/data/_next/static/chunks/206d5d181e4c738e.js +1 -0
  28. recce/data/_next/static/chunks/2c357efc34c5b859.js +25 -0
  29. recce/data/_next/static/chunks/2e9d95d2d48c479c.js +1 -0
  30. recce/data/_next/static/chunks/2f016dc4a3edad2e.js +2 -0
  31. recce/data/_next/static/chunks/313251962d698f7c.js +1 -0
  32. recce/data/_next/static/chunks/3a9f021f38eb5574.css +1 -0
  33. recce/data/_next/static/chunks/40079da8d2b8f651.js +1 -0
  34. recce/data/_next/static/chunks/4599182bffb64661.js +38 -0
  35. recce/data/_next/static/chunks/4e62f6e184173580.js +1 -0
  36. recce/data/_next/static/chunks/5c4dfb0d09eaa401.js +1 -0
  37. recce/data/_next/static/chunks/69e4f06ccfdfc3ac.js +1 -0
  38. recce/data/_next/static/chunks/6b206cb4707d6bee.js +1 -0
  39. recce/data/_next/static/chunks/6d8557f062aa4386.css +1 -0
  40. recce/data/_next/static/chunks/7fbe3650bd83b6b5.js +1 -0
  41. recce/data/_next/static/chunks/83fa823a825674f6.js +1 -0
  42. recce/data/_next/static/chunks/848a6c9b5f55f7ed.js +1 -0
  43. recce/data/_next/static/chunks/859462b0858aef88.css +2 -0
  44. recce/data/_next/static/chunks/923964f18c87d0f1.css +1 -0
  45. recce/data/_next/static/chunks/939390f911895d7c.js +48 -0
  46. recce/data/_next/static/chunks/99a9817237a07f43.js +1 -0
  47. recce/data/_next/static/chunks/9fed8b4b2b924054.js +5 -0
  48. recce/data/_next/static/chunks/b6949f6c5892110c.js +1 -0
  49. recce/data/_next/static/chunks/b851a1d3f8149828.js +1 -0
  50. recce/data/_next/static/chunks/c734f9ad957de0b4.js +1 -0
  51. recce/data/_next/static/chunks/cdde321b0ec75717.js +2 -0
  52. recce/data/_next/static/chunks/d0f91117d77ff844.css +1 -0
  53. recce/data/_next/static/chunks/d6c8667911c2500f.js +1 -0
  54. recce/data/_next/static/chunks/da8dab68c02752cf.js +74 -0
  55. recce/data/_next/static/chunks/dc074049c9d12d97.js +109 -0
  56. recce/data/_next/static/chunks/ee7f1a8227342421.js +1 -0
  57. recce/data/_next/static/chunks/fa2f4e56c2fccc73.js +1 -0
  58. recce/data/_next/static/chunks/turbopack-1fad664f62979b93.js +3 -0
  59. recce/data/_next/static/media/favicon.a8d38d84.ico +0 -0
  60. recce/data/_next/static/media/montserrat-cyrillic-800-normal.d80d830d.woff2 +0 -0
  61. recce/data/_next/static/media/{montserrat-cyrillic-800-normal.bd5c9f50.woff → montserrat-cyrillic-800-normal.f9d58125.woff} +0 -0
  62. recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.076c2a93.woff2 +0 -0
  63. recce/data/_next/static/media/montserrat-latin-800-normal.cde454cc.woff2 +0 -0
  64. recce/data/_next/static/media/{montserrat-latin-800-normal.fc315020.woff → montserrat-latin-800-normal.d5761935.woff} +0 -0
  65. recce/data/_next/static/media/montserrat-latin-ext-800-normal.40ec0659.woff2 +0 -0
  66. recce/data/_next/static/media/{montserrat-latin-ext-800-normal.2e5381b2.woff → montserrat-latin-ext-800-normal.b671449b.woff} +0 -0
  67. recce/data/_next/static/media/{montserrat-vietnamese-800-normal.20c545e6.woff → montserrat-vietnamese-800-normal.9f7b8541.woff} +0 -0
  68. recce/data/_next/static/media/montserrat-vietnamese-800-normal.f9eb854e.woff2 +0 -0
  69. recce/data/_next/static/nX-Uz0AH6Tc6hIQUFGqaB/_buildManifest.js +11 -0
  70. recce/data/_next/static/nX-Uz0AH6Tc6hIQUFGqaB/_clientMiddlewareManifest.json +1 -0
  71. recce/data/_not-found/__next._full.txt +24 -0
  72. recce/data/_not-found/__next._head.txt +8 -0
  73. recce/data/_not-found/__next._index.txt +13 -0
  74. recce/data/_not-found/__next._not-found.__PAGE__.txt +5 -0
  75. recce/data/_not-found/__next._not-found.txt +4 -0
  76. recce/data/_not-found/__next._tree.txt +6 -0
  77. recce/data/_not-found/index.html +2 -0
  78. recce/data/_not-found/index.txt +24 -0
  79. recce/data/auth_callback.html +1 -1
  80. recce/data/checks/__next.@lineage.__DEFAULT__.txt +7 -0
  81. recce/data/checks/__next._full.txt +39 -0
  82. recce/data/checks/__next._head.txt +8 -0
  83. recce/data/checks/__next._index.txt +14 -0
  84. recce/data/checks/__next._tree.txt +8 -0
  85. recce/data/checks/__next.checks.__PAGE__.txt +10 -0
  86. recce/data/checks/__next.checks.txt +4 -0
  87. recce/data/checks/index.html +2 -0
  88. recce/data/checks/index.txt +39 -0
  89. recce/data/index.html +2 -27
  90. recce/data/index.txt +32 -8
  91. recce/data/lineage/__next.@lineage.__DEFAULT__.txt +7 -0
  92. recce/data/lineage/__next._full.txt +39 -0
  93. recce/data/lineage/__next._head.txt +8 -0
  94. recce/data/lineage/__next._index.txt +14 -0
  95. recce/data/lineage/__next._tree.txt +8 -0
  96. recce/data/lineage/__next.lineage.__PAGE__.txt +10 -0
  97. recce/data/lineage/__next.lineage.txt +4 -0
  98. recce/data/lineage/index.html +2 -0
  99. recce/data/lineage/index.txt +39 -0
  100. recce/data/query/__next.@lineage.__DEFAULT__.txt +7 -0
  101. recce/data/query/__next._full.txt +37 -0
  102. recce/data/query/__next._head.txt +8 -0
  103. recce/data/query/__next._index.txt +14 -0
  104. recce/data/query/__next._tree.txt +8 -0
  105. recce/data/query/__next.query.__PAGE__.txt +9 -0
  106. recce/data/query/__next.query.txt +4 -0
  107. recce/data/query/index.html +2 -0
  108. recce/data/query/index.txt +37 -0
  109. recce/event/CONFIG.bak +1 -0
  110. recce/event/__init__.py +9 -8
  111. recce/event/collector.py +6 -2
  112. recce/event/track.py +10 -0
  113. recce/github.py +1 -1
  114. recce/mcp_server.py +725 -0
  115. recce/models/check.py +433 -15
  116. recce/models/types.py +61 -2
  117. recce/pull_request.py +1 -1
  118. recce/run.py +37 -17
  119. recce/server.py +216 -21
  120. recce/state/__init__.py +31 -0
  121. recce/state/cloud.py +644 -0
  122. recce/state/const.py +26 -0
  123. recce/state/local.py +56 -0
  124. recce/state/state.py +119 -0
  125. recce/state/state_loader.py +174 -0
  126. recce/summary.py +25 -3
  127. recce/tasks/dataframe.py +63 -1
  128. recce/tasks/query.py +40 -3
  129. recce/tasks/rowcount.py +4 -1
  130. recce/tasks/schema.py +4 -1
  131. recce/tasks/utils.py +147 -0
  132. recce/tasks/valuediff.py +85 -57
  133. recce/util/api_token.py +11 -2
  134. recce/util/breaking.py +10 -1
  135. recce/util/cll.py +1 -2
  136. recce/util/cloud/__init__.py +15 -0
  137. recce/util/cloud/base.py +115 -0
  138. recce/util/cloud/check_events.py +190 -0
  139. recce/util/cloud/checks.py +242 -0
  140. recce/util/io.py +2 -2
  141. recce/util/lineage.py +19 -18
  142. recce/util/perf_tracking.py +85 -0
  143. recce/util/recce_cloud.py +254 -5
  144. recce/util/startup_perf.py +121 -0
  145. recce/yaml/__init__.py +2 -2
  146. {recce_nightly-1.10.0.20250625.dist-info → recce_nightly-1.30.0.20251221.dist-info}/METADATA +91 -71
  147. recce_nightly-1.30.0.20251221.dist-info/RECORD +183 -0
  148. {recce_nightly-1.10.0.20250625.dist-info → recce_nightly-1.30.0.20251221.dist-info}/WHEEL +1 -2
  149. recce/data/_next/static/abCX3x3UoIdRLEDWxx4xd/_buildManifest.js +0 -1
  150. recce/data/_next/static/chunks/181-acc61ddada3bc0ca.js +0 -43
  151. recce/data/_next/static/chunks/1bff33f1-1ef85cf5e658a751.js +0 -1
  152. recce/data/_next/static/chunks/217-879a84d70f7a907c.js +0 -2
  153. recce/data/_next/static/chunks/29e3cc0d-60045b2e47aa3916.js +0 -1
  154. recce/data/_next/static/chunks/36e1c10d-8e7be4a6c1f6ab2d.js +0 -1
  155. recce/data/_next/static/chunks/3998a672-03adacad07b346ac.js +0 -1
  156. recce/data/_next/static/chunks/3a92ee20-1081c360214f9602.js +0 -1
  157. recce/data/_next/static/chunks/42-cd3c06533f5fd47c.js +0 -9
  158. recce/data/_next/static/chunks/450c323b-fd94e7ffaa4a5efa.js +0 -1
  159. recce/data/_next/static/chunks/47d8844f-929aed9b1c73a905.js +0 -1
  160. recce/data/_next/static/chunks/608-3b079b544e5d5f5e.js +0 -15
  161. recce/data/_next/static/chunks/6dc81886-adbfa45836061d79.js +0 -1
  162. recce/data/_next/static/chunks/7a8a3e83-edf6dc64b5d5f0a5.js +0 -1
  163. recce/data/_next/static/chunks/7f27ae6c-d5f0438edd5c2a5b.js +0 -1
  164. recce/data/_next/static/chunks/86730205-cfb14e3f051bab35.js +0 -1
  165. recce/data/_next/static/chunks/8d700b6a.8bb140898499c512.js +0 -1
  166. recce/data/_next/static/chunks/92-607cd1af83c41f43.js +0 -1
  167. recce/data/_next/static/chunks/9746af58-a42b7d169cacadf0.js +0 -1
  168. recce/data/_next/static/chunks/a30376cd-de84559016d7e133.js +0 -1
  169. recce/data/_next/static/chunks/app/_not-found/page-01ed58b7f971d311.js +0 -1
  170. recce/data/_next/static/chunks/app/layout-177a410a97e0d018.js +0 -1
  171. recce/data/_next/static/chunks/app/page-da6e046a8235dbfc.js +0 -1
  172. recce/data/_next/static/chunks/b63b1b3f-4282bdcf459e075c.js +0 -1
  173. recce/data/_next/static/chunks/bbda5537-9ec25eb1dd62348a.js +0 -1
  174. recce/data/_next/static/chunks/c132bf7d-08cb668a789d6afd.js +0 -1
  175. recce/data/_next/static/chunks/ce84277d-2e5d1d46910cf052.js +0 -1
  176. recce/data/_next/static/chunks/febdd86e-c6b525341634b860.js +0 -54
  177. recce/data/_next/static/chunks/fee69bc6-2dbccaf9b90474e6.js +0 -1
  178. recce/data/_next/static/chunks/framework-ded83d71b51ce901.js +0 -1
  179. recce/data/_next/static/chunks/main-app-39061b0166c47f55.js +0 -1
  180. recce/data/_next/static/chunks/main-b5b3ae20a1405261.js +0 -1
  181. recce/data/_next/static/chunks/pages/_app-437c455677d62394.js +0 -1
  182. recce/data/_next/static/chunks/pages/_error-e7650df18ca04bde.js +0 -1
  183. recce/data/_next/static/chunks/webpack-7b49d5ba7e3a434d.js +0 -1
  184. recce/data/_next/static/css/17a96168e3a9db13.css +0 -1
  185. recce/data/_next/static/css/1b121dc4d36aeb4d.css +0 -3
  186. recce/data/_next/static/css/35c6679a098e1e34.css +0 -1
  187. recce/data/_next/static/css/951e2e0eea2d4a5b.css +0 -14
  188. recce/data/_next/static/media/montserrat-cyrillic-800-normal.22628180.woff2 +0 -0
  189. recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.94a63aea.woff2 +0 -0
  190. recce/data/_next/static/media/montserrat-latin-800-normal.6f8fa298.woff2 +0 -0
  191. recce/data/_next/static/media/montserrat-latin-ext-800-normal.013b84f9.woff2 +0 -0
  192. recce/data/_next/static/media/montserrat-vietnamese-800-normal.c0035377.woff2 +0 -0
  193. recce/data/_next/static/media/reload-image.79aabb7d.svg +0 -4
  194. recce/state.py +0 -786
  195. recce_nightly-1.10.0.20250625.dist-info/RECORD +0 -154
  196. recce_nightly-1.10.0.20250625.dist-info/top_level.txt +0 -2
  197. tests/__init__.py +0 -0
  198. tests/adapter/__init__.py +0 -0
  199. tests/adapter/dbt_adapter/__init__.py +0 -0
  200. tests/adapter/dbt_adapter/conftest.py +0 -17
  201. tests/adapter/dbt_adapter/dbt_test_helper.py +0 -298
  202. tests/adapter/dbt_adapter/test_dbt_adapter.py +0 -25
  203. tests/adapter/dbt_adapter/test_dbt_cll.py +0 -384
  204. tests/adapter/dbt_adapter/test_selector.py +0 -202
  205. tests/tasks/__init__.py +0 -0
  206. tests/tasks/conftest.py +0 -4
  207. tests/tasks/test_histogram.py +0 -129
  208. tests/tasks/test_lineage.py +0 -55
  209. tests/tasks/test_preset_checks.py +0 -64
  210. tests/tasks/test_profile.py +0 -397
  211. tests/tasks/test_query.py +0 -151
  212. tests/tasks/test_row_count.py +0 -135
  213. tests/tasks/test_schema.py +0 -122
  214. tests/tasks/test_top_k.py +0 -77
  215. tests/tasks/test_valuediff.py +0 -85
  216. tests/test_cli.py +0 -133
  217. tests/test_config.py +0 -43
  218. tests/test_connect_to_cloud.py +0 -82
  219. tests/test_core.py +0 -29
  220. tests/test_dbt.py +0 -36
  221. tests/test_pull_request.py +0 -130
  222. tests/test_server.py +0 -104
  223. tests/test_state.py +0 -134
  224. tests/test_summary.py +0 -65
  225. /recce/data/_next/static/chunks/{polyfills-42372ed130431b0a.js → a6dad97d9634a72d.js} +0 -0
  226. /recce/data/_next/static/media/{montserrat-cyrillic-ext-800-normal.e6e0d8d0.woff → montserrat-cyrillic-ext-800-normal.a4fa76b5.woff} +0 -0
  227. /recce/data/_next/static/{abCX3x3UoIdRLEDWxx4xd → nX-Uz0AH6Tc6hIQUFGqaB}/_ssgManifest.js +0 -0
  228. {recce_nightly-1.10.0.20250625.dist-info → recce_nightly-1.30.0.20251221.dist-info}/entry_points.txt +0 -0
  229. {recce_nightly-1.10.0.20250625.dist-info → recce_nightly-1.30.0.20251221.dist-info}/licenses/LICENSE +0 -0
recce/util/recce_cloud.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  import logging
3
3
  import os
4
+ import typing
4
5
  from typing import IO, Dict
5
6
 
6
7
  import requests
@@ -9,9 +10,15 @@ from recce import get_version
9
10
  from recce.event import get_user_id, is_anonymous_tracking
10
11
  from recce.pull_request import PullRequestInfo
11
12
 
13
+ if typing.TYPE_CHECKING:
14
+ from recce.util.cloud import ChecksCloud
15
+
12
16
  RECCE_CLOUD_API_HOST = os.environ.get("RECCE_CLOUD_API_HOST", "https://cloud.datarecce.io")
13
17
  RECCE_CLOUD_BASE_URL = os.environ.get("RECCE_CLOUD_BASE_URL", RECCE_CLOUD_API_HOST)
14
18
 
19
+ DOCKER_INTERNAL_URL_PREFIX = "http://host.docker.internal"
20
+ LOCALHOST_URL_PREFIX = "http://localhost"
21
+
15
22
  logger = logging.getLogger("uvicorn")
16
23
 
17
24
 
@@ -39,6 +46,28 @@ class RecceCloud:
39
46
  self.token = token
40
47
  self.token_type = "github_token" if token.startswith(("ghp_", "gho_", "ghu_", "ghs_", "ghr_")) else "api_token"
41
48
  self.base_url = f"{RECCE_CLOUD_API_HOST}/api/v1"
49
+ self.base_url_v2 = f"{RECCE_CLOUD_API_HOST}/api/v2"
50
+
51
+ # Initialize modular clients
52
+ self._checks_client = None
53
+
54
+ @property
55
+ def checks(self) -> "ChecksCloud":
56
+ """
57
+ Get the checks client for check operations.
58
+
59
+ Returns:
60
+ ChecksCloud instance for check operations
61
+
62
+ Example:
63
+ >>> cloud = RecceCloud(token="your-token")
64
+ >>> checks = cloud.checks.list_checks("org", "proj", "sess")
65
+ """
66
+ if self._checks_client is None:
67
+ from recce.util.cloud import ChecksCloud
68
+
69
+ self._checks_client = ChecksCloud(self.token)
70
+ return self._checks_client
42
71
 
43
72
  def _request(self, method, url, headers: Dict = None, **kwargs):
44
73
  headers = {
@@ -66,7 +95,7 @@ class RecceCloud:
66
95
  pass
67
96
  return False
68
97
 
69
- def get_presigned_url(
98
+ def get_presigned_url_by_github_repo(
70
99
  self,
71
100
  method: PresignedUrlMethod,
72
101
  repository: str,
@@ -78,7 +107,37 @@ class RecceCloud:
78
107
  response = self._fetch_presigned_url(method, repository, artifact_name, metadata, pr_id, branch)
79
108
  return response.get("presigned_url")
80
109
 
81
- def get_download_presigned_url_with_tags(
110
+ def _replace_localhost_with_docker_internal(self, url: str) -> str:
111
+ if url is None:
112
+ return None
113
+ if (
114
+ os.environ.get("RECCE_SHARE_INSTANCE_ENV") == "docker"
115
+ or os.environ.get("RECCE_TASK_INSTANCE_ENV") == "docker"
116
+ or os.environ.get("RECCE_INSTANCE_ENV") == "docker"
117
+ ):
118
+ # For local development, convert the presigned URL from localhost to host.docker.internal
119
+ if url.startswith(LOCALHOST_URL_PREFIX):
120
+ return url.replace(LOCALHOST_URL_PREFIX, DOCKER_INTERNAL_URL_PREFIX)
121
+ return url
122
+
123
+ def get_presigned_url_by_share_id(
124
+ self,
125
+ method: PresignedUrlMethod,
126
+ share_id: str,
127
+ metadata: dict = None,
128
+ ) -> str:
129
+ response = self._fetch_presigned_url_by_share_id(method, share_id, metadata=metadata)
130
+ presigned_url = response.get("presigned_url")
131
+ if not presigned_url:
132
+ raise RecceCloudException(
133
+ message="Failed to get presigned URL from Recce Cloud.",
134
+ reason="No presigned URL returned from the server.",
135
+ status_code=404,
136
+ )
137
+ presigned_url = self._replace_localhost_with_docker_internal(presigned_url)
138
+ return presigned_url
139
+
140
+ def get_download_presigned_url_by_github_repo_with_tags(
82
141
  self, repository: str, artifact_name: str, branch: str = None
83
142
  ) -> (str, dict):
84
143
  response = self._fetch_presigned_url(PresignedUrlMethod.DOWNLOAD, repository, artifact_name, branch=branch)
@@ -110,6 +169,33 @@ class RecceCloud:
110
169
  )
111
170
  return response.json()
112
171
 
172
+ def _fetch_presigned_url_by_share_id(
173
+ self,
174
+ method: PresignedUrlMethod,
175
+ share_id: str,
176
+ metadata: dict = None,
177
+ ):
178
+ api_url = f"{self.base_url}/shares/{share_id}/presigned/{method}"
179
+ data = None
180
+ # Only provide metadata for upload requests
181
+ if method == PresignedUrlMethod.UPLOAD:
182
+ # Covert metadata values to strings to ensure JSON serializability
183
+ data = {"metadata": {key: str(value) for key, value in metadata.items()}} if metadata else None
184
+ response = self._request(
185
+ "POST",
186
+ api_url,
187
+ json=data,
188
+ )
189
+ if response.status_code != 200:
190
+ raise RecceCloudException(
191
+ message="Failed to {method} artifact {preposition} Recce Cloud.".format(
192
+ method=method, preposition="from" if method == PresignedUrlMethod.DOWNLOAD else "to"
193
+ ),
194
+ reason=response.text,
195
+ status_code=response.status_code,
196
+ )
197
+ return response.json()
198
+
113
199
  def get_artifact_metadata(self, pr_info: PullRequestInfo) -> dict:
114
200
  api_url = f"{self.base_url}/{pr_info.repository}/pulls/{pr_info.id}/metadata"
115
201
  response = self._request("GET", api_url)
@@ -123,12 +209,22 @@ class RecceCloud:
123
209
  )
124
210
  return response.json()
125
211
 
126
- def purge_artifacts(self, pr_info: PullRequestInfo):
127
- api_url = f"{self.base_url}/{pr_info.repository}/pulls/{pr_info.id}/artifacts"
212
+ def purge_artifacts(self, repository: str, pr_id: int = None, branch: str = None):
213
+ if pr_id is not None:
214
+ api_url = f"{self.base_url}/{repository}/pulls/{pr_id}/artifacts"
215
+ error_message = "Failed to purge artifacts from Recce Cloud."
216
+ elif branch is not None:
217
+ api_url = f"{self.base_url}/{repository}/commits/{branch}/artifacts"
218
+ error_message = "Failed to delete artifacts from Recce Cloud."
219
+ else:
220
+ raise ValueError(
221
+ "Please either run this command from within a pull request context "
222
+ "or specify a branch using the --branch option."
223
+ )
128
224
  response = self._request("DELETE", api_url)
129
225
  if response.status_code != 204:
130
226
  raise RecceCloudException(
131
- message="Failed to purge artifacts from Recce Cloud.",
227
+ message=error_message,
132
228
  reason=response.text,
133
229
  status_code=response.status_code,
134
230
  )
@@ -188,8 +284,161 @@ class RecceCloud:
188
284
  logger.warning(f"Failed to set Onboarding State in Recce Cloud. Reason: {str(e)}")
189
285
  return
190
286
 
287
+ def get_session(self, session_id: str):
288
+ api_url = f"{self.base_url_v2}/sessions/{session_id}"
289
+ response = self._request("GET", api_url)
290
+ if response.status_code == 403:
291
+ return {"status": "error", "message": response.json().get("detail")}
292
+ if response.status_code != 200:
293
+ raise RecceCloudException(
294
+ message="Failed to get session from Recce Cloud.",
295
+ reason=response.text,
296
+ status_code=response.status_code,
297
+ )
298
+ data = response.json()
299
+ if data["success"] is not True:
300
+ raise RecceCloudException(
301
+ message="Failed to get session from Recce Cloud.",
302
+ reason=data.get("message", "Unknown error"),
303
+ status_code=response.status_code,
304
+ )
305
+ return data["session"]
306
+
307
+ def update_session(self, org_id: str, project_id: str, session_id: str, adapter_type: str):
308
+ api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}"
309
+ data = {"adapter_type": adapter_type}
310
+ response = self._request("PATCH", api_url, json=data)
311
+ if response.status_code == 403:
312
+ return {"status": "error", "message": response.json().get("detail")}
313
+ if response.status_code != 200:
314
+ raise RecceCloudException(
315
+ message="Failed to update session in Recce Cloud.",
316
+ reason=response.text,
317
+ status_code=response.status_code,
318
+ )
319
+ return response.json()
320
+
321
+ def get_download_urls_by_session_id(self, org_id: str, project_id: str, session_id: str) -> dict[str, str]:
322
+ api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}/download-url"
323
+ response = self._request("GET", api_url)
324
+ if response.status_code != 200:
325
+ raise RecceCloudException(
326
+ message="Failed to download session from Recce Cloud.",
327
+ reason=response.text,
328
+ status_code=response.status_code,
329
+ )
330
+ data = response.json()
331
+ if data["presigned_urls"] is None:
332
+ raise RecceCloudException(
333
+ message="No presigned URLs returned from the server.",
334
+ reason="",
335
+ status_code=404,
336
+ )
337
+
338
+ presigned_urls = data["presigned_urls"]
339
+ for key, url in presigned_urls.items():
340
+ presigned_urls[key] = self._replace_localhost_with_docker_internal(url)
341
+ return presigned_urls
342
+
343
+ def get_base_session_download_urls(self, org_id: str, project_id: str) -> dict[str, str]:
344
+ """Get download URLs for the base session of a project."""
345
+ api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/base-session/download-url"
346
+ response = self._request("GET", api_url)
347
+ if response.status_code != 200:
348
+ raise RecceCloudException(
349
+ message="Failed to download base session from Recce Cloud.",
350
+ reason=response.text,
351
+ status_code=response.status_code,
352
+ )
353
+ data = response.json()
354
+ if data["presigned_urls"] is None:
355
+ raise RecceCloudException(
356
+ message="No presigned URLs returned from the server.",
357
+ reason="",
358
+ status_code=404,
359
+ )
360
+
361
+ presigned_urls = data["presigned_urls"]
362
+ for key, url in presigned_urls.items():
363
+ presigned_urls[key] = self._replace_localhost_with_docker_internal(url)
364
+ return presigned_urls
365
+
366
+ def get_upload_urls_by_session_id(self, org_id: str, project_id: str, session_id: str) -> dict[str, str]:
367
+ api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}/upload-url"
368
+ response = self._request("GET", api_url)
369
+ if response.status_code != 200:
370
+ raise RecceCloudException(
371
+ message="Failed to get upload URLs for session from Recce Cloud.",
372
+ reason=response.text,
373
+ status_code=response.status_code,
374
+ )
375
+ data = response.json()
376
+ if data["presigned_urls"] is None:
377
+ raise RecceCloudException(
378
+ message="No presigned URLs returned from the server.",
379
+ reason="",
380
+ status_code=404,
381
+ )
382
+
383
+ presigned_urls = data["presigned_urls"]
384
+ for key, url in presigned_urls.items():
385
+ presigned_urls[key] = self._replace_localhost_with_docker_internal(url)
386
+ return presigned_urls
387
+
388
+ def post_recce_state_uploaded_by_session_id(self, org_id: str, project_id: str, session_id: str):
389
+ api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}/recce-state-uploaded"
390
+ response = self._request("POST", api_url)
391
+ if response.status_code != 204:
392
+ raise RecceCloudException(
393
+ message="Failed to notify state uploaded for session in Recce Cloud.",
394
+ reason=response.text,
395
+ status_code=response.status_code,
396
+ )
397
+
398
+ def list_organizations(self) -> list:
399
+ """List all organizations the user has access to."""
400
+ api_url = f"{self.base_url_v2}/organizations"
401
+ response = self._request("GET", api_url)
402
+ if response.status_code != 200:
403
+ raise RecceCloudException(
404
+ message="Failed to list organizations from Recce Cloud.",
405
+ reason=response.text,
406
+ status_code=response.status_code,
407
+ )
408
+ data = response.json()
409
+ return data.get("organizations", [])
410
+
411
+ def list_projects(self, org_id: str) -> list:
412
+ """List all projects in an organization."""
413
+ api_url = f"{self.base_url_v2}/organizations/{org_id}/projects"
414
+ response = self._request("GET", api_url)
415
+ if response.status_code != 200:
416
+ raise RecceCloudException(
417
+ message="Failed to list projects from Recce Cloud.",
418
+ reason=response.text,
419
+ status_code=response.status_code,
420
+ )
421
+ data = response.json()
422
+ return data.get("projects", [])
423
+
424
+ def list_sessions(self, org_id: str, project_id: str) -> list:
425
+ """List all sessions in a project."""
426
+ api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions"
427
+ response = self._request("GET", api_url)
428
+ if response.status_code != 200:
429
+ raise RecceCloudException(
430
+ message="Failed to list sessions from Recce Cloud.",
431
+ reason=response.text,
432
+ status_code=response.status_code,
433
+ )
434
+ data = response.json()
435
+ return data.get("sessions", [])
436
+
191
437
 
192
438
  def get_recce_cloud_onboarding_state(token: str) -> str:
439
+ if token and token.startswith("rct-"):
440
+ return "undefined"
441
+
193
442
  try:
194
443
  recce_cloud = RecceCloud(token)
195
444
  user_info = recce_cloud.get_user_info()
@@ -0,0 +1,121 @@
1
+ import functools
2
+ import os
3
+ import time
4
+ from dataclasses import dataclass, field
5
+ from typing import Dict, Optional
6
+
7
+
8
+ @dataclass
9
+ class StartupPerfTracker:
10
+ """
11
+ Tracks startup performance metrics for Recce server.
12
+ All timing values are in milliseconds.
13
+ """
14
+
15
+ # All timings in ms (populated by @track_timing decorator)
16
+ timings: Dict[str, float] = field(default_factory=dict)
17
+
18
+ # Artifact sizes in bytes
19
+ artifact_sizes: Dict[str, int] = field(default_factory=dict)
20
+
21
+ # Metadata
22
+ cloud_mode: bool = False
23
+ catalog_type: Optional[str] = None # github, preview, session
24
+ adapter_type: Optional[str] = None
25
+ node_count: Optional[int] = None
26
+ command: Optional[str] = None # server, read-only, preview
27
+
28
+ def record_timing(self, name: str, elapsed_ms: float):
29
+ """Record timing for a named phase or artifact"""
30
+ self.timings[name] = elapsed_ms
31
+
32
+ def set_cloud_mode(self, cloud_mode: bool):
33
+ self.cloud_mode = cloud_mode
34
+
35
+ def set_catalog_type(self, catalog_type: str):
36
+ self.catalog_type = catalog_type
37
+
38
+ def set_artifact_size(self, name: str, size_bytes: int):
39
+ """Set artifact size by name"""
40
+ self.artifact_sizes[name] = size_bytes
41
+
42
+ def to_dict(self) -> Dict:
43
+ return {
44
+ "timings": self.timings if self.timings else None,
45
+ "artifact_sizes": self.artifact_sizes if self.artifact_sizes else None,
46
+ "cloud_mode": self.cloud_mode,
47
+ "catalog_type": self.catalog_type,
48
+ "adapter_type": self.adapter_type,
49
+ "node_count": self.node_count,
50
+ "command": self.command,
51
+ }
52
+
53
+
54
+ # Module-level singleton for tracking startup across the call stack
55
+ _startup_tracker: Optional[StartupPerfTracker] = None
56
+
57
+
58
+ def get_startup_tracker() -> Optional[StartupPerfTracker]:
59
+ """Get the global startup tracker instance"""
60
+ return _startup_tracker
61
+
62
+
63
+ def set_startup_tracker(tracker: StartupPerfTracker):
64
+ """Set the global startup tracker instance"""
65
+ global _startup_tracker
66
+ _startup_tracker = tracker
67
+
68
+
69
+ def clear_startup_tracker():
70
+ """Clear the global startup tracker instance"""
71
+ global _startup_tracker
72
+ _startup_tracker = None
73
+
74
+
75
+ def track_timing(timing_name: str = None, *, record_size: bool = False):
76
+ """
77
+ Decorator factory to track timing for any operation.
78
+
79
+ Args:
80
+ timing_name: Name for the timing. If None, expects 'timing_name' kwarg at call time.
81
+ record_size: If True, record file size from 'path' kwarg.
82
+
83
+ Usage:
84
+ # Name at decoration time
85
+ @track_timing("state_loader_init")
86
+ def create_state_loader_by_args(...):
87
+ ...
88
+
89
+ # Name at call time (for reusable functions)
90
+ @track_timing(record_size=True)
91
+ def load_manifest(path=None, data=None):
92
+ ...
93
+
94
+ load_manifest(path=p, timing_name="curr_manifest")
95
+ """
96
+
97
+ def decorator(func):
98
+ @functools.wraps(func)
99
+ def wrapper(*args, **kwargs):
100
+ # Get timing name from decorator arg or from kwargs
101
+ name = timing_name
102
+ if name is None:
103
+ name = kwargs.pop("timing_name", None)
104
+
105
+ path = kwargs.get("path") or (args[0] if args else None)
106
+
107
+ start = time.perf_counter_ns()
108
+ result = func(*args, **kwargs)
109
+ elapsed_ms = (time.perf_counter_ns() - start) / 1_000_000
110
+
111
+ if tracker := get_startup_tracker():
112
+ if name:
113
+ tracker.record_timing(name, elapsed_ms)
114
+ if record_size and name and path and os.path.exists(path):
115
+ tracker.set_artifact_size(name, os.path.getsize(path))
116
+
117
+ return result
118
+
119
+ return wrapper
120
+
121
+ return decorator
recce/yaml/__init__.py CHANGED
@@ -34,7 +34,7 @@ def dump(data, stream: Any = None, *, transform: Any = None) -> Any:
34
34
 
35
35
  def safe_load_yaml(file_path):
36
36
  try:
37
- with open(file_path, "r") as f:
37
+ with open(file_path, "r", encoding="utf-8") as f:
38
38
  payload = safe_load(f)
39
39
  except yaml.YAMLError as e:
40
40
  print(e)
@@ -45,7 +45,7 @@ def safe_load_yaml(file_path):
45
45
 
46
46
 
47
47
  def round_trip_load_yaml(file_path):
48
- with open(file_path, "r") as f:
48
+ with open(file_path, "r", encoding="utf-8") as f:
49
49
  try:
50
50
  payload = load(f)
51
51
  except yaml.YAMLError as e: