kiri-cli 1.0.0b3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kiri-cli might be problematic. Click here for more details.

Files changed (743) hide show
  1. kiri_adapters/__init__.py +193 -0
  2. kiri_adapters/backends/__init__.py +0 -0
  3. kiri_adapters/backends/databricks.manifest.yml +55 -0
  4. kiri_adapters/backends/databricks.py +2980 -0
  5. kiri_adapters/backends/fabric_dw.manifest.yml +17 -0
  6. kiri_adapters/backends/fabric_dw.py +307 -0
  7. kiri_adapters/backends/fabric_lakehouse.manifest.yml +19 -0
  8. kiri_adapters/backends/fabric_lakehouse.py +365 -0
  9. kiri_adapters/backends/iceberg.manifest.yml +17 -0
  10. kiri_adapters/backends/iceberg.py +451 -0
  11. kiri_adapters/backends/localduckdb.manifest.yml +43 -0
  12. kiri_adapters/backends/localduckdb.py +1295 -0
  13. kiri_adapters/backends/mssql.manifest.yml +17 -0
  14. kiri_adapters/backends/mssql.py +366 -0
  15. kiri_adapters/backends/postgres.manifest.yml +17 -0
  16. kiri_adapters/backends/postgres.py +434 -0
  17. kiri_adapters/backends/trino.manifest.yml +17 -0
  18. kiri_adapters/backends/trino.py +542 -0
  19. kiri_adapters/base.py +892 -0
  20. kiri_adapters/doctor_checks.py +81 -0
  21. kiri_adapters/dv_planner.py +1205 -0
  22. kiri_adapters/dv_planner_bridge.py +265 -0
  23. kiri_adapters/dv_planner_pit.py +265 -0
  24. kiri_adapters/dv_planner_ref.py +403 -0
  25. kiri_adapters/dv_planner_sat_variants.py +668 -0
  26. kiri_adapters/framework.py +112 -0
  27. kiri_adapters/incident/__init__.py +30 -0
  28. kiri_adapters/incident/_http.py +121 -0
  29. kiri_adapters/incident/base.py +89 -0
  30. kiri_adapters/incident/jira.py +365 -0
  31. kiri_adapters/incident/servicenow.py +314 -0
  32. kiri_adapters/incident/zendesk.py +285 -0
  33. kiri_adapters/manifest.py +466 -0
  34. kiri_adapters/orchestration/__init__.py +30 -0
  35. kiri_adapters/orchestration/airflow.py +117 -0
  36. kiri_adapters/orchestration/artifact_emitter.py +99 -0
  37. kiri_adapters/orchestration/autoloader_emitter.py +141 -0
  38. kiri_adapters/orchestration/azure_data_factory.py +137 -0
  39. kiri_adapters/orchestration/base.py +626 -0
  40. kiri_adapters/orchestration/databricks_workflows.py +1768 -0
  41. kiri_adapters/orchestration/k8s_cron.py +555 -0
  42. kiri_adapters/orchestration/lifecycle.py +222 -0
  43. kiri_adapters/orchestration/pipeline_compat.py +145 -0
  44. kiri_adapters/orchestration/runtime_python.py +188 -0
  45. kiri_adapters/paths.py +38 -0
  46. kiri_adapters/protocols/__init__.py +64 -0
  47. kiri_adapters/protocols/ai_service/__init__.py +7 -0
  48. kiri_adapters/protocols/ai_service/conformance.py +120 -0
  49. kiri_adapters/protocols/base.py +220 -0
  50. kiri_adapters/protocols/catalog/__init__.py +7 -0
  51. kiri_adapters/protocols/catalog/conformance.py +138 -0
  52. kiri_adapters/protocols/framework/__init__.py +7 -0
  53. kiri_adapters/protocols/framework/conformance.py +98 -0
  54. kiri_adapters/protocols/incident/__init__.py +7 -0
  55. kiri_adapters/protocols/incident/conformance.py +64 -0
  56. kiri_adapters/protocols/orchestration/__init__.py +7 -0
  57. kiri_adapters/protocols/orchestration/conformance.py +84 -0
  58. kiri_adapters/protocols/platform/__init__.py +7 -0
  59. kiri_adapters/protocols/platform/conformance.py +120 -0
  60. kiri_adapters/protocols/sql_dialect/__init__.py +7 -0
  61. kiri_adapters/protocols/sql_dialect/conformance.py +91 -0
  62. kiri_adapters/protocols/vault/__init__.py +7 -0
  63. kiri_adapters/protocols/vault/conformance.py +65 -0
  64. kiri_adapters/py.typed +0 -0
  65. kiri_adapters/registry.py +104 -0
  66. kiri_adapters/semantic/__init__.py +60 -0
  67. kiri_adapters/semantic/apply.py +274 -0
  68. kiri_adapters/semantic/base.py +530 -0
  69. kiri_adapters/semantic/cube.py +280 -0
  70. kiri_adapters/semantic/dbt_semantic.py +92 -0
  71. kiri_adapters/semantic/metric_views.py +249 -0
  72. kiri_adapters/semantic/metricflow.py +345 -0
  73. kiri_adapters/semantic/snowflake_views.py +75 -0
  74. kiri_adapters/sql_dialect.py +1592 -0
  75. kiri_adapters/tsql_to_spark.py +653 -0
  76. kiri_ai_gateway/__init__.py +147 -0
  77. kiri_ai_gateway/audit.py +334 -0
  78. kiri_ai_gateway/batch.py +293 -0
  79. kiri_ai_gateway/config.py +165 -0
  80. kiri_ai_gateway/gateway.py +642 -0
  81. kiri_ai_gateway/placeholder_guard.py +145 -0
  82. kiri_ai_gateway/prices/__init__.py +77 -0
  83. kiri_ai_gateway/prices/prices.yaml +64 -0
  84. kiri_ai_gateway/prompts/__init__.py +54 -0
  85. kiri_ai_gateway/prompts/airbyte_source_setup.yaml +212 -0
  86. kiri_ai_gateway/prompts/bdv_translation.yaml +90 -0
  87. kiri_ai_gateway/prompts/contract_draft_mvp.yaml +117 -0
  88. kiri_ai_gateway/prompts/describe_table.yaml +19 -0
  89. kiri_ai_gateway/prompts/design_gold_from_question.yaml +130 -0
  90. kiri_ai_gateway/prompts/detect_pii.yaml +59 -0
  91. kiri_ai_gateway/prompts/discover_classify_column.yaml +69 -0
  92. kiri_ai_gateway/prompts/discover_describe_table.yaml +61 -0
  93. kiri_ai_gateway/prompts/dv_quality_summary.yaml +36 -0
  94. kiri_ai_gateway/prompts/incident_assist.yaml +58 -0
  95. kiri_ai_gateway/prompts/infer_source_schema.yaml +31 -0
  96. kiri_ai_gateway/prompts/ingest_backend_chooser.yaml +116 -0
  97. kiri_ai_gateway/prompts/interactive_source_edit.yaml +94 -0
  98. kiri_ai_gateway/prompts/map_needed_entity_to_source.yaml +72 -0
  99. kiri_ai_gateway/prompts/meet_kiri.yaml +127 -0
  100. kiri_ai_gateway/prompts/native_source_setup.yaml +211 -0
  101. kiri_ai_gateway/prompts/source_grouping_reason.yaml +29 -0
  102. kiri_ai_gateway/prompts/suggest_attribute_classification.yaml +42 -0
  103. kiri_ai_gateway/prompts/suggest_data_tests.yaml +71 -0
  104. kiri_ai_gateway/prompts/suggest_gold_dimension.yaml +108 -0
  105. kiri_ai_gateway/prompts/suggest_gold_fact.yaml +107 -0
  106. kiri_ai_gateway/prompts/suggest_gold_model.yaml +70 -0
  107. kiri_ai_gateway/prompts/suggest_semantic_intent.yaml +91 -0
  108. kiri_ai_gateway/prompts/suggest_silver_model.yaml +140 -0
  109. kiri_ai_gateway/providers/__init__.py +7 -0
  110. kiri_ai_gateway/providers/anthropic_provider.py +26 -0
  111. kiri_ai_gateway/providers/gateway_provider.py +188 -0
  112. kiri_ai_gateway/providers/local_provider.py +177 -0
  113. kiri_ai_gateway/py.typed +0 -0
  114. kiri_ai_gateway/service.py +283 -0
  115. kiri_ai_gateway/transport.py +103 -0
  116. kiri_ai_gateway/transports/__init__.py +12 -0
  117. kiri_ai_gateway/transports/anthropic_transport.py +73 -0
  118. kiri_ai_gateway/transports/ollama_transport.py +82 -0
  119. kiri_ai_gateway/transports/openai_compatible_transport.py +125 -0
  120. kiri_ai_gateway/workspace_policy.py +52 -0
  121. kiri_catalog/__init__.py +199 -0
  122. kiri_catalog/annotation_plan.py +183 -0
  123. kiri_catalog/appearances.py +155 -0
  124. kiri_catalog/backends/__init__.py +79 -0
  125. kiri_catalog/backends/base.py +167 -0
  126. kiri_catalog/backends/memory.py +241 -0
  127. kiri_catalog/backends/postgres.py +497 -0
  128. kiri_catalog/backends/redacting.py +195 -0
  129. kiri_catalog/backends/sqlite.py +480 -0
  130. kiri_catalog/context.py +94 -0
  131. kiri_catalog/federation/__init__.py +114 -0
  132. kiri_catalog/federation/api.py +200 -0
  133. kiri_catalog/federation/cache.py +149 -0
  134. kiri_catalog/federation/emit.py +209 -0
  135. kiri_catalog/federation/fs_resolver.py +295 -0
  136. kiri_catalog/federation/http_resolver.py +486 -0
  137. kiri_catalog/federation/metrics.py +123 -0
  138. kiri_catalog/federation/release.py +342 -0
  139. kiri_catalog/federation/resolver.py +332 -0
  140. kiri_catalog/federation/schema.py +460 -0
  141. kiri_catalog/importer.py +668 -0
  142. kiri_catalog/lineage_drift.py +280 -0
  143. kiri_catalog/lineage_graph.py +176 -0
  144. kiri_catalog/lineage_graph_explain.py +96 -0
  145. kiri_catalog/lineage_graph_mermaid.py +230 -0
  146. kiri_catalog/observed_uc_lineage.py +216 -0
  147. kiri_catalog/pii_detect.py +176 -0
  148. kiri_catalog/push.py +122 -0
  149. kiri_catalog/py.typed +0 -0
  150. kiri_catalog/redact.py +101 -0
  151. kiri_catalog/review_actions.py +119 -0
  152. kiri_catalog/schema/__init__.py +70 -0
  153. kiri_catalog/schema/asset.py +142 -0
  154. kiri_catalog/schema/column.py +247 -0
  155. kiri_catalog/schema/enums.py +195 -0
  156. kiri_catalog/schema/job.py +51 -0
  157. kiri_catalog/schema/lineage.py +33 -0
  158. kiri_catalog/schema/policy.py +69 -0
  159. kiri_catalog/schema/primitives.py +90 -0
  160. kiri_catalog/schema/review_state.py +111 -0
  161. kiri_catalog/schema/urn.py +45 -0
  162. kiri_catalog/schema_discovery.py +160 -0
  163. kiri_catalog/sinks/__init__.py +64 -0
  164. kiri_catalog/sinks/base.py +178 -0
  165. kiri_catalog/sinks/horizon.py +195 -0
  166. kiri_catalog/sinks/purview.py +216 -0
  167. kiri_catalog/sinks/unity.py +352 -0
  168. kiri_catalog/sinks/unity_executor.py +543 -0
  169. kiri_catalog/sources/__init__.py +42 -0
  170. kiri_catalog/sources/base.py +104 -0
  171. kiri_catalog/sources/unity.py +465 -0
  172. kiri_catalog/steward_writeback.py +158 -0
  173. kiri_catalog/tag_sql.py +99 -0
  174. kiri_cli/LICENSE +105 -0
  175. kiri_cli/__init__.py +1 -0
  176. kiri_cli/_apply_cli.py +63 -0
  177. kiri_cli/_apply_reporter.py +38 -0
  178. kiri_cli/_closed_menu.py +36 -0
  179. kiri_cli/_fixture_option.py +18 -0
  180. kiri_cli/_layer_detect.py +158 -0
  181. kiri_cli/_project_option.py +79 -0
  182. kiri_cli/adapter_cmd.py +192 -0
  183. kiri_cli/ai_batch_cmd.py +258 -0
  184. kiri_cli/ai_cmd.py +352 -0
  185. kiri_cli/approve_cmd.py +659 -0
  186. kiri_cli/attr_cmd.py +575 -0
  187. kiri_cli/audit_cmd.py +348 -0
  188. kiri_cli/audit_correlate_cmd.py +648 -0
  189. kiri_cli/audit_join.py +437 -0
  190. kiri_cli/audit_join_cmd.py +160 -0
  191. kiri_cli/auto_cmd.py +97 -0
  192. kiri_cli/azure_cmd.py +243 -0
  193. kiri_cli/catalog.py +1293 -0
  194. kiri_cli/cli_reference_live.py +147 -0
  195. kiri_cli/compile_cmd.py +493 -0
  196. kiri_cli/compliance_cmd.py +221 -0
  197. kiri_cli/contract_approval_cmd.py +94 -0
  198. kiri_cli/contract_cmd.py +64 -0
  199. kiri_cli/contract_codeowners_cmd.py +162 -0
  200. kiri_cli/contract_diff.py +111 -0
  201. kiri_cli/contract_emit.py +90 -0
  202. kiri_cli/contract_export.py +192 -0
  203. kiri_cli/contract_lint.py +1505 -0
  204. kiri_cli/contract_merge_cmd.py +264 -0
  205. kiri_cli/contract_new.py +326 -0
  206. kiri_cli/contract_promote.py +216 -0
  207. kiri_cli/contract_scaffold_cmd.py +134 -0
  208. kiri_cli/contract_schema_export.py +69 -0
  209. kiri_cli/contract_show.py +150 -0
  210. kiri_cli/contract_stubs.py +60 -0
  211. kiri_cli/contract_sync_from_live.py +327 -0
  212. kiri_cli/contract_validate.py +154 -0
  213. kiri_cli/contract_verify_live.py +242 -0
  214. kiri_cli/cost_cmd.py +243 -0
  215. kiri_cli/databricks_health.py +1254 -0
  216. kiri_cli/databricks_setup_cmd.py +712 -0
  217. kiri_cli/discover_cmd.py +600 -0
  218. kiri_cli/docs_cmd.py +35 -0
  219. kiri_cli/doctor_cmd.py +145 -0
  220. kiri_cli/dv_cmd.py +814 -0
  221. kiri_cli/dv_conformance_cmd.py +154 -0
  222. kiri_cli/dv_install.py +493 -0
  223. kiri_cli/dv_migrate_cmd.py +183 -0
  224. kiri_cli/dv_test_cmd.py +175 -0
  225. kiri_cli/federation_cmd.py +315 -0
  226. kiri_cli/fk_cmd.py +160 -0
  227. kiri_cli/flows_cmd.py +910 -0
  228. kiri_cli/governance_cmd.py +358 -0
  229. kiri_cli/incident_api_cmd.py +180 -0
  230. kiri_cli/incident_cmd.py +410 -0
  231. kiri_cli/incident_setup_cmd.py +239 -0
  232. kiri_cli/ingest.py +427 -0
  233. kiri_cli/ingest_discover.py +480 -0
  234. kiri_cli/ingest_new_source.py +386 -0
  235. kiri_cli/intent_cmd.py +122 -0
  236. kiri_cli/invariants_cmd.py +118 -0
  237. kiri_cli/kiri_banner.py +161 -0
  238. kiri_cli/kpi_cmd.py +222 -0
  239. kiri_cli/layer_cmd.py +464 -0
  240. kiri_cli/lineage.py +601 -0
  241. kiri_cli/main.py +2472 -0
  242. kiri_cli/maturity_cmd.py +222 -0
  243. kiri_cli/migrate_cmd.py +1347 -0
  244. kiri_cli/onboard_cmd.py +223 -0
  245. kiri_cli/pack_cmd.py +496 -0
  246. kiri_cli/pipeline_cmd.py +127 -0
  247. kiri_cli/pre_classify_cmd.py +274 -0
  248. kiri_cli/project_cmd.py +592 -0
  249. kiri_cli/py.typed +0 -0
  250. kiri_cli/quality_cmd.py +295 -0
  251. kiri_cli/rbac.py +139 -0
  252. kiri_cli/rbac_cmd.py +291 -0
  253. kiri_cli/release.py +850 -0
  254. kiri_cli/release_semver.py +265 -0
  255. kiri_cli/repo_cmd.py +155 -0
  256. kiri_cli/retention_cmd.py +333 -0
  257. kiri_cli/sample_data/__init__.py +12 -0
  258. kiri_cli/sample_data/customers.contract.yml +47 -0
  259. kiri_cli/sample_data/customers.csv +25 -0
  260. kiri_cli/scaffold_cmd.py +721 -0
  261. kiri_cli/schema_cmd.py +185 -0
  262. kiri_cli/semantic_cmd.py +605 -0
  263. kiri_cli/silver_cmd.py +348 -0
  264. kiri_cli/skills_cmd.py +243 -0
  265. kiri_cli/skills_data/README.md +51 -0
  266. kiri_cli/skills_data/add-source/SKILL.md +116 -0
  267. kiri_cli/skills_data/azure-deploy/SKILL.md +261 -0
  268. kiri_cli/skills_data/azure-status/SKILL.md +111 -0
  269. kiri_cli/skills_data/compliance-check/SKILL.md +99 -0
  270. kiri_cli/skills_data/databricks-build-pipeline/SKILL.md +112 -0
  271. kiri_cli/skills_data/databricks-project-setup/SKILL.md +157 -0
  272. kiri_cli/skills_data/debug-apply/SKILL.md +186 -0
  273. kiri_cli/skills_data/draft-gold-model/SKILL.md +203 -0
  274. kiri_cli/skills_data/explain-kpi/SKILL.md +158 -0
  275. kiri_cli/skills_data/incident-coach/SKILL.md +135 -0
  276. kiri_cli/skills_data/incident-setup/SKILL.md +112 -0
  277. kiri_cli/skills_data/maturity-coach/SKILL.md +120 -0
  278. kiri_cli/skills_data/promote-contract/SKILL.md +91 -0
  279. kiri_cli/skills_data/review-attributes/SKILL.md +94 -0
  280. kiri_cli/sla_cmd.py +769 -0
  281. kiri_cli/source_cmd.py +909 -0
  282. kiri_cli/templates/__init__.py +6 -0
  283. kiri_cli/templates/dv4dbt_packages.yml.j2 +11 -0
  284. kiri_cli/upgrade_cmd.py +896 -0
  285. kiri_cli/use_cmd.py +120 -0
  286. kiri_cli/vault_cmd.py +241 -0
  287. kiri_cli/verify_generated.py +241 -0
  288. kiri_cli-1.0.0b3.dist-info/METADATA +212 -0
  289. kiri_cli-1.0.0b3.dist-info/RECORD +743 -0
  290. kiri_cli-1.0.0b3.dist-info/WHEEL +4 -0
  291. kiri_cli-1.0.0b3.dist-info/entry_points.txt +4 -0
  292. kiri_compliance/__init__.py +33 -0
  293. kiri_compliance/audit_coverage.py +354 -0
  294. kiri_compliance/controls.py +763 -0
  295. kiri_compliance/evidence.py +155 -0
  296. kiri_compliance/py.typed +0 -0
  297. kiri_compliance/quality_engine.py +246 -0
  298. kiri_compliance/renderer.py +195 -0
  299. kiri_compliance/report.py +44 -0
  300. kiri_compliance/schema.py +129 -0
  301. kiri_core/__init__.py +185 -0
  302. kiri_core/adapter_surfaces.py +149 -0
  303. kiri_core/ai_query_gate/__init__.py +92 -0
  304. kiri_core/ai_query_gate/audit.py +153 -0
  305. kiri_core/ai_query_gate/evaluator.py +484 -0
  306. kiri_core/ai_query_gate/models.py +162 -0
  307. kiri_core/ai_query_gate/parser.py +436 -0
  308. kiri_core/ai_query_gate/resolver.py +274 -0
  309. kiri_core/ai_query_gate/store.py +234 -0
  310. kiri_core/ai_query_gate/store_postgres.py +409 -0
  311. kiri_core/api_keys.py +243 -0
  312. kiri_core/apply/__init__.py +27 -0
  313. kiri_core/apply/conformance.py +99 -0
  314. kiri_core/apply/incident_router.py +176 -0
  315. kiri_core/apply/models.py +140 -0
  316. kiri_core/apply/reporter.py +46 -0
  317. kiri_core/apply/runner.py +3083 -0
  318. kiri_core/apply_log_store.py +155 -0
  319. kiri_core/approval_flow/__init__.py +133 -0
  320. kiri_core/approval_flow/integration.py +156 -0
  321. kiri_core/approval_flow/models.py +443 -0
  322. kiri_core/approval_flow/notifier.py +263 -0
  323. kiri_core/approval_flow/orchestrator.py +660 -0
  324. kiri_core/approval_flow/reconcile_signoff.py +53 -0
  325. kiri_core/approval_flow/store.py +220 -0
  326. kiri_core/approval_flow/store_jsonl.py +217 -0
  327. kiri_core/approval_flow/store_postgres.py +580 -0
  328. kiri_core/approval_policy.py +116 -0
  329. kiri_core/asgi_trace.py +160 -0
  330. kiri_core/compliance.py +802 -0
  331. kiri_core/cutover_approval.py +187 -0
  332. kiri_core/discovery/__init__.py +109 -0
  333. kiri_core/discovery/ai/__init__.py +37 -0
  334. kiri_core/discovery/ai/_payload.py +115 -0
  335. kiri_core/discovery/ai/budget.py +83 -0
  336. kiri_core/discovery/ai/classify.py +223 -0
  337. kiri_core/discovery/ai/describe.py +200 -0
  338. kiri_core/discovery/ai/errors.py +49 -0
  339. kiri_core/discovery/discover.py +648 -0
  340. kiri_core/discovery/heuristics/__init__.py +42 -0
  341. kiri_core/discovery/heuristics/classification.py +174 -0
  342. kiri_core/discovery/heuristics/medallion.py +157 -0
  343. kiri_core/discovery/heuristics/pii.py +92 -0
  344. kiri_core/discovery/introspector.py +636 -0
  345. kiri_core/discovery/introspector_databricks.py +396 -0
  346. kiri_core/discovery/introspector_postgres.py +394 -0
  347. kiri_core/discovery/introspector_snowflake.py +383 -0
  348. kiri_core/discovery/reporting/__init__.py +17 -0
  349. kiri_core/discovery/reporting/discovery_report.py +190 -0
  350. kiri_core/discovery/scaffold/__init__.py +41 -0
  351. kiri_core/discovery/scaffold/contract_writer.py +632 -0
  352. kiri_core/discovery/scaffold/provenance_overlay.py +143 -0
  353. kiri_core/discovery/scaffold/source_writer.py +211 -0
  354. kiri_core/discovery/scaffold/todo_marker.py +98 -0
  355. kiri_core/domain_policy.py +122 -0
  356. kiri_core/goal_coverage.py +82 -0
  357. kiri_core/gold_registry.py +211 -0
  358. kiri_core/health.py +192 -0
  359. kiri_core/incident.py +204 -0
  360. kiri_core/incident_builders.py +256 -0
  361. kiri_core/incident_log.py +418 -0
  362. kiri_core/intent/__init__.py +46 -0
  363. kiri_core/intent/agent_runner.py +82 -0
  364. kiri_core/intent/project_dv.py +261 -0
  365. kiri_core/intent/propose.py +132 -0
  366. kiri_core/intent/semantic_intent.py +446 -0
  367. kiri_core/invariants.py +301 -0
  368. kiri_core/kpi.py +373 -0
  369. kiri_core/latency.py +150 -0
  370. kiri_core/lifecycle/__init__.py +555 -0
  371. kiri_core/lifecycle/ai_index.py +453 -0
  372. kiri_core/lifecycle/auto_mode.py +172 -0
  373. kiri_core/lifecycle/bootstrap.py +316 -0
  374. kiri_core/lifecycle/cli_reference.py +1064 -0
  375. kiri_core/lifecycle/commit.py +258 -0
  376. kiri_core/lifecycle/compile_dispatch.py +296 -0
  377. kiri_core/lifecycle/compile_range.py +665 -0
  378. kiri_core/lifecycle/contract_inventory.py +354 -0
  379. kiri_core/lifecycle/contracts.py +250 -0
  380. kiri_core/lifecycle/doctor.py +412 -0
  381. kiri_core/lifecycle/git_remote.py +948 -0
  382. kiri_core/lifecycle/identity.py +147 -0
  383. kiri_core/lifecycle/ingestion_modes.py +215 -0
  384. kiri_core/lifecycle/layer_contract.py +452 -0
  385. kiri_core/lifecycle/layer_contract_migrate.py +969 -0
  386. kiri_core/lifecycle/layer_contract_parser.py +436 -0
  387. kiri_core/lifecycle/layer_contract_validator.py +2291 -0
  388. kiri_core/lifecycle/layout.py +298 -0
  389. kiri_core/lifecycle/onboarding.py +306 -0
  390. kiri_core/lifecycle/openlineage_emit.py +153 -0
  391. kiri_core/lifecycle/patch.py +231 -0
  392. kiri_core/lifecycle/plan.py +241 -0
  393. kiri_core/lifecycle/probe.py +204 -0
  394. kiri_core/lifecycle/project_context.py +334 -0
  395. kiri_core/lifecycle/project_status.py +532 -0
  396. kiri_core/lifecycle/scaffold.py +455 -0
  397. kiri_core/lifecycle/source_grouping.py +725 -0
  398. kiri_core/lifecycle/source_introspection.py +488 -0
  399. kiri_core/lifecycle/source_inventory.py +561 -0
  400. kiri_core/lifecycle/source_patch.py +353 -0
  401. kiri_core/lifecycle/sources.py +470 -0
  402. kiri_core/lifecycle/sync_from_live.py +727 -0
  403. kiri_core/lifecycle/validate.py +116 -0
  404. kiri_core/lifecycle/verify_annotations.py +391 -0
  405. kiri_core/lifecycle/verify_live.py +389 -0
  406. kiri_core/lifecycle/verify_metric_views.py +321 -0
  407. kiri_core/lifecycle/watermark.py +371 -0
  408. kiri_core/lifecycle/watermark_apply.py +656 -0
  409. kiri_core/lineage.py +418 -0
  410. kiri_core/loader.py +377 -0
  411. kiri_core/logging.py +374 -0
  412. kiri_core/maturity.py +592 -0
  413. kiri_core/migration_layer_policy.py +285 -0
  414. kiri_core/names.py +163 -0
  415. kiri_core/observed_lineage.py +62 -0
  416. kiri_core/odcs/__init__.py +15 -0
  417. kiri_core/otel_bootstrap.py +326 -0
  418. kiri_core/pipeline_ir.py +332 -0
  419. kiri_core/pipeline_loader.py +82 -0
  420. kiri_core/planning.py +110 -0
  421. kiri_core/project.py +1576 -0
  422. kiri_core/project_docs.py +199 -0
  423. kiri_core/py.typed +0 -0
  424. kiri_core/rate_limit.py +456 -0
  425. kiri_core/release_state/__init__.py +37 -0
  426. kiri_core/release_state/models.py +108 -0
  427. kiri_core/release_state/store.py +634 -0
  428. kiri_core/resilience/__init__.py +288 -0
  429. kiri_core/resilience/retry.py +173 -0
  430. kiri_core/runtime.py +40 -0
  431. kiri_core/schema/__init__.py +62 -0
  432. kiri_core/schema/column.py +140 -0
  433. kiri_core/schema/ingestion.py +665 -0
  434. kiri_core/schema/model.py +44 -0
  435. kiri_core/schema/reporting_goal.py +160 -0
  436. kiri_core/schema/source.py +188 -0
  437. kiri_core/silver/__init__.py +148 -0
  438. kiri_core/silver/apply_runner.py +830 -0
  439. kiri_core/silver/backfill.py +280 -0
  440. kiri_core/silver/dv_backend.py +426 -0
  441. kiri_core/silver/dv_graph.py +932 -0
  442. kiri_core/silver/dv_graph_mermaid.py +443 -0
  443. kiri_core/silver/dv_graph_payload.py +79 -0
  444. kiri_core/silver/dv_graph_views.py +416 -0
  445. kiri_core/silver/graph_projector.py +566 -0
  446. kiri_core/silver/hash_canonicaliser.py +172 -0
  447. kiri_core/silver/hash_policy.py +195 -0
  448. kiri_core/silver/load_ts_policy.py +202 -0
  449. kiri_core/silver/schema_evolution.py +410 -0
  450. kiri_core/silver/zone_rules.py +81 -0
  451. kiri_core/sizing.py +134 -0
  452. kiri_core/storage_paths.py +130 -0
  453. kiri_core/technique_validator.py +700 -0
  454. kiri_core/trace.py +409 -0
  455. kiri_core/types.py +41 -0
  456. kiri_core/urn.py +161 -0
  457. kiri_dbt_bridge/__init__.py +22 -0
  458. kiri_dbt_bridge/_schema_resolve.py +38 -0
  459. kiri_dbt_bridge/bridge.py +94 -0
  460. kiri_dbt_bridge/dbt.manifest.yml +26 -0
  461. kiri_dbt_bridge/dv4dbt/__init__.py +143 -0
  462. kiri_dbt_bridge/dv4dbt/backend.py +204 -0
  463. kiri_dbt_bridge/dv4dbt/bridge_generator.py +289 -0
  464. kiri_dbt_bridge/dv4dbt/compat.py +232 -0
  465. kiri_dbt_bridge/dv4dbt/hub_generator.py +282 -0
  466. kiri_dbt_bridge/dv4dbt/link_generator.py +306 -0
  467. kiri_dbt_bridge/dv4dbt/manifest.py +203 -0
  468. kiri_dbt_bridge/dv4dbt/pit_generator.py +318 -0
  469. kiri_dbt_bridge/dv4dbt/policy_translation.py +249 -0
  470. kiri_dbt_bridge/dv4dbt/project_writer.py +588 -0
  471. kiri_dbt_bridge/dv4dbt/ref_generator.py +404 -0
  472. kiri_dbt_bridge/dv4dbt/render.py +180 -0
  473. kiri_dbt_bridge/dv4dbt/sat_generator.py +480 -0
  474. kiri_dbt_bridge/dv4dbt/sat_variant_generator.py +529 -0
  475. kiri_dbt_bridge/dv4dbt/templates/__init__.py +16 -0
  476. kiri_dbt_bridge/dv4dbt/templates/bridge.sql.j2 +9 -0
  477. kiri_dbt_bridge/dv4dbt/templates/dbt_project.yml.j2 +37 -0
  478. kiri_dbt_bridge/dv4dbt/templates/hub.sql.j2 +9 -0
  479. kiri_dbt_bridge/dv4dbt/templates/link.sql.j2 +9 -0
  480. kiri_dbt_bridge/dv4dbt/templates/packages.yml.j2 +10 -0
  481. kiri_dbt_bridge/dv4dbt/templates/pit.sql.j2 +9 -0
  482. kiri_dbt_bridge/dv4dbt/templates/ref_historised.sql.j2 +9 -0
  483. kiri_dbt_bridge/dv4dbt/templates/ref_non_historised.sql.j2 +9 -0
  484. kiri_dbt_bridge/dv4dbt/templates/sat.sql.j2 +9 -0
  485. kiri_dbt_bridge/dv4dbt/templates/sat_effectivity.sql.j2 +9 -0
  486. kiri_dbt_bridge/dv4dbt/templates/sat_multi_active.sql.j2 +9 -0
  487. kiri_dbt_bridge/dv4dbt/templates/sat_non_historised.sql.j2 +9 -0
  488. kiri_dbt_bridge/dv4dbt/templates/sat_record_tracking.sql.j2 +9 -0
  489. kiri_dbt_bridge/dv4dbt/templates/sat_virtual_end_dated.sql.j2 +9 -0
  490. kiri_dbt_bridge/dv4dbt/templates/sources.yml.j2 +39 -0
  491. kiri_dbt_bridge/framework_adapter.py +310 -0
  492. kiri_dbt_bridge/generate.py +372 -0
  493. kiri_dbt_bridge/gold/__init__.py +21 -0
  494. kiri_dbt_bridge/gold/_sql_emit.py +128 -0
  495. kiri_dbt_bridge/gold/assemble.py +90 -0
  496. kiri_dbt_bridge/gold/canonical_columns.py +168 -0
  497. kiri_dbt_bridge/gold/computed_expressions.py +179 -0
  498. kiri_dbt_bridge/gold/dialects/__init__.py +69 -0
  499. kiri_dbt_bridge/gold/dialects/databricks.py +150 -0
  500. kiri_dbt_bridge/gold/dialects/duckdb.py +120 -0
  501. kiri_dbt_bridge/gold/dialects/trino.py +136 -0
  502. kiri_dbt_bridge/gold/dim_generator.py +688 -0
  503. kiri_dbt_bridge/gold/dimension_refs.py +255 -0
  504. kiri_dbt_bridge/gold/dispatch.py +69 -0
  505. kiri_dbt_bridge/gold/fact_generator.py +534 -0
  506. kiri_dbt_bridge/gold/flat_generator.py +144 -0
  507. kiri_dbt_bridge/gold/lineage.py +484 -0
  508. kiri_dbt_bridge/gold/localized_twins.py +218 -0
  509. kiri_dbt_bridge/gold/measures.py +49 -0
  510. kiri_dbt_bridge/gold/role_playing.py +75 -0
  511. kiri_dbt_bridge/gold/surrogate_key.py +114 -0
  512. kiri_dbt_bridge/macros/kiri_scd1_dim.sql +57 -0
  513. kiri_dbt_bridge/macros/kiri_scd2_dim.sql +188 -0
  514. kiri_dbt_bridge/macros/kiri_sha256.sql +32 -0
  515. kiri_dbt_bridge/macros/kiri_string_cast.sql +37 -0
  516. kiri_dbt_bridge/macros/kiri_surrogate_key.sql +43 -0
  517. kiri_dbt_bridge/profiles.py +162 -0
  518. kiri_dbt_bridge/py.typed +0 -0
  519. kiri_dbt_bridge/safe_ident.py +44 -0
  520. kiri_dbt_bridge/silver_conformance.py +188 -0
  521. kiri_dbt_bridge/silver_kimball/__init__.py +27 -0
  522. kiri_dbt_bridge/silver_kimball/assemble.py +174 -0
  523. kiri_dbt_bridge/silver_kimball/dim_generator.py +602 -0
  524. kiri_dbt_bridge/silver_kimball/dispatch.py +86 -0
  525. kiri_dbt_bridge/silver_kimball/fact_generator.py +320 -0
  526. kiri_dbt_bridge/silver_kimball/flat_generator.py +156 -0
  527. kiri_dbt_bridge/silver_kimball/lineage.py +464 -0
  528. kiri_dbt_bridge/silver_kimball/watermark_window.py +199 -0
  529. kiri_dbt_bridge/silver_kimball/zone.py +68 -0
  530. kiri_dbt_bridge/silver_scd2_curated/__init__.py +46 -0
  531. kiri_dbt_bridge/silver_scd2_curated/assemble.py +213 -0
  532. kiri_dbt_bridge/silver_scd2_curated/curated_generator.py +351 -0
  533. kiri_dbt_bridge/silver_scd2_curated/standardized_generator.py +261 -0
  534. kiri_dbt_bridge/silver_scd2_curated/standardized_plan.py +254 -0
  535. kiri_iceberg/__init__.py +11 -0
  536. kiri_iceberg/catalog.py +128 -0
  537. kiri_iceberg/profile.py +131 -0
  538. kiri_iceberg/py.typed +0 -0
  539. kiri_ingestion/__init__.py +63 -0
  540. kiri_ingestion/airbyte_client.py +428 -0
  541. kiri_ingestion/database_fetcher.py +224 -0
  542. kiri_ingestion/layout.py +71 -0
  543. kiri_ingestion/mssql_introspect.py +565 -0
  544. kiri_ingestion/py.typed +0 -0
  545. kiri_ingestion/rest_fetcher.py +472 -0
  546. kiri_ingestion/runner.py +341 -0
  547. kiri_ingestion/schema_drift.py +222 -0
  548. kiri_ingestion/storage.py +621 -0
  549. kiri_mcp/__init__.py +5 -0
  550. kiri_mcp/audit.py +99 -0
  551. kiri_mcp/audit_decorators.py +252 -0
  552. kiri_mcp/main.py +22 -0
  553. kiri_mcp/py.typed +0 -0
  554. kiri_mcp/rbac.py +110 -0
  555. kiri_mcp/server.py +766 -0
  556. kiri_mcp/skills.py +297 -0
  557. kiri_mcp/tools/__init__.py +70 -0
  558. kiri_mcp/tools/_shared.py +58 -0
  559. kiri_mcp/tools/adapter.py +150 -0
  560. kiri_mcp/tools/cli_reference.py +59 -0
  561. kiri_mcp/tools/compliance.py +119 -0
  562. kiri_mcp/tools/contract.py +374 -0
  563. kiri_mcp/tools/dv.py +62 -0
  564. kiri_mcp/tools/federation.py +152 -0
  565. kiri_mcp/tools/intent.py +71 -0
  566. kiri_mcp/tools/lineage.py +204 -0
  567. kiri_mcp/tools/lineage_drift.py +75 -0
  568. kiri_mcp/tools/plan.py +66 -0
  569. kiri_mcp/tools/project.py +311 -0
  570. kiri_migration/__init__.py +56 -0
  571. kiri_migration/name_preservation.py +271 -0
  572. kiri_migration/predeploy.py +311 -0
  573. kiri_migration/py.typed +0 -0
  574. kiri_migration/reconcile.py +1891 -0
  575. kiri_migration/scaffold/__init__.py +90 -0
  576. kiri_migration/scaffold/_audit_columns.py +74 -0
  577. kiri_migration/scaffold/_classify.py +100 -0
  578. kiri_migration/scaffold/_typemap.py +71 -0
  579. kiri_migration/scaffold/_yaml.py +33 -0
  580. kiri_migration/scaffold/bronze.py +279 -0
  581. kiri_migration/scaffold/compile_targets/__init__.py +271 -0
  582. kiri_migration/scaffold/compile_targets/_common.py +193 -0
  583. kiri_migration/scaffold/compile_targets/copy_into.py +33 -0
  584. kiri_migration/scaffold/compile_targets/dlt.py +125 -0
  585. kiri_migration/scaffold/compile_targets/dlt_with_append_flows.py +163 -0
  586. kiri_migration/scaffold/compile_targets/dlt_with_apply_changes.py +192 -0
  587. kiri_migration/scaffold/compile_targets/dlt_with_expectations.py +276 -0
  588. kiri_migration/scaffold/compile_targets/layer_dispatch.py +258 -0
  589. kiri_migration/scaffold/compile_targets/sql_full_snapshot.py +385 -0
  590. kiri_migration/scaffold/compile_targets/streaming_table.py +37 -0
  591. kiri_migration/scaffold/mart.py +234 -0
  592. kiri_migration/scaffold/plans/__init__.py +49 -0
  593. kiri_migration/scaffold/plans/_registry.py +308 -0
  594. kiri_migration/scaffold/plans/minimal.py +550 -0
  595. kiri_migration/scaffold/plans/plan_b_layer.py +640 -0
  596. kiri_migration/scaffold/silver_from_marts.py +256 -0
  597. kiri_migration/scaffold/silver_pattern.py +451 -0
  598. kiri_migration/sp_translator.py +398 -0
  599. kiri_odcs/LICENSE +204 -0
  600. kiri_odcs/__init__.py +234 -0
  601. kiri_odcs/ai_trust_tier.py +475 -0
  602. kiri_odcs/canonical.py +263 -0
  603. kiri_odcs/diff.py +63 -0
  604. kiri_odcs/errors.py +51 -0
  605. kiri_odcs/invariant_sql.py +136 -0
  606. kiri_odcs/kiri_bridge.py +71 -0
  607. kiri_odcs/kiri_ext.py +3166 -0
  608. kiri_odcs/kiri_fk.py +447 -0
  609. kiri_odcs/kiri_pit.py +121 -0
  610. kiri_odcs/kiri_ref.py +57 -0
  611. kiri_odcs/openlineage_adapter.py +105 -0
  612. kiri_odcs/parser.py +1213 -0
  613. kiri_odcs/pii_guardrails.py +159 -0
  614. kiri_odcs/py.typed +0 -0
  615. kiri_odcs/schema_export.py +223 -0
  616. kiri_openlineage/__init__.py +58 -0
  617. kiri_openlineage/builder.py +146 -0
  618. kiri_openlineage/cost.py +190 -0
  619. kiri_openlineage/emitter.py +165 -0
  620. kiri_openlineage/py.typed +0 -0
  621. kiri_openlineage/schema.py +121 -0
  622. kiri_packs/__init__.py +67 -0
  623. kiri_packs/installer.py +500 -0
  624. kiri_packs/manifest.py +134 -0
  625. kiri_packs/publisher.py +605 -0
  626. kiri_packs/py.typed +0 -0
  627. kiri_packs/validator.py +295 -0
  628. kiri_quality/__init__.py +108 -0
  629. kiri_quality/ai_audit_correlator.py +293 -0
  630. kiri_quality/ai_audit_correlator_apply.py +526 -0
  631. kiri_quality/conformance_evidence.py +272 -0
  632. kiri_quality/dbt_test_collector.py +214 -0
  633. kiri_quality/dq_codegen.py +300 -0
  634. kiri_quality/dv_checks.py +393 -0
  635. kiri_quality/dv_column_lineage.py +279 -0
  636. kiri_quality/dv_column_lineage_apply.py +856 -0
  637. kiri_quality/dv_conformance.py +841 -0
  638. kiri_quality/dv_fixture_runner.py +478 -0
  639. kiri_quality/dv_invariants.py +986 -0
  640. kiri_quality/dv_kiri.py +97 -0
  641. kiri_quality/dv_markdown.py +169 -0
  642. kiri_quality/dv_observed_uc_reader.py +187 -0
  643. kiri_quality/dv_runner.py +389 -0
  644. kiri_quality/evidence_status.py +337 -0
  645. kiri_quality/fk_checks.py +800 -0
  646. kiri_quality/fk_ddl.py +402 -0
  647. kiri_quality/fk_pit_contract.py +168 -0
  648. kiri_quality/fk_runner.py +950 -0
  649. kiri_quality/kernel.py +376 -0
  650. kiri_quality/pii.py +60 -0
  651. kiri_quality/pre_classify/__init__.py +55 -0
  652. kiri_quality/pre_classify/engine.py +346 -0
  653. kiri_quality/pre_classify/locale_packs/en.yaml +117 -0
  654. kiri_quality/pre_classify/locale_packs/sv.yaml +73 -0
  655. kiri_quality/pre_classify/merge.py +297 -0
  656. kiri_quality/pre_classify/model.py +163 -0
  657. kiri_quality/py.typed +0 -0
  658. kiri_quality/reject_lane.py +261 -0
  659. kiri_quality/rule_runner.py +565 -0
  660. kiri_quality/schema_evolution_check.py +88 -0
  661. kiri_quality/silver_quality.py +494 -0
  662. kiri_quality/silver_quality_markdown.py +187 -0
  663. kiri_quality/uc_security_compile.py +951 -0
  664. kiri_quality/uc_security_compile_apply.py +1186 -0
  665. kiri_rbac/__init__.py +87 -0
  666. kiri_rbac/access.py +371 -0
  667. kiri_rbac/loader.py +104 -0
  668. kiri_rbac/pr_gate.py +213 -0
  669. kiri_rbac/providers/__init__.py +29 -0
  670. kiri_rbac/providers/_jwt.py +121 -0
  671. kiri_rbac/providers/azure_ad.py +93 -0
  672. kiri_rbac/providers/base.py +107 -0
  673. kiri_rbac/providers/factory.py +48 -0
  674. kiri_rbac/providers/github.py +134 -0
  675. kiri_rbac/providers/oidc_generic.py +99 -0
  676. kiri_rbac/py.typed +0 -0
  677. kiri_rbac/resolver.py +118 -0
  678. kiri_rbac/schema.py +219 -0
  679. kiri_schema_registry/__init__.py +22 -0
  680. kiri_schema_registry/avro.py +127 -0
  681. kiri_schema_registry/base.py +71 -0
  682. kiri_schema_registry/confluent.py +184 -0
  683. kiri_schema_registry/glue.py +178 -0
  684. kiri_schema_registry/py.typed +0 -0
  685. kiri_slack_bot/__init__.py +24 -0
  686. kiri_slack_bot/handler.py +248 -0
  687. kiri_slack_bot/py.typed +0 -0
  688. kiri_slack_bot/queries.py +90 -0
  689. kiri_slack_bot/signature.py +94 -0
  690. kiri_vault/__init__.py +59 -0
  691. kiri_vault/audit.py +64 -0
  692. kiri_vault/aws_vault.py +123 -0
  693. kiri_vault/azure_vault.py +236 -0
  694. kiri_vault/boundaries.py +219 -0
  695. kiri_vault/client.py +54 -0
  696. kiri_vault/databricks_vault.py +292 -0
  697. kiri_vault/env_vault.py +77 -0
  698. kiri_vault/py.typed +0 -0
  699. kiri_vault/ref.py +84 -0
  700. kirimana_automation/__init__.py +0 -0
  701. kirimana_automation/business_calendar.py +179 -0
  702. kirimana_automation/dag_snapshot.py +252 -0
  703. kirimana_automation/db/__init__.py +5 -0
  704. kirimana_automation/db/migrate.py +571 -0
  705. kirimana_automation/db/migrations/0001_release_state.down.duckdb.sql +29 -0
  706. kirimana_automation/db/migrations/0001_release_state.down.postgres.sql +37 -0
  707. kirimana_automation/db/migrations/0001_release_state.duckdb.sql +170 -0
  708. kirimana_automation/db/migrations/0001_release_state.postgres.sql +176 -0
  709. kirimana_automation/db/migrations/0002_rate_limit_buckets.down.duckdb.sql +9 -0
  710. kirimana_automation/db/migrations/0002_rate_limit_buckets.down.postgres.sql +9 -0
  711. kirimana_automation/db/migrations/0002_rate_limit_buckets.duckdb.sql +14 -0
  712. kirimana_automation/db/migrations/0002_rate_limit_buckets.postgres.sql +18 -0
  713. kirimana_automation/db/migrations/0003_flow_runs.down.duckdb.sql +18 -0
  714. kirimana_automation/db/migrations/0003_flow_runs.down.postgres.sql +19 -0
  715. kirimana_automation/db/migrations/0003_flow_runs.duckdb.sql +85 -0
  716. kirimana_automation/db/migrations/0003_flow_runs.postgres.sql +102 -0
  717. kirimana_automation/db/migrations/0004_flow_dag_snapshots.down.duckdb.sql +11 -0
  718. kirimana_automation/db/migrations/0004_flow_dag_snapshots.down.postgres.sql +11 -0
  719. kirimana_automation/db/migrations/0004_flow_dag_snapshots.duckdb.sql +15 -0
  720. kirimana_automation/db/migrations/0004_flow_dag_snapshots.postgres.sql +31 -0
  721. kirimana_automation/db/migrations/0005_calendar_skip.down.duckdb.sql +109 -0
  722. kirimana_automation/db/migrations/0005_calendar_skip.down.postgres.sql +42 -0
  723. kirimana_automation/db/migrations/0005_calendar_skip.duckdb.sql +113 -0
  724. kirimana_automation/db/migrations/0005_calendar_skip.postgres.sql +42 -0
  725. kirimana_automation/db/migrations/0006_flow_apply_log.down.duckdb.sql +9 -0
  726. kirimana_automation/db/migrations/0006_flow_apply_log.down.postgres.sql +11 -0
  727. kirimana_automation/db/migrations/0006_flow_apply_log.duckdb.sql +45 -0
  728. kirimana_automation/db/migrations/0006_flow_apply_log.postgres.sql +49 -0
  729. kirimana_automation/db/migrations/0007_flow_task_error_redacted.down.duckdb.sql +14 -0
  730. kirimana_automation/db/migrations/0007_flow_task_error_redacted.down.postgres.sql +2 -0
  731. kirimana_automation/db/migrations/0007_flow_task_error_redacted.duckdb.sql +7 -0
  732. kirimana_automation/db/migrations/0007_flow_task_error_redacted.postgres.sql +11 -0
  733. kirimana_automation/db/migrations/README.md +84 -0
  734. kirimana_automation/flow_loader.py +220 -0
  735. kirimana_automation/freeze.py +133 -0
  736. kirimana_automation/kiri_recommender.py +313 -0
  737. kirimana_automation/main.py +195 -0
  738. kirimana_automation/py.typed +0 -0
  739. kirimana_automation/run_history.py +593 -0
  740. kirimana_automation/run_history_analysis.py +607 -0
  741. kirimana_automation/schedule.py +343 -0
  742. kirimana_automation/schedule_validator.py +572 -0
  743. kirimana_automation/workflow_compiler.py +1288 -0
