branchpy-cli 1.1.19__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.
Files changed (912) hide show
  1. bqf/__init__.py +16 -0
  2. bqf/registry.py +208 -0
  3. branchpy/__init__.py +29 -0
  4. branchpy/__main__.py +4 -0
  5. branchpy/ai/__init__.py +49 -0
  6. branchpy/ai/ai_models.py +65 -0
  7. branchpy/ai/ai_routing.py +119 -0
  8. branchpy/ai/ai_tasks.py +165 -0
  9. branchpy/ai/ast_integration/__init__.py +28 -0
  10. branchpy/ai/ast_integration/ast_context.py +471 -0
  11. branchpy/ai/ast_integration/code_review.py +368 -0
  12. branchpy/ai/ast_integration/explain_warning.py +428 -0
  13. branchpy/ai/ast_integration/refactor_suggester.py +413 -0
  14. branchpy/ai/config.py +203 -0
  15. branchpy/ai/data_guard.py +147 -0
  16. branchpy/ai/models.py +205 -0
  17. branchpy/ai/protocol.py +173 -0
  18. branchpy/ai/provider_base.py +59 -0
  19. branchpy/ai/provider_manager.py +105 -0
  20. branchpy/ai/provider_registry.py +117 -0
  21. branchpy/ai/providers/__init__.py +13 -0
  22. branchpy/ai/providers/anthropic_provider.py +309 -0
  23. branchpy/ai/providers/gemini_provider.py +177 -0
  24. branchpy/ai/providers/http_provider.py +214 -0
  25. branchpy/ai/providers/ollama_provider.py +453 -0
  26. branchpy/ai/providers/openai_provider.py +328 -0
  27. branchpy/ai/providers/venice_provider.py +423 -0
  28. branchpy/ai/request_models.py +38 -0
  29. branchpy/ai/safety/__init__.py +71 -0
  30. branchpy/ai/safety/consent.py +425 -0
  31. branchpy/ai/safety/governance.py +500 -0
  32. branchpy/ai/safety/middleware.py +389 -0
  33. branchpy/ai/safety/policy.py +410 -0
  34. branchpy/ai/safety/provider_validator.py +162 -0
  35. branchpy/ai/safety/redaction.py +345 -0
  36. branchpy/ai/safety/redaction_config.py +157 -0
  37. branchpy/ai/safety/safe_mode.py +215 -0
  38. branchpy/ai/safety/safe_mode_config.py +160 -0
  39. branchpy/ai/service.py +238 -0
  40. branchpy/ai/telemetry.py +81 -0
  41. branchpy/analysis/__init__.py +5 -0
  42. branchpy/analysis/catalog.py +20 -0
  43. branchpy/analysis/flow_graph_analysis.py +2831 -0
  44. branchpy/analysis/group_types.py +156 -0
  45. branchpy/analysis/image_validation/__init__.py +28 -0
  46. branchpy/analysis/image_validation/backends/__init__.py +52 -0
  47. branchpy/analysis/image_validation/backends/clip_backend.py +186 -0
  48. branchpy/analysis/image_validation/backends/phash_backend.py +248 -0
  49. branchpy/analysis/image_validation/benchmarks/README.md +145 -0
  50. branchpy/analysis/image_validation/benchmarks/__init__.py +99 -0
  51. branchpy/analysis/image_validation/benchmarks/benchmark_cache.py +134 -0
  52. branchpy/analysis/image_validation/benchmarks/benchmark_clip.py +92 -0
  53. branchpy/analysis/image_validation/benchmarks/benchmark_e2e.py +130 -0
  54. branchpy/analysis/image_validation/benchmarks/benchmark_phash.py +74 -0
  55. branchpy/analysis/image_validation/cache/__init__.py +8 -0
  56. branchpy/analysis/image_validation/cache/feature_store.py +258 -0
  57. branchpy/analysis/image_validation/clustering.py +231 -0
  58. branchpy/analysis/image_validation/config.py +115 -0
  59. branchpy/analysis/image_validation/embedding_cache.py +196 -0
  60. branchpy/analysis/image_validation/governance_logger.py +932 -0
  61. branchpy/analysis/image_validation/hasher.py +161 -0
  62. branchpy/analysis/image_validation/history.py +275 -0
  63. branchpy/analysis/image_validation/models.py +116 -0
  64. branchpy/analysis/image_validation/performance.slo +41 -0
  65. branchpy/analysis/image_validation/policies_bqf.py +46 -0
  66. branchpy/analysis/image_validation/preprocess.py +312 -0
  67. branchpy/analysis/image_validation/provider_policy.py +174 -0
  68. branchpy/analysis/image_validation/providers_v2/__init__.py +53 -0
  69. branchpy/analysis/image_validation/providers_v2/base.py +442 -0
  70. branchpy/analysis/image_validation/providers_v2/dropbox.py +355 -0
  71. branchpy/analysis/image_validation/providers_v2/errors.py +191 -0
  72. branchpy/analysis/image_validation/providers_v2/gdrive.py +784 -0
  73. branchpy/analysis/image_validation/providers_v2/github.py +256 -0
  74. branchpy/analysis/image_validation/providers_v2/mfiles.py +88 -0
  75. branchpy/analysis/image_validation/providers_v2/onedrive.py +565 -0
  76. branchpy/analysis/image_validation/providers_v2/registry.py +210 -0
  77. branchpy/analysis/image_validation/providers_v2/sync.py +290 -0
  78. branchpy/analysis/image_validation/providers_v2/thumbnails.py +249 -0
  79. branchpy/analysis/image_validation/providers_v2/util.py +273 -0
  80. branchpy/analysis/image_validation/providers_v2/vault.py +857 -0
  81. branchpy/analysis/image_validation/providers_v2/webdav.py +255 -0
  82. branchpy/analysis/image_validation/scanner.py +178 -0
  83. branchpy/analysis/image_validation/semantic/__init__.py +9 -0
  84. branchpy/analysis/image_validation/semantic/linker.py +346 -0
  85. branchpy/analysis/image_validation/semantic/nodes.py +220 -0
  86. branchpy/analysis/image_validation/similarity.py +227 -0
  87. branchpy/analysis/image_validation/tests/__init__.py +10 -0
  88. branchpy/analysis/image_validation/tests/run_tests.py +22 -0
  89. branchpy/analysis/image_validation/tests/test_feature_store.py +174 -0
  90. branchpy/analysis/image_validation/tests/test_integration.py +118 -0
  91. branchpy/analysis/image_validation/tests/test_phash_backend.py +121 -0
  92. branchpy/analysis/image_validation/tests/test_scanner.py +137 -0
  93. branchpy/analysis/image_validation/tests/test_semantic_linker.py +147 -0
  94. branchpy/analysis/image_validation/tests/test_semantic_nodes.py +232 -0
  95. branchpy/analysis/image_validation/v3/__init__.py +30 -0
  96. branchpy/analysis/image_validation/v3/cache_manager.py +290 -0
  97. branchpy/analysis/image_validation/v3/cluster_engine.py +253 -0
  98. branchpy/analysis/image_validation/validator.py +759 -0
  99. branchpy/analysis/observed/trace_ingestor.py +323 -0
  100. branchpy/analysis/omega.py +330 -0
  101. branchpy/analysis/pfi/__init__.py +56 -0
  102. branchpy/analysis/pfi/call_graph.py +217 -0
  103. branchpy/analysis/pfi/call_site_analyzer.py +465 -0
  104. branchpy/analysis/pfi/consistency_checker.py +440 -0
  105. branchpy/analysis/pfi/enhanced_analyzer.py +461 -0
  106. branchpy/analysis/pfi/exporter.py +176 -0
  107. branchpy/analysis/pfi/function_indexer.py +673 -0
  108. branchpy/analysis/pfi/governance.py +416 -0
  109. branchpy/analysis/pfi/stat_effect_analyzer.py +521 -0
  110. branchpy/analysis/sae/__init__.py +31 -0
  111. branchpy/analysis/sae/assets/__init__.py +64 -0
  112. branchpy/analysis/sae/assets/asset_scanner.py +301 -0
  113. branchpy/analysis/sae/assets/csv_export.py +361 -0
  114. branchpy/analysis/sae/assets/definition_extractor.py +160 -0
  115. branchpy/analysis/sae/assets/dimension_validator.py +370 -0
  116. branchpy/analysis/sae/assets/fuzzy.py +168 -0
  117. branchpy/analysis/sae/assets/governance.py +289 -0
  118. branchpy/analysis/sae/assets/models.py +166 -0
  119. branchpy/analysis/sae/assets/reference_extractor.py +271 -0
  120. branchpy/analysis/sae/assets/similarity.py +403 -0
  121. branchpy/analysis/sae/assets/sync_provider.py +471 -0
  122. branchpy/analysis/sae/assets/validators/__init__.py +1 -0
  123. branchpy/analysis/sae/assets/validators/assets_format_validator.py +258 -0
  124. branchpy/analysis/sae/assets/validators/assets_fuzzy_typo_validator.py +132 -0
  125. branchpy/analysis/sae/assets/validators/assets_missing_validator.py +194 -0
  126. branchpy/analysis/sae/assets/validators/assets_unused_validator.py +179 -0
  127. branchpy/analysis/sae/assignment_extractor.py +1220 -0
  128. branchpy/analysis/sae/cfg_builder.py +1221 -0
  129. branchpy/analysis/sae/config_schema.py +499 -0
  130. branchpy/analysis/sae/custom_rule_loader.py +269 -0
  131. branchpy/analysis/sae/custom_rule_registry.py +304 -0
  132. branchpy/analysis/sae/dataflow.py +281 -0
  133. branchpy/analysis/sae/exporters/__init__.py +5 -0
  134. branchpy/analysis/sae/exporters/flowgraph.py +99 -0
  135. branchpy/analysis/sae/exporters/unified_report.py +248 -0
  136. branchpy/analysis/sae/finding_adapter.py +83 -0
  137. branchpy/analysis/sae/finding_postprocess.py +241 -0
  138. branchpy/analysis/sae/graphs/__init__.py +14 -0
  139. branchpy/analysis/sae/graphs/variable_graph.py +259 -0
  140. branchpy/analysis/sae/image_validator.py +346 -0
  141. branchpy/analysis/sae/indexer.py +1043 -0
  142. branchpy/analysis/sae/job.py +268 -0
  143. branchpy/analysis/sae/locale_parser.py +267 -0
  144. branchpy/analysis/sae/project_policy.py +326 -0
  145. branchpy/analysis/sae/registry.py +63 -0
  146. branchpy/analysis/sae/renderers/html_assets_section.py +100 -0
  147. branchpy/analysis/sae/report_v1.py +93 -0
  148. branchpy/analysis/sae/schemas/analyze_report_v1.json +225 -0
  149. branchpy/analysis/sae/schemas/assets_report.json +161 -0
  150. branchpy/analysis/sae/schemas/flowgraph.json +134 -0
  151. branchpy/analysis/sae/schemas/job.json +118 -0
  152. branchpy/analysis/sae/schemas/unified_report.json +213 -0
  153. branchpy/analysis/sae/screen_return_resolver.py +758 -0
  154. branchpy/analysis/sae/semantics.py +218 -0
  155. branchpy/analysis/sae/statement_extractor.py +1107 -0
  156. branchpy/analysis/sae/validators/__init__.py +5 -0
  157. branchpy/analysis/sae/validators/dialogue_validator.py +839 -0
  158. branchpy/analysis/sae/validators/locale_validator.py +306 -0
  159. branchpy/analysis/sae/validators/menu_fallthrough_validator.py +318 -0
  160. branchpy/analysis/sae/validators/screen_action_validator.py +68 -0
  161. branchpy/analysis/sae/validators/tier1.py +783 -0
  162. branchpy/analysis/sae/validators/variable_analyzer.py +909 -0
  163. branchpy/analysis/sae/variable_usage_extractor.py +405 -0
  164. branchpy/analysis/sae/worker.py +535 -0
  165. branchpy/analysis/semantic_edges.py +743 -0
  166. branchpy/analysis/semantic_grouping.py +721 -0
  167. branchpy/analysis/stats2/__init__.py +46 -0
  168. branchpy/analysis/stats2/aggregator.py +516 -0
  169. branchpy/analysis/stats2/assignment_extractor.py +207 -0
  170. branchpy/analysis/stats2/compute.py +161 -0
  171. branchpy/analysis/stats2/exporter.py +301 -0
  172. branchpy/analysis/stats2/expr_evaluator.py +160 -0
  173. branchpy/analysis/stats2/expr_parser.py +250 -0
  174. branchpy/analysis/stats2/narrative_paths.py +1599 -0
  175. branchpy/analysis/stats2/path_stats.py +817 -0
  176. branchpy/analysis/stats2/ranges.py +141 -0
  177. branchpy/analysis/stats2/registry.py +72 -0
  178. branchpy/analysis/variable_flow.py +589 -0
  179. branchpy/analyze/engines/generic_media.py +348 -0
  180. branchpy/analyze/engines/godot_media.py +451 -0
  181. branchpy/analyze/engines/renpy_media.py +705 -0
  182. branchpy/analyze/engines/unity_media.py +447 -0
  183. branchpy/analyze/media_adapters/__init__.py +164 -0
  184. branchpy/analyze/media_adapters/generic_media.py +125 -0
  185. branchpy/analyze/media_adapters/godot_media.py +141 -0
  186. branchpy/analyze/media_adapters/renpy_phase_c_adapter.py +286 -0
  187. branchpy/analyze/media_adapters/unity_media.py +159 -0
  188. branchpy/analyze/media_adapters.py +286 -0
  189. branchpy/analyze/media_export.py +441 -0
  190. branchpy/analyze/media_phase_c_contract.py +372 -0
  191. branchpy/analyze/media_validate.py +333 -0
  192. branchpy/analyze/pfi/__init__.py +9 -0
  193. branchpy/analyze/pfi/media_inference.py +211 -0
  194. branchpy/analyze/pfi/media_inference_scaffold.py +383 -0
  195. branchpy/analyzer/ast_to_scriptgraph.py +151 -0
  196. branchpy/analyzer/flow_delta.py +385 -0
  197. branchpy/analyzer/media_indexer.py +235 -0
  198. branchpy/analyzer/merge_risk_analyzer.py +404 -0
  199. branchpy/analyzer/narrative_impact.py +414 -0
  200. branchpy/analyzer/parser.py +212 -0
  201. branchpy/analyzer/pfi_expressions.py +524 -0
  202. branchpy/analyzer/pfi_inference.py +730 -0
  203. branchpy/analyzer/providers.py +289 -0
  204. branchpy/analyzer/remote_context.py +136 -0
  205. branchpy/analyzer/remote_paths.py +278 -0
  206. branchpy/analyzer/script_graph.py +777 -0
  207. branchpy/analyzers/scene_coverage_analyzer_telemetry_example.py +294 -0
  208. branchpy/artifact_freshness.py +200 -0
  209. branchpy/attribution.py +123 -0
  210. branchpy/audit/verify_commit.py +35 -0
  211. branchpy/auto_detect/__init__.py +40 -0
  212. branchpy/auto_detect/events.py +344 -0
  213. branchpy/auto_detect/pattern_miner.py +730 -0
  214. branchpy/auto_detect/policy_scaffolder.py +637 -0
  215. branchpy/auto_detect/recommendation_engine.py +463 -0
  216. branchpy/auto_detect/rule_inference.py +613 -0
  217. branchpy/benchmarks/suite.py +327 -0
  218. branchpy/bootstrap.py +20 -0
  219. branchpy/bqf/__init__.py +19 -0
  220. branchpy/bqf/context_mapping.py +128 -0
  221. branchpy/bqf/models_ai.py +24 -0
  222. branchpy/bqf/policies/__init__.py +33 -0
  223. branchpy/bqf/policies/compare/__init__.py +5 -0
  224. branchpy/bqf/policies/compare/similarity_floor.py +162 -0
  225. branchpy/bqf/policies/media/__init__.py +6 -0
  226. branchpy/bqf/policies/media/checksum_verified.py +185 -0
  227. branchpy/bqf/policies/media/duplicate_cap.py +160 -0
  228. branchpy/bqf/policies/media_policies.py +320 -0
  229. branchpy/bqf/policies_ai.py +144 -0
  230. branchpy/bqf/policy_base.py +302 -0
  231. branchpy/bqf/policy_config.example.toml +30 -0
  232. branchpy/bqf/policy_config.example.yaml +38 -0
  233. branchpy/bqf/policy_enforcer.py +487 -0
  234. branchpy/bqf/registry.py +237 -0
  235. branchpy/bqf/rules/missing_media_reference.json +67 -0
  236. branchpy/bqf/rules/unused_media_file.json +69 -0
  237. branchpy/bqf/runner.py +182 -0
  238. branchpy/bqf/runner_ai.py +167 -0
  239. branchpy/bqf/semantic_policy.py +325 -0
  240. branchpy/cache/__init__.py +52 -0
  241. branchpy/cache/backends/__init__.py +20 -0
  242. branchpy/cache/backends/base.py +148 -0
  243. branchpy/cache/backends/memory.py +229 -0
  244. branchpy/cache/backends/redis.py +309 -0
  245. branchpy/cache/backends/sqlite.py +292 -0
  246. branchpy/cache/decorators.py +266 -0
  247. branchpy/cache/keys.py +92 -0
  248. branchpy/cache/manager.py +281 -0
  249. branchpy/cfg_viewer/__init__.py +19 -0
  250. branchpy/cfg_viewer/cfg_collapse.py +463 -0
  251. branchpy/cfg_viewer/cfg_exporter.py +196 -0
  252. branchpy/cfg_viewer/cfg_to_graphviz.py +294 -0
  253. branchpy/choice_analyzer.py +286 -0
  254. branchpy/cli/__init__.py +40 -0
  255. branchpy/cli/__main__.py +41 -0
  256. branchpy/cli/ai_cli.py +426 -0
  257. branchpy/cli/ai_cmd.py +382 -0
  258. branchpy/cli/audit_cmd.py +316 -0
  259. branchpy/cli/audit_diff_cmd.py +75 -0
  260. branchpy/cli/cloud_cli.py +220 -0
  261. branchpy/cli/commands/__init__.py +8 -0
  262. branchpy/cli/commands/ai_cmd.py +388 -0
  263. branchpy/cli/commands/ai_patch_cmd.py +479 -0
  264. branchpy/cli/commands/ai_report_cmd.py +249 -0
  265. branchpy/cli/commands/auto_detect_cmd.py +410 -0
  266. branchpy/cli/commands/bqf_rules_cmd.py +455 -0
  267. branchpy/cli/commands/export_media_cmd.py +169 -0
  268. branchpy/cli/commands/federation_cmd.py +297 -0
  269. branchpy/cli/commands/identity_hub_cmd.py +210 -0
  270. branchpy/cli/commands/journal_cmd.py +59 -0
  271. branchpy/cli/commands/l10n_audit_cmd.py +957 -0
  272. branchpy/cli/commands/l10n_trend_cmd.py +771 -0
  273. branchpy/cli/commands/license_cmd.py +741 -0
  274. branchpy/cli/commands/merge_cmd.py +273 -0
  275. branchpy/cli/commands/patch_cmd.py +586 -0
  276. branchpy/cli/commands/projects_hub_cmd.py +229 -0
  277. branchpy/cli/commands/redo_cmd.py +59 -0
  278. branchpy/cli/commands/semantics_v2_cmd.py +1715 -0
  279. branchpy/cli/commands/stats_policies_cmd.py +492 -0
  280. branchpy/cli/commands/telemetry_sync.py +178 -0
  281. branchpy/cli/commands/templates_cmd.py +427 -0
  282. branchpy/cli/commands/undo_cmd.py +62 -0
  283. branchpy/cli/commands/ws_cmd.py +326 -0
  284. branchpy/cli/coverage_cmd_minimal.py +282 -0
  285. branchpy/cli/debug_cmd.py +70 -0
  286. branchpy/cli/hooks_cmd.py +30 -0
  287. branchpy/cli/html_report.py +3461 -0
  288. branchpy/cli/identity_cmd.py +117 -0
  289. branchpy/cli/l10n_cmd.py +337 -0
  290. branchpy/cli/migrate_cmd.py +217 -0
  291. branchpy/cli/policy_cmd.py +377 -0
  292. branchpy/cli/rule_versioning_cli.py +446 -0
  293. branchpy/cli/rules_cmd.py +198 -0
  294. branchpy/cli/sae_cmd.py +141 -0
  295. branchpy/cli/serve_cmd.py +34 -0
  296. branchpy/cli/server_cmd.py +352 -0
  297. branchpy/cli/team_cmd.py +282 -0
  298. branchpy/cli/telemetry_cmd.py +2462 -0
  299. branchpy/cli/test_cli.py +170 -0
  300. branchpy/cli.py +1898 -0
  301. branchpy/cli_help.py +16 -0
  302. branchpy/cli_update.py +42 -0
  303. branchpy/cloud/mock_env.py +186 -0
  304. branchpy/commands/__init__.py +0 -0
  305. branchpy/commands/ai_cmd.py +532 -0
  306. branchpy/commands/analyze_cmd.py +1890 -0
  307. branchpy/commands/analyzer_media_cmd.py +179 -0
  308. branchpy/commands/audit_cmd.py +342 -0
  309. branchpy/commands/bootstrap_cmd.py +121 -0
  310. branchpy/commands/cmd_activate.py +28 -0
  311. branchpy/commands/cmd_deactivate.py +37 -0
  312. branchpy/commands/cmd_status.py +32 -0
  313. branchpy/commands/cmd_test.py +365 -0
  314. branchpy/commands/compare_cmd.py +443 -0
  315. branchpy/commands/compare_preview_cmd.py +407 -0
  316. branchpy/commands/config_cmd.py +343 -0
  317. branchpy/commands/dev_cmd.py +263 -0
  318. branchpy/commands/doctor_cmd.py +2189 -0
  319. branchpy/commands/doctor_cmd_old.py +561 -0
  320. branchpy/commands/enhanced_report.py +274 -0
  321. branchpy/commands/flowchart_cmd.py +181 -0
  322. branchpy/commands/guard_cmd.py +430 -0
  323. branchpy/commands/help_cmd.py +169 -0
  324. branchpy/commands/helpers.py +33 -0
  325. branchpy/commands/history_cmd.py +897 -0
  326. branchpy/commands/identity_cmd.py +192 -0
  327. branchpy/commands/image_semantic_cmd.py +386 -0
  328. branchpy/commands/image_validate_cmd.py +806 -0
  329. branchpy/commands/insights_cmd.py +443 -0
  330. branchpy/commands/interactive_diff_cmd.py +102 -0
  331. branchpy/commands/l10n_cmd.py +268 -0
  332. branchpy/commands/logs_cmd.py +249 -0
  333. branchpy/commands/media.py +139 -0
  334. branchpy/commands/media_cmd.py +1454 -0
  335. branchpy/commands/media_v3_cmd.py +605 -0
  336. branchpy/commands/migrate_cmd.py +229 -0
  337. branchpy/commands/omega_cmd.py +335 -0
  338. branchpy/commands/patch_state.py +41 -0
  339. branchpy/commands/patches_cmd.py +195 -0
  340. branchpy/commands/pfi_cmd.py +266 -0
  341. branchpy/commands/policy_cmd.py +258 -0
  342. branchpy/commands/project_resolver.py +76 -0
  343. branchpy/commands/projects_cmd.py +124 -0
  344. branchpy/commands/provider_cmd.py +740 -0
  345. branchpy/commands/provider_v3_cmd.py +556 -0
  346. branchpy/commands/redo_cmd.py +95 -0
  347. branchpy/commands/renpy_cmd.py +357 -0
  348. branchpy/commands/report_cmd.py +197 -0
  349. branchpy/commands/semantics_cmd.py +305 -0
  350. branchpy/commands/semantics_engine_cmd.py +263 -0
  351. branchpy/commands/serve_cmd.py +741 -0
  352. branchpy/commands/stats2_cmd.py +931 -0
  353. branchpy/commands/stats_cmd.py +1517 -0
  354. branchpy/commands/support_cmd.py +97 -0
  355. branchpy/commands/tests_cmd.py +418 -0
  356. branchpy/commands/trace_cmd.py +518 -0
  357. branchpy/commands/undo_cmd.py +95 -0
  358. branchpy/commands/uninstall_cmd.py +230 -0
  359. branchpy/commands/validate_cmd.py +219 -0
  360. branchpy/commands/watch_cmd.py +129 -0
  361. branchpy/commands/welcome_cmd.py +482 -0
  362. branchpy/compare/analyzer.py +202 -0
  363. branchpy/compare/compare_media_integration.py +143 -0
  364. branchpy/compare/constants.py +70 -0
  365. branchpy/compare/media_diff_engine.py +331 -0
  366. branchpy/compare/media_diff_types.py +118 -0
  367. branchpy/completeness_checker.py +363 -0
  368. branchpy/config.py +235 -0
  369. branchpy/config_store.py +322 -0
  370. branchpy/contract.py +37 -0
  371. branchpy/core/__init__.py +25 -0
  372. branchpy/core/audit.py +791 -0
  373. branchpy/core/cfg.py +90 -0
  374. branchpy/core/compare/__init__.py +42 -0
  375. branchpy/core/compare/alignment.py +296 -0
  376. branchpy/core/compare/anchors.py +229 -0
  377. branchpy/core/compare/exporter.py +458 -0
  378. branchpy/core/compare/guard_normalizer.py +157 -0
  379. branchpy/core/compare/pfi_integration.py +339 -0
  380. branchpy/core/compare/preview_engine.py +241 -0
  381. branchpy/core/compare/row_emitter.py +217 -0
  382. branchpy/core/compare/semantic_types.py +204 -0
  383. branchpy/core/compare/tape_builder.py +264 -0
  384. branchpy/core/config.py +19 -0
  385. branchpy/core/crash_report.py +15 -0
  386. branchpy/core/diffing.py +220 -0
  387. branchpy/core/engine_interface.py +34 -0
  388. branchpy/core/engine_resolver.py +406 -0
  389. branchpy/core/fs.py +43 -0
  390. branchpy/core/governance/README.md +475 -0
  391. branchpy/core/governance/__init__.py +46 -0
  392. branchpy/core/governance/__main__.py +156 -0
  393. branchpy/core/governance/audit_exporter.py +340 -0
  394. branchpy/core/governance/audit_hooks.py +210 -0
  395. branchpy/core/governance/benchmark_decorator_overhead.py +147 -0
  396. branchpy/core/governance/certificates.py +242 -0
  397. branchpy/core/governance/denial_history.py +461 -0
  398. branchpy/core/governance/denial_suggestions.py +311 -0
  399. branchpy/core/governance/guards.py +332 -0
  400. branchpy/core/governance/integrity.py +221 -0
  401. branchpy/core/governance/logger.py +471 -0
  402. branchpy/core/governance/policy_engine.py +305 -0
  403. branchpy/core/governance/schemas.py +217 -0
  404. branchpy/core/governance/standard_command_enforcement.py +276 -0
  405. branchpy/core/governance/team_manager.py +171 -0
  406. branchpy/core/history/README.md +217 -0
  407. branchpy/core/history/__init__.py +150 -0
  408. branchpy/core/history/compression.py +436 -0
  409. branchpy/core/history/consolidation_daemon.py +627 -0
  410. branchpy/core/history/delta_reconstructor.py +672 -0
  411. branchpy/core/history/diff_engine.py +637 -0
  412. branchpy/core/history/diff_export.py +938 -0
  413. branchpy/core/history/governance_bridge.py +473 -0
  414. branchpy/core/history/governance_diff.py +675 -0
  415. branchpy/core/history/merge_engine.py +791 -0
  416. branchpy/core/history/persistence.py +483 -0
  417. branchpy/core/history/sample_config.json +32 -0
  418. branchpy/core/history/sample_governance_event.json +22 -0
  419. branchpy/core/history/sample_history.jsonl +5 -0
  420. branchpy/core/history/sample_snapshot.json +144 -0
  421. branchpy/core/history/snapshot.py +834 -0
  422. branchpy/core/history/snapshot_optimizer.py +518 -0
  423. branchpy/core/history/stack.py +408 -0
  424. branchpy/core/history/timeline.py +484 -0
  425. branchpy/core/jsonio.py +40 -0
  426. branchpy/core/patches.py +442 -0
  427. branchpy/core/paths.py +18 -0
  428. branchpy/core/paths_v2.py +371 -0
  429. branchpy/core/perf_profiler.py +255 -0
  430. branchpy/core/plugins.py +299 -0
  431. branchpy/core/project_model.py +48 -0
  432. branchpy/core/remote_context.py +428 -0
  433. branchpy/core/renderer.py +162 -0
  434. branchpy/core/reports.py +209 -0
  435. branchpy/core/semantics/__init__.py +49 -0
  436. branchpy/core/semantics/definitions.py +337 -0
  437. branchpy/core/semantics/function_provider.py +296 -0
  438. branchpy/core/semantics/migration.py +362 -0
  439. branchpy/core/semantics/registry.py +234 -0
  440. branchpy/core/semantics/semantic_action.py +130 -0
  441. branchpy/core/semantics/semantic_node.py +85 -0
  442. branchpy/core/semantics/trace_exporter.py +190 -0
  443. branchpy/core/snapshot.py +22 -0
  444. branchpy/core/telemetry.py +35 -0
  445. branchpy/credential_vault/legacy_shim.py +282 -0
  446. branchpy/credential_vault/migrate.py +348 -0
  447. branchpy/credential_vault/schema_v3.json +250 -0
  448. branchpy/credential_vault/vault_v2.py +384 -0
  449. branchpy/daemon/context.py +127 -0
  450. branchpy/daemon/routes_governance.py +482 -0
  451. branchpy/daemon/routes_history.py +1090 -0
  452. branchpy/daemon/routes_validation.py +350 -0
  453. branchpy/daemon/shutdown.py +47 -0
  454. branchpy/dashboard/websocket_server.py +348 -0
  455. branchpy/database.py +55 -0
  456. branchpy/discovery/__init__.py +31 -0
  457. branchpy/discovery/base.py +256 -0
  458. branchpy/discovery/cache.py +322 -0
  459. branchpy/discovery/detectors/__init__.py +13 -0
  460. branchpy/discovery/detectors/godot.py +18 -0
  461. branchpy/discovery/detectors/renpy.py +67 -0
  462. branchpy/discovery/detectors/unity.py +18 -0
  463. branchpy/discovery/detectors/unreal.py +18 -0
  464. branchpy/discovery/orchestrator.py +252 -0
  465. branchpy/discovery/tests/__init__.py +1 -0
  466. branchpy/discovery/tests/test_ambiguity_and_metadata.py +121 -0
  467. branchpy/discovery/tests/test_base.py +85 -0
  468. branchpy/discovery/tests/test_cache_correctness.py +232 -0
  469. branchpy/discovery/tests/test_cache_performance.py +143 -0
  470. branchpy/discovery/tests/test_orchestrator.py +98 -0
  471. branchpy/discovery/tests/test_override_policy.py +119 -0
  472. branchpy/discovery/tests/test_renpy_detector.py +131 -0
  473. branchpy/doctor/omega_artifacts.py +155 -0
  474. branchpy/emit.py +54 -0
  475. branchpy/engines/__init__.py +5 -0
  476. branchpy/engines/phase5_debug.txt +4 -0
  477. branchpy/engines/renpy_cfg.py +320 -0
  478. branchpy/engines/renpy_engine.py +2986 -0
  479. branchpy/engines/renpy_metadata_extractor.py +302 -0
  480. branchpy/engines/renpy_script_reads.py +215 -0
  481. branchpy/engines/renpy_ui_exposure_extractor.py +425 -0
  482. branchpy/engines/variable_detector.py +134 -0
  483. branchpy/errors.py +57 -0
  484. branchpy/explorers/__init__.py +28 -0
  485. branchpy/explorers/cache_manager.py +159 -0
  486. branchpy/explorers/label_fingerprints.py +264 -0
  487. branchpy/explorers/menu_nesting.py +429 -0
  488. branchpy/explorers/static_renpy_explorer.py +516 -0
  489. branchpy/export/destinations/__init__.py +179 -0
  490. branchpy/export/destinations/azure.py +192 -0
  491. branchpy/export/destinations/base.py +218 -0
  492. branchpy/export/destinations/gcs.py +173 -0
  493. branchpy/export/destinations/github.py +154 -0
  494. branchpy/export/destinations/local.py +242 -0
  495. branchpy/export/destinations/retention.py +156 -0
  496. branchpy/export/destinations/s3.py +194 -0
  497. branchpy/federation/__init__.py +61 -0
  498. branchpy/federation/config.py +176 -0
  499. branchpy/federation/federation.toml.example +102 -0
  500. branchpy/federation/importer.py +289 -0
  501. branchpy/federation/serializer.py +168 -0
  502. branchpy/federation/signed_links.py +276 -0
  503. branchpy/fp_logger.py +110 -0
  504. branchpy/git/__init__.py +1 -0
  505. branchpy/git/diff_tools.py +57 -0
  506. branchpy/git/hooks.py +44 -0
  507. branchpy/git/trailers.py +28 -0
  508. branchpy/governance/__init__.py +52 -0
  509. branchpy/governance/capabilities.py +39 -0
  510. branchpy/governance/hooks.py +82 -0
  511. branchpy/governance/template_apply.py +401 -0
  512. branchpy/governance/template_index.py +289 -0
  513. branchpy/governance/template_loader.py +338 -0
  514. branchpy/graph_builder.py +479 -0
  515. branchpy/history/__init__.py +24 -0
  516. branchpy/history/journal.py +112 -0
  517. branchpy/history/patch.py +206 -0
  518. branchpy/history/patch_helpers.py +292 -0
  519. branchpy/history/timeline.py +242 -0
  520. branchpy/hub/__init__.py +46 -0
  521. branchpy/hub/hub_client.py +762 -0
  522. branchpy/hub/local_state.py +413 -0
  523. branchpy/hub/models.py +378 -0
  524. branchpy/identity/__init__.py +35 -0
  525. branchpy/identity/local_provider.py +273 -0
  526. branchpy/identity/provider.py +135 -0
  527. branchpy/identity/session.py +226 -0
  528. branchpy/image_validation_v3/__init__.py +48 -0
  529. branchpy/image_validation_v3/cli.py +219 -0
  530. branchpy/image_validation_v3/cluster_engine.py +269 -0
  531. branchpy/image_validation_v3/cluster_v3.py +634 -0
  532. branchpy/image_validation_v3/feature_store.py +462 -0
  533. branchpy/image_validation_v3/media.defaults.json +95 -0
  534. branchpy/image_validation_v3/providers.py +86 -0
  535. branchpy/image_validation_v3/providers_v2/__init__.py +22 -0
  536. branchpy/image_validation_v3/providers_v2/adapters/__init__.py +1 -0
  537. branchpy/image_validation_v3/providers_v2/adapters/dropbox.py +291 -0
  538. branchpy/image_validation_v3/providers_v2/adapters/gdrive.py +303 -0
  539. branchpy/image_validation_v3/providers_v2/adapters/github.py +382 -0
  540. branchpy/image_validation_v3/providers_v2/adapters/mfiles.py +284 -0
  541. branchpy/image_validation_v3/providers_v2/adapters/onedrive.py +297 -0
  542. branchpy/image_validation_v3/providers_v2/adapters/webdav.py +321 -0
  543. branchpy/image_validation_v3/providers_v2/base.py +205 -0
  544. branchpy/image_validation_v3/providers_v2/credentials.py +269 -0
  545. branchpy/image_validation_v3/providers_v2/registry.py +187 -0
  546. branchpy/image_validation_v3/semantic_linker.py +327 -0
  547. branchpy/image_validation_v3/similarity.py +532 -0
  548. branchpy/image_validation_v3/validator.py +312 -0
  549. branchpy/insight_summary.py +485 -0
  550. branchpy/interactive_diff.py +160 -0
  551. branchpy/interactive_diff_adapter.py +226 -0
  552. branchpy/interfaces/runtime.py +19 -0
  553. branchpy/interfaces/semantic.py +25 -0
  554. branchpy/internals/__init__.py +3 -0
  555. branchpy/internals/graph_builder.py +485 -0
  556. branchpy/internals/story_validator.py +618 -0
  557. branchpy/l10n/__init__.py +17 -0
  558. branchpy/l10n/coverage.py +82 -0
  559. branchpy/l10n/extractor.py +186 -0
  560. branchpy/l10n/findings.py +119 -0
  561. branchpy/l10n/quality_rules.py +521 -0
  562. branchpy/license/__init__.py +69 -0
  563. branchpy/license/auth.py +569 -0
  564. branchpy/license/detection.py +192 -0
  565. branchpy/license/device.py +139 -0
  566. branchpy/license/entitlements.py +462 -0
  567. branchpy/license/exceptions.py +60 -0
  568. branchpy/license/gating.py +433 -0
  569. branchpy/license/keys.py +82 -0
  570. branchpy/license/snapshot.py +250 -0
  571. branchpy/license/status_core.py +271 -0
  572. branchpy/license.py +75 -0
  573. branchpy/license_manager.py +130 -0
  574. branchpy/localization/__init__.py +10 -0
  575. branchpy/localization/coverage_history.py +244 -0
  576. branchpy/localization/coverage_utils.py +290 -0
  577. branchpy/localization/trend_visualizer.py +770 -0
  578. branchpy/localization/validators.py +319 -0
  579. branchpy/localization/weighted_policy.py +500 -0
  580. branchpy/logging_setup.py +102 -0
  581. branchpy/logs.py +932 -0
  582. branchpy/media/dynamic_path_extractor.py +595 -0
  583. branchpy/media/media_events.py +136 -0
  584. branchpy/media/media_slo.py +174 -0
  585. branchpy/media/providers.py +579 -0
  586. branchpy/media/remote_context.py +138 -0
  587. branchpy/media/remote_paths.py +86 -0
  588. branchpy/media/scanner_cache.py +473 -0
  589. branchpy/media/scanner_integration.py +153 -0
  590. branchpy/media_analyzer.py +554 -0
  591. branchpy/media_renpy.py +977 -0
  592. branchpy/merge/__init__.py +26 -0
  593. branchpy/merge/merge_engine.py +508 -0
  594. branchpy/obs.py +181 -0
  595. branchpy/omega/__init__.py +121 -0
  596. branchpy/omega/derived_variables.py +376 -0
  597. branchpy/omega/domains.py +435 -0
  598. branchpy/omega/edit_cardinality.py +245 -0
  599. branchpy/omega/metrics_export.py +213 -0
  600. branchpy/omega/omega_report.py +301 -0
  601. branchpy/omega/pf_contextual.py +533 -0
  602. branchpy/omega/state_width.py +548 -0
  603. branchpy/omega/symbol_audit.py +292 -0
  604. branchpy/omega/visibility.py +293 -0
  605. branchpy/parser.py +162 -0
  606. branchpy/patch_state.py +40 -0
  607. branchpy/patch_store.py +87 -0
  608. branchpy/patches/__init__.py +120 -0
  609. branchpy/patches/autofix.py +587 -0
  610. branchpy/patches/engine.py +790 -0
  611. branchpy/patches/git_integration.py +432 -0
  612. branchpy/patches/models.py +469 -0
  613. branchpy/patches/storage.py +441 -0
  614. branchpy/paths.py +47 -0
  615. branchpy/performance/optimizations.py +278 -0
  616. branchpy/pilot/adapters.py +135 -0
  617. branchpy/pilot/collect_call_index.py +180 -0
  618. branchpy/pilot/sae_cfg_adapter.py +131 -0
  619. branchpy/plugins/git_safeguards/__init__.py +87 -0
  620. branchpy/plugins/git_safeguards/manifest.toml +94 -0
  621. branchpy/policy/__init__.py +14 -0
  622. branchpy/policy/eval.py +231 -0
  623. branchpy/policy/loader.py +40 -0
  624. branchpy/policy/rules.py +56 -0
  625. branchpy/policy/schema.toml +21 -0
  626. branchpy/policy/schemas/policy-v1.schema.json +110 -0
  627. branchpy/policy/schemas/team-v1.schema.json +97 -0
  628. branchpy/policy/templates/permissive.json +34 -0
  629. branchpy/policy/templates/strict-enforcement.json +76 -0
  630. branchpy/prerequisite_chain.py +250 -0
  631. branchpy/project.py +23 -0
  632. branchpy/project_config.py +476 -0
  633. branchpy/project_resolver.py +65 -0
  634. branchpy/providers/__init__.py +35 -0
  635. branchpy/providers/_telemetry.py +155 -0
  636. branchpy/providers/base.py +391 -0
  637. branchpy/providers/dropbox.py +659 -0
  638. branchpy/providers/mfiles.py +455 -0
  639. branchpy/providers/onedrive.py +814 -0
  640. branchpy/providers/webdav.py +649 -0
  641. branchpy/quickfix/add_type_hints.py +498 -0
  642. branchpy/quickfix/call_graph_viz.py +539 -0
  643. branchpy/quickfix/convert_fstring.py +287 -0
  644. branchpy/quickfix/extract_variable.py +341 -0
  645. branchpy/quickfix/inline_variable.py +303 -0
  646. branchpy/quickfix/split_long_line.py +279 -0
  647. branchpy/rbac/__init__.py +33 -0
  648. branchpy/rbac/config_loader.py +394 -0
  649. branchpy/rbac/permissions.py +167 -0
  650. branchpy/rbac/rbac_service.py +379 -0
  651. branchpy/reachability_analyzer.py +298 -0
  652. branchpy/remote/__init__.py +49 -0
  653. branchpy/remote/bootstrap/__init__.py +193 -0
  654. branchpy/remote/bootstrap/ci.py +165 -0
  655. branchpy/remote/bootstrap/codespaces.py +169 -0
  656. branchpy/remote/bootstrap/container.py +173 -0
  657. branchpy/remote/bootstrap/local_noop.py +59 -0
  658. branchpy/remote/bootstrap/models.py +79 -0
  659. branchpy/remote/bootstrap/ssh.py +161 -0
  660. branchpy/remote/bootstrap/strategies.py +17 -0
  661. branchpy/remote/bootstrap/wsl.py +138 -0
  662. branchpy/remote/bootstrap_doctor.py +799 -0
  663. branchpy/remote/cache.py +86 -0
  664. branchpy/remote/context.py +161 -0
  665. branchpy/remote/detector.py +416 -0
  666. branchpy/remote/path_mapper.py +99 -0
  667. branchpy/renderer/__init__.py +16 -0
  668. branchpy/renderer/base.py +83 -0
  669. branchpy/renderer/html.py +62 -0
  670. branchpy/renderer/json.py +30 -0
  671. branchpy/renderer/templates/analyze.html +370 -0
  672. branchpy/renderer/templates/base.html +37 -0
  673. branchpy/renderer/templates/compare.html +23 -0
  674. branchpy/renderer/templates/partials/l10n_coverage.html +66 -0
  675. branchpy/renderer/templates/stats.html +18 -0
  676. branchpy/renpy_sdk.py +447 -0
  677. branchpy/report.py +118 -0
  678. branchpy/report_writer.py +265 -0
  679. branchpy/rules/__init__.py +1 -0
  680. branchpy/rules/registry.py +47 -0
  681. branchpy/rules/v2/__init__.py +31 -0
  682. branchpy/rules/v2/api.py +265 -0
  683. branchpy/rules/v2/builtins/__init__.py +7 -0
  684. branchpy/rules/v2/builtins/header_comment_required.py +109 -0
  685. branchpy/rules/v2/builtins/image_namespace_style.py +115 -0
  686. branchpy/rules/v2/builtins/label_naming_style.py +151 -0
  687. branchpy/rules/v2/builtins/missing_image.py +194 -0
  688. branchpy/rules/v2/builtins/missing_image_definition.py +148 -0
  689. branchpy/rules/v2/builtins/naming_conventions.py +109 -0
  690. branchpy/rules/v2/builtins/patterns/__init__.py +27 -0
  691. branchpy/rules/v2/builtins/patterns/anti_patterns.py +741 -0
  692. branchpy/rules/v2/builtins/performance_limits.py +126 -0
  693. branchpy/rules/v2/builtins/test_coverage_missing.py +101 -0
  694. branchpy/rules/v2/context.py +252 -0
  695. branchpy/rules/v2/loader.py +294 -0
  696. branchpy/rules/v2/registry.py +95 -0
  697. branchpy/rules/v2/types.py +265 -0
  698. branchpy/run_context.py +81 -0
  699. branchpy/runners/__init__.py +28 -0
  700. branchpy/runners/checkpoint_manager.py +127 -0
  701. branchpy/runners/event_router.py +118 -0
  702. branchpy/runners/renpy_runner.py +750 -0
  703. branchpy/runners/trace_tailer.py +150 -0
  704. branchpy/sae/__init__.py +73 -0
  705. branchpy/sae/effects.py +42 -0
  706. branchpy/sae/guards.py +381 -0
  707. branchpy/sae/interpreter.py +210 -0
  708. branchpy/sae/lattice.py +62 -0
  709. branchpy/sae/merger.py +77 -0
  710. branchpy/sae/reconstruct.py +293 -0
  711. branchpy/sae/report.py +130 -0
  712. branchpy/sae/solver.py +408 -0
  713. branchpy/sae/state_tracker.py +608 -0
  714. branchpy/sae/unified_report_schema_v0_8_4.json +177 -0
  715. branchpy/save_point_analyzer.py +291 -0
  716. branchpy/scan_context.py +80 -0
  717. branchpy/sdk/__init__.py +111 -0
  718. branchpy/sdk/media.py +466 -0
  719. branchpy/semantics/__init__.py +1 -0
  720. branchpy/semantics/ast/__init__.py +57 -0
  721. branchpy/semantics/ast/ast_cache_manager.py +293 -0
  722. branchpy/semantics/ast/nodes.py +629 -0
  723. branchpy/semantics/ast/parser.py +1416 -0
  724. branchpy/semantics/ast/python_ast_parser.py +386 -0
  725. branchpy/semantics/bqf_wrapper_semantics.py +15 -0
  726. branchpy/semantics/cfg_builder.py +26 -0
  727. branchpy/semantics/conditional_rules.py +16 -0
  728. branchpy/semantics/cross_file_tracker.py +441 -0
  729. branchpy/semantics/effects_multi.py +25 -0
  730. branchpy/semantics/expressions/__init__.py +73 -0
  731. branchpy/semantics/expressions/errors.py +230 -0
  732. branchpy/semantics/expressions/nodes.py +307 -0
  733. branchpy/semantics/expressions/parser.py +487 -0
  734. branchpy/semantics/expressions/types.py +280 -0
  735. branchpy/semantics/expressions/validator.py +322 -0
  736. branchpy/semantics/expressions/variables/__init__.py +12 -0
  737. branchpy/semantics/expressions/variables/tracker.py +331 -0
  738. branchpy/semantics/propagation/__init__.py +56 -0
  739. branchpy/semantics/propagation/ai_cache.py +493 -0
  740. branchpy/semantics/propagation/ai_rule_engine.py +722 -0
  741. branchpy/semantics/propagation/bqf_policy_converter.py +710 -0
  742. branchpy/semantics/propagation/cfg_ai_engine.py +489 -0
  743. branchpy/semantics/propagation/cfg_builder.py +1141 -0
  744. branchpy/semantics/propagation/cfg_generator.py +682 -0
  745. branchpy/semantics/propagation/cfg_regex_engine.py +347 -0
  746. branchpy/semantics/propagation/cfg_rule_validator.py +288 -0
  747. branchpy/semantics/propagation/conditional_analyzer.py +667 -0
  748. branchpy/semantics/propagation/effects_analyzer.py +940 -0
  749. branchpy/semantics/propagation/effects_metrics.py +402 -0
  750. branchpy/semantics/propagation/flow_api.py +480 -0
  751. branchpy/semantics/propagation/metrics.py +376 -0
  752. branchpy/semantics/propagation/pfi_flow_integration.py +453 -0
  753. branchpy/semantics/propagation/propagator.py +508 -0
  754. branchpy/semantics/propagation/regex_rule_engine.py +524 -0
  755. branchpy/semantics/propagation/rule_registry.py +778 -0
  756. branchpy/semantics/propagation/rule_validator.py +734 -0
  757. branchpy/semantics/propagation/rule_versioning.py +498 -0
  758. branchpy/semantics/propagation/state.py +223 -0
  759. branchpy/semantics/regex_engine_v2.py +18 -0
  760. branchpy/semantics/schema.json +31 -0
  761. branchpy/semantics/semantic_history.py +29 -0
  762. branchpy/semantics_v2/__init__.py +65 -0
  763. branchpy/semantics_v2/ai_assisted_rules.py +119 -0
  764. branchpy/semantics_v2/conditional_analyzer.py +141 -0
  765. branchpy/semantics_v2/effects_analyzer.py +175 -0
  766. branchpy/semantics_v2/engine.py +731 -0
  767. branchpy/semantics_v2/parser.py +161 -0
  768. branchpy/semantics_v2/policy_exporter.py +164 -0
  769. branchpy/semantics_v2/regex_rules.py +139 -0
  770. branchpy/semantics_v2/semantic_graph_builder.py +653 -0
  771. branchpy/semantics_v2/semantic_history.py +170 -0
  772. branchpy/server/__init__.py +1 -0
  773. branchpy/server/api.py +505 -0
  774. branchpy/server/app.py +102 -0
  775. branchpy/server/auto_start.py +107 -0
  776. branchpy/server/daemon.py +474 -0
  777. branchpy/server/dto.py +343 -0
  778. branchpy/server/ensure.py +229 -0
  779. branchpy/server/events/INTEGRATION_GUIDE.py +88 -0
  780. branchpy/server/events/__init__.py +1 -0
  781. branchpy/server/events/bus.py +116 -0
  782. branchpy/server/events/helpers.py +197 -0
  783. branchpy/server/graph_filter.py +326 -0
  784. branchpy/server/pilot_paths.py +313 -0
  785. branchpy/server/port_manager.py +247 -0
  786. branchpy/server/project_resolver.py +301 -0
  787. branchpy/server/report_adapter.py +276 -0
  788. branchpy/server/routes/analyze.py +205 -0
  789. branchpy/server/routes/auth.py +116 -0
  790. branchpy/server/routes/auth_v2.py +622 -0
  791. branchpy/server/routes/charts.py +323 -0
  792. branchpy/server/routes/claim.py +233 -0
  793. branchpy/server/routes/compare.py +340 -0
  794. branchpy/server/routes/daemon.py +113 -0
  795. branchpy/server/routes/dashboard_logs.py +80 -0
  796. branchpy/server/routes/demo.py +51 -0
  797. branchpy/server/routes/device.py +310 -0
  798. branchpy/server/routes/editor.py +115 -0
  799. branchpy/server/routes/events.py +56 -0
  800. branchpy/server/routes/functions.py +215 -0
  801. branchpy/server/routes/issues.py +92 -0
  802. branchpy/server/routes/license.py +94 -0
  803. branchpy/server/routes/metrics.py +93 -0
  804. branchpy/server/routes/project.py +192 -0
  805. branchpy/server/routes/sae.py +486 -0
  806. branchpy/server/routes/semantics.py +1002 -0
  807. branchpy/server/routes/semantics_ufm.py +807 -0
  808. branchpy/server/routes/server.py +47 -0
  809. branchpy/server/routes/three_button.py +544 -0
  810. branchpy/server/routes/update.py +94 -0
  811. branchpy/server/routes/wow_data.py +541 -0
  812. branchpy/server/security.py +30 -0
  813. branchpy/server/serve.py +756 -0
  814. branchpy/server/static/assets/index-ByW6G6Nt.css +1 -0
  815. branchpy/server/static/assets/index-CvXUgfrM.js +85 -0
  816. branchpy/server/static/assets/index-Vf3eaeC8.js +85 -0
  817. branchpy/server/static/assets/index-umre-IgL.js +85 -0
  818. branchpy/server/static/index-KzpGriR7.js +70 -0
  819. branchpy/server/static/index.html +14 -0
  820. branchpy/server/static/vite.svg +1 -0
  821. branchpy/server/summarizer.py +405 -0
  822. branchpy/stats/__init__.py +79 -0
  823. branchpy/stats/metrics_source.py +471 -0
  824. branchpy/stats/policy_evaluator.py +569 -0
  825. branchpy/stats/policy_loader.py +361 -0
  826. branchpy/stats/policy_models.py +351 -0
  827. branchpy/stats/report_format.py +322 -0
  828. branchpy/stats2/__init__.py +39 -0
  829. branchpy/stats2/expressions.py +673 -0
  830. branchpy/story_graph.py +653 -0
  831. branchpy/story_validator.py +612 -0
  832. branchpy/support_bundle.py +248 -0
  833. branchpy/telemetry/__init__.py +94 -0
  834. branchpy/telemetry/analyzer_events.py +214 -0
  835. branchpy/telemetry/bqf_events.py +579 -0
  836. branchpy/telemetry/collector.py +243 -0
  837. branchpy/telemetry/collectors.py +540 -0
  838. branchpy/telemetry/config.py +129 -0
  839. branchpy/telemetry/emit_governance.py +69 -0
  840. branchpy/telemetry/event_emitter.py +47 -0
  841. branchpy/telemetry/events_compare.py +132 -0
  842. branchpy/telemetry/exporters/__init__.py +312 -0
  843. branchpy/telemetry/exporters/base.py +123 -0
  844. branchpy/telemetry/exporters/csv_exporter.py +53 -0
  845. branchpy/telemetry/exporters/json_exporter.py +42 -0
  846. branchpy/telemetry/exporters/parquet_exporter.py +76 -0
  847. branchpy/telemetry/exporters.py +262 -0
  848. branchpy/telemetry/governance_linker.py +322 -0
  849. branchpy/telemetry/ingest.py +149 -0
  850. branchpy/telemetry/integration_snippets.py +251 -0
  851. branchpy/telemetry/local_writer.py +214 -0
  852. branchpy/telemetry/mysql_sink.py +239 -0
  853. branchpy/telemetry/package_builder.py +499 -0
  854. branchpy/telemetry/package_schema.py +172 -0
  855. branchpy/telemetry/patch_events.py +273 -0
  856. branchpy/telemetry/paths.py +137 -0
  857. branchpy/telemetry/phase3_handler.py +443 -0
  858. branchpy/telemetry/privacy.py +297 -0
  859. branchpy/telemetry/prometheus.py +273 -0
  860. branchpy/telemetry/query.py +311 -0
  861. branchpy/telemetry/remote_events.py +379 -0
  862. branchpy/telemetry/retention.py +253 -0
  863. branchpy/telemetry/schema_validator.py +300 -0
  864. branchpy/telemetry/schemas.py +592 -0
  865. branchpy/telemetry/sdk_telemetry.py +647 -0
  866. branchpy/telemetry/storage.py +364 -0
  867. branchpy/telemetry/storage_composite.py +467 -0
  868. branchpy/telemetry/storage_mysql.py +608 -0
  869. branchpy/telemetry/storage_sqlite.py +596 -0
  870. branchpy/telemetry/ui_metrics.py +203 -0
  871. branchpy/telemetry/utils.py +165 -0
  872. branchpy/telemetry/validation_events.py +359 -0
  873. branchpy/telemetry/writer.py +226 -0
  874. branchpy/telemetry.py +80 -0
  875. branchpy/templates/renpy_autoplay_shim.rpy +274 -0
  876. branchpy/templates/renpy_trace_shim.rpy +130 -0
  877. branchpy/testing/__init__.py +10 -0
  878. branchpy/testing/coverage.py +67 -0
  879. branchpy/testing/coverage_finder.py +161 -0
  880. branchpy/testing/executor.py +560 -0
  881. branchpy/testing/planner.py +344 -0
  882. branchpy/tools/__init__.py +1 -0
  883. branchpy/tools/bugbundle.py +104 -0
  884. branchpy/tools/validate_cli.py +289 -0
  885. branchpy/update_manager.py +210 -0
  886. branchpy/utils/__init__.py +0 -0
  887. branchpy/utils/emit.py +34 -0
  888. branchpy/utils/env.py +35 -0
  889. branchpy/utils/git_engine.py +38 -0
  890. branchpy/utils/logs.py +108 -0
  891. branchpy/watcher.py +167 -0
  892. branchpy/ws/__init__.py +1 -0
  893. branchpy/ws/audit_tasks.py +323 -0
  894. branchpy/ws/daemon.py +347 -0
  895. branchpy/ws/daemon_http.py +237 -0
  896. branchpy/ws/handshake_routes.py +55 -0
  897. branchpy/ws/pilot_routes.py +283 -0
  898. branchpy/ws/run.py +1320 -0
  899. branchpy/ws/watcher.py +194 -0
  900. branchpy/ws/ws_hub.py +184 -0
  901. branchpy-dashboard/node_modules/flatted/python/flatted.py +149 -0
  902. branchpy_bootstrap/__init__.py +1 -0
  903. branchpy_bootstrap/bootstrap.py +140 -0
  904. branchpy_bootstrap/manifest.json +25 -0
  905. branchpy_cli-1.1.19.dist-info/METADATA +163 -0
  906. branchpy_cli-1.1.19.dist-info/RECORD +912 -0
  907. branchpy_cli-1.1.19.dist-info/WHEEL +5 -0
  908. branchpy_cli-1.1.19.dist-info/entry_points.txt +4 -0
  909. branchpy_cli-1.1.19.dist-info/licenses/LICENSE +38 -0
  910. branchpy_cli-1.1.19.dist-info/top_level.txt +6 -0
  911. graph_builder.py +487 -0
  912. story_validator.py +620 -0
