@datarecce/ui 0.1.30 → 0.1.31

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.
Files changed (549) hide show
  1. package/dist/api.d.mts +1 -1
  2. package/dist/api.d.ts +1 -1
  3. package/dist/components.d.mts +1 -1
  4. package/dist/components.d.ts +1 -1
  5. package/dist/hooks.d.mts +1 -1
  6. package/dist/hooks.d.ts +1 -1
  7. package/dist/{index-BNUP2V_N.d.ts → index-B9lSPJTi.d.ts} +184 -2
  8. package/dist/index-B9lSPJTi.d.ts.map +1 -0
  9. package/dist/{index-DOPZuhD8.d.mts → index-IIXVIoOL.d.mts} +253 -71
  10. package/dist/index-IIXVIoOL.d.mts.map +1 -0
  11. package/dist/index.d.mts +2 -2
  12. package/dist/index.d.ts +2 -2
  13. package/dist/index.js +8 -1
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +3 -2
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/styles.css +4 -0
  18. package/dist/theme.d.mts +2 -185
  19. package/dist/theme.d.ts +2 -185
  20. package/dist/types.d.mts +1 -1
  21. package/dist/types.d.ts +1 -1
  22. package/package.json +4 -2
  23. package/recce-source/.editorconfig +26 -0
  24. package/recce-source/.flake8 +37 -0
  25. package/recce-source/.github/ISSUE_TEMPLATE/bug_report.yml +67 -0
  26. package/recce-source/.github/ISSUE_TEMPLATE/custom.md +10 -0
  27. package/recce-source/.github/ISSUE_TEMPLATE/feature_request.yml +42 -0
  28. package/recce-source/.github/PULL_REQUEST_TEMPLATE.md +21 -0
  29. package/recce-source/.github/copilot-instructions.md +331 -0
  30. package/recce-source/.github/instructions/backend-instructions.md +541 -0
  31. package/recce-source/.github/instructions/frontend-instructions.md +317 -0
  32. package/recce-source/.github/workflows/build-statics.yaml +72 -0
  33. package/recce-source/.github/workflows/bump.yaml +48 -0
  34. package/recce-source/.github/workflows/integration-tests-cloud.yaml +92 -0
  35. package/recce-source/.github/workflows/integration-tests-sqlmesh.yaml +33 -0
  36. package/recce-source/.github/workflows/integration-tests.yaml +52 -0
  37. package/recce-source/.github/workflows/nightly.yaml +246 -0
  38. package/recce-source/.github/workflows/release.yaml +196 -0
  39. package/recce-source/.github/workflows/tests-js.yaml +58 -0
  40. package/recce-source/.github/workflows/tests-python.yaml +128 -0
  41. package/recce-source/.pre-commit-config.yaml +26 -0
  42. package/recce-source/CLAUDE.md +483 -0
  43. package/recce-source/CODE_OF_CONDUCT.md +128 -0
  44. package/recce-source/CONTRIBUTING.md +107 -0
  45. package/recce-source/LICENSE +201 -0
  46. package/recce-source/Makefile +126 -0
  47. package/recce-source/README.md +182 -0
  48. package/recce-source/RECCE_CLOUD.md +81 -0
  49. package/recce-source/SECURITY.md +25 -0
  50. package/recce-source/docs/PACKAGING.md +340 -0
  51. package/recce-source/docs/README.md +1 -0
  52. package/recce-source/integration_tests/dbt/dbt_project.yml +26 -0
  53. package/recce-source/integration_tests/dbt/models/customers.sql +69 -0
  54. package/recce-source/integration_tests/dbt/models/docs.md +14 -0
  55. package/recce-source/integration_tests/dbt/models/orders.sql +56 -0
  56. package/recce-source/integration_tests/dbt/models/schema.yml +82 -0
  57. package/recce-source/integration_tests/dbt/models/staging/schema.yml +31 -0
  58. package/recce-source/integration_tests/dbt/models/staging/stg_customers.sql +22 -0
  59. package/recce-source/integration_tests/dbt/models/staging/stg_orders.sql +23 -0
  60. package/recce-source/integration_tests/dbt/models/staging/stg_payments.sql +25 -0
  61. package/recce-source/integration_tests/dbt/packages.yml +7 -0
  62. package/recce-source/integration_tests/dbt/profiles.yml +8 -0
  63. package/recce-source/integration_tests/dbt/seeds/raw_customers.csv +101 -0
  64. package/recce-source/integration_tests/dbt/seeds/raw_orders.csv +100 -0
  65. package/recce-source/integration_tests/dbt/seeds/raw_payments.csv +114 -0
  66. package/recce-source/integration_tests/dbt/seeds/raw_statuses.csv +5 -0
  67. package/recce-source/integration_tests/dbt/smoke_test.sh +72 -0
  68. package/recce-source/integration_tests/dbt/smoke_test_cloud.sh +71 -0
  69. package/recce-source/integration_tests/sqlmesh/__init__.py +0 -0
  70. package/recce-source/integration_tests/sqlmesh/audits/assert_item_price_above_zero.sql +9 -0
  71. package/recce-source/integration_tests/sqlmesh/audits/items.sql +7 -0
  72. package/recce-source/integration_tests/sqlmesh/audits/order_items.sql +7 -0
  73. package/recce-source/integration_tests/sqlmesh/config.py +171 -0
  74. package/recce-source/integration_tests/sqlmesh/helper.py +20 -0
  75. package/recce-source/integration_tests/sqlmesh/hooks/__init__.py +0 -0
  76. package/recce-source/integration_tests/sqlmesh/macros/__init__.py +0 -0
  77. package/recce-source/integration_tests/sqlmesh/macros/macros.py +8 -0
  78. package/recce-source/integration_tests/sqlmesh/macros/macros.sql +8 -0
  79. package/recce-source/integration_tests/sqlmesh/macros/utils.py +11 -0
  80. package/recce-source/integration_tests/sqlmesh/metrics/metrics.sql +25 -0
  81. package/recce-source/integration_tests/sqlmesh/models/customer_revenue_by_day.sql +41 -0
  82. package/recce-source/integration_tests/sqlmesh/models/customer_revenue_lifetime.sql +60 -0
  83. package/recce-source/integration_tests/sqlmesh/models/customers.sql +32 -0
  84. package/recce-source/integration_tests/sqlmesh/models/items.py +95 -0
  85. package/recce-source/integration_tests/sqlmesh/models/marketing.sql +15 -0
  86. package/recce-source/integration_tests/sqlmesh/models/order_items.py +95 -0
  87. package/recce-source/integration_tests/sqlmesh/models/orders.py +70 -0
  88. package/recce-source/integration_tests/sqlmesh/models/raw_marketing.py +62 -0
  89. package/recce-source/integration_tests/sqlmesh/models/top_waiters.sql +23 -0
  90. package/recce-source/integration_tests/sqlmesh/models/waiter_as_customer_by_day.sql +29 -0
  91. package/recce-source/integration_tests/sqlmesh/models/waiter_names.sql +10 -0
  92. package/recce-source/integration_tests/sqlmesh/models/waiter_revenue_by_day.sql +29 -0
  93. package/recce-source/integration_tests/sqlmesh/models/waiters.py +62 -0
  94. package/recce-source/integration_tests/sqlmesh/prep_env.sh +16 -0
  95. package/recce-source/integration_tests/sqlmesh/schema.yaml +5 -0
  96. package/recce-source/integration_tests/sqlmesh/seeds/waiter_names.csv +11 -0
  97. package/recce-source/integration_tests/sqlmesh/test_server.sh +29 -0
  98. package/recce-source/integration_tests/sqlmesh/tests/test_customer_revenue_by_day.yaml +63 -0
  99. package/recce-source/integration_tests/sqlmesh/tests/test_order_items.yaml +72 -0
  100. package/recce-source/js/.editorconfig +27 -0
  101. package/recce-source/js/.env.development +5 -0
  102. package/recce-source/js/.husky/pre-commit +29 -0
  103. package/recce-source/js/.nvmrc +1 -0
  104. package/recce-source/js/README.md +39 -0
  105. package/recce-source/js/app/(mainComponents)/DisplayModeToggle.tsx +65 -0
  106. package/recce-source/js/app/(mainComponents)/NavBar.tsx +228 -0
  107. package/recce-source/js/app/(mainComponents)/RecceVersionBadge.tsx +107 -0
  108. package/recce-source/js/app/(mainComponents)/TopBar.tsx +252 -0
  109. package/recce-source/js/app/@lineage/default.tsx +20 -0
  110. package/recce-source/js/app/@lineage/page.tsx +14 -0
  111. package/recce-source/js/app/MainLayout.tsx +170 -0
  112. package/recce-source/js/app/Providers.tsx +49 -0
  113. package/recce-source/js/app/checks/page.tsx +296 -0
  114. package/recce-source/js/app/error.tsx +93 -0
  115. package/recce-source/js/app/favicon.ico +0 -0
  116. package/recce-source/js/app/global-error.tsx +115 -0
  117. package/recce-source/js/app/global.css +82 -0
  118. package/recce-source/js/app/layout.tsx +48 -0
  119. package/recce-source/js/app/lineage/page.tsx +15 -0
  120. package/recce-source/js/app/page.tsx +12 -0
  121. package/recce-source/js/app/query/page.tsx +8 -0
  122. package/recce-source/js/biome.json +313 -0
  123. package/recce-source/js/jest.config.js +34 -0
  124. package/recce-source/js/jest.globals.d.ts +32 -0
  125. package/recce-source/js/jest.setup.js +91 -0
  126. package/recce-source/js/next.config.js +16 -0
  127. package/recce-source/js/package-lock.json +13843 -0
  128. package/recce-source/js/package.json +123 -0
  129. package/recce-source/js/pnpm-lock.yaml +9235 -0
  130. package/recce-source/js/pnpm-workspace.yaml +6 -0
  131. package/recce-source/js/postcss.config.js +5 -0
  132. package/recce-source/js/public/auth_callback.html +68 -0
  133. package/recce-source/js/public/imgs/feedback/thumbs-down.png +0 -0
  134. package/recce-source/js/public/imgs/feedback/thumbs-up.png +0 -0
  135. package/recce-source/js/public/imgs/reload-image.svg +4 -0
  136. package/recce-source/js/public/logo/recce-logo-white.png +0 -0
  137. package/recce-source/js/src/components/AuthModal/AuthModal.tsx +202 -0
  138. package/recce-source/js/src/components/app/AvatarDropdown.tsx +159 -0
  139. package/recce-source/js/src/components/app/EnvInfo.tsx +357 -0
  140. package/recce-source/js/src/components/app/Filename.tsx +388 -0
  141. package/recce-source/js/src/components/app/SetupConnectionPopover.tsx +91 -0
  142. package/recce-source/js/src/components/app/StateExporter.tsx +57 -0
  143. package/recce-source/js/src/components/app/StateImporter.tsx +198 -0
  144. package/recce-source/js/src/components/app/StateSharing.tsx +145 -0
  145. package/recce-source/js/src/components/app/StateSynchronizer.tsx +205 -0
  146. package/recce-source/js/src/components/charts/HistogramChart.tsx +291 -0
  147. package/recce-source/js/src/components/charts/SquareIcon.tsx +51 -0
  148. package/recce-source/js/src/components/charts/TopKSummaryList.tsx +457 -0
  149. package/recce-source/js/src/components/charts/chartTheme.ts +74 -0
  150. package/recce-source/js/src/components/check/CheckBreadcrumb.tsx +97 -0
  151. package/recce-source/js/src/components/check/CheckDescription.tsx +134 -0
  152. package/recce-source/js/src/components/check/CheckDetail.tsx +797 -0
  153. package/recce-source/js/src/components/check/CheckEmptyState.tsx +84 -0
  154. package/recce-source/js/src/components/check/CheckList.tsx +320 -0
  155. package/recce-source/js/src/components/check/LineageDiffView.tsx +32 -0
  156. package/recce-source/js/src/components/check/PresetCheckTemplateView.tsx +48 -0
  157. package/recce-source/js/src/components/check/SchemaDiffView.tsx +290 -0
  158. package/recce-source/js/src/components/check/check.ts +25 -0
  159. package/recce-source/js/src/components/check/timeline/CheckTimeline.tsx +163 -0
  160. package/recce-source/js/src/components/check/timeline/CommentInput.tsx +84 -0
  161. package/recce-source/js/src/components/check/timeline/TimelineEvent.tsx +468 -0
  162. package/recce-source/js/src/components/check/timeline/index.ts +12 -0
  163. package/recce-source/js/src/components/check/utils.ts +12 -0
  164. package/recce-source/js/src/components/data-grid/ScreenshotDataGrid.tsx +333 -0
  165. package/recce-source/js/src/components/data-grid/agGridStyles.css +55 -0
  166. package/recce-source/js/src/components/data-grid/agGridTheme.ts +43 -0
  167. package/recce-source/js/src/components/editor/CodeEditor.tsx +107 -0
  168. package/recce-source/js/src/components/editor/DiffEditor.tsx +162 -0
  169. package/recce-source/js/src/components/editor/index.ts +12 -0
  170. package/recce-source/js/src/components/errorboundary/ErrorBoundary.tsx +87 -0
  171. package/recce-source/js/src/components/histogram/HistogramDiffForm.tsx +147 -0
  172. package/recce-source/js/src/components/histogram/HistogramDiffResultView.tsx +63 -0
  173. package/recce-source/js/src/components/icons/index.tsx +142 -0
  174. package/recce-source/js/src/components/lineage/ActionControl.tsx +63 -0
  175. package/recce-source/js/src/components/lineage/ActionTag.tsx +141 -0
  176. package/recce-source/js/src/components/lineage/ChangeStatusLegend.tsx +46 -0
  177. package/recce-source/js/src/components/lineage/ColumnLevelLineageControl.tsx +327 -0
  178. package/recce-source/js/src/components/lineage/ColumnLevelLineageLegend.tsx +57 -0
  179. package/recce-source/js/src/components/lineage/GraphColumnNode.tsx +199 -0
  180. package/recce-source/js/src/components/lineage/GraphEdge.tsx +59 -0
  181. package/recce-source/js/src/components/lineage/GraphNode.tsx +555 -0
  182. package/recce-source/js/src/components/lineage/LineagePage.tsx +10 -0
  183. package/recce-source/js/src/components/lineage/LineageView.tsx +1384 -0
  184. package/recce-source/js/src/components/lineage/LineageViewContext.tsx +86 -0
  185. package/recce-source/js/src/components/lineage/LineageViewContextMenu.tsx +637 -0
  186. package/recce-source/js/src/components/lineage/LineageViewNotification.tsx +64 -0
  187. package/recce-source/js/src/components/lineage/LineageViewTopBar.tsx +596 -0
  188. package/recce-source/js/src/components/lineage/NodeSqlView.tsx +136 -0
  189. package/recce-source/js/src/components/lineage/NodeTag.tsx +278 -0
  190. package/recce-source/js/src/components/lineage/NodeView.tsx +642 -0
  191. package/recce-source/js/src/components/lineage/SandboxView.tsx +436 -0
  192. package/recce-source/js/src/components/lineage/ServerDisconnectedModalContent.tsx +105 -0
  193. package/recce-source/js/src/components/lineage/SetupConnectionBanner.tsx +52 -0
  194. package/recce-source/js/src/components/lineage/SingleEnvironmentQueryView.tsx +152 -0
  195. package/recce-source/js/src/components/lineage/graph.test.ts +31 -0
  196. package/recce-source/js/src/components/lineage/graph.ts +58 -0
  197. package/recce-source/js/src/components/lineage/lineage.test.ts +169 -0
  198. package/recce-source/js/src/components/lineage/lineage.ts +521 -0
  199. package/recce-source/js/src/components/lineage/styles.css +42 -0
  200. package/recce-source/js/src/components/lineage/styles.tsx +165 -0
  201. package/recce-source/js/src/components/lineage/useMultiNodesAction.ts +352 -0
  202. package/recce-source/js/src/components/lineage/useValueDiffAlertDialog.tsx +108 -0
  203. package/recce-source/js/src/components/onboarding-guide/Notification.tsx +62 -0
  204. package/recce-source/js/src/components/profile/ProfileDiffForm.tsx +134 -0
  205. package/recce-source/js/src/components/profile/ProfileDiffResultView.tsx +245 -0
  206. package/recce-source/js/src/components/query/ChangedOnlyCheckbox.tsx +29 -0
  207. package/recce-source/js/src/components/query/DiffText.tsx +120 -0
  208. package/recce-source/js/src/components/query/QueryDiffResultView.tsx +470 -0
  209. package/recce-source/js/src/components/query/QueryForm.tsx +80 -0
  210. package/recce-source/js/src/components/query/QueryPage.tsx +282 -0
  211. package/recce-source/js/src/components/query/QueryResultView.tsx +180 -0
  212. package/recce-source/js/src/components/query/SetupConnectionGuide.tsx +57 -0
  213. package/recce-source/js/src/components/query/SqlEditor.tsx +245 -0
  214. package/recce-source/js/src/components/query/ToggleSwitch.tsx +84 -0
  215. package/recce-source/js/src/components/query/styles.css +21 -0
  216. package/recce-source/js/src/components/routing/DirectUrlAccess.test.tsx +428 -0
  217. package/recce-source/js/src/components/routing/LineageStatePreservation.test.tsx +311 -0
  218. package/recce-source/js/src/components/routing/Navigation.test.tsx +256 -0
  219. package/recce-source/js/src/components/rowcount/RowCountDiffResultView.tsx +109 -0
  220. package/recce-source/js/src/components/rowcount/delta.ts +11 -0
  221. package/recce-source/js/src/components/run/RunList.tsx +303 -0
  222. package/recce-source/js/src/components/run/RunModal.tsx +191 -0
  223. package/recce-source/js/src/components/run/RunPage.tsx +26 -0
  224. package/recce-source/js/src/components/run/RunResultPane.tsx +454 -0
  225. package/recce-source/js/src/components/run/RunStatusAndDate.tsx +106 -0
  226. package/recce-source/js/src/components/run/RunToolbar.tsx +70 -0
  227. package/recce-source/js/src/components/run/RunView.tsx +196 -0
  228. package/recce-source/js/src/components/run/registry.ts +214 -0
  229. package/recce-source/js/src/components/run/types.ts +14 -0
  230. package/recce-source/js/src/components/schema/ColumnNameCell.test.tsx +169 -0
  231. package/recce-source/js/src/components/schema/ColumnNameCell.tsx +198 -0
  232. package/recce-source/js/src/components/schema/SchemaView.tsx +337 -0
  233. package/recce-source/js/src/components/schema/schemaDiff.ts +32 -0
  234. package/recce-source/js/src/components/schema/style.css +134 -0
  235. package/recce-source/js/src/components/screenshot/ScreenshotBox.tsx +39 -0
  236. package/recce-source/js/src/components/shared/HistoryToggle.tsx +35 -0
  237. package/recce-source/js/src/components/split/Split.tsx +40 -0
  238. package/recce-source/js/src/components/split/styles.css +24 -0
  239. package/recce-source/js/src/components/summary/ChangeSummary.tsx +264 -0
  240. package/recce-source/js/src/components/summary/SchemaSummary.tsx +123 -0
  241. package/recce-source/js/src/components/summary/SummaryView.tsx +29 -0
  242. package/recce-source/js/src/components/timeout/IdleTimeoutBadge.tsx +48 -0
  243. package/recce-source/js/src/components/top-k/TopKDiffForm.tsx +58 -0
  244. package/recce-source/js/src/components/top-k/TopKDiffResultView.tsx +73 -0
  245. package/recce-source/js/src/components/ui/dataGrid/DataFrameColumnGroupHeader.tsx +228 -0
  246. package/recce-source/js/src/components/ui/dataGrid/DataFrameColumnHeader.tsx +113 -0
  247. package/recce-source/js/src/components/ui/dataGrid/defaultRenderCell.tsx +72 -0
  248. package/recce-source/js/src/components/ui/dataGrid/index.ts +23 -0
  249. package/recce-source/js/src/components/ui/dataGrid/inlineRenderCell.test.tsx +607 -0
  250. package/recce-source/js/src/components/ui/dataGrid/inlineRenderCell.tsx +211 -0
  251. package/recce-source/js/src/components/ui/dataGrid/schemaCells.test.tsx +452 -0
  252. package/recce-source/js/src/components/ui/dataGrid/schemaCells.tsx +142 -0
  253. package/recce-source/js/src/components/ui/dataGrid/valueDiffCells.test.tsx +178 -0
  254. package/recce-source/js/src/components/ui/dataGrid/valueDiffCells.tsx +275 -0
  255. package/recce-source/js/src/components/ui/markdown/ExternalLinkConfirmDialog.tsx +134 -0
  256. package/recce-source/js/src/components/ui/markdown/MarkdownContent.tsx +364 -0
  257. package/recce-source/js/src/components/ui/mui/index.ts +13 -0
  258. package/recce-source/js/src/components/ui/mui-provider.tsx +67 -0
  259. package/recce-source/js/src/components/ui/mui-theme.ts +1039 -0
  260. package/recce-source/js/src/components/ui/mui-utils.ts +113 -0
  261. package/recce-source/js/src/components/ui/toaster.tsx +288 -0
  262. package/recce-source/js/src/components/valuediff/ValueDiffDetailResultView.tsx +217 -0
  263. package/recce-source/js/src/components/valuediff/ValueDiffForm.tsx +246 -0
  264. package/recce-source/js/src/components/valuediff/ValueDiffResultView.tsx +82 -0
  265. package/recce-source/js/src/components/valuediff/shared.ts +33 -0
  266. package/recce-source/js/src/constants/tooltipMessage.ts +3 -0
  267. package/recce-source/js/src/constants/urls.ts +1 -0
  268. package/recce-source/js/src/lib/UrlHash.ts +12 -0
  269. package/recce-source/js/src/lib/api/adhocQuery.ts +70 -0
  270. package/recce-source/js/src/lib/api/axiosClient.ts +9 -0
  271. package/recce-source/js/src/lib/api/cacheKeys.ts +13 -0
  272. package/recce-source/js/src/lib/api/checkEvents.ts +252 -0
  273. package/recce-source/js/src/lib/api/checks.ts +129 -0
  274. package/recce-source/js/src/lib/api/cll.ts +53 -0
  275. package/recce-source/js/src/lib/api/connectToCloud.ts +13 -0
  276. package/recce-source/js/src/lib/api/flag.ts +37 -0
  277. package/recce-source/js/src/lib/api/info.ts +198 -0
  278. package/recce-source/js/src/lib/api/instanceInfo.ts +25 -0
  279. package/recce-source/js/src/lib/api/keepAlive.ts +108 -0
  280. package/recce-source/js/src/lib/api/lineagecheck.ts +35 -0
  281. package/recce-source/js/src/lib/api/localStorageKeys.ts +7 -0
  282. package/recce-source/js/src/lib/api/models.ts +59 -0
  283. package/recce-source/js/src/lib/api/profile.ts +65 -0
  284. package/recce-source/js/src/lib/api/rowcount.ts +19 -0
  285. package/recce-source/js/src/lib/api/runs.ts +174 -0
  286. package/recce-source/js/src/lib/api/schemacheck.ts +31 -0
  287. package/recce-source/js/src/lib/api/select.ts +25 -0
  288. package/recce-source/js/src/lib/api/sessionStorageKeys.ts +8 -0
  289. package/recce-source/js/src/lib/api/state.ts +117 -0
  290. package/recce-source/js/src/lib/api/track.ts +281 -0
  291. package/recce-source/js/src/lib/api/types.ts +284 -0
  292. package/recce-source/js/src/lib/api/user.ts +42 -0
  293. package/recce-source/js/src/lib/api/valuediff.ts +46 -0
  294. package/recce-source/js/src/lib/api/version.ts +40 -0
  295. package/recce-source/js/src/lib/const.ts +9 -0
  296. package/recce-source/js/src/lib/dataGrid/crossFunctionConsistency.test.ts +626 -0
  297. package/recce-source/js/src/lib/dataGrid/dataGridFactory.test.ts +2140 -0
  298. package/recce-source/js/src/lib/dataGrid/dataGridFactory.ts +397 -0
  299. package/recce-source/js/src/lib/dataGrid/generators/rowCountUtils.test.ts +132 -0
  300. package/recce-source/js/src/lib/dataGrid/generators/rowCountUtils.ts +126 -0
  301. package/recce-source/js/src/lib/dataGrid/generators/toDataDiffGrid.test.ts +1627 -0
  302. package/recce-source/js/src/lib/dataGrid/generators/toDataDiffGrid.ts +140 -0
  303. package/recce-source/js/src/lib/dataGrid/generators/toDataGrid.ts +67 -0
  304. package/recce-source/js/src/lib/dataGrid/generators/toRowCountDataGrid.test.ts +142 -0
  305. package/recce-source/js/src/lib/dataGrid/generators/toRowCountDataGrid.ts +71 -0
  306. package/recce-source/js/src/lib/dataGrid/generators/toRowCountDiffDataGrid.test.ts +258 -0
  307. package/recce-source/js/src/lib/dataGrid/generators/toRowCountDiffDataGrid.ts +153 -0
  308. package/recce-source/js/src/lib/dataGrid/generators/toSchemaDataGrid.test.ts +951 -0
  309. package/recce-source/js/src/lib/dataGrid/generators/toSchemaDataGrid.ts +221 -0
  310. package/recce-source/js/src/lib/dataGrid/generators/toValueDataGrid.test.ts +395 -0
  311. package/recce-source/js/src/lib/dataGrid/generators/toValueDataGrid.ts +184 -0
  312. package/recce-source/js/src/lib/dataGrid/generators/toValueDiffGrid.test.ts +884 -0
  313. package/recce-source/js/src/lib/dataGrid/generators/toValueDiffGrid.ts +113 -0
  314. package/recce-source/js/src/lib/dataGrid/index.ts +51 -0
  315. package/recce-source/js/src/lib/dataGrid/propertyBased.test.ts +858 -0
  316. package/recce-source/js/src/lib/dataGrid/shared/columnBuilders.test.ts +482 -0
  317. package/recce-source/js/src/lib/dataGrid/shared/columnBuilders.ts +345 -0
  318. package/recce-source/js/src/lib/dataGrid/shared/dataTypeEdgeCases.test.ts +698 -0
  319. package/recce-source/js/src/lib/dataGrid/shared/diffColumnBuilder.test.tsx +820 -0
  320. package/recce-source/js/src/lib/dataGrid/shared/diffColumnBuilder.tsx +277 -0
  321. package/recce-source/js/src/lib/dataGrid/shared/gridUtils.test.ts +785 -0
  322. package/recce-source/js/src/lib/dataGrid/shared/gridUtils.ts +370 -0
  323. package/recce-source/js/src/lib/dataGrid/shared/index.ts +81 -0
  324. package/recce-source/js/src/lib/dataGrid/shared/rowBuilders.test.ts +909 -0
  325. package/recce-source/js/src/lib/dataGrid/shared/rowBuilders.ts +325 -0
  326. package/recce-source/js/src/lib/dataGrid/shared/simpleColumnBuilder.tsx +240 -0
  327. package/recce-source/js/src/lib/dataGrid/shared/toDiffColumn.test.tsx +719 -0
  328. package/recce-source/js/src/lib/dataGrid/shared/toDiffColumn.tsx +231 -0
  329. package/recce-source/js/src/lib/dataGrid/shared/validation.test.ts +559 -0
  330. package/recce-source/js/src/lib/dataGrid/shared/validation.ts +367 -0
  331. package/recce-source/js/src/lib/dataGrid/warehouseNamingConventions.test.ts +1117 -0
  332. package/recce-source/js/src/lib/formatSelect.ts +50 -0
  333. package/recce-source/js/src/lib/hooks/ApiConfigContext.tsx +181 -0
  334. package/recce-source/js/src/lib/hooks/IdleTimeoutContext.tsx +177 -0
  335. package/recce-source/js/src/lib/hooks/LineageGraphContext.tsx +512 -0
  336. package/recce-source/js/src/lib/hooks/RecceActionContext.tsx +269 -0
  337. package/recce-source/js/src/lib/hooks/RecceCheckContext.tsx +33 -0
  338. package/recce-source/js/src/lib/hooks/RecceContextProvider.tsx +54 -0
  339. package/recce-source/js/src/lib/hooks/RecceInstanceContext.tsx +129 -0
  340. package/recce-source/js/src/lib/hooks/RecceQueryContext.tsx +98 -0
  341. package/recce-source/js/src/lib/hooks/RecceShareStateContext.tsx +59 -0
  342. package/recce-source/js/src/lib/hooks/ScreenShot.tsx +399 -0
  343. package/recce-source/js/src/lib/hooks/useAppRouter.test.ts +211 -0
  344. package/recce-source/js/src/lib/hooks/useAppRouter.ts +200 -0
  345. package/recce-source/js/src/lib/hooks/useCheckEvents.ts +99 -0
  346. package/recce-source/js/src/lib/hooks/useCheckToast.tsx +14 -0
  347. package/recce-source/js/src/lib/hooks/useClipBoardToast.tsx +27 -0
  348. package/recce-source/js/src/lib/hooks/useCountdownToast.tsx +102 -0
  349. package/recce-source/js/src/lib/hooks/useFeedbackCollectionToast.tsx +130 -0
  350. package/recce-source/js/src/lib/hooks/useGuideToast.tsx +45 -0
  351. package/recce-source/js/src/lib/hooks/useIdleDetection.tsx +185 -0
  352. package/recce-source/js/src/lib/hooks/useModelColumns.tsx +113 -0
  353. package/recce-source/js/src/lib/hooks/useRecceInstanceInfo.tsx +13 -0
  354. package/recce-source/js/src/lib/hooks/useRecceServerFlag.tsx +13 -0
  355. package/recce-source/js/src/lib/hooks/useRun.tsx +89 -0
  356. package/recce-source/js/src/lib/hooks/useThemeColors.ts +115 -0
  357. package/recce-source/js/src/lib/mergeKeys.test.ts +89 -0
  358. package/recce-source/js/src/lib/mergeKeys.ts +86 -0
  359. package/recce-source/js/src/lib/result/ResultErrorFallback.tsx +9 -0
  360. package/recce-source/js/src/lib/utils/formatTime.ts +84 -0
  361. package/recce-source/js/src/lib/utils/urls.ts +16 -0
  362. package/recce-source/js/src/utils/DropdownValuesInput.tsx +297 -0
  363. package/recce-source/js/src/utils/formatters.tsx +237 -0
  364. package/recce-source/js/src/utils/transforms.ts +81 -0
  365. package/recce-source/js/tsconfig.json +47 -0
  366. package/recce-source/macros/README.md +8 -0
  367. package/recce-source/macros/recce_athena.sql +73 -0
  368. package/recce-source/pyproject.toml +109 -0
  369. package/recce-source/recce/VERSION +1 -0
  370. package/recce-source/recce/__init__.py +84 -0
  371. package/recce-source/recce/adapter/__init__.py +0 -0
  372. package/recce-source/recce/adapter/base.py +109 -0
  373. package/recce-source/recce/adapter/dbt_adapter/__init__.py +1699 -0
  374. package/recce-source/recce/adapter/dbt_adapter/dbt_version.py +42 -0
  375. package/recce-source/recce/adapter/sqlmesh_adapter.py +141 -0
  376. package/recce-source/recce/apis/__init__.py +0 -0
  377. package/recce-source/recce/apis/check_api.py +203 -0
  378. package/recce-source/recce/apis/check_events_api.py +353 -0
  379. package/recce-source/recce/apis/check_func.py +130 -0
  380. package/recce-source/recce/apis/run_api.py +130 -0
  381. package/recce-source/recce/apis/run_func.py +258 -0
  382. package/recce-source/recce/artifact.py +266 -0
  383. package/recce-source/recce/cli.py +1846 -0
  384. package/recce-source/recce/config.py +127 -0
  385. package/recce-source/recce/connect_to_cloud.py +138 -0
  386. package/recce-source/recce/core.py +334 -0
  387. package/recce-source/recce/diff.py +26 -0
  388. package/recce-source/recce/event/CONFIG +1 -0
  389. package/recce-source/recce/event/SENTRY_DNS +1 -0
  390. package/recce-source/recce/event/__init__.py +304 -0
  391. package/recce-source/recce/event/collector.py +184 -0
  392. package/recce-source/recce/event/track.py +158 -0
  393. package/recce-source/recce/exceptions.py +21 -0
  394. package/recce-source/recce/git.py +77 -0
  395. package/recce-source/recce/github.py +222 -0
  396. package/recce-source/recce/mcp_server.py +861 -0
  397. package/recce-source/recce/models/__init__.py +6 -0
  398. package/recce-source/recce/models/check.py +473 -0
  399. package/recce-source/recce/models/run.py +46 -0
  400. package/recce-source/recce/models/types.py +218 -0
  401. package/recce-source/recce/pull_request.py +124 -0
  402. package/recce-source/recce/run.py +390 -0
  403. package/recce-source/recce/server.py +877 -0
  404. package/recce-source/recce/state/__init__.py +31 -0
  405. package/recce-source/recce/state/cloud.py +644 -0
  406. package/recce-source/recce/state/const.py +26 -0
  407. package/recce-source/recce/state/local.py +56 -0
  408. package/recce-source/recce/state/state.py +119 -0
  409. package/recce-source/recce/state/state_loader.py +174 -0
  410. package/recce-source/recce/summary.py +575 -0
  411. package/recce-source/recce/tasks/__init__.py +23 -0
  412. package/recce-source/recce/tasks/core.py +134 -0
  413. package/recce-source/recce/tasks/dataframe.py +170 -0
  414. package/recce-source/recce/tasks/histogram.py +433 -0
  415. package/recce-source/recce/tasks/lineage.py +19 -0
  416. package/recce-source/recce/tasks/profile.py +298 -0
  417. package/recce-source/recce/tasks/query.py +450 -0
  418. package/recce-source/recce/tasks/rowcount.py +277 -0
  419. package/recce-source/recce/tasks/schema.py +65 -0
  420. package/recce-source/recce/tasks/top_k.py +172 -0
  421. package/recce-source/recce/tasks/utils.py +147 -0
  422. package/recce-source/recce/tasks/valuediff.py +497 -0
  423. package/recce-source/recce/util/__init__.py +4 -0
  424. package/recce-source/recce/util/api_token.py +80 -0
  425. package/recce-source/recce/util/breaking.py +330 -0
  426. package/recce-source/recce/util/cache.py +25 -0
  427. package/recce-source/recce/util/cll.py +355 -0
  428. package/recce-source/recce/util/cloud/__init__.py +15 -0
  429. package/recce-source/recce/util/cloud/base.py +115 -0
  430. package/recce-source/recce/util/cloud/check_events.py +190 -0
  431. package/recce-source/recce/util/cloud/checks.py +242 -0
  432. package/recce-source/recce/util/io.py +120 -0
  433. package/recce-source/recce/util/lineage.py +83 -0
  434. package/recce-source/recce/util/logger.py +25 -0
  435. package/recce-source/recce/util/onboarding_state.py +45 -0
  436. package/recce-source/recce/util/perf_tracking.py +85 -0
  437. package/recce-source/recce/util/pydantic_model.py +22 -0
  438. package/recce-source/recce/util/recce_cloud.py +454 -0
  439. package/recce-source/recce/util/singleton.py +18 -0
  440. package/recce-source/recce/util/startup_perf.py +121 -0
  441. package/recce-source/recce/yaml/__init__.py +58 -0
  442. package/recce-source/recce_cloud/README.md +780 -0
  443. package/recce-source/recce_cloud/VERSION +1 -0
  444. package/recce-source/recce_cloud/__init__.py +24 -0
  445. package/recce-source/recce_cloud/api/__init__.py +17 -0
  446. package/recce-source/recce_cloud/api/base.py +132 -0
  447. package/recce-source/recce_cloud/api/client.py +186 -0
  448. package/recce-source/recce_cloud/api/exceptions.py +26 -0
  449. package/recce-source/recce_cloud/api/factory.py +63 -0
  450. package/recce-source/recce_cloud/api/github.py +106 -0
  451. package/recce-source/recce_cloud/api/gitlab.py +111 -0
  452. package/recce-source/recce_cloud/artifact.py +57 -0
  453. package/recce-source/recce_cloud/ci_providers/__init__.py +9 -0
  454. package/recce-source/recce_cloud/ci_providers/base.py +82 -0
  455. package/recce-source/recce_cloud/ci_providers/detector.py +147 -0
  456. package/recce-source/recce_cloud/ci_providers/github_actions.py +136 -0
  457. package/recce-source/recce_cloud/ci_providers/gitlab_ci.py +130 -0
  458. package/recce-source/recce_cloud/cli.py +434 -0
  459. package/recce-source/recce_cloud/download.py +230 -0
  460. package/recce-source/recce_cloud/hatch_build.py +20 -0
  461. package/recce-source/recce_cloud/pyproject.toml +49 -0
  462. package/recce-source/recce_cloud/upload.py +214 -0
  463. package/recce-source/test.py +0 -0
  464. package/recce-source/tests/__init__.py +0 -0
  465. package/recce-source/tests/adapter/__init__.py +0 -0
  466. package/recce-source/tests/adapter/dbt_adapter/__init__.py +0 -0
  467. package/recce-source/tests/adapter/dbt_adapter/conftest.py +17 -0
  468. package/recce-source/tests/adapter/dbt_adapter/dbt_test_helper.py +298 -0
  469. package/recce-source/tests/adapter/dbt_adapter/test_dbt_adapter.py +25 -0
  470. package/recce-source/tests/adapter/dbt_adapter/test_dbt_cll.py +717 -0
  471. package/recce-source/tests/adapter/dbt_adapter/test_proj/dbt_project.yml +4 -0
  472. package/recce-source/tests/adapter/dbt_adapter/test_proj/manifest.json +1 -0
  473. package/recce-source/tests/adapter/dbt_adapter/test_proj/package-lock.yml +8 -0
  474. package/recce-source/tests/adapter/dbt_adapter/test_proj/packages.yml +7 -0
  475. package/recce-source/tests/adapter/dbt_adapter/test_proj/profiles.yml +6 -0
  476. package/recce-source/tests/adapter/dbt_adapter/test_selector.py +205 -0
  477. package/recce-source/tests/apis/__init__.py +0 -0
  478. package/recce-source/tests/apis/row_count_diff.json +59 -0
  479. package/recce-source/tests/apis/test_check_events_api.py +615 -0
  480. package/recce-source/tests/apis/test_run_func.py +433 -0
  481. package/recce-source/tests/catalog.json +527 -0
  482. package/recce-source/tests/data/manifest/base/catalog.json +1 -0
  483. package/recce-source/tests/data/manifest/base/manifest.json +1 -0
  484. package/recce-source/tests/data/manifest/pr2/catalog.json +1 -0
  485. package/recce-source/tests/data/manifest/pr2/manifest.json +1 -0
  486. package/recce-source/tests/manifest.json +10655 -0
  487. package/recce-source/tests/models/__init__.py +0 -0
  488. package/recce-source/tests/models/test_check.py +731 -0
  489. package/recce-source/tests/models/test_run_models.py +295 -0
  490. package/recce-source/tests/recce_cloud/__init__.py +0 -0
  491. package/recce-source/tests/recce_cloud/test_ci_providers.py +351 -0
  492. package/recce-source/tests/recce_cloud/test_cli.py +735 -0
  493. package/recce-source/tests/recce_cloud/test_client.py +379 -0
  494. package/recce-source/tests/recce_cloud/test_platform_clients.py +483 -0
  495. package/recce-source/tests/recce_state.json +1 -0
  496. package/recce-source/tests/state/test_cloud.py +719 -0
  497. package/recce-source/tests/state/test_local.py +164 -0
  498. package/recce-source/tests/state/test_state_loader.py +211 -0
  499. package/recce-source/tests/tasks/__init__.py +0 -0
  500. package/recce-source/tests/tasks/conftest.py +4 -0
  501. package/recce-source/tests/tasks/test_histogram.py +129 -0
  502. package/recce-source/tests/tasks/test_lineage.py +55 -0
  503. package/recce-source/tests/tasks/test_preset_checks.py +64 -0
  504. package/recce-source/tests/tasks/test_profile.py +397 -0
  505. package/recce-source/tests/tasks/test_query.py +528 -0
  506. package/recce-source/tests/tasks/test_row_count.py +133 -0
  507. package/recce-source/tests/tasks/test_schema.py +122 -0
  508. package/recce-source/tests/tasks/test_top_k.py +77 -0
  509. package/recce-source/tests/tasks/test_utils.py +439 -0
  510. package/recce-source/tests/tasks/test_valuediff.py +361 -0
  511. package/recce-source/tests/test_cli.py +236 -0
  512. package/recce-source/tests/test_cli_mcp_optional.py +45 -0
  513. package/recce-source/tests/test_cloud_listing_cli.py +324 -0
  514. package/recce-source/tests/test_config.py +43 -0
  515. package/recce-source/tests/test_connect_to_cloud.py +82 -0
  516. package/recce-source/tests/test_core.py +174 -0
  517. package/recce-source/tests/test_dbt.py +36 -0
  518. package/recce-source/tests/test_mcp_server.py +505 -0
  519. package/recce-source/tests/test_pull_request.py +130 -0
  520. package/recce-source/tests/test_server.py +202 -0
  521. package/recce-source/tests/test_server_lifespan.py +138 -0
  522. package/recce-source/tests/test_summary.py +73 -0
  523. package/recce-source/tests/util/__init__.py +0 -0
  524. package/recce-source/tests/util/cloud/__init__.py +0 -0
  525. package/recce-source/tests/util/cloud/test_check_events.py +255 -0
  526. package/recce-source/tests/util/cloud/test_checks.py +204 -0
  527. package/recce-source/tests/util/test_api_token.py +119 -0
  528. package/recce-source/tests/util/test_breaking.py +1427 -0
  529. package/recce-source/tests/util/test_cll.py +706 -0
  530. package/recce-source/tests/util/test_lineage.py +122 -0
  531. package/recce-source/tests/util/test_onboarding_state.py +84 -0
  532. package/recce-source/tests/util/test_recce_cloud.py +231 -0
  533. package/recce-source/tox.ini +40 -0
  534. package/recce-source/uv.lock +3928 -0
  535. package/src/api/index.ts +32 -0
  536. package/src/components/index.ts +154 -0
  537. package/src/global.d.ts +14 -0
  538. package/src/hooks/index.ts +56 -0
  539. package/src/index.ts +17 -0
  540. package/src/lib/hooks/RouteConfigContext.ts +139 -0
  541. package/src/lib/hooks/useAppRouter.ts +240 -0
  542. package/src/mui-augmentation.d.ts +139 -0
  543. package/src/theme/index.ts +13 -0
  544. package/src/theme.ts +23 -0
  545. package/src/types/index.ts +23 -0
  546. package/dist/index-BNUP2V_N.d.ts.map +0 -1
  547. package/dist/index-DOPZuhD8.d.mts.map +0 -1
  548. package/dist/theme.d.mts.map +0 -1
  549. package/dist/theme.d.ts.map +0 -1