kiri_cli/dv_cmd.py ADDED
@@ -0,0 +1,814 @@
1
+ """``kiri dv quality`` — Data Vault silver-quality CLI (ADR 0047).
2
+
3
+ Three subcommands:
4
+
5
+ - ``run`` — execute the catalogue against the configured target,
6
+ emit a JSON report (and exit non-zero on gate fails).
7
+ - ``list`` — print the catalogue (id, name, severity, scope).
8
+ - ``explain`` — print the rendered SQL for a single check, useful
9
+ when an operator wants to debug a finding by hand.
10
+
11
+ The wider ``kiri dv`` namespace is reserved for future DV-specific
12
+ subcommands (planner introspection, reconciliation scripts). This
13
+ module ships ``dv quality``; siblings remain open for later ADRs.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import json
19
+ import os
20
+ from dataclasses import asdict
21
+ from datetime import UTC, datetime
22
+ from pathlib import Path
23
+ from typing import TYPE_CHECKING, Annotated, Any
24
+
25
+ import typer
26
+ from kiri_adapters import get_adapter
27
+ from kiri_core import load_project
28
+ from kiri_quality.dv_runner import (
29
+ DvQualityConfig,
30
+ DvQualityRunError,
31
+ DvQualityRunner,
32
+ list_catalog,
33
+ )
34
+ from rich.console import Console
35
+ from rich.panel import Panel
36
+ from rich.table import Table as RichTable
37
+
38
+ if TYPE_CHECKING: # pragma: no cover — typing only
39
+ from kiri_core.silver import BackfillPlan
40
+
41
+ dv_app = typer.Typer(
42
+ name="dv",
43
+ help="Data Vault tooling — silver-quality checks (ADR 0047), more to come.",
44
+ no_args_is_help=True,
45
+ )
46
+
47
+ quality_app = typer.Typer(
48
+ name="quality",
49
+ help="Silver-quality checks for Data Vault projects.",
50
+ no_args_is_help=True,
51
+ )
52
+ dv_app.add_typer(quality_app, name="quality")
53
+
54
+ # Phase-3 migration helper for ADR 0048 raw vs business split.
55
+ from kiri_cli.dv_migrate_cmd import migrate_zones_app # noqa: E402
56
+
57
+ dv_app.add_typer(migrate_zones_app, name="migrate-zones")
58
+
59
+ # AI-roadmap #5 — fixture-based DV invariant runner.
60
+ from kiri_cli.dv_test_cmd import dv_test_cmd # noqa: E402
61
+
62
+ dv_app.command("test")(dv_test_cmd)
63
+
64
+ # ADR 0062 slice 8a — DataVault4dbt installer.
65
+ from kiri_cli.dv_install import ( # noqa: E402
66
+ DbtDepsRunError,
67
+ DbtProjectMissingError,
68
+ Dv4dbtTargetUnsupportedError,
69
+ install_dv4dbt,
70
+ supported_targets,
71
+ )
72
+
73
+ _console = Console()
74
+
75
+
76
+ # ---------------------------------------------------------------------------
77
+ # Helpers
78
+ # ---------------------------------------------------------------------------
79
+
80
+
81
+ def _split_csv(value: str) -> tuple[str, ...]:
82
+ return tuple(v.strip() for v in value.split(",") if v.strip())
83
+
84
+
85
+ def _resolve_adapter(project_dir: Path, target: str | None) -> Any:
86
+ p = load_project(project_dir)
87
+ chosen = target or p.config.default_target
88
+ profile = dict(p.config.profile_for(chosen))
89
+ adapter_name = str(profile.get("adapter") or p.config.adapter)
90
+ adapter = get_adapter(adapter_name, profile)
91
+ return p, adapter, chosen
92
+
93
+
94
+ # ---------------------------------------------------------------------------
95
+ # kiri dv quality run
96
+ # ---------------------------------------------------------------------------
97
+
98
+
99
+ @quality_app.command("run")
100
+ def quality_run(
101
+ project: Annotated[
102
+ Path | None,
103
+ typer.Option("--project", "-p", help="Project directory"),
104
+ ] = None,
105
+ target: Annotated[
106
+ str | None,
107
+ typer.Option("--target", "-t", help="Named profile from kiri.yml"),
108
+ ] = None,
109
+ gate: Annotated[
110
+ str,
111
+ typer.Option(
112
+ "--gate",
113
+ help="Comma-separated check IDs that block sign-off when failing (e.g. DV-001,DV-002).",
114
+ ),
115
+ ] = "",
116
+ exclude: Annotated[
117
+ str,
118
+ typer.Option(
119
+ "--exclude",
120
+ help="Comma-separated check IDs to skip entirely.",
121
+ ),
122
+ ] = "",
123
+ max_samples: Annotated[
124
+ int,
125
+ typer.Option(
126
+ "--max-samples",
127
+ help="Cap on violation rows per check (default 100).",
128
+ ),
129
+ ] = 100,
130
+ output: Annotated[
131
+ Path | None,
132
+ typer.Option(
133
+ "--output",
134
+ "-o",
135
+ help="Base path for the report. With --format both this writes "
136
+ "<output>.json and <output>.md; with --format json/md it writes "
137
+ "the single requested file at the literal path.",
138
+ ),
139
+ ] = None,
140
+ report_format: Annotated[
141
+ str,
142
+ typer.Option(
143
+ "--format",
144
+ help="Output format: json | md | both (default both).",
145
+ ),
146
+ ] = "both",
147
+ ai_summary: Annotated[
148
+ bool,
149
+ typer.Option(
150
+ "--ai-summary/--no-ai-summary",
151
+ help="Add a Kiri AI paragraph at the top of the report. "
152
+ "Audit-logged via the AI gateway. Default off.",
153
+ ),
154
+ ] = False,
155
+ ) -> None:
156
+ """Run the silver-quality catalogue against the target's silver layer."""
157
+ project = resolve_project(project)
158
+ # Validate args BEFORE touching the warehouse — typos like
159
+ # `--format markdown` should fail in milliseconds, not after a
160
+ # multi-second query against production silver.
161
+ if report_format not in ("json", "md", "both"):
162
+ raise typer.BadParameter(f"--format must be one of json|md|both (got {report_format!r})")
163
+
164
+ p, adapter, chosen = _resolve_adapter(project, target)
165
+ cfg = DvQualityConfig(
166
+ max_samples=max_samples,
167
+ gate_check_ids=_split_csv(gate),
168
+ excluded_check_ids=_split_csv(exclude),
169
+ )
170
+ gateway = None
171
+ if ai_summary:
172
+ try:
173
+ from kiri_ai_gateway import AIGateway
174
+
175
+ gateway = AIGateway.from_env()
176
+ except Exception as exc:
177
+ _console.print(f"[yellow]AI gateway unavailable, skipping summary:[/yellow] {exc}")
178
+ gateway = None
179
+ runner = DvQualityRunner(p, adapter, config=cfg, target=chosen, ai_gateway=gateway)
180
+ try:
181
+ report = runner.run()
182
+ except DvQualityRunError as exc:
183
+ _console.print(f"[red]error:[/red] {exc}")
184
+ raise typer.Exit(2) from exc
185
+
186
+ json_payload = report.model_dump_json(indent=2)
187
+ md_payload: str | None = None
188
+ if report_format in ("md", "both"):
189
+ from kiri_quality.dv_markdown import render_markdown
190
+
191
+ md_payload = render_markdown(report)
192
+
193
+ if output is not None:
194
+ output.parent.mkdir(parents=True, exist_ok=True)
195
+ if report_format == "json":
196
+ output.write_text(json_payload + "\n")
197
+ _console.print(f"[green]wrote[/green] {output}")
198
+ elif report_format == "md":
199
+ output.write_text(md_payload or "" + "\n")
200
+ _console.print(f"[green]wrote[/green] {output}")
201
+ else: # both
202
+ json_path = (
203
+ output.with_suffix(".json")
204
+ if output.suffix
205
+ else output.with_name(output.name + ".json")
206
+ )
207
+ md_path = (
208
+ output.with_suffix(".md")
209
+ if output.suffix
210
+ else output.with_name(output.name + ".md")
211
+ )
212
+ json_path.write_text(json_payload + "\n")
213
+ md_path.write_text((md_payload or "") + "\n")
214
+ _console.print(f"[green]wrote[/green] {json_path} + {md_path}")
215
+ else:
216
+ # No --output: print the format(s) the operator asked for. With
217
+ # both, emit JSON first, then a separator, then Markdown — never
218
+ # silently drop one half.
219
+ if report_format == "md":
220
+ _console.print(md_payload or "")
221
+ elif report_format == "json":
222
+ _console.print(json_payload)
223
+ else: # both
224
+ _console.print(json_payload)
225
+ _console.print("\n---\n")
226
+ _console.print(md_payload or "")
227
+
228
+ blocking = report.gate_blocking_findings
229
+ if blocking:
230
+ _console.print(
231
+ f"[red]gate blocked:[/red] {len(blocking)} fail finding(s) "
232
+ f"in gated checks ({', '.join(sorted({f.check_id for f in blocking}))})"
233
+ )
234
+ raise typer.Exit(1)
235
+ # Non-blocking by design: when --gate is set, only the listed
236
+ # check IDs that are in `blocking` raise. Failures outside the
237
+ # gate surface in the JSON but never exit non-zero — that's the
238
+ # whole point of letting operators pick which checks ship.
239
+
240
+
241
+ # ---------------------------------------------------------------------------
242
+ # kiri dv quality list
243
+ # ---------------------------------------------------------------------------
244
+
245
+
246
+ @quality_app.command("list")
247
+ def quality_list() -> None:
248
+ """Print the catalogue (id, name, severity, scope)."""
249
+ table = RichTable(title="DV quality catalogue", show_lines=False)
250
+ table.add_column("ID", style="bold")
251
+ table.add_column("Name")
252
+ table.add_column("Severity", style="cyan")
253
+ table.add_column("Scope", style="magenta")
254
+ for c in list_catalog():
255
+ table.add_row(c.id, c.name, c.severity.value, c.scope.value)
256
+ _console.print(table)
257
+
258
+
259
+ # ---------------------------------------------------------------------------
260
+ # kiri dv quality explain
261
+ # ---------------------------------------------------------------------------
262
+
263
+
264
+ @quality_app.command("explain")
265
+ def quality_explain(
266
+ check_id: Annotated[
267
+ str,
268
+ typer.Argument(help="Check ID (e.g. DV-001)"),
269
+ ],
270
+ ) -> None:
271
+ """Print the catalogue entry's description and references.
272
+
273
+ SQL rendering is per-target — the runner needs a project + adapter
274
+ to know schemas + dialect. ``run --gate <id>`` paired with
275
+ ``--max-samples 1`` produces the rendered SQL in the JSON report's
276
+ findings; for now ``explain`` covers the static metadata.
277
+ """
278
+ from kiri_quality.dv_checks import CHECK_CATALOG
279
+
280
+ spec = CHECK_CATALOG.get(check_id)
281
+ if spec is None:
282
+ _console.print(
283
+ f"[red]unknown check id {check_id!r}[/red]; available: "
284
+ f"{', '.join(sorted(CHECK_CATALOG))}"
285
+ )
286
+ raise typer.Exit(2)
287
+ payload = json.dumps(asdict(spec), indent=2, default=str)
288
+ typer.echo(payload)
289
+
290
+
291
+ # ---------------------------------------------------------------------------
292
+ # kiri dv install — ADR 0062 §"Installation choice" (slice 8a)
293
+ # ---------------------------------------------------------------------------
294
+
295
+
296
+ @dv_app.command("install")
297
+ def dv_install(
298
+ project_dir: Annotated[
299
+ Path | None,
300
+ typer.Option("--project", "-p", help="Project directory"),
301
+ ] = None,
302
+ target: Annotated[
303
+ str | None,
304
+ typer.Option(
305
+ "--target",
306
+ "-t",
307
+ help=(
308
+ "Active dbt target name. Must match the DataVault4dbt "
309
+ "compatibility matrix (snowflake, bigquery, postgres, "
310
+ "redshift, synapse, fabric, databricks, oracle, exasol). "
311
+ "Defaults to the project's default target."
312
+ ),
313
+ ),
314
+ ] = None,
315
+ ) -> None:
316
+ """Install / refresh DataVault4dbt for a Kirimana project (ADR 0062).
317
+
318
+ Renders ``packages.yml`` with the pinned DataVault4dbt version,
319
+ runs ``dbt deps`` against the project, and writes the lock
320
+ manifest to ``.kirimana/dv-backend/dv4dbt/lock.json``. Idempotent
321
+ — re-running with no version drift exits cleanly without
322
+ re-invoking ``dbt deps``.
323
+ """
324
+ project_dir = resolve_project(project_dir)
325
+
326
+ project = load_project(project_dir)
327
+ chosen = target or project.config.default_target
328
+ try:
329
+ result = install_dv4dbt(project, target=chosen)
330
+ except Dv4dbtTargetUnsupportedError as exc:
331
+ _console.print(
332
+ f"[red]✗[/red] DataVault4dbt does not support target "
333
+ f"[bold]{exc.target!r}[/bold]. Supported targets: "
334
+ f"{', '.join(supported_targets())}."
335
+ )
336
+ raise typer.Exit(2) from exc
337
+ except DbtDepsRunError as exc:
338
+ _console.print(f"[red]✗[/red] dbt deps failed (exit {exc.exit_code}):")
339
+ if exc.stderr:
340
+ _console.print(f"[dim]{exc.stderr}[/dim]")
341
+ raise typer.Exit(1) from exc
342
+ except DbtProjectMissingError as exc:
343
+ _console.print(f"[red]✗[/red] {exc}")
344
+ raise typer.Exit(2) from exc
345
+
346
+ if result.dbt_deps_invoked:
347
+ _console.print(
348
+ f"[green]✓[/green] DataVault4dbt installed for target [bold]{result.target}[/bold]"
349
+ )
350
+ else:
351
+ _console.print(
352
+ f"[green]✓[/green] DataVault4dbt already up to date for target "
353
+ f"[bold]{result.target}[/bold] (no changes)"
354
+ )
355
+ _console.print(
356
+ f" packages.yml: {result.packages_yml_path}\n"
357
+ f" lock manifest: {result.lock_manifest_path}\n"
358
+ f" DataVault4dbt: {result.dv4dbt_version}\n"
359
+ f" dbt adapter: {result.dbt_adapter_package}"
360
+ )
361
+
362
+
363
+ # ---------------------------------------------------------------------------
364
+ # kiri dv apply — ADR 0062 §7 (slice 6a CLI wiring)
365
+ # ---------------------------------------------------------------------------
366
+
367
+
368
+ def _print_backfill_plan(plan: BackfillPlan) -> None:
369
+ """Render the reviewed backfill plan as a Rich panel.
370
+
371
+ Operator-facing surface for ADR 0062 §8: shows the audited
372
+ request (who / when / why / from_batch) + exactly what the
373
+ backfill will destroy, preserve, and recompute, so the human can
374
+ veto before any node is touched. The same classification is the
375
+ one stamped onto the run manifest, so what the operator sees is
376
+ what the audit log records.
377
+ """
378
+
379
+ req = plan.request
380
+ lines = [
381
+ f"[bold]from_batch[/bold] {req.from_batch}",
382
+ f"[bold]requested_by[/bold] {req.requested_by}",
383
+ f"[bold]requested_at[/bold] {req.requested_at.isoformat()}",
384
+ f"[bold]reason[/bold] {req.reason}",
385
+ "",
386
+ f"[red]drop + recreate[/red] ({len(plan.nodes_to_drop_recreate)}): "
387
+ + (", ".join(plan.nodes_to_drop_recreate) or "[dim]none[/dim]"),
388
+ f"[green]preserved[/green] ({len(plan.nodes_preserved)}): "
389
+ + (", ".join(plan.nodes_preserved) or "[dim]none[/dim]"),
390
+ f"[yellow]recomputed[/yellow] ({len(plan.nodes_recomputed)}): "
391
+ + (", ".join(plan.nodes_recomputed) or "[dim]none[/dim]"),
392
+ ]
393
+ _console.print(
394
+ Panel(
395
+ "\n".join(lines),
396
+ title="[bold]DV backfill plan[/bold] — ADR 0062 §8",
397
+ border_style="red",
398
+ )
399
+ )
400
+
401
+
402
+ @dv_app.command("apply")
403
+ def dv_apply(
404
+ project_dir: Annotated[
405
+ Path | None,
406
+ typer.Option("--project", "-p", help="Project directory"),
407
+ ] = None,
408
+ json_out: Annotated[
409
+ bool,
410
+ typer.Option(
411
+ "--json",
412
+ help="Emit the run manifest as JSON on stdout instead of a table.",
413
+ ),
414
+ ] = False,
415
+ backfill: Annotated[
416
+ bool,
417
+ typer.Option(
418
+ "--backfill",
419
+ help=(
420
+ "Declared backfill mode (ADR 0062 §8): drop + recreate "
421
+ "satellites and PIT from --from-batch forward. Hubs + "
422
+ "links are preserved (insert-only). Requires "
423
+ "--from-batch and --reason; prints the plan and "
424
+ "requires --yes before any destructive apply."
425
+ ),
426
+ ),
427
+ ] = False,
428
+ from_batch: Annotated[
429
+ str | None,
430
+ typer.Option(
431
+ "--from-batch",
432
+ help="Batch id to rebuild from (inclusive). Required with --backfill.",
433
+ ),
434
+ ] = None,
435
+ reason: Annotated[
436
+ str | None,
437
+ typer.Option(
438
+ "--reason",
439
+ help="Audit justification for the backfill. Required with --backfill.",
440
+ ),
441
+ ] = None,
442
+ yes: Annotated[
443
+ bool,
444
+ typer.Option(
445
+ "--yes",
446
+ help=(
447
+ "Confirm a destructive backfill. Without it, --backfill "
448
+ "prints the plan and exits 0 (dry-run)."
449
+ ),
450
+ ),
451
+ ] = False,
452
+ ) -> None:
453
+ """Graph-driven idempotent DV silver apply (ADR 0062 §7/§8).
454
+
455
+ Builds the project's :class:`DataVaultGraphPlan`, resolves the
456
+ configured execution backend (native or datavault4dbt), and
457
+ walks ``plan.topological_order`` dispatching each node. Nodes
458
+ whose idempotency key is unchanged since the previous run are
459
+ skipped; the run manifest records every node's status.
460
+
461
+ With ``--backfill`` (ADR 0062 §8) the run is a *declared* rebuild
462
+ of historical state: satellites + PIT from ``--from-batch`` are
463
+ force-applied (the idempotency skip is bypassed), hubs + links
464
+ are preserved (insert-only), bridges + references are recomputed.
465
+ The audited request (who / when / why / from_batch) + the node
466
+ disposition are stamped onto the run manifest, which becomes the
467
+ ADR 0062 §8 audit-log entry. Without ``--yes`` the command prints
468
+ the plan and exits 0 (dry-run).
469
+
470
+ Exit codes mirror ``kiri dv test``:
471
+
472
+ - 0 — every node applied or skipped cleanly (or backfill dry-run)
473
+ - 1 — one or more nodes failed
474
+ - 2 — setup error (no project, backend unavailable, plan error)
475
+
476
+ The new run manifest is written under
477
+ ``<project>/.kirimana/dv-backend/<backend>/run-manifests/``
478
+ and the ``latest.json`` pointer is updated so the next run is
479
+ incremental.
480
+ """
481
+ project_dir = resolve_project(project_dir)
482
+
483
+ # Lazy imports keep the kiri_core.silver surface out of the
484
+ # module-load path for `dv test` / `dv install` callers.
485
+ from kiri_core.silver import (
486
+ ApplyRunnerError,
487
+ BackfillError,
488
+ BackfillRequest,
489
+ DvBackendUnavailableError,
490
+ apply_graph_plan,
491
+ build_graph_plan,
492
+ load_latest_manifest,
493
+ persist_run_manifest,
494
+ plan_backfill,
495
+ resolve_silver_backend,
496
+ )
497
+ from kiri_core.silver.dv_graph import DataVaultGraphPlanError
498
+
499
+ # --backfill demands its audit inputs up-front, before any
500
+ # project IO, so an operator who forgot --reason gets a clean
501
+ # BadParameter rather than a half-built request.
502
+ if backfill:
503
+ if not from_batch:
504
+ raise typer.BadParameter(
505
+ "--backfill requires --from-batch <batch id> (ADR 0062 §8: "
506
+ "an unbounded backfill would corrupt current-state "
507
+ "satellites / PIT)."
508
+ )
509
+ if not reason or not reason.strip():
510
+ raise typer.BadParameter(
511
+ "--backfill requires --reason <text> — the audit trail "
512
+ "must record why historical state was rebuilt (ADR 0062 §8)."
513
+ )
514
+
515
+ try:
516
+ project = load_project(project_dir)
517
+ except Exception as exc:
518
+ _console.print(f"[red]✗[/red] could not load project: {exc}")
519
+ raise typer.Exit(2) from exc
520
+
521
+ try:
522
+ plan = build_graph_plan(project)
523
+ except DataVaultGraphPlanError as exc:
524
+ _console.print(f"[red]✗[/red] DV graph plan error: {exc}")
525
+ raise typer.Exit(2) from exc
526
+
527
+ if not plan.nodes:
528
+ _console.print("[dim]no Data Vault contracts in this project — nothing to apply[/dim]")
529
+ raise typer.Exit(0)
530
+
531
+ try:
532
+ backend = resolve_silver_backend(project)
533
+ except DvBackendUnavailableError as exc:
534
+ _console.print(f"[red]✗[/red] DV backend unavailable: {exc}")
535
+ raise typer.Exit(2) from exc
536
+
537
+ backfill_plan = None
538
+ if backfill:
539
+ # ``from_batch`` / ``reason`` are guaranteed non-empty by the
540
+ # guard above; assert for the type-checker.
541
+ assert from_batch is not None
542
+ assert reason is not None
543
+ request = BackfillRequest(
544
+ from_batch=from_batch,
545
+ requested_by=os.environ.get("USER") or "cli",
546
+ requested_at=datetime.now(UTC),
547
+ reason=reason,
548
+ )
549
+ try:
550
+ backfill_plan = plan_backfill(request, plan)
551
+ except BackfillError as exc:
552
+ raise typer.BadParameter(str(exc)) from exc
553
+
554
+ _print_backfill_plan(backfill_plan)
555
+ if not yes:
556
+ _console.print(
557
+ "[yellow]dry-run[/yellow] — pass [bold]--yes[/bold] to "
558
+ "execute this destructive backfill."
559
+ )
560
+ raise typer.Exit(0)
561
+
562
+ previous = load_latest_manifest(project, backend)
563
+
564
+ try:
565
+ manifest = apply_graph_plan(
566
+ plan,
567
+ project,
568
+ backend,
569
+ previous_manifest=previous,
570
+ backfill=backfill_plan,
571
+ )
572
+ except ApplyRunnerError as exc:
573
+ _console.print(f"[red]✗[/red] apply runner setup error: {exc}")
574
+ raise typer.Exit(2) from exc
575
+
576
+ manifest_path = persist_run_manifest(manifest, project, backend)
577
+
578
+ if json_out:
579
+ typer.echo(manifest.model_dump_json(indent=2))
580
+ else:
581
+ table = RichTable(
582
+ title=f"DV apply — backend={backend.name.value} run={manifest.run_id[:8]}",
583
+ show_lines=False,
584
+ )
585
+ table.add_column("node")
586
+ table.add_column("kind")
587
+ table.add_column("zone")
588
+ table.add_column("status")
589
+ for entry in manifest.entries:
590
+ status_label = entry.status.value
591
+ if entry.status.value == "skipped" and entry.skip_reason:
592
+ status_label = f"skipped:{entry.skip_reason.value}"
593
+ table.add_row(
594
+ entry.node_name,
595
+ entry.kind,
596
+ entry.zone,
597
+ status_label,
598
+ )
599
+ _console.print(table)
600
+ _console.print(
601
+ f"[green]{manifest.applied_count} applied[/green], "
602
+ f"[yellow]{manifest.skipped_count} skipped[/yellow], "
603
+ f"[red]{manifest.failed_count} failed[/red] "
604
+ f"— manifest: {manifest_path}"
605
+ )
606
+
607
+ if manifest.failed_count > 0:
608
+ raise typer.Exit(1)
609
+ raise typer.Exit(0)
610
+
611
+
612
+ # ---------------------------------------------------------------------------
613
+ # kiri dv conformance — ADR 0062 §12 (slice 7a)
614
+ # ---------------------------------------------------------------------------
615
+
616
+ # Registered last so the diff stays a clean concatenation with the
617
+ # parallel slice-6b command addition (both append a @dv_app.command).
618
+ from kiri_cli._project_option import resolve_project # noqa: E402
619
+ from kiri_cli.dv_conformance_cmd import dv_conformance_cmd # noqa: E402
620
+
621
+ dv_app.command("conformance")(dv_conformance_cmd)
622
+
623
+
624
+ # ---------------------------------------------------------------------------
625
+ # kiri dv graph — ADR 0062 §11/§14 (slice 9b)
626
+ # ---------------------------------------------------------------------------
627
+
628
+
629
+ @dv_app.command("graph")
630
+ def dv_graph(
631
+ project_dir: Annotated[
632
+ Path | None,
633
+ typer.Option("--project", "-p", help="Project directory"),
634
+ ] = None,
635
+ view: Annotated[
636
+ str,
637
+ typer.Option(
638
+ "--view",
639
+ help=(
640
+ "Which bounded view to render: 'overview' (domain/zone "
641
+ "roll-up — the default), 'domain:<d>', 'zone:<z>' "
642
+ "(raw|business|pit), 'node:<n>' (BFS ball around a node; "
643
+ "pair with --depth), or 'path:<a>..<b>' (shortest "
644
+ "path). A mature vault is never rendered as one flat "
645
+ "graph — pick a scope (ADR 0062 §11/§14)."
646
+ ),
647
+ ),
648
+ ] = "overview",
649
+ depth: Annotated[
650
+ int,
651
+ typer.Option(
652
+ "--depth",
653
+ help="BFS radius for --view node:<n> (ignored otherwise).",
654
+ ),
655
+ ] = 1,
656
+ max_nodes: Annotated[
657
+ int,
658
+ typer.Option(
659
+ "--max-nodes",
660
+ help=(
661
+ "Hard node budget. Over budget collapses lowest-"
662
+ "priority nodes into counted summaries (default 50)."
663
+ ),
664
+ ),
665
+ ] = 50,
666
+ output_format: Annotated[
667
+ str,
668
+ typer.Option(
669
+ "--format",
670
+ help=(
671
+ "'mermaid' (default — deterministic, GitHub/mkdocs-"
672
+ "ready) or 'json' (overview → bounded domain rollup; "
673
+ "scoped views → the view's DataVaultGraphPlan "
674
+ "sub-plan = the BFF wire shape)."
675
+ ),
676
+ ),
677
+ ] = "mermaid",
678
+ ) -> None:
679
+ """Render a bounded Mermaid view of the project's DV graph.
680
+
681
+ Read-only. ``DataVaultGraphPlan`` is the machine source of truth;
682
+ Mermaid is its deterministic, byte-stable human projection
683
+ (ADR 0062 §11/§14). The whole-vault dump is unreachable by
684
+ design — every render is a scoped, budget-bounded view. This is
685
+ the surface the ADR 0074 agent-Kiri runs to *observe* the vault
686
+ and then *explain* the diagram; it never fabricates topology.
687
+
688
+ Exit codes mirror the rest of the ``kiri dv`` family:
689
+
690
+ - 0 — view rendered
691
+ - 2 — setup / selector error (no project, bad --view, unknown
692
+ domain/zone/node, plan error)
693
+ """
694
+ project_dir = resolve_project(project_dir)
695
+
696
+ # Lazy imports keep the kiri_core.silver surface off the module-
697
+ # load path for `dv test` / `dv install` callers (same pattern
698
+ # as `dv apply`).
699
+ from kiri_core.silver import (
700
+ build_graph_plan,
701
+ domain_projection,
702
+ dv_graph_view_payload,
703
+ neighborhood_projection,
704
+ overview_projection,
705
+ path_projection,
706
+ render_mermaid,
707
+ zone_projection,
708
+ )
709
+ from kiri_core.silver.dv_graph import DataVaultGraphPlanError
710
+ from kiri_core.silver.dv_graph_views import DvGraphView, DvGraphViewError
711
+
712
+ if output_format not in ("mermaid", "json"):
713
+ raise typer.BadParameter(f"--format must be 'mermaid' or 'json' (got {output_format!r})")
714
+
715
+ try:
716
+ project = load_project(project_dir)
717
+ except Exception as exc:
718
+ _console.print(f"[red]✗[/red] could not load project: {exc}")
719
+ raise typer.Exit(code=2) from exc
720
+
721
+ try:
722
+ plan = build_graph_plan(project)
723
+ except DataVaultGraphPlanError as exc:
724
+ _console.print(f"[red]✗[/red] DV graph plan error: {exc}")
725
+ raise typer.Exit(code=2) from exc
726
+
727
+ if not plan.nodes:
728
+ _console.print("[dim]no Data Vault contracts in this project — nothing to graph[/dim]")
729
+ raise typer.Exit(code=0)
730
+
731
+ try:
732
+ graph_view: DvGraphView = _resolve_view(
733
+ plan,
734
+ view,
735
+ depth,
736
+ overview_projection=overview_projection,
737
+ domain_projection=domain_projection,
738
+ zone_projection=zone_projection,
739
+ neighborhood_projection=neighborhood_projection,
740
+ path_projection=path_projection,
741
+ )
742
+ except DvGraphViewError as exc:
743
+ _console.print(f"[red]✗[/red] {exc}")
744
+ raise typer.Exit(code=2) from exc
745
+ except typer.BadParameter:
746
+ raise
747
+
748
+ if output_format == "json":
749
+ # View-aware JSON. The serialisation rule (overview → bounded
750
+ # rollup; scoped → the DataVaultGraphPlan sub-plan) lives ONCE
751
+ # in kiri_core.silver.dv_graph_payload so this CLI and slice
752
+ # 9c's BFF GET /api/dv/graph?view= never diverge
753
+ # (feedback_kiriapp_cli_no_divergence). `overview` is the
754
+ # bounded rollup — never the leaked unbounded plan; the raw
755
+ # whole-plan wire shape stays on slice 9a's BFF
756
+ # GET /api/dv/graph (no ?view=), the deliberate
757
+ # zero-divergence raw-retrieval surface (Codex review P1-B,
758
+ # 2026-05-15).
759
+ typer.echo(json.dumps(dv_graph_view_payload(graph_view), indent=2))
760
+ raise typer.Exit(code=0)
761
+
762
+ typer.echo(render_mermaid(graph_view, max_nodes=max_nodes))
763
+ raise typer.Exit(code=0)
764
+
765
+
766
+ def _resolve_view(
767
+ plan: Any,
768
+ selector: str,
769
+ depth: int,
770
+ *,
771
+ overview_projection: Any,
772
+ domain_projection: Any,
773
+ zone_projection: Any,
774
+ neighborhood_projection: Any,
775
+ path_projection: Any,
776
+ ) -> Any:
777
+ """Map a ``--view`` selector to the matching projection.
778
+
779
+ Selectors: ``overview`` | ``domain:<d>`` | ``zone:<z>`` |
780
+ ``node:<n>`` | ``path:<a>..<b>``. An unparseable selector is a
781
+ :class:`typer.BadParameter` (exit 2) — operators get a precise
782
+ "did you mean" rather than a silent empty diagram.
783
+ """
784
+
785
+ if selector == "overview":
786
+ return overview_projection(plan)
787
+ prefix, _, rest = selector.partition(":")
788
+ if not rest:
789
+ raise typer.BadParameter(
790
+ f"--view {selector!r} is not a valid selector. Use "
791
+ f"'overview', 'domain:<d>', 'zone:<z>', 'node:<n>', "
792
+ f"or 'path:<a>..<b>'."
793
+ )
794
+ if prefix == "domain":
795
+ return domain_projection(plan, rest)
796
+ if prefix == "zone":
797
+ return zone_projection(plan, rest)
798
+ if prefix == "node":
799
+ return neighborhood_projection(plan, rest, depth=depth)
800
+ if prefix == "path":
801
+ src, sep, dst = rest.partition("..")
802
+ if not sep or not src or not dst:
803
+ raise typer.BadParameter(
804
+ f"--view path selector must be 'path:<a>..<b>' (got {selector!r})."
805
+ )
806
+ return path_projection(plan, src, dst)
807
+ raise typer.BadParameter(
808
+ f"--view {selector!r} has unknown scope {prefix!r}. Use "
809
+ f"'overview', 'domain:<d>', 'zone:<z>', 'node:<n>', or "
810
+ f"'path:<a>..<b>'."
811
+ )
812
+
813
+
814
+ __all__ = ["dv_app"]