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,1316 @@
1
+ #!/usr/bin/env python3
2
+ """用可执行证据、Oracle 和反事实复验把候选问题升级为确认 Bug。"""
3
+
4
+ from __future__ import annotations
5
+ # --- 引擎导入根(直接执行脚本时自举 core.* 命名空间)---
6
+ import sys as _sys
7
+ from pathlib import Path as _Path
8
+
9
+ for _p in _Path(__file__).resolve().parents:
10
+ if (_p / "core" / "bugx.md").is_file():
11
+ if str(_p) not in _sys.path:
12
+ _sys.path.insert(0, str(_p))
13
+ break
14
+ del _p
15
+
16
+ import argparse
17
+ import json
18
+ import os
19
+ import sys
20
+ import tempfile
21
+ from collections import Counter
22
+ from pathlib import Path
23
+ from typing import Mapping
24
+
25
+ _CURRENT_DIR = Path(__file__).resolve().parent
26
+ _CORE_DIR = _CURRENT_DIR.parent
27
+ _REPO_ROOT = _CORE_DIR.parent
28
+ for _p in (str(_REPO_ROOT), str(_CORE_DIR)):
29
+ if _p not in sys.path:
30
+ sys.path.insert(0, _p)
31
+
32
+ # DES-02:原先这里顶层 ``import agent_eval``,而 agent_eval 又要(延迟)
33
+ # 导入本模块的 ``reproducible_contract_violation`` / ``is_confirmed`` —— 一对
34
+ # 顶层模块互为上下游。本模块对 agent_eval 的需求**只出现在 ``gate()`` 与
35
+ # ``main()`` 两个入口**,因此把导入下沉到函数内:导入期不再成环,运行期
36
+ # 语义完全不变(模块导入有缓存,延迟导入不产生额外开销)。
37
+
38
+ SCHEMA_VERSION = 1
39
+ CONFIRMATION_STATES = (
40
+ "candidate", "observed", "reproduced", "root_caused", "confirmed", "rejected",
41
+ )
42
+ ORACLE_TIERS = {
43
+ "requirement": 1,
44
+ "contract": 2,
45
+ "test": 3,
46
+ "invariant": 4,
47
+ "differential": 5,
48
+ "heuristic": 6,
49
+ }
50
+ OBSERVATION_OUTCOMES = {"failure", "pass", "blocked"}
51
+
52
+ #: 空字符串的 SHA-256:用于判定观测维度是否有实际内容(审计 A1)。
53
+ _EMPTY_SHA256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
54
+ ORACLE_PROVENANCE_KINDS = {
55
+ "user-approved", "repository-contract", "external-spec",
56
+ "independent-implementation", "runtime-invariant", "agent-generated",
57
+ }
58
+ REJECTION_CLASSES = {
59
+ "expected_behavior", "environment", "tool_failure", "duplicate",
60
+ "insufficient_evidence", "flaky", "not_reproducible",
61
+ }
62
+
63
+ # These weights are a quality signal only. They never replace the boolean
64
+ # confirmation gate below; a finding must still satisfy every hard check.
65
+ ASSURANCE_WEIGHTS = {
66
+ "oracle": 20,
67
+ "repeat": 20,
68
+ "independent_channels": 15,
69
+ "negative_control": 15,
70
+ "root_cause": 10,
71
+ "reproduction": 10,
72
+ "target_execution": 10,
73
+ # 工件绑定(F1' 新代际口径):对带 adjudicator_build 标记的新代际
74
+ # confirmed,failure 观测的工件哈希是硬门(缺失即在结算路径回退
75
+ # candidate);存量(无标记)confirmed 维持"缺省不罚"豁免不受追溯。
76
+ # 加分权重本身只作用于 assurance 画像,不改变硬门判定。
77
+ "observation_artifacts": 10,
78
+ }
79
+
80
+
81
+ class ConfirmationError(ValueError):
82
+ """Finding 确认协议错误。"""
83
+
84
+
85
+ REMEDIATION_DECISIONS = {"fixed", "deferred"}
86
+
87
+
88
+ def validate_remediation(finding: dict, root: Path | None = None) -> dict:
89
+ """Validate the non-blocking remediation contract for confirmed Findings."""
90
+ remediation = finding.get("remediation")
91
+ if not isinstance(remediation, dict):
92
+ return {"status": "fix_gap", "errors": ["缺 remediation 块"]}
93
+ decision = remediation.get("decision")
94
+ if decision not in REMEDIATION_DECISIONS:
95
+ return {"status": "fix_gap", "errors": ["remediation.decision 必须是 fixed 或 deferred"]}
96
+ if decision == "fixed":
97
+ fix_ref = remediation.get("fix_ref")
98
+ valid_ref = (
99
+ _nonempty(fix_ref)
100
+ or (
101
+ isinstance(fix_ref, dict)
102
+ and any(_nonempty(fix_ref.get(key)) for key in ("commit_ref", "test_ref"))
103
+ )
104
+ )
105
+ verified = remediation.get("verification_passed") is True
106
+ errors = []
107
+ if not valid_ref:
108
+ errors.append("fixed remediation 缺有效 fix_ref(commit/test 证据)")
109
+ if not verified:
110
+ errors.append("fixed remediation 必须 verification_passed=true")
111
+ return {"status": "ok" if not errors else "fix_gap", "errors": errors}
112
+
113
+ errors: list[str] = []
114
+ for field in ("proposal", "verification_plan"):
115
+ if not _nonempty(remediation.get(field)):
116
+ errors.append(f"deferred remediation 缺 {field}")
117
+ blast_radius = remediation.get("blast_radius")
118
+ if not isinstance(blast_radius, list) or not blast_radius or any(
119
+ not _nonempty(item) for item in blast_radius
120
+ ):
121
+ errors.append("deferred remediation.blast_radius 必须是非空路径数组")
122
+ elif root is not None:
123
+ resolved_root = Path(root).resolve()
124
+ for raw_path in blast_radius:
125
+ try:
126
+ raw = str(raw_path).replace("\\", "/")
127
+ candidate = Path(raw)
128
+ if candidate.is_absolute() or ".." in candidate.parts:
129
+ raise ValueError("路径越出项目根")
130
+ matches = list(resolved_root.glob(raw))
131
+ if not matches or any(
132
+ resolved_root not in item.resolve().parents
133
+ and item.resolve() != resolved_root
134
+ for item in matches
135
+ ):
136
+ raise ValueError("路径不存在或越出项目根")
137
+ except (OSError, RuntimeError, ValueError) as exc:
138
+ errors.append(f"blast_radius 无效: {raw_path} ({exc})")
139
+ blocking_deps = remediation.get("blocking_deps")
140
+ if blocking_deps is not None and (
141
+ not isinstance(blocking_deps, list) or any(not _nonempty(item) for item in blocking_deps)
142
+ ):
143
+ errors.append("blocking_deps 必须是字符串数组")
144
+ return {"status": "ok" if not errors else "fix_gap", "errors": errors}
145
+
146
+
147
+ def _nonempty(value: object) -> bool:
148
+ return isinstance(value, str) and bool(value.strip())
149
+
150
+
151
+ def reproducible_contract_violation(finding: dict) -> str | None:
152
+ """判定 finding 的 reproducible/reproduction 契约,纯函数、无副作用。
153
+
154
+ 这是「标为可复现的 finding 必须带非空复现步骤」这条规则的**唯一真源**:
155
+ 确认门禁 :func:`confirmation_issues` 与评测协议 ``agent_eval.validate_findings``
156
+ 都调用它。此前两处各写一遍,一处改一处漏就会让同一 finding 通过一个门禁却
157
+ 卡在另一个,门禁结论互相矛盾。
158
+
159
+ 契约(与 ``evals`` 的 output_contract 一致):
160
+ - ``reproducible`` 必须是布尔值,缺失或非布尔即违规;
161
+ - ``reproducible`` 为 ``True`` 时必须提供非空字符串 ``reproduction``;
162
+ - ``reproducible`` 为 ``False`` 时不要求 ``reproduction``。
163
+
164
+ 只报告「是否成立、为什么不成立」,不抛异常也不收集文案,由调用方各自决定
165
+ 上报风格(抛 ``EvalError`` 或追加 issue 字符串)。
166
+
167
+ :returns: ``None`` 表示契约成立;否则返回违规原因标识:
168
+ ``"not_bool"`` —— ``reproducible`` 不是布尔值;
169
+ ``"missing_reproduction"`` —— 标为可复现却缺有效 ``reproduction``。
170
+ """
171
+ reproducible = finding.get("reproducible")
172
+ if not isinstance(reproducible, bool):
173
+ return "not_bool"
174
+ if reproducible and not _nonempty(finding.get("reproduction")):
175
+ return "missing_reproduction"
176
+ if reproducible and reproduction_not_executable(finding.get("reproduction")):
177
+ return "reproduction_not_executable"
178
+ return None
179
+
180
+
181
+ #: 一条 reproduction 里允许的最大「自然语言痕迹」数。命令里出现一两个英文单词
182
+ #: 是正常的(`--flag explain`),但整句解说必然是缺陷。
183
+ _NARRATIVE_MARKERS = (
184
+ " shows ", " records ", " demonstrates ", " confirms ", " indicates ",
185
+ " which ", " while ", " whereas ", " that is ",
186
+ )
187
+ _SHELL_BINARIES = (
188
+ "python", "python3", "pytest", "node", "npm", "pnpm", "yarn", "bash",
189
+ "sh", "zsh", "curl", "go", "cargo", "make", "git", "ruby", "php",
190
+ )
191
+
192
+
193
+ MAX_TOOLS_PER_FINDING = 8
194
+ SHA256_RE = __import__("re").compile(r"^[0-9a-fA-F]{64}$")
195
+
196
+
197
+ def reproduction_not_executable(value: object) -> bool:
198
+ """判断 ``reproduction`` 是不是「伪装成命令的解说」。
199
+
200
+ 实测缺陷(OctoPrintMCP,dsh 宿主):worker 提交的 ``reproduction`` 是
201
+
202
+ python3 probe_files.py records the outbound request with httpx.MockTransport
203
+ (no network); unit-139-delete_file.json shows benign_url='...' vs ...
204
+
205
+ 也就是「命令 + 一句英文解说」拼在一起。它满足「非空」契约,
206
+ ``reproducible: True`` 一路通过摄入侧校验,但**根本跑不起来**
207
+ (``bash: syntax error near unexpected token '('``)。
208
+
209
+ 危害不是「不好看」,而是**让不可复现的东西看起来可复现**——正是
210
+ reproducible 契约要防的事,却因为只查非空而漏掉了。
211
+
212
+ ## 判据:只审「自称是命令」的串
213
+
214
+ 关键前提是**先判断这串有没有资格被当作命令**——必须以已知 shell 二进制
215
+ 开头。人工复现步骤(``构造 10 条记录,latest() 返回最早 5 条``、
216
+ ``mentions('a@b.c') 返回 [...]``)天然含括号和自然语言,它们是**合法的
217
+ 描述**,不该被命令规则审。
218
+
219
+ 早期版本漏了这条前提,直接对任何含 ``()`` 的串跑 ``bash -n``,结果把
220
+ golden 里的两条中文/表达式描述误判成不可执行,连带把 agent_eval 的
221
+ confirmation_rate 从 1.0 打到 0.6667(实测回归)。所以顺序必须是:
222
+
223
+ 不是命令开头 → 直接放行(人工描述是合法形态)
224
+ 是命令开头 → 才检查是否混入了解说
225
+
226
+ 刻意**不**执行该命令:复现步骤可能有副作用(起服务、写文件、打网络)。
227
+ 静态判定足以拦下这个缺陷,且不引入新风险。
228
+ """
229
+ if not isinstance(value, str):
230
+ return False
231
+ text = value.strip()
232
+ if not text:
233
+ return False
234
+
235
+ words = text.split()
236
+ first = words[0] if words else ""
237
+ looks_like_command = any(
238
+ first == binary or first.endswith("/" + binary) or first.startswith(binary + " ")
239
+ for binary in _SHELL_BINARIES
240
+ )
241
+ if not looks_like_command:
242
+ # 人工复现描述:合法形态,不按命令规则审。
243
+ return False
244
+
245
+ lowered = f" {text.lower()} "
246
+ if any(marker in lowered for marker in _NARRATIVE_MARKERS):
247
+ return True
248
+
249
+ if any(token in text for token in (";", "&&", "||", "|", "(", ")", "`")):
250
+ import subprocess
251
+ try:
252
+ result = subprocess.run(
253
+ ["bash", "-n", "-c", text], capture_output=True, text=True,
254
+ timeout=5, check=False,
255
+ )
256
+ except (OSError, subprocess.SubprocessError):
257
+ return False
258
+ if result.returncode != 0:
259
+ return True
260
+
261
+ # 以命令开头但长到像句子:命令 + 解释的混合写法。
262
+ if len(words) > 12 and any(marker in lowered for marker in
263
+ (" the ", " a ", " and then ")):
264
+ return True
265
+ return False
266
+
267
+
268
+ def _artifact_pair(item: dict, label: str, finding_id: object) -> None:
269
+ """可选工件绑定:artifact_path 与 artifact_sha256 必须成对且格式合法。
270
+
271
+ 绑定后「两个通道各失败一次」「负对照通过」不再是纯自报——报告期会用
272
+ :func:`verify_observation_artifacts` 重算哈希,伪造就现形。
273
+ """
274
+ path_value = item.get("artifact_path")
275
+ hash_value = item.get("artifact_sha256")
276
+ if path_value is None and hash_value is None:
277
+ return
278
+ if path_value is None or hash_value is None:
279
+ raise ConfirmationError(f"{finding_id} {label} 的 artifact_path/artifact_sha256 必须成对提供")
280
+ if not _nonempty(path_value) or not isinstance(path_value, str):
281
+ raise ConfirmationError(
282
+ f"{finding_id} {label}.artifact_path 必须是非空字符串,形如 "
283
+ '"state/host-confirmation/<slug>-a.json"(仓库相对路径)'
284
+ )
285
+ if not isinstance(hash_value, str) or not SHA256_RE.fullmatch(hash_value):
286
+ raise ConfirmationError(
287
+ f"{finding_id} {label}.artifact_sha256 必须是 64 位十六进制 SHA-256,"
288
+ "形如 " + "a" * 8 + "..." + "(用 `shasum -a 256 <file>` 生成),"
289
+ "且必须与 artifact_path 指向的文件实际内容一致"
290
+ )
291
+
292
+
293
+ def validate_tools(finding: dict) -> list[str]:
294
+ """结构化工具归因:可选字段 ``tools``,存在非空时必须是去重字符串数组。
295
+
296
+ 归因数据是工具经验账本(tool-feedback)的输入源;这里只做协议校验,
297
+ 不参与确认门禁——缺归因或空数组(=无归因)不阻止确认,但带错归因会污染经验统计。
298
+ 空数组等价于未填(无归因),返回空列表;若存在且非空,则必须满足非空字符串数组规则。
299
+ """
300
+ tools = finding.get("tools")
301
+ if tools is None or tools == []:
302
+ return []
303
+ if not isinstance(tools, list):
304
+ raise ConfirmationError(
305
+ f"{finding.get('id')} tools 必须是字符串数组,"
306
+ '形如 ["bugx_knowledge_route", "bugx_oracle_suggest"];'
307
+ "未使用工具请省略该字段,不要传 null 或空字符串"
308
+ )
309
+ if len(tools) > MAX_TOOLS_PER_FINDING:
310
+ raise ConfirmationError(f"{finding.get('id')} tools 不得超过 {MAX_TOOLS_PER_FINDING} 个")
311
+ seen: set[str] = set()
312
+ for item in tools:
313
+ if not _nonempty(item):
314
+ raise ConfirmationError(f"{finding.get('id')} tools 含空工具名")
315
+ if item in seen:
316
+ raise ConfirmationError(f"{finding.get('id')} tools 重复: {item}")
317
+ seen.add(item)
318
+ return tools
319
+
320
+
321
+ def _confirmation(finding: dict) -> dict:
322
+ value = finding.get("confirmation")
323
+ return value if isinstance(value, dict) else {}
324
+
325
+
326
+ def _validate_oracle_block(finding: dict, confirmation: dict) -> dict:
327
+ oracle = confirmation.get("oracle")
328
+ if not isinstance(oracle, dict) or oracle.get("tier") not in ORACLE_TIERS:
329
+ raise ConfirmationError(f"{finding.get('id')} 缺有效 confirmation.oracle")
330
+ if not _nonempty(oracle.get("reference")):
331
+ raise ConfirmationError(f"{finding.get('id')} oracle.reference 不能为空")
332
+ provenance = oracle.get("provenance")
333
+ if not isinstance(provenance, dict) or provenance.get("kind") not in ORACLE_PROVENANCE_KINDS:
334
+ raise ConfirmationError(f"{finding.get('id')} oracle.provenance 来源无效")
335
+ for field in ("independent_from_change", "verified"):
336
+ if not isinstance(provenance.get(field), bool):
337
+ raise ConfirmationError(
338
+ f"{finding.get('id')} oracle.provenance.{field} 必须是布尔值,"
339
+ "形如 true(不要写 \"yes\" / 1 / null);"
340
+ "provenance 用于声明 oracle 独立于本次改动"
341
+ )
342
+ return oracle
343
+
344
+
345
+ def _validate_observations_block(finding: dict, confirmation: dict) -> list:
346
+ observations = confirmation.get("observations")
347
+ if not isinstance(observations, list):
348
+ raise ConfirmationError(
349
+ f"{finding.get('id')} observations 必须是数组(同指纹 >=2 次独立运行),"
350
+ '形如 [{"run_id": "run-a", "channel": "channel-a", "fingerprint": "...", '
351
+ '"reference": "...", "outcome": "failure", "artifact_path": "...", '
352
+ '"artifact_sha256": "..."}];两个 observation 必须用**不同** channel'
353
+ )
354
+ seen_runs: set[str] = set()
355
+ for index, item in enumerate(observations, 1):
356
+ if not isinstance(item, dict):
357
+ raise ConfirmationError(
358
+ f"{finding.get('id')} observation #{index} 必须是对象,形如 "
359
+ '{"run_id": "...", "channel": "...", "fingerprint": "...", '
360
+ '"reference": "...", "outcome": "failure", '
361
+ '"artifact_path": "...", "artifact_sha256": "..."};'
362
+ "outcome 只能是 failure / pass / blocked"
363
+ )
364
+ for field in ("run_id", "channel", "fingerprint", "reference"):
365
+ if not _nonempty(item.get(field)):
366
+ raise ConfirmationError(
367
+ f"{finding.get('id')} observation #{index} 缺 {field}"
368
+ )
369
+ if item["run_id"] in seen_runs:
370
+ raise ConfirmationError(f"{finding.get('id')} observation run_id 重复")
371
+ seen_runs.add(item["run_id"])
372
+ if item.get("outcome") not in OBSERVATION_OUTCOMES:
373
+ raise ConfirmationError(f"{finding.get('id')} observation outcome 无效")
374
+ _artifact_pair(item, f"observation #{index}", finding.get("id"))
375
+ return observations
376
+
377
+
378
+ def _validate_negative_control_block(finding: dict, confirmation: dict) -> None:
379
+ negative = confirmation.get("negative_control")
380
+ if negative is not None and (
381
+ not isinstance(negative, dict)
382
+ or negative.get("outcome") not in OBSERVATION_OUTCOMES
383
+ or not _nonempty(negative.get("reference"))
384
+ ):
385
+ raise ConfirmationError(f"{finding.get('id')} negative_control 无效")
386
+ if isinstance(negative, dict):
387
+ _artifact_pair(negative, "negative_control", finding.get("id"))
388
+
389
+
390
+ def _validate_target_execution_block(finding: dict, confirmation: dict) -> None:
391
+ target = confirmation.get("target_execution")
392
+ if target is None:
393
+ return
394
+ if not isinstance(target, dict):
395
+ raise ConfirmationError(
396
+ f"{finding.get('id')} target_execution 必须是对象,形如 "
397
+ '{"target_platform": "darwin-arm64-cpython-3.14", '
398
+ '"executed_platform": "darwin-arm64-cpython-3.14", '
399
+ '"executed": true, "simulated": false, '
400
+ '"outcome": "failure", "errors": []};'
401
+ "target_platform 与 executed_platform 必须**逐字相同**"
402
+ )
403
+ for field in (
404
+ "target_platform", "executed_platform", "target_fingerprint", "run_reference",
405
+ ):
406
+ if not _nonempty(target.get(field)):
407
+ raise ConfirmationError(f"{finding.get('id')} target_execution 缺 {field}")
408
+ for field in ("executed", "simulated"):
409
+ if not isinstance(target.get(field), bool):
410
+ raise ConfirmationError(
411
+ f"{finding.get('id')} target_execution.{field} 必须是布尔值,"
412
+ "形如 true / false(不要写 \"yes\" / 1);"
413
+ "executed=true 表示真的在目标平台跑过,simulated 必须为 false"
414
+ )
415
+ if target.get("outcome") not in OBSERVATION_OUTCOMES:
416
+ raise ConfirmationError(f"{finding.get('id')} target_execution.outcome 无效")
417
+ errors = target.get("errors")
418
+ if not isinstance(errors, list) or any(not isinstance(item, str) or not item.strip() for item in errors):
419
+ raise ConfirmationError(
420
+ f"{finding.get('id')} target_execution.errors 必须是字符串数组"
421
+ "(无错误时传 [],不要传 null);每个元素须为非空字符串,"
422
+ '形如 ["ModuleNotFoundError: httpx"]'
423
+ )
424
+
425
+
426
+ def validate_confirmation(finding: dict) -> dict:
427
+ """校验 confirmation 协议;``rejected`` 是明确的非 Bug 终态,按档要求。
428
+
429
+ 分档原因(L1-ADV-D1 修复配套):驳回不需要 oracle/复现证据,否则"判为不是
430
+ Bug"这条终态会被确认侧的证据契约反噬(`gate()` 记 issue、写入侧无法落盘)。
431
+ 确认侧(candidate/observed/reproduced/root_caused/confirmed)仍要求完整证据,
432
+ 且附带字段只要出现就必须合法——放宽的只是"驳回是否需要证据",不是"证据可否乱填"。
433
+ """
434
+ validate_tools(finding)
435
+ confirmation = _confirmation(finding)
436
+ if not confirmation:
437
+ return {}
438
+ state = confirmation.get("state")
439
+ if state not in CONFIRMATION_STATES:
440
+ raise ConfirmationError(f"{finding.get('id')} confirmation.state 无效: {state}")
441
+ if state == "rejected":
442
+ if confirmation.get("rejection_class") not in REJECTION_CLASSES:
443
+ raise ConfirmationError(f"{finding.get('id')} rejected 缺 rejection_class")
444
+ if not _nonempty(confirmation.get("decision_reason")):
445
+ raise ConfirmationError(f"{finding.get('id')} rejected 缺 decision_reason")
446
+ if "oracle" in confirmation:
447
+ _validate_oracle_block(finding, confirmation)
448
+ if "observations" in confirmation:
449
+ _validate_observations_block(finding, confirmation)
450
+ _validate_negative_control_block(finding, confirmation)
451
+ _validate_target_execution_block(finding, confirmation)
452
+ return confirmation
453
+ _validate_oracle_block(finding, confirmation)
454
+ _validate_observations_block(finding, confirmation)
455
+ _validate_negative_control_block(finding, confirmation)
456
+ _validate_target_execution_block(finding, confirmation)
457
+ return confirmation
458
+
459
+
460
+ def verify_observation_artifacts(
461
+ finding: dict, root, *, require_artifacts: bool = False,
462
+ ) -> list[str]:
463
+ """重算 observation/negative_control 工件哈希;返回错误清单(空即通过)。
464
+
465
+ 只校验「声明了绑定」的工件;未绑定的旧 finding 不受影响,但会在
466
+ assurance 画像里拿不到 observation_artifacts 加分。
467
+
468
+ F1' 新代际口径:``require_artifacts=True``(结算路径对带
469
+ ``adjudicator_build`` 标记的 confirmed 启用)时,failure 观测**未声明**
470
+ 工件绑定也视为错误——新代际 confirmed 不允许"缺省不罚"式的无工件
471
+ 确认,缺哈希由结算路径回退 candidate 留存;存量 confirmed 不受追溯。
472
+ """
473
+ import hashlib
474
+ from pathlib import Path
475
+
476
+ errors: list[str] = []
477
+ confirmation = _confirmation(finding)
478
+ candidates: list[tuple[str, dict]] = [
479
+ (f"observation #{index}", item)
480
+ for index, item in enumerate(confirmation.get("observations", []), 1)
481
+ if isinstance(item, dict)
482
+ ]
483
+ negative = confirmation.get("negative_control")
484
+ if isinstance(negative, dict):
485
+ candidates.append(("negative_control", negative))
486
+ root_path = Path(root).resolve()
487
+ for label, item in candidates:
488
+ artifact_path = item.get("artifact_path")
489
+ if artifact_path is None:
490
+ continue
491
+ target = (root_path / str(artifact_path)).resolve()
492
+ if target != root_path and root_path not in target.parents:
493
+ errors.append(f"{label} artifact_path 逃逸项目根: {artifact_path}")
494
+ continue
495
+ if not target.is_file():
496
+ errors.append(f"{label} artifact_path 不存在: {artifact_path}")
497
+ continue
498
+ actual = hashlib.sha256(target.read_bytes()).hexdigest()
499
+ if actual.lower() != str(item.get("artifact_sha256", "")).lower():
500
+ errors.append(f"{label} artifact_sha256 不匹配: {artifact_path}")
501
+ if require_artifacts:
502
+ for index, item in enumerate(confirmation.get("observations", []), 1):
503
+ if not isinstance(item, dict) or item.get("outcome") != "failure":
504
+ continue
505
+ declared = (
506
+ _nonempty(item.get("artifact_path"))
507
+ and isinstance(item.get("artifact_sha256"), str)
508
+ and bool(SHA256_RE.fullmatch(item["artifact_sha256"]))
509
+ )
510
+ if not declared:
511
+ errors.append(
512
+ f"observation #{index} 新代际 confirmed 缺工件哈希绑定"
513
+ "(adjudicator_build 口径,缺失即回退候选)"
514
+ )
515
+ return errors
516
+
517
+
518
+ def confirmation_assurance(finding: dict) -> dict:
519
+ """Return a bounded, explainable confidence profile for one finding.
520
+
521
+ The profile is deliberately separate from :func:`is_confirmed`: it helps
522
+ the Supervisor prioritize follow-up work, but it cannot turn a partial
523
+ finding into a confirmed Bug.
524
+ """
525
+ confirmation = _confirmation(finding)
526
+ if not confirmation:
527
+ return {
528
+ "score": 0,
529
+ "level": "candidate",
530
+ "checks": {name: False for name in ASSURANCE_WEIGHTS},
531
+ "missing": ["缺 confirmation 协议"],
532
+ }
533
+ validate_confirmation(finding)
534
+ if confirmation.get("state") == "rejected":
535
+ # 驳回是终态非 Bug 决定:不要求 oracle/复现画像,也不因缺证据扣分。
536
+ return {
537
+ "score": 0,
538
+ "level": "rejected",
539
+ "checks": {name: False for name in ASSURANCE_WEIGHTS},
540
+ "missing": [],
541
+ }
542
+ oracle = confirmation["oracle"]
543
+ provenance = oracle["provenance"]
544
+ failures = [
545
+ item for item in confirmation["observations"]
546
+ if item["outcome"] == "failure"
547
+ ]
548
+ fingerprints = Counter(item["fingerprint"] for item in failures)
549
+ checks = {
550
+ "oracle": (
551
+ oracle["tier"] != "heuristic"
552
+ and provenance["kind"] != "agent-generated"
553
+ and provenance["independent_from_change"] is True
554
+ and provenance["verified"] is True
555
+ ),
556
+ "repeat": max(fingerprints.values(), default=0) >= 2,
557
+ "independent_channels": len({item["channel"] for item in failures}) >= 2,
558
+ "negative_control": (
559
+ isinstance(confirmation.get("negative_control"), dict)
560
+ and confirmation["negative_control"].get("outcome") == "pass"
561
+ ),
562
+ "root_cause": confirmation.get("root_cause_verified") is True,
563
+ "reproduction": (
564
+ # 加分项与门禁同源(reproducible_contract_violation),但这里额外要求
565
+ # reproducible 显式为 True:不可复现的 finding 不该拿复现加分。
566
+ finding.get("reproducible") is True
567
+ and reproducible_contract_violation(finding) is None
568
+ ),
569
+ "target_execution": (
570
+ isinstance(confirmation.get("target_execution"), dict)
571
+ and confirmation["target_execution"].get("executed") is True
572
+ and confirmation["target_execution"].get("simulated") is False
573
+ and confirmation["target_execution"].get("outcome") == "failure"
574
+ and not confirmation["target_execution"].get("errors")
575
+ and confirmation["target_execution"].get("target_platform")
576
+ == confirmation["target_execution"].get("executed_platform")
577
+ ),
578
+ "observation_artifacts": (
579
+ all(
580
+ isinstance(item, dict) and _nonempty(item.get("artifact_path"))
581
+ for item in failures
582
+ )
583
+ and isinstance(confirmation.get("negative_control"), dict)
584
+ and _nonempty(confirmation["negative_control"].get("artifact_path"))
585
+ ),
586
+ }
587
+ score = sum(ASSURANCE_WEIGHTS[name] for name, passed in checks.items() if passed)
588
+ issues = confirmation_issues(finding)
589
+ if not issues and confirmation.get("state") == "confirmed":
590
+ level = "confirmed"
591
+ elif score >= 70:
592
+ level = "strong_candidate"
593
+ elif score >= 35:
594
+ level = "partial"
595
+ else:
596
+ level = "candidate"
597
+ return {
598
+ "score": score,
599
+ "level": level,
600
+ "checks": checks,
601
+ "missing": issues,
602
+ }
603
+
604
+
605
+ def confirmation_issues(finding: dict) -> list[str]:
606
+ confirmation = validate_confirmation(finding)
607
+ if not confirmation:
608
+ return ["缺 confirmation 协议"]
609
+ issues: list[str] = []
610
+ if confirmation.get("state") == "rejected":
611
+ return issues
612
+ if confirmation.get("state") == "confirmed":
613
+ from core.agent import agent_eval
614
+
615
+ if str(finding.get("severity") or "").lower() not in agent_eval.SEVERITY_ORDER:
616
+ issues.append("confirmed Finding 缺有效 severity")
617
+ oracle = confirmation["oracle"]
618
+ if oracle["tier"] == "heuristic":
619
+ issues.append("仅有启发式 Oracle,不能确认 Bug")
620
+ provenance = oracle["provenance"]
621
+ if provenance["kind"] == "agent-generated":
622
+ issues.append("Oracle 与被测改动同源,不能独立确认 Bug")
623
+ if provenance["independent_from_change"] is not True:
624
+ issues.append("Oracle 未独立于被测改动")
625
+ if provenance["verified"] is not True:
626
+ issues.append("Oracle 来源尚未核验")
627
+ failures = [
628
+ item for item in confirmation["observations"] if item["outcome"] == "failure"
629
+ ]
630
+ # 复现次数按**独立运行**计(审计 A2):同一次运行的多维观测不是两次复现。
631
+ reproductions: dict[str, set[str]] = {}
632
+ for item in failures:
633
+ key = str(item.get("fingerprint") or "")
634
+ execution = str(item.get("execution_id") or item.get("run_id") or "")
635
+ reproductions.setdefault(key, set()).add(execution.split("#", 1)[0])
636
+ stable = max((len(runs) for runs in reproductions.values()), default=0)
637
+ if stable < 2:
638
+ issues.append("缺至少两次同指纹失败复现")
639
+ channels = {item["channel"] for item in failures}
640
+ if len(channels) < 2:
641
+ issues.append(
642
+ "缺两个独立证据通道(engine-verify 只从 receipt 的 stdout/stderr "
643
+ "派生第二通道:正例验证命令必须打印非空失败观测,纯静默 "
644
+ "SystemExit 非零只有 exit-code 一个通道,会被本门禁拒绝——"
645
+ "请在正例命令退出前 print 失败标记后重跑 verify_finding)"
646
+ )
647
+ negative = confirmation.get("negative_control")
648
+ if not isinstance(negative, dict) or negative.get("outcome") != "pass":
649
+ issues.append("缺通过的负对照")
650
+ if confirmation.get("root_cause_verified") is not True:
651
+ issues.append("根因尚未验证")
652
+ # 与 agent_eval 共用唯一真源。注意:reproducible 显式为 False 时**不再**要求
653
+ # reproduction——规则是「标为可复现才必须给步骤」;旧实现用 `is not True`
654
+ # 会把 reproducible=False 也判为缺步骤,与 agent_eval 判定相反。
655
+ if reproducible_contract_violation(finding) is not None:
656
+ issues.append("Finding 缺可复现步骤")
657
+ target = confirmation.get("target_execution")
658
+ if not isinstance(target, dict):
659
+ issues.append("缺真实目标执行证明")
660
+ else:
661
+ if target["executed"] is not True:
662
+ issues.append("目标环境未实际执行")
663
+ if target["simulated"] is not False:
664
+ issues.append("模拟执行不能确认目标平台 Bug")
665
+ if target["target_platform"] != target["executed_platform"]:
666
+ issues.append("目标平台与实际执行平台不一致")
667
+ if target["outcome"] != "failure":
668
+ issues.append("目标执行未观察到失败")
669
+ # PE-20261005-003: target_execution.errors 是记录字段不是阻断项——
670
+ # 复现失败天然带报错输出(如沙盒超时型 DoS),"未观察到失败"已由
671
+ # outcome != failure 承担;assurance 画像仍对非空 errors 扣 10 分留信号。
672
+ return issues
673
+
674
+
675
+ def _evidence_paths(finding: dict) -> set[str]:
676
+ """收集 finding 指向的源码路径(file/path/artifact_path/evidence[].path)。
677
+
678
+ F-RSI-20261110-028:逐条 ``os.path.normpath`` 归一——oracle 侧 reference
679
+ 经 ``resolve()`` 已是规范路径,证据侧此前只 ``lstrip("./")``,
680
+ ``sub/../x.py`` 型别名会绕过 oracle 独立性重合检查(同一文件既当判据
681
+ 又当证据)。与 F-019 路径别名漏并向同根因:路径比较前必须归一。
682
+ """
683
+ paths: set[str] = set()
684
+ for key in ("file", "path", "artifact_path"):
685
+ value = finding.get(key)
686
+ if _nonempty(value):
687
+ paths.add(os.path.normpath(str(value).strip().lstrip("./")))
688
+ evidence = finding.get("evidence")
689
+ if isinstance(evidence, list):
690
+ for item in evidence:
691
+ if isinstance(item, dict) and _nonempty(item.get("path")):
692
+ paths.add(os.path.normpath(str(item["path"]).strip().lstrip("./")))
693
+ elif isinstance(item, str) and item.strip():
694
+ paths.add(os.path.normpath(item.strip().lstrip("./")))
695
+ return paths
696
+
697
+
698
+ def _oracle_provenance(finding: dict, reference: str, oracle_hash: object, root) -> dict:
699
+ """引擎侧核算 oracle 来源:两项都是**算出来**的,不是声明出来的。
700
+
701
+ - ``verified``:``reference`` 的文件部分指向真实文件,且其 SHA-256 与 recipe
702
+ 里已封入 digest 的 ``oracle_hash`` 一致(宿主事后无法改写);
703
+ - ``independent_from_change``:该文件不在 finding 的证据路径集合内——不拿被测
704
+ 缺陷文件本身当判据。
705
+ """
706
+ import hashlib
707
+ from pathlib import Path
708
+
709
+ verdict = {"verified": False, "independent_from_change": False, "reason": ""}
710
+ path_text = str(reference or "").strip().split("#", 1)[0].strip()
711
+ if not path_text:
712
+ verdict["reason"] = "oracle.reference 缺文件路径(要求 path[#anchor])"
713
+ return verdict
714
+ if root is None:
715
+ verdict["reason"] = "缺项目根,无法核算 oracle 文件哈希"
716
+ return verdict
717
+ root_path = Path(root).resolve()
718
+ candidate = (root_path / path_text).resolve()
719
+ if candidate != root_path and root_path not in candidate.parents:
720
+ verdict["reason"] = "oracle.reference 越出项目根"
721
+ return verdict
722
+ if not candidate.is_file():
723
+ verdict["reason"] = "oracle.reference 指向的文件不存在"
724
+ return verdict
725
+ actual = hashlib.sha256(candidate.read_bytes()).hexdigest()
726
+ if not isinstance(oracle_hash, str) or actual != oracle_hash.strip().lower():
727
+ verdict["reason"] = "oracle_hash 与 oracle.reference 文件内容不一致"
728
+ return verdict
729
+ verdict["verified"] = True
730
+ relative = candidate.relative_to(root_path).as_posix()
731
+ if relative in _evidence_paths(finding):
732
+ verdict["reason"] = "oracle 与 finding 证据文件重合,无法独立判定"
733
+ return verdict
734
+ verdict["independent_from_change"] = True
735
+ return verdict
736
+
737
+
738
+ def _verification_observations(receipt: dict, fingerprint: str) -> list[dict]:
739
+ """把 receipt 的双次正例重放成失败观测(判据必须能表达失败)。"""
740
+ runs = receipt.get("positive_runs")
741
+ if not isinstance(runs, list) or len(runs) < 2:
742
+ raise ConfirmationError("verification receipt 缺双次正例运行")
743
+ observations: list[dict] = []
744
+ for index, record in enumerate(runs, 1):
745
+ if not isinstance(record, dict):
746
+ raise ConfirmationError(f"verification 正例 #{index} 记录无效")
747
+ oracle = record.get("oracle") if isinstance(record.get("oracle"), dict) else {}
748
+ expected = oracle.get("expected_exit_code")
749
+ if (
750
+ oracle.get("kind") != "exit_code"
751
+ or isinstance(expected, bool)
752
+ or not isinstance(expected, int)
753
+ or expected == 0
754
+ ):
755
+ raise ConfirmationError(
756
+ f"verification 正例 #{index} 判据无法表达失败观测"
757
+ "(要求 exit_code 且 expected_exit_code != 0)"
758
+ )
759
+ if record.get("oracle_matched") is not True:
760
+ raise ConfirmationError(f"verification 正例 #{index} 未观察到失败")
761
+ if record.get("timed_out") or record.get("output_exceeded"):
762
+ raise ConfirmationError(f"verification 正例 #{index} 超时或输出超限,不能作为复现证据")
763
+ execution_id = str(record.get("execution_id") or "").strip()
764
+ if not execution_id:
765
+ raise ConfirmationError(f"verification 正例 #{index} 缺 execution_id")
766
+ argv = record.get("argv") if isinstance(record.get("argv"), list) else []
767
+ reference = " ".join(str(item) for item in argv)[:200] or execution_id
768
+ base = {
769
+ "execution_id": execution_id,
770
+ "reference": reference,
771
+ "outcome": "failure",
772
+ "exit_code": record.get("exit_code"),
773
+ "stdout_sha256": record.get("stdout_sha256"),
774
+ "stderr_sha256": record.get("stderr_sha256"),
775
+ "verification_id": str(receipt.get("verification_id") or ""),
776
+ }
777
+ observations.append({
778
+ **base,
779
+ "run_id": f"{execution_id}#exit-code",
780
+ "channel": "engine-verify:exit-code",
781
+ "fingerprint": f"exit:{record.get('exit_code')}",
782
+ })
783
+ for field, channel, label in (
784
+ ("stderr_sha256", "engine-verify:stderr", "stderr"),
785
+ ("stdout_sha256", "engine-verify:stdout", "stdout"),
786
+ ):
787
+ digest = str(record.get(field) or "").strip()
788
+ if not digest or digest == _EMPTY_SHA256:
789
+ continue
790
+ observations.append({
791
+ **base,
792
+ "run_id": f"{execution_id}#{label}",
793
+ "channel": channel,
794
+ "fingerprint": f"{label}:{digest[:16]}",
795
+ })
796
+ return observations
797
+
798
+
799
+ def _verification_negative_control(receipt: dict) -> dict:
800
+ """负对照只能来自 receipt 里引擎真跑过、判据命中的那条记录。"""
801
+ record = receipt.get("negative_control")
802
+ if not isinstance(record, dict):
803
+ raise ConfirmationError("verification receipt 缺负对照记录")
804
+ if record.get("oracle_matched") is not True:
805
+ raise ConfirmationError("verification 负对照未通过,不能确认 Finding")
806
+ if record.get("timed_out") or record.get("output_exceeded"):
807
+ raise ConfirmationError("verification 负对照超时或输出超限")
808
+ execution_id = str(record.get("execution_id") or "").strip()
809
+ if not execution_id:
810
+ raise ConfirmationError("verification 负对照缺 execution_id")
811
+ return {
812
+ "outcome": "pass",
813
+ "reference": execution_id,
814
+ "exit_code": record.get("exit_code"),
815
+ "stdout_sha256": record.get("stdout_sha256"),
816
+ "verification_id": str(receipt.get("verification_id") or ""),
817
+ }
818
+
819
+
820
+ def build_confirmation_from_verification(
821
+ finding: dict, receipt: object, *, oracle: object,
822
+ root_cause_verified: object, target_platform: object = None, root=None,
823
+ ) -> dict:
824
+ """用引擎核验 receipt 组装 confirmation 证据块(只重放已记录事实)。
825
+
826
+ L1-ADV-D1 根因修复:确认侧原先只写 ``{state, reason, at}``,读取侧却要求
827
+ oracle/observations/negative_control/root_cause_verified/target_execution,
828
+ 两个引擎自有契约互斥 ⇒ post 永不收敛。本函数把"证据从哪来"固定为
829
+ **引擎 receipt**:宿主自述不构成证据,receipt 没记录的材料一律不造。
830
+ """
831
+ if not isinstance(receipt, dict) or not receipt:
832
+ raise ConfirmationError(
833
+ "confirmed 需要引擎核验 receipt:先调用 bugx_supervisor_verify_finding"
834
+ )
835
+ if receipt.get("status") != "CONFIRMED":
836
+ raise ConfirmationError(
837
+ f"引擎核验状态为 {receipt.get('status')},未通过双正例 + 负对照,不能确认 Finding"
838
+ )
839
+ verification_id = str(receipt.get("verification_id") or "").strip()
840
+ if not verification_id:
841
+ raise ConfirmationError("verification receipt 缺 verification_id")
842
+ fingerprint = str(
843
+ finding.get("fingerprint") or finding.get("id") or finding.get("finding_id") or ""
844
+ ).strip()
845
+ if not fingerprint:
846
+ raise ConfirmationError("Finding 缺稳定指纹,无法绑定复现")
847
+ target_fingerprint = str(receipt.get("target_fingerprint") or "").strip()
848
+ if not target_fingerprint:
849
+ raise ConfirmationError("verification receipt 缺 target_fingerprint,无法证明目标环境执行")
850
+ if root_cause_verified is not True:
851
+ raise ConfirmationError("confirmed 需要宿主显式断言 root_cause_verified=true")
852
+ declared = oracle if isinstance(oracle, Mapping) else {}
853
+ tier = declared.get("tier")
854
+ if tier not in ORACLE_TIERS:
855
+ raise ConfirmationError(f"oracle.tier 无效: {tier}(允许 {sorted(ORACLE_TIERS)})")
856
+ kind = declared.get("provenance_kind", declared.get("kind"))
857
+ if kind not in ORACLE_PROVENANCE_KINDS:
858
+ raise ConfirmationError(f"oracle.provenance_kind 无效: {kind}")
859
+ reference = str(receipt.get("oracle_reference") or "").strip()
860
+ if not reference:
861
+ raise ConfirmationError("verification receipt 缺 oracle_reference")
862
+ claimed_reference = declared.get("reference")
863
+ if claimed_reference is not None and str(claimed_reference).strip() != reference:
864
+ raise ConfirmationError("声明的 oracle.reference 与引擎核验时使用的 reference 不一致")
865
+ provenance = _oracle_provenance(finding, reference, receipt.get("oracle_hash"), root)
866
+ if not provenance["verified"] or not provenance["independent_from_change"]:
867
+ raise ConfirmationError(
868
+ "oracle 来源未通过引擎核算: " + (provenance["reason"] or "未知原因")
869
+ )
870
+ platform = str(target_platform or receipt.get("target_platform") or "source").strip() or "source"
871
+ return {
872
+ "oracle": {
873
+ "tier": tier,
874
+ "reference": reference,
875
+ "hash": receipt.get("oracle_hash"),
876
+ "provenance": {
877
+ "kind": kind,
878
+ "independent_from_change": True,
879
+ "verified": True,
880
+ },
881
+ },
882
+ "observations": _verification_observations(receipt, fingerprint),
883
+ "negative_control": _verification_negative_control(receipt),
884
+ "root_cause_verified": True,
885
+ "target_execution": {
886
+ "target_platform": platform,
887
+ "executed_platform": platform,
888
+ "target_fingerprint": target_fingerprint,
889
+ "run_reference": str(receipt.get("run_id") or verification_id),
890
+ "executed": True,
891
+ "simulated": False,
892
+ "outcome": "failure",
893
+ "errors": [],
894
+ },
895
+ "verification_id": verification_id,
896
+ "verification_digest": receipt.get("verification_digest"),
897
+ "verified_by": "engine:bugx_supervisor_verify_finding",
898
+ "evidence_reproduction": {
899
+ "receipt_path": str(receipt.get("receipt_path") or ""),
900
+ "verification_digest": str(receipt.get("verification_digest") or ""),
901
+ "oracle_reference": reference,
902
+ "oracle_hash": receipt.get("oracle_hash"),
903
+ "recipe_digest": str(receipt.get("recipe_digest") or ""),
904
+ "positive_command": (
905
+ " ".join(str(x) for x in receipt["positive_runs"][0].get("argv", []))
906
+ if isinstance(receipt.get("positive_runs"), list) and receipt["positive_runs"]
907
+ else ""
908
+ ),
909
+ },
910
+ }
911
+
912
+
913
+ def apply_decision(
914
+ finding: dict, decision: str, *, reason: str, now: object = None,
915
+ receipt: object = None, oracle: object = None, root_cause_verified: object = None,
916
+ remediation: object = None, target_platform: object = None,
917
+ rejection_class: object = None, root=None,
918
+ severity: object = None,
919
+ ) -> dict:
920
+ """``severity``:确认方对 confirmed 报告的定级补录(F-RSI-20261118-009)。
921
+
922
+ triage 档 worker 的候选可能不携带 severity(初筛不定级是合法形态),
923
+ 而 confirmed 门禁要求有效 severity——评级责任随确认动作落到确认方。
924
+ 仅在 ``decision == "confirmed"`` 且确认方显式提供合法值(SEVERITY_ORDER
925
+ 值域)时补写;finding 已有有效 severity 时不覆盖(worker 定级优先)。
926
+
927
+ 唯一的 Finding 裁决写入口:合并证据 → 门禁自检 → 通过才返回新块。
928
+ 失败一律抛 :class:`ConfirmationError`,调用方不得落盘——半成品 confirmed
929
+ 正是 L1-ADV-D1 的成因(写入侧不校验读取侧门禁)。
930
+ """
931
+ import copy
932
+
933
+ if decision not in {"confirmed", "rejected"}:
934
+ raise ConfirmationError("decision 只能是 confirmed 或 rejected")
935
+ if not _nonempty(reason):
936
+ raise ConfirmationError("reason 不能为空")
937
+ existing = _confirmation(finding)
938
+ work = copy.deepcopy(finding)
939
+ confirmation = dict(existing)
940
+ if decision == "confirmed":
941
+ built = build_confirmation_from_verification(
942
+ work, receipt, oracle=oracle, root_cause_verified=root_cause_verified,
943
+ target_platform=target_platform, root=root,
944
+ )
945
+ prior_observations = (
946
+ [item for item in existing["observations"] if isinstance(item, dict)]
947
+ if isinstance(existing.get("observations"), list) else []
948
+ )
949
+ merged_runs = {str(item.get("run_id")) for item in prior_observations}
950
+ prior_negative = existing.get("negative_control")
951
+ if isinstance(prior_negative, dict) and prior_negative != built["negative_control"]:
952
+ # 不同来源的负对照留档,避免重复裁决时丢掉 worker 提交的那份记录。
953
+ confirmation["prior_negative_control"] = prior_negative
954
+ confirmation.update(built)
955
+ confirmation["observations"] = prior_observations + [
956
+ item for item in built["observations"]
957
+ if str(item.get("run_id")) not in merged_runs
958
+ ]
959
+ confirmation["state"] = "confirmed"
960
+ else:
961
+ if rejection_class not in REJECTION_CLASSES:
962
+ raise ConfirmationError(
963
+ f"rejected 必须提供 rejection_class(允许 {sorted(REJECTION_CLASSES)})"
964
+ )
965
+ confirmation["rejection_class"] = rejection_class
966
+ confirmation["state"] = "rejected"
967
+ confirmation["decision_reason"] = str(reason).strip()
968
+ if now is not None:
969
+ confirmation["decided_at"] = now
970
+ confirmation["decided_by"] = "confirm_finding"
971
+ work["confirmation"] = confirmation
972
+ if decision == "confirmed":
973
+ # F-RSI-20261118-009:确认方定级补录——仅补缺失/无效的 severity,
974
+ # 已有有效值(worker 定级)不覆盖;非法值 fail-closed 抛错。
975
+ if severity is not None:
976
+ normalized = str(severity).strip().lower()
977
+ from core.agent import agent_eval
978
+ if normalized not in agent_eval.SEVERITY_ORDER:
979
+ raise ConfirmationError(
980
+ f"severity 无效: {severity!r}(允许 {sorted(agent_eval.SEVERITY_ORDER)})"
981
+ )
982
+ current = str(work.get("severity") or "").strip().lower()
983
+ if current not in agent_eval.SEVERITY_ORDER:
984
+ work["severity"] = normalized
985
+ issues = confirmation_issues(work)
986
+ if issues:
987
+ raise ConfirmationError(
988
+ "确认门禁失败,拒绝写入不可收敛的 confirmed:" + ";".join(issues)
989
+ )
990
+ if issues:
991
+ raise ConfirmationError(
992
+ "确认门禁失败,拒绝写入不可收敛的 confirmed:" + ";".join(issues)
993
+ )
994
+ validate_confirmation(work)
995
+ severity_applied: str | None = None
996
+ if decision == "confirmed" and severity is not None:
997
+ normalized_sev = str(severity).strip().lower()
998
+ if normalized_sev in agent_eval.SEVERITY_ORDER:
999
+ current = str(work.get("severity") or "").strip().lower()
1000
+ if current not in agent_eval.SEVERITY_ORDER:
1001
+ work["severity"] = normalized_sev
1002
+ severity_applied = normalized_sev
1003
+ result: dict = {
1004
+ "confirmation": dict(confirmation),
1005
+ "remediation": None,
1006
+ "severity_applied": severity_applied,
1007
+ "severity_final": str(work.get("severity") or "") or None,
1008
+ }
1009
+ if remediation is not None:
1010
+ if not isinstance(remediation, Mapping):
1011
+ # 只说「必须是对象」是不可自愈的:worker 交了合理的人类可读建议
1012
+ # (实测 OctoPrintMCP:一条完整的 validate/encode 建议字符串),
1013
+ # 被告知「要对象」却不知道对象长什么样,只能反复猜。
1014
+ # 错误文案必须自带最小可用 schema 和一个反例。
1015
+ raise ConfirmationError(
1016
+ f"remediation 必须是对象(收到 {type(remediation).__name__})。"
1017
+ "最小合法形态:"
1018
+ '{"decision": "fixed" | "deferred", '
1019
+ '"fix_ref": "<commit sha 或测试路径>"};'
1020
+ "decision=fixed 时 fix_ref 必填,"
1021
+ 'decision=deferred 时可写 {"decision": "deferred", "reason": "..."}。'
1022
+ "自然语言修复建议请写进 finding 的 notes 或 root_cause,不要塞进 remediation。"
1023
+ )
1024
+ work["remediation"] = copy.deepcopy(dict(remediation))
1025
+ verdict = validate_remediation(work, root)
1026
+ if verdict.get("status") != "ok":
1027
+ raise ConfirmationError(
1028
+ "remediation 无效: " + ";".join(verdict.get("errors") or [])
1029
+ )
1030
+ result["remediation"] = work["remediation"]
1031
+ return result
1032
+
1033
+
1034
+ def is_confirmed(finding: dict) -> bool:
1035
+ confirmation = _confirmation(finding)
1036
+ return confirmation.get("state") == "confirmed" and not confirmation_issues(finding)
1037
+
1038
+
1039
+ def open_findings(findings: object, root: Path | None = None) -> list[dict[str, object]]:
1040
+ """Return bugs that still prevent an unattended successful stop.
1041
+
1042
+ ``rejected`` is a terminal non-bug decision. A confirmed finding is only
1043
+ closed after a valid fixed remediation; ``deferred`` remains open by
1044
+ design. This is intentionally independent from the coverage ledger so a
1045
+ fully covered but still-broken project cannot be reported as converged.
1046
+ """
1047
+ if not isinstance(findings, (list, tuple)):
1048
+ return [{"id": "unknown", "state": "invalid", "reason": "finding ledger 无效"}]
1049
+ result: list[dict[str, object]] = []
1050
+ for finding in findings:
1051
+ if not isinstance(finding, dict):
1052
+ result.append({
1053
+ "id": "unknown", "state": "invalid", "reason": "finding entry 无效",
1054
+ })
1055
+ continue
1056
+ finding_id = str(finding.get("id") or finding.get("fingerprint") or "unknown")
1057
+ confirmation = _confirmation(finding)
1058
+ state = str(confirmation.get("state") or "candidate")
1059
+ reason = "confirmation_pending: 未进入 confirmed/rejected 终态"
1060
+ if state == "rejected":
1061
+ continue
1062
+ if state == "confirmed" and is_confirmed(finding):
1063
+ remediation = validate_remediation(finding, root)
1064
+ if remediation.get("status") == "ok" and (
1065
+ isinstance(finding.get("remediation"), dict)
1066
+ and finding["remediation"].get("decision") == "fixed"
1067
+ ):
1068
+ continue
1069
+ reason = "confirmed Finding 缺有效 fixed remediation"
1070
+ result.append({"id": finding_id, "state": state, "reason": reason})
1071
+ return result
1072
+
1073
+
1074
+ def transition(finding: dict, state: str, reason: str | None = None,
1075
+ rejection_class: str | None = None) -> dict:
1076
+ if state not in CONFIRMATION_STATES:
1077
+ raise ConfirmationError(f"目标状态无效: {state}")
1078
+ confirmation = validate_confirmation(finding)
1079
+ if not confirmation:
1080
+ raise ConfirmationError("Finding 尚未配置 confirmation 协议")
1081
+ current = confirmation["state"]
1082
+ if current in {"confirmed", "rejected"} and state != current:
1083
+ raise ConfirmationError(f"终态 {current} 不可直接迁移")
1084
+ if state == "confirmed":
1085
+ issues = confirmation_issues(finding)
1086
+ if issues:
1087
+ raise ConfirmationError("确认门禁失败: " + ";".join(issues))
1088
+ elif state == "rejected":
1089
+ if rejection_class not in REJECTION_CLASSES or not _nonempty(reason):
1090
+ raise ConfirmationError("rejected 必须提供 rejection_class 和 reason")
1091
+ confirmation["rejection_class"] = rejection_class
1092
+ confirmation["decision_reason"] = reason
1093
+ else:
1094
+ current_index = CONFIRMATION_STATES.index(current)
1095
+ target_index = CONFIRMATION_STATES.index(state)
1096
+ if target_index < current_index:
1097
+ raise ConfirmationError(f"禁止从 {current} 回退到 {state}")
1098
+ confirmation["state"] = state
1099
+ if reason and state != "rejected":
1100
+ confirmation["decision_reason"] = reason
1101
+ finding["confirmation"] = confirmation
1102
+ return finding
1103
+
1104
+
1105
+ def degraded_gate(error: str) -> dict:
1106
+ """Return a stable gate shape when aggregate metrics cannot be trusted."""
1107
+ return {
1108
+ "schema_version": SCHEMA_VERSION,
1109
+ "total": None,
1110
+ "confirmed": None,
1111
+ "rejected": None,
1112
+ "pending": None,
1113
+ "ready": False,
1114
+ "degraded": True,
1115
+ "error": error,
1116
+ "states": {},
1117
+ "assurance": {
1118
+ "average_score": None,
1119
+ "minimum_score": None,
1120
+ "fully_confirmed_rate": None,
1121
+ "blocking_reasons": {},
1122
+ },
1123
+ "findings": [],
1124
+ }
1125
+
1126
+
1127
+ def gate(payload: dict) -> dict:
1128
+ """Aggregate the confirmation gate without inventing metrics on failure.
1129
+
1130
+ Payload-level errors leave the finding list enumerable, so each row is
1131
+ still classified independently. Only an unenumerable ``findings`` field
1132
+ makes aggregate counts unknown; that path returns ``None`` plus
1133
+ ``degraded`` rather than a misleading zero.
1134
+ """
1135
+ from core.agent import agent_eval # DES-02:见模块顶部说明(避免导入期成环)
1136
+
1137
+ structural = _gate_structural_error(payload)
1138
+ findings_value = payload.get("findings") if isinstance(payload, Mapping) else None
1139
+ if structural is not None and not isinstance(findings_value, list):
1140
+ return degraded_gate(f"confirmation protocol invalid: {structural}")
1141
+
1142
+ findings = findings_value
1143
+ details = []
1144
+ counts = Counter()
1145
+ row_validation_errors: list[str] = []
1146
+ for index, finding in enumerate(findings, 1):
1147
+ if not isinstance(finding, dict):
1148
+ counts["candidate"] += 1
1149
+ details.append({
1150
+ "id": f"#{index}",
1151
+ "state": "candidate",
1152
+ "confirmed": False,
1153
+ "issues": [f"finding #{index} 必须是对象"],
1154
+ "assurance": {"score": 0, "level": "invalid"},
1155
+ })
1156
+ continue
1157
+ confirmation = _confirmation(finding)
1158
+ state = str(confirmation.get("state", "candidate"))
1159
+ counts[state] += 1
1160
+ issues: list[str] = []
1161
+ # Validate one row at a time so malformed data cannot poison the
1162
+ # aggregate, while retaining the original agent_eval contract.
1163
+ try:
1164
+ agent_eval.validate_findings({
1165
+ "schema_version": 1,
1166
+ "duration_seconds": 0,
1167
+ "token_count": 0,
1168
+ "findings": [finding],
1169
+ })
1170
+ except agent_eval.EvalError as exc: # row-level schema error is pending
1171
+ issues.append(str(exc))
1172
+ row_validation_errors.append(str(exc))
1173
+ except Exception as exc:
1174
+ # An unexpected validator failure means the aggregate itself is
1175
+ # unknown; do not turn an implementation fault into row counts.
1176
+ return degraded_gate(f"confirmation validator unavailable: {exc}")
1177
+ try:
1178
+ issues.extend(confirmation_issues(finding))
1179
+ except ConfirmationError as exc:
1180
+ issues.append(str(exc))
1181
+ except Exception as exc:
1182
+ return degraded_gate(f"confirmation issue evaluation unavailable: {exc}")
1183
+ try:
1184
+ assurance = confirmation_assurance(finding)
1185
+ except ConfirmationError:
1186
+ assurance = {"score": 0, "level": "invalid"}
1187
+ except Exception as exc:
1188
+ return degraded_gate(f"confirmation assurance unavailable: {exc}")
1189
+ details.append({
1190
+ "id": finding.get("id") if isinstance(finding.get("id"), str)
1191
+ and finding.get("id") else f"#{index}",
1192
+ "state": state,
1193
+ "confirmed": state == "confirmed" and not issues,
1194
+ "issues": issues,
1195
+ "assurance": assurance,
1196
+ })
1197
+ confirmed = sum(item["confirmed"] for item in details)
1198
+ rejected = counts["rejected"]
1199
+ pending = len(details) - confirmed - rejected
1200
+ scores = [item["assurance"]["score"] for item in details]
1201
+ blocking = Counter(
1202
+ issue
1203
+ for item in details
1204
+ if not item["confirmed"] and item["state"] != "rejected"
1205
+ for issue in item["issues"]
1206
+ )
1207
+ result = {
1208
+ "schema_version": SCHEMA_VERSION,
1209
+ "total": len(details),
1210
+ "confirmed": confirmed,
1211
+ "rejected": rejected,
1212
+ "pending": pending,
1213
+ # rejected 是有证据、有分类、有理由的终态,不应阻塞最终报告;只有仍待
1214
+ # 判定的 candidate/observed/reproduced/root_caused 或无效 confirmed 阻塞。
1215
+ "ready": pending == 0,
1216
+ "states": dict(sorted(counts.items())),
1217
+ "assurance": {
1218
+ "average_score": round(sum(scores) / len(scores), 2) if scores else 0.0,
1219
+ "minimum_score": min(scores) if scores else 0,
1220
+ "fully_confirmed_rate": round(confirmed / len(details), 4) if details else 0.0,
1221
+ "blocking_reasons": dict(blocking.most_common()),
1222
+ },
1223
+ "findings": details,
1224
+ }
1225
+ if structural is not None:
1226
+ result["degraded"] = True
1227
+ result["error"] = f"confirmation protocol invalid: {structural}"
1228
+ elif row_validation_errors:
1229
+ # FIX-003 B4(回归修复):单条数据问题只**逐条**上报,绝不给整门设全局
1230
+ # ``error``(BX-ENGINE-18 契约:单条越界不得让整门失败)。聚合仍可计算,
1231
+ # 故不置 degraded;机器可见性由 ``findings[].issues``、
1232
+ # ``assurance.blocking_reasons`` 与 ``ready`` 提供,另以独立字段保留原始
1233
+ # 行级错误,避免旧调用方把畸形行误当干净门禁。
1234
+ result["row_validation_errors"] = row_validation_errors[:3]
1235
+ return result
1236
+
1237
+
1238
+ def _gate_structural_error(payload: object) -> str | None:
1239
+ """只检查**结构性**问题(fail-closed);单条数据问题由逐条路径处理。"""
1240
+ if not isinstance(payload, Mapping):
1241
+ return "payload 必须是对象"
1242
+ if payload.get("schema_version") != 1:
1243
+ return "findings.schema_version 必须为 1"
1244
+ findings = payload.get("findings")
1245
+ if not isinstance(findings, list):
1246
+ return "findings 必须是数组"
1247
+ duration = payload.get("duration_seconds")
1248
+ if not isinstance(duration, (int, float)) or isinstance(duration, bool) or duration < 0:
1249
+ return "findings.duration_seconds 必须是非负数"
1250
+ token_count = payload.get("token_count")
1251
+ if token_count is not None and (
1252
+ not isinstance(token_count, int) or isinstance(token_count, bool) or token_count < 0
1253
+ ):
1254
+ return "findings.token_count 必须是非负整数或 null"
1255
+ return None
1256
+
1257
+
1258
+ def _write_atomic(path: Path, payload: dict) -> None:
1259
+ path.parent.mkdir(parents=True, exist_ok=True)
1260
+ descriptor, temporary = tempfile.mkstemp(
1261
+ dir=str(path.parent), prefix=f".{path.name}.", suffix=".tmp",
1262
+ )
1263
+ try:
1264
+ with os.fdopen(descriptor, "w", encoding="utf-8") as handle:
1265
+ json.dump(payload, handle, ensure_ascii=False, indent=2)
1266
+ handle.write("\n")
1267
+ os.replace(temporary, path)
1268
+ except BaseException:
1269
+ try:
1270
+ os.unlink(temporary)
1271
+ except OSError:
1272
+ pass
1273
+ raise
1274
+
1275
+
1276
+ def main(argv: list[str] | None = None) -> int:
1277
+ from core.agent import agent_eval # DES-02:见模块顶部说明(避免导入期成环)
1278
+ parser = argparse.ArgumentParser(description=__doc__)
1279
+ parser.add_argument("command", choices=("validate", "gate", "transition"))
1280
+ parser.add_argument("--input", type=Path, required=True)
1281
+ parser.add_argument("--output", type=Path)
1282
+ parser.add_argument("--id")
1283
+ parser.add_argument("--state", choices=CONFIRMATION_STATES)
1284
+ parser.add_argument("--reason")
1285
+ parser.add_argument("--rejection-class", choices=sorted(REJECTION_CLASSES))
1286
+ parser.add_argument("--json", action="store_true")
1287
+ args = parser.parse_args(argv)
1288
+ try:
1289
+ payload = agent_eval.load_json(args.input)
1290
+ findings = agent_eval.validate_findings(payload)
1291
+ if args.command == "transition":
1292
+ if not args.id or not args.state:
1293
+ raise ConfirmationError("transition 必须提供 --id 和 --state")
1294
+ finding = next((item for item in findings if item["id"] == args.id), None)
1295
+ if finding is None:
1296
+ raise ConfirmationError(f"Finding 不存在: {args.id}")
1297
+ transition(finding, args.state, args.reason, args.rejection_class)
1298
+ result = payload
1299
+ else:
1300
+ for finding in findings:
1301
+ validate_confirmation(finding)
1302
+ result = gate(payload)
1303
+ if args.output:
1304
+ _write_atomic(args.output, result)
1305
+ if args.json or not args.output:
1306
+ print(json.dumps(result, ensure_ascii=False, indent=2))
1307
+ if args.command == "gate" and not result["ready"]:
1308
+ return 1
1309
+ return 0
1310
+ except (ConfirmationError, agent_eval.EvalError, OSError, json.JSONDecodeError) as exc:
1311
+ print(f"[finding_confirmation] ✗ {exc}", file=sys.stderr)
1312
+ return 2
1313
+
1314
+
1315
+ if __name__ == "__main__":
1316
+ raise SystemExit(main())