bugx-cli 0.1.1__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 (762) hide show
  1. bugx_cli/__init__.py +6 -0
  2. bugx_cli/cli.py +1685 -0
  3. bugx_cli/commands/__init__.py +1 -0
  4. bugx_cli/commands/advisory.py +94 -0
  5. bugx_cli/commands/agent.py +4210 -0
  6. bugx_cli/commands/audit.py +632 -0
  7. bugx_cli/commands/autonomous.py +260 -0
  8. bugx_cli/commands/cloud.py +1371 -0
  9. bugx_cli/commands/daemon.py +50 -0
  10. bugx_cli/commands/doctor.py +1590 -0
  11. bugx_cli/commands/goal.py +107 -0
  12. bugx_cli/commands/interaction.py +248 -0
  13. bugx_cli/commands/knowledge.py +619 -0
  14. bugx_cli/commands/lifecycle.py +2763 -0
  15. bugx_cli/commands/patch.py +1014 -0
  16. bugx_cli/commands/plugin.py +2749 -0
  17. bugx_cli/commands/plugin_claude.py +1446 -0
  18. bugx_cli/commands/plugin_cline.py +269 -0
  19. bugx_cli/commands/plugin_codex.py +74 -0
  20. bugx_cli/commands/plugin_funide.py +729 -0
  21. bugx_cli/commands/plugin_qoder.py +216 -0
  22. bugx_cli/commands/plugin_zcode.py +710 -0
  23. bugx_cli/commands/project.py +670 -0
  24. bugx_cli/commands/report.py +256 -0
  25. bugx_cli/commands/skill.py +251 -0
  26. bugx_cli/commands/stats.py +133 -0
  27. bugx_cli/commands/system.py +2567 -0
  28. bugx_cli/common.py +906 -0
  29. bugx_cli/host_adapters.py +1892 -0
  30. bugx_cli/hosts/__init__.py +80 -0
  31. bugx_cli/hosts/base.py +99 -0
  32. bugx_cli/hosts/registry.py +573 -0
  33. bugx_cli/hosts/template_engine.py +188 -0
  34. bugx_cli/infra/__init__.py +209 -0
  35. bugx_cli/infra/ai_advisor.py +851 -0
  36. bugx_cli/infra/engine_installer.py +1945 -0
  37. bugx_cli/infra/host_sync.py +548 -0
  38. bugx_cli/infra/mcp_advisor.py +826 -0
  39. bugx_cli/infra/security.py +339 -0
  40. bugx_cli-0.1.1.data/data/share/bugx-agent/bugx-mcp-manifest.json +53 -0
  41. bugx_cli-0.1.1.data/data/share/bugx-agent/core/CATALOG.json +141 -0
  42. bugx_cli-0.1.1.data/data/share/bugx-agent/core/README.md +254 -0
  43. bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/README.md +35 -0
  44. bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/android-interaction.json +81 -0
  45. bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/android.json +24 -0
  46. bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/desktop-macos.json +20 -0
  47. bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/ios-interaction.json +34 -0
  48. bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/ios.json +23 -0
  49. bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/memory-macos.json +24 -0
  50. bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/README.md +51 -0
  51. bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/__init__.py +146 -0
  52. bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_artifacts.py +766 -0
  53. bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_eval.py +1155 -0
  54. bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_execution.py +718 -0
  55. bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_orchestrator.py +1351 -0
  56. bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_targets.py +877 -0
  57. bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_workspace.py +770 -0
  58. bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/feature_baseline.py +150 -0
  59. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/README.md +24 -0
  60. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
  61. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/LICENSE.txt +362 -0
  62. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/UPSTREAM.md +10 -0
  63. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/axe.min.js +12 -0
  64. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-1024.png +0 -0
  65. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-512.png +0 -0
  66. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-tight.svg +23 -0
  67. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar.svg +28 -0
  68. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-cn.png +0 -0
  69. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-en.png +0 -0
  70. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-en.svg +74 -0
  71. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-zh.svg +74 -0
  72. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/codex.png +0 -0
  73. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/dsh.png +0 -0
  74. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/project-layout.md +42 -0
  75. bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/zcode.png +0 -0
  76. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/README.md +37 -0
  77. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/manifest.json +94 -0
  78. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/00-scope.md +14 -0
  79. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/10-schema-inventory.md +14 -0
  80. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/20-query-and-integrity.md +14 -0
  81. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/80-evidence-regression.md +14 -0
  82. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/manifest.json +123 -0
  83. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/00-scope.md +15 -0
  84. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/10-process-model.md +14 -0
  85. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/20-package-integrity.md +15 -0
  86. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/30-ui-behavior.md +14 -0
  87. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/80-evidence-regression.md +15 -0
  88. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/memory-testing.md +227 -0
  89. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/manifest.json +155 -0
  90. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/android.md +19 -0
  91. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/h5.md +18 -0
  92. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/ios.md +25 -0
  93. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/miniprogram.md +26 -0
  94. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/webview.md +18 -0
  95. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/00-scope.md +14 -0
  96. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/10-platform-inventory.md +14 -0
  97. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/20-masvs-static.md +20 -0
  98. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/30-component-exposure.md +14 -0
  99. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/40-device-behavior.md +14 -0
  100. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/80-evidence-regression.md +13 -0
  101. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/manifest.json +127 -0
  102. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/00-scope.md +14 -0
  103. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/10-static-white-box.md +14 -0
  104. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/20-memory-concurrency.md +15 -0
  105. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/30-behavior-black-box.md +39 -0
  106. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/80-evidence-regression.md +14 -0
  107. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/platform-testing.md +174 -0
  108. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/manifest.json +191 -0
  109. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/graphql.md +5 -0
  110. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/h5.md +18 -0
  111. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/multi-tenant.md +4 -0
  112. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/oauth.md +4 -0
  113. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/upload.md +4 -0
  114. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/websocket.md +4 -0
  115. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/00-scope.md +13 -0
  116. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/10-discovery.md +13 -0
  117. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/20-auth-session.md +13 -0
  118. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/30-authz-business.md +13 -0
  119. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/40-input-output.md +13 -0
  120. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/50-state-async.md +13 -0
  121. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/60-file-ssrf-deser.md +12 -0
  122. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/70-config-dependency.md +12 -0
  123. bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/80-evidence-regression.md +12 -0
  124. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/INTERFACE.md +61 -0
  125. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/README.md +58 -0
  126. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/SPEC.md +25 -0
  127. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/__init__.py +109 -0
  128. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/attack_graph.py +1096 -0
  129. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/attack_graph_store.py +1868 -0
  130. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/audit_campaign.py +1232 -0
  131. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/behavior_graph.py +465 -0
  132. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/ghsa_advisories.py +174 -0
  133. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/models.py +93 -0
  134. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/mutator.py +87 -0
  135. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/patcher.py +126 -0
  136. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/scout.py +278 -0
  137. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/synthesizer.py +207 -0
  138. bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/verifier.py +103 -0
  139. bugx_cli-0.1.1.data/data/share/bugx-agent/core/bugx.md +1299 -0
  140. bugx_cli-0.1.1.data/data/share/bugx-agent/core/bugx_paths.py +1881 -0
  141. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cli-help.txt +66 -0
  142. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/INTERFACE.md +32 -0
  143. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/README.md +62 -0
  144. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/SPEC.md +25 -0
  145. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/__init__.py +23 -0
  146. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/auto_sync.py +398 -0
  147. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_client.py +1218 -0
  148. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_onboard.py +743 -0
  149. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_schema.py +648 -0
  150. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/consent.py +81 -0
  151. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/device_identity.py +307 -0
  152. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/endpoint_router.py +415 -0
  153. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/flywheel_client.py +769 -0
  154. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/network_transport.py +296 -0
  155. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/onboard_wizard.py +493 -0
  156. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sensitive_filter.py +285 -0
  157. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sync_pull.py +695 -0
  158. bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sync_push.py +723 -0
  159. bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/AGENT_GUIDE.md +359 -0
  160. bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/README.md +34 -0
  161. bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-blackbox.md +541 -0
  162. bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-opencode.md +469 -0
  163. bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-quick.md +44 -0
  164. bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-runtime-contract.md +353 -0
  165. bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-worker.md +470 -0
  166. bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/engine_gap_contracts.py +473 -0
  167. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/README.md +70 -0
  168. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/__init__.py +106 -0
  169. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_ai_review.py +185 -0
  170. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_backfill.py +54 -0
  171. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_bootstrap.py +713 -0
  172. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_business.py +36 -0
  173. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_cli.py +715 -0
  174. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_discovery.py +1429 -0
  175. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_evidence.py +1024 -0
  176. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_forensics.py +124 -0
  177. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_gate.py +277 -0
  178. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_intelligence.py +734 -0
  179. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_manifest.py +396 -0
  180. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_platform.py +77 -0
  181. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_validate.py +241 -0
  182. bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/module_coverage.py +157 -0
  183. bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/INTERFACE.md +20 -0
  184. bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/README.md +21 -0
  185. bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/SPEC.md +25 -0
  186. bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/__init__.py +5 -0
  187. bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/interaction_preset.py +408 -0
  188. bugx_cli-0.1.1.data/data/share/bugx-agent/core/engine-integrity.json +2797 -0
  189. bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/README.md +49 -0
  190. bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/__init__.py +82 -0
  191. bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/concurrency_fuzzer.py +435 -0
  192. bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/differential_oracle.py +1164 -0
  193. bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/fuzz_input.py +1291 -0
  194. bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/stateful_fuzzer.py +404 -0
  195. bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/README.md +61 -0
  196. bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/__init__.py +130 -0
  197. bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/capacity_planner.py +124 -0
  198. bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/dependency_lock.py +317 -0
  199. bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/goal_governor.py +754 -0
  200. bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/guide_budget.py +458 -0
  201. bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/lockdown.sh +50 -0
  202. bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/readonly_enforcer.py +154 -0
  203. bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/runtime_tool_gate.py +373 -0
  204. bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/secret_redactor.py +784 -0
  205. bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/token_budget.py +38 -0
  206. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/INTERFACE.md +36 -0
  207. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/README.md +51 -0
  208. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/SPEC.md +25 -0
  209. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/__init__.py +121 -0
  210. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/base.py +111 -0
  211. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/claude.py +99 -0
  212. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/cline.py +298 -0
  213. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/codex.py +300 -0
  214. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/dsh.py +106 -0
  215. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/opencode.py +209 -0
  216. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/pi.py +94 -0
  217. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/zcode.py +99 -0
  218. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/INTERFACE.md +24 -0
  219. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/README.md +62 -0
  220. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/SPEC.md +25 -0
  221. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/__init__.py +21 -0
  222. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/adapters.py +412 -0
  223. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/autonomous_runner.py +1152 -0
  224. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/cline.py +448 -0
  225. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/common.py +103 -0
  226. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/free_models.py +786 -0
  227. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_bootstrap.py +389 -0
  228. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_evaluators.py +761 -0
  229. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_probe.py +41 -0
  230. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_provider_arbitrator.py +831 -0
  231. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_registry.py +662 -0
  232. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_usage.py +127 -0
  233. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/mcp_process_tracker.py +509 -0
  234. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/mcp_registry_gate.py +379 -0
  235. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/pi.py +102 -0
  236. bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/provider_facts.py +66 -0
  237. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/INTERFACE.md +51 -0
  238. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/README.md +67 -0
  239. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/SPEC.md +25 -0
  240. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/__init__.py +140 -0
  241. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_base_usage.py +152 -0
  242. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_codex_usage.py +297 -0
  243. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_dsh_usage.py +184 -0
  244. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_mcp_toml.py +365 -0
  245. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_zcode_usage.py +269 -0
  246. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/base.py +479 -0
  247. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/claude.py +212 -0
  248. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/cline.py +229 -0
  249. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/codex.py +1006 -0
  250. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/dsh.py +526 -0
  251. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/opencode.py +358 -0
  252. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/pi.py +308 -0
  253. bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/zcode.py +219 -0
  254. bugx_cli-0.1.1.data/data/share/bugx-agent/core/i18n.py +252 -0
  255. bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/README.md +41 -0
  256. bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/__init__.py +17 -0
  257. bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/build_info.py +105 -0
  258. bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/client_metadata.py +185 -0
  259. bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/json_utils.py +22 -0
  260. bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/python_runtime.py +540 -0
  261. bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/safe_xml.py +221 -0
  262. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_bugx.py +118 -0
  263. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/INTERFACE.md +31 -0
  264. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/README.md +106 -0
  265. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/SPEC.md +25 -0
  266. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/__init__.py +29 -0
  267. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/candidate_revalidation.py +484 -0
  268. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/common.py +1060 -0
  269. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/finding_confirm_phase.py +391 -0
  270. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/finding_settlement.py +1432 -0
  271. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/findings_adjudication.py +666 -0
  272. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/findings_snapshot.py +357 -0
  273. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/judge_phase.py +848 -0
  274. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/lesson_context.py +536 -0
  275. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/lifecycle_reporter.py +627 -0
  276. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/orchestrator_controls.py +686 -0
  277. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_commit.py +567 -0
  278. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_coverage_sync.py +598 -0
  279. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_dry_run.py +817 -0
  280. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_observability.py +367 -0
  281. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_phase.py +1223 -0
  282. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_receipt.py +373 -0
  283. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_round_lifecycle.py +786 -0
  284. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_phase.py +1029 -0
  285. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_recon_scout.py +879 -0
  286. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_state_builder.py +1133 -0
  287. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/report_sharing.py +414 -0
  288. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/round_orchestrator.py +1116 -0
  289. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/session_runtime.py +1670 -0
  290. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_gates.py +1050 -0
  291. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_interaction.py +1003 -0
  292. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_version_gate.py +879 -0
  293. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_bridge.py +1253 -0
  294. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_coverage.py +423 -0
  295. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_degraded.py +1211 -0
  296. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_barriers.py +424 -0
  297. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_orchestrator.py +1246 -0
  298. bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_prior.py +749 -0
  299. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/INTERFACE.md +35 -0
  300. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/README.md +160 -0
  301. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/SPEC.md +25 -0
  302. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/__init__.py +67 -0
  303. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/_facade.py +227 -0
  304. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/archive_ops.py +630 -0
  305. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/auto_materialization.py +459 -0
  306. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/bug-log.md +22 -0
  307. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/cli.py +275 -0
  308. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/export_ops.py +554 -0
  309. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_confirmation.py +1316 -0
  310. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_io.py +299 -0
  311. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_lifecycle.py +730 -0
  312. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_verification.py +405 -0
  313. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/incidents.py +1005 -0
  314. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson-replay-cases.json +20 -0
  315. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson_ledger.py +241 -0
  316. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson_replay.py +272 -0
  317. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/life_ledger.py +668 -0
  318. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/mistake-book.md +130 -0
  319. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/patterns.py +684 -0
  320. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/receipt_contract.py +269 -0
  321. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/schema.py +1192 -0
  322. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/sync_ops.py +940 -0
  323. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/tool_experience.py +683 -0
  324. bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/verify_life.py +1597 -0
  325. bugx_cli-0.1.1.data/data/share/bugx-agent/core/lesson-ledger.json +275 -0
  326. bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/README.md +19 -0
  327. bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/en-US.json +462 -0
  328. bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/zh-CN.json +462 -0
  329. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/INTERFACE.md +75 -0
  330. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/README.md +62 -0
  331. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/SPEC.md +25 -0
  332. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/__init__.py +128 -0
  333. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/base.py +717 -0
  334. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/channel_lifecycle.py +751 -0
  335. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/graph_handlers.py +222 -0
  336. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/knowledge_handlers.py +536 -0
  337. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/mining_handlers.py +586 -0
  338. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/resource_prompt_table.py +116 -0
  339. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/retrieval_handlers.py +249 -0
  340. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/rpc_server.py +470 -0
  341. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/supervisor_handlers.py +1461 -0
  342. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/telemetry_handlers.py +227 -0
  343. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/tool_table.py +1030 -0
  344. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/README.md +21 -0
  345. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/__init__.py +1 -0
  346. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/common.py +363 -0
  347. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/environment.py +567 -0
  348. bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/verifier.py +758 -0
  349. bugx_cli-0.1.1.data/data/share/bugx-agent/core/metadata.txt +4 -0
  350. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/README.md +157 -0
  351. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/__init__.py +242 -0
  352. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/capability_plan.py +187 -0
  353. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/capability_planner.py +195 -0
  354. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/domain_archetype.py +542 -0
  355. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/domain_router.py +269 -0
  356. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/dynamic_flow_analyzer.py +533 -0
  357. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/impact_pruner.py +435 -0
  358. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/intent_adjudicator.py +175 -0
  359. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/judge_pipeline.py +1246 -0
  360. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/logic_analysis.py +419 -0
  361. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/prompt_harness.py +1704 -0
  362. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/source_inspector.py +267 -0
  363. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/spec_harvester.py +449 -0
  364. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/target_sandbox_manager.py +573 -0
  365. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/test_capability_verifier.py +1364 -0
  366. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/tools-kb.md +38 -0
  367. bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/unit_kind.py +122 -0
  368. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/INTERFACE.md +83 -0
  369. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/README.md +51 -0
  370. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/SPEC.md +36 -0
  371. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/__init__.py +76 -0
  372. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/android_probe.py +552 -0
  373. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/base.py +147 -0
  374. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/codebase_memory_probe.py +647 -0
  375. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/desktop_probe.py +342 -0
  376. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/differential_probe.py +434 -0
  377. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/efficiency_probe.py +232 -0
  378. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ios_binary_probe.py +472 -0
  379. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/memory_probe.py +392 -0
  380. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/miniprogram_probe.py +385 -0
  381. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/mobile_probe.py +466 -0
  382. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/native_probe.py +302 -0
  383. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/openwiki_probe.py +263 -0
  384. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/pattern_probe.py +453 -0
  385. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/platform_probe.py +424 -0
  386. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/probe_registry.py +1770 -0
  387. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_fixture_corpus.py +340 -0
  388. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_probe.py +1510 -0
  389. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_rules.py +1481 -0
  390. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sca_scanner.py +779 -0
  391. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_accessibility.py +149 -0
  392. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_audit.py +513 -0
  393. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_contract.py +273 -0
  394. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_evidence.py +212 -0
  395. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_measurements.py +314 -0
  396. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_repair.py +250 -0
  397. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_review.py +133 -0
  398. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_storybook.py +107 -0
  399. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_tokens.py +185 -0
  400. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_visual_diff.py +131 -0
  401. bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/web_probe.py +714 -0
  402. bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/INTERFACE.md +62 -0
  403. bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/README.md +53 -0
  404. bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/SPEC.md +28 -0
  405. bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/__init__.py +201 -0
  406. bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/arbitrator.py +316 -0
  407. bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/constants.py +247 -0
  408. bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/detector.py +399 -0
  409. bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/extractors.py +836 -0
  410. bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/fingerprint.py +116 -0
  411. bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/storage.py +258 -0
  412. bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/strategy.py +301 -0
  413. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/README.md +35 -0
  414. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/codex_dialog_dispatch.md +9 -0
  415. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/command_routing_en.md +42 -0
  416. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/command_routing_zh.md +42 -0
  417. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/l0_router.md +47 -0
  418. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/anti_patterns.md +16 -0
  419. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/concurrency_rules.md +14 -0
  420. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/memory_leak_rules.md +13 -0
  421. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/prompt_injection_defense.md +13 -0
  422. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_explore.md +31 -0
  423. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_gate.md +43 -0
  424. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_mutate.md +42 -0
  425. bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_repair.md +85 -0
  426. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/README.md +74 -0
  427. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/__init__.py +169 -0
  428. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/fix_watchlist.py +391 -0
  429. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_dynamic.py +418 -0
  430. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_repair_loop.py +462 -0
  431. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_selfcheck.py +862 -0
  432. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/minimize_repro.py +466 -0
  433. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/patch_synthesizer.py +617 -0
  434. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/regression_pack.py +379 -0
  435. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_fixer.py +910 -0
  436. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_loop.py +311 -0
  437. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_repair.py +348 -0
  438. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_rounds.py +212 -0
  439. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_scope.py +281 -0
  440. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/self_heal.py +604 -0
  441. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_generator.py +1108 -0
  442. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_quality_auditor.py +410 -0
  443. bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_strategy.py +511 -0
  444. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/INTERFACE.md +59 -0
  445. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/README.md +69 -0
  446. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/SPEC.md +28 -0
  447. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/__init__.py +47 -0
  448. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/attestation.py +228 -0
  449. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/authority.py +255 -0
  450. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/finding_report.py +418 -0
  451. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/formal_report_builder.py +924 -0
  452. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/html_renderers.py +696 -0
  453. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/models.py +759 -0
  454. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/pdf_exporter.py +231 -0
  455. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/projects_assets.py +730 -0
  456. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_client.py +743 -0
  457. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_data_builder.py +388 -0
  458. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_share.py +459 -0
  459. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/sast_bridge.py +116 -0
  460. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/server.py +832 -0
  461. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/visual_report_builder.py +796 -0
  462. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/web-conformance.md +168 -0
  463. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/web_conformance.py +428 -0
  464. bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/workbench_assets.py +484 -0
  465. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/INTERFACE.md +20 -0
  466. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/README.md +161 -0
  467. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/SPEC.md +25 -0
  468. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/__init__.py +3 -0
  469. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/code_analyzer.py +1720 -0
  470. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/codebase_memory_bridge.py +337 -0
  471. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/context_assembler.py +240 -0
  472. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/corpus_fetch.py +369 -0
  473. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/graph_ego.py +597 -0
  474. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_auto.py +662 -0
  475. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_sources.py +168 -0
  476. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_sync.py +1003 -0
  477. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/memory_store.py +480 -0
  478. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/query_planner.py +1020 -0
  479. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/rrf_engine.py +137 -0
  480. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_extractor.py +1209 -0
  481. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_normalizer.py +373 -0
  482. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_spec.py +357 -0
  483. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/symbol_index.py +1151 -0
  484. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/universal_code_matcher.py +622 -0
  485. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/xerj_bridge.py +476 -0
  486. bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/xerj_supervisor.py +362 -0
  487. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/README.md +33 -0
  488. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/PROVENANCE.json +30 -0
  489. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/crypto.yaml +36 -0
  490. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/network.yaml +20 -0
  491. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/resilience.yaml +47 -0
  492. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/storage.yaml +48 -0
  493. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/LICENSE +173 -0
  494. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/PROVENANCE.json +270 -0
  495. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-asymmetric-key-pair-used-for-multiple-purposes.yml +13 -0
  496. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-backup-manifest.yml +24 -0
  497. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-event-bound.yml +49 -0
  498. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-invalidated-enrollment.yml +11 -0
  499. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-no-confirmation-required.yml +10 -0
  500. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-validity-duration.yml +24 -0
  501. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-broken-encryption-algorithms.yaml +9 -0
  502. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-broken-encryption-modes.yaml +13 -0
  503. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-content-provider-exported.yml +35 -0
  504. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-custom-deeplink-scheme.yml +29 -0
  505. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-dangerous-app-permissions.yaml +65 -0
  506. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-apis.yml +36 -0
  507. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-manifest.yml +15 -0
  508. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-debuggable-flag.yml +10 -0
  509. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-debugger-checks.yml +12 -0
  510. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-deeplink-autoverify-missing.yml +33 -0
  511. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-deeplink-unvalidated-parameter.yml +11 -0
  512. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-device-passcode-present.yml +17 -0
  513. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-fileprovider-broad-scope.yml +46 -0
  514. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-hardcoded-crypto-keys-usage.yml +14 -0
  515. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-hardcoded-security-provider.yaml +18 -0
  516. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-implicit-intent-internal-communication.yml +30 -0
  517. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-implicit-intent-leaking-extras.yml +29 -0
  518. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-input-field-usage.yml +11 -0
  519. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-key-generation-with-insufficient-key-length.yml +21 -0
  520. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-keyboard-cache-input-types.yml +10 -0
  521. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-local-storage-input-validation.yml +48 -0
  522. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-native-debugger-checks.yml +12 -0
  523. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-checkservertrusted.yml +12 -0
  524. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-hostname-verification.yml +11 -0
  525. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-insecure-trust-anchors.yml +11 -0
  526. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-onreceivedsslerror.yml +12 -0
  527. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-non-random-use.yml +16 -0
  528. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-object-deserialization.yml +14 -0
  529. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-overlay-protection.yml +68 -0
  530. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-pendingintent-mutable.yml +39 -0
  531. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-random-apis-insufficient-entropy.yml +17 -0
  532. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-root-detection.yaml +59 -0
  533. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sdk-version.yml +10 -0
  534. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-notifications-manifest.yml +17 -0
  535. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-notifications.yml +11 -0
  536. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-screenshot.yml +18 -0
  537. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sql-injection-contentprovider.yml +17 -0
  538. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-ssl-socket-hostnameverifier.yml +15 -0
  539. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-strictmode.yml +10 -0
  540. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-system-alert-window.yml +9 -0
  541. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-allow-local-access.yml +15 -0
  542. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-bridges.yml +28 -0
  543. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-safebrowsing.yml +20 -0
  544. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-url-handlers.yml +41 -0
  545. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/PROVENANCE.json +26 -0
  546. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/network.yaml +37 -0
  547. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/platform.yaml +36 -0
  548. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/storage.yaml +48 -0
  549. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/LICENSE +165 -0
  550. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/PROVENANCE.json +58 -0
  551. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/auth.yaml +59 -0
  552. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/crypto.yaml +66 -0
  553. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/jailbreak.yaml +14 -0
  554. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/keyboard.yaml +34 -0
  555. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/logging.yaml +23 -0
  556. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/network.yaml +55 -0
  557. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/resilience.yaml +29 -0
  558. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/secrets.yaml +33 -0
  559. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/storage.yaml +29 -0
  560. bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/webview.yaml +32 -0
  561. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/README.md +198 -0
  562. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/__init__.py +3 -0
  563. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/bugx_logging.py +1464 -0
  564. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/daemon_runner.py +623 -0
  565. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/fixture_solidify.py +444 -0
  566. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/global_telemetry.py +549 -0
  567. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/incident_eval.py +148 -0
  568. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interaction.py +605 -0
  569. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interaction_store.py +435 -0
  570. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interactive_menu.py +95 -0
  571. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/log_analytics.py +922 -0
  572. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/mining_quality_framework.py +1387 -0
  573. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/model_runner.py +732 -0
  574. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/platform_adapter.py +579 -0
  575. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/prep_validate.py +478 -0
  576. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_graph.py +827 -0
  577. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_init.py +481 -0
  578. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_profile.py +224 -0
  579. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_settings.py +964 -0
  580. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/provider_window.py +97 -0
  581. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/resume_ticket.py +115 -0
  582. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/scenario_eval.py +856 -0
  583. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/seed_drill.py +549 -0
  584. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/self_audit.py +550 -0
  585. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/session_profile.py +205 -0
  586. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/setup_ui_env.py +229 -0
  587. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/startup_environment.py +859 -0
  588. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/sync_store.py +1421 -0
  589. bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/tool_install_targets.py +18 -0
  590. bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/README.md +35 -0
  591. bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/agent-graph.schema.json +368 -0
  592. bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/attack-graph.schema.json +88 -0
  593. bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/evidence-bundle.schema.json +33 -0
  594. bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/skill-pack.schema.json +230 -0
  595. bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/worker-checkpoint.schema.json +119 -0
  596. bugx_cli-0.1.1.data/data/share/bugx-agent/core/secure_atomic.py +289 -0
  597. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/README.md +55 -0
  598. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/c.txt +29 -0
  599. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/cpp.txt +32 -0
  600. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/css.txt +70 -0
  601. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/go.txt +46 -0
  602. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/java.txt +30 -0
  603. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/javascript.txt +55 -0
  604. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/kotlin.txt +28 -0
  605. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/python.txt +71 -0
  606. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/rust.txt +53 -0
  607. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/swift.txt +29 -0
  608. bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/typescript.txt +29 -0
  609. bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/README.md +53 -0
  610. bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/__init__.py +189 -0
  611. bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/bugx_docs_mcp_server.py +418 -0
  612. bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/bugx_mcp_server.py +1161 -0
  613. bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mcp_runtime.py +968 -0
  614. bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mcp_session_proof.py +605 -0
  615. bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mobile_ui_inspector.py +405 -0
  616. bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/skill_pack.py +1214 -0
  617. bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/skill_synthesizer.py +1153 -0
  618. bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/tools_kb.py +313 -0
  619. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/INTERFACE.md +121 -0
  620. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/README.md +209 -0
  621. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/SPEC.md +25 -0
  622. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/__init__.py +175 -0
  623. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/audit_supervisor.py +1015 -0
  624. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/budget_governor.py +1254 -0
  625. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_handler.py +368 -0
  626. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_pipeline.py +1564 -0
  627. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_sync.py +653 -0
  628. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/claim_events.py +74 -0
  629. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/claim_sync.py +590 -0
  630. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/cli.py +812 -0
  631. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/context_sync.py +55 -0
  632. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/coverage_sync.py +115 -0
  633. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_commit.py +470 -0
  634. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_sync.py +688 -0
  635. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_workflow.py +676 -0
  636. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finish_policy.py +224 -0
  637. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finish_sync.py +185 -0
  638. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/graph_sync.py +669 -0
  639. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/lease_manager.py +788 -0
  640. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/lifecycle_blocks.py +129 -0
  641. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/next_round_sync.py +126 -0
  642. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/observability.py +140 -0
  643. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/recovery_sync.py +165 -0
  644. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/rejection_remedies.py +355 -0
  645. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/round_governor.py +306 -0
  646. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/serial_authorization.py +544 -0
  647. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/start_sync.py +87 -0
  648. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/state_store.py +249 -0
  649. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/supervisor_host.py +511 -0
  650. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/supervisor_models.py +1143 -0
  651. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/systemic_failure.py +104 -0
  652. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/task_scheduler.py +1640 -0
  653. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_checkpoint.py +230 -0
  654. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_execution.py +265 -0
  655. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_handoff.py +192 -0
  656. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_lifecycle.py +396 -0
  657. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_runtime.py +1005 -0
  658. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_sync.py +89 -0
  659. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/README.md +36 -0
  660. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/__init__.py +0 -0
  661. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/exceptions.py +52 -0
  662. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/graph_models.py +357 -0
  663. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/path_containment.py +151 -0
  664. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/target_fingerprint.py +310 -0
  665. bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/worker_claim.py +411 -0
  666. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/INTERFACE.md +50 -0
  667. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/README.md +57 -0
  668. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/SPEC.md +26 -0
  669. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/__init__.py +11 -0
  670. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/__init__.py +27 -0
  671. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/base.py +87 -0
  672. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/bugx.py +102 -0
  673. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/claude.py +222 -0
  674. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/cline.py +407 -0
  675. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/codex.py +260 -0
  676. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/dsh.py +177 -0
  677. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/opencode.py +218 -0
  678. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/pi.py +272 -0
  679. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/registry.py +100 -0
  680. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/zcode.py +312 -0
  681. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/api_routes_post.py +668 -0
  682. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/dispatcher.py +1376 -0
  683. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/docs_session_service.py +473 -0
  684. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/handler.py +674 -0
  685. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/ide_cloud_service.py +526 -0
  686. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/mcp_inspector.py +1747 -0
  687. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/00-base.css +1060 -0
  688. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/01-monitoring.css +802 -0
  689. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/02-header-actions.css +321 -0
  690. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/03-trigger-popover.css +697 -0
  691. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/04-composer.css +628 -0
  692. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/05-skills-center.css +878 -0
  693. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/06-mcp-center.css +623 -0
  694. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/07-skill-detail.css +265 -0
  695. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/08-files-management.css +167 -0
  696. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/09-files-center.css +386 -0
  697. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/10-icons.css +105 -0
  698. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/11-project-options.css +185 -0
  699. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/12-profile-tab.css +383 -0
  700. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/index-CXAsl8mr.js +333 -0
  701. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/index-DHQUtWtx.css +1 -0
  702. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-400-normal-B8Z6Jvzv.woff +0 -0
  703. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-400-normal-C44pakCn.woff2 +0 -0
  704. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-500-normal-Bb4u56_6.woff +0 -0
  705. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-500-normal-BdVUvljg.woff2 +0 -0
  706. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-CWV284fw.woff2 +0 -0
  707. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-DLkyKLvH.woff +0 -0
  708. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-8-8HP2PF.woff +0 -0
  709. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-DaDZE_Na.woff2 +0 -0
  710. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-400-normal-BccYJ-vZ.woff +0 -0
  711. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-400-normal-Cw5-AHNN.woff2 +0 -0
  712. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-500-normal-By8GFJzz.woff2 +0 -0
  713. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-500-normal-z-Q6FFuG.woff +0 -0
  714. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-400-normal-DJ5YJwmz.woff2 +0 -0
  715. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-400-normal-Dn3IlU-Z.woff +0 -0
  716. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-500-normal-CUHe9xxf.woff2 +0 -0
  717. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-500-normal-DVVamBqs.woff +0 -0
  718. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-400-normal-CEpydyUl.woff +0 -0
  719. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-400-normal-Cp7z-ARB.woff2 +0 -0
  720. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-500-normal-BYjRCDVy.woff2 +0 -0
  721. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-500-normal-D-qasQTj.woff +0 -0
  722. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-400-normal-BbG3LG1A.woff2 +0 -0
  723. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-400-normal-DR1UuFon.woff +0 -0
  724. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-500-normal-8N8MYVKB.woff +0 -0
  725. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-500-normal-Bi3OSTTW.woff2 +0 -0
  726. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/design-tokens.css +113 -0
  727. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/favicon.png +0 -0
  728. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/icon-192.png +0 -0
  729. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/index.html +55 -0
  730. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/manifest.webmanifest +19 -0
  731. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/project-settings.js +9602 -0
  732. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/sw.js +8 -0
  733. bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/workspace_service.py +218 -0
  734. bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/agents/bugx.md +27 -0
  735. bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/dsh-patch.yml +18 -0
  736. bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/cordis.patch.yml +4 -0
  737. bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/index.js +219 -0
  738. bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/package.json +28 -0
  739. bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/skills/bugx/SKILL.md +70 -0
  740. bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/skills/bugx-dsh/SKILL.md +229 -0
  741. bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/client.js +87 -0
  742. bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/cordis.patch.yml +4 -0
  743. bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/index.js +7 -0
  744. bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/package.json +27 -0
  745. bugx_cli-0.1.1.data/data/share/bugx-agent/mcp-lock.json +3075 -0
  746. bugx_cli-0.1.1.data/data/share/bugx-agent/opencode.json +129 -0
  747. bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/README.md +12 -0
  748. bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/index.ts +299 -0
  749. bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/manifest.json +11 -0
  750. bugx_cli-0.1.1.data/data/share/bugx-agent/pi/skills/bugx/SKILL.md +69 -0
  751. bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-claude/SKILL.md +326 -0
  752. bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-opencode/SKILL.md +129 -0
  753. bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-zcode/SKILL.md +459 -0
  754. bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/connector-meta.json +19 -0
  755. bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/icon.png +0 -0
  756. bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/skills/bugx/SKILL.md +70 -0
  757. bugx_cli-0.1.1.dist-info/METADATA +335 -0
  758. bugx_cli-0.1.1.dist-info/RECORD +762 -0
  759. bugx_cli-0.1.1.dist-info/WHEEL +5 -0
  760. bugx_cli-0.1.1.dist-info/entry_points.txt +2 -0
  761. bugx_cli-0.1.1.dist-info/licenses/LICENSE +55 -0
  762. bugx_cli-0.1.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1429 @@
