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,1387 @@
1
+ #!/usr/bin/env python3
2
+ """BugX 挖掘方案与用例全息保证框架 (Mining Quality Framework, DOC-052).
3
+
4
+ 专司对 BugX 漏洞挖掘方案 (Mining Plan / Campaign) 与挖掘用例进行全息质量保证:
5
+ 1. MiningSurfaceExplorer: 全息勘测代码库的可挖掘功能主体 (AST函数、Web路由、CLI分支、临界区、反序列化);
6
+ 2. ThreatModelMatcher: 威胁模型与挖掘技术、Oracle精准对齐;
7
+ 3. MiningPlanAuditor: 四维 (准确/完整/有效/全面) 100 分制量化审计评估与严格门禁;
8
+ 4. MiningPlanHardener: 挖掘方案自动加固 (自动补全隐式入口、健全 DAG 依赖、绑定深度语义 Oracle).
9
+ """
10
+ from __future__ import annotations
11
+ # --- 引擎导入根(直接执行脚本时自举 core.* 命名空间)---
12
+ import sys as _sys
13
+ from pathlib import Path as _Path
14
+
15
+ for _p in _Path(__file__).resolve().parents:
16
+ if (_p / "core" / "bugx.md").is_file():
17
+ if str(_p) not in _sys.path:
18
+ _sys.path.insert(0, str(_p))
19
+ break
20
+ del _p
21
+ import sys
22
+ from pathlib import Path
23
+
24
+
25
+ import argparse
26
+ import ast
27
+ import json
28
+ import os
29
+ import re
30
+ from collections import Counter, defaultdict
31
+ from dataclasses import asdict, dataclass, field
32
+ from typing import Any, Mapping
33
+
34
+ try:
35
+ from core.retrieval.universal_code_matcher import EXT_TO_LANG, UniversalCodeMatcher
36
+ except ImportError:
37
+ try:
38
+ from core.retrieval.universal_code_matcher import EXT_TO_LANG, UniversalCodeMatcher
39
+ except ImportError:
40
+ EXT_TO_LANG = {}
41
+ UniversalCodeMatcher = None
42
+
43
+ SCHEMA_VERSION = 1
44
+
45
+ SUPPORTED_SOURCE_EXTS = {
46
+ ".py",
47
+ ".go",
48
+ ".c", ".h", ".cc", ".cpp", ".cxx", ".hpp",
49
+ ".java", ".kt", ".kts",
50
+ ".rs",
51
+ ".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx",
52
+ ".cs", ".php", ".rb",
53
+ }
54
+
55
+ SKIP_DIRS = {
56
+ ".git", ".bugx", ".venv", "venv", "node_modules", "__pycache__",
57
+ "dist", "build", "target", ".tox", ".mypy_cache", ".pytest_cache",
58
+ "vendor", "Pods", ".gradle", ".idea",
59
+ }
60
+
61
+ # 路由装饰器识别正则与特征
62
+ ROUTE_DECORATOR_PATTERNS = [
63
+ re.compile(r"^(get|post|put|delete|patch|options|head|route|api_route|websocket)$", re.I),
64
+ ]
65
+ CLI_PATTERNS = [
66
+ re.compile(r"\b(argparse|click|typer|fire|docopt|sys\.argv)\b"),
67
+ ]
68
+ DESERIALIZE_PATTERNS = [
69
+ re.compile(r"\b(pickle|yaml|marshal|shelve|json\.loads|JSON\.parse|eval|exec)\b"),
70
+ ]
71
+ CONCURRENCY_PATTERNS = [
72
+ re.compile(r"\b(lock|rlock|semaphore|event|condition|barrier|mutex|threading\.lock|asyncio\.lock)\b", re.I),
73
+ ]
74
+ STATE_TRANSITION_PATTERNS = [
75
+ re.compile(r"\b(state|status|transition|workflow|stage|step|phase)\b", re.I),
76
+ ]
77
+
78
+ # 多语言函数定义提取正则
79
+ GO_FUNC_PATTERN = re.compile(
80
+ r"^\s*func\s+(?:\((?P<recv>[^)]+)\)\s+)?(?P<name>[A-Za-z0-9_]+)\s*\(",
81
+ re.MULTILINE,
82
+ )
83
+ C_CPP_FUNC_PATTERN = re.compile(
84
+ r"^\s*(?:(?:inline|static|virtual|extern|const|unsigned|signed|volatile|void|int|char|bool|float|double|size_t|ssize_t|auto|[A-Za-z0-9_]+)(?:\s*[*&]+|\s+))+\s*(?:(?P<class>[A-Za-z0-9_]+)::)?(?P<name>[A-Za-z0-9_~]+)\s*\([^;{()]*\)\s*(?:const|override|noexcept)?\s*\{",
85
+ re.MULTILINE,
86
+ )
87
+ JAVA_FUNC_PATTERN = re.compile(
88
+ r"^\s*(?:@\w+(?:\([^)]*\))?\s+)*(?:public|protected|private|static|final|abstract|synchronized|native|\s)*\s*(?:[\w<>\[\],?]+)\s+(?P<name>[A-Za-z0-9_]+)\s*\([^;{]*\)\s*(?:throws\s+[\w.,\s]+)?\{",
89
+ re.MULTILINE,
90
+ )
91
+ KOTLIN_FUNC_PATTERN = re.compile(
92
+ r"^\s*(?:@\w+(?:\([^)]*\))?\s+)*(?:suspend\s+|override\s+|private\s+|public\s+|protected\s+|internal\s+)*fun\s+(?:\([^)]+\)\.)?(?P<name>[A-Za-z0-9_]+)\s*\(",
93
+ re.MULTILINE,
94
+ )
95
+ RUST_FUNC_PATTERN = re.compile(
96
+ r"^\s*(?:pub(?:\([^)]+\))?\s+)?(?:async\s+)?(?:unsafe\s+)?fn\s+(?P<name>[A-Za-z0-9_]+)\s*(?:<[^>]*>)?\s*\(",
97
+ re.MULTILINE,
98
+ )
99
+ JS_TS_FUNC_PATTERN = re.compile(
100
+ r"^\s*(?:export\s+)?(?:async\s+)?function\s+(?P<name>[A-Za-z0-9_]+)\s*\(|^\s*(?:export\s+)?(?:const|let|var)\s+(?P<var_name>[A-Za-z0-9_]+)\s*=\s*(?:async\s*)?\([^)]*\)\s*=>",
101
+ re.MULTILINE,
102
+ )
103
+
104
+ # 多语言高危与特征模式
105
+ MEMORY_SAFETY_PATTERNS = [
106
+ re.compile(r"\b(strcpy|strcat|sprintf|vsprintf|gets|scanf|malloc|calloc|realloc|free|memcpy|memmove|memset|unsafe\.Pointer|unsafe\s*\{)\b"),
107
+ ]
108
+ UNIVERSAL_ROUTE_PATTERNS = [
109
+ re.compile(
110
+ r"(?:http\.ResponseWriter|\*http\.Request|\*gin\.Context|echo\.Context|"
111
+ r"\b(?:http\.HandleFunc|r\.(?:GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD|Group)|e\.(?:GET|POST|PUT|DELETE)|router\.(?:HandleFunc|Handle|GET|POST)|"
112
+ r"@(GetMapping|PostMapping|PutMapping|DeleteMapping|RequestMapping|PatchMapping)|"
113
+ r"CROW_ROUTE|ENDPOINT\(|ADD_ROUTE|(?:app|router)\.(?:get|post|put|delete|patch))\b)",
114
+ re.IGNORECASE,
115
+ ),
116
+ ]
117
+ UNIVERSAL_CONCURRENCY_PATTERNS = [
118
+ re.compile(r"\b(sync\.(?:Mutex|RWMutex|WaitGroup|Once|Cond)|atomic\.|select\s*\{|chan\s+[A-Za-z0-9_]+|go\s+(?:func|[A-Za-z0-9_]+)|pthread_mutex|std::mutex|std::lock_guard|std::unique_lock|pthread_create|std::thread|std::atomic|synchronized|ReentrantLock|ConcurrentHashMap|AtomicInteger|AtomicReference|tokio::sync|std::sync::Mutex)\b"),
119
+ ]
120
+ UNIVERSAL_DESERIALIZE_PATTERNS = [
121
+ re.compile(r"\b(json\.Unmarshal|xml\.Unmarshal|gob\.NewDecoder|yaml\.Unmarshal|readObject|ObjectMapper|XMLDecoder|fromXML|protobuf.*ParseFromString|nlohmann::json::parse)\b"),
122
+ ]
123
+ UNIVERSAL_CLI_PATTERNS = [
124
+ re.compile(r"\b(flag\.Parse|cobra\.Command|os\.Args|process\.argv|getopt|getopt_long|argc\s*,\s*argv|CommandLineParser|args\[|clap::|std::env::args)\b"),
125
+ ]
126
+
127
+ # Explicit overrides are intentionally limited to the productized surface
128
+ # languages. Auto-detection still preserves the older regex fallback for the
129
+ # other extensions supported by this module.
130
+ SURFACE_LANGUAGE_ALIASES = {
131
+ "python": "python", "py": "python",
132
+ "javascript": "javascript", "js": "javascript", "jsx": "javascript", "mjs": "javascript", "cjs": "javascript",
133
+ "typescript": "typescript", "ts": "typescript", "tsx": "tsx",
134
+ "javascript/typescript": "javascript/typescript", "js/ts": "javascript/typescript",
135
+ "go": "go",
136
+ "c": "c", "cpp": "cpp", "c++": "cpp", "c/c++": "c/c++", "c-family": "c/c++",
137
+ "java": "java",
138
+ }
139
+ TREE_SITTER_SURFACE_LANGUAGES = {"javascript", "typescript", "tsx", "go", "c", "cpp", "java"}
140
+ TREE_SITTER_CPP_EXTS = {".cc", ".cpp", ".cxx", ".hpp"}
141
+ TREE_SITTER_TS_EXTS = {".ts", ".tsx"}
142
+ TREE_SITTER_NAME_TYPES = {
143
+ "identifier", "type_identifier", "property_identifier", "field_identifier",
144
+ "namespace_identifier", "name",
145
+ }
146
+ TREE_SITTER_TYPE_NODES = {
147
+ "class_declaration": "class", "abstract_class_declaration": "class",
148
+ "interface_declaration": "type", "type_alias_declaration": "type",
149
+ "enum_declaration": "type", "record_declaration": "type",
150
+ "annotation_type_declaration": "type", "type_declaration": "type",
151
+ "class_specifier": "class", "struct_specifier": "type",
152
+ "union_specifier": "type", "enum_specifier": "type",
153
+ }
154
+ TREE_SITTER_FUNCTION_NODES = {
155
+ "function_declaration", "function_definition", "function_item",
156
+ "method_definition", "method_declaration", "constructor_declaration",
157
+ "generator_function_declaration", "function_expression", "arrow_function",
158
+ "variable_declarator",
159
+ }
160
+ TREE_SITTER_MACRO_NODES = {"preproc_def", "preproc_function_def"}
161
+ TREE_SITTER_ROUTE_METHODS = {
162
+ "get", "post", "put", "delete", "patch", "options", "head", "all",
163
+ "route", "websocket", "handle", "handlefunc", "endpoint",
164
+ }
165
+ TREE_SITTER_DANGEROUS_MACRO_PATTERNS = [
166
+ re.compile(r"\b(strcpy|strcat|sprintf|vsprintf|gets|memcpy|memmove|system|popen|exec(?:l|le|lp|v|ve|vp)?)\s*\(", re.I),
167
+ re.compile(r"\b(unsafe|danger|raw_copy|unchecked|no_sanitize)\b", re.I),
168
+ ]
169
+ ROUTE_ENDPOINT_PATTERNS = (
170
+ re.compile(
171
+ r"@(?P<method>GetMapping|PostMapping|PutMapping|DeleteMapping|PatchMapping|RequestMapping)"
172
+ r"\s*\(\s*[\"'](?P<path>[^\"']+)"
173
+ ),
174
+ re.compile(
175
+ r"\b(?:app|router|r|e)\s*\.\s*(?P<method>get|post|put|delete|patch|options|head|route|handle)"
176
+ r"\s*\(\s*[\"'](?P<path>[^\"']+)",
177
+ re.IGNORECASE,
178
+ ),
179
+ re.compile(
180
+ r"\b(?:http\.HandleFunc|router\.HandleFunc|router\.Handle|e\.GET|e\.POST)"
181
+ r"\s*\(\s*[\"'](?P<path>[^\"']+)",
182
+ re.IGNORECASE,
183
+ ),
184
+ re.compile(
185
+ r"\b(?:ADD_ROUTE|ENDPOINT|CROW_ROUTE)\s*\(\s*(?:[^,]+\s*,\s*)?"
186
+ r"[\"'](?P<path>[^\"']+)"
187
+ ),
188
+ re.compile(
189
+ r"@\w+\s*\.\s*(?P<method>get|post|put|delete|patch|route)"
190
+ r"\s*\(\s*[\"'](?P<path>[^\"']+)"
191
+ ),
192
+ )
193
+
194
+
195
+ @dataclass
196
+ class MineableSubject:
197
+ """可挖掘功能主体结构化表示。"""
198
+ scope: str
199
+ path: str
200
+ name: str
201
+ kind: str # function, method, http_route, cli_command, critical_section, state_transition, deserialization
202
+ start_line: int
203
+ end_line: int
204
+ threat_models: list[str] = field(default_factory=list)
205
+ recommended_techniques: list[str] = field(default_factory=list)
206
+ oracle_types: list[str] = field(default_factory=list)
207
+ risk_level: str = "MEDIUM" # CRITICAL, HIGH, MEDIUM, LOW
208
+ metadata: dict[str, Any] = field(default_factory=dict)
209
+
210
+ def to_dict(self) -> dict[str, Any]:
211
+ return asdict(self)
212
+
213
+
214
+ class MiningSurfaceExplorer:
215
+ """全息勘测代码库的可挖掘功能主体。"""
216
+
217
+ def __init__(self, root: Path, language: str | None = None) -> None:
218
+ self.root = root.resolve()
219
+ self.language = self._normalize_language(language)
220
+ # Partial discovery is useful, but callers must be able to tell when
221
+ # a file or an enrichment source was skipped.
222
+ self.errors: list[str] = []
223
+
224
+ @staticmethod
225
+ def _normalize_language(language: str | None) -> str | None:
226
+ if language is None:
227
+ return None
228
+ key = str(language).strip().lower()
229
+ normalized = SURFACE_LANGUAGE_ALIASES.get(key)
230
+ if normalized is None:
231
+ supported = ", ".join(sorted(set(SURFACE_LANGUAGE_ALIASES.values())))
232
+ raise ValueError(f"不支持的扫描语言 {language!r};可选值: {supported}")
233
+ return normalized
234
+
235
+ def _language_for_path(self, filepath: Path) -> str | None:
236
+ override = self.language
237
+ suffix = filepath.suffix.lower()
238
+ if override == "javascript/typescript":
239
+ return "typescript" if suffix in TREE_SITTER_TS_EXTS else "javascript"
240
+ if override == "c/c++":
241
+ return "cpp" if suffix in TREE_SITTER_CPP_EXTS else "c"
242
+ if override:
243
+ return override
244
+ return EXT_TO_LANG.get(suffix)
245
+
246
+ def _record_error(self, context: str, exc: Exception) -> None:
247
+ if len(self.errors) >= 32:
248
+ return
249
+ detail = str(exc).strip().replace("\n", " ")[:160]
250
+ suffix = f": {detail}" if detail else ""
251
+ self.errors.append(f"{context}: {type(exc).__name__}{suffix}")
252
+
253
+ def explore(self, subpath: str | None = None) -> list[MineableSubject]:
254
+ self.errors.clear()
255
+ subjects: list[MineableSubject] = []
256
+ target_dir = (self.root / subpath) if subpath else self.root
257
+ if not target_dir.exists():
258
+ return subjects
259
+
260
+ source_files: list[Path] = []
261
+ if target_dir.is_file():
262
+ if target_dir.suffix.lower() in SUPPORTED_SOURCE_EXTS:
263
+ source_files = [target_dir]
264
+ elif target_dir.is_dir():
265
+ for p in target_dir.rglob("*"):
266
+ if not p.is_file():
267
+ continue
268
+ if p.suffix.lower() not in SUPPORTED_SOURCE_EXTS:
269
+ continue
270
+ rel_parts = p.relative_to(self.root).parts
271
+ if any(part in SKIP_DIRS or part.startswith((".", "venv", "__pycache__", "build", "dist", "node_modules", "target", "vendor")) for part in rel_parts):
272
+ continue
273
+ source_files.append(p)
274
+
275
+ for src_path in source_files:
276
+ rel_path = str(src_path.relative_to(self.root)).replace("\\", "/")
277
+ try:
278
+ content = src_path.read_text(encoding="utf-8", errors="replace")
279
+ language = self._language_for_path(src_path)
280
+ if language == "python":
281
+ try:
282
+ tree = ast.parse(content, filename=str(src_path))
283
+ subjects.extend(self._scan_ast(tree, rel_path, content))
284
+ except Exception as ast_exc:
285
+ self._record_error(f"scan {rel_path}", ast_exc)
286
+ subjects.extend(self._scan_universal(src_path, rel_path, content, language=language))
287
+ else:
288
+ subjects.extend(self._scan_universal(src_path, rel_path, content, language=language))
289
+ except Exception as exc:
290
+ self._record_error(f"scan {rel_path}", exc)
291
+ continue
292
+
293
+
294
+ # 融合架构拓扑循环依赖脆弱靶点 (DOC-060)
295
+ try:
296
+
297
+ profile_path = self.root / ".bugx" / "knowledge" / "project-profile.json"
298
+ if profile_path.is_file():
299
+ import json
300
+ pdata = json.loads(profile_path.read_text(encoding="utf-8"))
301
+ topo = pdata.get("architecture_topology") or {}
302
+ cycles = topo.get("cycles") or topo.get("circular_dependency_cycles") or []
303
+ seen_mods: set[str] = set()
304
+ for cycle in cycles:
305
+ for mod_file in cycle:
306
+ mod_str = str(mod_file).replace("\\", "/")
307
+ if mod_str in seen_mods:
308
+ continue
309
+ seen_mods.add(mod_str)
310
+ if subpath and not mod_str.startswith(subpath):
311
+ continue
312
+ subjects.append(MineableSubject(
313
+ scope=f"{mod_str}::circular_dependency",
314
+ path=mod_str,
315
+ name="circular_dependency_hazard",
316
+ kind="circular_dependency",
317
+ start_line=1,
318
+ end_line=1,
319
+ threat_models=["reentrancy_deadlock", "state_corruption"],
320
+ recommended_techniques=["concurrency-race", "state-machine"],
321
+ oracle_types=["concurrency_barrier", "transition_invariant"],
322
+ risk_level="HIGH",
323
+ ))
324
+ except Exception as exc:
325
+ self._record_error("load architecture topology", exc)
326
+
327
+ # 排序:CRITICAL > HIGH > MEDIUM > LOW,同级按路径+行号
328
+ risk_order = {"CRITICAL": 0, "HIGH": 1, "MEDIUM": 2, "LOW": 3}
329
+ subjects.sort(key=lambda s: (risk_order.get(s.risk_level, 4), s.path, s.start_line))
330
+ return subjects
331
+
332
+
333
+ def _scan_ast(self, tree: ast.AST, rel_path: str, content: str) -> list[MineableSubject]:
334
+ found: list[MineableSubject] = []
335
+ lines = content.splitlines()
336
+
337
+ class SurfaceVisitor(ast.NodeVisitor):
338
+ def __init__(self, explorer: MiningSurfaceExplorer) -> None:
339
+ self.explorer = explorer
340
+ self.current_class: str | None = None
341
+
342
+ def visit_ClassDef(self, node: ast.ClassDef) -> None:
343
+ prev = self.current_class
344
+ self.current_class = node.name
345
+ found.append(MineableSubject(
346
+ scope=f"{rel_path}::{node.name}",
347
+ path=rel_path,
348
+ name=node.name,
349
+ kind="class",
350
+ start_line=getattr(node, "lineno", 1),
351
+ end_line=getattr(node, "end_lineno", getattr(node, "lineno", 1)),
352
+ threat_models=["boundary", "negative-control"],
353
+ recommended_techniques=["boundary", "negative-control"],
354
+ oracle_types=["invariant", "contract"],
355
+ risk_level="LOW",
356
+ metadata={"language": "python", "parser": "python-ast", "node_type": "ClassDef"},
357
+ ))
358
+ self.generic_visit(node)
359
+ self.current_class = prev
360
+
361
+ def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
362
+ self._analyze_func(node)
363
+ self.generic_visit(node)
364
+
365
+ def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) -> None:
366
+ self._analyze_func(node)
367
+ self.generic_visit(node)
368
+
369
+ def _analyze_func(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:
370
+ scope_prefix = f"{self.current_class}." if self.current_class else ""
371
+ scope = f"{rel_path}::{scope_prefix}{node.name}"
372
+ start_l = getattr(node, "lineno", 1)
373
+ end_l = getattr(node, "end_lineno", start_l)
374
+ func_snippet = "\n".join(lines[max(0, start_l - 1):end_l])
375
+
376
+ kind = "method" if self.current_class else "function"
377
+ threats: list[str] = ["boundary", "negative-control"]
378
+ techniques: list[str] = ["boundary", "negative-control"]
379
+ oracles: list[str] = ["invariant", "contract"]
380
+ risk = "LOW"
381
+
382
+ # 1. 检测 Web 路由装饰器
383
+ is_route = False
384
+ route_method = "GET"
385
+ route_path = ""
386
+ for dec in node.decorator_list:
387
+ dec_call = dec if isinstance(dec, ast.Call) else None
388
+ dec_func = dec_call.func if dec_call else dec
389
+ dec_name = ""
390
+ if isinstance(dec_func, ast.Attribute):
391
+ dec_name = dec_func.attr
392
+ elif isinstance(dec_func, ast.Name):
393
+ dec_name = dec_func.id
394
+
395
+ for pat in ROUTE_DECORATOR_PATTERNS:
396
+ if pat.match(dec_name):
397
+ is_route = True
398
+ route_method = dec_name.upper()
399
+ if dec_call and dec_call.args and isinstance(dec_call.args[0], ast.Constant):
400
+ route_path = str(dec_call.args[0].value)
401
+ break
402
+ if is_route:
403
+ break
404
+
405
+ if is_route:
406
+ kind = "http_route"
407
+ threats.extend(["auth_bypass", "input_injection", "idor"])
408
+ techniques.extend(["property-based", "guided-fuzz", "contract-differential"])
409
+ oracles.extend(["status_code", "schema_validation"])
410
+ risk = "CRITICAL" if any(kw in route_path.lower() for kw in ("admin", "auth", "user", "order", "pay", "token")) else "HIGH"
411
+
412
+ # 2. 检测 CLI 解析入口
413
+ if any(pat.search(func_snippet) for pat in CLI_PATTERNS):
414
+ kind = "cli_command"
415
+ threats.extend(["argument_injection", "flag_abuse", "path_traversal"])
416
+ techniques.extend(["guided-fuzz", "boundary"])
417
+ risk = "HIGH" if risk != "CRITICAL" else risk
418
+
419
+ # 3. 检测反序列化高危汇聚点
420
+ if any(pat.search(func_snippet) for pat in DESERIALIZE_PATTERNS):
421
+ kind = "deserialization" if not is_route else kind
422
+ threats.extend(["rce", "type_confusion", "resource_exhaustion"])
423
+ techniques.extend(["fault-injection", "guided-fuzz"])
424
+ oracles.extend(["memory_safety", "sandbox_integrity"])
425
+ risk = "CRITICAL"
426
+
427
+ # 4. 检测并发临界区
428
+ if any(pat.search(func_snippet) for pat in CONCURRENCY_PATTERNS):
429
+ if kind in ("function", "method"):
430
+ kind = "critical_section"
431
+ threats.extend(["race_condition", "deadlock", "lost_update"])
432
+ techniques.extend(["concurrency-race"])
433
+ oracles.append("concurrency_barrier")
434
+ if risk == "LOW":
435
+ risk = "MEDIUM"
436
+
437
+ # 5. 检测状态迁移
438
+ if any(pat.search(func_snippet) for pat in STATE_TRANSITION_PATTERNS):
439
+ threats.extend(["state_machine_bypass", "illegal_transition"])
440
+ techniques.extend(["state-machine"])
441
+ oracles.append("transition_invariant")
442
+ if risk == "LOW":
443
+ risk = "MEDIUM"
444
+
445
+ found.append(MineableSubject(
446
+ scope=scope,
447
+ path=rel_path,
448
+ name=node.name,
449
+ kind=kind,
450
+ start_line=start_l,
451
+ end_line=end_l,
452
+ threat_models=sorted(set(threats)),
453
+ recommended_techniques=sorted(set(techniques)),
454
+ oracle_types=sorted(set(oracles)),
455
+ risk_level=risk,
456
+ metadata={
457
+ "language": "python",
458
+ "parser": "python-ast",
459
+ **({"endpoint": route_path, "method": route_method} if is_route else {}),
460
+ },
461
+ ))
462
+
463
+ visitor = SurfaceVisitor(self)
464
+ visitor.visit(tree)
465
+ found.extend(self._route_subjects(rel_path, content, "python"))
466
+
467
+ # 融合代码分析引擎的深度污点流分析 (Taint Flow) 与高熵机密 (DOC-060)
468
+ try:
469
+ from core.retrieval import code_analyzer
470
+
471
+ ast_metrics = code_analyzer._analyze_python_ast(content)
472
+ taints = ast_metrics.get("taint_flows") or []
473
+ for t in taints[:5]: # 每个文件最多取前 5 处关键污点流
474
+ func_name = str(t.get("func") or "unknown")
475
+ sink = str(t.get("sink") or "sensitive_sink")
476
+ line_no = int(t.get("line") or 1)
477
+ found.append(MineableSubject(
478
+ scope=f"{rel_path}::{func_name}",
479
+ path=rel_path,
480
+ name=f"{func_name}_taint_{sink}",
481
+ kind="taint_sink",
482
+ start_line=line_no,
483
+ end_line=line_no,
484
+ threat_models=["command_injection", "rce", "sql_injection", "unsafe_deserialization"],
485
+ recommended_techniques=["guided-fuzz", "fault-injection"],
486
+ oracle_types=["invariant", "contract", "exit_code"],
487
+ risk_level="CRITICAL",
488
+ ))
489
+
490
+ secrets = code_analyzer.scan_high_entropy_secrets(content)
491
+ for sec in secrets[:3]: # 每个文件最多取前 3 处高熵机密
492
+ var_name = str(sec.get("var") or "secret")
493
+ line_no = int(sec.get("line") or 1)
494
+ found.append(MineableSubject(
495
+ scope=f"{rel_path}::{var_name}",
496
+ path=rel_path,
497
+ name=f"secret_{var_name}",
498
+ kind="hardcoded_secret",
499
+ start_line=line_no,
500
+ end_line=line_no,
501
+ threat_models=["credential_leak", "unauthorized_access"],
502
+ recommended_techniques=["boundary"],
503
+ oracle_types=["invariant"],
504
+ risk_level="HIGH",
505
+ ))
506
+ except Exception as exc:
507
+ self._record_error(f"deep analysis {rel_path}", exc)
508
+
509
+ return found
510
+
511
+ @staticmethod
512
+ def _tree_node_name(node: object) -> str | None:
513
+ direct = node.child_by_field_name("name")
514
+ if direct is not None:
515
+ return direct.text.decode("utf-8", errors="replace")
516
+ declarator = node.child_by_field_name("declarator")
517
+ queue = [declarator] if declarator is not None else list(node.named_children[:6])
518
+ while queue:
519
+ current = queue.pop(0)
520
+ if current.type in TREE_SITTER_NAME_TYPES:
521
+ return current.text.decode("utf-8", errors="replace")
522
+ queue[0:0] = list(current.named_children[:6])
523
+ return None
524
+
525
+ @staticmethod
526
+ def _tree_node_text(node: object, source_bytes: bytes) -> str:
527
+ return source_bytes[node.start_byte:node.end_byte].decode("utf-8", errors="replace")
528
+
529
+ def _classify_tree_surface(
530
+ self,
531
+ base_kind: str,
532
+ snippet: str,
533
+ language: str,
534
+ *,
535
+ endpoint: str | None = None,
536
+ method: str | None = None,
537
+ ) -> tuple[str, list[str], list[str], list[str], str, dict[str, Any]]:
538
+ kind = base_kind
539
+ threats: list[str] = ["boundary", "negative-control"]
540
+ techniques: list[str] = ["boundary", "negative-control"]
541
+ oracles: list[str] = ["invariant", "contract"]
542
+ risk = "LOW"
543
+ metadata: dict[str, Any] = {
544
+ "language": language,
545
+ "parser": f"tree-sitter-{language}",
546
+ }
547
+ if endpoint:
548
+ metadata.update({"endpoint": endpoint, "method": method or "GET"})
549
+
550
+ if base_kind in {"class", "type"}:
551
+ return kind, threats, techniques, oracles, risk, metadata
552
+
553
+ if language in {"c", "cpp", "go"} and any(
554
+ pattern.search(snippet) for pattern in MEMORY_SAFETY_PATTERNS
555
+ ):
556
+ kind = "memory_safety"
557
+ threats.extend(["buffer_overflow", "heap_corruption", "use_after_free", "out_of_bounds_write"])
558
+ techniques.extend(["guided-fuzz", "boundary", "fault-injection"])
559
+ oracles.extend(["memory_safety", "asan_crash", "crash_signal"])
560
+ risk = "CRITICAL"
561
+
562
+ route_call = bool(re.search(
563
+ r"(?:http\.HandleFunc|router\.(?:HandleFunc|Handle|GET|POST|PUT|DELETE|PATCH)|"
564
+ r"r\.(?:GET|POST|PUT|DELETE|PATCH)|e\.(?:GET|POST|PUT|DELETE|PATCH)|"
565
+ r"(?:app|router)\.(?:get|post|put|delete|patch)|@(?:GetMapping|PostMapping|PutMapping|DeleteMapping|RequestMapping|PatchMapping)|"
566
+ r"CROW_ROUTE|ENDPOINT\(|ADD_ROUTE)",
567
+ snippet,
568
+ re.IGNORECASE,
569
+ ))
570
+ http_handler_signature = bool(re.search(r"http\.ResponseWriter|\*http\.Request|\*gin\.Context|echo\.Context", snippet))
571
+ if endpoint or route_call:
572
+ kind = "http_route"
573
+ threats.extend(["auth_bypass", "input_injection", "idor"])
574
+ techniques.extend(["property-based", "guided-fuzz", "contract-differential"])
575
+ oracles.extend(["status_code", "schema_validation"])
576
+ risk = "CRITICAL" if any(
577
+ word in (endpoint or snippet).lower()
578
+ for word in ("admin", "auth", "user", "order", "pay", "token")
579
+ ) else "HIGH"
580
+ elif http_handler_signature:
581
+ # A Go/HTTP handler is an attack surface even when its declaration
582
+ # has no literal route call; keep the callable kind for planning.
583
+ threats.extend(["auth_bypass", "input_injection", "idor"])
584
+ techniques.extend(["property-based", "guided-fuzz", "contract-differential"])
585
+ oracles.extend(["status_code", "schema_validation"])
586
+ risk = "CRITICAL" if any(
587
+ word in snippet.lower() for word in ("admin", "auth", "user", "order", "pay", "token")
588
+ ) else "HIGH"
589
+
590
+ if any(pattern.search(snippet) for pattern in UNIVERSAL_CLI_PATTERNS):
591
+ if kind in {"function", "method"}:
592
+ kind = "cli_command"
593
+ threats.extend(["argument_injection", "flag_abuse", "path_traversal"])
594
+ techniques.extend(["guided-fuzz", "boundary"])
595
+ if risk != "CRITICAL":
596
+ risk = "HIGH"
597
+
598
+ if any(pattern.search(snippet) for pattern in UNIVERSAL_DESERIALIZE_PATTERNS) or any(
599
+ pattern.search(snippet) for pattern in DESERIALIZE_PATTERNS
600
+ ):
601
+ if kind not in {"http_route", "memory_safety"}:
602
+ kind = "deserialization"
603
+ threats.extend(["rce", "type_confusion", "resource_exhaustion"])
604
+ techniques.extend(["fault-injection", "guided-fuzz"])
605
+ oracles.extend(["memory_safety", "sandbox_integrity"])
606
+ risk = "CRITICAL"
607
+
608
+ if any(pattern.search(snippet) for pattern in UNIVERSAL_CONCURRENCY_PATTERNS) or any(pattern.search(snippet) for pattern in CONCURRENCY_PATTERNS):
609
+ if kind in {"function", "method"}:
610
+ kind = "critical_section"
611
+ threats.extend(["race_condition", "deadlock", "lost_update"])
612
+ techniques.append("concurrency-race")
613
+ oracles.append("concurrency_barrier")
614
+ if risk == "LOW":
615
+ risk = "MEDIUM"
616
+
617
+ if any(pattern.search(snippet) for pattern in STATE_TRANSITION_PATTERNS):
618
+ threats.extend(["state_machine_bypass", "illegal_transition"])
619
+ techniques.append("state-machine")
620
+ oracles.append("transition_invariant")
621
+ if risk == "LOW":
622
+ risk = "MEDIUM"
623
+
624
+ return kind, threats, techniques, oracles, risk, metadata
625
+
626
+ def _route_subjects(self, rel_path: str, content: str, language: str) -> list[MineableSubject]:
627
+ found: list[MineableSubject] = []
628
+ seen: set[tuple[str, int]] = set()
629
+ for pattern in ROUTE_ENDPOINT_PATTERNS:
630
+ for match in pattern.finditer(content):
631
+ endpoint = match.groupdict().get("path")
632
+ if not endpoint:
633
+ continue
634
+ line = content[:match.start()].count("\n") + 1
635
+ method = (match.groupdict().get("method") or "GET").upper()
636
+ if method.endswith("MAPPING"):
637
+ method = method.removesuffix("MAPPING") or "GET"
638
+ if method == "REQUEST":
639
+ method = "ANY"
640
+ key = (endpoint, line)
641
+ if key in seen:
642
+ continue
643
+ seen.add(key)
644
+ kind, threats, techniques, oracles, risk, metadata = self._classify_tree_surface(
645
+ "http_route", endpoint, language, endpoint=endpoint, method=method,
646
+ )
647
+ found.append(MineableSubject(
648
+ scope=f"{rel_path}::route:{method} {endpoint}",
649
+ path=rel_path,
650
+ name=f"{method} {endpoint}",
651
+ kind=kind,
652
+ start_line=line,
653
+ end_line=line,
654
+ threat_models=sorted(set(threats)),
655
+ recommended_techniques=sorted(set(techniques)),
656
+ oracle_types=sorted(set(oracles)),
657
+ risk_level=risk,
658
+ metadata=metadata,
659
+ ))
660
+ return found
661
+
662
+ def _scan_tree_sitter(
663
+ self, filepath: Path, rel_path: str, content: str, language: str,
664
+ ) -> list[MineableSubject]:
665
+ from tree_sitter_language_pack import get_parser
666
+
667
+ tree = get_parser(language).parse(content.encode("utf-8"))
668
+ source_bytes = content.encode("utf-8")
669
+ found: list[MineableSubject] = []
670
+
671
+ def append_node(node: object, parents: list[str], base_kind: str, name: str) -> list[str]:
672
+ snippet = self._tree_node_text(node, source_bytes)
673
+ node_kind = node.type
674
+ if base_kind == "macro":
675
+ dangerous = any(pattern.search(snippet) for pattern in TREE_SITTER_DANGEROUS_MACRO_PATTERNS)
676
+ if not dangerous:
677
+ return parents
678
+ threats = ["unsafe_macro"]
679
+ techniques = ["guided-fuzz", "boundary", "fault-injection"]
680
+ oracles = ["invariant", "memory_safety"]
681
+ if re.search(r"\b(strcpy|strcat|sprintf|vsprintf|gets|memcpy|memmove)\s*\(", snippet, re.I):
682
+ threats.extend(["buffer_overflow", "out_of_bounds_write"])
683
+ if re.search(r"\b(system|popen|exec(?:l|le|lp|v|ve|vp)?)\s*\(", snippet, re.I):
684
+ threats.extend(["command_injection", "rce"])
685
+ found.append(MineableSubject(
686
+ scope=f"{rel_path}::{name}",
687
+ path=rel_path,
688
+ name=name,
689
+ kind="dangerous_macro",
690
+ start_line=node.start_point[0] + 1,
691
+ end_line=node.end_point[0] + 1,
692
+ threat_models=sorted(set(threats)),
693
+ recommended_techniques=techniques,
694
+ oracle_types=oracles,
695
+ risk_level="CRITICAL",
696
+ metadata={
697
+ "language": language,
698
+ "parser": f"tree-sitter-{language}",
699
+ "node_type": node_kind,
700
+ },
701
+ ))
702
+ return parents
703
+
704
+ kind, threats, techniques, oracles, risk, metadata = self._classify_tree_surface(
705
+ base_kind, snippet, language,
706
+ )
707
+ metadata["node_type"] = node_kind
708
+ found.append(MineableSubject(
709
+ scope=f"{rel_path}::{'.'.join([*parents, name])}",
710
+ path=rel_path,
711
+ name=name,
712
+ kind=kind,
713
+ start_line=node.start_point[0] + 1,
714
+ end_line=node.end_point[0] + 1,
715
+ threat_models=sorted(set(threats)),
716
+ recommended_techniques=sorted(set(techniques)),
717
+ oracle_types=sorted(set(oracles)),
718
+ risk_level=risk,
719
+ metadata=metadata,
720
+ ))
721
+ return [*parents, name]
722
+
723
+ def walk(node: object, parents: list[str]) -> None:
724
+ node_type = node.type
725
+ if node_type in TREE_SITTER_MACRO_NODES:
726
+ name = self._tree_node_name(node)
727
+ if name:
728
+ append_node(node, parents, "macro", name)
729
+ elif node_type in TREE_SITTER_TYPE_NODES:
730
+ name = self._tree_node_name(node)
731
+ if name:
732
+ parents = append_node(node, parents, TREE_SITTER_TYPE_NODES[node_type], name)
733
+ elif node_type in TREE_SITTER_FUNCTION_NODES:
734
+ is_arrow_declaration = node_type == "variable_declarator" and any(
735
+ child.type in {"arrow_function", "function_expression"}
736
+ for child in node.named_children
737
+ )
738
+ if node_type != "variable_declarator" or is_arrow_declaration:
739
+ name = self._tree_node_name(node)
740
+ if name:
741
+ base_kind = "method" if node_type in {
742
+ "method_definition", "method_declaration", "constructor_declaration",
743
+ } or parents else "function"
744
+ parents = append_node(node, parents, base_kind, name)
745
+ for child in node.named_children:
746
+ walk(child, parents)
747
+
748
+ walk(tree.root_node, [])
749
+ found.extend(self._route_subjects(rel_path, content, language))
750
+ if tree.root_node.has_error:
751
+ self._record_error(
752
+ f"tree-sitter parse {rel_path}",
753
+ ValueError(f"{language} syntax tree contains ERROR nodes"),
754
+ )
755
+ return found
756
+
757
+ def _append_universal_taint(
758
+ self, found: list[MineableSubject], filepath: Path, rel_path: str,
759
+ content: str, language: str | None,
760
+ ) -> list[MineableSubject]:
761
+ if not UniversalCodeMatcher:
762
+ return found
763
+ try:
764
+ matcher = UniversalCodeMatcher(language=language or UniversalCodeMatcher.detect_language(filepath))
765
+ parsed = matcher.parse_content(content, filepath, rel_path)
766
+ for call in parsed.calls[:5]:
767
+ if call.is_tainted:
768
+ found.append(MineableSubject(
769
+ scope=f"{rel_path}::{call.enclosing_function or call.callee}",
770
+ path=rel_path,
771
+ name=f"{call.method_name}_taint_sink",
772
+ kind="taint_sink",
773
+ start_line=call.span.line,
774
+ end_line=call.span.end_line or call.span.line,
775
+ threat_models=["command_injection", "rce", "sql_injection", "unsafe_deserialization"],
776
+ recommended_techniques=["guided-fuzz", "fault-injection"],
777
+ oracle_types=["invariant", "contract", "exit_code"],
778
+ risk_level="CRITICAL",
779
+ metadata={"language": language or parsed.language, "parser": "universal-code-matcher"},
780
+ ))
781
+ except Exception as exc:
782
+ self._record_error(f"universal parse {rel_path}", exc)
783
+ return found
784
+
785
+ def _scan_universal(
786
+ self, filepath: Path, rel_path: str, content: str, *, language: str | None = None,
787
+ ) -> list[MineableSubject]:
788
+ language = language or self._language_for_path(filepath)
789
+ if language in TREE_SITTER_SURFACE_LANGUAGES:
790
+ try:
791
+ found = self._scan_tree_sitter(filepath, rel_path, content, language)
792
+ if found:
793
+ return self._append_universal_taint(found, filepath, rel_path, content, language)
794
+ except Exception as exc:
795
+ self._record_error(f"tree-sitter scan {rel_path}", exc)
796
+
797
+ found: list[MineableSubject] = []
798
+ lines = content.splitlines()
799
+ if not lines:
800
+ return found
801
+
802
+ ext = filepath.suffix.lower()
803
+
804
+ parsed = None
805
+ if UniversalCodeMatcher:
806
+ try:
807
+ parsed = UniversalCodeMatcher.parse_file(filepath, rel_path=rel_path, content=content)
808
+ except Exception as exc:
809
+ self._record_error(f"universal parse {rel_path}", exc)
810
+
811
+ func_headers: list[tuple[str, str, int]] = []
812
+ if ext == ".go":
813
+ for m in GO_FUNC_PATTERN.finditer(content):
814
+ fn_name = m.group("name")
815
+ recv = m.group("recv")
816
+ start_l = content[:m.start()].count("\n") + 1
817
+ scope_prefix = ""
818
+ if recv:
819
+ recv_clean = re.sub(r"[*&]", "", recv).strip().split()
820
+ if recv_clean:
821
+ scope_prefix = f"{recv_clean[-1]}."
822
+ func_headers.append((fn_name, scope_prefix, start_l))
823
+ elif ext in (".c", ".h", ".cc", ".cpp", ".cxx", ".hpp"):
824
+ for m in C_CPP_FUNC_PATTERN.finditer(content):
825
+ fn_name = m.group("name")
826
+ cls_name = m.group("class")
827
+ start_l = content[:m.start()].count("\n") + 1
828
+ scope_prefix = f"{cls_name}." if cls_name else ""
829
+ func_headers.append((fn_name, scope_prefix, start_l))
830
+ elif ext in (".java", ".cs"):
831
+ for m in JAVA_FUNC_PATTERN.finditer(content):
832
+ fn_name = m.group("name")
833
+ start_l = content[:m.start()].count("\n") + 1
834
+ func_headers.append((fn_name, "", start_l))
835
+ elif ext in (".kt", ".kts"):
836
+ for m in KOTLIN_FUNC_PATTERN.finditer(content):
837
+ fn_name = m.group("name")
838
+ start_l = content[:m.start()].count("\n") + 1
839
+ func_headers.append((fn_name, "", start_l))
840
+ elif ext == ".rs":
841
+ for m in RUST_FUNC_PATTERN.finditer(content):
842
+ fn_name = m.group("name")
843
+ start_l = content[:m.start()].count("\n") + 1
844
+ func_headers.append((fn_name, "", start_l))
845
+ elif ext in (".js", ".jsx", ".mjs", ".ts", ".tsx"):
846
+ for m in JS_TS_FUNC_PATTERN.finditer(content):
847
+ fn_name = m.group("name") or m.group("var_name") or "anonymous"
848
+ start_l = content[:m.start()].count("\n") + 1
849
+ func_headers.append((fn_name, "", start_l))
850
+
851
+ if not func_headers:
852
+ func_headers.append((filepath.stem, "", 1))
853
+
854
+ func_headers.sort(key=lambda x: x[2])
855
+ for idx, (fn_name, scope_prefix, start_l) in enumerate(func_headers):
856
+ scope = f"{rel_path}::{scope_prefix}{fn_name}"
857
+ next_start = func_headers[idx + 1][2] if idx + 1 < len(func_headers) else len(lines) + 1
858
+
859
+ end_l = start_l
860
+ depth = 0
861
+ seen_open = False
862
+ for line_idx in range(start_l - 1, min(len(lines), next_start - 1)):
863
+ line = lines[line_idx]
864
+ opens = line.count("{")
865
+ closes = line.count("}")
866
+ depth += opens - closes
867
+ if opens > 0:
868
+ seen_open = True
869
+ if seen_open and depth <= 0:
870
+ end_l = line_idx + 1
871
+ break
872
+ else:
873
+ end_l = max(start_l, next_start - 1)
874
+
875
+ func_snippet = "\n".join(lines[max(0, start_l - 1):end_l])
876
+
877
+ kind = "method" if scope_prefix else "function"
878
+ threats: list[str] = ["boundary", "negative-control"]
879
+ techniques: list[str] = ["boundary", "negative-control"]
880
+ oracles: list[str] = ["invariant", "contract"]
881
+ risk = "LOW"
882
+
883
+ # 1. 内存安全检测 (C/C++, unsafe Rust/Go)
884
+ if ext in (".c", ".h", ".cc", ".cpp", ".cxx", ".hpp", ".rs", ".go"):
885
+ if any(pat.search(func_snippet) for pat in MEMORY_SAFETY_PATTERNS):
886
+ kind = "memory_safety"
887
+ threats.extend(["buffer_overflow", "heap_corruption", "use_after_free", "out_of_bounds_write"])
888
+ techniques.extend(["guided-fuzz", "boundary", "fault-injection"])
889
+ oracles.extend(["memory_safety", "asan_crash", "crash_signal"])
890
+ risk = "CRITICAL"
891
+
892
+ # 2. Web 路由检测
893
+ if any(pat.search(func_snippet) for pat in UNIVERSAL_ROUTE_PATTERNS):
894
+ kind = "http_route"
895
+ threats.extend(["auth_bypass", "input_injection", "idor"])
896
+ techniques.extend(["property-based", "guided-fuzz", "contract-differential"])
897
+ oracles.extend(["status_code", "schema_validation"])
898
+ risk = "CRITICAL" if any(kw in func_snippet.lower() for kw in ("admin", "auth", "user", "order", "pay", "token")) else "HIGH"
899
+
900
+ # 3. CLI 入口检测
901
+ if any(pat.search(func_snippet) for pat in UNIVERSAL_CLI_PATTERNS) or any(pat.search(func_snippet) for pat in CLI_PATTERNS):
902
+ if kind in ("function", "method"):
903
+ kind = "cli_command"
904
+ threats.extend(["argument_injection", "flag_abuse", "path_traversal"])
905
+ techniques.extend(["guided-fuzz", "boundary"])
906
+ if risk != "CRITICAL":
907
+ risk = "HIGH"
908
+
909
+ # 4. 反序列化汇聚点
910
+ if any(pat.search(func_snippet) for pat in UNIVERSAL_DESERIALIZE_PATTERNS) or any(pat.search(func_snippet) for pat in DESERIALIZE_PATTERNS):
911
+ if kind not in ("http_route", "memory_safety"):
912
+ kind = "deserialization"
913
+ threats.extend(["rce", "type_confusion", "resource_exhaustion"])
914
+ techniques.extend(["fault-injection", "guided-fuzz"])
915
+ oracles.extend(["memory_safety", "sandbox_integrity"])
916
+ risk = "CRITICAL"
917
+
918
+ # 5. 并发临界区与协程/锁争用
919
+ if any(pat.search(func_snippet) for pat in UNIVERSAL_CONCURRENCY_PATTERNS) or any(pat.search(func_snippet) for pat in CONCURRENCY_PATTERNS):
920
+ if kind in ("function", "method"):
921
+ kind = "critical_section"
922
+ threats.extend(["race_condition", "deadlock", "lost_update"])
923
+ techniques.extend(["concurrency-race"])
924
+ oracles.append("concurrency_barrier")
925
+ if risk == "LOW":
926
+ risk = "MEDIUM"
927
+
928
+ # 6. 状态迁移检测
929
+ if any(pat.search(func_snippet) for pat in STATE_TRANSITION_PATTERNS):
930
+ threats.extend(["state_machine_bypass", "illegal_transition"])
931
+ techniques.append("state-machine")
932
+ oracles.append("transition_invariant")
933
+ if risk == "LOW":
934
+ risk = "MEDIUM"
935
+
936
+ found.append(MineableSubject(
937
+ scope=scope,
938
+ path=rel_path,
939
+ name=fn_name,
940
+ kind=kind,
941
+ start_line=start_l,
942
+ end_line=end_l,
943
+ threat_models=sorted(set(threats)),
944
+ recommended_techniques=sorted(set(techniques)),
945
+ oracle_types=sorted(set(oracles)),
946
+ risk_level=risk,
947
+ ))
948
+
949
+ if parsed and parsed.calls:
950
+ for call in parsed.calls[:5]:
951
+ if call.is_tainted:
952
+ found.append(MineableSubject(
953
+ scope=f"{rel_path}::{call.enclosing_function or call.callee}",
954
+ path=rel_path,
955
+ name=f"{call.method_name}_taint_sink",
956
+ kind="taint_sink",
957
+ start_line=call.span.line,
958
+ end_line=call.span.end_line or call.span.line,
959
+ threat_models=["command_injection", "rce", "sql_injection", "unsafe_deserialization"],
960
+ recommended_techniques=["guided-fuzz", "fault-injection"],
961
+ oracle_types=["invariant", "contract", "exit_code"],
962
+ risk_level="CRITICAL",
963
+ ))
964
+
965
+ return found
966
+
967
+
968
+ class ThreatModelMatcher:
969
+ """威胁模型匹配与挖掘用例合法性验证器。"""
970
+
971
+ @staticmethod
972
+ def validate_command_template(template: str) -> tuple[bool, str]:
973
+ """验证挖掘命令模板合法性(占位符、参数注入、非破坏性)。"""
974
+ if not template or not isinstance(template, str):
975
+ return False, "命令模板不能为空"
976
+ # 阻断直接 rm -rf 危险命令
977
+ if re.search(r"\brm\s+-rf\s+[/~]", template):
978
+ return False, "命令模板包含高危全盘删除指令"
979
+ if "{input}" not in template and "{payload}" not in template and "{target}" not in template:
980
+ return False, "命令模板缺少输入占位符 ({input} / {payload} / {target})"
981
+ return True, "OK"
982
+
983
+ @staticmethod
984
+ def match_techniques_for_threats(threats: list[str]) -> list[dict[str, str]]:
985
+ mapping = {
986
+ "auth_bypass": {"name": "boundary", "oracle": "invariant", "reason": "无凭据与越权身份边界"},
987
+ "input_injection": {"name": "guided-fuzz", "oracle": "contract", "reason": "特殊字符与反常编码注入"},
988
+ "idor": {"name": "metamorphic", "oracle": "invariant", "reason": "对象ID置换与跨租户访问关系"},
989
+ "argument_injection": {"name": "boundary", "oracle": "contract", "reason": "Shell参数逃逸与连字符注入"},
990
+ "flag_abuse": {"name": "property-based", "oracle": "contract", "reason": "参数组合空间属性探测"},
991
+ "path_traversal": {"name": "boundary", "oracle": "contract", "reason": "点斜杠相对路径穿透"},
992
+ "rce": {"name": "fault-injection", "oracle": "invariant", "reason": "恶意载荷沙箱隔离与逃逸阻断"},
993
+ "command_injection": {"name": "fault-injection", "oracle": "invariant", "reason": "命令注入与管道逃逸"},
994
+ "sql_injection": {"name": "guided-fuzz", "oracle": "contract", "reason": "动态SQL拼接与注入测试"},
995
+ "credential_leak": {"name": "boundary", "oracle": "invariant", "reason": "敏感凭据硬编码与泄露验证"},
996
+ "reentrancy_deadlock": {"name": "concurrency", "oracle": "invariant", "reason": "循环依赖重入死锁与时序反常"},
997
+ "state_corruption": {"name": "state-machine", "oracle": "invariant", "reason": "循环调用状态破坏与数据污染"},
998
+ "race_condition": {"name": "concurrency", "oracle": "invariant", "reason": "并发时序与原子性竞争"},
999
+ "deadlock": {"name": "concurrency", "oracle": "invariant", "reason": "多锁逆序争用与超时检测"},
1000
+ "lost_update": {"name": "concurrency", "oracle": "invariant", "reason": "无锁读改写丢失更新验证"},
1001
+ "state_machine_bypass": {"name": "state-machine", "oracle": "invariant", "reason": "跳步与反向状态跃迁校验"},
1002
+ "illegal_transition": {"name": "state-machine", "oracle": "invariant", "reason": "非法前置状态强行流转"},
1003
+ "buffer_overflow": {"name": "guided-fuzz", "oracle": "invariant", "reason": "缓冲区超长边界与内存覆写"},
1004
+ "heap_corruption": {"name": "guided-fuzz", "oracle": "invariant", "reason": "堆破坏与异常释放检测"},
1005
+ "use_after_free": {"name": "guided-fuzz", "oracle": "invariant", "reason": "悬挂指针与释放后引用检测"},
1006
+ "out_of_bounds_write": {"name": "boundary", "oracle": "invariant", "reason": "数组与指针越界写入"},
1007
+ }
1008
+
1009
+ res: list[dict[str, str]] = []
1010
+ for t in threats:
1011
+ if t in mapping:
1012
+ res.append(mapping[t])
1013
+ if not res:
1014
+ res = [
1015
+ {"name": "boundary", "oracle": "contract", "reason": "默认边界探测"},
1016
+ {"name": "negative-control", "oracle": "invariant", "reason": "正反双向对照"},
1017
+ ]
1018
+ # 去重
1019
+ seen = set()
1020
+ deduped = []
1021
+ for r in res:
1022
+ if r["name"] not in seen:
1023
+ seen.add(r["name"])
1024
+ deduped.append(r)
1025
+ return deduped
1026
+
1027
+
1028
+ class MiningPlanAuditor:
1029
+ """挖掘方案与用例四维质量量化审计评估器 (满分 100 分)."""
1030
+
1031
+ def __init__(self, root: Path | None = None) -> None:
1032
+ self.root = (root or Path.cwd()).resolve()
1033
+
1034
+ def audit(self, plan: dict[str, Any], *, min_score: float = 80.0, strict: bool = False) -> dict[str, Any]:
1035
+ violations: list[str] = []
1036
+ dimensions = {
1037
+ "accuracy": {"score": 25.0, "max_score": 25.0, "issues": []},
1038
+ "completeness": {"score": 25.0, "max_score": 25.0, "issues": []},
1039
+ "effectiveness": {"score": 25.0, "max_score": 25.0, "issues": []},
1040
+ "comprehensiveness": {"score": 25.0, "max_score": 25.0, "issues": []},
1041
+ }
1042
+
1043
+ units = plan.get("units", [])
1044
+ if not isinstance(units, list):
1045
+ units = []
1046
+
1047
+ # ── 1. 准确性 (Accuracy, 25分) ──
1048
+ # 1.1 目标主体真实存在率 (10分)
1049
+ missing_count = 0
1050
+ for u in units:
1051
+ scope = u.get("scope", "")
1052
+ file_part = scope.split("::")[0] if "::" in scope else u.get("path", "")
1053
+ if file_part and not (self.root / file_part).exists():
1054
+ missing_count += 1
1055
+ if units and missing_count > 0:
1056
+ deduct = min(10.0, round((missing_count / len(units)) * 10.0, 2))
1057
+ dimensions["accuracy"]["score"] -= deduct
1058
+ msg = f"存在 {missing_count} 个引用不存在源文件的挖掘单元"
1059
+ dimensions["accuracy"]["issues"].append(msg)
1060
+ violations.append(f"[Accuracy] {msg}")
1061
+
1062
+ # 1.2 挖掘命令模板与占位符合法性 (10分)
1063
+ invalid_cmd_count = 0
1064
+ for u in units:
1065
+ cmd = u.get("cmd_template") or u.get("command") or ""
1066
+ if cmd:
1067
+ valid, reason = ThreatModelMatcher.validate_command_template(cmd)
1068
+ if not valid:
1069
+ invalid_cmd_count += 1
1070
+ if invalid_cmd_count > 0:
1071
+ deduct = min(10.0, invalid_cmd_count * 2.5)
1072
+ dimensions["accuracy"]["score"] -= deduct
1073
+ msg = f"{invalid_cmd_count} 个挖掘命令模板不合法或缺少占位符"
1074
+ dimensions["accuracy"]["issues"].append(msg)
1075
+ violations.append(f"[Accuracy] {msg}")
1076
+
1077
+ # 1.3 威胁模型与目标匹配度 (5分)
1078
+ # 检查是否全部单元都是无脑挂单一策略
1079
+ all_techs = [t.get("name") if isinstance(t, dict) else t for u in units for t in u.get("techniques", [])]
1080
+ if units and len(set(all_techs)) <= 1 and len(units) >= 3:
1081
+ dimensions["accuracy"]["score"] -= 3.0
1082
+ dimensions["accuracy"]["issues"].append("挖掘策略手段过于单一,缺少针对目标特性的威胁模型匹配")
1083
+
1084
+ # ── 2. 完整性 (Completeness, 25分) ──
1085
+ # 2.1 可挖掘功能主体覆盖度 (10分)
1086
+ explorer = MiningSurfaceExplorer(self.root)
1087
+ discovered = explorer.explore()
1088
+ planned_scopes = {u.get("scope") for u in units if u.get("scope")}
1089
+ planned_files = {u.get("path") for u in units if u.get("path")}
1090
+
1091
+ uncovered_critical = [
1092
+ s for s in discovered
1093
+ if s.risk_level in ("CRITICAL", "HIGH")
1094
+ and s.scope not in planned_scopes
1095
+ and s.path not in planned_files
1096
+ ]
1097
+ if uncovered_critical:
1098
+ deduct = min(10.0, len(uncovered_critical) * 1.5)
1099
+ dimensions["completeness"]["score"] -= deduct
1100
+ msg = f"遗漏 {len(uncovered_critical)} 个高危可挖掘主体(如 Web 路由/CLI/反序列化点)未纳入计划"
1101
+ dimensions["completeness"]["issues"].append(msg)
1102
+ violations.append(f"[Completeness] {msg}")
1103
+
1104
+ # 2.2 DAG 调度依赖闭合度 (8分)
1105
+ # 检查是否存在死循环依赖或未知依赖
1106
+ scope_set = {u.get("scope") for u in units if u.get("scope")}
1107
+ broken_prereqs = 0
1108
+ for u in units:
1109
+ prereqs = u.get("prerequisites", [])
1110
+ for p in prereqs:
1111
+ if p not in scope_set:
1112
+ broken_prereqs += 1
1113
+ if broken_prereqs > 0:
1114
+ deduct = min(8.0, broken_prereqs * 2.0)
1115
+ dimensions["completeness"]["score"] -= deduct
1116
+ msg = f"存在 {broken_prereqs} 处前置依赖无法在挖掘计划中闭合解析"
1117
+ dimensions["completeness"]["issues"].append(msg)
1118
+ violations.append(f"[Completeness] {msg}")
1119
+
1120
+ # 2.3 资源声明与资产完整性 (7分)
1121
+ # 针对需要凭据/会话的单元是否有资源说明
1122
+ needs_resource_units = [u for u in units if any(t in ("auth_bypass", "idor", "state-machine") for t in [
1123
+ t.get("name") if isinstance(t, dict) else str(t) for t in u.get("techniques", [])
1124
+ ])]
1125
+ missing_res = [u for u in needs_resource_units if not u.get("resources") and not u.get("prerequisites")]
1126
+ if missing_res:
1127
+ deduct = min(7.0, len(missing_res) * 1.5)
1128
+ dimensions["completeness"]["score"] -= deduct
1129
+ dimensions["completeness"]["issues"].append(f"{len(missing_res)} 个敏感/状态挖掘单元缺少资源上下文或前置依赖")
1130
+
1131
+ # ── 3. 有效性 (Effectiveness, 25分) ──
1132
+ # 3.1 风险密度倾斜 (10分)
1133
+ high_risk_count = sum(1 for u in units if u.get("risk_score", 0) >= 60 or u.get("priority", 0) >= 60)
1134
+ if units and high_risk_count == 0 and len(discovered) > 0:
1135
+ dimensions["effectiveness"]["score"] -= 5.0
1136
+ dimensions["effectiveness"]["issues"].append("挖掘计划未建立风险倾斜,高危脆弱点未被优先排期")
1137
+
1138
+ # 3.2 深度语义 Oracle 绑定率 (10分)
1139
+ # 非纯 Crash 判定,至少有 invariant / contract / differential / status_code
1140
+ semantic_oracle_count = 0
1141
+ for u in units:
1142
+ techs = u.get("techniques", [])
1143
+ oracles = [t.get("oracle") for t in techs if isinstance(t, dict)]
1144
+ if any(o in ("invariant", "contract", "differential", "standard") for o in oracles):
1145
+ semantic_oracle_count += 1
1146
+ if units and semantic_oracle_count < len(units) * 0.5:
1147
+ deduct = round((1 - (semantic_oracle_count / max(1, len(units)))) * 10.0, 2)
1148
+ dimensions["effectiveness"]["score"] -= deduct
1149
+ msg = f"语义 Oracle 绑定率仅为 {round(semantic_oracle_count / max(1, len(units)) * 100, 1)}%,过多依赖粗暴 Crash 退出码"
1150
+ dimensions["effectiveness"]["issues"].append(msg)
1151
+ violations.append(f"[Effectiveness] {msg}")
1152
+
1153
+ # 3.3 路径有效性与死代码排除 (5分)
1154
+ empty_units = [u for u in units if u.get("lines_count", 1) == 0]
1155
+ if empty_units:
1156
+ dimensions["effectiveness"]["score"] -= min(5.0, len(empty_units) * 1.0)
1157
+ dimensions["effectiveness"]["issues"].append(f"包含 {len(empty_units)} 个空代码/无效文件单元")
1158
+
1159
+ # ── 4. 全面性 (Comprehensiveness, 25分) ──
1160
+ # 4.1 挖掘技术手段多样性 (10分)
1161
+ unique_techniques = set(all_techs)
1162
+ if len(unique_techniques) >= 5:
1163
+ tech_score = 10.0
1164
+ elif len(unique_techniques) >= 3:
1165
+ tech_score = 7.0
1166
+ elif len(unique_techniques) >= 2:
1167
+ tech_score = 4.0
1168
+ else:
1169
+ tech_score = 1.0
1170
+ dimensions["comprehensiveness"]["score"] = tech_score
1171
+ if tech_score < 7.0:
1172
+ dimensions["comprehensiveness"]["issues"].append(f"规划的挖掘手段种类较少 ({len(unique_techniques)} 种)")
1173
+
1174
+ # 4.2 多阶段挖掘场景谱系覆盖 (15分)
1175
+ # Happy Path / Boundary / Fault Injection / Concurrency / Stateful 各 3 分
1176
+ scenario_scores = 0.0
1177
+ has_boundary = any("boundary" in all_techs for _ in [1])
1178
+ has_negative = any("negative-control" in all_techs for _ in [1])
1179
+ has_fuzz = any("guided-fuzz" in all_techs or "property-based" in all_techs for _ in [1])
1180
+ has_concurrency = any("concurrency" in all_techs for _ in [1])
1181
+ has_state = any("state-machine" in all_techs or "fault-injection" in all_techs for _ in [1])
1182
+
1183
+ if has_boundary:
1184
+ scenario_scores += 3.0
1185
+ if has_negative:
1186
+ scenario_scores += 3.0
1187
+ if has_fuzz:
1188
+ scenario_scores += 3.0
1189
+ if has_concurrency:
1190
+ scenario_scores += 3.0
1191
+ if has_state:
1192
+ scenario_scores += 3.0
1193
+ dimensions["comprehensiveness"]["score"] += scenario_scores
1194
+ if scenario_scores < 12.0:
1195
+ dimensions["comprehensiveness"]["issues"].append("挖掘场景未形成全谱系闭环(缺边界/负对照/模糊变异/并发/状态机中的某些场景)")
1196
+
1197
+ # 归一化各维分数
1198
+ for k in dimensions:
1199
+ dimensions[k]["score"] = max(0.0, min(dimensions[k]["max_score"], round(dimensions[k]["score"], 1)))
1200
+
1201
+ total_score = round(sum(d["score"] for d in dimensions.values()), 1)
1202
+ if total_score >= min_score and (not strict or len(violations) == 0):
1203
+ level = "PASS"
1204
+ elif total_score >= 60.0:
1205
+ level = "DEGRADED"
1206
+ else:
1207
+ level = "FAIL"
1208
+
1209
+ return {
1210
+ "score": total_score,
1211
+ "level": level,
1212
+ "min_score": min_score,
1213
+ "strict_mode": strict,
1214
+ "units_count": len(units),
1215
+ "discovered_surfaces_count": len(discovered),
1216
+ "dimensions": dimensions,
1217
+ "violations": violations,
1218
+ "summary": {
1219
+ "high_risk_units": high_risk_count,
1220
+ "unique_techniques": sorted(unique_techniques),
1221
+ "uncovered_critical_surfaces": len(uncovered_critical),
1222
+ "exploration_errors": len(explorer.errors),
1223
+ },
1224
+ "exploration_errors": list(explorer.errors),
1225
+ }
1226
+
1227
+
1228
+ class MiningPlanHardener:
1229
+ """挖掘方案自动加固器:补全缺失主体、完善依赖图与强化 Oracle。"""
1230
+
1231
+ @staticmethod
1232
+ def harden(plan: dict[str, Any], root: Path) -> dict[str, Any]:
1233
+ root = root.resolve()
1234
+ hardened = dict(plan)
1235
+ units: list[dict[str, Any]] = list(hardened.get("units", []))
1236
+
1237
+ existing_scopes = {u.get("scope") for u in units if u.get("scope")}
1238
+ explorer = MiningSurfaceExplorer(root)
1239
+ discovered = explorer.explore()
1240
+
1241
+ added_count = 0
1242
+ for s in discovered:
1243
+ if s.scope not in existing_scopes and s.risk_level in ("CRITICAL", "HIGH"):
1244
+ # 自动补全高危隐式端点
1245
+ new_unit = {
1246
+ "scope": s.scope,
1247
+ "path": s.path,
1248
+ "name": s.name,
1249
+ "kind": s.kind,
1250
+ "risk_score": 85.0 if s.risk_level == "CRITICAL" else 70.0,
1251
+ # This score orders automatically discovered surfaces; it is
1252
+ # a heuristic derived from static risk level, not measured evidence.
1253
+ "risk_score_source": "heuristic_surface_risk_level",
1254
+ "priority": 85 if s.risk_level == "CRITICAL" else 70,
1255
+ "techniques": ThreatModelMatcher.match_techniques_for_threats(s.threat_models),
1256
+ "prerequisites": [],
1257
+ "resources": {"consumed": [], "produced": []},
1258
+ "scaffold_ready": True,
1259
+ "auto_hardened": True,
1260
+ }
1261
+ units.append(new_unit)
1262
+ existing_scopes.add(s.scope)
1263
+ added_count += 1
1264
+
1265
+ # 强化已有单元中的弱 Oracle
1266
+ for u in units:
1267
+ techs = u.get("techniques", [])
1268
+ for t in techs:
1269
+ if isinstance(t, dict) and t.get("oracle") in (None, "", "crash"):
1270
+ t["oracle"] = "invariant"
1271
+ t["reason"] = (t.get("reason") or "") + " (由 Hardener 自动绑定不变量断言)"
1272
+
1273
+ # 重新按优先级排序
1274
+ units.sort(key=lambda item: (-item.get("risk_score", item.get("priority", 0)), item.get("scope", "")))
1275
+ hardened["units"] = units
1276
+ hardened["hardened_additions_count"] = added_count
1277
+ hardened["exploration_errors"] = list(explorer.errors)
1278
+ return hardened
1279
+
1280
+
1281
+ def main(argv: list[str] | None = None) -> int:
1282
+ parser = argparse.ArgumentParser(description="BugX 挖掘方案与用例全息保证框架")
1283
+ subparsers = parser.add_subparsers(dest="subcommand", required=True)
1284
+
1285
+ # 1. audit 子命令
1286
+ audit_parser = subparsers.add_parser("audit", help="对挖掘方案进行四维质量量化审计")
1287
+ audit_parser.add_argument("plan_file", type=Path, help="挖掘方案 JSON 文件路径")
1288
+ audit_parser.add_argument("--root", type=Path, default=Path.cwd(), help="项目根目录")
1289
+ audit_parser.add_argument("--min-score", type=float, default=80.0, help="最低通过分数(默认 80.0)")
1290
+ audit_parser.add_argument("--strict", action="store_true", help="严格模式(有违规项即阻断)")
1291
+ audit_parser.add_argument(
1292
+ "--allow-degraded", action="store_true",
1293
+ help="明确接受降级方案;否则 DEGRADED 返回 2,要求调用方先取得用户决策",
1294
+ )
1295
+ audit_parser.add_argument("--json", action="store_true", help="以 JSON 格式输出审计结果")
1296
+
1297
+ # 2. explore 子命令
1298
+ explore_parser = subparsers.add_parser("explore", help="勘测项目可挖掘功能主体(多语种 AST/Web路由/CLI/反序列化/临界区)")
1299
+ explore_parser.add_argument("--root", type=Path, default=Path.cwd(), help="项目根目录")
1300
+ explore_parser.add_argument("--language", help="显式指定扫描语言;省略时按文件扩展名识别")
1301
+ explore_parser.add_argument("--json", action="store_true", help="以 JSON 格式输出勘测结果")
1302
+
1303
+ # 3. harden 子命令
1304
+ harden_parser = subparsers.add_parser("harden", help="自动加固补全挖掘方案")
1305
+ harden_parser.add_argument("plan_file", type=Path, help="待加固挖掘方案 JSON 文件")
1306
+ harden_parser.add_argument("--root", type=Path, default=Path.cwd(), help="项目根目录")
1307
+ harden_parser.add_argument("--out", type=Path, help="加固后保存路径(默认打印到 stdout)")
1308
+
1309
+ args = parser.parse_args(argv)
1310
+
1311
+ if args.subcommand == "explore":
1312
+ try:
1313
+ explorer = MiningSurfaceExplorer(args.root, language=args.language)
1314
+ except ValueError as exc:
1315
+ parser.error(str(exc))
1316
+ surfaces = explorer.explore()
1317
+ if args.json:
1318
+ print(json.dumps([s.to_dict() for s in surfaces], indent=2, ensure_ascii=False))
1319
+ else:
1320
+ print(f"[mining-explorer] 在 {args.root} 中勘测到 {len(surfaces)} 个可挖掘功能主体:")
1321
+ for s in surfaces[:20]:
1322
+ print(f" - [{s.risk_level}] {s.scope} ({s.kind}) -> 威胁: {','.join(s.threat_models[:3])}")
1323
+ if len(surfaces) > 20:
1324
+ print(f" ... 另有 {len(surfaces) - 20} 个主体")
1325
+ for error in explorer.errors:
1326
+ print(f" ⚠ {error}", file=sys.stderr)
1327
+ return 0
1328
+
1329
+ if args.subcommand == "audit":
1330
+ if not args.plan_file.is_file():
1331
+ print(f"[mining-audit] ✗ 挖掘方案文件不存在: {args.plan_file}", file=sys.stderr)
1332
+ return 1
1333
+ try:
1334
+ plan_data = json.loads(args.plan_file.read_text(encoding="utf-8"))
1335
+ except Exception as exc:
1336
+ print(f"[mining-audit] ✗ 读取方案 JSON 失败: {exc}", file=sys.stderr)
1337
+ return 1
1338
+
1339
+ auditor = MiningPlanAuditor(args.root)
1340
+ report = auditor.audit(plan_data, min_score=args.min_score, strict=args.strict)
1341
+ if args.json:
1342
+ print(json.dumps(report, indent=2, ensure_ascii=False))
1343
+ else:
1344
+ print(f"[mining-audit] 评分: {report['score']} / 100 ({report['level']})")
1345
+ for dim, ddata in report["dimensions"].items():
1346
+ print(f" - {dim}: {ddata['score']}/{ddata['max_score']}")
1347
+ for issue in ddata["issues"]:
1348
+ print(f" ⚠ {issue}")
1349
+ if report["violations"]:
1350
+ print(" 违规拦截项:")
1351
+ for v in report["violations"]:
1352
+ print(f" ✗ {v}")
1353
+ # 退出码必须区分「验证通过」与「降级通过」:把 DEGRADED 和 PASS 一起
1354
+ # 返回 0,会让一个远低于阈值的方案被下游自动化当成「验证通过」放行,
1355
+ # 也就是「无法验证伪装成验证通过」。语义与 sast_probe 保持一致:
1356
+ # PASS=0 / FAIL=1 / DEGRADED=2(显式 --allow-degraded 才降为 0)。
1357
+ level = report["level"]
1358
+ if level == "PASS":
1359
+ return 0
1360
+ if level == "FAIL":
1361
+ return 1
1362
+ if args.strict:
1363
+ return 1
1364
+ if not args.json and not args.allow_degraded:
1365
+ print(f" ⏸ 方案评分 {report['score']}/{report['min_score']} 仅达降级水平({level});"
1366
+ "需显式 --allow-degraded 才视为通过。")
1367
+ return 0 if args.allow_degraded else 2
1368
+
1369
+ if args.subcommand == "harden":
1370
+ if not args.plan_file.is_file():
1371
+ print(f"[mining-harden] ✗ 挖掘方案文件不存在: {args.plan_file}", file=sys.stderr)
1372
+ return 1
1373
+ plan_data = json.loads(args.plan_file.read_text(encoding="utf-8"))
1374
+ hardened = MiningPlanHardener.harden(plan_data, args.root)
1375
+ output_str = json.dumps(hardened, indent=2, ensure_ascii=False)
1376
+ if args.out:
1377
+ args.out.write_text(output_str, encoding="utf-8")
1378
+ print(f"[mining-harden] ✓ 加固方案已写入: {args.out} (补全 {hardened['hardened_additions_count']} 个主体)")
1379
+ else:
1380
+ print(output_str)
1381
+ return 0
1382
+
1383
+ return 0
1384
+
1385
+
1386
+ if __name__ == "__main__":
1387
+ sys.exit(main())