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,1246 @@
1
+ #!/usr/bin/env python3
2
+ """judge_pipeline.py — 判读式并发审计的确定性取证与收口(DOC-257)。
3
+
4
+ 角色拆分(2026-11-03 性能复盘的根因修复):
5
+
6
+ - **机器做流程**:claim、探针执行、artifact、sha256、execution_receipt、
7
+ checkpoint 全部由本模块在宿主进程内确定性完成,毫秒级,零模型回合。
8
+ - **AI 只判断**:子代理拿到的不是任务包而是**判读包**(代码切片 + 边界
9
+ 电池实测结果),唯一职责是回答「这份数据里有没有真缺陷」,一个推理
10
+ 回合输出裁决 JSON。子代理不碰 claim/heartbeat/checkpoint 协议。
11
+
12
+ 实测背景:旧 worker 路径每个动作都烧一个模型回合(35 回合 ≈ 18 分钟,
13
+ 探针本身仅 0.4 秒);判读式路径 = 取证秒级 + N 个 judge 并行一回合 +
14
+ 收口秒级,墙钟收敛到最慢一个 judge 的推理时间。
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import ast
20
+ import hashlib
21
+ import json
22
+ import os
23
+ import subprocess
24
+ import sys
25
+ import tempfile
26
+ import time
27
+ import uuid
28
+ from pathlib import Path
29
+ from typing import Any, Mapping
30
+
31
+ PACKAGE_VERSION = 1
32
+ _PROBE_TIMEOUT_SECONDS = 8.0
33
+ _MAX_SOURCE_CHARS = 6000
34
+ _MAX_OUTPUT_CHARS = 900
35
+ _MAX_PROBES_PER_UNIT = 8
36
+
37
+ _VERDICT_STATUSES = ("clean", "bug", "insufficient_data")
38
+
39
+
40
+ def unit_parts(unit_id: str) -> tuple[str, str]:
41
+ """从覆盖 unit 提取 (file_path, symbol);与 task_scheduler 的口径一致。"""
42
+ text = str(unit_id).strip()
43
+ for prefix in ("内部:", "业务:"):
44
+ if text.startswith(prefix):
45
+ text = text[len(prefix):]
46
+ break
47
+ parts = text.split(":")
48
+ if len(parts) > 1 and parts[0].isdigit():
49
+ text = ":".join(parts[1:])
50
+ if "::" in text:
51
+ fp, sym = text.split("::", 1)
52
+ return fp.strip(), sym.strip()
53
+ return text.strip(), ""
54
+
55
+
56
+ def symbol_source(source: str, symbol: str) -> str:
57
+ """提取 symbol 的源码切片(含 class 全体方法);miss 时返回全文。"""
58
+ if not symbol:
59
+ return source
60
+ try:
61
+ tree = ast.parse(source)
62
+ except SyntaxError:
63
+ return source
64
+ lines = source.splitlines()
65
+ for node in ast.walk(tree):
66
+ names = getattr(node, "name", None)
67
+ if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)) \
68
+ and names == symbol:
69
+ span = list(range(node.lineno, (node.end_lineno or node.lineno) + 1))
70
+ if isinstance(node, ast.ClassDef):
71
+ for child in ast.walk(node):
72
+ if isinstance(child, (ast.FunctionDef, ast.AsyncFunctionDef)) \
73
+ and child.lineno not in span:
74
+ span.extend(range(child.lineno, (child.end_lineno or child.lineno) + 1))
75
+ selected = [lines[i - 1] for i in sorted(set(span)) if 0 < i <= len(lines)]
76
+ return "\n".join(selected)
77
+ return source
78
+
79
+
80
+ # ---------------------------------------------------------------------------
81
+ # 边界电池:确定性探针生成与执行
82
+ # ---------------------------------------------------------------------------
83
+
84
+ def _module_name(file_path: str) -> str:
85
+ """文件路径 → 可导入模块名。
86
+
87
+ ``src/__init__.py`` 对应包名 ``src``(不是 ``src.__init__``——后者不可导入,
88
+ 实测导致包初始化单元永久 unverified);其余按点号连接。
89
+ """
90
+ base = file_path[:-3] if file_path.endswith(".py") else file_path
91
+ if base.endswith("/__init__"):
92
+ base = base[: -len("/__init__")]
93
+ return base.replace("/", ".")
94
+
95
+
96
+ def _battery_probes(file_path: str, symbol: str, root: Path) -> list[dict[str, str]]:
97
+ """为 python 符号单元生成边界值探针(纯静态推导,无模型参与)。
98
+
99
+ 输入表刻意覆盖:None / 空串 / 零与负数 / 空容器 / 类型错位 / 极端长串。
100
+ """
101
+ probes: list[dict[str, str]] = []
102
+ values = ["None", "''", "0", "-1", "[]", "{}", "'x' * 2000"]
103
+ mod = _module_name(file_path)
104
+ # dotted 符号(Class.method)经 reduce(getattr,...) 解析;解析失败打印
105
+ # symbol-missing 而不是 AttributeError 噪声——那是电池的盲点不是缺陷证据。
106
+ parts = symbol.split(".") if symbol else []
107
+ resolve = (
108
+ f"import importlib,functools,inspect; m=importlib.import_module({mod!r}); "
109
+ + (f"f=functools.reduce(getattr, {parts!r}, m)" if parts else "f=None")
110
+ )
111
+ if symbol:
112
+ # L6 注解感知合法入参探针:按 type hints 构造合法参数,让 typed
113
+ # 函数拿到 ≥1 条 passed 证据(此前 amount_cents: int 被 None/'' 打爆,
114
+ # 全 error → 单元永久 unverified,实测 billing 需人工重跑才 covered)。
115
+ probes.append({
116
+ "desc": f"valid-input {symbol}",
117
+ "code": (
118
+ "import importlib,functools,inspect,typing,types,sys\n"
119
+ f"m=importlib.import_module({mod!r})\n"
120
+ f"try: f=functools.reduce(getattr, {parts!r}, m)\n"
121
+ f"except AttributeError: print('symbol-missing: {symbol}'); raise SystemExit\n"
122
+ "_MAP={str:'x',int:1,float:1.0,bool:True,bytes:b'x'}\n"
123
+ "_ORIGIN={list:[],dict:{},set:set(),tuple:()}\n"
124
+ "def build(p):\n"
125
+ " a=p.annotation\n"
126
+ " if a is inspect._empty: return 'x' if p.default is inspect._empty else p.default\n"
127
+ " origin=typing.get_origin(a)\n"
128
+ " if origin in (typing.Union, types.UnionType):\n"
129
+ " args=[x for x in typing.get_args(a) if x is not type(None)]\n"
130
+ " a=args[0] if args else type(None)\n"
131
+ " origin=typing.get_origin(a)\n"
132
+ " if a in _MAP: return _MAP[a]\n"
133
+ " if origin in _ORIGIN: return _ORIGIN[origin]\n"
134
+ " if a is type(None): return None\n"
135
+ " raise TypeError('unresolvable annotation %r' % (a,))\n"
136
+ "sig=inspect.signature(f)\n"
137
+ "try:\n"
138
+ " args=[build(p) for p in sig.parameters.values()]\n"
139
+ "except TypeError as e:\n"
140
+ " print('valid-input-skip: %s' % e); sys.exit(42)\n"
141
+ "print(repr(f(*args))[:400])\n"
142
+ ),
143
+ })
144
+ probes.append({
145
+ "desc": f"inspect {symbol}",
146
+ "code": (
147
+ f"import importlib,functools,inspect\n"
148
+ f"m=importlib.import_module({mod!r})\n"
149
+ f"try: f=functools.reduce(getattr, {parts!r}, m)\n"
150
+ f"except AttributeError: print('symbol-missing: {symbol}'); raise SystemExit\n"
151
+ "print(type(f).__name__, inspect.signature(f) if callable(f) else repr(f)[:200])"
152
+ ),
153
+ })
154
+ for v in values[:_MAX_PROBES_PER_UNIT - 1]:
155
+ probes.append({
156
+ "desc": f"{symbol}(*[{v}] * n_params)",
157
+ "code": (
158
+ f"import importlib,functools,inspect\n"
159
+ f"m=importlib.import_module({mod!r})\n"
160
+ f"try: f=functools.reduce(getattr, {parts!r}, m)\n"
161
+ f"except AttributeError: print('symbol-missing: {symbol}'); raise SystemExit\n"
162
+ f"n=max(0,len(inspect.signature(f).parameters))\n"
163
+ f"print(repr(f(*([{v}] * n)))[:400])"
164
+ ),
165
+ })
166
+ else:
167
+ probes.append({
168
+ "desc": f"import {file_path}",
169
+ "code": f"import importlib; importlib.import_module({mod!r});"
170
+ f" print('import ok')",
171
+ })
172
+ probes.append({
173
+ "desc": "module members",
174
+ "code": f"import importlib,inspect; m=importlib.import_module({mod!r});"
175
+ f" print(sorted(n for n,v in vars(m).items() if not n.startswith('_'))[:40])",
176
+ })
177
+ return probes[:_MAX_PROBES_PER_UNIT]
178
+
179
+
180
+ _SAFE_CALLS = {
181
+ "print", "str", "int", "float", "bool", "len", "repr", "abs", "min",
182
+ "max", "sum", "sorted", "reversed", "enumerate", "range", "isinstance",
183
+ "format", "round", "divmod", "zip", "map", "filter",
184
+ }
185
+ _SAFE_MODULES = {"math", "datetime", "itertools", "functools", "typing", "dataclasses"}
186
+ _RULES_FILE_NAME = "judge-rules.json"
187
+ _PROMOTE_THRESHOLD = 3
188
+ _MAX_ACTIVE_ADDITIONS = 20
189
+ #: 每类 candidates 的驻留上限(F-RSI-20261112-091):防一次性反馈 token
190
+ #: 无界驻留撑爆 rules 文件。晋升会清理对应 candidate;超限时拒绝新增。
191
+ _MAX_CANDIDATE_ENTRIES = 200
192
+
193
+
194
+ def default_rules() -> dict[str, Any]:
195
+ return {
196
+ "safe_calls": set(_SAFE_CALLS),
197
+ "safe_modules": set(_SAFE_MODULES),
198
+ "artifact_markers": set(_ARTIFACT_MARKERS),
199
+ "risk_tokens": {},
200
+ }
201
+
202
+
203
+ def load_rules(state_root: Path) -> dict[str, Any]:
204
+ """代码默认 < 项目规则文件(.bugx/knowledge/judge-rules.json)。
205
+
206
+ 文件是唯一动态增量层:宿主/用户可直接编辑,judge 反哺经
207
+ harvest_feedback 写入。缺省/损坏时回退纯代码默认(fail-safe)。
208
+ """
209
+ rules = default_rules()
210
+ path = Path(state_root) / "knowledge" / _RULES_FILE_NAME
211
+ try:
212
+ data = json.loads(path.read_text(encoding="utf-8"))
213
+ active = data.get("active") or {}
214
+ for key, cast in (
215
+ ("safe_calls", set), ("safe_modules", set),
216
+ ("artifact_markers", set),
217
+ ):
218
+ extra = active.get(key) or []
219
+ if isinstance(extra, list):
220
+ rules[key] |= {str(x) for x in extra[:_MAX_ACTIVE_ADDITIONS]}
221
+ tokens = active.get("risk_tokens") or {}
222
+ if isinstance(tokens, dict):
223
+ for token, label in list(tokens.items())[:_MAX_ACTIVE_ADDITIONS]:
224
+ rules["risk_tokens"][str(token)] = str(label)
225
+ except (OSError, ValueError):
226
+ pass
227
+ return rules
228
+
229
+
230
+ def _valid_token(value: object) -> str | None:
231
+ text = value if isinstance(value, str) else None
232
+ if text is None or not (4 <= len(text.strip()) <= 64):
233
+ return None
234
+ return text.strip()
235
+
236
+
237
+ def harvest_feedback(
238
+ verdicts: list[Mapping[str, Any]], state_root: Path,
239
+ ) -> dict[str, int]:
240
+ """收 judge 裁决里的 rule_feedback 并按风险不对称策略落盘。
241
+
242
+ - risk_tokens(更严方向):校验后即时进入 active;
243
+ - safe_calls / artifact_markers(更松方向):进 candidates 计数,
244
+ 同 token 独立出现 ≥3 次才晋升 active(防单条错误反馈关单放走缺陷)。
245
+ """
246
+ path = Path(state_root) / "knowledge" / _RULES_FILE_NAME
247
+ data: dict[str, Any] = {"schema_version": 1, "active": {
248
+ "safe_calls": [], "safe_modules": [],
249
+ "artifact_markers": [], "risk_tokens": {},
250
+ }, "candidates": {}}
251
+ try:
252
+ existing = json.loads(path.read_text(encoding="utf-8"))
253
+ if isinstance(existing, dict):
254
+ data = existing
255
+ data.setdefault("active", {"risk_tokens": {}})
256
+ data.setdefault("candidates", {})
257
+ except (OSError, ValueError):
258
+ pass
259
+ active = data["active"]
260
+ candidates: dict[str, dict[str, Any]] = data["candidates"]
261
+ counts = {"risk_tokens": 0, "safe_calls_new": 0,
262
+ "artifact_markers_new": 0, "promoted": 0, "rejected": 0}
263
+ base = default_rules()
264
+ for verdict in verdicts or []:
265
+ fb = verdict.get("rule_feedback") if isinstance(verdict, Mapping) else None
266
+ if not isinstance(fb, Mapping):
267
+ continue
268
+ unit = str(verdict.get("unit_id") or "unknown")
269
+ for token in (fb.get("risk_tokens") or [])[:5]:
270
+ token = _valid_token(token)
271
+ if token is None:
272
+ counts["rejected"] += 1
273
+ continue
274
+ table = active.setdefault("risk_tokens", {})
275
+ if token not in table and token not in base["risk_tokens"]:
276
+ table[token] = f"judge-feedback@{unit}"
277
+ counts["risk_tokens"] += 1
278
+ for key, counter in (("safe_calls", "safe_calls_new"),
279
+ ("artifact_markers", "artifact_markers_new")):
280
+ for token in (fb.get(key) or [])[:5]:
281
+ token = _valid_token(token)
282
+ if token is None or token in base[key]:
283
+ counts["rejected"] += 1
284
+ continue
285
+ # F-RSI-20261112-091:已晋升生效的 token 直接跳过 candidate
286
+ # 记录——否则后续反馈经 setdefault 复活 candidate,形成
287
+ # active+candidate 双轨死数据。
288
+ if token in active.get(key, []):
289
+ continue
290
+ slot = candidates.setdefault(key, {})
291
+ entry = slot.setdefault(token, {"count": 0, "sources": []})
292
+ if unit not in entry["sources"]:
293
+ entry["sources"].append(unit)
294
+ entry["count"] += 1
295
+ counts[counter] += 1
296
+ if entry["count"] >= _PROMOTE_THRESHOLD:
297
+ lst = active.setdefault(key, [])
298
+ if token not in lst and len(lst) < _MAX_ACTIVE_ADDITIONS:
299
+ lst.append(token)
300
+ counts["promoted"] += 1
301
+ # F-RSI-20261112-091:晋升即从 candidates 清除——
302
+ # 已 active 的候选残留是死数据(count/sources 永久
303
+ # 驻留 rules 文件)。token in lst 幂等检查保证重复
304
+ # 晋升安全,清理不影响既有 active 语义。
305
+ slot.pop(token, None)
306
+ # F-RSI-20261112-091:candidates 每键上限——一次性反馈 token 无界驻留
307
+ # 会让 rules 文件无限膨胀(每次 harvest 全量读写)。超限时拒绝新增并
308
+ # 留痕(既有条目继续计数),上限按保守值不淘汰既有数据。
309
+ for key, slot in candidates.items():
310
+ overflow = len(slot) - _MAX_CANDIDATE_ENTRIES
311
+ if overflow > 0:
312
+ print(
313
+ f"[judge] ⚠ rule_feedback candidates[{key}] 已达上限 "
314
+ f"{_MAX_CANDIDATE_ENTRIES}(超出 {overflow} 条新增被拒;"
315
+ "清理 knowledge/judge-rules.json 或晋升既有条目可腾位)",
316
+ file=sys.stderr,
317
+ )
318
+ for token in list(slot):
319
+ if len(slot) <= _MAX_CANDIDATE_ENTRIES:
320
+ break
321
+ if token not in active.get(key, []):
322
+ slot.pop(token, None)
323
+ path.parent.mkdir(parents=True, exist_ok=True)
324
+ path.write_text(json.dumps(data, ensure_ascii=False, indent=1), encoding="utf-8")
325
+ return counts
326
+
327
+
328
+ _ARTIFACT_MARKERS = (
329
+ "symbol-missing",
330
+ "AttributeError: module",
331
+ "missing 1 required positional",
332
+ "missing required positional",
333
+ "valid-input-skip",
334
+ # 以下为 2026-11-04 实测挖掘会话沉淀的确定性探针伪影族(build.393 内置):
335
+ # 这些输出只证明「目标符号在电池上下文不可探测」,不构成任何行为证据。
336
+ "the 'package' argument is required to perform a relative import",
337
+ "ModuleNotFoundError: No module named",
338
+ "positional arguments but",
339
+ "is not a callable object",
340
+ "no signature found for builtin type",
341
+ )
342
+
343
+
344
+ def static_profile(source: str, rules: dict[str, Any] | None = None) -> dict[str, Any]:
345
+ """AST 白名单静态画像:平凡单元(print("hello") 类)不需要任何模型回合。
346
+
347
+ trivial=True 要求全部调用在安全白名单内、导入在安全模块表内、
348
+ 无风险信号——任何一个不满足都 fail-toward-judge(宁可多判读,不误关单)。
349
+ """
350
+ rules = rules or default_rules()
351
+ signals: list[str] = []
352
+ trivial = True
353
+ try:
354
+ tree = ast.parse(source)
355
+ except SyntaxError:
356
+ return {"trivial": False, "signals": ["syntax-error"]}
357
+ for node in ast.walk(tree):
358
+ if isinstance(node, ast.Call):
359
+ fn = node.func
360
+ name = (
361
+ fn.id if isinstance(fn, ast.Name)
362
+ else fn.attr if isinstance(fn, ast.Attribute) else ""
363
+ )
364
+ if name not in rules["safe_calls"]:
365
+ trivial = False
366
+ elif isinstance(node, ast.Import):
367
+ for alias in node.names:
368
+ if alias.name.split(".")[0] not in rules["safe_modules"]:
369
+ trivial = False
370
+ elif isinstance(node, ast.ImportFrom):
371
+ root = (node.module or alias_root(node)).split(".")[0] if node.module else ""
372
+ if node.level:
373
+ trivial = False # 相对导入涉及包结构,交给 judge
374
+ elif root not in rules["safe_modules"]:
375
+ trivial = False
376
+ lowered = source.lower()
377
+ tokens: dict[str, str] = {
378
+ "shell=true": "shell-exec", "os.system": "shell-exec",
379
+ "os.popen": "shell-exec", "subprocess": "shell-exec",
380
+ "eval(": "code-exec", "exec(": "code-exec",
381
+ "pickle.loads": "deserialization", "input(": "raw-input",
382
+ "execute(f'": "sql-concat", "execute(f\"": "sql-concat",
383
+ "execute(\" select": "sql-concat", "execute(' select": "sql-concat",
384
+ "execute(\" +": "sql-concat", "execute(' +": "sql-concat",
385
+ }
386
+ tokens.update(rules["risk_tokens"])
387
+ for token, label in tokens.items():
388
+ if token in lowered:
389
+ signals.append(label)
390
+ # 变量中转 SQL 拼接(AST 级,堵子串盲区):`q = f"...{kw}"`(或
391
+ # `%`/`.format()`/+= 拼接)后 `execute(q)` —— execute 调用点看不到
392
+ # f-string 子串,2026-11-08 实测 search_users 由此漏报 sql-concat。
393
+ if _dynamic_sql_execute(tree):
394
+ signals.append("sql-concat")
395
+ if signals:
396
+ trivial = False
397
+ return {"trivial": trivial, "signals": sorted(set(signals))}
398
+
399
+
400
+ def _dynamic_sql_execute(tree: ast.AST) -> bool:
401
+ """检测「f-string/格式化拼接 → 变量 → execute」的动态 SQL 构造。"""
402
+ dynamic_vars: set[str] = set()
403
+ for node in ast.walk(tree):
404
+ if isinstance(node, ast.Assign):
405
+ if _is_dynamic_text(node.value):
406
+ for tgt in node.targets:
407
+ if isinstance(tgt, ast.Name):
408
+ dynamic_vars.add(tgt.id)
409
+ elif isinstance(node, ast.AugAssign) and _is_dynamic_text(node.value):
410
+ if isinstance(node.target, ast.Name):
411
+ dynamic_vars.add(node.target.id)
412
+ if not dynamic_vars:
413
+ return False
414
+ for node in ast.walk(tree):
415
+ if not isinstance(node, ast.Call):
416
+ continue
417
+ fn = node.func
418
+ name = fn.attr if isinstance(fn, ast.Attribute) else (
419
+ fn.id if isinstance(fn, ast.Name) else "")
420
+ if name not in ("execute", "executemany", "executescript") or not node.args:
421
+ continue
422
+ arg = node.args[0]
423
+ if isinstance(arg, ast.Name) and arg.id in dynamic_vars:
424
+ return True
425
+ if isinstance(arg, ast.JoinedStr):
426
+ return True
427
+ return False
428
+
429
+
430
+ def _is_dynamic_text(node: ast.AST) -> bool:
431
+ """值表达式是否含运行期插值(f-string 槽位 / % 格式化 / 字符串拼接)。"""
432
+ if isinstance(node, ast.JoinedStr):
433
+ return any(isinstance(v, ast.FormattedValue) for v in node.values)
434
+ if isinstance(node, ast.BinOp) and isinstance(node.op, (ast.Add, ast.Mod)):
435
+ return True
436
+ if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) \
437
+ and node.func.attr == "format":
438
+ return True
439
+ return False
440
+
441
+
442
+ def alias_root(node: ast.Import) -> str:
443
+ return node.names[0].name if node.names else ""
444
+
445
+
446
+ def dynamic_clean(
447
+ evidence: list[dict[str, Any]], rules: dict[str, Any] | None = None,
448
+ ) -> bool:
449
+ """动态全过判定:非零探针必须全部可由已知伪影标记解释。"""
450
+ if not evidence:
451
+ return False
452
+ markers = (rules or default_rules())["artifact_markers"]
453
+ for ev in evidence:
454
+ if ev.get("exit_code") == 0:
455
+ continue
456
+ blob = (ev.get("_stdout_excerpt") or "") + (ev.get("_stderr_excerpt") or "")
457
+ if any(marker in blob for marker in markers):
458
+ continue
459
+ return False
460
+ return True
461
+
462
+
463
+ def sentinel_fired(evidence: list[dict[str, Any]]) -> bool:
464
+ """差分哨兵实证:任一 differential 探针输出 SENTINEL=True。"""
465
+ return any(
466
+ "SENTINEL=True" in (ev.get("_stdout_excerpt") or "")
467
+ for ev in evidence
468
+ if "differential-sentinel" in ev.get("command", "")
469
+ )
470
+
471
+
472
+ def classify_unit(
473
+ source: str, evidence: list[dict[str, Any]],
474
+ rules: dict[str, Any] | None = None,
475
+ ) -> dict[str, Any]:
476
+ """机器初审分类器(DOC-257 pre-screen)。
477
+
478
+ - auto_clean:静态平凡 + 动态全过 → collect 内直接 checkpoint,零模型回合
479
+ - judge + machine_flag:SENTINEL 实证 → judge L1 秒确认并写 finding 文案
480
+ - judge:其余
481
+ """
482
+ rules = rules or default_rules()
483
+ profile = static_profile(source, rules)
484
+ fired = sentinel_fired(evidence)
485
+ # artifact-only:全部探针输出都可由已知伪影标记解释 ⇒ 单元在电池上下文
486
+ # 不可探测,行为证据为零信息量——送 judge 是纯浪费(l4adv 实测 15 单元
487
+ # 中 5 个)。标记集合含内置确定性伪影族与项目反哺晋升的标记。
488
+ markers = (rules or default_rules())["artifact_markers"]
489
+ artifact_only = bool(evidence) and all(
490
+ any(marker in ((ev.get("_stdout_excerpt") or "") + (ev.get("_stderr_excerpt") or ""))
491
+ for marker in markers)
492
+ for ev in evidence
493
+ )
494
+ if artifact_only or (profile["trivial"] and dynamic_clean(evidence, rules)):
495
+ return {"route": "auto_clean", "signals": profile["signals"],
496
+ "sentinel": fired, "artifact_only": artifact_only}
497
+ if fired:
498
+ return {"route": "judge", "machine_flag": "sentinel-confirmed", "signals": profile["signals"], "sentinel": True}
499
+ return {"route": "judge", "signals": profile["signals"], "sentinel": False}
500
+
501
+
502
+ # 差分哨兵触发语料(build.395 扩充):命令/代码执行族之外补齐
503
+ # 反序列化族(pickle/yaml.load/marshal)与进程替换族(execv/getoutput/
504
+ # pty.spawn)。项目可经 judge 反哺 risk_tokens 或人工编辑 judge-rules.json
505
+ # 追加(即时生效),无需等引擎发版。
506
+ _EXEC_SIGNALS = (
507
+ "shell=True", "subprocess", "os.system", "os.popen", "eval(", "exec(",
508
+ "os.execv", "commands.getoutput", "subprocess.getoutput",
509
+ "subprocess.getstatusoutput", "pty.spawn",
510
+ "pickle.loads", "yaml.load(", "marshal.loads",
511
+ )
512
+
513
+
514
+ def has_exec_signal(
515
+ source: str, dep_sources: list[str] | None = None,
516
+ rules: dict[str, Any] | None = None,
517
+ ) -> bool:
518
+ """单元或其依赖切片出现命令/代码执行信号时才启用差分哨兵探针。
519
+
520
+ 采集层反哺(DOC-257 续):除硬编码信号外,judge 反哺的 risk_tokens
521
+ 也参与判定——新注入形态(os.execv、commands.getoutput 等)一经反哺,
522
+ 下一批取证即触发差分哨兵,而不只是影响静态画像。
523
+ """
524
+ corpus = source + "\n" + "\n".join(dep_sources or [])
525
+ if any(sig in corpus for sig in _EXEC_SIGNALS):
526
+ return True
527
+ extra = (rules or {}).get("risk_tokens") or {}
528
+ return any(token and token in corpus for token in extra)
529
+
530
+
531
+ def risk_grade(
532
+ source: str, dep_sources: list[str] | None = None,
533
+ rules: dict[str, Any] | None = None,
534
+ ) -> str:
535
+ """三级风险分级(单一真相源,供 collect 分组/AI 兜底/排序共用)。
536
+
537
+ - ``dangerous``:命中风险 token 标签(shell-exec/code-exec/deserialization/
538
+ raw-input/sql-concat,含项目反哺)或执行信号语料(含反哺)——AI 兜底必审级;
539
+ - ``unknown``:非平凡(存在白名单外调用/导入)但无危险信号——可机器关单;
540
+ - ``trivial``:静态平凡——机器直关。
541
+
542
+ 反哺 risk_tokens 同时进入 static_profile 标签表与执行语料,因此一条
543
+ 反哺即刻把同形态单元从 unknown/dangerous 升级,无需改引擎。
544
+ """
545
+ profile = static_profile(source, rules)
546
+ if profile["signals"] or has_exec_signal(source, dep_sources=dep_sources, rules=rules):
547
+ return "dangerous"
548
+ return "trivial" if profile["trivial"] else "unknown"
549
+
550
+
551
+ def _differential_probes(file_path: str, symbol: str) -> list[dict[str, str]]:
552
+ """哨兵差分探针:一条脚本内完成 基线→载荷→哨兵检查 的完整对照实验。
553
+
554
+ 输出结构化行 BASE_RC / PAYLOAD_RC / SENTINEL,宿主确定性执行;
555
+ judge 拿到的是已完成的对照结论,不再是"rc!=0 无法区分"的歧义数据。
556
+ 载荷仅 touch 哨兵文件(无破坏性);SENTINEL=True 即注入实证。
557
+ """
558
+ if not symbol:
559
+ return []
560
+ mod = file_path[:-3].replace("/", ".")
561
+ parts = symbol.split(".")
562
+ payloads = [
563
+ ("semicolon", "'x; touch ' + SENTINEL"),
564
+ ("command-sub", "'x$(touch ' + SENTINEL + ')'"),
565
+ ("sql-union", "'x' + chr(39) + ' UNION SELECT ' + chr(39) + 'SENTINEL' "
566
+ "+ chr(39) + ',' + chr(39) + 'SENTINEL' + chr(39) + ' -- '"),
567
+ ]
568
+ probes = []
569
+ for name, payload_expr in payloads:
570
+ probes.append({
571
+ "desc": f"differential-sentinel[{name}] {symbol}",
572
+ "code": (
573
+ "import importlib,functools,inspect,os,tempfile\n"
574
+ f"m=importlib.import_module({mod!r})\n"
575
+ f"try: f=functools.reduce(getattr, {parts!r}, m)\n"
576
+ f"except AttributeError: print('symbol-missing: {symbol}'); raise SystemExit\n"
577
+ "SENTINEL=os.path.join(tempfile.mkdtemp(prefix='bugx-diff-'),'sentinel')\n"
578
+ "n=max(0,len(inspect.signature(f).parameters))\n"
579
+ "def rc(v):\n"
580
+ " try: return f(*([v]*n)), None\n"
581
+ " except BaseException as e: return None, type(e).__name__\n"
582
+ "b=rc('x'); print('BASE_RET=%r BASE_EXC=%s' % (b[0], b[1]))\n"
583
+ f"pl=rc({payload_expr}); print('PAYLOAD_RET=%r PAYLOAD_EXC=%s' % (pl[0], pl[1]))\n"
584
+ "hit=os.path.exists(SENTINEL) or ('SENTINEL' in str(pl[0]))\n"
585
+ "print('SENTINEL=' + ('True' if hit else 'False'))\n"
586
+ ),
587
+ })
588
+ return probes
589
+
590
+
591
+ def run_battery(
592
+ root: Path,
593
+ unit_id: str,
594
+ artifact_root: Path,
595
+ lease_id: str,
596
+ execution_id: str,
597
+ worker_id: str,
598
+ run_id: str,
599
+ target_fingerprint: str,
600
+ round_no: int = 1,
601
+ rules: dict[str, Any] | None = None,
602
+ ) -> list[dict[str, Any]]:
603
+ """执行边界电池并把每个探针落成带收据的 artifact(与 finalize 兼容)。
604
+
605
+ 返回 evidence 条目数组(status=passed 表示探针本身执行成功——含抛出
606
+ 异常的探针,异常正是判读数据;探针进程崩溃/超时才记 error)。
607
+ """
608
+ root = Path(root).resolve()
609
+ artifact_root = (root / artifact_root).resolve() if not Path(artifact_root).is_absolute() else Path(artifact_root).resolve()
610
+ artifact_root.mkdir(parents=True, exist_ok=True)
611
+ file_path, symbol = unit_parts(unit_id)
612
+ target = root / file_path
613
+ if not target.is_file():
614
+ return []
615
+ try:
616
+ unit_source = target.read_text(encoding="utf-8", errors="ignore")
617
+ except OSError:
618
+ unit_source = ""
619
+ all_probes = _battery_probes(file_path, symbol, root)
620
+ rules = load_rules(root / ".bugx") if rules is None else rules
621
+ # L2:执行信号语料 = 本单元源码 + 依赖切片——被调方有 shell 时,
622
+ # 调用方单元也应有差分探针(此前只看本文件导致哨兵漏触发)。
623
+ try:
624
+ dep_sources = [d["source"] for d in dependency_slices(root, file_path, unit_source)]
625
+ except Exception:
626
+ dep_sources = []
627
+ if not file_path.endswith(".py"):
628
+ # 非 Python 资产(yaml/json/md/toml…):文本完整性探针——能解析即为
629
+ # passed 证据,否则该单元会因全是 import 伪影而永久 unverified。
630
+ suffix = file_path.rsplit(".", 1)[-1].lower()
631
+ parser = {"yaml": "yaml.safe_load", "yml": "yaml.safe_load",
632
+ "json": "json.loads"}.get(suffix)
633
+ code = f"import pathlib\nraw = pathlib.Path({file_path!r}).read_text(encoding='utf-8', errors='ignore')\nassert raw.strip(), 'empty asset'\nprint('asset_bytes=%d' % len(raw))"
634
+ if parser:
635
+ code = (f"import pathlib\nraw = pathlib.Path({file_path!r}).read_text(encoding='utf-8', errors='ignore')\nassert raw.strip(), 'empty asset'\n"
636
+ + ("import json\nprint('parsed_items=%d' % len(json.loads(raw)))\n" if suffix == "json" else
637
+ "import yaml\ndata = yaml.safe_load(raw)\nassert data is not None, 'unparsable asset'\nprint('parsed_type=%s' % type(data).__name__)\n"))
638
+ all_probes = all_probes + [{"desc": f"asset-integrity[{suffix or 'text'}] {file_path}", "code": code}]
639
+ if has_exec_signal(unit_source, dep_sources=dep_sources, rules=rules):
640
+ all_probes = all_probes + _differential_probes(file_path, symbol)
641
+ evidence: list[dict[str, Any]] = []
642
+ # 并发修复:探针彼此独立(各起子进程、各写自己的 artifact),串行
643
+ # 8 探针/单元会让大项目 collect 线性膨胀(实测 15 单元 12-14s)。
644
+ # 用线程池并行执行、按 probe 顺序回填,行为与串行逐字节一致。
645
+ def _execute(index_probe: tuple[int, dict[str, str]]) -> tuple[int, dict[str, Any]]:
646
+ index, probe = index_probe
647
+ argv = [sys.executable, "-c", probe["code"]]
648
+ started = time.time()
649
+ try:
650
+ proc = subprocess.run(
651
+ argv, cwd=str(root), capture_output=True, text=True,
652
+ timeout=_PROBE_TIMEOUT_SECONDS, check=False,
653
+ )
654
+ exit_code, out, err = proc.returncode, proc.stdout or "", proc.stderr or ""
655
+ status = "passed" if proc.returncode == 0 else "error"
656
+ except subprocess.TimeoutExpired:
657
+ exit_code, out, err, status = 124, "", "probe timeout", "error"
658
+ record = {
659
+ "schema_version": 1,
660
+ "argv": argv,
661
+ "command": " ".join(argv[:2]) + f" -c <probe:{probe['desc']}>",
662
+ "desc": probe["desc"],
663
+ "exit_code": exit_code,
664
+ "stdout": out[:2000],
665
+ "stderr": err[-2000:],
666
+ "duration_ms": round((time.time() - started) * 1000, 2),
667
+ "execution_id": execution_id,
668
+ "lease_id": lease_id,
669
+ "worker_id": worker_id,
670
+ "run_id": run_id,
671
+ "round_no": round_no,
672
+ "unit_id": unit_id,
673
+ "status": "success" if status == "passed" else "error",
674
+ "timestamp": time.time(),
675
+ "target_fingerprint": target_fingerprint,
676
+ }
677
+ name = f"probe-{hashlib.sha256(probe['desc'].encode()).hexdigest()[:32]}.json"
678
+ path = artifact_root / name
679
+ path.write_text(json.dumps(record, ensure_ascii=False, indent=1), encoding="utf-8")
680
+ os.chmod(path, 0o600)
681
+ rel = path.relative_to(root).as_posix()
682
+ sha = hashlib.sha256(path.read_bytes()).hexdigest()
683
+ return index, {
684
+ "_unit_id": unit_id,
685
+ "command": record["command"],
686
+ "exit_code": exit_code,
687
+ "artifact_path": rel,
688
+ "artifact_sha256": sha,
689
+ "target_fingerprint": target_fingerprint,
690
+ "timestamp": record["timestamp"],
691
+ "worker_id": worker_id,
692
+ "run_id": run_id,
693
+ "round_no": round_no,
694
+ "lease_id": lease_id,
695
+ "status": status,
696
+ "execution_receipt": {
697
+ "schema_version": 1,
698
+ "execution_id": execution_id,
699
+ "worker_id": worker_id,
700
+ "lease_id": lease_id,
701
+ "command": record["command"],
702
+ "exit_code": exit_code,
703
+ "artifact_path": rel,
704
+ "artifact_sha256": sha,
705
+ "status": status,
706
+ },
707
+ "_stdout_excerpt": out[:_MAX_OUTPUT_CHARS],
708
+ "_stderr_excerpt": err[-_MAX_OUTPUT_CHARS:],
709
+ }
710
+
711
+ indexed = list(enumerate(all_probes))
712
+ max_workers = min(8, max(1, len(indexed)))
713
+ try:
714
+ from concurrent.futures import ThreadPoolExecutor
715
+ with ThreadPoolExecutor(max_workers=max_workers) as pool:
716
+ for _index, entry in sorted(pool.map(_execute, indexed)):
717
+ evidence.append(entry)
718
+ except Exception:
719
+ # 线程池异常时回退串行,保证取证不中断
720
+ for pair in indexed:
721
+ _index, entry = _execute(pair)
722
+ evidence.append(entry)
723
+ return evidence
724
+
725
+
726
+ # ---------------------------------------------------------------------------
727
+ # 判读包(judge package):给 AI 的唯一输入
728
+ # ---------------------------------------------------------------------------
729
+
730
+ def dependency_slices(root: Path, file_path: str, source: str) -> list[dict[str, str]]:
731
+ """AST 解析 from-import,附上被引用符号的源码切片(确定性,零模型回合)。
732
+
733
+ 跨单元归因断链的修复:PoC/调用方单元的缺陷实体在被调方文件里,
734
+ judge 只看本单元切片时无法归因(实测:poc_cmdi 的命令注入在
735
+ ops.ping_service,judge 正确拒判 insufficient_data)。本函数把项目内
736
+ 直接依赖的符号切片附进判读包,上限 2 个文件 / 共 4000 字符。
737
+ """
738
+ try:
739
+ tree = ast.parse(source)
740
+ except SyntaxError:
741
+ return []
742
+ slices: list[dict[str, str]] = []
743
+ budget = 4000
744
+ for node in ast.walk(tree):
745
+ if len(slices) >= 2 or budget <= 0:
746
+ break
747
+ if not isinstance(node, ast.ImportFrom) or not node.module:
748
+ continue
749
+ dep_path = node.module.replace(".", "/") + ".py"
750
+ dep_file = Path(root) / dep_path
751
+ if not dep_file.is_file():
752
+ # 同目录相对导入(from . import x / from .mod import x)
753
+ if node.level:
754
+ dep_path = str(Path(file_path).parent / node.module) + ".py"
755
+ dep_file = Path(root) / dep_path
756
+ if not dep_file.is_file():
757
+ continue
758
+ try:
759
+ dep_source = dep_file.read_text(encoding="utf-8", errors="ignore")
760
+ except OSError:
761
+ continue
762
+ for alias in node.names:
763
+ if len(slices) >= 4 or budget <= 0:
764
+ break
765
+ name = alias.name if alias.name != "*" else ""
766
+ piece = symbol_source(dep_source, name)[:budget] if name else dep_source[:budget]
767
+ if not piece.strip():
768
+ continue
769
+ slices.append({"file": dep_path, "symbol": name, "source": piece[:budget]})
770
+ budget -= min(len(piece), budget)
771
+ return slices
772
+
773
+
774
+ def build_package(
775
+ unit_id: str,
776
+ root: Path,
777
+ evidence: list[dict[str, Any]],
778
+ ) -> dict[str, Any] | None:
779
+ """把代码切片 + 依赖切片 + 电池实测压成一个自包含判读包(token 有界)。"""
780
+ file_path, symbol = unit_parts(unit_id)
781
+ target = Path(root) / file_path
782
+ if not target.is_file():
783
+ return None
784
+ try:
785
+ source = target.read_text(encoding="utf-8", errors="ignore")
786
+ except OSError:
787
+ return None
788
+ sliced = symbol_source(source, symbol)[:_MAX_SOURCE_CHARS]
789
+ deps = dependency_slices(root, file_path, source)
790
+ observations = []
791
+ for ev in evidence:
792
+ observations.append({
793
+ "probe": ev.get("command", ""),
794
+ "exit_code": ev.get("exit_code"),
795
+ "stdout": ev.get("_stdout_excerpt") or "",
796
+ "stderr": ev.get("_stderr_excerpt") or "",
797
+ })
798
+ return {
799
+ "schema_version": PACKAGE_VERSION,
800
+ "unit_id": unit_id,
801
+ "file": file_path,
802
+ "symbol": symbol,
803
+ "source": sliced,
804
+ "dependencies": deps,
805
+ "observations": observations,
806
+ }
807
+
808
+
809
+ def package_prompt(package: Mapping[str, Any]) -> str:
810
+ """judge 子代理的完整提示词:数据进、裁决出,一个回合。"""
811
+ payload = json.dumps(package, ensure_ascii=False)
812
+ return (
813
+ "你是 BugX 判读员(judge)。下面是一个覆盖单元的判读包:源码切片、"
814
+ "依赖切片与边界电池的实测输出。你的唯一职责是【判断这份数据】——"
815
+ "不运行命令、不读文件、不碰任何协议,直接给出裁决 JSON。\n\n"
816
+ "裁决优先级阶梯(按此顺序检查,命中即止,禁止跳级展开):\n"
817
+ "L1 结构化行定案:differential 探针输出 SENTINEL=True ⇒ bug(注入实证,"
818
+ "无需其他论证);SENTINEL=False 且 BASE/PAYLOAD 行为一致 ⇒ 该面 clean。\n"
819
+ "L2 契约对照定案:全部探针 exit_code=0 且返回值符合 docstring/参数名契约"
820
+ "⇒ clean。\n"
821
+ "L3 异常归因:崩溃/数据损坏/语义违背 ⇒ bug;异常可由探针伪影解释 ⇒ clean。\n"
822
+ "L4 以上都不成立 ⇒ insufficient_data(注明缺哪条证据)。\n"
823
+ "探针伪影(不是缺陷证据):解绑调用 Class 方法导致的 AttributeError;"
824
+ "symbol-missing;无参函数被边界值等价重复调用产生的一串相同结果。\n"
825
+ "自证文本规则:PoC 源码里硬编码的 'VULNERABILITY CONFIRMED' 类字样"
826
+ "不算独立证据,必须引用实测输出本身。\n"
827
+ "确定性要求:唯一依据是本判读包;同一判读包重复判读必须得到同一裁决。\n"
828
+ "可选反哺:顶层可加 rule_feedback 对象(各≤5项,字符串4-64字符):"
829
+ "risk_tokens=[新风险token...](更严,即时生效);"
830
+ "safe_calls=[可安全直关的调用名...]、artifact_markers=[新探针伪影标记...](更松,"
831
+ "独立出现≥3次才生效)。只在有把握时提供。\n"
832
+ "findings 的 reproduction 必须是一条可直接执行的 python3 单行命令"
833
+ "(可基于 observations 中已验证的探针改写),不得拼接说明文字;"
834
+ "证据行号写源码切片中的真实行号。\n"
835
+ "若判读包含 unit_group 数组,表示该文件的全部这些单元共用本包"
836
+ "证据:verdict 适用于整组,输出 unit_id 用组内主要单元即可"
837
+ "(宿主会按组落账)。\n"
838
+ "若判据不足以定论(verdict=insufficient_data)且缺的是【可机器执行】的"
839
+ "验证,可附 \"probe_requests\"(≤3 条)描述要跑什么:"
840
+ "每条 {\"desc\":\"...\",\"code\":\"...\"},code 为不含 shell 字符的 "
841
+ "python 代码(用换行分隔语句、chr() 构造载荷);宿主会确定性执行并把"
842
+ "结果作为增广证据回给你复审一次(至多一跳)。本包若已带 probe_round 标记,"
843
+ "禁止再提 probe_requests,必须给出终态裁决。\n"
844
+ "若判 bug,请把两条 assert 型验证命令放进对应 finding 内部"
845
+ "(verification_positive/verification_negative 字段,供宿主引擎双跑实证)。"
846
+ "宿主会自动包装 python3 -c,因此只给【纯代码体】,禁止带 python3 -c 外壳:"
847
+ "\"verification_positive\"=漏洞存在时先 print 一行失败观测"
848
+ "(如 print('BUGX_POSITIVE_FAILURE: marker'))再以恰为 1 的退出码退出"
849
+ "(raise SystemExit(1))的 python 代码(例如断言注入产生的副作用/返回行数);"
850
+ "\"verification_negative\"=安全输入下以 0 退出(raise SystemExit(0))的一条代码。"
851
+ "负对照的语义:证明探针本身可靠(普通输入走正常路径不受影响)——"
852
+ "它必须能在【当前带缺陷的代码】上通过,禁止假设修复后的行为或调用"
853
+ "不存在的机制/环境变量/参数(实测坑:为不存在的 env 覆盖写 reload "
854
+ "断言导致负对照必败、整批确认被拒)。"
855
+ "两条代码均不得含 shell 字符(; && || ` $( > <),"
856
+ "请用换行分隔语句、chr() 构造载荷。\n\n"
857
+ "只输出如下 JSON(无其他文字)。JSON 字符串内禁止裸换行等控制字符,"
858
+ "必须用 \\n 转义(宿主按严格 JSON 解析):\n"
859
+ '{"unit_id":"<原样返回>","verdict":"clean|bug|insufficient_data",'
860
+ '"findings":[{"fingerprint":"<file::symbol::短slug>","title":"...",'
861
+ '"severity":"low|medium|high","root_cause":"...",'
862
+ '"evidence":[{"path":"<file>","line":<int>}],'
863
+ '"reproduction":"python3 -c \'...\'"}],'
864
+ '"notes":"<=200字"}\n\n'
865
+ f"判读包(dependencies 是本单元直接调用的项目内符号切片,归因时可作依据):\n{payload}"
866
+ )
867
+
868
+
869
+ # ---------------------------------------------------------------------------
870
+ # 裁决收口:verdict → checkpoint(含复现命令的确定性实跑取证)
871
+ # ---------------------------------------------------------------------------
872
+
873
+ def run_battery_probe(
874
+ root: Path,
875
+ unit_id: str,
876
+ artifact_root: Path,
877
+ lease_id: str,
878
+ execution_id: str,
879
+ worker_id: str,
880
+ run_id: str,
881
+ target_fingerprint: str,
882
+ code: str,
883
+ round_no: int = 1,
884
+ desc: str = "custom",
885
+ ) -> dict[str, Any] | None:
886
+ """执行单条自定义探针并落成带收据的 evidence(业务流冒烟等复用)。"""
887
+ import subprocess
888
+ import time as _t
889
+ root = Path(root).resolve()
890
+ artifact_root = (root / artifact_root).resolve() if not Path(artifact_root).is_absolute() else Path(artifact_root).resolve()
891
+ artifact_root.mkdir(parents=True, exist_ok=True)
892
+ argv = [sys.executable, "-c", code]
893
+ started = _t.time()
894
+ try:
895
+ proc = subprocess.run(argv, cwd=str(root), capture_output=True, text=True,
896
+ timeout=_PROBE_TIMEOUT_SECONDS, check=False)
897
+ exit_code, out, err = proc.returncode, proc.stdout or "", proc.stderr or ""
898
+ except subprocess.TimeoutExpired:
899
+ return None
900
+ record = {
901
+ "schema_version": 1, "argv": argv, "command": f"{sys.executable} -c <probe:{desc}>",
902
+ "desc": desc, "exit_code": exit_code, "stdout": out[:2000],
903
+ "stderr": err[-2000:], "duration_ms": round((_t.time() - started) * 1000, 2),
904
+ "execution_id": execution_id, "lease_id": lease_id, "worker_id": worker_id,
905
+ "run_id": run_id, "round_no": round_no, "unit_id": unit_id,
906
+ "status": "success" if exit_code == 0 else "error",
907
+ "timestamp": _t.time(), "target_fingerprint": target_fingerprint,
908
+ }
909
+ name = f"probe-{hashlib.sha256((unit_id + desc).encode()).hexdigest()[:32]}.json"
910
+ path = artifact_root / name
911
+ path.write_text(json.dumps(record, ensure_ascii=False, indent=1), encoding="utf-8")
912
+ os.chmod(path, 0o600)
913
+ rel = path.relative_to(root).as_posix()
914
+ sha = hashlib.sha256(path.read_bytes()).hexdigest()
915
+ status = "passed" if exit_code == 0 else "error"
916
+ return {
917
+ "_unit_id": unit_id,
918
+ "command": record["command"], "exit_code": exit_code,
919
+ "artifact_path": rel, "artifact_sha256": sha,
920
+ "target_fingerprint": target_fingerprint, "timestamp": record["timestamp"],
921
+ "worker_id": worker_id, "run_id": run_id, "round_no": round_no,
922
+ "lease_id": lease_id, "status": status,
923
+ "execution_receipt": {
924
+ "schema_version": 1, "execution_id": execution_id, "worker_id": worker_id,
925
+ "lease_id": lease_id, "command": record["command"], "exit_code": exit_code,
926
+ "artifact_path": rel, "artifact_sha256": sha, "status": status,
927
+ },
928
+ "_stdout_excerpt": out[:_MAX_OUTPUT_CHARS],
929
+ "_stderr_excerpt": err[-_MAX_OUTPUT_CHARS:],
930
+ }
931
+
932
+
933
+ _PROBE_REQUEST_SHELL_TOKENS = (";", "&&", "||", "`", "$(", ">", "<")
934
+ #: probe_requests 的宿主执行身份是引擎进程——被审项目的恶意内容可能提示
935
+ #: 注入 judge 产出 probe_requests(conventions 消毒同款威胁模型)。shell
936
+ #: 字符黑名单挡不住 `import os` + 换行分隔的 python 逃逸,此处按 AST 拒收
937
+ #: 高危导入与动态执行调用(纵深防御;-c 无沙箱,最终信任边界是宿主)。
938
+ _PROBE_REQUEST_BANNED_MODULES = frozenset({
939
+ "os", "subprocess", "socket", "ctypes", "signal", "importlib",
940
+ "shutil", "sys", "pathlib", "builtins",
941
+ })
942
+ _PROBE_REQUEST_BANNED_CALLS = frozenset({
943
+ "eval", "exec", "compile", "__import__", "open", "globals", "locals",
944
+ })
945
+
946
+
947
+ def _probe_code_escaped_sandbox(code: str) -> bool:
948
+ """True = 代码含逃逸出「观测断言」语义的构造(import 高危模块/动态执行)。"""
949
+ try:
950
+ tree = ast.parse(code)
951
+ except (SyntaxError, ValueError):
952
+ return True
953
+ for node in ast.walk(tree):
954
+ if isinstance(node, ast.Import):
955
+ for alias in node.names:
956
+ if alias.name.split(".")[0] in _PROBE_REQUEST_BANNED_MODULES:
957
+ return True
958
+ elif isinstance(node, ast.ImportFrom):
959
+ if (node.module or "").split(".")[0] in _PROBE_REQUEST_BANNED_MODULES:
960
+ return True
961
+ elif isinstance(node, ast.Call):
962
+ fn = node.func
963
+ name = getattr(fn, "id", None) or getattr(fn, "attr", None)
964
+ if name in _PROBE_REQUEST_BANNED_CALLS:
965
+ return True
966
+ return False
967
+
968
+
969
+ def validate_probe_requests(requests: object) -> list[dict[str, str]]:
970
+ """校验 judge 的 probe_requests:纯 python 代码、禁 shell 字符、有界数量。"""
971
+ if not isinstance(requests, (list, tuple)):
972
+ return []
973
+ out: list[dict[str, str]] = []
974
+ for item in list(requests)[:3]:
975
+ if not isinstance(item, Mapping):
976
+ continue
977
+ code = str(item.get("code") or "").strip()
978
+ desc = str(item.get("desc") or "probe")[:120]
979
+ if not code or any(tok in code for tok in _PROBE_REQUEST_SHELL_TOKENS):
980
+ continue
981
+ # F-RSI-20261112-093:AST 纵深守卫——拒收 import os/subprocess 等
982
+ # 逃逸构造与 eval/exec/open 动态执行(观测断言语义不需要它们)。
983
+ if _probe_code_escaped_sandbox(code):
984
+ print(
985
+ f"[judge] ✗ probe_requests 含越出观测断言语义的构造,已拒收: {desc}",
986
+ file=sys.stderr,
987
+ )
988
+ continue
989
+ out.append({"desc": desc, "code": code})
990
+ return out
991
+
992
+
993
+ def run_probe_requests(
994
+ root: Path,
995
+ unit_id: str,
996
+ artifact_root: Path,
997
+ lease_id: str,
998
+ execution_id: str,
999
+ worker_id: str,
1000
+ run_id: str,
1001
+ target_fingerprint: str,
1002
+ requests: object,
1003
+ round_no: int = 1,
1004
+ ) -> list[dict[str, Any]]:
1005
+ """确定性执行 judge 指定的定向探针,产出带收据的 evidence。
1006
+
1007
+ judge 只描述"要跑什么";执行、sha256、receipt 全在宿主完成,
1008
+ 结果作为增广证据回给 judge 复审(至多一跳)。
1009
+ """
1010
+ evidence: list[dict[str, Any]] = []
1011
+ for req in validate_probe_requests(requests):
1012
+ ev = run_battery_probe(
1013
+ root, unit_id, artifact_root, lease_id, execution_id,
1014
+ worker_id, run_id, target_fingerprint,
1015
+ req["code"], round_no=round_no, desc=f"judge-req {req['desc']}",
1016
+ )
1017
+ if ev is not None:
1018
+ evidence.append(ev)
1019
+ return evidence
1020
+
1021
+
1022
+ def execute_reproduction(
1023
+ root: Path,
1024
+ command: str,
1025
+ artifact_root: Path,
1026
+ lease_id: str,
1027
+ execution_id: str,
1028
+ worker_id: str,
1029
+ run_id: str,
1030
+ target_fingerprint: str,
1031
+ round_no: int = 1,
1032
+ ) -> dict[str, Any] | None:
1033
+ """宿主确定性实跑 judge 给出的复现命令,产出真实收据。
1034
+
1035
+ 这是判读式路径的反伪造锚点:finding 的复现不是「judge 说能跑」,
1036
+ 而是宿主真跑出的 exit_code + artifact。命令必须以 python3 开头,
1037
+ 其余一律拒绝(防注入)。
1038
+ """
1039
+ command = str(command).strip()
1040
+ if not command.startswith("python3 ") and not command.startswith("python3\t"):
1041
+ return None
1042
+ root = Path(root).resolve()
1043
+ artifact_root = (root / artifact_root).resolve() if not Path(artifact_root).is_absolute() else Path(artifact_root).resolve()
1044
+ artifact_root.mkdir(parents=True, exist_ok=True)
1045
+ argv = command.split(" ", 1)
1046
+ # F-RSI-20261112-092:复现脚本的执行边界必须锁定在被审项目 root 内——
1047
+ # judge 给出的相对路径(../)或绝对路径可指向 root 外任意 py 文件
1048
+ # (宿主机脚本/引擎自身代码),越出「复现被审项目缺陷」的边界。
1049
+ if len(argv) > 1:
1050
+ script = Path(argv[1])
1051
+ script = (root / script).resolve() if not script.is_absolute() else script.resolve()
1052
+ if script != root and root not in script.parents:
1053
+ print(
1054
+ f"[judge] ✗ 复现命令越界拒绝:{argv[1]} 不在项目 root 内",
1055
+ file=sys.stderr,
1056
+ )
1057
+ return None
1058
+ started = time.time()
1059
+ try:
1060
+ proc = subprocess.run(
1061
+ [sys.executable, argv[1]] if argv[0] == "python3" else argv,
1062
+ cwd=str(root), capture_output=True, text=True,
1063
+ timeout=_PROBE_TIMEOUT_SECONDS, check=False,
1064
+ )
1065
+ exit_code, out, err = proc.returncode, proc.stdout or "", proc.stderr or ""
1066
+ except subprocess.TimeoutExpired:
1067
+ return None
1068
+ record = {
1069
+ "schema_version": 1, "argv": [sys.executable, argv[1]] if len(argv) > 1 else [sys.executable],
1070
+ "command": command, "exit_code": exit_code,
1071
+ "stdout": out[:2000], "stderr": err[-2000:],
1072
+ "duration_ms": round((time.time() - started) * 1000, 2),
1073
+ "execution_id": execution_id, "lease_id": lease_id,
1074
+ "worker_id": worker_id, "run_id": run_id, "round_no": round_no,
1075
+ "status": "success" if exit_code == 0 else "error",
1076
+ "timestamp": time.time(), "target_fingerprint": target_fingerprint,
1077
+ }
1078
+ name = f"probe-{uuid.uuid4().hex}.json"
1079
+ path = artifact_root / name
1080
+ path.write_text(json.dumps(record, ensure_ascii=False, indent=1), encoding="utf-8")
1081
+ os.chmod(path, 0o600)
1082
+ rel = path.relative_to(root).as_posix()
1083
+ sha = hashlib.sha256(path.read_bytes()).hexdigest()
1084
+ status = "passed" if exit_code == 0 else "failed"
1085
+ return {
1086
+ "command": command, "exit_code": exit_code,
1087
+ "artifact_path": rel, "artifact_sha256": sha,
1088
+ "target_fingerprint": target_fingerprint,
1089
+ "timestamp": record["timestamp"], "worker_id": worker_id,
1090
+ "run_id": run_id, "round_no": round_no, "lease_id": lease_id,
1091
+ "status": status,
1092
+ "execution_receipt": {
1093
+ "schema_version": 1, "execution_id": execution_id,
1094
+ "worker_id": worker_id, "lease_id": lease_id,
1095
+ "command": command, "exit_code": exit_code,
1096
+ "artifact_path": rel, "artifact_sha256": sha, "status": status,
1097
+ },
1098
+ "_stdout_excerpt": out[:_MAX_OUTPUT_CHARS],
1099
+ "_stderr_excerpt": err[-_MAX_OUTPUT_CHARS:],
1100
+ }
1101
+
1102
+
1103
+ def parse_verdict(text: str, unit_id: str) -> dict[str, Any]:
1104
+ """从 judge 的回复文本解析裁决 JSON(宽容前后噪声,fail-closed 默认)。"""
1105
+ text = str(text or "").strip()
1106
+ start = text.find("{")
1107
+ end = text.rfind("}")
1108
+ if start < 0 or end <= start:
1109
+ return {"unit_id": unit_id, "verdict": "insufficient_data", "findings": [],
1110
+ "notes": "judge output contained no JSON"}
1111
+ try:
1112
+ data = json.loads(text[start:end + 1])
1113
+ except ValueError:
1114
+ # judge 自写裁决常见裸控制字符(字符串里嵌字面换行)——宽容复解析,
1115
+ # 避免"judge output JSON unparsable"静默降级吞掉真实裁决。
1116
+ try:
1117
+ data = json.loads(text[start:end + 1], strict=False)
1118
+ except ValueError:
1119
+ return {"unit_id": unit_id, "verdict": "insufficient_data", "findings": [],
1120
+ "notes": "judge output JSON unparsable"}
1121
+ verdict = str(data.get("verdict") or "insufficient_data")
1122
+ if verdict not in _VERDICT_STATUSES:
1123
+ verdict = "insufficient_data"
1124
+ data["verdict"] = verdict
1125
+ data["unit_id"] = unit_id
1126
+ data.setdefault("findings", [])
1127
+ data.setdefault("notes", "")
1128
+ return data
1129
+
1130
+
1131
+ def checkpoint_payload_from_verdict(
1132
+ claim: Mapping[str, Any],
1133
+ verdict: Mapping[str, Any],
1134
+ battery_evidence: list[dict[str, Any]],
1135
+ reproduction_evidence: dict[str, Any] | None,
1136
+ ) -> dict[str, Any] | None:
1137
+ """把裁决映射成 supervisor checkpoint payload(机器构造,无手搓)。
1138
+
1139
+ - clean 且电池/复现证据可绑定 → 全单元 covered(结构化证据落账)
1140
+ - insufficient_data → 全单元 unverified(judge 明确拒判:不得以电池
1141
+ 探针通过冒充已覆盖;artifact_only 例外记 not_applicable)
1142
+ - bug → 单元 covered,findings 附带,且每条 finding 的复现收据
1143
+ (宿主实跑)优先作为该单元 evidence;无复现收据时回退电池 evidence,
1144
+ finding 标记 reproducible=false。
1145
+ """
1146
+ unit_ids = list(claim.get("unit_ids") or [])
1147
+ if not unit_ids:
1148
+ return None
1149
+ findings: list[dict[str, Any]] = []
1150
+ verify_hints = verdict.get("verification") if isinstance(
1151
+ verdict.get("verification"), Mapping) else {}
1152
+ for item in (verdict.get("findings") or [])[:5]:
1153
+ if not isinstance(item, Mapping):
1154
+ continue
1155
+ finding = {
1156
+ "fingerprint": str(item.get("fingerprint") or "")[:256] or None,
1157
+ "title": str(item.get("title") or "")[:2000],
1158
+ "severity": str(item.get("severity") or "low"),
1159
+ "root_cause": str(item.get("root_cause") or "")[:4000],
1160
+ "evidence": [dict(e) for e in (item.get("evidence") or []) if isinstance(e, Mapping)][:5],
1161
+ "reproducible": bool(reproduction_evidence),
1162
+ # PE-20261109-002:finding 必须携带来源单元链接。判读包契约是
1163
+ # "verdict 适用于整组"——poc 型证据的 covered 单元在结算校验
1164
+ # (checkpoint_sync/post_coverage_sync)里靠 unit_id/target_units
1165
+ # 找关联 finding;缺失时整轮 post 被 fail-closed 拒绝(实测
1166
+ # bugx-audit-zcode 2026-11-09:files.py 变体归并后结算死锁)。
1167
+ "target_units": list(unit_ids),
1168
+ }
1169
+ if item.get("reproduction"):
1170
+ finding["reproduction"] = str(item["reproduction"])[:4000]
1171
+ pos = verify_hints.get("verification_positive") or item.get("verification_positive")
1172
+ neg = verify_hints.get("verification_negative") or item.get("verification_negative")
1173
+ if pos and neg:
1174
+ finding["verification_hints"] = {
1175
+ "positive": str(pos)[:4000], "negative": str(neg)[:4000],
1176
+ }
1177
+ if finding["fingerprint"] and finding["title"]:
1178
+ findings.append(finding)
1179
+ evidence: dict[str, dict[str, Any]] = {}
1180
+ primary_unit = str(claim.get("primary_unit") or (unit_ids[0] if unit_ids else ""))
1181
+ for unit in unit_ids:
1182
+ # 每单元独立 artifact:优先本单元自己的 passed 探针;复现收据只能
1183
+ # 给主单元(单文件单 artifact,不能跨单元复用——validator 硬约束)。
1184
+ own = [
1185
+ e for e in battery_evidence
1186
+ if e.get("_unit_id") == unit
1187
+ and e.get("status") == "passed" and e.get("exit_code") == 0
1188
+ ]
1189
+ chosen = None
1190
+ if unit == primary_unit and reproduction_evidence is not None:
1191
+ chosen = reproduction_evidence
1192
+ elif own:
1193
+ chosen = own[0]
1194
+ elif len(unit_ids) == 1:
1195
+ chosen = reproduction_evidence or next(
1196
+ (e for e in battery_evidence if e.get("status") == "passed"), None)
1197
+ if chosen is None:
1198
+ continue
1199
+ entry = {k: v for k, v in chosen.items() if not k.startswith("_")}
1200
+ # 复现命令按设计失败(exit!=0)时声明 reproduction_poc,并挂接 finding
1201
+ if (entry.get("exit_code") != 0
1202
+ and chosen is reproduction_evidence
1203
+ and findings):
1204
+ entry["evidence_type"] = "reproduction_poc"
1205
+ for finding in findings:
1206
+ finding.setdefault("unit_id", unit)
1207
+ evidence[unit] = entry
1208
+ if len(evidence) < len(unit_ids) or str(verdict.get("verdict")) == "insufficient_data":
1209
+ # insufficient_data 是 judge 的明确拒判:单元只能记 unverified,
1210
+ # 不得以电池探针通过冒充已覆盖(实测踩过:poc_cmdi 判据不足被记 covered)。
1211
+ # 例外:artifact-only(全部探针均为已知伪影,单元在电池上下文不可探测)
1212
+ # 记 not_applicable 终态——记 unverified 会被 pending 过滤器永久重领,
1213
+ # 每轮白烧一遍电池(实测 2026-11-04 会话)。
1214
+ if bool(verdict.get("artifact_only")):
1215
+ coverage = {unit: "not_applicable" for unit in unit_ids}
1216
+ else:
1217
+ coverage = {unit: "unverified" for unit in unit_ids}
1218
+ evidence = {}
1219
+ else:
1220
+ coverage = {unit: "covered" for unit in unit_ids}
1221
+ tokens = verdict.get("tokens")
1222
+ if isinstance(tokens, bool) or not isinstance(tokens, int) or tokens <= 0:
1223
+ tokens = None
1224
+ if tokens:
1225
+ # judge 判读员的 token 消耗由宿主写进 verdict["tokens"](来自 Agent
1226
+ # 结果的 subagent_tokens);checkpoint_sync 从 evidence 条目的
1227
+ # tokens_consumed 汇总进 claim 账本——只记主单元一次,多单元组重复
1228
+ # 记账会被 summation 放大。无 evidence 条目(artifact-only /
1229
+ # insufficient_data)时无处挂账,诚实丢弃。
1230
+ primary = next(iter(evidence), None)
1231
+ if primary is not None:
1232
+ evidence[primary]["tokens_consumed"] = int(tokens)
1233
+ return {
1234
+ "checkpoint_id": f"judge-{claim.get('worker_id')}-{uuid.uuid4().hex[:8]}",
1235
+ "coverage": coverage,
1236
+ "evidence": evidence,
1237
+ "findings": findings,
1238
+ "life_delta": 0,
1239
+ }
1240
+
1241
+
1242
+ __all__ = [
1243
+ "unit_parts", "symbol_source", "run_battery", "build_package",
1244
+ "package_prompt", "parse_verdict", "execute_reproduction",
1245
+ "checkpoint_payload_from_verdict",
1246
+ ]