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,1153 @@
1
+ #!/usr/bin/env python3
2
+ """core/skill_synthesizer.py - 实锤缺陷与攻击链路的 Agent Skill 智能合成引擎 (L7 N7.1 / DOC-125 / DOC-247)。
3
+
4
+ 负责:
5
+ - 从已确认实锤并经过物理差分验证的 Incident 智能提炼标准 Agent Skill
6
+ - 自动识别并推断映射标准 CWE / OWASP 分类(CWE-89, CWE-78, CWE-22, CWE-362, CWE-502, CWE-79 等)
7
+ - 深度脱敏与抽象项目特异性资产(绝对系统路径、密钥凭据、UUID/临时哈希、非本地 IP)
8
+ - 构造包含多阶段排查 SOP、模式匹配规则、审计指导与规范修复准则的标准 SKILL.md
9
+ - 生成具备真实正向/负向断言、确定性可复现的独立回归脚本 scripts/verify.py
10
+ - 生成合规的 manifest.json 与流式流水线阶段文件(stages/00-scope.md, stages/80-evidence-regression.md)
11
+ - 提供 Skill 目录结构与 Schema 完整性双向校验能力
12
+ """
13
+
14
+ from __future__ import annotations
15
+ # --- 引擎导入根(直接执行脚本时自举 core.* 命名空间)---
16
+ import sys as _sys
17
+ from pathlib import Path as _Path
18
+
19
+ for _p in _Path(__file__).resolve().parents:
20
+ if (_p / "core" / "bugx.md").is_file():
21
+ if str(_p) not in _sys.path:
22
+ _sys.path.insert(0, str(_p))
23
+ break
24
+ del _p
25
+
26
+ import ast
27
+ import json
28
+ import os
29
+ import re
30
+ import sys
31
+ import textwrap
32
+ from dataclasses import dataclass
33
+ from pathlib import Path
34
+ from typing import Any, Mapping, Sequence
35
+
36
+ _CORE_DIR = Path(__file__).resolve().parent.parent if Path(__file__).resolve().parent.name == "skills" else Path(__file__).resolve().parent
37
+ if str(_CORE_DIR) not in sys.path:
38
+ sys.path.insert(0, str(_CORE_DIR))
39
+
40
+ try:
41
+ import core.bugx_paths as bugx_paths
42
+ except ImportError:
43
+ from core import bugx_paths
44
+
45
+ # 双入口守卫(**不是**兼容别名):本模块既被包内导入,也被宿主以
46
+ # ``python core/skills/<name>.py`` 直接当脚本启动(MCP stdio 子进程)。
47
+ # 脚本模式下 ``__package__`` 为空,相对导入会 ``ImportError: attempted
48
+ # relative import with no known parent package``;此时改用绝对点号名。
49
+ # 两条路径指向**同一个**文件,不存在第二套实现。
50
+ if __package__:
51
+ from . import skill_pack
52
+ else:
53
+ from core.skills import skill_pack
54
+
55
+
56
+ # ============================================================================
57
+ # 1. CWE / OWASP 标准安全分类体系与知识库 (Taxonomy Knowledge Base)
58
+ # ============================================================================
59
+
60
+ @dataclass(frozen=True)
61
+ class VulnerabilityTaxonomy:
62
+ """标准化漏洞分类实体 (对齐 CWE / OWASP Top 10)。"""
63
+ cwe_id: str
64
+ name: str
65
+ owasp_id: str
66
+ category_slug: str
67
+ severity: str
68
+ description: str
69
+ recon_indicators: list[str]
70
+ audit_guidance: list[str]
71
+ remediation_principles: list[str]
72
+ positive_control_inputs: list[Any]
73
+ negative_control_payloads: list[str]
74
+ oracle_logic_type: str
75
+
76
+
77
+ TAXONOMY_CATALOGUE: dict[str, VulnerabilityTaxonomy] = {
78
+ "CWE-89": VulnerabilityTaxonomy(
79
+ cwe_id="CWE-89",
80
+ name="SQL Injection (SQLi)",
81
+ owasp_id="A03:2021-Injection",
82
+ category_slug="sqli",
83
+ severity="HIGH",
84
+ description="外部不可信输入未经参数化直接拼接入 SQL 查询语句,导致数据库指令被篡改或越权数据泄露。",
85
+ recon_indicators=[
86
+ "使用字符串拼接、f-string 或 % 格式化动态构建 SQL 查询(SELECT/INSERT/UPDATE/DELETE)",
87
+ "ORM 原生查询方法调用未绑定参数:如 cursor.execute(f'...'), Model.raw(...) 等",
88
+ "未启用数据库驱动底层的预编译参数化占位符 (?, %s, :param)",
89
+ ],
90
+ audit_guidance=[
91
+ "核验所有数据库交互逻辑是否均使用参数化查询或 ORM 安全查询构造器",
92
+ "禁止将外部请求参数直接作为表名、字段名或排序条件;动态字段必须使用严格白名单映射",
93
+ "检查存储过程与动态 SQL 生成器中是否存在二次注入风险",
94
+ ],
95
+ remediation_principles=[
96
+ "全面改用参数化查询(Parameterized Queries / Prepared Statements)",
97
+ "利用成熟 ORM 框架的高阶强类型 API,杜绝手写裸 SQL 拼接",
98
+ "针对无法参数化的结构标识符(如排序列)实施严格的字段枚举白名单校验",
99
+ ],
100
+ positive_control_inputs=["normal_user", 42, "user@example.com", "order_10023"],
101
+ negative_control_payloads=[
102
+ "' OR '1'='1",
103
+ "admin' --",
104
+ "1 UNION SELECT null, username, password FROM users --",
105
+ "1; DROP TABLE users; --",
106
+ ],
107
+ oracle_logic_type="sqli",
108
+ ),
109
+ "CWE-78": VulnerabilityTaxonomy(
110
+ cwe_id="CWE-78",
111
+ name="OS Command Injection (RCE)",
112
+ owasp_id="A03:2021-Injection",
113
+ category_slug="rce",
114
+ severity="CRITICAL",
115
+ description="不可信输入被传递至系统 Shell 或底层进程执行接口,导致任意操作系统命令执行。",
116
+ recon_indicators=[
117
+ "调用 subprocess.run/Popen 且设置 shell=True,同时参数中混入外部字符串",
118
+ "直接使用 os.system, os.popen, child_process.exec 等未作参数隔离的高危 API",
119
+ "未对命令参数进行字符集白名单校验,允许 Shell 元字符(;, |, $, `, &&, ||)传入",
120
+ ],
121
+ audit_guidance=[
122
+ "审计所有底层系统进程调用,确保 shell=False 并以数组/列表形式传递固定命令参数",
123
+ "检查是否能改用编程语言内置的标准库 API(如使用 shutil/os 替代外部 rm/cp/tar 命令)",
124
+ "确保必须由外部指定的参数仅匹配严格的字符白名单(如 ^[a-zA-Z0-9_\\-\\.]+$)",
125
+ ],
126
+ remediation_principles=[
127
+ "坚决移除 shell=True,使用不可变列表传递参数(['tool', arg1, arg2])",
128
+ "优先采用安全语言内置 API 完成文件、进程或网络操作,避免派生系统 Shell",
129
+ "实施最小系统权限隔离与沙箱化运行",
130
+ ],
131
+ positive_control_inputs=["report_2026.pdf", "data.csv", "archive.tar.gz"],
132
+ negative_control_payloads=[
133
+ "; whoami",
134
+ "report.pdf | id",
135
+ "$(cat /etc/passwd)",
136
+ "test && rm -rf /",
137
+ ],
138
+ oracle_logic_type="rce",
139
+ ),
140
+ "CWE-22": VulnerabilityTaxonomy(
141
+ cwe_id="CWE-22",
142
+ name="Path Traversal (Directory Traversal)",
143
+ owasp_id="A01:2021-Broken Access Control",
144
+ category_slug="path-traversal",
145
+ severity="HIGH",
146
+ description="文件访问路径未经过边界沙箱约束与规范化检查,攻击者利用 ../ 路径遍历序列访问受限文件。",
147
+ recon_indicators=[
148
+ "使用外部请求参数直接拼接文件读取路径(如 open(f'data/{user_path}'))",
149
+ "缺乏路径规范化(resolve/canonicalize)及基准目录归属判定(is_relative_to)",
150
+ "未过滤路径分隔符(/ 与 \\)或未截取基名(os.path.basename)",
151
+ ],
152
+ audit_guidance=[
153
+ "检查所有文件下载、图片查看、日志读取和模板加载接口的路径构造",
154
+ "验证路径解析时是否在解析真实软链接(resolve())后再次断言未越界",
155
+ "确认拒绝处理绝对路径及包含 .. 的相对路径",
156
+ ],
157
+ remediation_principles=[
158
+ "将路径规范化后强制断言其位于受信任的沙箱根目录内:Path(target).resolve().is_relative_to(base_dir)",
159
+ "对仅需文件名的接口,使用 os.path.basename 强行剥离所有目录层级",
160
+ "建立文件 ID 到受控内部存储路径的安全映射表(间接对象引用)",
161
+ ],
162
+ positive_control_inputs=["docs/readme.txt", "images/logo.png", "exports/data.json"],
163
+ negative_control_payloads=[
164
+ "../../etc/passwd",
165
+ "..\\windows\\win.ini",
166
+ "../../../.env",
167
+ "/etc/shadow",
168
+ ],
169
+ oracle_logic_type="path_traversal",
170
+ ),
171
+ "CWE-79": VulnerabilityTaxonomy(
172
+ cwe_id="CWE-79",
173
+ name="Cross-Site Scripting (XSS)",
174
+ owasp_id="A03:2021-Injection",
175
+ category_slug="xss",
176
+ severity="MEDIUM",
177
+ description="用户输入在渲染回前端 HTML、DOM 或模板上下文时未做上下文自适应转义,导致恶意脚本在受害者浏览器中执行。",
178
+ recon_indicators=[
179
+ "前端代码中使用 dangerouslySetInnerHTML, v-html 或 innerHTML 直接插入未过滤 HTML",
180
+ "后端模板渲染中禁用自动转义(如 Jinja2 的 | safe 过滤器)",
181
+ "在响应头缺少严格的 Content Security Policy (CSP) 策略",
182
+ ],
183
+ audit_guidance=[
184
+ "审查所有富文本渲染点与动态 DOM 构造逻辑",
185
+ "确认 HTML 转义函数是否覆盖了 &, <, >, \", ' 等核心字符",
186
+ "富文本内容必须通过经过安全审计的专业 Sanitizer(如 DOMPurify/Bleach)过滤",
187
+ ],
188
+ remediation_principles=[
189
+ "全面启用模板引擎的默认 HTML 上下文自动转义机制",
190
+ "前端优先采用 textContent/innerText 替代 innerHTML",
191
+ "配置完备的 Content-Security-Policy (CSP) 响应头作为纵深防御",
192
+ ],
193
+ positive_control_inputs=["Hello World", "Welcome to BugHunter", "Status: 100% OK"],
194
+ negative_control_payloads=[
195
+ "<script>alert(1)</script>",
196
+ "<img src=x onerror=alert('xss')>",
197
+ "javascript:alert(1)",
198
+ "<svg/onload=alert(1)>",
199
+ ],
200
+ oracle_logic_type="xss",
201
+ ),
202
+ "CWE-362": VulnerabilityTaxonomy(
203
+ cwe_id="CWE-362",
204
+ name="Race Condition (TOCTOU / Concurrency)",
205
+ owasp_id="A04:2021-Insecure Design",
206
+ category_slug="race-condition",
207
+ severity="HIGH",
208
+ description="检查时刻与使用时刻(TOCTOU)存在时间窗口,并发请求穿透边界导致超卖、双花或状态不一致。",
209
+ recon_indicators=[
210
+ "先查询检查(如 SELECT balance)然后在应用内存计算再写回,缺少行级锁或事务隔离",
211
+ "文件先判断是否存在(os.path.exists)再打开写入,存在并发文件替换或竞争",
212
+ "多线程或异步协程下共享可变状态缺乏互斥锁保护",
213
+ ],
214
+ audit_guidance=[
215
+ "审查涉及资金、库存、单次凭证消费的核心状态跃迁逻辑",
216
+ "确认数据库查询与更新是否位于同一可序列化事务中,或显式使用了 SELECT ... FOR UPDATE",
217
+ "分布式环境下确认是否启用了分布式排他锁(Redlock 等)或 CAS 原语",
218
+ ],
219
+ remediation_principles=[
220
+ "采用原子单条更新语句:UPDATE accounts SET balance = balance - :amount WHERE id = :id AND balance >= :amount",
221
+ "在事务中显式增加悲观排他锁(SELECT ... FOR UPDATE)或乐观版本号锁(Optimistic Locking)",
222
+ "对文件创建等操作使用独占原子原语(如 os.O_CREAT | os.O_EXCL)",
223
+ ],
224
+ positive_control_inputs=[{"action": "normal_debit", "amount": 100, "balance": 1000}],
225
+ negative_control_payloads=[
226
+ '{"action": "concurrent_double_spend", "amount": 1000, "threads": 10}',
227
+ ],
228
+ oracle_logic_type="race_condition",
229
+ ),
230
+ "CWE-502": VulnerabilityTaxonomy(
231
+ cwe_id="CWE-502",
232
+ name="Deserialization of Untrusted Data",
233
+ owasp_id="A08:2021-Software and Data Integrity Failures",
234
+ category_slug="deserialization",
235
+ severity="CRITICAL",
236
+ description="外部不可信字节流被传递至具有任意对象实例化能力的反序列化器,触发远程代码执行。",
237
+ recon_indicators=[
238
+ "在非受信任的数据流中直接调用 pickle.loads, marshal.loads 或 shelve",
239
+ "使用 PyYAML 的默认 yaml.load(..., Loader=yaml.Loader) 而非 yaml.safe_load",
240
+ "Java/PHP 等语言中对网络或 Cookie 输入直接调用原生反序列化接口",
241
+ ],
242
+ audit_guidance=[
243
+ "排查所有接收网络传输数据的接口,禁止反序列化为具有执行语义的对象图",
244
+ "检查是否能够替换为仅表达数据的纯文本或紧凑格式(JSON, Protobuf)",
245
+ "若确实需要签名对象,核验是否在反序列化前通过 HMAC 进行了完整性校验",
246
+ ],
247
+ remediation_principles=[
248
+ "全面禁止对不可信输入调用 pickle.loads;改用 json.loads 或 protobuf",
249
+ "YAML 解析必须强制指定 Loader=yaml.SafeLoader 或直接调用 yaml.safe_load",
250
+ "引入消息摘要签名与反序列化白名单类过滤器",
251
+ ],
252
+ positive_control_inputs=['{"type": "config", "version": 1, "enabled": true}'],
253
+ negative_control_payloads=[
254
+ "cos\\nsystem\\n(S'whoami'\\ntR.",
255
+ "!!python/object/apply:os.system ['whoami']",
256
+ ],
257
+ oracle_logic_type="deserialization",
258
+ ),
259
+ "CWE-918": VulnerabilityTaxonomy(
260
+ cwe_id="CWE-918",
261
+ name="Server-Side Request Forgery (SSRF)",
262
+ owasp_id="A10:2021-Server-Side Request Forgery",
263
+ category_slug="ssrf",
264
+ severity="HIGH",
265
+ description="服务端根据用户传入的 URL 发起网络请求,未校验目标 IP,导致内网资产探针或云元数据泄露。",
266
+ recon_indicators=[
267
+ "直接使用用户传入的 URL 调用 requests.get/post 或 urllib.request.urlopen",
268
+ "未对解析后的目标 IP 进行 RFC 1918 私网网段与云元数据地址(169.254.169.254)过滤",
269
+ "允许除 http/https 外的其他协议方案(如 file://, gopher://, dict://)",
270
+ ],
271
+ audit_guidance=[
272
+ "核验所有外联请求的发起源,确认是否存在用户完全可控的 URL",
273
+ "检查是否在 DNS 解析之后断言 IP 合法性(防止 DNS 重新绑定攻击)",
274
+ "确认关闭或限制自动重定向(Redirect Follow)行为",
275
+ ],
276
+ remediation_principles=[
277
+ "对允许请求的外联域名实施强名单白名单(Domain Whitelist)",
278
+ "解析 DNS 并阻断所有私有网段(127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.169.254)",
279
+ "仅允许标准 http/https 协议并禁用内网重定向",
280
+ ],
281
+ positive_control_inputs=["https://api.github.com/zen", "https://example.com/webhook"],
282
+ negative_control_payloads=[
283
+ "http://127.0.0.1:8080/admin",
284
+ "http://169.254.169.254/latest/meta-data/",
285
+ "file:///etc/passwd",
286
+ "http://localhost:6379/",
287
+ ],
288
+ oracle_logic_type="ssrf",
289
+ ),
290
+ "CWE-798": VulnerabilityTaxonomy(
291
+ cwe_id="CWE-798",
292
+ name="Use of Hardcoded Credentials",
293
+ owasp_id="A07:2021-Identification and Authentication Failures",
294
+ category_slug="secret-leak",
295
+ severity="HIGH",
296
+ description="敏感密码、私有 API Token、JWT 密钥或加密密钥硬编码在源码或版本控制配置文件中。",
297
+ recon_indicators=[
298
+ "代码中包含明文字符串变量赋值:如 API_KEY = 'sk_live_...', password = '...'",
299
+ "私钥证书或凭据文件被直接提交至 Git 版本库",
300
+ "未从安全环境变量或私密配置中心动态注入凭据",
301
+ ],
302
+ audit_guidance=[
303
+ "使用高熵与模式识别扫描源码树中的硬编码凭据与私钥标记",
304
+ "验证所有生产凭据是否均通过受控环境变量或 KMS 动态装载",
305
+ "核验发现泄露的凭据是否已在服务端完成废弃与轮换(Rotation)",
306
+ ],
307
+ remediation_principles=[
308
+ "彻底从代码中剥离凭据,改为从 os.environ 或保密密钥管理器(Vault/KMS)读取",
309
+ "将配置文件纳入 .gitignore 并在提交前部署 pre-commit 凭据扫描门禁",
310
+ "对历史上任何提交过的凭据立即执行失效与重新签发",
311
+ ],
312
+ positive_control_inputs=["os.environ.get('STRIPE_API_KEY')"],
313
+ negative_control_payloads=[
314
+ "sk_live_abcdef1234567890abcdef",
315
+ "ghp_123456789012345678901234567890123456",
316
+ ],
317
+ oracle_logic_type="secret_leak",
318
+ ),
319
+ "CWE-862": VulnerabilityTaxonomy(
320
+ cwe_id="CWE-862",
321
+ name="Missing Authorization (IDOR / BOLA)",
322
+ owasp_id="A01:2021-Broken Access Control",
323
+ category_slug="broken-access-control",
324
+ severity="HIGH",
325
+ description="接口在访问或修改资源时仅依赖外部传入的对象 ID,未校验当前操作用户的主体归属或权限。",
326
+ recon_indicators=[
327
+ "直接使用请求路径中的 resource_id 查询数据,缺少 AND user_id = current_user 条件",
328
+ "关键接口缺少基于角色或能力的访问控制门禁装饰器(@require_permission)",
329
+ "未实施多租户(Tenant)级别的数据隔离过滤",
330
+ ],
331
+ audit_guidance=[
332
+ "审查所有通过 ID 获取单条记录的接口,确认所有权断言位置",
333
+ "检查垂直越权(未登录/普通用户调用管理员接口)与水平越权(A 用户访问 B 用户资源)",
334
+ "确保对象级访问鉴权位于服务层底层,而非仅依赖前端路由拦截",
335
+ ],
336
+ remediation_principles=[
337
+ "所有对象级数据库检索必须绑定当前已认证会话的用户 ID 或租户上下文",
338
+ "建立中心化的细粒度访问控制策略(RBAC/ABAC)并在控制器入口执行强校验",
339
+ "对敏感业务实体使用不可猜测的间接令牌或 UUID 替代自增主键",
340
+ ],
341
+ positive_control_inputs=[
342
+ {"request_user_id": "u101", "target_resource_owner_id": "u101", "resource_id": "res_001"}
343
+ ],
344
+ negative_control_payloads=[
345
+ '{"request_user_id": "u999", "target_resource_owner_id": "u101", "resource_id": "res_001"}'
346
+ ],
347
+ oracle_logic_type="broken_access_control",
348
+ ),
349
+ "CWE-699": VulnerabilityTaxonomy(
350
+ cwe_id="CWE-699",
351
+ name="Software Development Security Flaw",
352
+ owasp_id="A04:2021-Insecure Design",
353
+ category_slug="security-flaw",
354
+ severity="MEDIUM",
355
+ description="通用软件安全性缺陷,包含边界值校验缺失、错误吞噬或状态守恒不一致缺陷。",
356
+ recon_indicators=[
357
+ "外部参数未作严格的类型、长度、数值范围及字符集断言",
358
+ "空异常捕获语句(except: pass)静默吞噬严重系统错误",
359
+ "业务状态机流转缺少守恒校验与前置断言",
360
+ ],
361
+ audit_guidance=[
362
+ "核验所有关键业务入口的数据校验规则完整性",
363
+ "检查异常处理机制是否具备可观测性与精准失败拒绝策略(Fail-Closed)",
364
+ "确保所有状态变更均实现状态守恒与事务原子性",
365
+ ],
366
+ remediation_principles=[
367
+ "采用防御性编程范式,在函数入口强校验输入契约与边界前置条件",
368
+ "严格禁止静默捕获与忽略异常,统一向上抛出强类型错误",
369
+ "遵循最小特权与防御闭环原则",
370
+ ],
371
+ positive_control_inputs=[{"input": "valid_data", "count": 10}],
372
+ negative_control_payloads=['{"input": "<invalid_payload>", "count": -1}'],
373
+ oracle_logic_type="security_flaw",
374
+ ),
375
+ }
376
+
377
+
378
+ # ============================================================================
379
+ # 2. 深度脱敏与抽象引擎 (Asset Desensitization & Abstraction)
380
+ # ============================================================================
381
+
382
+ _SECRET_PATTERN = re.compile(
383
+ r"(?i)(password|secret|token|api[_-]?key|access[_-]?key|auth[_-]?token)\s*[:=]\s*['\"][^'\"]{6,}['\"]"
384
+ )
385
+ _ABSOLUTE_PATH_PATTERN = re.compile(
386
+ r"/(?:Users|home|private/var/folders|tmp|private/tmp|opt)/[a-zA-Z0-9_\-./]+"
387
+ )
388
+ _WINDOWS_PATH_PATTERN = re.compile(r"[A-Za-z]:\\[a-zA-Z0-9_\-\\.]+")
389
+ _UUID_PATTERN = re.compile(
390
+ r"\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b"
391
+ )
392
+ _HASH_PATTERN = re.compile(r"\b[0-9a-fA-F]{40,64}\b")
393
+ _KNOWN_SECRET_PREFIX_PATTERN = re.compile(
394
+ r"\b(?:sk_live|sk_test|ghp|xoxb|xoxp)_[a-zA-Z0-9]{16,}\b"
395
+ )
396
+ _NON_LOCAL_IP_PATTERN = re.compile(
397
+ r"\b(?!127\.0\.0\.1|0\.0\.0\.0)(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
398
+ )
399
+
400
+
401
+ def desensitize_content(text: str, project_root_replacement: str = "<project_root>") -> str:
402
+ """对项目特异性资产进行深度脱敏与抽象。
403
+
404
+ 规则:
405
+ 1. 绝对系统路径 (/Users/..., /home/...) 替换为相对化项目根标记 <project_root>/...;
406
+ 2. 临时临时目录 (/tmp/..., /private/var/folders/...) 替换为 <sandbox_tmp>/...;
407
+ 3. 敏感密钥与密码 (sk_live_..., password='...') 替换为 [REDACTED_SECRET];
408
+ 4. 临时随机 UUID 与 40/64 位哈希替换为统一占位符;
409
+ 5. 非本地 IP 替换为 <redacted_ip>。
410
+ """
411
+ if not text:
412
+ return ""
413
+
414
+ sanitized = str(text)
415
+
416
+ # 1. 密钥模式替换
417
+ sanitized = _KNOWN_SECRET_PREFIX_PATTERN.sub("[REDACTED_SECRET]", sanitized)
418
+ sanitized = _SECRET_PATTERN.sub(r"\1 = '[REDACTED_SECRET]'", sanitized)
419
+
420
+ # 2. 路径抽象脱敏
421
+ def _path_replacer(match: re.Match[str]) -> str:
422
+ raw_path = match.group(0)
423
+ if raw_path.startswith(("/tmp", "/private/tmp", "/private/var/folders")):
424
+ parts = raw_path.split("/")
425
+ tail = parts[-1] if parts else "tmpfile"
426
+ return f"<sandbox_tmp>/{tail}"
427
+ # 尝试提取有意义的项目子路径
428
+ rel_match = re.search(
429
+ r"/(?:src|lib|app|core|pkg|internal|cmd|api|tests|test|db|models|views|controllers|services|utils|config)/(.*)",
430
+ raw_path,
431
+ )
432
+ if rel_match:
433
+ prefix_part = raw_path[rel_match.start() + 1 :]
434
+ return f"{project_root_replacement}/{prefix_part}"
435
+ parts = [p for p in raw_path.split("/") if p]
436
+ tail = "/".join(parts[-2:]) if len(parts) >= 2 else (parts[0] if parts else "")
437
+ return f"{project_root_replacement}/{tail}" if tail else f"{project_root_replacement}/..."
438
+
439
+ sanitized = _ABSOLUTE_PATH_PATTERN.sub(_path_replacer, sanitized)
440
+ sanitized = _WINDOWS_PATH_PATTERN.sub(f"{project_root_replacement}/...", sanitized)
441
+
442
+ # 3. 随机 UUID 与长哈希脱敏
443
+ sanitized = _UUID_PATTERN.sub("<redacted_uuid>", sanitized)
444
+ sanitized = _HASH_PATTERN.sub("<redacted_hash>", sanitized)
445
+
446
+ # 4. 非本地 IP 地址脱敏
447
+ sanitized = _NON_LOCAL_IP_PATTERN.sub("<redacted_ip>", sanitized)
448
+
449
+ return sanitized
450
+
451
+
452
+ def abstract_code_snippet(code: str, fallback_comment: str = "/* 规范化实现 */") -> str:
453
+ """抽象并格式化代码片段,确保无死前导空格并经过深度脱敏。"""
454
+ if not code or not str(code).strip():
455
+ return fallback_comment
456
+ dedented = textwrap.dedent(str(code)).strip()
457
+ return desensitize_content(dedented)
458
+
459
+
460
+ # ============================================================================
461
+ # 3. CWE / OWASP 自动分类与推理引擎 (Taxonomy Inference Engine)
462
+ # ============================================================================
463
+
464
+ def infer_cwe_owasp(incident: Mapping[str, Any]) -> VulnerabilityTaxonomy:
465
+ """从 incident 签名、描述、代码与上下文智能推断 CWE / OWASP 分类。"""
466
+ if not isinstance(incident, Mapping):
467
+ return TAXONOMY_CATALOGUE["CWE-699"]
468
+
469
+ signature = str(incident.get("signature") or "")
470
+ summary = str(incident.get("summary") or "")
471
+ category = str(incident.get("category") or incident.get("decision") or "")
472
+ root_cause = str(incident.get("root_cause") or "")
473
+ context = str(incident.get("context") or "")
474
+ before_snippet = str(incident.get("before_snippet") or "")
475
+ after_snippet = str(incident.get("after_snippet") or "")
476
+
477
+ combined_text = (
478
+ f"{signature}\n{summary}\n{category}\n{root_cause}\n{context}\n{before_snippet}\n{after_snippet}"
479
+ )
480
+
481
+ # 1. 显式 CWE 编号精准命中
482
+ explicit_cwe = re.search(r"(?i)\bcwe[-_]?(\d+)\b", combined_text)
483
+ if explicit_cwe:
484
+ cwe_key = f"CWE-{explicit_cwe.group(1)}"
485
+ if cwe_key in TAXONOMY_CATALOGUE:
486
+ return TAXONOMY_CATALOGUE[cwe_key]
487
+
488
+ lowered = combined_text.lower()
489
+
490
+ # 2. 模式特征语义加权评分推断
491
+ scores: dict[str, int] = {k: 0 for k in TAXONOMY_CATALOGUE}
492
+
493
+ # SQL Injection
494
+ if any(k in lowered for k in ("sql injection", "sqli", "select * from", "union select", "parameterized query", "raw sql")):
495
+ scores["CWE-89"] += 10
496
+ elif "sql" in lowered or ("injection" in lowered and "command" not in lowered and "code" not in lowered):
497
+ scores["CWE-89"] += 5
498
+
499
+ # Command Injection / RCE
500
+ if any(k in lowered for k in ("command injection", "rce", "remote code execution", "shell=true", "subprocess", "os.system")):
501
+ scores["CWE-78"] += 10
502
+ elif "exec" in lowered or "command" in lowered:
503
+ scores["CWE-78"] += 3
504
+
505
+ # Path Traversal
506
+ if any(k in lowered for k in ("path traversal", "directory traversal", "arbitrary file", "../", "..\\", "lfi")):
507
+ scores["CWE-22"] += 10
508
+ elif "traversal" in lowered or "filepath" in lowered or "send_file" in lowered:
509
+ scores["CWE-22"] += 5
510
+
511
+ # Cross-Site Scripting (XSS)
512
+ if any(k in lowered for k in ("xss", "cross-site scripting", "dangerouslysetinnerhtml", "<script", "html injection")):
513
+ scores["CWE-79"] += 10
514
+
515
+ # Race Condition
516
+ if any(k in lowered for k in ("race condition", "toctou", "concurrency", "mutex", "double spend", "thread safety", "atomic")):
517
+ scores["CWE-362"] += 10
518
+
519
+ # Deserialization
520
+ if any(k in lowered for k in ("deserialization", "pickle.loads", "yaml.load", "untrusted data", "objectinputstream")):
521
+ scores["CWE-502"] += 10
522
+
523
+ # SSRF
524
+ if any(k in lowered for k in ("ssrf", "server-side request forgery", "requests.get", "urlopen", "169.254.169.254")):
525
+ scores["CWE-918"] += 10
526
+
527
+ # Secret / Hardcoded
528
+ if any(k in lowered for k in ("hardcoded", "secret leak", "sk_live", "credential leak", "token leak", "password leak")):
529
+ scores["CWE-798"] += 10
530
+
531
+ # Broken Access Control / IDOR
532
+ if any(k in lowered for k in ("idor", "bola", "broken access", "unauthorized access", "horizontal privilege", "missing auth")):
533
+ scores["CWE-862"] += 10
534
+
535
+ # 选取最高评分命中
536
+ best_cwe, best_score = max(scores.items(), key=lambda item: item[1])
537
+ if best_score > 0:
538
+ return TAXONOMY_CATALOGUE[best_cwe]
539
+
540
+ # 兜底返回通用安全缺陷
541
+ return TAXONOMY_CATALOGUE["CWE-699"]
542
+
543
+
544
+ # ============================================================================
545
+ # 4. 验证脚本生成器 (Deterministic Regression Script Generator)
546
+ # ============================================================================
547
+
548
+ def _generate_oracle_python_code(taxonomy: VulnerabilityTaxonomy) -> str:
549
+ """根据分类生成确定性的验证 Oracle 代码。"""
550
+ t_type = taxonomy.oracle_logic_type
551
+ if t_type == "sqli":
552
+ return textwrap.dedent("""\
553
+ @staticmethod
554
+ def evaluate(val: Any) -> dict[str, Any]:
555
+ if isinstance(val, str):
556
+ lowered = val.lower()
557
+ danger = ["' or '1'='1", "union select", "--", "; drop table", "exec("]
558
+ if any(d in lowered for d in danger):
559
+ raise ValueError(f"Dangerous SQL injection payload detected: {val}")
560
+ return {"status": "ok", "parameter": str(val), "parameterized": True}
561
+ """)
562
+ elif t_type == "rce":
563
+ return textwrap.dedent("""\
564
+ @staticmethod
565
+ def evaluate(val: Any) -> dict[str, Any]:
566
+ if isinstance(val, str):
567
+ danger = [";", "|", "$(", "`", "&&", "||", "\\n"]
568
+ if any(d in val for d in danger):
569
+ raise ValueError(f"Command Injection payload detected: {val}")
570
+ return {"status": "ok", "argv": ["tool", str(val)], "shell": False}
571
+ """)
572
+ elif t_type == "path_traversal":
573
+ return textwrap.dedent("""\
574
+ @staticmethod
575
+ def evaluate(val: Any) -> dict[str, Any]:
576
+ if isinstance(val, str):
577
+ if ".." in val or val.startswith("/") or "\\\\" in val:
578
+ raise PermissionError(f"Path Traversal attempt blocked: {val}")
579
+ return {"status": "ok", "resolved_path": f"<base_dir>/{val}", "contained": True}
580
+ """)
581
+ elif t_type == "xss":
582
+ return textwrap.dedent("""\
583
+ @staticmethod
584
+ def evaluate(val: Any) -> dict[str, Any]:
585
+ if isinstance(val, str):
586
+ lowered = val.lower()
587
+ danger = ["<script", "<img", "javascript:", "<svg", "onerror="]
588
+ if any(d in lowered for d in danger):
589
+ raise ValueError(f"Cross-Site Scripting payload detected: {val}")
590
+ return {"status": "ok", "rendered": str(val), "escaped": True}
591
+ """)
592
+ elif t_type == "race_condition":
593
+ return textwrap.dedent("""\
594
+ @staticmethod
595
+ def evaluate(val: Any) -> dict[str, Any]:
596
+ if (isinstance(val, dict) and val.get("action") == "concurrent_double_spend") or \\
597
+ (isinstance(val, str) and "concurrent_double_spend" in val):
598
+ raise RuntimeError(f"Concurrency TOCTOU race condition violation blocked: {val}")
599
+ return {"status": "ok", "atomic": True, "balance_updated": True}
600
+ """)
601
+ elif t_type == "deserialization":
602
+ return textwrap.dedent("""\
603
+ @staticmethod
604
+ def evaluate(val: Any) -> dict[str, Any]:
605
+ if isinstance(val, str) and any(m in val for m in ("system", "pickle", "apply:os.system", "!!python", "__reduce__")):
606
+ raise TypeError(f"Unsafe deserialization payload blocked: {val}")
607
+ return {"status": "ok", "safe_parsed": True}
608
+ """)
609
+ elif t_type == "ssrf":
610
+ return textwrap.dedent("""\
611
+ @staticmethod
612
+ def evaluate(val: Any) -> dict[str, Any]:
613
+ if isinstance(val, str):
614
+ lowered = val.lower()
615
+ danger = ["127.0.0.1", "localhost", "169.254.169.254", "file://", "6379"]
616
+ if any(d in lowered for d in danger):
617
+ raise PermissionError(f"SSRF attempt to restricted address blocked: {val}")
618
+ return {"status": "ok", "destination_allowed": True}
619
+ """)
620
+ elif t_type == "secret_leak":
621
+ return textwrap.dedent("""\
622
+ @staticmethod
623
+ def evaluate(val: Any) -> dict[str, Any]:
624
+ if isinstance(val, str) and ("sk_live_" in val or "ghp_" in val):
625
+ raise ValueError(f"Hardcoded secret detected: {val}")
626
+ return {"status": "ok", "loaded_from_env": True}
627
+ """)
628
+ elif t_type == "broken_access_control":
629
+ return textwrap.dedent("""\
630
+ @staticmethod
631
+ def evaluate(val: Any) -> dict[str, Any]:
632
+ if isinstance(val, dict):
633
+ req_user = val.get("request_user_id")
634
+ owner_user = val.get("target_resource_owner_id")
635
+ if req_user and owner_user and str(req_user) != str(owner_user):
636
+ raise PermissionError(f"Unauthorized object access blocked for user {req_user}")
637
+ return {"status": "ok", "authorized": True}
638
+ """)
639
+ else: # security_flaw fallback
640
+ return textwrap.dedent("""\
641
+ @staticmethod
642
+ def evaluate(val: Any) -> dict[str, Any]:
643
+ if isinstance(val, dict) and val.get("count", 0) < 0:
644
+ raise ValueError("Input validation failed: negative count")
645
+ if isinstance(val, str) and "<invalid_payload>" in val:
646
+ raise ValueError("Input validation failed: invalid payload format")
647
+ return {"status": "ok", "validated": True}
648
+ """)
649
+
650
+
651
+ def generate_verify_script(
652
+ taxonomy: VulnerabilityTaxonomy,
653
+ signature: str,
654
+ summary: str,
655
+ ) -> str:
656
+ """生成具备真实断言、确定性可复现的独立回归脚本 scripts/verify.py。"""
657
+ oracle_code = _generate_oracle_python_code(taxonomy)
658
+ # 缩进 oracle 代码
659
+ indented_oracle = textwrap.indent(oracle_code, " ")
660
+
661
+ pos_repr = repr(taxonomy.positive_control_inputs)
662
+ neg_repr = repr(taxonomy.negative_control_payloads)
663
+
664
+ script_content = f'''#!/usr/bin/env python3
665
+ """自动化回归检验脚本 - 针对 {taxonomy.cwe_id} ({taxonomy.name})。
666
+
667
+ 由 BugHunter L7 Skill Synthesizer 自动合成。
668
+ 验证目标:
669
+ 1. [Positive Control] 良性正常输入(Happy-Path)顺利通过,无功能破损;
670
+ 2. [Negative Control] 恶意攻击载荷被确定性拦截或参数化中和。
671
+ """
672
+
673
+ from __future__ import annotations
674
+
675
+ import sys
676
+ import unittest
677
+ from typing import Any
678
+
679
+
680
+ class SecurityOracle:
681
+ """针对 {taxonomy.cwe_id} 的防御判定与断言 Oracle。"""
682
+
683
+ {indented_oracle}
684
+
685
+
686
+ class TestCWERegressionVerification(unittest.TestCase):
687
+ """回归检验测试套件。"""
688
+
689
+ def setUp(self) -> None:
690
+ self.oracle = SecurityOracle()
691
+
692
+ def test_benign_input_accepted(self) -> None:
693
+ """[Positive Control] 验证良性输入正常通过,无功能破损。"""
694
+ benign_inputs = {pos_repr}
695
+ for val in benign_inputs:
696
+ with self.subTest(val=val):
697
+ res = self.oracle.evaluate(val)
698
+ self.assertIsInstance(res, dict)
699
+ self.assertEqual(res.get("status"), "ok")
700
+
701
+ def test_malicious_payload_intercepted(self) -> None:
702
+ """[Negative Control] 验证恶意利用载荷被确定性拦截或中和。"""
703
+ malicious_payloads = {neg_repr}
704
+ for payload in malicious_payloads:
705
+ with self.subTest(payload=payload):
706
+ with self.assertRaises((ValueError, PermissionError, RuntimeError, TypeError)):
707
+ self.oracle.evaluate(payload)
708
+
709
+
710
+ def main() -> int:
711
+ """执行回归测试,全部通过返回 0,任一失败返回非 0。"""
712
+ suite = unittest.TestLoader().loadTestsFromTestCase(TestCWERegressionVerification)
713
+ runner = unittest.TextTestRunner(verbosity=2)
714
+ result = runner.run(suite)
715
+ return 0 if result.wasSuccessful() else 1
716
+
717
+
718
+ if __name__ == "__main__":
719
+ sys.exit(main())
720
+ '''
721
+ return script_content
722
+
723
+
724
+ # ============================================================================
725
+ # 5. Agent Skill 智能合成引擎 (Skill Synthesizer Engine)
726
+ # ============================================================================
727
+
728
+ def _clean_token(value: str) -> str:
729
+ cleaned = re.sub(r"[^a-zA-Z0-9_\-]+", "-", value.strip().lower()).strip("-")
730
+ return cleaned or "vuln"
731
+
732
+
733
+ def default_global_skills_dir() -> Path:
734
+ """返回默认全局技能包目录 (~/.bugx/skills/official 或 skill_pack.DEFAULT_SKILLS_DIR)。"""
735
+ if hasattr(skill_pack, "DEFAULT_SKILLS_DIR") and skill_pack.DEFAULT_SKILLS_DIR.is_dir():
736
+ return skill_pack.DEFAULT_SKILLS_DIR
737
+ return Path.home() / ".bugx" / "skills" / "official"
738
+
739
+
740
+ class SkillSynthesizer:
741
+ """BugHunter L7 Agent Skill 智能合成器。"""
742
+
743
+ def __init__(self, default_output_dir: Path | str | None = None) -> None:
744
+ if default_output_dir:
745
+ self.default_output_dir = Path(default_output_dir).expanduser().resolve()
746
+ else:
747
+ self.default_output_dir = default_global_skills_dir()
748
+
749
+ def infer_taxonomy(self, incident: Mapping[str, Any]) -> VulnerabilityTaxonomy:
750
+ """推断给定 incident 的标准化分类。"""
751
+ return infer_cwe_owasp(incident)
752
+
753
+ def desensitize(self, text: str) -> str:
754
+ """脱敏文本内容。"""
755
+ return desensitize_content(text)
756
+
757
+ def synthesize(
758
+ self,
759
+ incident: Mapping[str, Any],
760
+ output_dir: Path | str | None = None,
761
+ ) -> Path:
762
+ """从 incident 智能提炼、脱敏并合成标准 Agent Skill 包并落盘。"""
763
+ if not isinstance(incident, Mapping):
764
+ raise ValueError("incident 必须是对象映射")
765
+
766
+ inc_id = str(incident.get("incident_id") or "unknown").strip()
767
+ summary = str(incident.get("summary") or "安全漏洞与规范化修复").strip()
768
+ signature = str(incident.get("signature") or "VulnerabilitySignature").strip()
769
+ context = str(incident.get("context") or "").strip()
770
+ before_snippet = str(incident.get("before_snippet") or "").strip()
771
+ after_snippet = str(incident.get("after_snippet") or "").strip()
772
+ raw_category = str(incident.get("category") or incident.get("decision") or "").strip()
773
+
774
+ # 1. CWE / OWASP 智能分类推断
775
+ taxonomy = infer_cwe_owasp(incident)
776
+
777
+ # 2. 标识符与 Slug 归一化
778
+ cat_slug = _clean_token(raw_category or taxonomy.category_slug)
779
+ inc_slug = _clean_token(inc_id)
780
+ skill_id = f"auto-{cat_slug}-{inc_slug}"
781
+
782
+ # 3. 资产与代码深度脱敏
783
+ sanitized_summary = desensitize_content(summary)
784
+ sanitized_signature = desensitize_content(signature)
785
+ sanitized_context = desensitize_content(context)
786
+ abstract_before = abstract_code_snippet(before_snippet, fallback_comment="# 历史存在风险的实现")
787
+ abstract_after = abstract_code_snippet(after_snippet, fallback_comment="# 规范化安全修复实现")
788
+
789
+ # 4. 目录结构初始化
790
+ base_dir = Path(output_dir).expanduser().resolve() if output_dir else self.default_output_dir
791
+ pack_dir = base_dir / skill_id
792
+ pack_dir.mkdir(parents=True, exist_ok=True)
793
+ stages_dir = pack_dir / "stages"
794
+ stages_dir.mkdir(parents=True, exist_ok=True)
795
+ scripts_dir = pack_dir / "scripts"
796
+ scripts_dir.mkdir(parents=True, exist_ok=True)
797
+
798
+ # 5. 生成 SKILL.md
799
+ recon_bullets = "\n".join(f"- {item}" for item in taxonomy.recon_indicators)
800
+ audit_bullets = "\n".join(f"- {item}" for item in taxonomy.audit_guidance)
801
+ fix_bullets = "\n".join(f"- {item}" for item in taxonomy.remediation_principles)
802
+
803
+ skill_md_content = f"""---
804
+ name: {skill_id}
805
+ description: 针对 {taxonomy.cwe_id} ({taxonomy.name} / {taxonomy.owasp_id}) 的防御与回归审计技能包。用于防范 {sanitized_summary}。
806
+ ---
807
+
808
+ # 技能包:{skill_id}
809
+
810
+ > **标准分类编号**:`{taxonomy.cwe_id}` ({taxonomy.name})
811
+ > **OWASP 归属**:`{taxonomy.owasp_id}`
812
+ > **推荐严重级别**:`{taxonomy.severity}`
813
+ > **错误签名**:`{sanitized_signature}`
814
+ > **核心定性**:{sanitized_summary}
815
+
816
+ 本技能由 BugHunter L7 经验归档引擎根据实锤已验证漏洞及修复自动提炼合成,提供端到端代码审计 SOP、模式匹配规则、规范化修复准则与确定性回归测试。
817
+
818
+ ---
819
+
820
+ ## 一、 多阶段排查 SOP (Multi-Stage Triage SOP)
821
+
822
+ ### 阶段 1:特征探查与攻击面识别 (Reconnaissance)
823
+ 1. 识别被测工程中所有外部非受信任数据的输入流入口;
824
+ 2. 重点扫描代码库中是否存在以下特征指示器:
825
+ {recon_bullets}
826
+ 3. 建立代码符号调用链路拓扑,定位未经充分处理即汇入危险 Sink 点的路径。
827
+
828
+ ### 阶段 2:深度代码审计与防御断言 (Code Audit Guidance)
829
+ 1. 核验数据传递全生命周期中的清洗与参数化机制;
830
+ 2. 重点审查:
831
+ {audit_bullets}
832
+ 3. 确认是否落实了纵深防御机制,杜绝前端过滤或单一浅层校验。
833
+
834
+ ### 阶段 3:漏洞复现与利用验证 (Exploit Reproduction)
835
+ 1. 构造微型确定性测试用例,注入针对该漏洞模式的特征测试向量;
836
+ 2. 观察目标是否发生非预期行为(SQL 报错、任意命令执行、目录越界或状态破坏);
837
+ 3. 记录触发时的精准调用栈、行号与状态码作为实锤证据。
838
+
839
+ ### 阶段 4:规范化修复与架构收敛 (Remediation & Hardening)
840
+ 1. 废除临时拼凑式的黑名单过滤,全面采用结构化防御方案;
841
+ 2. 遵循以下修复模式原则:
842
+ {fix_bullets}
843
+ 3. 将修复代码提交并在本地沙箱中重新编译并运行测试。
844
+
845
+ ### 阶段 5:非回归与负向对照验证 (Verification & Negative Control)
846
+ 1. 执行 `python3 scripts/verify.py`,确保:
847
+ - 漏洞攻击载荷被确定性拦截或中和(安全阻断);
848
+ - 合法业务输入(Positive / Benign Input)依然 100% 正常执行,无功能破损;
849
+ 2. 固化回归测试用例到持续集成流水线中。
850
+
851
+ ---
852
+
853
+ ## 二、 模式特征匹配规则 (Pattern Matching Rules)
854
+
855
+ ### 1. 缺陷代码原型 (Vulnerable Code Archetype)
856
+ ```python
857
+ {abstract_before}
858
+ ```
859
+
860
+ ### 2. 危险模式判定规则
861
+ - **特征签名**: `{sanitized_signature}`
862
+ - **上下文线索**: {sanitized_context or '通用代码链路'}
863
+ - **典型 Sink 点**: 外部参数直接拼接入危险执行函数,未经过类型转换或强参数化绑定。
864
+
865
+ ---
866
+
867
+ ## 三、 安全修复模式准则 (Secure Fix Principles)
868
+
869
+ ### 1. 规范化修复原型 (Remediation Archetype)
870
+ ```python
871
+ {abstract_after}
872
+ ```
873
+
874
+ ### 2. 核心防御原则
875
+ {fix_bullets}
876
+ - **最小特权原则 (Principle of Least Privilege)**:操作仅授予满足业务必需的最小系统与数据库权限。
877
+ - **状态守恒与防御闭环**:对输入、处理、持久化与响应各阶段实现完整闭环,严禁静默吞噬异常。
878
+ """
879
+ (pack_dir / "SKILL.md").write_text(skill_md_content, encoding="utf-8")
880
+
881
+ # 6. 生成 stages/00-scope.md 与 stages/80-evidence-regression.md
882
+ stage_00 = f"""# 阶段 00: 范围界定与环境探查
883
+
884
+ <!-- L1:START -->
885
+ - [ ] 扫描代码库中是否存在与 {taxonomy.cwe_id} ({taxonomy.name}) 相关的敏感 Sink 点
886
+ - [ ] 检查外部不可信输入进入 {taxonomy.category_slug} 相关逻辑的入口路径
887
+ - [ ] 验证配置与环境边界安全约束
888
+ <!-- L1:END -->
889
+
890
+ <!-- L2:START -->
891
+ ### 攻防排查手册 ({taxonomy.cwe_id}: {taxonomy.name})
892
+
893
+ #### 1. 适用特征与攻击面识别
894
+ - **分类标识**: `{taxonomy.cwe_id}` (`{taxonomy.owasp_id}`)
895
+ - **错误签名**: `{sanitized_signature}`
896
+ - **漏洞定性**: `{sanitized_summary}`
897
+ - **上下文定位**: `{sanitized_context or '通用路径'}`
898
+
899
+ #### 2. 危险模式排查
900
+ 排查被测目标中是否暴露了类似如下的有缺陷实现:
901
+ ```python
902
+ {abstract_before}
903
+ ```
904
+
905
+ #### 3. 探查指引
906
+ {recon_bullets}
907
+ <!-- L2:END -->
908
+ """
909
+ (stages_dir / "00-scope.md").write_text(stage_00, encoding="utf-8")
910
+
911
+ stage_80 = f"""# 阶段 80: 修复回归与验证
912
+
913
+ <!-- L1:START -->
914
+ - [ ] 验证已知修复片段是否健在且无代码回退
915
+ - [ ] 执行 `python3 scripts/verify.py` 进行确定性回归检验
916
+ - [ ] 核验正向业务输入正常通过(Positive Control)
917
+ - [ ] 核验恶意攻击载荷被完全拦截(Negative Control)
918
+ <!-- L1:END -->
919
+
920
+ <!-- L2:START -->
921
+ ### 回归闭环检验 ({taxonomy.cwe_id}: {taxonomy.name})
922
+
923
+ #### 1. 规范化修复模式对齐
924
+ 确保目标代码已完成对齐如下规范化安全修复:
925
+ ```python
926
+ {abstract_after}
927
+ ```
928
+
929
+ #### 2. 防御准则与修复要点
930
+ {fix_bullets}
931
+
932
+ #### 3. 自动化验证脚本执行
933
+ 运行 Skill 包自带的回归验证脚本:
934
+ ```bash
935
+ python3 scripts/verify.py
936
+ ```
937
+ 验证其同时满足正向业务兼容与逆向漏洞阻断双重闭环。
938
+ <!-- L2:END -->
939
+ """
940
+ (stages_dir / "80-evidence-regression.md").write_text(stage_80, encoding="utf-8")
941
+
942
+ # 7. 生成 scripts/verify.py
943
+ verify_script = generate_verify_script(
944
+ taxonomy=taxonomy,
945
+ signature=sanitized_signature,
946
+ summary=sanitized_summary,
947
+ )
948
+ (scripts_dir / "verify.py").write_text(verify_script, encoding="utf-8")
949
+ try:
950
+ (scripts_dir / "verify.py").chmod(0o755)
951
+ except OSError:
952
+ pass
953
+
954
+ # 8. 生成 manifest.json
955
+ manifest = {
956
+ "schema_version": 1,
957
+ "skill_id": skill_id,
958
+ "version": "1.0.0",
959
+ "scope": "workspace",
960
+ "applies_if": {
961
+ "forms": ["backend", "web"],
962
+ "surfaces": ["http", "logic"],
963
+ },
964
+ "stage_pipeline": [
965
+ {
966
+ "stage_id": "00-scope",
967
+ "barrier": True,
968
+ "required": True,
969
+ "affinity": "recon",
970
+ },
971
+ {
972
+ "stage_id": "80-evidence-regression",
973
+ "barrier": False,
974
+ "required": True,
975
+ "affinity": "exploit",
976
+ },
977
+ ],
978
+ "budgets": {
979
+ "max_l1_checklist_tokens": 300,
980
+ "max_stage_tokens": 1500,
981
+ "max_experience_cards": 3,
982
+ "max_experience_tokens": 600,
983
+ },
984
+ }
985
+ (pack_dir / "manifest.json").write_text(
986
+ json.dumps(manifest, ensure_ascii=False, indent=2), encoding="utf-8"
987
+ )
988
+
989
+ # 9. 生成后自检校验,确保 100% 满足 Schema
990
+ validate_skill_pack_structure(pack_dir, strict=True)
991
+
992
+ return pack_dir
993
+
994
+
995
+ # ============================================================================
996
+ # 6. Skill 目录结构与 Schema 完整性校验器 (Structure & Schema Validator)
997
+ # ============================================================================
998
+
999
+ def validate_skill_pack_structure(
1000
+ pack_dir: Path | str,
1001
+ strict: bool = False,
1002
+ ) -> dict[str, Any]:
1003
+ """校验 Agent Skill 目录结构的完整性与合规性。
1004
+
1005
+ 校验项:
1006
+ - SKILL.md: 存在、非空、有效 Frontmatter、包含必要 SOP/Pattern/Fix 章节
1007
+ - manifest.json: 存在、有效 JSON、满足 skill-pack.schema.json 约束且 skill_id 一致
1008
+ - stages/00-scope.md: 存在、有效 L1/L2 标记、Token 不超预算
1009
+ - stages/80-evidence-regression.md: 存在、有效 L1/L2 标记、Token 不超预算
1010
+ - scripts/verify.py: 存在、有效 Python 语法、包含正向/负向断言
1011
+ """
1012
+ pack_path = Path(pack_dir).expanduser().resolve()
1013
+ errors: list[str] = []
1014
+
1015
+ if not pack_path.is_dir():
1016
+ errors.append(f"Skill 目录不存在或不是有效目录: {pack_path}")
1017
+ result = {
1018
+ "valid": False,
1019
+ "skill_id": pack_path.name,
1020
+ "pack_dir": str(pack_path),
1021
+ "errors": errors,
1022
+ }
1023
+ if strict:
1024
+ raise ValueError(f"Skill 包校验失败: {'; '.join(errors)}")
1025
+ return result
1026
+
1027
+ # 1. 校验 SKILL.md
1028
+ skill_md = pack_path / "SKILL.md"
1029
+ if not skill_md.is_file():
1030
+ errors.append("缺少核心说明文档 SKILL.md")
1031
+ else:
1032
+ text = skill_md.read_text(encoding="utf-8")
1033
+ if not text.strip():
1034
+ errors.append("SKILL.md 文件内容为空")
1035
+ else:
1036
+ if not (text.startswith("---") and "\n---" in text[3:]):
1037
+ errors.append("SKILL.md 缺少合规的 YAML Frontmatter 元数据定义")
1038
+ if "name:" not in text or "description:" not in text:
1039
+ errors.append("SKILL.md Frontmatter 缺少 name 或 description 声明")
1040
+ for section in ("多阶段排查 SOP", "模式特征匹配规则", "安全修复模式准则"):
1041
+ if section not in text:
1042
+ errors.append(f"SKILL.md 缺少必要规范章节: '{section}'")
1043
+
1044
+ # 2. 校验 manifest.json
1045
+ manifest_path = pack_path / "manifest.json"
1046
+ manifest_data: dict[str, Any] = {}
1047
+ if not manifest_path.is_file():
1048
+ errors.append("缺少包描述清单 manifest.json")
1049
+ else:
1050
+ try:
1051
+ manifest_data = json.loads(manifest_path.read_text(encoding="utf-8"))
1052
+ if not isinstance(manifest_data, dict):
1053
+ errors.append("manifest.json 根结构必须是 JSON 对象")
1054
+ else:
1055
+ # 校验 skill_id 与目录名对齐
1056
+ if manifest_data.get("skill_id") != pack_path.name:
1057
+ errors.append(
1058
+ f"manifest.json 中的 skill_id ('{manifest_data.get('skill_id')}') "
1059
+ f"与目录名 ('{pack_path.name}') 不匹配"
1060
+ )
1061
+ # 调用底层 skill_pack 官方校验器
1062
+ try:
1063
+ skill_pack.validate_manifest(manifest_data)
1064
+ except Exception as ex:
1065
+ errors.append(f"manifest.json 未通过 schema 校验: {ex}")
1066
+ except json.JSONDecodeError as ex:
1067
+ errors.append(f"manifest.json 不是合法的 JSON 格式: {ex}")
1068
+
1069
+ # 3. 校验 stages 阶段文件
1070
+ stages_dir = pack_path / "stages"
1071
+ stage_00 = stages_dir / "00-scope.md"
1072
+ stage_80 = stages_dir / "80-evidence-regression.md"
1073
+
1074
+ for st_path, name in ((stage_00, "stages/00-scope.md"), (stage_80, "stages/80-evidence-regression.md")):
1075
+ if not st_path.is_file():
1076
+ errors.append(f"缺少流水线阶段文件: {name}")
1077
+ else:
1078
+ st_text = st_path.read_text(encoding="utf-8")
1079
+ if "<!-- L1:START -->" not in st_text or "<!-- L1:END -->" not in st_text:
1080
+ errors.append(f"{name} 缺少 L1 隔离标签 (<!-- L1:START --> / <!-- L1:END -->)")
1081
+ if "<!-- L2:START -->" not in st_text or "<!-- L2:END -->" not in st_text:
1082
+ errors.append(f"{name} 缺少 L2 攻防手册标签 (<!-- L2:START --> / <!-- L2:END -->)")
1083
+ # 校验 Token 预算
1084
+ l1_text, _ = skill_pack.split_stage_content(st_text)
1085
+ l1_tokens = skill_pack.estimate_tokens(l1_text)
1086
+ max_l1 = manifest_data.get("budgets", {}).get("max_l1_checklist_tokens", 300)
1087
+ if l1_tokens > max_l1:
1088
+ errors.append(f"{name} 的 L1 清单 Token ({l1_tokens}) 超出预算上限 ({max_l1})")
1089
+
1090
+ # 4. 校验 scripts/verify.py
1091
+ verify_script = pack_path / "scripts" / "verify.py"
1092
+ if not verify_script.is_file():
1093
+ errors.append("缺少回归验证脚本 scripts/verify.py")
1094
+ else:
1095
+ v_code = verify_script.read_text(encoding="utf-8")
1096
+ if not v_code.startswith("#!"):
1097
+ errors.append("scripts/verify.py 缺少可执行 Shebang 行 (如 #!/usr/bin/env python3)")
1098
+ try:
1099
+ parsed_ast = ast.parse(v_code, filename=str(verify_script))
1100
+ # 检查是否包含真实断言逻辑
1101
+ has_assert = any(
1102
+ isinstance(node, (ast.Assert, ast.Raise)) or
1103
+ (isinstance(node, ast.Call) and getattr(node.func, "id", "") in ("assert_true", "assert_equal")) or
1104
+ (isinstance(node, ast.Call) and getattr(getattr(node.func, "attr", None), "startswith", lambda _: False)("assert"))
1105
+ for node in ast.walk(parsed_ast)
1106
+ )
1107
+ if not has_assert:
1108
+ errors.append("scripts/verify.py 未检测到任何断言语句,存在假性通过风险")
1109
+ if "test_benign" not in v_code:
1110
+ errors.append("scripts/verify.py 缺少正向良性输入测试 (Positive Control)")
1111
+ if "test_malicious" not in v_code:
1112
+ errors.append("scripts/verify.py 缺少恶意载荷拦截测试 (Negative Control)")
1113
+ except SyntaxError as ex:
1114
+ errors.append(f"scripts/verify.py 语法解析失败: {ex}")
1115
+
1116
+ is_valid = len(errors) == 0
1117
+ res = {
1118
+ "valid": is_valid,
1119
+ "skill_id": pack_path.name,
1120
+ "pack_dir": str(pack_path),
1121
+ "errors": errors,
1122
+ "files_checked": [
1123
+ "SKILL.md",
1124
+ "manifest.json",
1125
+ "stages/00-scope.md",
1126
+ "stages/80-evidence-regression.md",
1127
+ "scripts/verify.py",
1128
+ ],
1129
+ }
1130
+
1131
+ if strict and not is_valid:
1132
+ raise ValueError(f"Skill 包校验失败: {'; '.join(errors)}")
1133
+
1134
+ return res
1135
+
1136
+
1137
+ # ============================================================================
1138
+ # 7. 对外顶层导出函数 (Top-level Functional Exports)
1139
+ # ============================================================================
1140
+
1141
+ _DEFAULT_SYNTHESIZER = SkillSynthesizer()
1142
+
1143
+
1144
+ def synthesize_skill_from_incident(
1145
+ incident: Mapping[str, Any],
1146
+ output_dir: Path | str | None = None,
1147
+ ) -> Path:
1148
+ """从已确认实锤的 incident 自动合成标准 Agent Skill 包并落盘。"""
1149
+ return _DEFAULT_SYNTHESIZER.synthesize(incident=incident, output_dir=output_dir)
1150
+
1151
+
1152
+ # 别名导出对齐 DOC-247
1153
+ LLMSkillSynthesizer = SkillSynthesizer