@@ -0,0 +1,1846 @@
1
+ import asyncio
2
+ import os
3
+ from pathlib import Path
4
+ from typing import List
5
+
6
+ import click
7
+ import uvicorn
8
+ from click import Abort
9
+
10
+ from recce import event
11
+ from recce.artifact import (
12
+ delete_dbt_artifacts,
13
+ download_dbt_artifacts,
14
+ upload_artifacts_to_session,
15
+ upload_dbt_artifacts,
16
+ )
17
+ from recce.config import RECCE_CONFIG_FILE, RECCE_ERROR_LOG_FILE, RecceConfig
18
+ from recce.connect_to_cloud import (
19
+ generate_key_pair,
20
+ prepare_connection_url,
21
+ run_one_time_http_server,
22
+ )
23
+ from recce.exceptions import RecceConfigException
24
+ from recce.git import current_branch, current_default_branch
25
+ from recce.run import check_github_ci_env, cli_run
26
+ from recce.server import RecceServerMode
27
+ from recce.state import (
28
+ CloudStateLoader,
29
+ FileStateLoader,
30
+ RecceCloudStateManager,
31
+ RecceShareStateManager,
32
+ )
33
+ from recce.summary import generate_markdown_summary
34
+ from recce.util.api_token import prepare_api_token, show_invalid_api_token_message
35
+ from recce.util.logger import CustomFormatter
36
+ from recce.util.onboarding_state import update_onboarding_state
37
+ from recce.util.recce_cloud import (
38
+ RecceCloudException,
39
+ )
40
+ from recce.util.startup_perf import track_timing
41
+
42
+ from .core import RecceContext, set_default_context
43
+ from .event.track import TrackCommand
44
+
45
+ event.init()
46
+
47
+
48
+ def create_state_loader(review_mode, cloud_mode, state_file, cloud_options):
49
+ from rich.console import Console
50
+
51
+ console = Console()
52
+
53
+ try:
54
+ state_loader = (
55
+ CloudStateLoader(review_mode=review_mode, cloud_options=cloud_options)
56
+ if cloud_mode
57
+ else FileStateLoader(review_mode=review_mode, state_file=state_file)
58
+ )
59
+ state_loader.load()
60
+ return state_loader
61
+ except RecceCloudException as e:
62
+ console.print("[[red]Error[/red]] Failed to load recce state file")
63
+ console.print(f"Reason: {e.reason}")
64
+ exit(1)
65
+ except Exception as e:
66
+ console.print("[[red]Error[/red]] Failed to load recce state file")
67
+ console.print(f"Reason: {e}")
68
+ exit(1)
69
+
70
+
71
+ def patch_derived_args(args):
72
+ """
73
+ Patch derived args based on other args.
74
+ """
75
+ if args.get("session_id") or args.get("share_url"):
76
+ args["cloud"] = True
77
+ args["review"] = True
78
+
79
+
80
+ @track_timing("state_loader_init")
81
+ def create_state_loader_by_args(state_file=None, **kwargs):
82
+ """
83
+ Create a state loader based on CLI arguments.
84
+
85
+ This function handles the cloud options logic that is shared between
86
+ server and mcp-server commands.
87
+
88
+ Args:
89
+ state_file: Optional path to state file
90
+ **kwargs: CLI arguments including api_token, cloud, review, session_id, share_url, etc.
91
+
92
+ Returns:
93
+ state_loader: The created state loader instance
94
+ """
95
+ from rich.console import Console
96
+
97
+ console = Console()
98
+
99
+ api_token = kwargs.get("api_token")
100
+ is_review = kwargs.get("review", False)
101
+ is_cloud = kwargs.get("cloud", False)
102
+ cloud_options = None
103
+
104
+ # Handle share_url and session_id
105
+ share_url = kwargs.get("share_url")
106
+ session_id = kwargs.get("session_id")
107
+
108
+ if share_url:
109
+ share_id = share_url.split("/")[-1]
110
+ if not share_id:
111
+ console.print("[[red]Error[/red]] Invalid share URL format.")
112
+ exit(1)
113
+
114
+ if is_cloud:
115
+ # Cloud mode
116
+ if share_url:
117
+ cloud_options = {
118
+ "host": kwargs.get("state_file_host"),
119
+ "api_token": api_token,
120
+ "share_id": share_id,
121
+ }
122
+ elif session_id:
123
+ cloud_options = {
124
+ "host": kwargs.get("state_file_host"),
125
+ "api_token": api_token,
126
+ "session_id": session_id,
127
+ }
128
+ else:
129
+ cloud_options = {
130
+ "host": kwargs.get("state_file_host"),
131
+ "github_token": kwargs.get("cloud_token"),
132
+ "password": kwargs.get("password"),
133
+ }
134
+
135
+ # Create state loader
136
+ state_loader = create_state_loader(is_review, is_cloud, state_file, cloud_options)
137
+
138
+ return state_loader
139
+
140
+
141
+ def handle_debug_flag(**kwargs):
142
+ if kwargs.get("debug"):
143
+ import logging
144
+
145
+ ch = logging.StreamHandler()
146
+ ch.setFormatter(CustomFormatter())
147
+ logging.basicConfig(handlers=[ch], level=logging.DEBUG)
148
+
149
+ # Explicitly set uvicorn logger to DEBUG level
150
+ uvicorn_logger = logging.getLogger("uvicorn")
151
+ uvicorn_logger.setLevel(logging.DEBUG)
152
+
153
+ # Set all child loggers to DEBUG as well
154
+ for handler in uvicorn_logger.handlers:
155
+ handler.setLevel(logging.DEBUG)
156
+
157
+
158
+ def add_options(options):
159
+ def _add_options(func):
160
+ for option in reversed(options):
161
+ func = option(func)
162
+ return func
163
+
164
+ return _add_options
165
+
166
+
167
+ dbt_related_options = [
168
+ click.option("--target", "-t", help="Which target to load for the given profile.", type=click.STRING),
169
+ click.option("--profile", help="Which existing profile to load.", type=click.STRING),
170
+ click.option(
171
+ "--project-dir",
172
+ help="Which directory to look in for the dbt_project.yml file.",
173
+ type=click.Path(),
174
+ envvar="DBT_PROJECT_DIR",
175
+ ),
176
+ click.option(
177
+ "--profiles-dir",
178
+ help="Which directory to look in for the profiles.yml file.",
179
+ type=click.Path(),
180
+ envvar="DBT_PROFILES_DIR",
181
+ ),
182
+ ]
183
+
184
+ sqlmesh_related_options = [
185
+ click.option("--sqlmesh", is_flag=True, help="Use SQLMesh ", hidden=True),
186
+ click.option("--sqlmesh-envs", is_flag=False, help="SQLMesh envs to compare. SOURCE:TARGET", hidden=True),
187
+ click.option("--sqlmesh-config", is_flag=False, help="SQLMesh config name to use", hidden=True),
188
+ ]
189
+
190
+ recce_options = [
191
+ click.option(
192
+ "--config",
193
+ help="Path to the recce config file.",
194
+ type=click.Path(),
195
+ default=RECCE_CONFIG_FILE,
196
+ show_default=True,
197
+ ),
198
+ click.option(
199
+ "--error-log", help="Path to the error log file.", type=click.Path(), default=RECCE_ERROR_LOG_FILE, hidden=True
200
+ ),
201
+ click.option("--debug", is_flag=True, help="Enable debug mode.", hidden=True),
202
+ ]
203
+
204
+ recce_cloud_options = [
205
+ click.option("--cloud", is_flag=True, help="Fetch the state file from cloud."),
206
+ click.option(
207
+ "--cloud-token", help="The GitHub token used by Recce Cloud.", type=click.STRING, envvar="GITHUB_TOKEN"
208
+ ),
209
+ click.option(
210
+ "--state-file-host",
211
+ help="The host to fetch the state file from.",
212
+ type=click.STRING,
213
+ envvar="RECCE_STATE_FILE_HOST",
214
+ default="",
215
+ hidden=True,
216
+ ),
217
+ click.option(
218
+ "--password",
219
+ "-p",
220
+ help="The password to encrypt the state file in cloud.",
221
+ type=click.STRING,
222
+ envvar="RECCE_STATE_PASSWORD",
223
+ ),
224
+ ]
225
+
226
+ recce_cloud_auth_options = [
227
+ click.option(
228
+ "--api-token",
229
+ help="The personal token generated by Recce Cloud.",
230
+ type=click.STRING,
231
+ envvar="RECCE_API_TOKEN",
232
+ )
233
+ ]
234
+
235
+ recce_dbt_artifact_dir_options = [
236
+ click.option(
237
+ "--target-path",
238
+ help="dbt artifacts directory for your development branch.",
239
+ type=click.STRING,
240
+ default="target",
241
+ ),
242
+ click.option(
243
+ "--target-base-path",
244
+ help="dbt artifacts directory to be used as the base for the comparison.",
245
+ type=click.STRING,
246
+ default="target-base",
247
+ ),
248
+ ]
249
+
250
+ recce_hidden_options = [
251
+ click.option(
252
+ "--mode",
253
+ envvar="RECCE_SERVER_MODE",
254
+ type=click.Choice(RecceServerMode.available_members(), case_sensitive=False),
255
+ hidden=True,
256
+ ),
257
+ click.option(
258
+ "--share-url",
259
+ help="The share URL triggers this instance.",
260
+ type=click.STRING,
261
+ envvar="RECCE_SHARE_URL",
262
+ hidden=True,
263
+ ),
264
+ click.option(
265
+ "--session-id",
266
+ help="The session ID triggers this instance.",
267
+ type=click.STRING,
268
+ envvar=["RECCE_SESSION_ID", "RECCE_SNAPSHOT_ID"], # Backward compatibility with RECCE_SNAPSHOT_ID
269
+ hidden=True,
270
+ ),
271
+ ]
272
+
273
+
274
+ def _execute_sql(context, sql_template, base=False):
275
+ try:
276
+ import pandas as pd
277
+ except ImportError:
278
+ print("'pandas' package not found. You can install it using the command: 'pip install pandas'.")
279
+ exit(1)
280
+
281
+ from recce.adapter.dbt_adapter import DbtAdapter
282
+
283
+ dbt_adapter: DbtAdapter = context.adapter
284
+ with dbt_adapter.connection_named("recce"):
285
+ sql = dbt_adapter.generate_sql(sql_template, base)
286
+ response, result = dbt_adapter.execute(sql, fetch=True, auto_begin=True)
287
+ table = result
288
+ df = pd.DataFrame([row.values() for row in table.rows], columns=table.column_names)
289
+ return df
290
+
291
+
292
+ @click.group()
293
+ @click.pass_context
294
+ def cli(ctx, **kwargs):
295
+ """Recce: Data validation toolkit for comprehensive PR review"""
296
+ from rich.console import Console
297
+
298
+ from recce import __is_recce_outdated__, __latest_version__
299
+
300
+ if __is_recce_outdated__ is True:
301
+ error_console = Console(stderr=True, style="bold")
302
+ error_console.print(
303
+ f"[[yellow]Update Available[/yellow]] A new version of Recce {__latest_version__} is available.",
304
+ )
305
+ error_console.print("Please update using the command: 'pip install --upgrade recce'.", end="\n\n")
306
+
307
+
308
+ @cli.command(cls=TrackCommand)
309
+ def version():
310
+ """
311
+ Show version information
312
+ """
313
+ from recce import __version__
314
+
315
+ print(__version__)
316
+
317
+
318
+ @cli.command(cls=TrackCommand)
319
+ @add_options(dbt_related_options)
320
+ @add_options(recce_dbt_artifact_dir_options)
321
+ def debug(**kwargs):
322
+ """
323
+ Diagnose and verify Recce setup for the development and the base environments
324
+ """
325
+
326
+ from rich.console import Console
327
+
328
+ from recce.adapter.dbt_adapter import DbtAdapter
329
+ from recce.core import load_context
330
+
331
+ console = Console()
332
+
333
+ def check_artifacts(env_name, target_path):
334
+ console.rule(f"{env_name} Environment", style="orange3")
335
+ if not target_path.is_dir():
336
+ console.print(f"[[red]MISS[/red]] Directory not found: {target_path}")
337
+ return [False, False, False]
338
+
339
+ console.print(f"[[green]OK[/green]] Directory exists: {target_path}")
340
+
341
+ manifest_path = target_path / "manifest.json"
342
+ manifest_is_ready = manifest_path.is_file()
343
+ if manifest_is_ready:
344
+ console.print(f"[[green]OK[/green]] Manifest JSON file exists : {manifest_path}")
345
+ else:
346
+ console.print(f"[[red]MISS[/red]] Manifest JSON file not found: {manifest_path}")
347
+
348
+ catalog_path = target_path / "catalog.json"
349
+ catalog_is_ready = catalog_path.is_file()
350
+ if catalog_is_ready:
351
+ console.print(f"[[green]OK[/green]] Catalog JSON file exists: {catalog_path}")
352
+ else:
353
+ console.print(f"[[red]MISS[/red]] Catalog JSON file not found: {catalog_path}")
354
+
355
+ return [True, manifest_is_ready, catalog_is_ready]
356
+
357
+ project_dir_path = Path(kwargs.get("project_dir") or "./")
358
+ target_path = project_dir_path.joinpath(Path(kwargs.get("target_path", "target")))
359
+ target_base_path = project_dir_path.joinpath(Path(kwargs.get("target_base_path", "target-base")))
360
+
361
+ curr_is_ready = check_artifacts("Development", target_path)
362
+ base_is_ready = check_artifacts("Base", target_base_path)
363
+
364
+ console.rule("Warehouse Connection", style="orange3")
365
+ conn_is_ready = True
366
+ try:
367
+ context_kwargs = {**kwargs, "target_base_path": kwargs.get("target_path")}
368
+ ctx = load_context(**context_kwargs)
369
+ dbt_adapter: DbtAdapter = ctx.adapter
370
+ sql = dbt_adapter.generate_sql("select 1", False)
371
+ dbt_adapter.execute(sql, fetch=True, auto_begin=True)
372
+ console.print("[[green]OK[/green]] Connection test")
373
+ except Exception:
374
+ conn_is_ready = False
375
+ console.print("[[red]FAIL[/red]] Connection test")
376
+
377
+ console.rule("Result", style="orange3")
378
+ if all(curr_is_ready) and all(base_is_ready) and conn_is_ready:
379
+ console.print("[[green]OK[/green]] Ready to launch! Type 'recce server'.")
380
+ elif all(curr_is_ready) and conn_is_ready:
381
+ console.print("[[orange3]OK[/orange3]] Ready to launch with [i]limited features[/i]. Type 'recce server'.")
382
+
383
+ if not curr_is_ready[0]:
384
+ console.print(
385
+ "[[orange3]TIP[/orange3]] Run dbt or overwrite the default directory of the development environment with '--target-path'."
386
+ )
387
+ else:
388
+ if not curr_is_ready[1]:
389
+ console.print(
390
+ "[[orange3]TIP[/orange3]] 'dbt run' to generate the manifest JSON file for the development environment."
391
+ )
392
+ if not curr_is_ready[2]:
393
+ console.print(
394
+ "[[orange3]TIP[/orange3]] 'dbt docs generate' to generate the catalog JSON file for the development environment."
395
+ )
396
+
397
+ if not base_is_ready[0]:
398
+ console.print(
399
+ "[[orange3]TIP[/orange3]] Run dbt with '--target-path target-base' or overwrite the default directory of the base environment with '--target-base-path'."
400
+ )
401
+ else:
402
+ if not base_is_ready[1]:
403
+ console.print(
404
+ "[[orange3]TIP[/orange3]] 'dbt run --target-path target-base' to generate the manifest JSON file for the base environment."
405
+ )
406
+ if not base_is_ready[2]:
407
+ console.print(
408
+ "[[orange3]TIP[/orange3]] 'dbt docs generate --target-path target-base' to generate the catalog JSON file for the base environment."
409
+ )
410
+
411
+ if not conn_is_ready:
412
+ console.print("[[orange3]TIP[/orange3]] Run 'dbt debug' to check the connection.")
413
+
414
+
415
+ @cli.command(hidden=True, cls=TrackCommand)
416
+ @click.option("--sql", help="Sql template to query", required=True)
417
+ @click.option("--base", is_flag=True, help="Run the query on the base environment")
418
+ @add_options(dbt_related_options)
419
+ def query(sql, base: bool = False, **kwargs):
420
+ """
421
+ Run a query on the current or base environment
422
+
423
+ Examples:\n
424
+
425
+ - run an adhoc query\n
426
+ recce query --sql 'select * from {{ ref("mymodel") }} order by 1'
427
+
428
+ - run an adhoc query on base environment\n
429
+ recce query --base --sql 'select * from {{ ref("mymodel") }} order by 1'
430
+ """
431
+ context = RecceContext.load(**kwargs)
432
+ result = _execute_sql(context, sql, base=base)
433
+ print(result.to_string(na_rep="-", index=False))
434
+
435
+
436
+ def _split_comma_separated(ctx, param, value):
437
+ return value.split(",") if value else None
438
+
439
+
440
+ @cli.command(hidden=True, cls=TrackCommand)
441
+ @click.option("--sql", help="Sql template to query.", required=True)
442
+ @click.option(
443
+ "--primary-keys",
444
+ type=click.STRING,
445
+ help="Comma-separated list of primary key columns.",
446
+ callback=_split_comma_separated,
447
+ )
448
+ @click.option("--keep-shape", is_flag=True, help="Keep unchanged columns. Otherwise, unchanged columns are hidden.")
449
+ @click.option(
450
+ "--keep-equal", is_flag=True, help='Keep values that are equal. Otherwise, equal values are shown as "-".'
451
+ )
452
+ @add_options(dbt_related_options)
453
+ def diff(sql, primary_keys: List[str] = None, keep_shape: bool = False, keep_equal: bool = False, **kwargs):
454
+ """
455
+ Run queries on base and current environments and diff the results
456
+
457
+ Examples:\n
458
+
459
+ - run adhoc queries and diff the results\n
460
+ recce diff --sql 'select * from {{ ref("mymodel") }} order by 1'
461
+ """
462
+
463
+ context = RecceContext.load(**kwargs)
464
+ before = _execute_sql(context, sql, base=True)
465
+ if primary_keys is not None:
466
+ before.set_index(primary_keys, inplace=True)
467
+ after = _execute_sql(context, sql, base=False)
468
+ if primary_keys is not None:
469
+ after.set_index(primary_keys, inplace=True)
470
+
471
+ before_aligned, after_aligned = before.align(after)
472
+ diff = before_aligned.compare(
473
+ after_aligned, result_names=("base", "current"), keep_equal=keep_equal, keep_shape=keep_shape
474
+ )
475
+ print(diff.to_string(na_rep="-") if not diff.empty else "no changes")
476
+
477
+
478
+ @cli.command(cls=TrackCommand)
479
+ @click.argument("state_file", required=False)
480
+ @click.option("--host", default="localhost", show_default=True, help="The host to bind to.")
481
+ @click.option("--port", default=8000, show_default=True, help="The port to bind to.", type=int)
482
+ @click.option("--lifetime", default=0, show_default=True, help="The lifetime of the server in seconds.", type=int)
483
+ @click.option(
484
+ "--idle-timeout",
485
+ default=0,
486
+ show_default=True,
487
+ help="The idle timeout in seconds. If 0, idle timeout is disabled. Maximum value is capped by lifetime.",
488
+ type=int,
489
+ )
490
+ @click.option("--review", is_flag=True, help="Open the state file in the review mode.")
491
+ @click.option("--single-env", is_flag=True, help="Launch in single environment mode directly.")
492
+ @add_options(dbt_related_options)
493
+ @add_options(sqlmesh_related_options)
494
+ @add_options(recce_options)
495
+ @add_options(recce_dbt_artifact_dir_options)
496
+ @add_options(recce_cloud_options)
497
+ @add_options(recce_cloud_auth_options)
498
+ @add_options(recce_hidden_options)
499
+ def server(host, port, lifetime, idle_timeout=0, state_file=None, **kwargs):
500
+ """
501
+ Launch the recce server
502
+
503
+ STATE_FILE is the path to the recce state file. Defaults=None, which will be no persistent state.
504
+
505
+ Examples:\n
506
+
507
+ \b
508
+ # Launch the recce server
509
+ recce server
510
+
511
+ \b
512
+ # Launch the recce server with a state file
513
+ recce server recce_state.json
514
+
515
+ \b
516
+ # Launch the server in the review mode
517
+ recce server --review recce_state.json
518
+
519
+ \b
520
+ # Launch the server using the state from the PR of your current branch. (Requires GitHub token)
521
+ export GITHUB_TOKEN=<your-github-token>
522
+ recce server --cloud
523
+ recce server --review --cloud
524
+
525
+ """
526
+
527
+ from rich.console import Console
528
+ from rich.prompt import Confirm
529
+
530
+ from .server import AppState, app
531
+
532
+ RecceConfig(config_file=kwargs.get("config"))
533
+
534
+ # Initialize startup performance tracking
535
+ from recce.util.startup_perf import StartupPerfTracker, set_startup_tracker
536
+
537
+ startup_tracker = StartupPerfTracker()
538
+ set_startup_tracker(startup_tracker)
539
+
540
+ handle_debug_flag(**kwargs)
541
+ patch_derived_args(kwargs)
542
+
543
+ server_mode = kwargs.get("mode") if kwargs.get("mode") else RecceServerMode.server
544
+ is_review = kwargs.get("review", False)
545
+ is_cloud = kwargs.get("cloud", False)
546
+ startup_tracker.set_cloud_mode(is_cloud)
547
+ flag = {
548
+ "single_env_onboarding": False,
549
+ "show_relaunch_hint": False,
550
+ "preview": False,
551
+ "read_only": False,
552
+ }
553
+ console = Console()
554
+
555
+ # Prepare API token
556
+ try:
557
+ api_token = prepare_api_token(**kwargs)
558
+ kwargs["api_token"] = api_token
559
+ except RecceConfigException:
560
+ show_invalid_api_token_message()
561
+ exit(1)
562
+ auth_options = {
563
+ "api_token": api_token,
564
+ }
565
+
566
+ # Check Single Environment Onboarding Mode if not in cloud mode and not in review mode
567
+ if not is_cloud and not is_review:
568
+ project_dir_path = Path(kwargs.get("project_dir") or "./")
569
+ target_base_path = project_dir_path.joinpath(Path(kwargs.get("target_base_path", "target-base")))
570
+ if not target_base_path.is_dir():
571
+ # Mark as single env onboarding mode if user provides the target-path only
572
+ flag["single_env_onboarding"] = True
573
+ flag["show_relaunch_hint"] = True
574
+ # Use the target path as the base path
575
+ kwargs["target_base_path"] = kwargs.get("target_path")
576
+
577
+ # Server mode:
578
+ #
579
+ # It's used to determine the features disabled in the Web UI. Only used in the cloud-managed recce instances.
580
+ #
581
+ # Read-Only: No run query, no checklist
582
+ # Preview (Metadata-Only): No run query
583
+ if server_mode == RecceServerMode.preview:
584
+ flag["preview"] = True
585
+ elif server_mode == RecceServerMode.read_only:
586
+ flag["read_only"] = True
587
+
588
+ # Onboarding State logic update here
589
+ update_onboarding_state(api_token, flag.get("single_env_onboarding"))
590
+
591
+ # Create state loader using shared function
592
+ from recce.util.startup_perf import get_startup_tracker
593
+
594
+ state_loader = create_state_loader_by_args(state_file, **kwargs)
595
+
596
+ if (tracker := get_startup_tracker()) and hasattr(state_loader, "catalog"):
597
+ tracker.set_catalog_type(state_loader.catalog)
598
+
599
+ if not state_loader.verify():
600
+ error, hint = state_loader.error_and_hint
601
+ console.print(f"[[red]Error[/red]] {error}")
602
+ console.print(f"{hint}")
603
+ exit(1)
604
+
605
+ try:
606
+ result, message = RecceContext.verify_required_artifacts(**kwargs)
607
+ except Exception as e:
608
+ result = False
609
+ error_type = type(e).__name__
610
+ error_message = str(e)
611
+ message = f"{error_type}: {error_message}"
612
+ if not result:
613
+ console.rule("Notice", style="orange3")
614
+ console.print(f"[[red]Error[/red]] {message}")
615
+ exit(1)
616
+
617
+ if state_loader.review_mode:
618
+ console.rule("Recce Server : Review Mode")
619
+ elif flag.get("single_env_onboarding"):
620
+ # Show warning message
621
+ console.rule("Notice", style="orange3")
622
+ console.print(
623
+ "Recce will launch with limited features (no environment comparison).\n"
624
+ "\n"
625
+ "For full functionality, set up a base environment first.\n"
626
+ "Setup help: 'recce debug' or https://docs.datarecce.io/configure-diff/\n"
627
+ )
628
+
629
+ single_env_flag = kwargs.get("single_env", False)
630
+ if not single_env_flag:
631
+ lanch_in_single_env = Confirm.ask("Continue to launch Recce?")
632
+ if not lanch_in_single_env:
633
+ exit(0)
634
+
635
+ console.rule("Recce Server : Limited Features")
636
+ else:
637
+ console.rule("Recce Server")
638
+
639
+ # Validate idle_timeout: cap at lifetime if it exceeds lifetime
640
+ if idle_timeout > 0:
641
+ # If lifetime is set (> 0) and idle_timeout exceeds it, cap to lifetime
642
+ if lifetime > 0 and idle_timeout > lifetime:
643
+ effective_idle_timeout = lifetime
644
+ console.print(
645
+ f"[[yellow]Warning[/yellow]] idle_timeout ({idle_timeout}s) exceeds lifetime ({lifetime}s). "
646
+ f"Capping idle_timeout to {effective_idle_timeout}s."
647
+ )
648
+ else:
649
+ # Use idle_timeout as-is (either lifetime is 0, or idle_timeout <= lifetime)
650
+ effective_idle_timeout = idle_timeout
651
+ else:
652
+ # idle_timeout is 0 or negative, disable idle timeout
653
+ effective_idle_timeout = 0
654
+
655
+ state = AppState(
656
+ command=server_mode,
657
+ state_loader=state_loader,
658
+ kwargs=kwargs,
659
+ flag=flag,
660
+ auth_options=auth_options,
661
+ lifetime=lifetime,
662
+ idle_timeout=effective_idle_timeout,
663
+ share_url=kwargs.get("share_url"),
664
+ organization_name=os.environ.get("RECCE_SESSION_ORGANIZATION_NAME"),
665
+ web_url=os.environ.get("RECCE_CLOUD_WEB_URL"),
666
+ )
667
+ app.state = state
668
+
669
+ if server_mode == RecceServerMode.read_only:
670
+ set_default_context(RecceContext.load(**kwargs, state_loader=state_loader))
671
+
672
+ uvicorn.run(app, host=host, port=port, lifespan="on")
673
+
674
+
675
+ DEFAULT_RECCE_STATE_FILE = "recce_state.json"
676
+
677
+
678
+ @cli.command(cls=TrackCommand)
679
+ @click.option(
680
+ "-o",
681
+ "--output",
682
+ help="Path of the output state file.",
683
+ type=click.Path(),
684
+ default=DEFAULT_RECCE_STATE_FILE,
685
+ show_default=True,
686
+ )
687
+ @click.option("--state-file", help="Path of the import state file.", type=click.Path())
688
+ @click.option("--summary", help="Path of the summary markdown file.", type=click.Path())
689
+ @click.option("--skip-query", is_flag=True, help="Skip running the queries for the checks.")
690
+ @click.option("--skip-check", is_flag=True, help="Skip running the checks.")
691
+ @click.option(
692
+ "--git-current-branch",
693
+ help="The git branch of the current environment.",
694
+ type=click.STRING,
695
+ envvar="GITHUB_HEAD_REF",
696
+ )
697
+ @click.option(
698
+ "--git-base-branch", help="The git branch of the base environment.", type=click.STRING, envvar="GITHUB_BASE_REF"
699
+ )
700
+ @click.option(
701
+ "--github-pull-request-url", help="The github pull request url to use for the lineage.", type=click.STRING
702
+ )
703
+ @add_options(dbt_related_options)
704
+ @add_options(sqlmesh_related_options)
705
+ @add_options(recce_options)
706
+ @add_options(recce_dbt_artifact_dir_options)
707
+ @add_options(recce_cloud_options)
708
+ @add_options(recce_cloud_auth_options)
709
+ @add_options(recce_hidden_options)
710
+ def run(output, **kwargs):
711
+ """
712
+ Run recce and output the state file
713
+
714
+ Examples:\n
715
+
716
+ \b
717
+ # Run recce and output to the default path [recce_state.json]
718
+ recce run
719
+
720
+ \b
721
+ # Run recce and output to the specified path
722
+ recce run -o my_recce_state.json
723
+
724
+ \b
725
+ # Run recce and output to the specified path
726
+ recce run --cloud --cloud-token <token> --password <password>
727
+
728
+ """
729
+ from rich.console import Console
730
+
731
+ handle_debug_flag(**kwargs)
732
+ console = Console()
733
+ is_github_action, pr_url = check_github_ci_env(**kwargs)
734
+ if is_github_action is True and pr_url is not None:
735
+ kwargs["github_pull_request_url"] = pr_url
736
+
737
+ # Initialize Recce Config
738
+ RecceConfig(config_file=kwargs.get("config"))
739
+
740
+ patch_derived_args(kwargs)
741
+ # Remove share_url from kwargs to avoid affecting state loader creation
742
+ kwargs.pop("share_url", None)
743
+
744
+ state_file = kwargs.pop("state_file", None)
745
+
746
+ # Prepare API token
747
+ try:
748
+ api_token = prepare_api_token(**kwargs)
749
+ kwargs["api_token"] = api_token
750
+ except RecceConfigException:
751
+ show_invalid_api_token_message()
752
+ exit(1)
753
+
754
+ # Create state loader using shared function
755
+ state_loader = create_state_loader_by_args(state_file, **kwargs)
756
+
757
+ if not state_loader.verify():
758
+ error, hint = state_loader.error_and_hint
759
+ console.print(f"[[red]Error[/red]] {error}")
760
+ console.print(f"{hint}")
761
+ exit(1)
762
+
763
+ result, message = RecceContext.verify_required_artifacts(**kwargs)
764
+ if not result:
765
+ console.print(f"[[red]Error[/red]] {message}")
766
+ exit(1)
767
+
768
+ # Verify the output state file path
769
+ try:
770
+ if os.path.isdir(output) or output.endswith("/"):
771
+
772
+ output_dir = Path(output)
773
+ # Create the directory if not exists
774
+ output_dir.mkdir(parents=True, exist_ok=True)
775
+ output = os.path.join(output, DEFAULT_RECCE_STATE_FILE)
776
+ console.print(
777
+ f"[[yellow]Warning[/yellow]] The path '{output_dir}' is a directory. "
778
+ f"The state file will be saved as '{output}'."
779
+ )
780
+ else:
781
+ # Create the parent directory if not exists
782
+ output_dir = Path(output).parent
783
+ output_dir.mkdir(parents=True, exist_ok=True)
784
+ except FileExistsError as e:
785
+ console.print(f"[[red]Error[/red]] Failed to access file path '{output}'.")
786
+ console.print(f"Reason: {e}")
787
+ exit(1)
788
+
789
+ return asyncio.run(cli_run(output, state_loader=state_loader, **kwargs))
790
+
791
+
792
+ @cli.command(cls=TrackCommand)
793
+ @click.argument("state_file", required=False)
794
+ @click.option(
795
+ "--format",
796
+ "-f",
797
+ help="Output format. Currently only markdown is supported.",
798
+ type=click.Choice(["markdown", "mermaid", "check"], case_sensitive=False),
799
+ default="markdown",
800
+ show_default=True,
801
+ hidden=True,
802
+ )
803
+ @add_options(dbt_related_options)
804
+ @add_options(recce_options)
805
+ @add_options(recce_cloud_options)
806
+ def summary(state_file, **kwargs):
807
+ """
808
+ Generate a summary of the recce state file
809
+ """
810
+ from rich.console import Console
811
+
812
+ from .core import load_context
813
+
814
+ handle_debug_flag(**kwargs)
815
+ console = Console()
816
+ cloud_mode = kwargs.get("cloud", False)
817
+ cloud_options = (
818
+ {
819
+ "host": kwargs.get("state_file_host"),
820
+ "github_token": kwargs.get("cloud_token"),
821
+ "password": kwargs.get("password"),
822
+ }
823
+ if cloud_mode
824
+ else None
825
+ )
826
+
827
+ state_loader = create_state_loader(
828
+ review_mode=True, cloud_mode=cloud_mode, state_file=state_file, cloud_options=cloud_options
829
+ )
830
+
831
+ if not state_loader.verify():
832
+ error, hint = state_loader.error_and_hint
833
+ console.print(f"[[red]Error[/red]] {error}")
834
+ console.print(f"{hint}")
835
+ exit(1)
836
+ try:
837
+ # Load context in review mode, won't need to check dbt_project.yml file.
838
+ ctx = load_context(**kwargs, state_loader=state_loader, review=True)
839
+ except Exception as e:
840
+ console.print("[[red]Error[/red]] Failed to generate summary")
841
+ console.print(f"{e}")
842
+ exit(1)
843
+
844
+ output = generate_markdown_summary(ctx, summary_format=kwargs.get("format"))
845
+ print(output)
846
+
847
+
848
+ @cli.command(cls=TrackCommand)
849
+ def connect_to_cloud():
850
+ """
851
+ Connect OSS to Cloud
852
+ """
853
+ import webbrowser
854
+
855
+ from rich.console import Console
856
+
857
+ console = Console()
858
+
859
+ # Prepare RSA keys for connecting to cloud
860
+ private_key, public_key = generate_key_pair()
861
+
862
+ connect_url, callback_port = prepare_connection_url(public_key)
863
+ console.rule("Connecting to Recce Cloud")
864
+ console.print("Attempting to automatically open the Recce Cloud authorization page in your default browser.")
865
+ console.print("If the browser does not open, please open the following URL:")
866
+ console.print(connect_url)
867
+ webbrowser.open(connect_url)
868
+
869
+ # Launch a callback HTTP server for fetching the api-token
870
+ run_one_time_http_server(private_key, port=callback_port)
871
+
872
+
873
+ @cli.group("cloud", short_help="Manage Recce Cloud state file.")
874
+ def cloud(**kwargs):
875
+ # Manage Recce Cloud.
876
+ pass
877
+
878
+
879
+ @cloud.command(cls=TrackCommand)
880
+ @click.option("--cloud-token", help="The GitHub token used by Recce Cloud.", type=click.STRING, envvar="GITHUB_TOKEN")
881
+ @click.option(
882
+ "--state-file-host",
883
+ help="The host to fetch the state file from.",
884
+ type=click.STRING,
885
+ envvar="RECCE_STATE_FILE_HOST",
886
+ default="",
887
+ hidden=True,
888
+ )
889
+ @click.option(
890
+ "--password",
891
+ "-p",
892
+ help="The password to encrypt the state file in cloud.",
893
+ type=click.STRING,
894
+ envvar="RECCE_STATE_PASSWORD",
895
+ )
896
+ @click.option("--force", "-f", help="Bypasses the confirmation prompt. Purge the state file directly.", is_flag=True)
897
+ @add_options(recce_options)
898
+ def purge(**kwargs):
899
+ """
900
+ Purge the state file from cloud
901
+ """
902
+ from rich.console import Console
903
+
904
+ handle_debug_flag(**kwargs)
905
+ console = Console()
906
+ state_loader = None
907
+ cloud_options = {
908
+ "host": kwargs.get("state_file_host"),
909
+ "github_token": kwargs.get("cloud_token"),
910
+ "password": kwargs.get("password"),
911
+ }
912
+ force_to_purge = kwargs.get("force", False)
913
+
914
+ try:
915
+ console.rule("Check Recce State from Cloud")
916
+ state_loader = create_state_loader(
917
+ review_mode=False, cloud_mode=True, state_file=None, cloud_options=cloud_options
918
+ )
919
+ except Exception:
920
+ console.print("[[yellow]Skip[/yellow]] Cannot access existing state file from cloud. Purge it directly.")
921
+
922
+ if state_loader is None:
923
+ try:
924
+ if force_to_purge is True or click.confirm("\nDo you want to purge the state file?"):
925
+ rc, err_msg = RecceCloudStateManager(cloud_options).purge_cloud_state()
926
+ if rc is True:
927
+ console.rule("Purged Successfully")
928
+ else:
929
+ console.rule("Failed to Purge", style="red")
930
+ console.print(f"Reason: {err_msg}")
931
+
932
+ except click.exceptions.Abort:
933
+ pass
934
+ return 0
935
+
936
+ info = state_loader.info()
937
+ if info is None:
938
+ console.print("[[yellow]Skip[/yellow]] No state file found in cloud.")
939
+ return 0
940
+
941
+ pr_info = info.get("pull_request")
942
+ console.print("[green]State File hosted by[/green]", info.get("source"))
943
+ console.print("[green]GitHub Repository[/green]", info.get("pull_request").repository)
944
+ console.print(f"[green]GitHub Pull Request[/green]\n{pr_info.title} #{pr_info.id}")
945
+ console.print(f"Branch merged into [blue]{pr_info.base_branch}[/blue] from [blue]{pr_info.branch}[/blue]")
946
+ console.print(pr_info.url)
947
+
948
+ try:
949
+ if force_to_purge is True or click.confirm("\nDo you want to purge the state file?"):
950
+ response = state_loader.purge()
951
+ if response is True:
952
+ console.rule("Purged Successfully")
953
+ else:
954
+ console.rule("Failed to Purge", style="red")
955
+ console.print(f"Reason: {state_loader.error_message}")
956
+ except click.exceptions.Abort:
957
+ pass
958
+
959
+ return 0
960
+
961
+
962
+ @cloud.command(cls=TrackCommand)
963
+ @click.argument("state_file", type=click.Path(exists=True))
964
+ @click.option("--cloud-token", help="The GitHub token used by Recce Cloud.", type=click.STRING, envvar="GITHUB_TOKEN")
965
+ @click.option(
966
+ "--state-file-host",
967
+ help="The host to fetch the state file from.",
968
+ type=click.STRING,
969
+ envvar="RECCE_STATE_FILE_HOST",
970
+ default="",
971
+ hidden=True,
972
+ )
973
+ @click.option(
974
+ "--password",
975
+ "-p",
976
+ help="The password to encrypt the state file in cloud.",
977
+ type=click.STRING,
978
+ envvar="RECCE_STATE_PASSWORD",
979
+ )
980
+ @add_options(recce_options)
981
+ def upload(state_file, **kwargs):
982
+ """
983
+ Upload the state file to cloud
984
+ """
985
+ from rich.console import Console
986
+
987
+ handle_debug_flag(**kwargs)
988
+ cloud_options = {
989
+ "host": kwargs.get("state_file_host"),
990
+ "github_token": kwargs.get("cloud_token"),
991
+ "password": kwargs.get("password"),
992
+ }
993
+
994
+ console = Console()
995
+
996
+ # load local state
997
+ state_loader = create_state_loader(
998
+ review_mode=False, cloud_mode=False, state_file=state_file, cloud_options=cloud_options
999
+ )
1000
+
1001
+ if not state_loader.verify():
1002
+ error, hint = state_loader.error_and_hint
1003
+ console.print(f"[[red]Error[/red]] {error}")
1004
+ console.print(f"{hint}")
1005
+ exit(1)
1006
+
1007
+ # check if state exists in cloud
1008
+ state_manager = RecceCloudStateManager(cloud_options)
1009
+ if not state_manager.verify():
1010
+ error, hint = state_manager.error_and_hint
1011
+ console.print(f"[[red]Error[/red]] {error}")
1012
+ console.print(f"{hint}")
1013
+ exit(1)
1014
+
1015
+ cloud_state_file_exists = state_manager.check_cloud_state_exists()
1016
+
1017
+ if cloud_state_file_exists and not click.confirm("\nDo you want to overwrite the existing state file?"):
1018
+ return 0
1019
+
1020
+ console.print(state_manager.upload_state_to_cloud(state_loader.state))
1021
+
1022
+
1023
+ @cloud.command(cls=TrackCommand)
1024
+ @click.option(
1025
+ "-o",
1026
+ "--output",
1027
+ help="Path of the downloaded state file.",
1028
+ type=click.STRING,
1029
+ default=DEFAULT_RECCE_STATE_FILE,
1030
+ show_default=True,
1031
+ )
1032
+ @click.option("--cloud-token", help="The GitHub token used by Recce Cloud.", type=click.STRING, envvar="GITHUB_TOKEN")
1033
+ @click.option(
1034
+ "--state-file-host",
1035
+ help="The host to fetch the state file from.",
1036
+ type=click.STRING,
1037
+ envvar="RECCE_STATE_FILE_HOST",
1038
+ default="",
1039
+ hidden=True,
1040
+ )
1041
+ @click.option(
1042
+ "--password",
1043
+ "-p",
1044
+ help="The password to encrypt the state file in cloud.",
1045
+ type=click.STRING,
1046
+ envvar="RECCE_STATE_PASSWORD",
1047
+ )
1048
+ @add_options(recce_options)
1049
+ def download(**kwargs):
1050
+ """
1051
+ Download the state file to cloud
1052
+ """
1053
+ from rich.console import Console
1054
+
1055
+ handle_debug_flag(**kwargs)
1056
+ filepath = kwargs.get("output")
1057
+ cloud_options = {
1058
+ "host": kwargs.get("state_file_host"),
1059
+ "github_token": kwargs.get("cloud_token"),
1060
+ "password": kwargs.get("password"),
1061
+ }
1062
+
1063
+ console = Console()
1064
+
1065
+ # check if state exists in cloud
1066
+ state_manager = RecceCloudStateManager(cloud_options)
1067
+ if not state_manager.verify():
1068
+ error, hint = state_manager.error_and_hint
1069
+ console.print(f"[[red]Error[/red]] {error}")
1070
+ console.print(f"{hint}")
1071
+ exit(1)
1072
+
1073
+ cloud_state_file_exists = state_manager.check_cloud_state_exists()
1074
+
1075
+ if not cloud_state_file_exists:
1076
+ console.print("[yellow]Skip[/yellow] No state file found in cloud.")
1077
+ return 0
1078
+
1079
+ state_manager.download_state_from_cloud(filepath)
1080
+ console.print(f'Downloaded state file to "{filepath}"')
1081
+
1082
+
1083
+ @cloud.command(cls=TrackCommand)
1084
+ @click.option("--cloud-token", help="The GitHub token used by Recce Cloud.", type=click.STRING, envvar="GITHUB_TOKEN")
1085
+ @click.option(
1086
+ "--branch",
1087
+ "-b",
1088
+ help="The branch of the provided artifacts.",
1089
+ type=click.STRING,
1090
+ envvar="GITHUB_HEAD_REF",
1091
+ default=current_branch(),
1092
+ show_default=True,
1093
+ )
1094
+ @click.option(
1095
+ "--target-path",
1096
+ help="dbt artifacts directory for your artifacts.",
1097
+ type=click.STRING,
1098
+ default="target",
1099
+ show_default=True,
1100
+ )
1101
+ @click.option(
1102
+ "--password",
1103
+ "-p",
1104
+ help="The password to encrypt the dbt artifacts in cloud.",
1105
+ type=click.STRING,
1106
+ envvar="RECCE_STATE_PASSWORD",
1107
+ required=True,
1108
+ )
1109
+ @add_options(recce_options)
1110
+ def upload_artifacts(**kwargs):
1111
+ """
1112
+ Upload the dbt artifacts to cloud
1113
+
1114
+ Upload the dbt artifacts (metadata.json, catalog.json) to Recce Cloud for the given branch.
1115
+ The password is used to encrypt the dbt artifacts in the cloud. You will need the password to download the dbt artifacts.
1116
+
1117
+ By default, the artifacts are uploaded to the current branch. You can specify the branch using the --branch option.
1118
+ The target path is set to 'target' by default. You can specify the target path using the --target-path option.
1119
+ """
1120
+ from rich.console import Console
1121
+
1122
+ console = Console()
1123
+ cloud_token = kwargs.get("cloud_token")
1124
+ password = kwargs.get("password")
1125
+ target_path = kwargs.get("target_path")
1126
+ branch = kwargs.get("branch")
1127
+
1128
+ try:
1129
+ rc = upload_dbt_artifacts(
1130
+ target_path, branch=branch, token=cloud_token, password=password, debug=kwargs.get("debug", False)
1131
+ )
1132
+ console.rule("Uploaded Successfully")
1133
+ console.print(
1134
+ f'Uploaded dbt artifacts to Recce Cloud for branch "{branch}" from "{os.path.abspath(target_path)}"'
1135
+ )
1136
+ except Exception as e:
1137
+ console.rule("Failed to Upload", style="red")
1138
+ console.print("[[red]Error[/red]] Failed to upload the dbt artifacts to cloud.")
1139
+ console.print(f"Reason: {e}")
1140
+ rc = 1
1141
+ return rc
1142
+
1143
+
1144
+ def _download_artifacts(branch, cloud_token, console, kwargs, password, target_path):
1145
+ try:
1146
+ rc = download_dbt_artifacts(
1147
+ target_path,
1148
+ branch=branch,
1149
+ token=cloud_token,
1150
+ password=password,
1151
+ force=kwargs.get("force", False),
1152
+ debug=kwargs.get("debug", False),
1153
+ )
1154
+ console.rule("Downloaded Successfully")
1155
+ console.print(
1156
+ f'Downloaded dbt artifacts from Recce Cloud for branch "{branch}" to "{os.path.abspath(target_path)}"'
1157
+ )
1158
+ except Exception as e:
1159
+ console.rule("Failed to Download", style="red")
1160
+ console.print("[[red]Error[/red]] Failed to download the dbt artifacts from cloud.")
1161
+ reason = str(e)
1162
+
1163
+ if (
1164
+ "Requests specifying Server Side Encryption with Customer provided keys must provide the correct secret key"
1165
+ in reason
1166
+ ):
1167
+ console.print("Reason: Decryption failed due to incorrect password.")
1168
+ console.print(
1169
+ "Please provide the correct password to decrypt the dbt artifacts. Or re-upload the dbt artifacts with a new password."
1170
+ )
1171
+ elif "The specified key does not exist" in reason:
1172
+ console.print("Reason: The dbt artifacts is not found in the cloud.")
1173
+ console.print("Please upload the dbt artifacts to the cloud before downloading it.")
1174
+ else:
1175
+ console.print(f"Reason: {reason}")
1176
+ rc = 1
1177
+ return rc
1178
+
1179
+
1180
+ @cloud.command(cls=TrackCommand)
1181
+ @click.option("--cloud-token", help="The GitHub token used by Recce Cloud.", type=click.STRING, envvar="GITHUB_TOKEN")
1182
+ @click.option(
1183
+ "--branch",
1184
+ "-b",
1185
+ help="The branch of the selected artifacts.",
1186
+ type=click.STRING,
1187
+ envvar="GITHUB_BASE_REF",
1188
+ default=current_branch(),
1189
+ show_default=True,
1190
+ )
1191
+ @click.option(
1192
+ "--target-path",
1193
+ help="The dbt artifacts directory for your artifacts.",
1194
+ type=click.STRING,
1195
+ default="target",
1196
+ show_default=True,
1197
+ )
1198
+ @click.option(
1199
+ "--password",
1200
+ "-p",
1201
+ help="The password to decrypt the dbt artifacts in cloud.",
1202
+ type=click.STRING,
1203
+ envvar="RECCE_STATE_PASSWORD",
1204
+ required=True,
1205
+ )
1206
+ @click.option("--force", "-f", help="Bypasses the confirmation prompt. Download the artifacts directly.", is_flag=True)
1207
+ @add_options(recce_options)
1208
+ def download_artifacts(**kwargs):
1209
+ """
1210
+ Download the dbt artifacts from cloud
1211
+
1212
+ Download the dbt artifacts (metadata.json, catalog.json) from Recce Cloud for the given branch.
1213
+ The password is used to decrypt the dbt artifacts in the cloud.
1214
+
1215
+ By default, the artifacts are downloaded from the current branch. You can specify the branch using the --branch option.
1216
+ The target path is set to 'target' by default. You can specify the target path using the --target-path option.
1217
+ """
1218
+ from rich.console import Console
1219
+
1220
+ console = Console()
1221
+ cloud_token = kwargs.get("cloud_token")
1222
+ password = kwargs.get("password")
1223
+ target_path = kwargs.get("target_path")
1224
+ branch = kwargs.get("branch")
1225
+ return _download_artifacts(branch, cloud_token, console, kwargs, password, target_path)
1226
+
1227
+
1228
+ @cloud.command(cls=TrackCommand)
1229
+ @click.option("--cloud-token", help="The GitHub token used by Recce Cloud.", type=click.STRING, envvar="GITHUB_TOKEN")
1230
+ @click.option(
1231
+ "--branch",
1232
+ "-b",
1233
+ help="The branch of the selected artifacts.",
1234
+ type=click.STRING,
1235
+ envvar="GITHUB_BASE_REF",
1236
+ default=current_default_branch(),
1237
+ show_default=True,
1238
+ )
1239
+ @click.option(
1240
+ "--target-path",
1241
+ help="The dbt artifacts directory for your artifacts.",
1242
+ type=click.STRING,
1243
+ default="target-base",
1244
+ show_default=True,
1245
+ )
1246
+ @click.option(
1247
+ "--password",
1248
+ "-p",
1249
+ help="The password to decrypt the dbt artifacts in cloud.",
1250
+ type=click.STRING,
1251
+ envvar="RECCE_STATE_PASSWORD",
1252
+ required=True,
1253
+ )
1254
+ @click.option("--force", "-f", help="Bypasses the confirmation prompt. Download the artifacts directly.", is_flag=True)
1255
+ @add_options(recce_options)
1256
+ def download_base_artifacts(**kwargs):
1257
+ """
1258
+ Download the base dbt artifacts from cloud
1259
+
1260
+ Download the base dbt artifacts (metadata.json, catalog.json) from Recce Cloud.
1261
+ This is useful when you start to set up the base dbt artifacts for the first time.
1262
+
1263
+ Please make sure you have uploaded the dbt artifacts before downloading them.
1264
+ """
1265
+ from rich.console import Console
1266
+
1267
+ console = Console()
1268
+ cloud_token = kwargs.get("cloud_token")
1269
+ password = kwargs.get("password")
1270
+ target_path = kwargs.get("target_path")
1271
+ branch = kwargs.get("branch")
1272
+ # If recce can't infer default branch from "GITHUB_BASE_REF" and current_default_branch()
1273
+ if branch is None:
1274
+ console.print(
1275
+ "[[red]Error[/red]] Please provide your base branch name with '--branch' to download the base " "artifacts."
1276
+ )
1277
+ exit(1)
1278
+
1279
+ return _download_artifacts(branch, cloud_token, console, kwargs, password, target_path)
1280
+
1281
+
1282
+ @cloud.command(cls=TrackCommand)
1283
+ @click.option("--cloud-token", help="The GitHub token used by Recce Cloud.", type=click.STRING, envvar="GITHUB_TOKEN")
1284
+ @click.option(
1285
+ "--branch",
1286
+ "-b",
1287
+ help="The branch to delete artifacts from.",
1288
+ type=click.STRING,
1289
+ envvar="GITHUB_HEAD_REF",
1290
+ default=current_branch(),
1291
+ show_default=True,
1292
+ )
1293
+ @click.option("--force", "-f", help="Bypasses the confirmation prompt. Delete the artifacts directly.", is_flag=True)
1294
+ @add_options(recce_options)
1295
+ def delete_artifacts(**kwargs):
1296
+ """
1297
+ Delete the dbt artifacts from cloud
1298
+
1299
+ Delete the dbt artifacts (metadata.json, catalog.json) from Recce Cloud for the given branch.
1300
+ This will permanently remove the artifacts from the cloud storage.
1301
+
1302
+ By default, the artifacts are deleted from the current branch. You can specify the branch using the --branch option.
1303
+ """
1304
+ from rich.console import Console
1305
+
1306
+ console = Console()
1307
+ cloud_token = kwargs.get("cloud_token")
1308
+ branch = kwargs.get("branch")
1309
+ force = kwargs.get("force", False)
1310
+
1311
+ if not force:
1312
+ if not click.confirm(f'Do you want to delete artifacts from branch "{branch}"?'):
1313
+ console.print("Deletion cancelled.")
1314
+ return 0
1315
+
1316
+ try:
1317
+ delete_dbt_artifacts(branch=branch, token=cloud_token, debug=kwargs.get("debug", False))
1318
+ console.print(f"[[green]Success[/green]] Artifacts deleted from branch: {branch}")
1319
+ return 0
1320
+ except click.exceptions.Abort:
1321
+ pass
1322
+ except RecceCloudException as e:
1323
+ console.print("[[red]Error[/red]] Failed to delete the dbt artifacts from cloud.")
1324
+ console.print(f"Reason: {e.reason}")
1325
+ exit(1)
1326
+ except Exception as e:
1327
+ console.print("[[red]Error[/red]] Failed to delete the dbt artifacts from cloud.")
1328
+ console.print(f"Reason: {e}")
1329
+ exit(1)
1330
+
1331
+
1332
+ @cloud.command(cls=TrackCommand, name="list-organizations")
1333
+ @click.option("--api-token", help="The Recce Cloud API token.", type=click.STRING, envvar="RECCE_API_TOKEN")
1334
+ @add_options(recce_options)
1335
+ def list_organizations(**kwargs):
1336
+ """
1337
+ List organizations from Recce Cloud
1338
+
1339
+ Lists all organizations that the authenticated user has access to.
1340
+ """
1341
+ from rich.console import Console
1342
+ from rich.table import Table
1343
+
1344
+ console = Console()
1345
+ handle_debug_flag(**kwargs)
1346
+
1347
+ try:
1348
+ api_token = prepare_api_token(**kwargs)
1349
+ except RecceConfigException:
1350
+ show_invalid_api_token_message()
1351
+ exit(1)
1352
+
1353
+ try:
1354
+ from recce.util.recce_cloud import RecceCloud
1355
+
1356
+ cloud = RecceCloud(api_token)
1357
+ organizations = cloud.list_organizations()
1358
+
1359
+ if not organizations:
1360
+ console.print("No organizations found.")
1361
+ return
1362
+
1363
+ table = Table(title="Organizations")
1364
+ table.add_column("ID", style="cyan")
1365
+ table.add_column("Name", style="green")
1366
+ table.add_column("Display Name", style="yellow")
1367
+
1368
+ for org in organizations:
1369
+ table.add_row(str(org.get("id", "")), org.get("name", ""), org.get("display_name", ""))
1370
+
1371
+ console.print(table)
1372
+
1373
+ except RecceCloudException as e:
1374
+ console.print(f"[[red]Error[/red]] {e}")
1375
+ exit(1)
1376
+ except Exception as e:
1377
+ console.print(f"[[red]Error[/red]] {e}")
1378
+ exit(1)
1379
+
1380
+
1381
+ @cloud.command(cls=TrackCommand, name="list-projects")
1382
+ @click.option(
1383
+ "--organization",
1384
+ "-o",
1385
+ help="Organization ID (can also be set via RECCE_ORGANIZATION_ID environment variable)",
1386
+ type=click.STRING,
1387
+ envvar="RECCE_ORGANIZATION_ID",
1388
+ )
1389
+ @click.option("--api-token", help="The Recce Cloud API token.", type=click.STRING, envvar="RECCE_API_TOKEN")
1390
+ @add_options(recce_options)
1391
+ def list_projects(**kwargs):
1392
+ """
1393
+ List projects from Recce Cloud
1394
+
1395
+ Lists all projects in the specified organization that the authenticated user has access to.
1396
+
1397
+ Examples:
1398
+
1399
+ # Using environment variable
1400
+ export RECCE_ORGANIZATION_ID=8
1401
+ recce cloud list-projects
1402
+
1403
+ # Using command line argument
1404
+ recce cloud list-projects --organization 8
1405
+
1406
+ # Override environment variable
1407
+ export RECCE_ORGANIZATION_ID=8
1408
+ recce cloud list-projects --organization 10
1409
+ """
1410
+ from rich.console import Console
1411
+ from rich.table import Table
1412
+
1413
+ console = Console()
1414
+ handle_debug_flag(**kwargs)
1415
+
1416
+ try:
1417
+ api_token = prepare_api_token(**kwargs)
1418
+ except RecceConfigException:
1419
+ show_invalid_api_token_message()
1420
+ exit(1)
1421
+
1422
+ organization = kwargs.get("organization")
1423
+ if not organization:
1424
+ console.print("[[red]Error[/red]] Organization ID is required. Please provide it via:")
1425
+ console.print(" --organization <id> or set RECCE_ORGANIZATION_ID environment variable")
1426
+ exit(1)
1427
+
1428
+ try:
1429
+ from recce.util.recce_cloud import RecceCloud
1430
+
1431
+ cloud = RecceCloud(api_token)
1432
+ projects = cloud.list_projects(organization)
1433
+
1434
+ if not projects:
1435
+ console.print(f"No projects found in organization {organization}.")
1436
+ return
1437
+
1438
+ table = Table(title=f"Projects in Organization {organization}")
1439
+ table.add_column("ID", style="cyan")
1440
+ table.add_column("Name", style="green")
1441
+ table.add_column("Display Name", style="yellow")
1442
+
1443
+ for project in projects:
1444
+ table.add_row(str(project.get("id", "")), project.get("name", ""), project.get("display_name", ""))
1445
+
1446
+ console.print(table)
1447
+
1448
+ except RecceCloudException as e:
1449
+ console.print(f"[[red]Error[/red]] {e}")
1450
+ exit(1)
1451
+ except Exception as e:
1452
+ console.print(f"[[red]Error[/red]] {e}")
1453
+ exit(1)
1454
+
1455
+
1456
+ @cloud.command(cls=TrackCommand, name="list-sessions")
1457
+ @click.option(
1458
+ "--organization",
1459
+ "-o",
1460
+ help="Organization ID (can also be set via RECCE_ORGANIZATION_ID environment variable)",
1461
+ type=click.STRING,
1462
+ envvar="RECCE_ORGANIZATION_ID",
1463
+ )
1464
+ @click.option(
1465
+ "--project",
1466
+ "-p",
1467
+ help="Project ID (can also be set via RECCE_PROJECT_ID environment variable)",
1468
+ type=click.STRING,
1469
+ envvar="RECCE_PROJECT_ID",
1470
+ )
1471
+ @click.option("--api-token", help="The Recce Cloud API token.", type=click.STRING, envvar="RECCE_API_TOKEN")
1472
+ @add_options(recce_options)
1473
+ def list_sessions(**kwargs):
1474
+ """
1475
+ List sessions from Recce Cloud
1476
+
1477
+ Lists all sessions in the specified project that the authenticated user has access to.
1478
+
1479
+ Examples:
1480
+
1481
+ # Using environment variables
1482
+ export RECCE_ORGANIZATION_ID=8
1483
+ export RECCE_PROJECT_ID=7
1484
+ recce cloud list-sessions
1485
+
1486
+ # Using command line arguments
1487
+ recce cloud list-sessions --organization 8 --project 7
1488
+
1489
+ # Mixed usage (env + CLI override)
1490
+ export RECCE_ORGANIZATION_ID=8
1491
+ recce cloud list-sessions --project 7
1492
+
1493
+ # Override environment variables
1494
+ export RECCE_ORGANIZATION_ID=8
1495
+ export RECCE_PROJECT_ID=7
1496
+ recce cloud list-sessions --organization 10 --project 9
1497
+ """
1498
+ from rich.console import Console
1499
+ from rich.table import Table
1500
+
1501
+ console = Console()
1502
+ handle_debug_flag(**kwargs)
1503
+
1504
+ try:
1505
+ api_token = prepare_api_token(**kwargs)
1506
+ except RecceConfigException:
1507
+ show_invalid_api_token_message()
1508
+ exit(1)
1509
+
1510
+ organization = kwargs.get("organization")
1511
+ project = kwargs.get("project")
1512
+
1513
+ # Validate required parameters
1514
+ if not organization:
1515
+ console.print("[[red]Error[/red]] Organization ID is required. Please provide it via:")
1516
+ console.print(" --organization <id> or set RECCE_ORGANIZATION_ID environment variable")
1517
+ exit(1)
1518
+
1519
+ if not project:
1520
+ console.print("[[red]Error[/red]] Project ID is required. Please provide it via:")
1521
+ console.print(" --project <id> or set RECCE_PROJECT_ID environment variable")
1522
+ exit(1)
1523
+
1524
+ try:
1525
+ from recce.util.recce_cloud import RecceCloud
1526
+
1527
+ cloud = RecceCloud(api_token)
1528
+ sessions = cloud.list_sessions(organization, project)
1529
+
1530
+ if not sessions:
1531
+ console.print(f"No sessions found in project {project}.")
1532
+ return
1533
+
1534
+ table = Table(title=f"Sessions in Project {project}")
1535
+ table.add_column("ID", style="cyan")
1536
+ table.add_column("Name", style="green")
1537
+ table.add_column("Is Base", style="yellow")
1538
+
1539
+ for session in sessions:
1540
+ is_base = "✓" if session.get("is_base", False) else ""
1541
+ table.add_row(session.get("id", ""), session.get("name", ""), is_base)
1542
+
1543
+ console.print(table)
1544
+
1545
+ except RecceCloudException as e:
1546
+ console.print(f"[[red]Error[/red]] {e}")
1547
+ exit(1)
1548
+ except Exception as e:
1549
+ console.print(f"[[red]Error[/red]] {e}")
1550
+ exit(1)
1551
+
1552
+
1553
+ @cli.group("github", short_help="GitHub related commands", hidden=True)
1554
+ def github(**kwargs):
1555
+ pass
1556
+
1557
+
1558
+ @github.command(
1559
+ cls=TrackCommand, short_help="Download the artifacts from the GitHub repository based on the current Pull Request."
1560
+ )
1561
+ @click.option(
1562
+ "--github-token",
1563
+ help="The github token to use for accessing GitHub repo.",
1564
+ type=click.STRING,
1565
+ envvar="GITHUB_TOKEN",
1566
+ )
1567
+ @click.option(
1568
+ "--github-repo",
1569
+ help="The github repo to use for accessing GitHub repo.",
1570
+ type=click.STRING,
1571
+ envvar="GITHUB_REPOSITORY",
1572
+ )
1573
+ def artifact(**kwargs):
1574
+ from recce.github import recce_ci_artifact
1575
+
1576
+ return recce_ci_artifact(**kwargs)
1577
+
1578
+
1579
+ @cli.command(cls=TrackCommand)
1580
+ @click.argument("state_file", type=click.Path(exists=True))
1581
+ @click.option(
1582
+ "--api-token",
1583
+ help="The personal token generated by Recce Cloud.",
1584
+ type=click.STRING,
1585
+ envvar="RECCE_API_TOKEN",
1586
+ )
1587
+ def share(state_file, **kwargs):
1588
+ """
1589
+ Share the state file
1590
+ """
1591
+ from rich.console import Console
1592
+
1593
+ console = Console()
1594
+ handle_debug_flag(**kwargs)
1595
+ cloud_options = None
1596
+
1597
+ # read or input the api token
1598
+ try:
1599
+ api_token = prepare_api_token(interaction=True, **kwargs)
1600
+ except Abort:
1601
+ console.print("[yellow]Abort[/yellow]")
1602
+ exit(0)
1603
+ except RecceConfigException:
1604
+ show_invalid_api_token_message()
1605
+ exit(1)
1606
+
1607
+ auth_options = {"api_token": api_token}
1608
+
1609
+ # load local state
1610
+ state_loader = create_state_loader(
1611
+ review_mode=True, cloud_mode=False, state_file=state_file, cloud_options=cloud_options
1612
+ )
1613
+
1614
+ if not state_loader.verify():
1615
+ error, hint = state_loader.error_and_hint
1616
+ console.print(f"[[red]Error[/red]] {error}")
1617
+ console.print(f"{hint}")
1618
+ exit(1)
1619
+
1620
+ # check if state exists in cloud
1621
+ state_manager = RecceShareStateManager(auth_options)
1622
+ if not state_manager.verify():
1623
+ error, hint = state_manager.error_and_hint
1624
+ console.print(f"[[red]Error[/red]] {error}")
1625
+ console.print(f"{hint}")
1626
+ exit(1)
1627
+
1628
+ # check if state exists in cloud
1629
+ state_file_name = os.path.basename(state_file)
1630
+
1631
+ try:
1632
+ response = state_manager.share_state(state_file_name, state_loader.state)
1633
+ if response.get("status") == "error":
1634
+ console.print("[[red]Error[/red]] Failed to share the state.\n" f"Reason: {response.get('message')}")
1635
+ else:
1636
+ console.print(f"Shared Link: {response.get('share_url')}")
1637
+ except RecceCloudException as e:
1638
+ console.print(f"[[red]Error[/red]] {e}")
1639
+ console.print(f"Reason: {e.reason}")
1640
+ exit(1)
1641
+
1642
+
1643
+ snapshot_id_option = click.option(
1644
+ "--snapshot-id",
1645
+ help="The snapshot ID to upload artifacts to cloud.",
1646
+ type=click.STRING,
1647
+ envvar=["RECCE_SNAPSHOT_ID", "RECCE_SESSION_ID"],
1648
+ required=True,
1649
+ )
1650
+
1651
+ session_id_option = click.option(
1652
+ "--session-id",
1653
+ help="The session ID to upload artifacts to cloud.",
1654
+ type=click.STRING,
1655
+ envvar=["RECCE_SESSION_ID", "RECCE_SNAPSHOT_ID"],
1656
+ required=True,
1657
+ )
1658
+
1659
+ target_path_option = click.option(
1660
+ "--target-path",
1661
+ help="dbt artifacts directory for your artifacts.",
1662
+ type=click.STRING,
1663
+ default="target",
1664
+ show_default=True,
1665
+ )
1666
+
1667
+
1668
+ @cli.command(cls=TrackCommand, hidden=True)
1669
+ @add_options([session_id_option, target_path_option])
1670
+ @add_options(recce_cloud_auth_options)
1671
+ @add_options(recce_options)
1672
+ def upload_session(**kwargs):
1673
+ """
1674
+ Upload target/manifest.json and target/catalog.json to the specific session ID
1675
+
1676
+ Upload the dbt artifacts (manifest.json, catalog.json) to Recce Cloud for the given session ID.
1677
+ This allows you to associate artifacts with a specific session for later use.
1678
+
1679
+ Examples:\n
1680
+
1681
+ \b
1682
+ # Upload artifacts to a session ID
1683
+ recce upload-session --session-id <session-id>
1684
+
1685
+ \b
1686
+ # Upload artifacts from custom target path to a session ID
1687
+ recce upload-session --session-id <session-id> --target-path my-target
1688
+ """
1689
+ from rich.console import Console
1690
+
1691
+ console = Console()
1692
+ handle_debug_flag(**kwargs)
1693
+
1694
+ # Initialize Recce Config
1695
+ RecceConfig(config_file=kwargs.get("config"))
1696
+
1697
+ try:
1698
+ api_token = prepare_api_token(**kwargs)
1699
+ except RecceConfigException:
1700
+ show_invalid_api_token_message()
1701
+ exit(1)
1702
+
1703
+ session_id = kwargs.get("session_id")
1704
+ target_path = kwargs.get("target_path")
1705
+
1706
+ try:
1707
+ rc = upload_artifacts_to_session(
1708
+ target_path, session_id=session_id, token=api_token, debug=kwargs.get("debug", False)
1709
+ )
1710
+ console.rule("Uploaded Successfully")
1711
+ console.print(
1712
+ f'Uploaded dbt artifacts to Recce Cloud for session ID "{session_id}" from "{os.path.abspath(target_path)}"'
1713
+ )
1714
+ except Exception as e:
1715
+ console.rule("Failed to Upload Session", style="red")
1716
+ console.print(f"[[red]Error[/red]] Failed to upload the dbt artifacts to the session {session_id}.")
1717
+ console.print(f"Reason: {e}")
1718
+ rc = 1
1719
+ return rc
1720
+
1721
+
1722
+ # Backward compatibility for `recce snapshot` command
1723
+ @cli.command(
1724
+ cls=TrackCommand,
1725
+ hidden=True,
1726
+ deprecated=True,
1727
+ help="Upload target/manifest.json and target/catalog.json to the specific snapshot ID",
1728
+ )
1729
+ @add_options([snapshot_id_option, target_path_option])
1730
+ @add_options(recce_cloud_auth_options)
1731
+ @add_options(recce_options)
1732
+ def snapshot(**kwargs):
1733
+ kwargs["session_id"] = kwargs.get("snapshot_id")
1734
+ return upload_session(**kwargs)
1735
+
1736
+
1737
+ @cli.command(hidden=True, cls=TrackCommand)
1738
+ @click.argument("state_file", required=True)
1739
+ @click.option("--host", default="localhost", show_default=True, help="The host to bind to.")
1740
+ @click.option("--port", default=8000, show_default=True, help="The port to bind to.", type=int)
1741
+ @click.option("--lifetime", default=0, show_default=True, help="The lifetime of the server in seconds.", type=int)
1742
+ @click.option("--share-url", help="The share URL triggers this instance.", type=click.STRING, envvar="RECCE_SHARE_URL")
1743
+ @click.pass_context
1744
+ def read_only(ctx, state_file=None, **kwargs):
1745
+ # Invoke `recce server --mode read-only <state_file> ...
1746
+ kwargs["mode"] = RecceServerMode.read_only
1747
+ ctx.invoke(server, state_file=state_file, **kwargs)
1748
+
1749
+
1750
+ @cli.command(cls=TrackCommand)
1751
+ @click.argument("state_file", required=False)
1752
+ @click.option("--sse", is_flag=True, default=False, help="Start in HTTP/SSE mode instead of stdio mode")
1753
+ @click.option("--host", default="localhost", help="Host to bind to in SSE mode (default: localhost)")
1754
+ @click.option("--port", default=8000, type=int, help="Port to bind to in SSE mode (default: 8000)")
1755
+ @add_options(dbt_related_options)
1756
+ @add_options(sqlmesh_related_options)
1757
+ @add_options(recce_options)
1758
+ @add_options(recce_dbt_artifact_dir_options)
1759
+ @add_options(recce_cloud_options)
1760
+ @add_options(recce_cloud_auth_options)
1761
+ @add_options(recce_hidden_options)
1762
+ def mcp_server(state_file, sse, host, port, **kwargs):
1763
+ """
1764
+ Start the Recce MCP (Model Context Protocol) server
1765
+
1766
+ The MCP server provides an interface for AI assistants and tools to interact
1767
+ with Recce's data validation capabilities. By default, it uses stdio for
1768
+ communication. Use --sse to enable HTTP/Server-Sent Events mode instead.
1769
+
1770
+ STATE_FILE is the path to the recce state file (optional).
1771
+
1772
+ Examples:\n
1773
+
1774
+ \b
1775
+ # Start the MCP server in stdio mode (default)
1776
+ recce mcp-server
1777
+
1778
+ \b
1779
+ # Start with a state file
1780
+ recce mcp-server recce_state.json
1781
+
1782
+ \b
1783
+ # Start in HTTP/SSE mode on default port 8000
1784
+ recce mcp-server --sse
1785
+
1786
+ \b
1787
+ # Start in HTTP/SSE mode with custom host and port
1788
+ recce mcp-server --sse --host 0.0.0.0 --port 9000
1789
+
1790
+ SSE Connection URL (when using --sse): http://<host>:<port>/sse
1791
+ """
1792
+ from rich.console import Console
1793
+
1794
+ console = Console()
1795
+ try:
1796
+ # Import here to avoid import errors if mcp is not installed
1797
+ from recce.mcp_server import run_mcp_server
1798
+ except ImportError as e:
1799
+ console.print(f"[[red]Error[/red]] Failed to import MCP server: {e}")
1800
+ console.print(r"Please install the MCP package: pip install 'recce\[mcp]'")
1801
+ exit(1)
1802
+
1803
+ # Initialize Recce Config
1804
+ RecceConfig(config_file=kwargs.get("config"))
1805
+
1806
+ handle_debug_flag(**kwargs)
1807
+ patch_derived_args(kwargs)
1808
+
1809
+ # Prepare API token
1810
+ try:
1811
+ api_token = prepare_api_token(**kwargs)
1812
+ kwargs["api_token"] = api_token
1813
+ except RecceConfigException:
1814
+ show_invalid_api_token_message()
1815
+ exit(1)
1816
+
1817
+ # Create state loader using shared function (for cloud mode or when state_file is provided)
1818
+ is_cloud = kwargs.get("cloud", False)
1819
+ if is_cloud or state_file:
1820
+ state_loader = create_state_loader_by_args(state_file, **kwargs)
1821
+ kwargs["state_loader"] = state_loader
1822
+
1823
+ try:
1824
+ if sse:
1825
+ console.print(f"Starting Recce MCP Server in HTTP/SSE mode on {host}:{port}...")
1826
+ console.print(f"SSE endpoint: http://{host}:{port}/sse")
1827
+ else:
1828
+ console.print("Starting Recce MCP Server in stdio mode...")
1829
+
1830
+ # Run the server (stdio or SSE based on --sse flag)
1831
+ asyncio.run(run_mcp_server(sse=sse, host=host, port=port, **kwargs))
1832
+ except (asyncio.CancelledError, KeyboardInterrupt):
1833
+ # Graceful shutdown (e.g., Ctrl+C)
1834
+ console.print("[yellow]MCP Server interrupted[/yellow]")
1835
+ exit(0)
1836
+ except Exception as e:
1837
+ console.print(f"[[red]Error[/red]] Failed to start MCP server: {e}")
1838
+ if kwargs.get("debug"):
1839
+ import traceback
1840
+
1841
+ traceback.print_exc()
1842
+ exit(1)
1843
+
1844
+
1845
+ if __name__ == "__main__":
1846
+ cli()