bqf/__init__.py ADDED
@@ -0,0 +1,16 @@
1
+ """
2
+ BQF (BranchPy Quality Framework) - Policy-based validation system.
3
+
4
+ This module provides the core infrastructure for BQF policy validation including:
5
+ - Policy registry (YAML-based configuration)
6
+ - Policy runner (dynamic validator loading and execution)
7
+ - Event emission (lifecycle tracking)
8
+ - Result aggregation (JSON formatting)
9
+
10
+ Version: 0.9.1.1
11
+ Created: 2025-11-12
12
+ """
13
+
14
+ from .registry import PolicyRegistry, PolicyResult
15
+
16
+ __all__ = ["PolicyRegistry", "PolicyResult"]
bqf/registry.py ADDED
@@ -0,0 +1,208 @@
1
+ """
2
+ BQF Policy Registry - Dynamic policy loading and execution.
3
+
4
+ This module provides the PolicyRegistry class for:
5
+ - Loading policies from YAML configuration
6
+ - Dynamically importing validator modules
7
+ - Executing policies with event emission
8
+ - Aggregating results into JSON format
9
+
10
+ Version: 0.9.1.1
11
+ Created: 2025-11-12
12
+ """
13
+
14
+ import time
15
+ from dataclasses import dataclass
16
+ from importlib import import_module
17
+ from pathlib import Path
18
+ from typing import Literal, Optional
19
+
20
+ import yaml
21
+
22
+
23
+ @dataclass
24
+ class PolicyResult:
25
+ """Result from a single policy validator execution."""
26
+
27
+ policy_id: str
28
+ status: Literal["pass", "warn", "fail"]
29
+ messages: list[str]
30
+ duration_ms: float
31
+ metadata: dict
32
+
33
+
34
+ class PolicyRegistry:
35
+ """
36
+ BQF Policy Registry - manages policy loading and execution.
37
+
38
+ Usage:
39
+ registry = PolicyRegistry()
40
+ result = registry.run_policies("analyze", analysis_result, context)
41
+ """
42
+
43
+ def __init__(self, registry_path: Optional[Path] = None):
44
+ """
45
+ Initialize policy registry.
46
+
47
+ Args:
48
+ registry_path: Path to policies.yaml. If None, uses default location.
49
+ """
50
+ if registry_path is None:
51
+ registry_path = Path(__file__).parent / "policies.yaml"
52
+
53
+ self.registry_path = registry_path
54
+ self.policies = self._load_policies()
55
+
56
+ def _load_policies(self) -> list[dict]:
57
+ """Load policies from YAML configuration file."""
58
+ if not self.registry_path.exists():
59
+ raise FileNotFoundError(f"Policy registry not found: {self.registry_path}")
60
+
61
+ with open(self.registry_path, "r", encoding="utf-8") as f:
62
+ config = yaml.safe_load(f)
63
+
64
+ return config.get("policies", [])
65
+
66
+ def get_policies_for_module(
67
+ self, module: str, enabled_only: bool = True
68
+ ) -> list[dict]:
69
+ """
70
+ Get policies for a specific module.
71
+
72
+ Args:
73
+ module: Module name ("analyze", "compare", "media")
74
+ enabled_only: If True, only return enabled policies
75
+
76
+ Returns:
77
+ List of policy definitions for the module
78
+ """
79
+ policies = [p for p in self.policies if p["module"] == module]
80
+
81
+ if enabled_only:
82
+ policies = [p for p in policies if p.get("enabled", True)]
83
+
84
+ return policies
85
+
86
+ def _import_validator(self, validator_path: str):
87
+ """
88
+ Dynamically import validator function from module path.
89
+
90
+ Args:
91
+ validator_path: Dotted path like "bqf.validators.analyze.story_structure.validate"
92
+
93
+ Returns:
94
+ Validator function
95
+ """
96
+ module_path, func_name = validator_path.rsplit(".", 1)
97
+ validator_module = import_module(module_path)
98
+ return getattr(validator_module, func_name)
99
+
100
+ def run_policies(self, module: str, analysis_result: dict, context: dict) -> dict:
101
+ """
102
+ Run all enabled policies for a module.
103
+
104
+ Args:
105
+ module: Module name ("analyze", "compare", "media")
106
+ analysis_result: Full analysis/comparison/media result dict
107
+ context: Additional context (project_path, correlation_id, etc.)
108
+
109
+ Returns:
110
+ Aggregated BQF result dict with format:
111
+ {
112
+ "policies_run": 2,
113
+ "policies_passed": 2,
114
+ "policies_warned": 0,
115
+ "policies_failed": 0,
116
+ "duration_ms": 1.23,
117
+ "details": [...] # Per-policy results
118
+ }
119
+ """
120
+ policies = self.get_policies_for_module(module, enabled_only=True)
121
+
122
+ if not policies:
123
+ return {
124
+ "policies_run": 0,
125
+ "policies_passed": 0,
126
+ "policies_warned": 0,
127
+ "policies_failed": 0,
128
+ "duration_ms": 0.0,
129
+ "details": [],
130
+ }
131
+
132
+ # Emit start event (TODO: integrate with governance.events)
133
+ correlation_id = context.get("correlation_id", "unknown")
134
+ self._emit_event(
135
+ "validation.policy.start",
136
+ {
137
+ "module": module,
138
+ "policy_count": len(policies),
139
+ "correlationId": correlation_id,
140
+ },
141
+ )
142
+
143
+ start_time = time.perf_counter()
144
+ results = []
145
+
146
+ for policy in policies:
147
+ try:
148
+ # Dynamically load validator
149
+ validator_func = self._import_validator(policy["validator"])
150
+
151
+ # Run validation
152
+ result = validator_func(analysis_result, context)
153
+ results.append(result)
154
+
155
+ except Exception as e:
156
+ # If validator fails to load or execute, treat as failure
157
+ results.append(
158
+ PolicyResult(
159
+ policy_id=policy["id"],
160
+ status="fail",
161
+ messages=[f"Validator error: {str(e)}"],
162
+ duration_ms=0.0,
163
+ metadata={"error": str(e)},
164
+ )
165
+ )
166
+
167
+ total_duration_ms = (time.perf_counter() - start_time) * 1000
168
+
169
+ # Aggregate results (treat "info" as "warn" for counting)
170
+ aggregated = {
171
+ "policies_run": len(results),
172
+ "policies_passed": sum(1 for r in results if r.status == "pass"),
173
+ "policies_warned": sum(1 for r in results if r.status in ("warn", "info")),
174
+ "policies_failed": sum(1 for r in results if r.status == "fail"),
175
+ "duration_ms": round(total_duration_ms, 4),
176
+ "details": [
177
+ {
178
+ "policy_id": r.policy_id,
179
+ "status": r.status,
180
+ "messages": r.messages,
181
+ "duration_ms": round(r.duration_ms, 4),
182
+ "metadata": r.metadata,
183
+ }
184
+ for r in results
185
+ ],
186
+ }
187
+
188
+ # Emit complete event
189
+ self._emit_event(
190
+ "validation.policy.complete",
191
+ {"module": module, "results": aggregated, "correlationId": correlation_id},
192
+ )
193
+
194
+ return aggregated
195
+
196
+ def _emit_event(self, event_name: str, data: dict):
197
+ """
198
+ Emit governance event (placeholder for future integration).
199
+
200
+ Args:
201
+ event_name: Event name following domain.action.phase pattern
202
+ data: Event data payload
203
+
204
+ TODO: Integrate with governance.events module in v0.9.2
205
+ """
206
+ # For now, just log to console (will integrate with governance logger later)
207
+ # print(f"[BQF EVENT] {event_name}: {data}")
208
+ pass # Silent for now, will wire to governance.events in v0.9.2
branchpy/__init__.py ADDED
@@ -0,0 +1,29 @@
1
+ from . import cli # exposes branchpy.cli
2
+ from . import parser, report
3
+ from .contract import VERSION
4
+
5
+ # Try to import telemetry and governance, but don't fail if they have optional dependencies
6
+ try:
7
+ from . import telemetry
8
+ except (ImportError, ModuleNotFoundError):
9
+ # telemetry has optional dependencies, skip if not available
10
+ pass
11
+
12
+ try:
13
+ from . import governance
14
+ except (ImportError, ModuleNotFoundError):
15
+ # governance may have optional dependencies, skip if not available
16
+ pass
17
+
18
+ # Expose version as both VERSION and __version__ for compatibility
19
+ __version__ = VERSION
20
+
21
+ __all__ = [
22
+ "cli",
23
+ "parser",
24
+ "report",
25
+ "telemetry",
26
+ "governance",
27
+ "VERSION",
28
+ "__version__",
29
+ ]
branchpy/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .cli import main as cli_main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(cli_main())
@@ -0,0 +1,49 @@
1
+ """
2
+ branchpy.ai.__init__.py
3
+ BranchPy v1.0.0 — AI Integration Strategy
4
+
5
+ AI-as-a-Service module for BranchPy.
6
+ Supports multiple providers (OpenAI, Anthropic, Ollama, Venice.ai) with local API keys.
7
+
8
+ Governance:
9
+ - All AI operations emit governance events
10
+ - Privacy-preserving: no data sent to BranchPy servers
11
+ - User-controlled API keys
12
+
13
+ Local AI Support:
14
+ - Ollama provider for local Llama models (100% private)
15
+ - LM Studio support (OpenAI-compatible)
16
+ - Safe mode restricts to local-only providers
17
+
18
+ BQS Compliance:
19
+ - Input validation on all API calls
20
+ - Rate limiting and error handling
21
+ - Cross-platform compatibility
22
+ """
23
+
24
+ from .ai_models import AIModel, AITask
25
+ from .ai_routing import AIRouter
26
+ from .config import AIConfig, ProviderConfig, load_ai_config
27
+ from .protocol import AIProvider, ChatRequest, ChatResponse, Message, TokenUsage
28
+ from .provider_manager import ProviderManager
29
+ from .providers.ollama_provider import OllamaProvider
30
+ from .providers.venice_provider import VeniceProvider
31
+
32
+ __all__ = [
33
+ "ProviderManager",
34
+ "AIModel",
35
+ "AITask",
36
+ "AIRouter",
37
+ "AIProvider",
38
+ "ChatRequest",
39
+ "ChatResponse",
40
+ "Message",
41
+ "TokenUsage",
42
+ "ProviderConfig",
43
+ "AIConfig",
44
+ "load_ai_config",
45
+ "OllamaProvider",
46
+ "VeniceProvider",
47
+ ]
48
+
49
+ __version__ = "1.0.0"
@@ -0,0 +1,65 @@
1
+ """
2
+ branchpy.ai.ai_models.py
3
+ BranchPy v0.9.4 — AI Integration Strategy
4
+
5
+ AI models and task definitions
6
+ """
7
+
8
+ from dataclasses import dataclass
9
+ from enum import Enum
10
+ from typing import Any, Dict, Optional
11
+
12
+
13
+ class AIModel(Enum):
14
+ """Supported AI models"""
15
+
16
+ GPT4 = "gpt-4"
17
+ GPT4_TURBO = "gpt-4-turbo"
18
+ GPT5 = "gpt-5" # Future
19
+ CLAUDE_35_SONNET = "claude-3-5-sonnet-20241022"
20
+ CLAUDE_45 = "claude-4-5" # Future
21
+
22
+
23
+ class AITask(Enum):
24
+ """AI task types"""
25
+
26
+ CODE_REVIEW = "code_review"
27
+ DOCGEN = "documentation_generation"
28
+ SEMANTIC_ASSIST = "semantic_assistance"
29
+ ASSET_GUESS = "asset_guessing"
30
+ EXPLAIN_WARNING = "explain_warning"
31
+ HELP = "help_support"
32
+
33
+
34
+ @dataclass
35
+ class AIRequest:
36
+ """AI request data structure"""
37
+
38
+ task: AITask
39
+ provider: str
40
+ model: str
41
+ input_data: Dict[str, Any]
42
+ context: Optional[Dict[str, Any]] = None
43
+
44
+
45
+ @dataclass
46
+ class AIResponse:
47
+ """AI response data structure"""
48
+
49
+ task: AITask
50
+ provider: str
51
+ model: str
52
+ output: Any
53
+ metadata: Optional[Dict[str, Any]] = None
54
+ error: Optional[str] = None
55
+
56
+
57
+ @dataclass
58
+ class AIConfig:
59
+ """AI configuration"""
60
+
61
+ provider: str
62
+ api_key: str
63
+ model: Optional[str] = None
64
+ temperature: float = 0.5
65
+ max_tokens: int = 4096
@@ -0,0 +1,119 @@
1
+ """
2
+ branchpy.ai.ai_routing.py
3
+ BranchPy v0.9.4 — AI Integration Strategy
4
+
5
+ AI task routing and execution
6
+ Routes tasks to appropriate providers based on configuration and task type
7
+ """
8
+
9
+ from typing import Any, Dict, Optional
10
+
11
+ from .ai_models import AIRequest, AIResponse, AITask
12
+ from .provider_manager import AIProvider, ProviderManager
13
+ from .providers.anthropic_provider import AnthropicProvider
14
+ from .providers.openai_provider import OpenAIProvider
15
+
16
+
17
+ class AIRouter:
18
+ """
19
+ Routes AI tasks to appropriate providers.
20
+
21
+ Handles:
22
+ - Provider selection
23
+ - Task routing
24
+ - Error handling
25
+ - Governance event emission
26
+ """
27
+
28
+ def __init__(self):
29
+ self.provider_manager = ProviderManager()
30
+ self._providers: Dict[str, Any] = {}
31
+
32
+ def _get_provider_instance(self, provider: AIProvider):
33
+ """Get or create provider instance"""
34
+ if provider.value in self._providers:
35
+ return self._providers[provider.value]
36
+
37
+ api_key = self.provider_manager.get_api_key(provider)
38
+ if not api_key:
39
+ raise ValueError(f"No API key configured for {provider.value}")
40
+
41
+ model = self.provider_manager.get_model(provider)
42
+
43
+ if provider == AIProvider.OPENAI:
44
+ instance = OpenAIProvider(api_key, model or "gpt-4")
45
+ elif provider == AIProvider.ANTHROPIC:
46
+ instance = AnthropicProvider(api_key, model or "claude-3-5-sonnet-20241022")
47
+ else:
48
+ raise ValueError(f"Unsupported provider: {provider}")
49
+
50
+ self._providers[provider.value] = instance
51
+ return instance
52
+
53
+ def execute(self, request: AIRequest) -> AIResponse:
54
+ """
55
+ Execute an AI task.
56
+
57
+ Args:
58
+ request: AI request
59
+
60
+ Returns:
61
+ AI response
62
+ """
63
+ try:
64
+ # Get provider
65
+ provider = AIProvider(request.provider)
66
+ instance = self._get_provider_instance(provider)
67
+
68
+ # Route task
69
+ if request.task == AITask.CODE_REVIEW:
70
+ output = instance.code_review(
71
+ code=request.input_data["code"],
72
+ language=request.input_data.get("language", "python"),
73
+ )
74
+ elif request.task == AITask.DOCGEN:
75
+ output = instance.generate_documentation(
76
+ code=request.input_data["code"],
77
+ doc_type=request.input_data.get("doc_type", "readme"),
78
+ )
79
+ elif request.task == AITask.EXPLAIN_WARNING:
80
+ output = instance.explain_warning(
81
+ warning_text=request.input_data["warning"],
82
+ context=request.input_data.get("context"),
83
+ )
84
+ elif request.task == AITask.ASSET_GUESS:
85
+ if provider == AIProvider.ANTHROPIC:
86
+ output = instance.guess_asset(
87
+ asset_context=request.input_data["context"],
88
+ available_assets=request.input_data["available_assets"],
89
+ )
90
+ else:
91
+ output = {"error": "Asset guessing only supported on Anthropic"}
92
+ else:
93
+ output = {"error": f"Unsupported task: {request.task}"}
94
+
95
+ return AIResponse(
96
+ task=request.task,
97
+ provider=request.provider,
98
+ model=request.model,
99
+ output=output,
100
+ )
101
+
102
+ except Exception as e:
103
+ return AIResponse(
104
+ task=request.task,
105
+ provider=request.provider,
106
+ model=request.model,
107
+ output=None,
108
+ error=str(e),
109
+ )
110
+
111
+ def is_available(self, provider: Optional[AIProvider] = None) -> bool:
112
+ """Check if AI is available"""
113
+ if provider is None:
114
+ provider = self.provider_manager.get_active_provider()
115
+
116
+ if provider is None:
117
+ return False
118
+
119
+ return self.provider_manager.is_configured(provider)
@@ -0,0 +1,165 @@
1
+ """
2
+ branchpy.ai.ai_tasks.py
3
+ BranchPy v0.9.4 — AI Integration Strategy
4
+
5
+ High-level AI task implementations
6
+ Convenience functions for common AI operations
7
+ """
8
+
9
+ from typing import Any, Dict, List, Optional
10
+
11
+ from .ai_models import AIRequest, AITask
12
+ from .ai_routing import AIRouter
13
+ from .provider_manager import ProviderManager
14
+
15
+
16
+ def code_review(
17
+ file_path: str, code: Optional[str] = None, language: str = "python"
18
+ ) -> Dict[str, Any]:
19
+ """
20
+ Run AI code review on a file.
21
+
22
+ Args:
23
+ file_path: Path to file
24
+ code: Optional code string (if not provided, read from file)
25
+ language: Programming language
26
+
27
+ Returns:
28
+ Review results
29
+ """
30
+ try:
31
+ if code is None:
32
+ with open(file_path, "r", encoding="utf-8") as f:
33
+ code = f.read()
34
+ except FileNotFoundError:
35
+ return {"error": f"File not found: {file_path}", "findings": []}
36
+ except Exception as e:
37
+ return {"error": f"Failed to read file: {str(e)}", "findings": []}
38
+
39
+ pm = ProviderManager()
40
+ provider = pm.get_active_provider()
41
+
42
+ if provider is None:
43
+ return {"error": "No AI provider configured", "findings": []}
44
+
45
+ model = pm.get_model(provider) or "default"
46
+
47
+ request = AIRequest(
48
+ task=AITask.CODE_REVIEW,
49
+ provider=provider.value,
50
+ model=model,
51
+ input_data={"code": code, "language": language},
52
+ )
53
+
54
+ router = AIRouter()
55
+ response = router.execute(request)
56
+
57
+ if response.error:
58
+ return {"error": response.error, "findings": []}
59
+
60
+ return response.output
61
+
62
+
63
+ def generate_docs(code: str, doc_type: str = "readme") -> str:
64
+ """
65
+ Generate documentation for code.
66
+
67
+ Args:
68
+ code: Source code
69
+ doc_type: Documentation type
70
+
71
+ Returns:
72
+ Generated documentation
73
+ """
74
+ pm = ProviderManager()
75
+ provider = pm.get_active_provider()
76
+
77
+ if provider is None:
78
+ return "Error: No AI provider configured"
79
+
80
+ model = pm.get_model(provider) or "default"
81
+
82
+ request = AIRequest(
83
+ task=AITask.DOCGEN,
84
+ provider=provider.value,
85
+ model=model,
86
+ input_data={"code": code, "doc_type": doc_type},
87
+ )
88
+
89
+ router = AIRouter()
90
+ response = router.execute(request)
91
+
92
+ if response.error:
93
+ return f"Error: {response.error}"
94
+
95
+ return response.output
96
+
97
+
98
+ def explain_warning(warning_text: str, context: Optional[str] = None) -> str:
99
+ """
100
+ Get AI explanation for a warning.
101
+
102
+ Args:
103
+ warning_text: Warning message
104
+ context: Optional context
105
+
106
+ Returns:
107
+ Explanation
108
+ """
109
+ pm = ProviderManager()
110
+ provider = pm.get_active_provider()
111
+
112
+ if provider is None:
113
+ return "Error: No AI provider configured"
114
+
115
+ model = pm.get_model(provider) or "default"
116
+
117
+ request = AIRequest(
118
+ task=AITask.EXPLAIN_WARNING,
119
+ provider=provider.value,
120
+ model=model,
121
+ input_data={"warning": warning_text, "context": context},
122
+ )
123
+
124
+ router = AIRouter()
125
+ response = router.execute(request)
126
+
127
+ if response.error:
128
+ return f"Error: {response.error}"
129
+
130
+ return response.output
131
+
132
+
133
+ def guess_missing_asset(context: str, available_assets: List[str]) -> List[str]:
134
+ """
135
+ Guess missing asset based on context.
136
+
137
+ Args:
138
+ context: Asset context
139
+ available_assets: Available asset filenames
140
+
141
+ Returns:
142
+ List of suggestions
143
+ """
144
+ pm = ProviderManager()
145
+ provider = pm.get_active_provider()
146
+
147
+ if provider is None:
148
+ return []
149
+
150
+ model = pm.get_model(provider) or "default"
151
+
152
+ request = AIRequest(
153
+ task=AITask.ASSET_GUESS,
154
+ provider=provider.value,
155
+ model=model,
156
+ input_data={"context": context, "available_assets": available_assets},
157
+ )
158
+
159
+ router = AIRouter()
160
+ response = router.execute(request)
161
+
162
+ if response.error:
163
+ return []
164
+
165
+ return response.output if isinstance(response.output, list) else []
@@ -0,0 +1,28 @@
1
+ """AI integration with Python AST analysis.
2
+
3
+ This module provides AI-powered code analysis using rich context
4
+ extracted from Python AST nodes.
5
+
6
+ Components:
7
+ - ast_context: Extract rich context from AST for AI operations
8
+ - code_review: AI-powered code review
9
+ - explain_warning: AI explanations of BranchPy warnings
10
+ - refactor: AI-powered refactoring suggestions
11
+ """
12
+
13
+ from .ast_context import AIContext, ASTContextBuilder
14
+ from .code_review import AICodeReviewer, CodeReview
15
+ from .explain_warning import AIWarningExplainer, WarningExplanation
16
+ from .refactor import AIRefactorSuggester, RefactoringPatch, RefactorSuggestion
17
+
18
+ __all__ = [
19
+ "ASTContextBuilder",
20
+ "AIContext",
21
+ "AICodeReviewer",
22
+ "CodeReview",
23
+ "AIWarningExplainer",
24
+ "WarningExplanation",
25
+ "AIRefactorSuggester",
26
+ "RefactorSuggestion",
27
+ "RefactoringPatch",
28
+ ]