1
+ #!/usr/bin/env python3
2
+ """覆盖清单的**发现单元与业务切面**原语(DES-07 二期)。
3
+
4
+ 本模块由 ``module_coverage.py`` 拆分而来,承载「发现」与「业务发现」两簇。它们
5
+ 只依赖 ``coverage_manifest`` 的叶子原语与 ``symbol_index`` / ``project_graph``,
6
+ 彼此单向(业务簇 → 发现簇),且**不依赖** ``module_coverage`` 里的对账门禁、
7
+ 校验、自动回填、命令入口四簇。依赖方向因此是单向无环:
8
+
9
+ module_coverage → coverage_discovery → coverage_manifest
10
+
11
+ ``module_coverage`` 会**再导出**这里的全部公开名字,既有调用方
12
+ (``coverage_bootstrap``、``launch_phases.*``、``check`` / ``status`` 等)无需改动。
13
+
14
+ * D 发现单元 —— ``discover_minimum_unit_paths`` / ``discover_asset_unit_paths`` /
15
+ ``discover_audit_unit_paths`` / ``discovery_units`` / ``discovery_rows`` /
16
+ ``discovery_row`` / ``row_text`` / ``scope_path`` / ``coverage_unit_id`` /
17
+ ``evidence_manifest_errors`` / ``participant_ids`` / ``asset_units``
18
+ * F 业务发现 —— ``extract_feature_surface`` / ``announce_feature_surface`` /
19
+ ``business_discovery`` / ``business_discovery_rows`` / ``graph_scope`` /
20
+ ``PassContext`` / ``coverage_summary``(含端点/CLI 模式常量)
21
+
22
+ 恢复结算合账语义(DIM3,2026-11-17 用户裁决"新证据为准 + chain 保留")的判定
23
+ 原语也落在本模块:``inherited_unit_coverage_verdicts``(维度 1 链判定)与
24
+ ``recovery_closeout_coverage_census``(维度 2 普查)。单元证据分三层——L1 本轮
25
+ 本地记录 / L2 本 Life 历史本地记录 / L3 沿链继承(``inherited_from`` 备注 +
26
+ ``resolve_inherited_evidence`` 溯源);合账判定读取优先级为 L1 > L2 > L3,继承
27
+ chain 只作历史层留痕、不参与判定权威,双记录并存不互写背书。语义细则与扩展点
28
+ 见 ``docs/08_internal/01_standards/RECOVERY_SETTLEMENT_SEMANTICS_2026-11-17.md``。
29
+ """
30
+
31
+ from __future__ import annotations
32
+
33
+ import json
34
+ import math
35
+ import os
36
+ import re
37
+ import sys
38
+ from datetime import datetime
39
+ from pathlib import Path
40
+ from typing import Any, Iterable
41
+
42
+ from core.runtime import project_graph
43
+ from core.retrieval import symbol_index
44
+
45
+ from core.coverage.coverage_manifest import EvidenceProbe, ModuleRow, parse_manifest
46
+ # unit_platform 属 platform 簇(七簇层次 platform(0) <- discovery(1))。
47
+ # 原先误写为从 coverage_manifest 导入,导致 ImportError:
48
+ # 18 个文件受影响,module_coverage 无法导入,pre/post 端到端全失败。
49
+ from core.coverage.coverage_platform import unit_platform
50
+
51
+
52
+ def discover_minimum_unit_paths(root: Path, strict: bool = False) -> set[str]:
53
+ """递归发现产品源码文件,作为最小单元清单的机械下限。"""
54
+ return {
55
+ path.relative_to(root.resolve()).as_posix()
56
+ for path in symbol_index.discover_source_paths(root, strict=strict)
57
+ }
58
+
59
+
60
+ def discover_asset_unit_paths(
61
+ root: Path, strict: bool = False, asset_paths: list[Path] | None = None,
62
+ ) -> set[str]:
63
+ """Return configuration/dependency/build/CI/deployment assets in scope.
64
+
65
+ ``asset_paths`` 允许调用方复用同一次校验内已经枚举好的资产列表,避免在
66
+ ``discover_audit_unit_paths`` 与 ``discovery_units`` 里各走一遍全仓遍历。
67
+ """
68
+ if asset_paths is None:
69
+ asset_paths = symbol_index.discover_asset_paths(root, strict=strict)
70
+ return {
71
+ path.relative_to(root.resolve()).as_posix()
72
+ for path in asset_paths
73
+ }
74
+
75
+
76
+ def discover_audit_unit_paths(
77
+ root: Path, strict: bool = False, asset_paths: list[Path] | None = None,
78
+ ) -> set[str]:
79
+ """Return the file-level lower bound for source and behavior assets."""
80
+ return discover_minimum_unit_paths(root, strict=strict) | discover_asset_unit_paths(
81
+ root, strict=strict, asset_paths=asset_paths,
82
+ )
83
+
84
+
85
+ def scope_path(path: str) -> str:
86
+ """把 ``file::symbol`` 归一到源码文件路径。"""
87
+ return path.strip().strip("`").rstrip("/").split("::", 1)[0]
88
+
89
+
90
+ def coverage_unit_id(row: ModuleRow) -> str:
91
+ """Return the stable unit id used by ``coverage_evidence`` submissions."""
92
+ scope = row.path.strip().strip("`")
93
+ if not scope or scope in {"-", "待定"}:
94
+ scope = row.name.strip()
95
+ return f"{row.phase}:{row.number}:{scope}"
96
+
97
+
98
+ def cached_unit_risk_score(
99
+ file_path: str,
100
+ root: Path,
101
+ content_hash: str,
102
+ cache: dict[tuple[str, str, str], float | None],
103
+ ) -> float | None:
104
+ """Analyze one source snapshot once per discovery/reconciliation operation."""
105
+ key = (str(root.resolve()), file_path, content_hash)
106
+ if key not in cache:
107
+ try:
108
+ from core.repair import test_strategy
109
+
110
+ cache[key] = test_strategy.calculate_unit_risk_score(file_path, root)
111
+ except Exception:
112
+ # Risk is prioritization metadata, not coverage evidence. Preserve the
113
+ # existing default-difficulty behavior and don't retry per symbol row.
114
+ cache[key] = None
115
+ return cache[key]
116
+
117
+
118
+ # F3'(对抗审计重设计):跨 Session 继承覆盖的备注锚点,与
119
+ # ``coverage_bootstrap.apply_inherited_coverage`` 写入的
120
+ # ``inherited_from=<polling_id>/<lifecycle_id>`` 同形。
121
+ INHERITED_FROM_RE = re.compile(
122
+ r"inherited_from=(polling-[0-9]{6,})/(lifecycle-[0-9]{6,})"
123
+ )
124
+
125
+
126
+ def inherited_evidence_reference(note: str) -> tuple[str, str] | None:
127
+ """从清单行备注解析 ``inherited_from=<polling>/<lifecycle>`` 引用。"""
128
+ match = INHERITED_FROM_RE.search(note or "")
129
+ if match is None:
130
+ return None
131
+ return match.group(1), match.group(2)
132
+
133
+
134
+ def inheritable_scope(row: object) -> str:
135
+ """跨 Session 稳定的内部单元身份(与 coverage_bootstrap 同一口径:scope)。"""
136
+ scope = (getattr(row, "path", "") or "").strip().strip("`").rstrip("/")
137
+ if not scope or scope in {"-", "待定", "N/A"}:
138
+ return ""
139
+ return scope
140
+
141
+
142
+ # 继承链溯源深度上限:只为防环与病态链路兜底,正常链条(每个 lifecycle 一代)
143
+ # 远达不到该值;超过即按完整性异常 fail-closed。
144
+ MAX_INHERITED_CHAIN_DEPTH = 32
145
+
146
+
147
+ def _covered_source_verdict(
148
+ source_state: Path, scope: str,
149
+ ) -> tuple[str, str, str]:
150
+ """Resolve the newest covered manifest verdict for ``scope`` in one hop.
151
+
152
+ 返回 ``(unit_id, note, reason)``:成功时 ``unit_id`` 非空且 ``reason`` 为空,
153
+ ``note`` 是该清单行备注(供继承链继续溯源);失败时 ``unit_id`` 为空且
154
+ ``reason`` 说明拒绝原因。
155
+ """
156
+ source_manifest = source_state / "module-coverage.md"
157
+ if source_manifest.is_symlink() or not source_manifest.is_file():
158
+ return "", "", f"源清单缺失: {source_manifest}"
159
+ try:
160
+ source_rows, parse_errors = parse_manifest(source_manifest)
161
+ except (OSError, UnicodeError, ValueError) as exc:
162
+ return "", "", f"源清单无法解析: {source_manifest}: {exc}"
163
+ if parse_errors:
164
+ return "", "", f"源清单无效: {source_manifest}: {'; '.join(parse_errors[:3])}"
165
+ source_unit_id = ""
166
+ source_note = ""
167
+ for source_row in source_rows:
168
+ if (
169
+ getattr(source_row, "status", "") == "已覆盖"
170
+ and inheritable_scope(source_row) == scope
171
+ ):
172
+ # 后写覆盖先写,与 historical_unit_verdicts 的「最近一次判定」一致。
173
+ source_unit_id = coverage_unit_id(source_row)
174
+ source_note = getattr(source_row, "note", "") or ""
175
+ if not source_unit_id:
176
+ return "", "", f"源清单没有该 scope 的 covered 判定: scope={scope or '-'}"
177
+ return source_unit_id, source_note, ""
178
+
179
+
180
+ def _passed_source_evidence(
181
+ source_state: Path, source_unit_id: str, *, workspace_root: Path,
182
+ ) -> tuple[bool, str, bool]:
183
+ """Check one hop's local evidence for a passed record of ``source_unit_id``.
184
+
185
+ 返回 ``(passed, reason, found)``:``found=False`` 表示该跳没有可判定的本地
186
+ 记录(文件缺失/无法解析/没有该单元记录);``found=True`` 且非 passed 表示
187
+ 本地存在**矛盾证据**(该跳自报 covered 却有 failed/error 记录)。
188
+ """
189
+ source_evidence = source_state / "coverage-evidence.json"
190
+ if source_evidence.is_symlink() or not source_evidence.is_file():
191
+ return False, f"源覆盖证据缺失: {source_evidence}", False
192
+ try:
193
+ payload = json.loads(source_evidence.read_text(encoding="utf-8"))
194
+ except (OSError, UnicodeError, ValueError) as exc:
195
+ return False, f"源覆盖证据无法解析: {source_evidence}: {exc}", False
196
+ records = payload.get("records") if isinstance(payload, dict) else None
197
+ if not isinstance(records, list):
198
+ return False, f"源覆盖证据缺少 records 数组: {source_evidence}", False
199
+ from core.coverage import coverage_evidence
200
+
201
+ for item in records:
202
+ if not isinstance(item, dict) or item.get("unit_id") != source_unit_id:
203
+ continue
204
+ try:
205
+ record = coverage_evidence.EvidenceRecord.from_dict(item)
206
+ except ValueError as exc:
207
+ return False, f"源证据记录损坏 unit={source_unit_id}: {exc}", False
208
+ # OQ-5:沿链跳与本地 P1 同口径补 sha 完整性 + target_drifted 标志
209
+ # 校验;**不**启用当前指纹一致性——祖先记录必然来自不同会话的
210
+ # 指纹,按当前指纹判 stale 会杀死跨 Session 继承机制本身。
211
+ # 校验失败的记录不构成该跳的可判定依据(既非 passed 权威、也不
212
+ # 构成矛盾证据——被篡改的 failed 记录不得作为推翻依据),继续
213
+ # 找该单元的下一条记录。
214
+ ok, check_reason = coverage_evidence.record_authority_check(
215
+ record, workspace_root, require_current_fingerprint=False,
216
+ )
217
+ if not ok:
218
+ continue
219
+ if record.status != "passed" or record.exit_code != 0:
220
+ return False, (
221
+ f"源证据记录非 passed unit={source_unit_id} "
222
+ f"status={record.status} exit_code={record.exit_code}"
223
+ ), True
224
+ return True, "", True
225
+ return False, (
226
+ f"源覆盖证据没有该单元可判定记录: unit={source_unit_id} in {source_evidence}"
227
+ ), False
228
+
229
+
230
+ def resolve_inherited_evidence(
231
+ root: Path, row: object, polling_id: str, lifecycle_id: str,
232
+ ) -> tuple[bool, str]:
233
+ """Transitive provenance validation of a bootstrap-inherited reference.
234
+
235
+ 门禁对带 ``inherited_from`` 备注的已覆盖单元,只做**源 lifecycle 证据在案**
236
+ 校验:引用链最终必须在某个祖先 lifecycle 的 ``coverage-evidence.json`` 中
237
+ 落到该 scope(单元编号跨 Session 重排,scope 才是稳定身份)的 passed
238
+ 记录(形状完整)。
239
+
240
+ F3''(宿主矩阵 E2 实证修复):``historical_unit_verdicts`` 的继承引用总是
241
+ 指向**最近一个写入该 covered 判定的 lifecycle**,而该判定自身可能也是继承
242
+ 而来(清单行带 ``inherited_from`` 备注、本地证据文件没有该单元记录,
243
+ 实证:靶场 polling-000003→000002→000001 链条,002 的证据文件只有它自己
244
+ 4 条 worker 记录)。因此当一跳没有本地 passed 记录、但该跳清单行的
245
+ covered 判定本身带 ``inherited_from`` 备注时,沿备注继续向祖先溯源。
246
+
247
+ 以下情形一律 fail-closed,不随链条放宽:
248
+ * 引用链任一跳清单缺失/无法解析/scope 无 covered 判定(伪造引用在此被拦);
249
+ * 任一跳存在**矛盾的本地非 passed 记录**(自报 covered 却有 failed/error);
250
+ * 链条成环或深度超过 ``MAX_INHERITED_CHAIN_DEPTH``;
251
+ * 链条终点(判定自称本地产出)却没有本地 passed 记录。
252
+
253
+ 绝不复制证据文件、绝不改写任何字段——源记录的 ``target_fingerprint`` 漂移
254
+ 与 ``observed_at`` 年龄信号原样保留,引擎也不为继承背书写任何新记录
255
+ (语义审计 BLOCK 条款)。多跳溯源成功时返回 ``chain=a/b -> c/d`` 供结算
256
+ 日志留痕;单跳成功返回空串(与既有日志形态一致)。
257
+ """
258
+ import core.bugx_paths as bugx_paths
259
+
260
+ scope = inheritable_scope(row)
261
+ if not scope:
262
+ return False, "继承单元缺少稳定 scope,拒绝溯源"
263
+ base = bugx_paths.bugx_root(root) / "pollings"
264
+ polling_id, lifecycle_id = str(polling_id), str(lifecycle_id)
265
+ visited: set[tuple[str, str]] = set()
266
+ chain: list[str] = []
267
+ while True:
268
+ chain.append(f"{polling_id}/{lifecycle_id}")
269
+ key = (polling_id, lifecycle_id)
270
+ if key in visited:
271
+ return False, "继承链成环: " + " -> ".join(chain)
272
+ visited.add(key)
273
+ if len(visited) > MAX_INHERITED_CHAIN_DEPTH:
274
+ return False, (
275
+ f"继承链深度超过上限 {MAX_INHERITED_CHAIN_DEPTH}: "
276
+ + " -> ".join(chain)
277
+ )
278
+ source_state = base / polling_id / "lifecycles" / lifecycle_id / "state"
279
+ source_unit_id, source_note, reason = _covered_source_verdict(
280
+ source_state, scope,
281
+ )
282
+ if not source_unit_id:
283
+ return False, reason
284
+ passed, reason, found = _passed_source_evidence(
285
+ source_state, source_unit_id, workspace_root=root,
286
+ )
287
+ if passed:
288
+ if len(chain) == 1:
289
+ return True, ""
290
+ return True, "chain=" + " -> ".join(chain)
291
+ if found:
292
+ # 本地存在可解析的非 passed 记录:矛盾证据,禁止沿链绕过。
293
+ return False, reason
294
+ reference = inherited_evidence_reference(source_note)
295
+ if reference is None:
296
+ # 该跳的 covered 判定自称本地产出,却没有本地 passed 记录:
297
+ # 完整性异常,保持 fail-closed(伪造清单在此被拦截)。
298
+ return False, reason
299
+ polling_id, lifecycle_id = reference
300
+
301
+
302
+ def accept_inherited_evidence(
303
+ rows: list[ModuleRow], root: Path, missing: list[str],
304
+ ) -> set[str]:
305
+ """对缺失证据的单元尝试 bootstrap 继承引用,返回通过核实的 unit_id 集合。
306
+
307
+ 接受时在结算输出记录 ``covered via inherited evidence from`` 引用;拒绝时
308
+ 向 stderr 打印含源路径与原因的显式告警(R7 复盘第三节:继承失败不得静默)。
309
+ """
310
+ if not missing:
311
+ return set()
312
+ rows_by_id = {coverage_unit_id(row): row for row in rows}
313
+ accepted: set[str] = set()
314
+ for unit_id in missing:
315
+ row = rows_by_id.get(unit_id)
316
+ if row is None or getattr(row, "status", "") != "已覆盖":
317
+ continue
318
+ reference = inherited_evidence_reference(getattr(row, "note", "") or "")
319
+ if reference is None:
320
+ continue
321
+ polling_id, lifecycle_id = reference
322
+ ok, reason = resolve_inherited_evidence(root, row, polling_id, lifecycle_id)
323
+ if ok:
324
+ accepted.add(unit_id)
325
+ # 多跳溯源时 reason 形如 chain=a/b -> c/d,必须随结算日志留痕,
326
+ # 保证继承通过的证据始终可追溯到原始证据 lifecycle。
327
+ detail = f" ({reason})" if reason else ""
328
+ print(
329
+ f"[coverage] {unit_id} covered via inherited evidence "
330
+ f"from {polling_id}/{lifecycle_id}{detail}"
331
+ )
332
+ else:
333
+ print(
334
+ f"[coverage] ⚠ 继承证据引用校验失败 unit={unit_id} "
335
+ f"source={polling_id}/{lifecycle_id}: {reason}",
336
+ file=sys.stderr,
337
+ )
338
+ return accepted
339
+
340
+
341
+ def _observed_record_epoch(observed_at: str) -> float | None:
342
+ """把证据记录的 ``observed_at``(ISO-8601)解析为 epoch 秒;失败返回 None。
343
+
344
+ 只读解析,不做任何宽恕:调用方对 None 按各自语义 fail-closed 处理。
345
+ """
346
+ text = str(observed_at or "").strip()
347
+ if not text:
348
+ return None
349
+ try:
350
+ return datetime.fromisoformat(text.replace("Z", "+00:00")).timestamp()
351
+ except (ValueError, OverflowError, OSError):
352
+ return None
353
+
354
+
355
+ def _local_evidence_records(
356
+ evidence_path: Path,
357
+ ) -> tuple[list[dict[str, object]], str]:
358
+ """只读装载本 lifecycle 的本地证据记录(R-1 P1 本地预查的数据基础)。
359
+
360
+ 返回 ``(records, error)``:``error`` 非空表示证据文件**存在但无法解析**
361
+ 或形状非法(census 对此整体 fail-closed;verdict P1 同
362
+ ``_passed_source_evidence`` 口径视为「无可判定本地记录」落到 P2 沿链)。
363
+ 文件缺失返回 ``([], "")``——纯继承 Life 的合法形态(L3-only),P1 无本地
364
+ 记录、判定自然落到 P2。本函数绝不写任何文件。
365
+ """
366
+ if evidence_path.is_symlink() or not evidence_path.is_file():
367
+ return [], ""
368
+ try:
369
+ payload = json.loads(evidence_path.read_text(encoding="utf-8"))
370
+ except (OSError, UnicodeError, ValueError) as exc:
371
+ return [], f"证据文件无法解析: {evidence_path}: {exc}"
372
+ raw_records = payload.get("records") if isinstance(payload, dict) else None
373
+ if not isinstance(raw_records, list):
374
+ return [], f"证据文件缺少 records 数组: {evidence_path}"
375
+ return [item for item in raw_records if isinstance(item, dict)], ""
376
+
377
+
378
+ def _latest_local_record(
379
+ records_by_unit: dict[str, list[dict[str, object]]], unit_id: str,
380
+ *, workspace_root: Path,
381
+ ) -> tuple[dict[str, object] | None, float | None, list[str]]:
382
+ """取该单元按 ``observed_at`` **最新**的本地记录(R-1 P1「取最新」口径)。
383
+
384
+ 返回 ``(record, observed_epoch, exclusions)``:无可用记录返回
385
+ ``(None, None, exclusions)``;时间戳不可解析时 ``observed_epoch`` 为
386
+ None,调用方按 fail-closed 口径处理(无法证明早于本轮 → 视为本轮新增)。
387
+ 排序规则:不可解析时间戳视为最新(fail-closed 保守),同 epoch 按文件序
388
+ (append = checkpoint 时序)取后者。结论只依赖证据文件当前状态,可确定
389
+ 性重算。
390
+
391
+ 记录候选门槛(OQ-5 用户裁决 2026-11-18):``EvidenceRecord.from_dict``
392
+ 形状校验之外,须通过 ``record_authority_check``(sha 完整性 +
393
+ ``target_drifted`` 标志 + 当前指纹一致性,store/validate 同口径)。
394
+ 校验失败的记录不构成可判定候选——**排除原因逐条记入 ``exclusions``
395
+ 留痕**(不静默丢弃);完好记录仍正常参与排序,仅当该单元不存在任何
396
+ 完好候选时才落 ``None`` 交由调用方走下一优先级。
397
+ """
398
+ from core.coverage import coverage_evidence
399
+
400
+ candidates = records_by_unit.get(unit_id) or []
401
+ best: tuple[tuple[float, float, int], dict[str, object], float | None] | None = None
402
+ exclusions: list[str] = []
403
+ for index, item in enumerate(candidates):
404
+ if not isinstance(item, dict):
405
+ continue
406
+ try:
407
+ record = coverage_evidence.EvidenceRecord.from_dict(item)
408
+ except ValueError as exc:
409
+ # 损坏记录(同口径 _passed_source_evidence found=False):不构成
410
+ # 可判定候选,也不阻断对其余记录的判定。
411
+ exclusions.append(f"records[{index}] 形状损坏: {exc}")
412
+ continue
413
+ ok, reason = coverage_evidence.record_authority_check(
414
+ record, workspace_root, require_current_fingerprint=True,
415
+ )
416
+ if not ok:
417
+ exclusions.append(f"records[{index}] 权威校验失败: {reason}")
418
+ continue
419
+ epoch = _observed_record_epoch(str(item.get("observed_at") or ""))
420
+ # 不可解析 → 排序键第一分量取 2(恒新于任何可解析记录,fail-closed)。
421
+ order_key = (2, 0.0, index) if epoch is None else (1, epoch, index)
422
+ if best is None or order_key > best[0]:
423
+ best = (order_key, item, epoch)
424
+ if best is None:
425
+ return None, None, exclusions
426
+ return best[1], best[2], exclusions
427
+
428
+
429
+ def _resolve_unit_backing(
430
+ root: Path,
431
+ row: ModuleRow,
432
+ *,
433
+ local_record: dict[str, object] | None,
434
+ observed_epoch: float | None,
435
+ round_started_epoch: float,
436
+ record_exclusions: list[str] | None = None,
437
+ ) -> dict[str, object]:
438
+ """按合账语义 R-1 优先级解析单个 covered 判定行的归属。
439
+
440
+ P1 本地最新记录(L1/L2,``observed_at`` 取最新)> P2 沿链继承(L3,
441
+ ``resolve_inherited_evidence`` 现行 fail-closed 规则逐字不变)> P3
442
+ unbacked。返回 ``{covered, backing, reference, chain, reason, detail,
443
+ local_record}``:
444
+
445
+ * P1.a passed/exit 0 → ``covered=True``,``backing=local_round``(本轮)
446
+ 或 ``local_historical``(早于本轮开始;时间戳不可解析按 fail-closed
447
+ 归入本轮);清单行带 ``inherited_from`` 备注时尽力沿链解析 ``chain``
448
+ 作双记录审计留痕(S6:祖先矛盾**不阻断**本地判定,只记入 reason)。
449
+ * P1.b 非 passed(failed/error)→ ``covered=False``,
450
+ ``backing=local_overturns``(新证据为准,继承判定被推翻,R-4/R-5)。
451
+ * P2.c 溯源可达祖先 passed → ``covered=True``,``backing=inherited``。
452
+ * P2.d/P3 → ``covered=False``,``backing=unbacked``(伪造/无凭据,
453
+ fail-closed)。
454
+
455
+ ``inherited`` 判定(维度 1 豁免决策字段)由调用方按
456
+ ``backing == "inherited"`` 推导:字面 DIM1 只有沿链继承豁免(R-6)。
457
+ """
458
+ note = getattr(row, "note", "") or ""
459
+ reference = inherited_evidence_reference(note)
460
+ reference_str = f"{reference[0]}/{reference[1]}" if reference else None
461
+ # OQ-5:被权威校验排除的记录逐条留痕(sha 不符/漂移标志/指纹漂移),
462
+ # 不静默丢弃——判定结论无论落到哪一优先级,审计者都能看到排除依据。
463
+ exclusion_note = (
464
+ ";记录排除: " + "; ".join(record_exclusions)
465
+ if record_exclusions else ""
466
+ )
467
+ result: dict[str, object] = {
468
+ "covered": False,
469
+ "backing": "unbacked",
470
+ "reference": reference_str,
471
+ "chain": "",
472
+ "reason": "",
473
+ "detail": "",
474
+ "local_record": None,
475
+ }
476
+ if local_record is not None:
477
+ status = str(local_record.get("status") or "")
478
+ result["local_record"] = {
479
+ "observed_at": str(local_record.get("observed_at") or ""),
480
+ "worker_id": str(local_record.get("worker_id") or ""),
481
+ "status": status,
482
+ }
483
+ if status == "passed" and local_record.get("exit_code") == 0:
484
+ result["covered"] = True
485
+ if (
486
+ observed_epoch is not None
487
+ and observed_epoch < float(round_started_epoch)
488
+ ):
489
+ result["backing"] = "local_historical"
490
+ detail = "本地历史 passed 证据(早于本轮开始)"
491
+ else:
492
+ # observed_at 不可解析 → 无法证明早于本轮,fail-closed 归入本轮。
493
+ result["backing"] = "local_round"
494
+ detail = "本轮本地 passed 记录(新证据为准)"
495
+ if reference is not None and inheritable_scope(row):
496
+ chain_ok, chain_reason = resolve_inherited_evidence(
497
+ root, row, reference[0], reference[1],
498
+ )
499
+ if chain_ok:
500
+ # 双记录并存(R-2):chain=<沿链串> 与 local record 同时在案。
501
+ result["chain"] = chain_reason or reference_str or ""
502
+ detail += f";双记录并存,沿链 {result['chain']}"
503
+ else:
504
+ # S6/P4:祖先矛盾不阻断本 lifecycle 判定(P1 短路),
505
+ # 溯源失败只作审计留痕。
506
+ result["reason"] = (
507
+ "祖先链溯源失败(本地实测权威,不阻断判定): "
508
+ f"{chain_reason}"
509
+ )
510
+ result["detail"] = detail + exclusion_note
511
+ return result
512
+ result["backing"] = "local_overturns"
513
+ result["reason"] = (
514
+ f"本地最新记录非 passed(status={status}),"
515
+ "清单/继承判定被新证据推翻(R-1 P1.b)"
516
+ )
517
+ result["detail"] = result["reason"] + exclusion_note
518
+ return result
519
+ # P2:无本地记录 → 清单行 inherited_from 备注 → 沿链溯源(现行规则)。
520
+ if reference is not None:
521
+ if not inheritable_scope(row):
522
+ result["reason"] = "无稳定 scope,无法沿链溯源继承引用"
523
+ result["detail"] = result["reason"] + exclusion_note
524
+ return result
525
+ ok, reason = resolve_inherited_evidence(root, row, reference[0], reference[1])
526
+ if ok:
527
+ result["covered"] = True
528
+ result["backing"] = "inherited"
529
+ result["chain"] = reason or reference_str or ""
530
+ result["detail"] = result["chain"] + exclusion_note
531
+ return result
532
+ result["reason"] = f"继承链溯源失败: {reason}"
533
+ result["detail"] = result["reason"] + exclusion_note
534
+ return result
535
+ # P3:无本地记录且无备注。
536
+ result["reason"] = (
537
+ "covered 行无 inherited_from 备注(继承豁免只认沿链继承覆盖)"
538
+ if inheritable_scope(row)
539
+ else "无稳定 scope 且无本地记录或 inherited_from 备注"
540
+ )
541
+ result["detail"] = result["reason"] + exclusion_note
542
+ return result
543
+
544
+
545
+ def inherited_unit_coverage_verdicts(
546
+ root: Path, manifest_path: Path, scopes: Iterable[str], *,
547
+ evidence_path: Path, round_started_epoch: float,
548
+ ) -> dict[str, dict[str, object]]:
549
+ """只读判定:每个 scope 最近一次 covered 判定的合账归属(R-1 优先级)。
550
+
551
+ 供恢复会话结算语义的维度 1(继承豁免)使用。判定按 R-1 读取优先级:
552
+
553
+ P1 先查本 lifecycle ``coverage-evidence.json`` 中该单元(scope → 当前
554
+ 清单行 unit_id)的最新本地记录(L1/L2,同 ``_passed_source_evidence``
555
+ 口径校验记录形状):passed/exit 0 → ``covered=True`` 且 ``backing``
556
+ 为 ``local_round``/``local_historical``;非 passed → ``covered=False``
557
+ 且 ``backing=local_overturns``(新证据推翻继承判定,R-4)。P1 无本地
558
+ 记录才走 P2:清单行带 ``inherited_from`` 备注 →
559
+ :func:`resolve_inherited_evidence` 沿链溯源(现行 fail-closed 规则逐字
560
+ 不变),可达祖先 passed → ``backing=inherited``;失败/无备注 →
561
+ ``backing=unbacked``。清单行遗留的 ``inherited_from`` 备注不再遮蔽更新
562
+ 的本地实测(双记录场景 R-2:本地为判定权威,chain 作历史层留痕并存)。
563
+
564
+ **维度 1 决策字段不变(R-6 字面裁决)**:``inherited=True`` 当且仅当
565
+ ``backing == "inherited"``(沿链继承豁免);本地证据覆盖
566
+ (``local_round``/``local_historical``)不触发豁免(OQ-1 有意的
567
+ fail-closed 浪费,放宽与否待用户裁决)。supersede 快照经 ``backing``
568
+ 可区分「凭继承豁免」与「凭本地证据豁免」。
569
+
570
+ fail-closed 红线:scope 无 covered 判定、清单行**无** ``inherited_from``
571
+ 备注(伪造继承覆盖)、或链溯源失败(伪造引用在此被拦),一律
572
+ ``inherited=False`` 并附拒绝原因。本地证据文件缺失/无法解析时 P1 视为
573
+ 无本地记录(同 ``_passed_source_evidence`` 口径),判定落到 P2——与
574
+ legacy(纯链判定)行为一致,不因基础设施故障放宽。本函数绝不写任何
575
+ 文件、绝不改写清单。
576
+ """
577
+ wanted = [str(scope).strip() for scope in scopes if str(scope).strip()]
578
+ if not wanted:
579
+ return {}
580
+
581
+ def _denied(reason: str, reference: str | None = None) -> dict[str, object]:
582
+ return {
583
+ "inherited": False, "covered": False, "backing": "unbacked",
584
+ "reference": reference, "chain": "", "reason": reason,
585
+ "detail": reason, "local_record": None,
586
+ }
587
+
588
+ if manifest_path.is_symlink() or not manifest_path.is_file():
589
+ return {s: _denied(f"清单缺失: {manifest_path}") for s in wanted}
590
+ try:
591
+ rows, parse_errors = parse_manifest(manifest_path)
592
+ except (OSError, UnicodeError, ValueError) as exc:
593
+ return {s: _denied(f"清单无法解析: {exc}") for s in wanted}
594
+ if parse_errors:
595
+ return {
596
+ s: _denied(f"清单无效: {'; '.join(parse_errors[:3])}")
597
+ for s in wanted
598
+ }
599
+ # R-1 P1 数据基础:本 lifecycle 本地证据记录(缺失/损坏 → 无本地记录)。
600
+ records, _evidence_error = _local_evidence_records(evidence_path)
601
+ records_by_unit: dict[str, list[dict[str, object]]] = {}
602
+ for record in records:
603
+ unit_key = str(record.get("unit_id") or "")
604
+ if unit_key:
605
+ records_by_unit.setdefault(unit_key, []).append(record)
606
+ # 与 _covered_source_verdict 同口径:后写覆盖先写,取最近一次 covered 判定。
607
+ newest_covered: dict[str, ModuleRow] = {}
608
+ for row in rows:
609
+ if getattr(row, "status", "") == "已覆盖":
610
+ scope = inheritable_scope(row)
611
+ if scope:
612
+ newest_covered[scope] = row
613
+ verdicts: dict[str, dict[str, object]] = {}
614
+ for scope in wanted:
615
+ row = newest_covered.get(scope)
616
+ if row is None:
617
+ verdicts[scope] = _denied(
618
+ f"清单没有该 scope 的 covered 判定: scope={scope}"
619
+ )
620
+ continue
621
+ local_record, observed_epoch, exclusions = _latest_local_record(
622
+ records_by_unit, coverage_unit_id(row), workspace_root=root,
623
+ )
624
+ resolution = _resolve_unit_backing(
625
+ root, row,
626
+ local_record=local_record, observed_epoch=observed_epoch,
627
+ round_started_epoch=round_started_epoch,
628
+ record_exclusions=exclusions,
629
+ )
630
+ verdicts[scope] = {
631
+ "inherited": resolution["backing"] == "inherited",
632
+ "covered": bool(resolution["covered"]),
633
+ "backing": str(resolution["backing"]),
634
+ "reference": resolution["reference"],
635
+ "chain": str(resolution["chain"]),
636
+ "reason": str(resolution["reason"]),
637
+ "detail": str(resolution.get("detail", "")),
638
+ "local_record": resolution["local_record"],
639
+ }
640
+ return verdicts
641
+
642
+
643
+ def recovery_closeout_coverage_census(
644
+ root: Path,
645
+ manifest_path: Path,
646
+ evidence_path: Path,
647
+ round_started_epoch: float,
648
+ ) -> dict[str, object]:
649
+ """只读普查:恢复结算维度 2 条件①/②的覆盖来源账本(R-1 归属口径)。
650
+
651
+ 回答两个问题(语义见 budget_governor 恢复会话结算注释块):
652
+
653
+ 1. 本 Life 的 covered 判定是否 100% 来自「沿链继承」或「本 Life 历史
654
+ 证据」(observed_at 早于本轮开始时间的本地 passed 记录)——
655
+ 即零新增挖掘意图(条件①);
656
+ 2. 本 round 是否**零新增证据记录**——OQ-2 加强口径:统计全部状态的
657
+ 记录(含 failed/error,不只 passed),任何新证据都证明本轮存在真实
658
+ 挖掘/重派动作,并发证明债豁免必须整体退场(条件②)。
659
+
660
+ 每条 covered 判定的归属按合账语义 R-1 优先级判定(**本地直查先于沿链**,
661
+ 反转 legacy「有备注先沿链」在双记录场景的误标):本 lifecycle 最新本地
662
+ 记录(P1:passed → ``local_round``/``local_historical``;非 passed →
663
+ ``local_overturns``)> 沿链继承(P2:备注 + ``resolve_inherited_evidence``
664
+ 溯源通过 → ``inherited``;溯源失败 → ``unbacked``)> unbacked。entries
665
+ 携带本地记录身份(observed_at/worker_id/status)与 ``chain_reference``;
666
+ 清单行自称 covered 而判定为推翻/溯源失败的单元记入 ``divergences``
667
+ (R-5 显性化,不做清单行自动翻转)。清单/证据文件损坏、解析失败一律
668
+ fail-closed(available=False 且两条件为 False);证据文件缺失是纯继承
669
+ Life 的合法形态。
670
+ """
671
+ fail: dict[str, object] = {
672
+ "available": False,
673
+ "covered_all_inherited_or_historical": False,
674
+ "no_new_evidence_records_this_round": False,
675
+ }
676
+ if manifest_path.is_symlink() or not manifest_path.is_file():
677
+ return {**fail, "reason": f"清单缺失: {manifest_path}"}
678
+ try:
679
+ rows, parse_errors = parse_manifest(manifest_path)
680
+ except (OSError, UnicodeError, ValueError) as exc:
681
+ return {**fail, "reason": f"清单无法解析: {exc}"}
682
+ if parse_errors:
683
+ return {
684
+ **fail,
685
+ "reason": f"清单无效: {'; '.join(parse_errors[:3])}",
686
+ }
687
+
688
+ evidence_absent = evidence_path.is_symlink() or not evidence_path.is_file()
689
+ records, evidence_error = _local_evidence_records(evidence_path)
690
+ evidence_note = ""
691
+ if evidence_error:
692
+ # 证据文件存在但损坏/形状非法:基础设施故障,整体 fail-closed。
693
+ return {**fail, "reason": evidence_error}
694
+ if evidence_absent:
695
+ evidence_note = "证据文件缺失(纯继承 Life 的合法形态)"
696
+
697
+ # OQ-2 加强口径:本轮新增证据记录 = 全部状态(含 failed/error)。
698
+ # None = 时间戳不可解析:无法证明不是本轮新增,fail-closed 计入。
699
+ new_evidence_this_round = 0
700
+ for record in records:
701
+ epoch = _observed_record_epoch(str(record.get("observed_at") or ""))
702
+ if epoch is None or epoch >= float(round_started_epoch):
703
+ new_evidence_this_round += 1
704
+ records_by_unit: dict[str, list[dict[str, object]]] = {}
705
+ for record in records:
706
+ unit_key = str(record.get("unit_id") or "")
707
+ if unit_key:
708
+ records_by_unit.setdefault(unit_key, []).append(record)
709
+
710
+ entries: list[dict[str, object]] = []
711
+ unbacked = 0
712
+ inherited_total = 0
713
+ historical_total = 0
714
+ local_round_total = 0
715
+ overturns_total = 0
716
+ # 与 _covered_source_verdict 同口径:后写覆盖先写。身份用 scope;scope
717
+ # 不稳定(业务行 path 为 ``-``)的行退回 unit_id 身份,不得静默跳过。
718
+ newest_covered: dict[str, ModuleRow] = {}
719
+ order: list[str] = []
720
+ for row in rows:
721
+ if getattr(row, "status", "") != "已覆盖":
722
+ continue
723
+ scope = inheritable_scope(row)
724
+ identity = scope or f"unit:{coverage_unit_id(row)}"
725
+ if identity not in newest_covered:
726
+ order.append(identity)
727
+ newest_covered[identity] = row
728
+ for identity in order:
729
+ row = newest_covered[identity]
730
+ unit_id = coverage_unit_id(row)
731
+ local_record, observed_epoch, exclusions = _latest_local_record(
732
+ records_by_unit, unit_id, workspace_root=root,
733
+ )
734
+ resolution = _resolve_unit_backing(
735
+ root, row,
736
+ local_record=local_record, observed_epoch=observed_epoch,
737
+ round_started_epoch=round_started_epoch,
738
+ record_exclusions=exclusions,
739
+ )
740
+ backing = str(resolution["backing"])
741
+ if backing == "inherited":
742
+ inherited_total += 1
743
+ elif backing == "local_historical":
744
+ historical_total += 1
745
+ elif backing == "local_round":
746
+ local_round_total += 1
747
+ elif backing == "local_overturns":
748
+ overturns_total += 1
749
+ else:
750
+ unbacked += 1
751
+ entries.append({
752
+ "identity": identity, "unit_id": unit_id,
753
+ "backing": backing,
754
+ "detail": str(resolution.get("detail", "")),
755
+ "covered": bool(resolution["covered"]),
756
+ "manifest_row_status": getattr(row, "status", ""),
757
+ "evidence_verdict": (
758
+ "covered" if resolution["covered"] else "not_covered"
759
+ ),
760
+ "chain_reference": resolution["reference"],
761
+ "chain": str(resolution["chain"]),
762
+ "reason": str(resolution["reason"]),
763
+ "local_record": resolution["local_record"],
764
+ })
765
+ # R-5 divergence 显性化:清单行自称已覆盖(含 inherited_from 引用)而
766
+ # 判定为「新证据推翻」或「沿链溯源失败」。不做清单行自动翻转(OQ-3),
767
+ # 后果走诚实路径:该单元不在有效 covered 集 → coverage_complete 不成立。
768
+ divergences = [
769
+ entry for entry in entries
770
+ if entry["backing"] == "local_overturns"
771
+ or (entry["backing"] == "unbacked" and entry["chain_reference"])
772
+ ]
773
+ return {
774
+ "available": True,
775
+ "covered_total": len(entries),
776
+ # entries 全量在案(R-3.4 审计四跳:快照 → 本地记录 → 祖先记录 → 清单
777
+ # 备注引用,全部机读可达;backing/local_record/chain_reference 逐行在案)。
778
+ "entries": entries,
779
+ "inherited_total": inherited_total,
780
+ "historical_local_total": historical_total,
781
+ "local_round_total": local_round_total,
782
+ "local_overturns_total": overturns_total,
783
+ "unbacked_total": unbacked,
784
+ "unbacked_entries": [e for e in entries if e["backing"] == "unbacked"],
785
+ "divergences": divergences,
786
+ "new_evidence_records_this_round": new_evidence_this_round,
787
+ "evidence_note": evidence_note,
788
+ # 条件①:全部归属落在 {inherited, historical_local} 才算「零新增
789
+ # 挖掘意图」;local_round(新证据)/local_overturns(推翻)/unbacked
790
+ # (伪造)任一在场即 False。
791
+ "covered_all_inherited_or_historical": bool(entries) and all(
792
+ entry["backing"] in {"inherited", "local_historical"}
793
+ for entry in entries
794
+ ),
795
+ # 条件②(OQ-2):零新增证据记录(含 failed/error)。
796
+ "no_new_evidence_records_this_round": new_evidence_this_round == 0,
797
+ }
798
+
799
+
800
+ def evidence_manifest_errors(
801
+ rows: list[ModuleRow], root: Path, manifest: Path | None, *, final: bool,
802
+ require: bool = False,
803
+ ) -> list[str]:
804
+ """Validate worker evidence when an evidence manifest is supplied."""
805
+ if manifest is None:
806
+ if require:
807
+ return ["覆盖证据 manifest 为必需项,不能只凭 Markdown 自报"]
808
+ return []
809
+ expected = {
810
+ coverage_unit_id(row)
811
+ for row in rows
812
+ if row.status == "已覆盖" or final
813
+ }
814
+ if not manifest.is_file():
815
+ # F3':全新 Session 的首个 lifecycle 可能尚无本地证据文件。若全部期望
816
+ # 单元都能经 bootstrap 继承引用在源 lifecycle 核实,则不因文件缺席直接
817
+ # 拒绝;任何单元核实失败,维持原有拒绝(保留缺文件错误本身)。
818
+ if expected and accept_inherited_evidence(rows, root, sorted(expected)) >= expected:
819
+ return []
820
+ # F-RSI-20261118-008b:``expected`` 为空(无已覆盖单元的 allow-incomplete
821
+ # 收口轮)即不存在任何证据义务——manifest 缺席是诚实状态,不再阻断
822
+ # (移动靶场 0/14 覆盖轮 post 实证:与 allow-incomplete 的
823
+ # 「接受诚实的未覆盖债务」语义矛盾)。
824
+ if not expected:
825
+ return []
826
+ return [f"覆盖证据 manifest 不存在: {manifest}"]
827
+ try:
828
+ from core.coverage import coverage_evidence
829
+
830
+ report = coverage_evidence.validate_manifest(
831
+ manifest, workspace_root=root, expected_units=expected,
832
+ )
833
+ except (OSError, ValueError) as exc:
834
+ return [f"覆盖证据 manifest 无法验证: {exc}"]
835
+ errors: list[str] = []
836
+ if report.missing:
837
+ accepted = accept_inherited_evidence(rows, root, list(report.missing))
838
+ unresolved = [unit for unit in report.missing if unit not in accepted]
839
+ if unresolved:
840
+ errors.append("缺少覆盖证据: " + ", ".join(unresolved))
841
+ for key, items in (
842
+ ("invalid", report.invalid), ("stale", report.stale),
843
+ ("duplicate", report.duplicate), ("conflict", report.conflicts),
844
+ ):
845
+ if items:
846
+ errors.append(f"覆盖证据 {key}: {json.dumps(list(items), ensure_ascii=False)}")
847
+ return errors
848
+
849
+
850
+ def participant_ids(value: str) -> set[str]:
851
+ return set(re.findall(r"#?([A-Za-z0-9_.-]+)", value))
852
+
853
+
854
+ def asset_units(root: Path, strict: bool = True,
855
+ asset_paths: list[Path] | None = None) -> list[dict]:
856
+ units: list[dict] = []
857
+ if asset_paths is None:
858
+ asset_paths = symbol_index.discover_asset_paths(root, strict=strict)
859
+ for path in asset_paths:
860
+ relative = path.relative_to(root.resolve()).as_posix()
861
+ units.append({
862
+ "scope": relative,
863
+ "path": relative,
864
+ "name": path.name,
865
+ "kind": "asset",
866
+ "line": 1,
867
+ "parser": "asset-inventory",
868
+ "error": None,
869
+ "language": "asset",
870
+ "content_hash": symbol_index.file_sha256(path),
871
+ })
872
+ return units
873
+
874
+
875
+ def discovery_units(root: Path, symbols: bool = True, strict: bool = True,
876
+ asset_paths: list[Path] | None = None) -> list[dict]:
877
+ """Build the authoritative source + behavior-asset discovery list."""
878
+ root = root.resolve()
879
+ if symbols:
880
+ units = symbol_index.audit_units(root, strict=strict)
881
+ else:
882
+ units = [
883
+ {
884
+ "scope": path,
885
+ "path": path,
886
+ "name": Path(path).stem,
887
+ "kind": "file",
888
+ "line": 1,
889
+ "parser": "files-only",
890
+ "error": None,
891
+ "content_hash": symbol_index.file_sha256(root / path),
892
+ }
893
+ for path in sorted(discover_minimum_unit_paths(root, strict=strict))
894
+ ]
895
+ return units + asset_units(root, strict=strict, asset_paths=asset_paths)
896
+
897
+
898
+ def row_text(row: ModuleRow) -> str:
899
+ path = row.path if row.path.startswith("`") else f"`{row.path}`"
900
+ values = [
901
+ row.number, row.phase, row.parent, row.name, path,
902
+ row.participants, row.minimality, row.difficulty, row.hit, row.tool,
903
+ row.owner, row.deps, row.status, row.findings, row.evidence, row.note,
904
+ ]
905
+ return "| " + " | ".join(values) + " |"
906
+
907
+
908
+ def discovery_row(number: str, unit: dict, *, reset: bool = True,
909
+ previous: ModuleRow | None = None,
910
+ root: Path | None = None,
911
+ risk_cache: dict[tuple[str, str, str], float | None] | None = None) -> ModuleRow:
912
+ file_path = str(unit["path"])
913
+ scope = str(unit["scope"])
914
+ source = Path(file_path)
915
+ parent = str(source.parent) if str(source.parent) != "." else "ROOT"
916
+ kind = str(unit["kind"])
917
+ minimality = (
918
+ "源码文件(未发现可继续拆分的声明)" if kind == "file"
919
+ else "配置/依赖/构建资产,作为独立行为边界"
920
+ if kind == "asset"
921
+ else f"{kind},可独立构造输入与验证行为"
922
+ )
923
+ digest = str(unit.get("content_hash") or "")
924
+ note = f"{unit.get('parser', 'unknown')} line {unit.get('line', 1)}"
925
+ if digest:
926
+ note += f" sha256:{digest}"
927
+ unit_platform_name = unit_platform(scope)
928
+ if unit_platform_name:
929
+ note += f" platform:{unit_platform_name}"
930
+ difficulty = "3"
931
+ calc_risk: float | None = None
932
+ if root is not None:
933
+ try:
934
+ operation_cache = risk_cache if risk_cache is not None else {}
935
+ calc_risk = cached_unit_risk_score(file_path, root, digest, operation_cache)
936
+ if calc_risk is not None:
937
+ from core.repair import test_strategy
938
+
939
+ difficulty = test_strategy.risk_score_to_difficulty(calc_risk)
940
+ note += f" risk:{int(calc_risk)}"
941
+ except Exception:
942
+ pass
943
+ if previous is not None and not reset:
944
+ prev_note = previous.note or note
945
+ if calc_risk is not None:
946
+ if re.search(r"\brisk:\d+", prev_note):
947
+ prev_note = re.sub(r"\brisk:\d+", f"risk:{int(calc_risk)}", prev_note)
948
+ else:
949
+ prev_note += f" risk:{int(calc_risk)}"
950
+ return ModuleRow(
951
+ number=number, phase="内部", parent=parent,
952
+ name=str(unit["name"]), path=scope,
953
+ participants=previous.participants, minimality=previous.minimality,
954
+ difficulty=difficulty if previous.difficulty in {"1", "2", "3", "4", "5"} else previous.difficulty,
955
+ hit=previous.hit,
956
+ tool=previous.tool, owner=previous.owner, deps=previous.deps,
957
+ status=previous.status, findings=previous.findings,
958
+ evidence=previous.evidence, note=prev_note,
959
+ )
960
+ return ModuleRow(
961
+ number=number, phase="内部", parent=parent,
962
+ name=str(unit["name"]), path=scope, participants="-",
963
+ minimality=minimality, difficulty=difficulty, hit="3", tool="待定",
964
+ owner="待定", deps="无", status="未覆盖", findings="0",
965
+ evidence="待补", note=note,
966
+ )
967
+
968
+
969
+ def discovery_rows(root: Path, symbols: bool = True) -> list[str]:
970
+ """生成源码、配置和依赖资产的内部最小单元 Markdown 行。"""
971
+ units = discovery_units(root, symbols=symbols, strict=True)
972
+ unit_errors = [unit for unit in units if unit.get("error")]
973
+ if unit_errors:
974
+ raise symbol_index.SourceDiscoveryError(
975
+ "源码解析不完整,拒绝生成覆盖清单: "
976
+ + "; ".join(
977
+ f"{unit['path']}: {unit['error']}" for unit in unit_errors[:5]
978
+ )
979
+ )
980
+ risk_cache: dict[tuple[str, str, str], float | None] = {}
981
+ return [row_text(discovery_row(str(index), unit, root=root, risk_cache=risk_cache))
982
+ for index, unit in enumerate(units, 1)]
983
+
984
+
985
+ WEB_ENDPOINT_PATTERNS = [
986
+ # FastAPI / Flask / Bottle / Tornado: @app.get('/path'), @router.post("/path"), @bp.route("/path", methods=[...])
987
+ (
988
+ re.compile(
989
+ r"""@(?:app|router|bp|blueprint|api)\.(get|post|put|delete|patch|options|head|route)\s*\(\s*["']([^"']+)["']""",
990
+ re.IGNORECASE,
991
+ ),
992
+ "python_route",
993
+ ),
994
+ # Express / Koa / Router (JS/TS): app.get('/path', ...), router.post('/path', ...)
995
+ (
996
+ re.compile(
997
+ r"""\b(?:app|router)\.(get|post|put|delete|patch|options|head)\s*\(\s*["']([^"']+)["']""",
998
+ re.IGNORECASE,
999
+ ),
1000
+ "js_route",
1001
+ ),
1002
+ # NestJS decorators (@Get('/path'), @Post('/path'))
1003
+ (
1004
+ re.compile(
1005
+ r"""@(Get|Post|Put|Delete|Patch|Options|Head)\s*\(\s*["']([^"']+)["']""",
1006
+ ),
1007
+ "nestjs_route",
1008
+ ),
1009
+ # Go Gin / Echo: r.GET("/path", ...), e.POST("/path", ...)
1010
+ (
1011
+ re.compile(
1012
+ r"""\.(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)\s*\(\s*["']([^"']+)["']""",
1013
+ ),
1014
+ "go_route",
1015
+ ),
1016
+ # Go net/http: http.HandleFunc("/path", ...)
1017
+ (
1018
+ re.compile(
1019
+ r"""http\.HandleFunc\s*\(\s*["']([^"']+)["']""",
1020
+ ),
1021
+ "go_http",
1022
+ ),
1023
+ ]
1024
+
1025
+ CLI_COMMAND_PATTERNS = [
1026
+ # Click: @click.command("name") or @click.group("name") or @cli.command("name")
1027
+ (
1028
+ re.compile(
1029
+ r"""@(?:click|cli|group|cmd)\.(?:command|group)\s*(?:\(\s*(?:name\s*=\s*)?["']([^"']+)["']|\(\s*\))?""",
1030
+ ),
1031
+ "click_cli",
1032
+ ),
1033
+ # Argparse add_parser: subparsers.add_parser("cmd", ...)
1034
+ (
1035
+ re.compile(
1036
+ r"""(?:add_parser|add_command)\s*\(\s*["']([^"']+)["']""",
1037
+ ),
1038
+ "argparse_cli",
1039
+ ),
1040
+ ]
1041
+
1042
+
1043
+ def announce_feature_surface(root: Path, surfaces: list[dict[str, Any]]) -> None:
1044
+ """DOC-125 C125-2:端点切面一旦被抽取出来,就即刻喂给活图谱。
1045
+
1046
+ 这里是全仓**唯一**真正产出 endpoint 事实的地方(业务清单的 EP 行同源),
1047
+ 所以 ``endpoint_discovered`` / ``endpoints_ready`` 从这根管线发出,图谱才不再是
1048
+ 无人写的死库。清单生成绝不能因为图谱写不进去而失败,因此:未初始化的工作区
1049
+ (``bugx_paths.require`` 抛 LayoutError)、引擎副本缺 ``attack_graph*.py``、
1050
+ 快照损坏等一律静默降级——图谱的可观测性由 pre/post 的 ``attack-graph-*``
1051
+ 运行事件负责,那条路径在拥有完整布局的地方跑。
1052
+ """
1053
+ if not surfaces:
1054
+ return
1055
+ try:
1056
+ from core.autonomous_cve import attack_graph_store
1057
+
1058
+ attack_graph_store.absorb_surface(Path(root), surfaces)
1059
+ except Exception: # noqa: BLE001 - 图谱降级不得冒泡到清单生成
1060
+ pass
1061
+
1062
+
1063
+ def extract_feature_surface(root: Path) -> list[dict[str, Any]]:
1064
+ """提取工程中的业务特性切面与端点(Web API 路由、CLI 命令端点等)。"""
1065
+ root = root.resolve()
1066
+ surfaces: list[dict[str, Any]] = []
1067
+ seen: set[str] = set()
1068
+
1069
+ try:
1070
+ source_paths = sorted(discover_audit_unit_paths(root, strict=False))
1071
+ except Exception:
1072
+ source_paths = []
1073
+
1074
+ for rel_path in source_paths:
1075
+ file_path = root / rel_path
1076
+ if not file_path.is_file() or file_path.stat().st_size > 512 * 1024:
1077
+ continue
1078
+ try:
1079
+ content = file_path.read_text(encoding="utf-8", errors="replace")
1080
+ except (OSError, UnicodeDecodeError):
1081
+ continue
1082
+
1083
+ for line_no, line in enumerate(content.splitlines(), 1):
1084
+ line_str = line.strip()
1085
+ if not line_str or line_str.startswith(("#", "//", "/*", "*")):
1086
+ continue
1087
+
1088
+ # 1. 匹配 Web API 路由
1089
+ for pattern, fw in WEB_ENDPOINT_PATTERNS:
1090
+ m = pattern.search(line_str)
1091
+ if m:
1092
+ if fw == "go_http":
1093
+ method = "ALL"
1094
+ route_path = m.group(1)
1095
+ else:
1096
+ method = m.group(1).upper()
1097
+ route_path = m.group(2)
1098
+ if method == "ROUTE":
1099
+ method = "ALL"
1100
+ if not route_path.startswith("/"):
1101
+ route_path = "/" + route_path
1102
+ name = f"endpoint:{method}:{route_path}"
1103
+ if name not in seen:
1104
+ seen.add(name)
1105
+ surfaces.append({
1106
+ "type": "endpoint",
1107
+ "name": name,
1108
+ "method": method,
1109
+ "path": route_path,
1110
+ "source_file": rel_path,
1111
+ "line": line_no,
1112
+ "framework": fw,
1113
+ })
1114
+
1115
+ # 2. 匹配 CLI 命令
1116
+ for pattern, fw in CLI_COMMAND_PATTERNS:
1117
+ m = pattern.search(line_str)
1118
+ if m:
1119
+ cmd_name = m.group(1) if m.groups() and m.group(1) else ""
1120
+ if not cmd_name:
1121
+ continue
1122
+ name = f"cli:{cmd_name}"
1123
+ if name not in seen:
1124
+ seen.add(name)
1125
+ surfaces.append({
1126
+ "type": "cli",
1127
+ "name": name,
1128
+ "method": "CLI",
1129
+ "path": cmd_name,
1130
+ "source_file": rel_path,
1131
+ "line": line_no,
1132
+ "framework": fw,
1133
+ })
1134
+
1135
+ announce_feature_surface(root, surfaces)
1136
+ return surfaces
1137
+
1138
+
1139
+ def graph_scope(node_id: str) -> str:
1140
+ if node_id.startswith("symbol:"):
1141
+ return node_id[len("symbol:"):]
1142
+ if node_id.startswith("file:"):
1143
+ return node_id[len("file:"):]
1144
+ return node_id
1145
+
1146
+
1147
+ def business_discovery(root: Path, rows: list[ModuleRow]) -> dict:
1148
+ """把自动关系图中的 scope 映射到清单内部单元编号。"""
1149
+ graph = project_graph.build_graph(root)
1150
+ flows = project_graph.discover_business_flows(graph) if graph.get("complete") else []
1151
+ scope_to_id = {
1152
+ row.path.strip().strip("`").rstrip("/"): row.number
1153
+ for row in rows if row.phase == "内部"
1154
+ }
1155
+
1156
+ def closest_scheduled_scope(scope: str) -> str | None:
1157
+ """Map parser-only nested callables to their scheduled owner."""
1158
+ candidate = scope
1159
+ while candidate:
1160
+ if candidate in scope_to_id:
1161
+ return candidate
1162
+ if "::" not in candidate:
1163
+ return None
1164
+ file_path, qualified = candidate.split("::", 1)
1165
+ if "." not in qualified:
1166
+ return None
1167
+ candidate = f"{file_path}::{qualified.rsplit('.', 1)[0]}"
1168
+ return None
1169
+
1170
+ mapped = []
1171
+ for flow in flows:
1172
+ scopes = [graph_scope(node) for node in flow["participants"]]
1173
+ participants = list(dict.fromkeys(
1174
+ scope_to_id[scheduled]
1175
+ for scope in scopes
1176
+ if (scheduled := closest_scheduled_scope(scope)) is not None
1177
+ ))
1178
+ mapped.append({**flow, "scopes": scopes, "participant_ids": participants})
1179
+ return {
1180
+ "schema_version": 1,
1181
+ "complete": graph.get("complete", False),
1182
+ "errors": graph.get("parse_errors", []),
1183
+ "flows": mapped,
1184
+ }
1185
+
1186
+
1187
+ class PassContext:
1188
+ """一次覆盖校验的共享上下文:证据探测缓存 + 全仓枚举结果。
1189
+
1190
+ 生命周期严格限定在单次 ``validate_rows`` 调用(以及调用方显式复用的同一轮
1191
+ 门禁,如 ``startup_gate_errors`` 的「发现单元 + 校验」两步)。跨会话或跨进程
1192
+ 复用会把旧的文件系统快照当成新结论,对安全门禁是正确性风险,因此这里只做
1193
+ 轮内去重,不做全局 memo:``probe`` 缓存证据文件事实,其余槽位缓存
1194
+ ``discover_audit_unit_paths`` / ``discovery_units`` / ``business_discovery``
1195
+ 的全仓遍历结果,三者在一轮内各自只计算一次。
1196
+ """
1197
+
1198
+ __slots__ = ("root", "probe", "_asset_paths", "_audit_paths",
1199
+ "_units", "_units_ready", "_business", "_business_ready")
1200
+
1201
+ def __init__(self, root: Path):
1202
+ self.root = root
1203
+ self.probe = EvidenceProbe(root)
1204
+ self._asset_paths: list[Path] | None = None
1205
+ self._audit_paths: set[str] | None = None
1206
+ self._units: list[dict] | None = None
1207
+ self._units_ready = False
1208
+ self._business: dict | None = None
1209
+ self._business_ready = False
1210
+
1211
+ def asset_paths(self) -> list[Path]:
1212
+ """全仓资产枚举只走一次,供审计单元路径与符号单元共用。"""
1213
+ if self._asset_paths is None:
1214
+ self._asset_paths = symbol_index.discover_asset_paths(
1215
+ self.root, strict=True,
1216
+ )
1217
+ return self._asset_paths
1218
+
1219
+ def audit_unit_paths(self) -> set[str]:
1220
+ """全仓源码/资产路径枚举只跑一次;失败照旧抛给调用方处理。"""
1221
+ if self._audit_paths is None:
1222
+ self._audit_paths = discover_audit_unit_paths(
1223
+ self.root, strict=True, asset_paths=self.asset_paths(),
1224
+ )
1225
+ return self._audit_paths
1226
+
1227
+ def units(self) -> list[dict]:
1228
+ """符号级最小单元枚举只跑一次,复用已枚举的资产列表。"""
1229
+ if not self._units_ready:
1230
+ self._units = discovery_units(
1231
+ self.root, symbols=True, strict=True,
1232
+ asset_paths=self.asset_paths(),
1233
+ )
1234
+ self._units_ready = True
1235
+ return self._units
1236
+
1237
+ def business(self, rows: list[ModuleRow]) -> dict:
1238
+ """自动关系图只构建一次;``rows`` 在同一轮内是稳定入参。"""
1239
+ if not self._business_ready:
1240
+ self._business = business_discovery(self.root, rows)
1241
+ self._business_ready = True
1242
+ return self._business
1243
+
1244
+
1245
+ def auto_business_cap() -> int:
1246
+ """DOC-203 D1-c:自动业务单元生成上限。
1247
+
1248
+ 环境变量 ``BUGX_MAX_AUTO_BUSINESS_UNITS`` 可调;<1、非整数或超上界
1249
+ 回退默认 64 并告警(fail-closed 到保守值,不静默)。硬上界 4096 防
1250
+ env 注入把覆盖义务重新撑爆。
1251
+ """
1252
+ default_cap, max_cap = 64, 4096
1253
+ raw = os.environ.get("BUGX_MAX_AUTO_BUSINESS_UNITS")
1254
+ if not raw:
1255
+ return default_cap
1256
+ try:
1257
+ value = int(str(raw).strip())
1258
+ except (TypeError, ValueError):
1259
+ print(
1260
+ f"[coverage] ⚠ BUGX_MAX_AUTO_BUSINESS_UNITS={raw!r} 非法,"
1261
+ f"回退默认 {default_cap}",
1262
+ file=sys.stderr,
1263
+ )
1264
+ return default_cap
1265
+ if value < 1:
1266
+ print(
1267
+ f"[coverage] ⚠ BUGX_MAX_AUTO_BUSINESS_UNITS={value} < 1,"
1268
+ f"回退默认 {default_cap}",
1269
+ file=sys.stderr,
1270
+ )
1271
+ return default_cap
1272
+ if value > max_cap:
1273
+ print(
1274
+ f"[coverage] ⚠ BUGX_MAX_AUTO_BUSINESS_UNITS={value} 超过硬上界 "
1275
+ f"{max_cap},按 {max_cap} 执行",
1276
+ file=sys.stderr,
1277
+ )
1278
+ return max_cap
1279
+ return value
1280
+
1281
+
1282
+ def business_discovery_rows(root: Path, rows: list[ModuleRow]) -> list[str]:
1283
+ """生成自动业务链路/端点面清单行(DOC-203 D1-c 加上限)。
1284
+
1285
+ 截断只发生在清单**生成**时刻(bootstrap),确定性排序为
1286
+ ``(tier, -confidence, id)``:flow 行按 confidence 降序(非有限/缺失
1287
+ 视为最低档),EP 端点行无置信度语义,固定排在 flow 之后按 id 序。
1288
+ 绝不对已绑定 target_fingerprint 的存量清单做事后截断/收缩/重编号。
1289
+ """
1290
+ # (tier, neg_confidence, id, row) —— tier 0=flow, 1=EP。
1291
+ entries: list[tuple[int, float, str, str]] = []
1292
+ # 1. 关系图自动发现的跨模块业务流
1293
+ for flow in business_discovery(root, rows)["flows"]:
1294
+ p_ids = flow.get("participant_ids") or []
1295
+ if len(p_ids) < 2:
1296
+ continue
1297
+ participants = ",".join(p_ids)
1298
+ evidence = flow["evidence"][0] if flow["evidence"] else "待补"
1299
+ try:
1300
+ confidence = float(flow["confidence"])
1301
+ except (KeyError, TypeError, ValueError):
1302
+ confidence = float("-inf")
1303
+ if not math.isfinite(confidence):
1304
+ confidence = float("-inf")
1305
+ entries.append((
1306
+ 0,
1307
+ -confidence,
1308
+ str(flow["id"]),
1309
+ f"| {flow['id']} | 业务 | AUTO | 自动业务链路 {flow['id']} | - | "
1310
+ f"{participants} | project_graph 自动发现跨模块关系 | 3 | 4 | "
1311
+ f"project_graph | 待定 | {participants} | 未覆盖 | 0 | {evidence} | "
1312
+ f"flow:{flow['id']} confidence={flow['confidence']:.2f} |",
1313
+ ))
1314
+
1315
+ # 2. 功能特性端点与 API 路由切面 (DOC-046)
1316
+ surfaces = extract_feature_surface(root)
1317
+ if surfaces:
1318
+ internal_file_to_id: dict[str, str] = {}
1319
+ for r in rows:
1320
+ if r.phase == "内部":
1321
+ clean_p = r.path.strip().strip("`").split("::")[0].rstrip("/")
1322
+ if clean_p not in internal_file_to_id:
1323
+ internal_file_to_id[clean_p] = r.number
1324
+ all_internals = [r.number for r in rows if r.phase == "内部"]
1325
+
1326
+ for idx, s in enumerate(surfaces, 1):
1327
+ s_id = f"EP{idx:02d}"
1328
+ s_name = s["name"]
1329
+ s_file = s["source_file"]
1330
+ p_ids = []
1331
+ if s_file in internal_file_to_id:
1332
+ p_ids.append(internal_file_to_id[s_file])
1333
+ for uid in all_internals:
1334
+ if uid not in p_ids:
1335
+ p_ids.append(uid)
1336
+ if len(p_ids) >= 2:
1337
+ break
1338
+ participants = ",".join(p_ids) if len(p_ids) >= 2 else (",".join(all_internals[:2]) if len(all_internals) >= 2 else "UNRESOLVED")
1339
+ parent = "API" if s["type"] == "endpoint" else "CLI"
1340
+
1341
+ diff = "3"
1342
+ try:
1343
+ from core.repair import test_strategy
1344
+ risk = test_strategy.calculate_unit_risk_score(s_file, root)
1345
+ diff = test_strategy.risk_score_to_difficulty(risk)
1346
+ r_note = f" risk:{int(risk)}"
1347
+ except Exception:
1348
+ r_note = ""
1349
+
1350
+ entries.append((
1351
+ 1,
1352
+ 0.0,
1353
+ s_id,
1354
+ f"| {s_id} | 业务 | {parent} | {s_name} | - | "
1355
+ f"{participants} | 功能特性端点,驱动内部服务与状态迁移 | {diff} | 4 | "
1356
+ f"project_graph | 待定 | {participants} | 未覆盖 | 0 | 待补 | "
1357
+ f"feature:{s_name}{r_note} framework={s['framework']} |",
1358
+ ))
1359
+
1360
+ cap = auto_business_cap()
1361
+ ordered = sorted(entries, key=lambda entry: (entry[0], entry[1], entry[2]))
1362
+ if len(ordered) > cap:
1363
+ print(
1364
+ f"[coverage] ⚠ 自动业务单元生成 {len(ordered)} 条,超过上限 "
1365
+ f"{cap}(BUGX_MAX_AUTO_BUSINESS_UNITS),已按确定性排序截断;"
1366
+ f"被截单元视同发现范围之外,不伪造覆盖",
1367
+ file=sys.stderr,
1368
+ )
1369
+ ordered = ordered[:cap]
1370
+ return [entry[3] for entry in ordered]
1371
+
1372
+
1373
+ def coverage_summary(rows: list[ModuleRow], errors: list[str] | None = None) -> dict:
1374
+ """返回供状态页/自动化消费的两阶段进度,不把未完成当成命令失败。"""
1375
+ internals = [row for row in rows if row.phase == "内部"]
1376
+ business = [row for row in rows if row.phase == "业务"]
1377
+ internal_covered = sum(row.status == "已覆盖" for row in internals)
1378
+ business_covered = sum(row.status == "已覆盖" for row in business)
1379
+ active_rows = [row for row in rows if row.status in {"挖掘中", "未知"}]
1380
+ if not active_rows:
1381
+ active_rows = [row for row in rows if row.status == "挂起"]
1382
+ if internal_covered < len(internals):
1383
+ phase = "内部"
1384
+ elif business_covered < len(business):
1385
+ phase = "业务"
1386
+ elif rows:
1387
+ phase = "完成"
1388
+ else:
1389
+ phase = "未规划"
1390
+ total = len(internals) + len(business)
1391
+ covered = internal_covered + business_covered
1392
+ unknown_internal = sum(row.status == "未知" for row in internals)
1393
+ unknown_business = sum(row.status == "未知" for row in business)
1394
+ return {
1395
+ "phase": phase,
1396
+ "current_units": [
1397
+ {
1398
+ "id": row.number,
1399
+ "name": row.name,
1400
+ "scope": row.path if row.phase == "内部" else row.participants,
1401
+ "status": row.status,
1402
+ }
1403
+ for row in active_rows
1404
+ ],
1405
+ "internal": {
1406
+ "covered": internal_covered,
1407
+ "total": len(internals),
1408
+ "percent": round(internal_covered / len(internals) * 100, 1)
1409
+ if internals else 0.0,
1410
+ },
1411
+ "business": {
1412
+ "covered": business_covered,
1413
+ "total": len(business),
1414
+ "percent": round(business_covered / len(business) * 100, 1)
1415
+ if business else 0.0,
1416
+ },
1417
+ "unknown": {
1418
+ "internal": unknown_internal,
1419
+ "business": unknown_business,
1420
+ "total": unknown_internal + unknown_business,
1421
+ },
1422
+ "overall": {
1423
+ "covered": covered,
1424
+ "total": total,
1425
+ "percent": round(covered / total * 100, 1) if total else 0.0,
1426
+ },
1427
+ "structure_valid": not errors,
1428
+ "errors": list(errors or []),
1429
+ }