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,1364 @@
1
+ #!/usr/bin/env python3
2
+ """BugX 测试用例能力动态验证框架 (Test Capability Verifier, DOC-052).
3
+
4
+ 基于 AST 语义微观变异 (Mutation Testing) 与隔离沙箱执行,对测试用例抓 Bug 能力进行动态验证:
5
+ 1. SemanticMutator: 针对被测代码生成 6 类高阶语义变异体 (ROR, AOR, LCR, BCR, EOR, SVR);
6
+ 2. MutationSandboxRunner: 独立安全沙箱中执行基线验证与变异体杀伤动态测试;
7
+ 3. TestCapabilityEvaluator: 计算变异击杀率 (Mutation Score) 并评定能力等级 (ELITE/CAPABLE/WEAK/INEFFECTIVE);
8
+ 4. 产出结构化报告与覆盖智能系统 (coverage_intelligence) 兼容数据。
9
+ """
10
+
11
+ from __future__ import annotations
12
+ # --- 引擎导入根(直接执行脚本时自举 core.* 命名空间)---
13
+ import sys as _sys
14
+ from pathlib import Path as _Path
15
+
16
+ for _p in _Path(__file__).resolve().parents:
17
+ if (_p / "core" / "bugx.md").is_file():
18
+ if str(_p) not in _sys.path:
19
+ _sys.path.insert(0, str(_p))
20
+ break
21
+ del _p
22
+
23
+ import argparse
24
+ import ast
25
+ import copy
26
+ import json
27
+ import os
28
+ import re
29
+ import shlex
30
+ import shutil
31
+ import signal
32
+ import subprocess
33
+ import sys
34
+ import tempfile
35
+ import time
36
+ from dataclasses import asdict, dataclass, field
37
+ from pathlib import Path
38
+ from typing import Any, Callable, Sequence
39
+
40
+ SCHEMA_VERSION = 1
41
+
42
+ # 允许作为测试入口的解释器白名单。``test_target`` 由 Worker 通过 MCP 传入,
43
+ # 而 Worker 上下文必然携带被审计项目的不可信源码:若不限制首 token,
44
+ # ``sh -c '<任意命令>'`` 会被直接执行并获得完整 RCE 与环境变量。
45
+ ALLOWED_TEST_RUNNERS = frozenset({
46
+ "python", "python3", "py", "pytest",
47
+ "go",
48
+ "ctest", "cargo", "make", "ninja",
49
+ "node", "npm",
50
+ })
51
+
52
+ # 沙箱执行时透传的环境变量白名单(对齐 platform_adapter.SAFE_ENV 并覆盖多语言工具链)。
53
+ SAFE_ENV_KEYS = (
54
+ "PATH", "HOME", "TMPDIR", "TEMP", "TMP", "LANG", "LC_ALL",
55
+ "SYSTEMROOT", "COMSPEC", "PYTHONIOENCODING",
56
+ # Go 运行环境
57
+ "GOPATH", "GOROOT", "GOCACHE", "GO111MODULE", "CGO_ENABLED", "CGO_CFLAGS", "CGO_LDFLAGS",
58
+ # Rust 运行环境
59
+ "CARGO_HOME", "RUSTUP_HOME", "RUST_BACKTRACE",
60
+ # C/C++ 构建与测试环境
61
+ "CC", "CXX", "CFLAGS", "CXXFLAGS", "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH",
62
+ # Node / JS / TS 运行环境
63
+ "NODE_PATH", "NODE_OPTIONS",
64
+ )
65
+
66
+ # 变异验证隔离副本的排除规则。SEC-11:变异测试只改写私有副本,
67
+ # 复制 ``self.cwd`` 时跳过缓存、仓库元数据与构建产物等无关且体积巨大的目录,
68
+ # 避免把整个仓库(含 .git / .bugx)逐变异体复制一遍。
69
+ MUTATION_COPY_IGNORE = shutil.ignore_patterns(
70
+ "__pycache__", ".git", ".bugx", "node_modules", "build", "dist", ".venv",
71
+ "*.pyc", "*.pyo", ".mypy_cache", ".pytest_cache", ".ruff_cache", ".tox",
72
+ )
73
+
74
+ # 能力评级阈值
75
+ LEVEL_ELITE_THRESHOLD = 80.0
76
+ LEVEL_CAPABLE_THRESHOLD = 60.0
77
+ LEVEL_WEAK_THRESHOLD = 30.0
78
+
79
+ # 变异算子定义
80
+ OP_ROR = "ROR" # Relational Operator Replacement
81
+ OP_AOR = "AOR" # Arithmetic Operator Replacement
82
+ OP_LCR = "LCR" # Logical Connector Replacement
83
+ OP_BCR = "BCR" # Boundary Condition Replacement
84
+ OP_EOR = "EOR" # Exception / Return Alteration
85
+ OP_SVR = "SVR" # Statement Voiding Replacement
86
+
87
+ OPERATOR_DESCRIPTIONS = {
88
+ OP_ROR: "关系比较符变异 (<, <=, >, >=, ==, !=, in, is)",
89
+ OP_AOR: "算术运算符变异 (+, -, *, //, /, %)",
90
+ OP_LCR: "逻辑连接符变异 (and, or)",
91
+ OP_BCR: "边界数值与布尔常量变异 (0<->1, True<->False, 边界增减)",
92
+ OP_EOR: "异常与返回值篡改 (return None, 抹除 raise)",
93
+ OP_SVR: "语句置空变异 (副作用调用/累加语句置为 pass)",
94
+ }
95
+
96
+ OP_SYMBOLS: dict[type, str] = {
97
+ ast.Lt: "<", ast.LtE: "<=", ast.Gt: ">", ast.GtE: ">=", ast.Eq: "==", ast.NotEq: "!=",
98
+ ast.In: "in", ast.NotIn: "not in", ast.Is: "is", ast.IsNot: "is not",
99
+ ast.Add: "+", ast.Sub: "-", ast.Mult: "*", ast.Div: "/", ast.FloorDiv: "//", ast.Mod: "%",
100
+ ast.And: "and", ast.Or: "or",
101
+ }
102
+
103
+
104
+ @dataclass
105
+ class Mutant:
106
+ """单个变异体定义。"""
107
+ mutant_id: str
108
+ operator: str
109
+ target_path: str
110
+ lineno: int
111
+ col_offset: int
112
+ original_repr: str
113
+ mutated_repr: str
114
+ description: str
115
+ mutated_source: str
116
+
117
+ def to_dict(self) -> dict[str, Any]:
118
+ d = asdict(self)
119
+ d.pop("mutated_source", None) # 摘要中默认剔除完整代码,避免体积过大
120
+ return d
121
+
122
+
123
+ @dataclass
124
+ class MutantExecutionResult:
125
+ """变异体执行结果。"""
126
+ mutant_id: str
127
+ operator: str
128
+ lineno: int
129
+ status: str # KILLED, SURVIVED, KILLED_TIMEOUT, INVALID, BASELINE_FAIL
130
+ duration_ms: float
131
+ description: str
132
+ diagnostic: str = ""
133
+
134
+ def to_dict(self) -> dict[str, Any]:
135
+ return asdict(self)
136
+
137
+
138
+ @dataclass
139
+ class CapabilitySummary:
140
+ """测试用例能力评估汇总。"""
141
+ target_path: str
142
+ test_target: str
143
+ total_mutants: int
144
+ killed_mutants: int
145
+ survived_mutants: int
146
+ timeout_mutants: int
147
+ mutation_score: float
148
+ capability_level: str # ELITE, CAPABLE, WEAK, INEFFECTIVE
149
+ operator_scores: dict[str, dict[str, Any]]
150
+ survived_mutants_details: list[dict[str, Any]]
151
+ recommendations: list[str]
152
+ execution_time_sec: float
153
+
154
+ def to_dict(self) -> dict[str, Any]:
155
+ return asdict(self)
156
+
157
+
158
+ class SemanticMutator:
159
+ """基于 AST 或通用 Token 的语义变异体生成引擎。"""
160
+
161
+ def __init__(self, target_path: str | Path, source_code: str | None = None):
162
+ self.target_path = Path(target_path)
163
+ if source_code is not None:
164
+ self.source_code = source_code
165
+ else:
166
+ self.source_code = self.target_path.read_text(encoding="utf-8")
167
+ self.is_python = self.target_path.suffix.lower() == ".py"
168
+ self.tree: ast.AST | None = None
169
+ if self.is_python:
170
+ try:
171
+ self.tree = ast.parse(self.source_code, filename=str(self.target_path))
172
+ self._index_tree(self.tree)
173
+ except Exception:
174
+ self.tree = None
175
+
176
+ @staticmethod
177
+ def _index_tree(tree: ast.AST) -> None:
178
+ """为 AST 每个节点打上唯一的内部 _nid。"""
179
+ idx = 0
180
+ for node in ast.walk(tree):
181
+ node._nid = idx # type: ignore[attr-defined]
182
+ idx += 1
183
+
184
+ def generate_mutants(self, max_mutants: int = 30, operators: Sequence[str] | None = None) -> list[Mutant]:
185
+ """生成变异体列表,支持最大数量控制与算子过滤。"""
186
+ if self.tree is None:
187
+ return self._generate_universal_mutants(max_mutants, operators)
188
+
189
+ enabled_ops = set(operators or [OP_ROR, OP_AOR, OP_LCR, OP_BCR, OP_EOR, OP_SVR])
190
+ raw_mutants: list[Mutant] = []
191
+
192
+ # 1. 收集被保护的节点(如文档字符串、函数参数类型标注等)
193
+ protected_nids = self._collect_protected_nids()
194
+
195
+ # 2. 遍历 AST 收集各算子候选
196
+ for node in ast.walk(self.tree):
197
+ nid = getattr(node, "_nid", -1)
198
+ if nid in protected_nids:
199
+ continue
200
+
201
+ lineno = getattr(node, "lineno", 1)
202
+ col_offset = getattr(node, "col_offset", 0)
203
+
204
+ # ROR 算子
205
+ if OP_ROR in enabled_ops and isinstance(node, ast.Compare):
206
+ for i, op in enumerate(node.ops):
207
+ swapped_ops = self._mutate_relational_op(op)
208
+ orig_sym = OP_SYMBOLS.get(type(op), op.__class__.__name__)
209
+ for new_op, desc in swapped_ops:
210
+ new_sym = OP_SYMBOLS.get(type(new_op), new_op.__class__.__name__)
211
+ mutant = self._create_mutant(
212
+ operator=OP_ROR,
213
+ target_nid=nid,
214
+ transformer=lambda n, i=i, new_op=new_op: self._apply_compare_op(n, i, new_op),
215
+ lineno=lineno,
216
+ col_offset=col_offset,
217
+ orig_repr=orig_sym,
218
+ mut_repr=new_sym,
219
+ description=f"ROR 行 {lineno}: {desc}",
220
+ )
221
+ if mutant:
222
+ raw_mutants.append(mutant)
223
+
224
+ # AOR 算子
225
+ if OP_AOR in enabled_ops and isinstance(node, ast.BinOp):
226
+ swapped_ops = self._mutate_arithmetic_op(node.op)
227
+ orig_sym = OP_SYMBOLS.get(type(node.op), node.op.__class__.__name__)
228
+ for new_op, desc in swapped_ops:
229
+ new_sym = OP_SYMBOLS.get(type(new_op), new_op.__class__.__name__)
230
+ mutant = self._create_mutant(
231
+ operator=OP_AOR,
232
+ target_nid=nid,
233
+ transformer=lambda n, new_op=new_op: self._apply_bin_op(n, new_op),
234
+ lineno=lineno,
235
+ col_offset=col_offset,
236
+ orig_repr=orig_sym,
237
+ mut_repr=new_sym,
238
+ description=f"AOR 行 {lineno}: {desc}",
239
+ )
240
+ if mutant:
241
+ raw_mutants.append(mutant)
242
+
243
+ # LCR 算子
244
+ if OP_LCR in enabled_ops and isinstance(node, ast.BoolOp):
245
+ new_op, desc = self._mutate_logical_op(node.op)
246
+ if new_op:
247
+ orig_sym = OP_SYMBOLS.get(type(node.op), node.op.__class__.__name__)
248
+ new_sym = OP_SYMBOLS.get(type(new_op), new_op.__class__.__name__)
249
+ mutant = self._create_mutant(
250
+ operator=OP_LCR,
251
+ target_nid=nid,
252
+ transformer=lambda n, new_op=new_op: self._apply_bool_op(n, new_op),
253
+ lineno=lineno,
254
+ col_offset=col_offset,
255
+ orig_repr=orig_sym,
256
+ mut_repr=new_sym,
257
+ description=f"LCR 行 {lineno}: {desc}",
258
+ )
259
+ if mutant:
260
+ raw_mutants.append(mutant)
261
+
262
+ # BCR 算子 (边界数值与布尔常量)
263
+ if OP_BCR in enabled_ops and isinstance(node, ast.Constant):
264
+ if isinstance(node.value, bool):
265
+ new_val = not node.value
266
+ mutant = self._create_mutant(
267
+ operator=OP_BCR,
268
+ target_nid=nid,
269
+ transformer=lambda n, new_val=new_val: self._apply_constant(n, new_val),
270
+ lineno=lineno,
271
+ col_offset=col_offset,
272
+ orig_repr=str(node.value),
273
+ mut_repr=str(new_val),
274
+ description=f"BCR 行 {lineno}: 布尔翻转 {node.value} -> {new_val}",
275
+ )
276
+ if mutant:
277
+ raw_mutants.append(mutant)
278
+ elif isinstance(node.value, (int, float)) and not isinstance(node.value, bool):
279
+ candidates = self._mutate_numeric_boundary(node.value)
280
+ for new_val, desc in candidates:
281
+ mutant = self._create_mutant(
282
+ operator=OP_BCR,
283
+ target_nid=nid,
284
+ transformer=lambda n, new_val=new_val: self._apply_constant(n, new_val),
285
+ lineno=lineno,
286
+ col_offset=col_offset,
287
+ orig_repr=str(node.value),
288
+ mut_repr=str(new_val),
289
+ description=f"BCR 行 {lineno}: {desc}",
290
+ )
291
+ if mutant:
292
+ raw_mutants.append(mutant)
293
+
294
+ # EOR 算子 (返回值或异常)
295
+ if OP_EOR in enabled_ops:
296
+ if isinstance(node, ast.Return) and node.value is not None:
297
+ if not (isinstance(node.value, ast.Constant) and node.value.value is None):
298
+ mutant = self._create_mutant(
299
+ operator=OP_EOR,
300
+ target_nid=nid,
301
+ transformer=lambda n: self._apply_return_none(n),
302
+ lineno=lineno,
303
+ col_offset=col_offset,
304
+ orig_repr=ast.unparse(node),
305
+ mut_repr="return None",
306
+ description=f"EOR 行 {lineno}: 返回值篡改为 return None",
307
+ )
308
+ if mutant:
309
+ raw_mutants.append(mutant)
310
+ elif isinstance(node, ast.Raise):
311
+ mutant = self._create_mutant(
312
+ operator=OP_EOR,
313
+ target_nid=nid,
314
+ transformer=lambda n: ast.Pass(),
315
+ lineno=lineno,
316
+ col_offset=col_offset,
317
+ orig_repr=ast.unparse(node),
318
+ mut_repr="pass",
319
+ description=f"EOR 行 {lineno}: 抹除异常抛出 (raise -> pass)",
320
+ )
321
+ if mutant:
322
+ raw_mutants.append(mutant)
323
+
324
+ # SVR 算子 (语句置空)
325
+ if OP_SVR in enabled_ops and isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
326
+ for stmt in node.body:
327
+ stmt_nid = getattr(stmt, "_nid", -1)
328
+ if isinstance(stmt, (ast.Expr, ast.AugAssign)) and stmt_nid not in protected_nids:
329
+ mutant = self._create_mutant(
330
+ operator=OP_SVR,
331
+ target_nid=stmt_nid,
332
+ transformer=lambda n: ast.Pass(),
333
+ lineno=getattr(stmt, "lineno", lineno),
334
+ col_offset=getattr(stmt, "col_offset", 0),
335
+ orig_repr=ast.unparse(stmt),
336
+ mut_repr="pass",
337
+ description=f"SVR 行 {getattr(stmt, 'lineno', lineno)}: 置空副作用语句为 pass",
338
+ )
339
+ if mutant:
340
+ raw_mutants.append(mutant)
341
+
342
+ # 3. 按算子进行均衡采样截断,防止单类算子占满配额
343
+ return self._balance_mutants(raw_mutants, max_mutants)
344
+
345
+ def _collect_protected_nids(self) -> set[int]:
346
+ """识别不应被变异的节点,如文档字符串、类型注解、导入语句等。"""
347
+ protected: set[int] = set()
348
+ for node in ast.walk(self.tree):
349
+ nid = getattr(node, "_nid", -1)
350
+ # 导入语句
351
+ if isinstance(node, (ast.Import, ast.ImportFrom)):
352
+ protected.add(nid)
353
+ for child in ast.walk(node):
354
+ protected.add(getattr(child, "_nid", -1))
355
+ # 函数返回值注解与参数注解
356
+ elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
357
+ if node.returns:
358
+ for child in ast.walk(node.returns):
359
+ protected.add(getattr(child, "_nid", -1))
360
+ for arg in node.args.args + node.args.kwonlyargs + node.args.posonlyargs:
361
+ if arg.annotation:
362
+ for child in ast.walk(arg.annotation):
363
+ protected.add(getattr(child, "_nid", -1))
364
+ # 函数体首句 docstring
365
+ if node.body and isinstance(node.body[0], ast.Expr) and isinstance(node.body[0].value, ast.Constant):
366
+ if isinstance(node.body[0].value.value, str):
367
+ protected.add(getattr(node.body[0], "_nid", -1))
368
+ protected.add(getattr(node.body[0].value, "_nid", -1))
369
+ # 类体首句 docstring
370
+ elif isinstance(node, ast.ClassDef):
371
+ if node.body and isinstance(node.body[0], ast.Expr) and isinstance(node.body[0].value, ast.Constant):
372
+ if isinstance(node.body[0].value.value, str):
373
+ protected.add(getattr(node.body[0], "_nid", -1))
374
+ protected.add(getattr(node.body[0].value, "_nid", -1))
375
+ # 模块首句 docstring
376
+ elif isinstance(node, ast.Module):
377
+ if node.body and isinstance(node.body[0], ast.Expr) and isinstance(node.body[0].value, ast.Constant):
378
+ if isinstance(node.body[0].value.value, str):
379
+ protected.add(getattr(node.body[0], "_nid", -1))
380
+ protected.add(getattr(node.body[0].value, "_nid", -1))
381
+ return protected
382
+
383
+ def _create_mutant(
384
+ self,
385
+ operator: str,
386
+ target_nid: int,
387
+ transformer: Callable[[ast.AST], ast.AST],
388
+ lineno: int,
389
+ col_offset: int,
390
+ orig_repr: str,
391
+ mut_repr: str,
392
+ description: str,
393
+ ) -> Mutant | None:
394
+ """克隆 AST 并替换指定 nid 节点,产出合法 Python 源码变异体。"""
395
+ new_tree = copy.deepcopy(self.tree)
396
+
397
+ class Replacer(ast.NodeTransformer):
398
+ def visit(self, node: ast.AST) -> ast.AST:
399
+ if getattr(node, "_nid", -1) == target_nid:
400
+ res = transformer(node)
401
+ return ast.copy_location(res, node)
402
+ return self.generic_visit(node)
403
+
404
+ transformed = Replacer().visit(new_tree)
405
+ ast.fix_missing_locations(transformed)
406
+
407
+ try:
408
+ mutated_code = ast.unparse(transformed)
409
+ # 语法健全性防御:必须能够被 Python 编译
410
+ compile(mutated_code, f"<mutant_{target_nid}>", "exec")
411
+ except Exception:
412
+ return None
413
+
414
+ # 确保变异后源码有实质变动
415
+ if mutated_code == self.source_code:
416
+ return None
417
+
418
+ mutant_id = f"MUT_{operator}_{lineno}_{abs(hash(mut_repr)) % 10000:04d}"
419
+ return Mutant(
420
+ mutant_id=mutant_id,
421
+ operator=operator,
422
+ target_path=str(self.target_path),
423
+ lineno=lineno,
424
+ col_offset=col_offset,
425
+ original_repr=orig_repr,
426
+ mutated_repr=mut_repr,
427
+ description=description,
428
+ mutated_source=mutated_code,
429
+ )
430
+
431
+ # ---- 算子变异辅助规则 ----
432
+
433
+ @staticmethod
434
+ def _mutate_relational_op(op: ast.cmpop) -> list[tuple[ast.cmpop, str]]:
435
+ res: list[tuple[ast.cmpop, str]] = []
436
+ if isinstance(op, ast.Lt):
437
+ res.append((ast.LtE(), "< -> <="))
438
+ res.append((ast.Gt(), "< -> >"))
439
+ elif isinstance(op, ast.LtE):
440
+ res.append((ast.Lt(), "<= -> <"))
441
+ res.append((ast.GtE(), "<= -> >="))
442
+ elif isinstance(op, ast.Gt):
443
+ res.append((ast.GtE(), "> -> >="))
444
+ res.append((ast.Lt(), "> -> <"))
445
+ elif isinstance(op, ast.GtE):
446
+ res.append((ast.Gt(), ">= -> >"))
447
+ res.append((ast.LtE(), ">= -> <="))
448
+ elif isinstance(op, ast.Eq):
449
+ res.append((ast.NotEq(), "== -> !="))
450
+ elif isinstance(op, ast.NotEq):
451
+ res.append((ast.Eq(), "!= -> =="))
452
+ elif isinstance(op, ast.In):
453
+ res.append((ast.NotIn(), "in -> not in"))
454
+ elif isinstance(op, ast.NotIn):
455
+ res.append((ast.In(), "not in -> in"))
456
+ elif isinstance(op, ast.Is):
457
+ res.append((ast.IsNot(), "is -> is not"))
458
+ elif isinstance(op, ast.IsNot):
459
+ res.append((ast.Is(), "is not -> is"))
460
+ return res
461
+
462
+ @staticmethod
463
+ def _mutate_arithmetic_op(op: ast.operator) -> list[tuple[ast.operator, str]]:
464
+ res: list[tuple[ast.operator, str]] = []
465
+ if isinstance(op, ast.Add):
466
+ res.append((ast.Sub(), "+ -> -"))
467
+ elif isinstance(op, ast.Sub):
468
+ res.append((ast.Add(), "- -> +"))
469
+ elif isinstance(op, ast.Mult):
470
+ res.append((ast.FloorDiv(), "* -> //"))
471
+ elif isinstance(op, (ast.Div, ast.FloorDiv)):
472
+ res.append((ast.Mult(), "/ -> *"))
473
+ elif isinstance(op, ast.Mod):
474
+ res.append((ast.Mult(), "% -> *"))
475
+ return res
476
+
477
+ @staticmethod
478
+ def _mutate_logical_op(op: ast.boolop) -> tuple[ast.boolop | None, str]:
479
+ if isinstance(op, ast.And):
480
+ return ast.Or(), "and -> or"
481
+ elif isinstance(op, ast.Or):
482
+ return ast.And(), "or -> and"
483
+ return None, ""
484
+
485
+ @staticmethod
486
+ def _mutate_numeric_boundary(val: int | float) -> list[tuple[int | float, str]]:
487
+ res: list[tuple[int | float, str]] = []
488
+ if val == 0:
489
+ res.append((1, "0 -> 1"))
490
+ elif val == 1:
491
+ res.append((0, "1 -> 0"))
492
+ elif val > 1:
493
+ res.append((val - 1, f"{val} -> {val - 1}"))
494
+ res.append((val + 1, f"{val} -> {val + 1}"))
495
+ elif val < 0:
496
+ res.append((val + 1, f"{val} -> {val + 1}"))
497
+ return res
498
+
499
+ @staticmethod
500
+ def _apply_compare_op(node: ast.AST, index: int, new_op: ast.cmpop) -> ast.AST:
501
+ assert isinstance(node, ast.Compare)
502
+ node.ops[index] = new_op
503
+ return node
504
+
505
+ @staticmethod
506
+ def _apply_bin_op(node: ast.AST, new_op: ast.operator) -> ast.AST:
507
+ assert isinstance(node, ast.BinOp)
508
+ node.op = new_op
509
+ return node
510
+
511
+ @staticmethod
512
+ def _apply_bool_op(node: ast.AST, new_op: ast.boolop) -> ast.AST:
513
+ assert isinstance(node, ast.BoolOp)
514
+ node.op = new_op
515
+ return node
516
+
517
+ @staticmethod
518
+ def _apply_constant(node: ast.AST, new_val: Any) -> ast.AST:
519
+ assert isinstance(node, ast.Constant)
520
+ node.value = new_val
521
+ return node
522
+
523
+ @staticmethod
524
+ def _apply_return_none(node: ast.AST) -> ast.AST:
525
+ assert isinstance(node, ast.Return)
526
+ node.value = ast.Constant(value=None)
527
+ return node
528
+
529
+ @staticmethod
530
+ def _balance_mutants(mutants: list[Mutant], max_mutants: int) -> list[Mutant]:
531
+ """按算子均衡采样,避免单类变异体过度集中。"""
532
+ if len(mutants) <= max_mutants:
533
+ return mutants
534
+ by_op: dict[str, list[Mutant]] = {}
535
+ for m in mutants:
536
+ by_op.setdefault(m.operator, []).append(m)
537
+
538
+ selected: list[Mutant] = []
539
+ op_keys = sorted(by_op.keys())
540
+ idx = 0
541
+ while len(selected) < max_mutants and any(by_op.values()):
542
+ op = op_keys[idx % len(op_keys)]
543
+ if by_op[op]:
544
+ selected.append(by_op[op].pop(0))
545
+ idx += 1
546
+
547
+ # 按行号排序输出
548
+ selected.sort(key=lambda m: (m.lineno, m.col_offset))
549
+ return selected
550
+
551
+ def _generate_universal_mutants(self, max_mutants: int = 30, operators: Sequence[str] | None = None) -> list[Mutant]:
552
+ """为 C-family 语言 (C/C++, Go, Rust, Java, TS/JS) 提供基于源码分词与切片的通用变异生成。"""
553
+ enabled_ops = set(operators or [OP_ROR, OP_AOR, OP_LCR, OP_BCR])
554
+ raw_mutants: list[Mutant] = []
555
+
556
+ lines = self.source_code.splitlines(keepends=True)
557
+
558
+ # ROR: ==, !=, <=, >=, <, >
559
+ ror_map = {
560
+ "==": "!=",
561
+ "!=": "==",
562
+ "<=": ">",
563
+ ">=": "<",
564
+ "<": ">=",
565
+ ">": "<=",
566
+ }
567
+
568
+ # AOR: +, -, *, /, %
569
+ aor_map = {
570
+ "+": "-",
571
+ "-": "+",
572
+ "*": "/",
573
+ "/": "*",
574
+ "%": "*",
575
+ }
576
+
577
+ # LCR: &&, ||
578
+ lcr_map = {
579
+ "&&": "||",
580
+ "||": "&&",
581
+ }
582
+
583
+ # BCR: 0, 1, true, false
584
+ bcr_map = {
585
+ "0": "1",
586
+ "1": "0",
587
+ "true": "false",
588
+ "false": "true",
589
+ }
590
+
591
+ # ROR 匹配:优先匹配双字符运算符
592
+ ror_pat = re.compile(r"(==|!=|<=|>=|<|>)")
593
+ # AOR 匹配:二元算术运算符,避免匹配 ++, --, +=, -=, ->, /* 等
594
+ aor_pat = re.compile(r"(?<![+\-*/%=<>!&|])(?<!->)\s*([+\-*/%])\s*(?![+\-*/%=<>!&|])")
595
+ # LCR 匹配:&&, ||
596
+ lcr_pat = re.compile(r"(&&|\|\|)")
597
+ # BCR 匹配:布尔与基本数值边界
598
+ bcr_pat = re.compile(r"\b(0|1|true|false)\b")
599
+
600
+ for lineno_0, line in enumerate(lines):
601
+ lineno = lineno_0 + 1
602
+ stripped = line.strip()
603
+ if not stripped or stripped.startswith(("//", "/*", "*", "#", "import ", "package ", "using ", "include ")):
604
+ continue
605
+
606
+ # 剥离行内注释
607
+ code_line = line
608
+ comment_idx = -1
609
+ if "//" in code_line:
610
+ comment_idx = code_line.index("//")
611
+ elif "/*" in code_line:
612
+ comment_idx = code_line.index("/*")
613
+ if comment_idx != -1:
614
+ code_line = code_line[:comment_idx]
615
+
616
+ # 1. ROR 算子
617
+ if OP_ROR in enabled_ops:
618
+ for match in ror_pat.finditer(code_line):
619
+ orig_op = match.group(1)
620
+ if orig_op in ror_map:
621
+ new_op = ror_map[orig_op]
622
+ start_col = match.start(1)
623
+ end_col = match.end(1)
624
+ mut_lines = list(lines)
625
+ mut_lines[lineno - 1] = line[:start_col] + new_op + line[end_col:]
626
+ mut_code = "".join(mut_lines)
627
+ mut_id = f"MUT_ROR_{lineno}_{abs(hash(new_op + str(lineno) + str(start_col))) % 10000:04d}"
628
+ raw_mutants.append(Mutant(
629
+ mutant_id=mut_id,
630
+ operator=OP_ROR,
631
+ target_path=str(self.target_path),
632
+ lineno=lineno,
633
+ col_offset=start_col,
634
+ original_repr=orig_op,
635
+ mutated_repr=new_op,
636
+ description=f"ROR 行 {lineno}: {orig_op} -> {new_op}",
637
+ mutated_source=mut_code,
638
+ ))
639
+
640
+ # 2. AOR 算子
641
+ if OP_AOR in enabled_ops:
642
+ for match in aor_pat.finditer(code_line):
643
+ orig_op = match.group(1)
644
+ if orig_op in aor_map:
645
+ new_op = aor_map[orig_op]
646
+ start_col = match.start(1)
647
+ end_col = match.end(1)
648
+ mut_lines = list(lines)
649
+ mut_lines[lineno - 1] = line[:start_col] + new_op + line[end_col:]
650
+ mut_code = "".join(mut_lines)
651
+ mut_id = f"MUT_AOR_{lineno}_{abs(hash(new_op + str(lineno) + str(start_col))) % 10000:04d}"
652
+ raw_mutants.append(Mutant(
653
+ mutant_id=mut_id,
654
+ operator=OP_AOR,
655
+ target_path=str(self.target_path),
656
+ lineno=lineno,
657
+ col_offset=start_col,
658
+ original_repr=orig_op,
659
+ mutated_repr=new_op,
660
+ description=f"AOR 行 {lineno}: {orig_op} -> {new_op}",
661
+ mutated_source=mut_code,
662
+ ))
663
+
664
+ # 3. LCR 算子
665
+ if OP_LCR in enabled_ops:
666
+ for match in lcr_pat.finditer(code_line):
667
+ orig_op = match.group(1)
668
+ if orig_op in lcr_map:
669
+ new_op = lcr_map[orig_op]
670
+ start_col = match.start(1)
671
+ end_col = match.end(1)
672
+ mut_lines = list(lines)
673
+ mut_lines[lineno - 1] = line[:start_col] + new_op + line[end_col:]
674
+ mut_code = "".join(mut_lines)
675
+ mut_id = f"MUT_LCR_{lineno}_{abs(hash(new_op + str(lineno) + str(start_col))) % 10000:04d}"
676
+ raw_mutants.append(Mutant(
677
+ mutant_id=mut_id,
678
+ operator=OP_LCR,
679
+ target_path=str(self.target_path),
680
+ lineno=lineno,
681
+ col_offset=start_col,
682
+ original_repr=orig_op,
683
+ mutated_repr=new_op,
684
+ description=f"LCR 行 {lineno}: {orig_op} -> {new_op}",
685
+ mutated_source=mut_code,
686
+ ))
687
+
688
+ # 4. BCR 算子
689
+ if OP_BCR in enabled_ops:
690
+ for match in bcr_pat.finditer(code_line):
691
+ orig_val = match.group(1)
692
+ if orig_val in bcr_map:
693
+ new_val = bcr_map[orig_val]
694
+ start_col = match.start(1)
695
+ end_col = match.end(1)
696
+ mut_lines = list(lines)
697
+ mut_lines[lineno - 1] = line[:start_col] + new_val + line[end_col:]
698
+ mut_code = "".join(mut_lines)
699
+ mut_id = f"MUT_BCR_{lineno}_{abs(hash(new_val + str(lineno) + str(start_col))) % 10000:04d}"
700
+ raw_mutants.append(Mutant(
701
+ mutant_id=mut_id,
702
+ operator=OP_BCR,
703
+ target_path=str(self.target_path),
704
+ lineno=lineno,
705
+ col_offset=start_col,
706
+ original_repr=orig_val,
707
+ mutated_repr=new_val,
708
+ description=f"BCR 行 {lineno}: {orig_val} -> {new_val}",
709
+ mutated_source=mut_code,
710
+ ))
711
+
712
+ return self._balance_mutants(raw_mutants, max_mutants)
713
+
714
+
715
+ def _is_python_runner(token: str) -> bool:
716
+ """判断 argv 首 token 是否为本仓库认可的 Python 解释器入口。"""
717
+ if token == sys.executable:
718
+ return True
719
+ name = Path(token).name
720
+ return name in ("python", "python3", "py") or bool(re.fullmatch(r"python3\.\d+", name))
721
+
722
+
723
+ def normalize_test_command(test_command: list[str] | str) -> list[str]:
724
+ """把 ``test_target`` 归一化为 argv,并校验执行入口与子命令合法性。
725
+
726
+ 这是测试入口的单一归一化实现:MCP handler 与沙箱执行器都调用它,
727
+ 避免「协议层校验一套、执行层归一化另一套」的漂移。
728
+
729
+ 单 token 字符串按 schema 语义视为测试文件路径,展开为
730
+ ``[python, -m, unittest, <path>]``;多 token 字符串按 argv 解析。
731
+ """
732
+ if isinstance(test_command, str):
733
+ cmd_str = test_command.strip()
734
+ if not cmd_str:
735
+ raise ValueError("test_target 不能为空")
736
+ if " " not in cmd_str:
737
+ return [sys.executable, "-m", "unittest", cmd_str]
738
+ try:
739
+ parts = shlex.split(cmd_str)
740
+ except ValueError as exc:
741
+ raise ValueError(f"test_target 无法解析: {exc}") from exc
742
+ else:
743
+ parts = [str(item) for item in test_command]
744
+ if not parts:
745
+ raise ValueError("test_target 不能为空")
746
+
747
+ runner = Path(parts[0]).name
748
+
749
+ # 1. Python 解释器入口
750
+ if _is_python_runner(parts[0]):
751
+ if "-m" not in parts or "unittest" not in parts:
752
+ raise ValueError(
753
+ "test_target 必须是 `python -m unittest <target> ...`;"
754
+ "拒绝内联代码与任意模块执行"
755
+ )
756
+ parts[0] = sys.executable
757
+ return parts
758
+
759
+ # 2. Go 测试运行器
760
+ if runner == "go":
761
+ if len(parts) < 2 or parts[1] != "test":
762
+ raise ValueError("Go test_target 必须是 `go test ...`;拒绝执行非 test 子命令")
763
+ if any(p.startswith("-exec") or p == "-exec" for p in parts):
764
+ raise ValueError("Go test_target 拒绝使用 -exec 高危参数")
765
+ return parts
766
+
767
+ # 3. CTest 测试运行器
768
+ if runner == "ctest":
769
+ return parts
770
+
771
+ # 4. Make / Ninja 测试目标
772
+ if runner in ("make", "ninja"):
773
+ if len(parts) >= 2 and any(t in ("test", "check") for t in parts[1:]):
774
+ return parts
775
+ raise ValueError(f"{runner} test_target 必须指定 test 或 check 目标")
776
+
777
+ # 5. Cargo 测试运行器
778
+ if runner == "cargo":
779
+ if len(parts) < 2 or parts[1] != "test":
780
+ raise ValueError("Cargo test_target 必须是 `cargo test ...`;拒绝执行非 test 子命令")
781
+ return parts
782
+
783
+ # 6. Pytest 运行器
784
+ if runner == "pytest":
785
+ return parts
786
+
787
+ # 7. Node / NPM 测试运行器
788
+ if runner in ("node", "npm"):
789
+ if runner == "npm":
790
+ if len(parts) < 2 or parts[1] != "test":
791
+ raise ValueError("npm test_target 必须是 `npm test ...`;拒绝执行非 test 子命令")
792
+ return parts
793
+
794
+ raise ValueError(
795
+ f"test_target 必须使用受支持的测试运行器(python/go/ctest/cargo/node/npm),"
796
+ f"拒绝执行: {parts[0]}"
797
+ )
798
+
799
+
800
+ class MutationSandboxRunner:
801
+ """安全沙箱执行器:支持 Golden 基线验证与变异杀伤隔离执行。"""
802
+
803
+ def __init__(
804
+ self,
805
+ target_path: str | Path,
806
+ test_command: list[str] | str,
807
+ timeout_sec: float = 2.0,
808
+ cwd: str | Path | None = None,
809
+ ):
810
+ self.target_path = Path(target_path).resolve()
811
+ self.cwd = Path(cwd).resolve() if cwd else Path.cwd()
812
+ # 首 token 必须是受信任的 Python 解释器。此处是唯一的可执行入口防线:
813
+ # 任何非 Python 可执行名(sh/bash/curl/…)一律拒绝,不做「看起来安全就放行」
814
+ # 的猜测——shell 与下载器只需一次放行即可完成 RCE。
815
+ self.test_command = normalize_test_command(test_command)
816
+
817
+ # 规整测试文件路径,避免 unittest 对绝对路径抛出 ModuleNotFoundError
818
+ for i, arg in enumerate(self.test_command):
819
+ if arg.endswith(".py"):
820
+ p = Path(arg)
821
+ try:
822
+ rel_p = p.resolve().relative_to(self.cwd)
823
+ self.test_command[i] = str(rel_p)
824
+ except Exception:
825
+ if i >= 2 and self.test_command[i-2:i] == ["-m", "unittest"]:
826
+ self.test_command = [
827
+ self.test_command[0], "-m", "unittest", "discover",
828
+ "-s", str(p.parent.resolve()), "-p", p.name,
829
+ ]
830
+ break
831
+
832
+ # 确保 Python 运行测试时不写入和复用 .pyc 缓存
833
+ if self.test_command and _is_python_runner(self.test_command[0]) and "-B" not in self.test_command:
834
+ self.test_command.insert(1, "-B")
835
+
836
+ self.timeout_sec = timeout_sec
837
+ # FIX-003 D1:基线实测耗时,用于把变异体看门狗设为**相对**上限。
838
+ # 固定绝对超时(默认 2s)在「测试模块本身 ≥ 超时」时会让**所有**变异体
839
+ # 超时并被误判为"击杀",伪造出 100%/ELITE 的假绿(实测 8/8 全超时)。
840
+ self._baseline_duration_sec: float | None = None
841
+
842
+ # SEC-11 隔离副本的**每次运行只建一次**状态。
843
+ # 历史实现把 ``mkdtemp``/``copytree`` 放在 ``run_mutant`` 内部,于是每个
844
+ # 变异体都完整复制一次 ``self.cwd``;而生产路径上 ``self.cwd`` 就是项目根
845
+ # (``mcp_handlers/mining_handlers.py`` 传 ``cwd=service.root``)。实测复制
846
+ # ``core/``(205 文件 / 3.7MB)在本环境需 ~50s,``max_mutants=50`` 会让
847
+ # ``bugx_test_verify`` 完全不可用。改为惰性建一次、运行结束统一销毁。
848
+ self._sandbox_root: Path | None = None
849
+ self._staged_cwd: Path | None = None
850
+ self._staged_target: Path | None = None
851
+ self._rel_target: Path | None = None
852
+ self._original_target_source: str | None = None
853
+
854
+ def _relative_target(self) -> Path:
855
+ """目标文件相对 ``self.cwd`` 的路径;必须在 cwd 内才能被副本承接。"""
856
+ if self._rel_target is None:
857
+ try:
858
+ self._rel_target = self.target_path.relative_to(self.cwd)
859
+ except ValueError as exc:
860
+ raise RuntimeError(
861
+ "变异验证要求 target_path 位于 cwd 之内,才能在不改写共享工作树的前提下"
862
+ f"隔离执行: target={self.target_path} cwd={self.cwd}"
863
+ ) from exc
864
+ return self._rel_target
865
+
866
+ def _ensure_sandbox(self) -> Path:
867
+ """惰性创建隔离副本(整个验证运行只创建一次),返回副本根目录。
868
+
869
+ 副本排除缓存/仓库元数据等无关重目录(``MUTATION_COPY_IGNORE``),
870
+ 并记录副本内目标文件的原始内容,供每个变异体跑完后恢复。
871
+ """
872
+ if self._staged_cwd is not None:
873
+ return self._staged_cwd
874
+ rel_target = self._relative_target()
875
+ ignored_patterns = [
876
+ "__pycache__", ".git", ".bugx", "node_modules", ".venv",
877
+ "*.pyc", "*.pyo", ".mypy_cache", ".pytest_cache", ".ruff_cache", ".tox",
878
+ ]
879
+ rel_parts = rel_target.parts
880
+ if "build" not in rel_parts:
881
+ ignored_patterns.append("build")
882
+ if "dist" not in rel_parts:
883
+ ignored_patterns.append("dist")
884
+ copy_ignore = shutil.ignore_patterns(*ignored_patterns)
885
+
886
+ tmp_dir = tempfile.mkdtemp(prefix="bugx-mut-sandbox-")
887
+ sandbox_root = Path(tmp_dir)
888
+ staged_cwd = sandbox_root / "work"
889
+ try:
890
+ shutil.copytree(
891
+ self.cwd,
892
+ staged_cwd,
893
+ ignore=copy_ignore,
894
+ symlinks=False,
895
+ ignore_dangling_symlinks=True,
896
+ )
897
+ staged_target = staged_cwd / rel_target
898
+ original = staged_target.read_text(encoding="utf-8")
899
+ except Exception:
900
+ shutil.rmtree(tmp_dir, ignore_errors=True)
901
+ raise
902
+ self._sandbox_root = sandbox_root
903
+ self._staged_cwd = staged_cwd
904
+ self._staged_target = staged_target
905
+ self._original_target_source = original
906
+ return staged_cwd
907
+
908
+ def cleanup(self) -> None:
909
+ """销毁隔离副本;可重复调用,共享工作树全程未被写入。"""
910
+ root = self._sandbox_root
911
+ self._sandbox_root = None
912
+ self._staged_cwd = None
913
+ self._staged_target = None
914
+ self._original_target_source = None
915
+ if root is not None:
916
+ shutil.rmtree(root, ignore_errors=True)
917
+
918
+ def _build_env(self, cwd: Path | None = None, target_path: Path | None = None) -> dict[str, str]:
919
+ # 白名单继承:被测项目的测试进程不需要、也不应看到宿主的凭据类环境变量。
920
+ # ``cwd`` / ``target_path`` 允许调用方传入隔离副本路径,使 PYTHONPATH
921
+ # 指向副本而非共享工作树(SEC-11)。
922
+ env = {key: os.environ[key] for key in SAFE_ENV_KEYS if key in os.environ}
923
+ base_cwd = cwd if cwd is not None else self.cwd
924
+ base_target = target_path if target_path is not None else self.target_path
925
+ extra_paths = [str(base_cwd)]
926
+ if (base_cwd / "src").is_dir():
927
+ extra_paths.append(str(base_cwd / "src"))
928
+
929
+ # 向上寻找模块所在的最外层包根目录,避免将包内子目录(如 werkzeug/ 或 werkzeug/sansio/)
930
+ # 错误作为顶层搜索路径加入 PYTHONPATH,导致遮蔽标准库模块(如 http、email 等)
931
+ pkg_root = base_target.parent
932
+ while pkg_root != base_cwd and pkg_root.parent != pkg_root and (pkg_root / "__init__.py").exists():
933
+ pkg_root = pkg_root.parent
934
+ if str(pkg_root) not in extra_paths:
935
+ extra_paths.append(str(pkg_root))
936
+
937
+ env["PYTHONPATH"] = os.pathsep.join(extra_paths)
938
+ env["BUGX_TEST_TARGET_DIR"] = str(base_target.parent)
939
+ env["PYTHONDONTWRITEBYTECODE"] = "1"
940
+ if (self.cwd / "node_modules").is_dir():
941
+ orig_nm = str(self.cwd / "node_modules")
942
+ existing_np = env.get("NODE_PATH", "")
943
+ env["NODE_PATH"] = f"{orig_nm}:{existing_np}" if existing_np else orig_nm
944
+ return env
945
+
946
+ def run_baseline(self) -> tuple[bool, str]:
947
+ """运行 Golden Check 原版测试;在隔离副本内执行,共享工作树只读。
948
+
949
+ SEC-11:基线与变异体必须在**同一份副本**上运行。若基线跑真实工作树、
950
+ 变异体跑副本,而副本又排除了 ``.git`` 等目录,则「测试需要被排除目录」
951
+ 的项目会出现「基线通过、变异体全部失败」→ 变异分数被静默抬高。
952
+ 统一到副本后,副本缺东西只会表现为基线失败(显式 INEFFECTIVE),
953
+ 不会伪装成高覆盖率。
954
+ """
955
+ try:
956
+ staged_cwd = self._ensure_sandbox()
957
+ except Exception as exc:
958
+ return False, f"隔离副本创建失败: {exc}"
959
+ try:
960
+ baseline_start = time.perf_counter()
961
+ proc = subprocess.run(
962
+ self.test_command,
963
+ cwd=str(staged_cwd),
964
+ stdout=subprocess.PIPE,
965
+ stderr=subprocess.PIPE,
966
+ text=True,
967
+ env=self._build_env(cwd=staged_cwd, target_path=self._staged_target),
968
+ timeout=max(self.timeout_sec * 3, 10.0),
969
+ )
970
+ self._baseline_duration_sec = time.perf_counter() - baseline_start
971
+ if proc.returncode == 0:
972
+ return True, "Baseline OK"
973
+ return False, f"原版测试失败 (退出码 {proc.returncode}):\n{proc.stderr}\n{proc.stdout}"
974
+ except subprocess.TimeoutExpired:
975
+ return False, f"原版基线测试运行超时 (> {self.timeout_sec * 3}s)"
976
+ except Exception as exc:
977
+ return False, f"原版测试执行异常: {exc}"
978
+
979
+ def _mutant_timeout(self) -> float:
980
+ """变异体看门狗:以基线实测耗时为准,而非固定绝对值(FIX-003 D1)。
981
+
982
+ 固定 2s 在「测试模块运行 ≥ 2s」时会让每个变异体都超时并被计为击杀,
983
+ 从而伪造 100%/ELITE。这里取 ``max(配置下限, 基线*3 + 1s)``:
984
+ 配置值仍是**下限**(不降低既有严格度),基线足够慢时自动放宽。
985
+ """
986
+ base = self._baseline_duration_sec
987
+ if base is None or base <= 0:
988
+ return self.timeout_sec
989
+ return max(self.timeout_sec, base * 3.0 + 1.0)
990
+
991
+ def run_mutant(self, mutant: Mutant) -> MutantExecutionResult:
992
+ """在隔离副本中执行变异杀伤测试,绝不改写共享工作树源码。
993
+
994
+ SEC-11:历史实现直接原地覆写 ``self.target_path``,并写出
995
+ ``.bugx_mut_bak`` 备份用于恢复。并发 Worker 共享同一工作树时会读到
996
+ 彼此的变异源码(污染 ``target_fingerprint``),崩溃/中断还会残留
997
+ ``.bugx_mut_bak`` 与半变异源码。
998
+
999
+ 现改为:把 ``self.cwd`` 复制到私有 ``tempfile`` 目录(**整个验证运行
1000
+ 只复制一次**,见 :meth:`_ensure_sandbox`),只在副本内应用
1001
+ ``mutant.mutated_source``,并让测试进程的 cwd / PYTHONPATH 全部指向
1002
+ 副本。每个变异体跑完后把副本内目标文件恢复成原始内容,避免上一个
1003
+ 变异体的改动泄漏到下一个。共享工作树全程只读。
1004
+ """
1005
+ rel_target = self._relative_target()
1006
+ staged_cwd = self._ensure_sandbox()
1007
+ staged_target = self._staged_target
1008
+ assert staged_target is not None # _ensure_sandbox 已保证
1009
+
1010
+ start_time = time.perf_counter()
1011
+ status = "UNKNOWN"
1012
+ diagnostic = ""
1013
+ duration_ms = 0.0
1014
+
1015
+ try:
1016
+ # 1. 只改写副本内的目标文件,共享工作树保持只读
1017
+ staged_target.write_text(mutant.mutated_source, encoding="utf-8")
1018
+
1019
+ # 2. 在副本内执行测试命令,测试导入的是变异后的副本
1020
+ proc = subprocess.run(
1021
+ self.test_command,
1022
+ cwd=str(staged_cwd),
1023
+ stdout=subprocess.PIPE,
1024
+ stderr=subprocess.PIPE,
1025
+ text=True,
1026
+ env=self._build_env(cwd=staged_cwd, target_path=staged_target),
1027
+ timeout=self._mutant_timeout(),
1028
+ )
1029
+ duration_ms = (time.perf_counter() - start_time) * 1000.0
1030
+
1031
+ if proc.returncode != 0:
1032
+ status = "KILLED"
1033
+ diagnostic = f"测试捕获变异 (退出码 {proc.returncode})"
1034
+ else:
1035
+ status = "SURVIVED"
1036
+ diagnostic = "测试通过,未能捕获此逻辑变异"
1037
+
1038
+ except subprocess.TimeoutExpired:
1039
+ duration_ms = (time.perf_counter() - start_time) * 1000.0
1040
+ status = "KILLED_TIMEOUT"
1041
+ diagnostic = f"变异导致超时 (> {self._mutant_timeout():.1f}s),被超时看门狗捕获"
1042
+ except Exception as exc:
1043
+ duration_ms = (time.perf_counter() - start_time) * 1000.0
1044
+ status = "INVALID"
1045
+ diagnostic = f"变异体执行异常: {exc}"
1046
+ finally:
1047
+ # 3. 恢复副本内目标文件,使下一个变异体从干净副本开始。
1048
+ # 必须在 finally 中执行:变异体超时/异常时若忘记恢复,后续
1049
+ # 变异体会带着上一个变异体的源码运行,结果全部失真。
1050
+ if self._original_target_source is not None:
1051
+ try:
1052
+ staged_target.write_text(
1053
+ self._original_target_source, encoding="utf-8",
1054
+ )
1055
+ except OSError:
1056
+ pass
1057
+
1058
+ return MutantExecutionResult(
1059
+ mutant_id=mutant.mutant_id,
1060
+ operator=mutant.operator,
1061
+ lineno=mutant.lineno,
1062
+ status=status,
1063
+ duration_ms=round(duration_ms, 2),
1064
+ description=mutant.description,
1065
+ diagnostic=diagnostic,
1066
+ )
1067
+
1068
+ class TestCapabilityEvaluator:
1069
+ """测试用例能力量化评估器。"""
1070
+
1071
+ @classmethod
1072
+ def evaluate(
1073
+ cls,
1074
+ target_path: str | Path,
1075
+ test_target: str,
1076
+ results: Sequence[MutantExecutionResult],
1077
+ total_time_sec: float,
1078
+ ) -> CapabilitySummary:
1079
+ total = len(results)
1080
+ # FIX-003 D1:KILLED_TIMEOUT 是「测量失效」而非「击杀」。把超时计入击杀
1081
+ # 会在测试模块本身 ≥ 超时时伪造 100%/ELITE(实测 8/8 全超时仍报 ELITE)。
1082
+ killed = sum(1 for r in results if r.status == "KILLED")
1083
+ survived = sum(1 for r in results if r.status == "SURVIVED")
1084
+ timeouts = sum(1 for r in results if r.status == "KILLED_TIMEOUT")
1085
+
1086
+ score = round((killed / total * 100.0) if total > 0 else 0.0, 2)
1087
+
1088
+ # 评定等级
1089
+ if score >= LEVEL_ELITE_THRESHOLD:
1090
+ level = "ELITE"
1091
+ elif score >= LEVEL_CAPABLE_THRESHOLD:
1092
+ level = "CAPABLE"
1093
+ elif score >= LEVEL_WEAK_THRESHOLD:
1094
+ level = "WEAK"
1095
+ else:
1096
+ level = "INEFFECTIVE"
1097
+
1098
+ # FIX-003 D1:存在超时 ⇒ 测量不可靠,绝不冒领 ELITE。
1099
+ if timeouts > 0 and level == "ELITE":
1100
+ level = "CAPABLE"
1101
+
1102
+ # 算子分项击杀率统计
1103
+ op_groups: dict[str, list[MutantExecutionResult]] = {}
1104
+ for r in results:
1105
+ op_groups.setdefault(r.operator, []).append(r)
1106
+
1107
+ operator_scores: dict[str, dict[str, Any]] = {}
1108
+ for op, op_res in sorted(op_groups.items()):
1109
+ op_total = len(op_res)
1110
+ op_killed = sum(1 for r in op_res if r.status == "KILLED")
1111
+ op_score = round(op_killed / op_total * 100.0, 2) if op_total > 0 else 0.0
1112
+ operator_scores[op] = {
1113
+ "name": op,
1114
+ "description": OPERATOR_DESCRIPTIONS.get(op, op),
1115
+ "total": op_total,
1116
+ "killed": op_killed,
1117
+ "survived": op_total - op_killed,
1118
+ "score": op_score,
1119
+ }
1120
+
1121
+ # 存活变异体详情
1122
+ survived_details = [
1123
+ {
1124
+ "mutant_id": r.mutant_id,
1125
+ "operator": r.operator,
1126
+ "lineno": r.lineno,
1127
+ "description": r.description,
1128
+ }
1129
+ for r in results
1130
+ if r.status == "SURVIVED"
1131
+ ]
1132
+
1133
+ # 智能诊断建议
1134
+ recommendations = cls._generate_recommendations(
1135
+ score, level, operator_scores, survived_details, timeouts=timeouts,
1136
+ )
1137
+
1138
+ return CapabilitySummary(
1139
+ target_path=str(target_path),
1140
+ test_target=test_target,
1141
+ total_mutants=total,
1142
+ killed_mutants=killed,
1143
+ survived_mutants=survived,
1144
+ timeout_mutants=timeouts,
1145
+ mutation_score=score,
1146
+ capability_level=level,
1147
+ operator_scores=operator_scores,
1148
+ survived_mutants_details=survived_details,
1149
+ recommendations=recommendations,
1150
+ execution_time_sec=round(total_time_sec, 2),
1151
+ )
1152
+
1153
+ @staticmethod
1154
+ def _generate_recommendations(
1155
+ score: float,
1156
+ level: str,
1157
+ op_scores: dict[str, dict[str, Any]],
1158
+ survived: list[dict[str, Any]],
1159
+ timeouts: int = 0,
1160
+ ) -> list[str]:
1161
+ recs: list[str] = []
1162
+ if timeouts > 0:
1163
+ recs.append(
1164
+ f"【测量不可靠】{timeouts} 个变异体被超时看门狗终止,不构成有效击杀;"
1165
+ "请提高 --timeout 或缩小被测模块范围,否则击杀率会被系统性低估。"
1166
+ )
1167
+ if level in ("INEFFECTIVE", "WEAK"):
1168
+ recs.append("【高危弱用例警示】测试用例断言严重不足或存在假断言 (Fake Assertion),仅断言非空不足以杀死语义突变。")
1169
+
1170
+ for op, data in op_scores.items():
1171
+ if data["score"] < 60.0 and data["survived"] > 0:
1172
+ if op == OP_ROR:
1173
+ recs.append(f"【强化边界断言】关系比较算子 (ROR) 击杀率偏低 ({data['score']}%),请补充边界条件测试 (如 0, 负数, 极端大值).")
1174
+ elif op == OP_AOR:
1175
+ recs.append(f"【强化计算断言】算术运算符 (AOR) 击杀率偏低 ({data['score']}%),用例需校验具体的运算数值而非仅校验返回值类型.")
1176
+ elif op == OP_BCR:
1177
+ recs.append(f"【强化布尔/零值断言】边界常量 (BCR) 存在存活变异体,请增加对 False/True 与 0 边界特判用例.")
1178
+ elif op == OP_EOR:
1179
+ recs.append(f"【强化返回值与异常检验】EOR 击杀率低 ({data['score']}%),请使用 assertRaises 显式断言预期异常.")
1180
+
1181
+ if survived:
1182
+ lines = sorted({str(s['lineno']) for s in survived[:5]})
1183
+ recs.append(f"优先在以下源码行补充精确断言:第 {', '.join(lines)} 行.")
1184
+
1185
+ if not recs:
1186
+ recs.append("测试用例具备卓越的逻辑杀伤力,有效防范微观缺陷注入。")
1187
+
1188
+ return recs
1189
+
1190
+
1191
+ def to_coverage_intelligence_format(summary: CapabilitySummary) -> dict[str, Any]:
1192
+ """生成兼容 core/coverage_intelligence.py 变异格式的结构化数据。"""
1193
+ locations = [
1194
+ {"line": s["lineno"], "operator": s["operator"], "status": "survived"}
1195
+ for s in summary.survived_mutants_details
1196
+ ]
1197
+ return {
1198
+ "format": "mutation",
1199
+ "files": [
1200
+ {
1201
+ "path": summary.target_path,
1202
+ "killed": summary.killed_mutants,
1203
+ "total": summary.total_mutants,
1204
+ "mutation": summary.mutation_score,
1205
+ "locations": locations,
1206
+ }
1207
+ ]
1208
+ }
1209
+
1210
+
1211
+ def verify_test_capability(
1212
+ target_path: str | Path,
1213
+ test_target: str | Sequence[str],
1214
+ max_mutants: int = 30,
1215
+ timeout_sec: float = 2.0,
1216
+ operators: Sequence[str] | None = None,
1217
+ cwd: str | Path | None = None,
1218
+ ) -> CapabilitySummary:
1219
+ """高层执行入口:变异体生成 -> 基线检查 -> 沙箱执行 -> 综合评估。"""
1220
+ t_start = time.perf_counter()
1221
+ mutator = SemanticMutator(target_path)
1222
+ mutants = mutator.generate_mutants(max_mutants=max_mutants, operators=operators)
1223
+
1224
+ runner = MutationSandboxRunner(
1225
+ target_path=target_path,
1226
+ test_command=test_target,
1227
+ timeout_sec=timeout_sec,
1228
+ cwd=cwd,
1229
+ )
1230
+ # 报告里记录归一化后的 argv,便于复核实际执行入口。
1231
+ display_target = " ".join(runner.test_command)
1232
+
1233
+ # SEC-11:隔离副本由 runner 惰性创建(整个运行只建一次),
1234
+ # 无论成功、基线失败还是异常,都必须在 finally 中销毁。
1235
+ try:
1236
+ # 1. 基线 Golden Check
1237
+ baseline_ok, msg = runner.run_baseline()
1238
+ if not baseline_ok:
1239
+ t_cost = time.perf_counter() - t_start
1240
+ # 基线失败直接评为 INEFFECTIVE 并说明原因
1241
+ return CapabilitySummary(
1242
+ target_path=str(target_path),
1243
+ test_target=display_target,
1244
+ total_mutants=len(mutants),
1245
+ killed_mutants=0,
1246
+ survived_mutants=len(mutants),
1247
+ timeout_mutants=0,
1248
+ mutation_score=0.0,
1249
+ capability_level="INEFFECTIVE",
1250
+ operator_scores={},
1251
+ survived_mutants_details=[],
1252
+ recommendations=[f"【门禁阻断】{msg}"],
1253
+ execution_time_sec=round(t_cost, 2),
1254
+ )
1255
+
1256
+ # 2. 沙箱执行杀伤测试(复用同一份隔离副本)
1257
+ results: list[MutantExecutionResult] = []
1258
+ for mutant in mutants:
1259
+ res = runner.run_mutant(mutant)
1260
+ results.append(res)
1261
+
1262
+ t_cost = time.perf_counter() - t_start
1263
+ return TestCapabilityEvaluator.evaluate(
1264
+ target_path=target_path,
1265
+ test_target=display_target,
1266
+ results=results,
1267
+ total_time_sec=t_cost,
1268
+ )
1269
+ finally:
1270
+ runner.cleanup()
1271
+
1272
+
1273
+ # ---------------------------------------------------------------------------
1274
+ # CLI 入口实现
1275
+ # ---------------------------------------------------------------------------
1276
+
1277
+
1278
+ def build_parser() -> argparse.ArgumentParser:
1279
+ parser = argparse.ArgumentParser(
1280
+ prog="bugx test-verify",
1281
+ description="BugX 测试用例能力动态验证框架 (Mutation Testing Verifier)",
1282
+ )
1283
+ sub = parser.add_subparsers(dest="subcommand", help="子命令")
1284
+
1285
+ # verify 子命令
1286
+ p_verify = sub.add_parser("verify", help="动态验证测试用例对目标代码的变异杀伤能力")
1287
+ p_verify.add_argument("--target", required=True, help="被测源码文件路径 (例如 core/foo.py)")
1288
+ p_verify.add_argument("--test", required=True, help="测试用例模块或路径 (例如 tests/test_foo.py 或 tests.test_foo)")
1289
+ p_verify.add_argument("--max-mutants", type=int, default=30, help="最大变异体数量 (默认 30)")
1290
+ p_verify.add_argument("--timeout", type=float, default=2.0, help="单次变异测试超时秒数 (默认 2.0s)")
1291
+ p_verify.add_argument("--strict", action="store_true", help="严格门禁模式 (击杀率 < 60%% 时非零退出)")
1292
+ p_verify.add_argument("--json", action="store_true", help="输出完整 JSON 结构报告")
1293
+
1294
+ # mutate 子命令 (仅生成预览变异体)
1295
+ p_mut = sub.add_parser("mutate", help="仅生成并预览 AST 变异体")
1296
+ p_mut.add_argument("--target", required=True, help="目标源码路径")
1297
+ p_mut.add_argument("--max-mutants", type=int, default=30, help="最大变异体数量")
1298
+ p_mut.add_argument("--json", action="store_true", help="以 JSON 输出变异体清单")
1299
+
1300
+ return parser
1301
+
1302
+
1303
+ def main(argv: Sequence[str] | None = None) -> int:
1304
+ parser = build_parser()
1305
+ args = parser.parse_args(argv)
1306
+
1307
+ if not args.subcommand or args.subcommand == "verify":
1308
+ target = getattr(args, "target", None)
1309
+ test = getattr(args, "test", None)
1310
+ if not target or not test:
1311
+ parser.print_help()
1312
+ return 1
1313
+
1314
+ summary = verify_test_capability(
1315
+ target_path=target,
1316
+ test_target=test,
1317
+ max_mutants=args.max_mutants,
1318
+ timeout_sec=args.timeout,
1319
+ )
1320
+
1321
+ if args.json:
1322
+ print(json.dumps(summary.to_dict(), indent=2, ensure_ascii=False))
1323
+ else:
1324
+ print("=" * 68)
1325
+ print(" BugX 测试用例能力动态验证报告 (Mutation Capability Report)")
1326
+ print("=" * 68)
1327
+ print(f"被测源码: {summary.target_path}")
1328
+ print(f"测试目标: {summary.test_target}")
1329
+ print(f"变异体数: {summary.total_mutants} 个")
1330
+ print(f"击杀数量: {summary.killed_mutants} 个 (其中超时 {summary.timeout_mutants} 个)")
1331
+ print(f"存活数量: {summary.survived_mutants} 个")
1332
+ print(f"击杀比例: {summary.mutation_score}%")
1333
+ print(f"能力评级: [{summary.capability_level}]")
1334
+ print(f"执行耗时: {summary.execution_time_sec}s")
1335
+ print("-" * 68)
1336
+ print("各变异算子击杀率:")
1337
+ for op, d in summary.operator_scores.items():
1338
+ print(f" - {op:<4} ({d['description']}): {d['killed']}/{d['total']} ({d['score']}%)")
1339
+ print("-" * 68)
1340
+ print("智能加固建议:")
1341
+ for rec in summary.recommendations:
1342
+ print(f" * {rec}")
1343
+ print("=" * 68)
1344
+
1345
+ if args.strict and summary.mutation_score < LEVEL_CAPABLE_THRESHOLD:
1346
+ return 2
1347
+ return 0
1348
+
1349
+ elif args.subcommand == "mutate":
1350
+ mutator = SemanticMutator(args.target)
1351
+ mutants = mutator.generate_mutants(max_mutants=args.max_mutants)
1352
+ if args.json:
1353
+ print(json.dumps([m.to_dict() for m in mutants], indent=2, ensure_ascii=False))
1354
+ else:
1355
+ print(f"成功为 {args.target} 生成 {len(mutants)} 个有效变异体:")
1356
+ for m in mutants:
1357
+ print(f"[{m.operator}] {m.mutant_id} (行 {m.lineno}): {m.description}")
1358
+ return 0
1359
+
1360
+ return 0
1361
+
1362
+
1363
+ if __name__ == "__main__":
1364
+ sys.exit(main())