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,1351 @@
1
+ #!/usr/bin/env python3
2
+ """Deterministic, bounded graph orchestration for native BugX agents.
3
+
4
+ The engine owns graph state, immutable input snapshots, artifact receipts, and
5
+ controlled checks. It does not launch native agents or call host UI APIs; the
6
+ Host MCP channel binds native agent identities and dispatches the returned
7
+ Task prompt through its own native interface.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import base64
13
+ import contextlib
14
+ import datetime as dt
15
+ import hashlib
16
+ import json
17
+ import os
18
+ import re
19
+ import shutil
20
+ import signal
21
+ import stat
22
+ import subprocess
23
+ import sys
24
+ import tempfile
25
+ import threading
26
+ import time
27
+ import uuid
28
+ from pathlib import Path, PurePosixPath
29
+ from typing import Any, Iterator, Mapping, Sequence
30
+
31
+ try:
32
+ import fcntl
33
+ except ImportError: # pragma: no cover - Windows uses msvcrt.
34
+ fcntl = None # type: ignore[assignment]
35
+
36
+ try:
37
+ import msvcrt
38
+ except ImportError: # pragma: no cover - POSIX uses fcntl.
39
+ msvcrt = None # type: ignore[assignment]
40
+
41
+ try:
42
+ import core.bugx_paths as bugx_paths
43
+ except ImportError:
44
+ from core import bugx_paths
45
+
46
+ try:
47
+ import core.secure_atomic as secure_atomic
48
+ except ImportError:
49
+ from core import secure_atomic
50
+
51
+
52
+ SCHEMA_VERSION = 1
53
+ MAX_ATTEMPTS = 3
54
+ MAX_CONCURRENCY = 16
55
+ MAX_SPEC_BYTES = 64 * 1024
56
+ MAX_TASK_TEXT_LENGTH = 8 * 1024
57
+ MAX_TARGET_FILES = 100
58
+ MAX_SNAPSHOT_FILES = 100_000
59
+ MAX_SNAPSHOT_BYTES = 2 * 1024 * 1024 * 1024
60
+ MAX_CONTEXT_FILE_BYTES = 512 * 1024
61
+ MAX_CONTEXT_BYTES = 4 * 1024 * 1024
62
+ MAX_ENVELOPE_BYTES = 128 * 1024
63
+ MAX_ATTACHMENT_BYTES = 256 * 1024
64
+ MAX_ATTACHMENTS_BYTES = 300 * 1024
65
+ MAX_CHECK_FILES = 20
66
+ MAX_CHECK_TIMEOUT_SECONDS = 300
67
+ MAX_CHECK_OUTPUT_BYTES = 32 * 1024
68
+ GRAPH_ID_RE = re.compile(r"^[0-9a-f]{32}$")
69
+ SHA256_RE = re.compile(r"^[0-9a-f]{64}$")
70
+ NATIVE_AGENT_ID_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_.:@/-]{0,255}$")
71
+ STAGES = ("Recon", "Repro", "Review", "Patch", "Check", "Report")
72
+ ACTIVE_TASK_STATES = frozenset({"assigned", "running"})
73
+ RESERVED_TASK_STATES = frozenset({"offered", *ACTIVE_TASK_STATES})
74
+ TERMINAL_TASK_STATES = frozenset({"complete", "failed", "cancelled", "superseded"})
75
+ IGNORED_NAMES = frozenset({
76
+ ".bugx", ".git", ".hg", ".svn", ".DS_Store", "node_modules", "venv",
77
+ ".venv", "__pycache__", ".pytest_cache", ".mypy_cache", ".tox",
78
+ })
79
+
80
+ STAGE_INSTRUCTIONS = {
81
+ "Recon": (
82
+ "Inspect the immutable project snapshot and identify concrete candidate behavior. "
83
+ "Do not modify source files. Keep observations separate from hypotheses."
84
+ ),
85
+ "Repro": (
86
+ "Produce a minimal, repeatable reproduction for the candidate using the snapshot. "
87
+ "Do not modify source files and preserve exact commands, inputs, and observed output."
88
+ ),
89
+ "Review": (
90
+ "Independently review the candidate and reproduction artifacts. Verify the claimed "
91
+ "cause, scope, and evidence. Do not rely on the producer's conclusion alone."
92
+ ),
93
+ "Patch": (
94
+ "Apply the smallest change needed to address the reviewed issue, staying inside the "
95
+ "declared modification and ownership boundaries. Preserve all stated invariants."
96
+ ),
97
+ "Check": (
98
+ "Submit a bounded CheckPlan with tests under tests/ using graph_run_check. Do not "
99
+ "claim a check passed without its returned Observation."
100
+ ),
101
+ "Report": (
102
+ "Compile the final report from checkpointed artifacts and Observations. Clearly mark "
103
+ "unsupported or unverified claims; do not invent host or runtime evidence."
104
+ ),
105
+ }
106
+
107
+
108
+ class GraphError(RuntimeError):
109
+ """Invalid graph transition, identity, or bounded input."""
110
+
111
+
112
+ def _now() -> str:
113
+ return dt.datetime.now(dt.timezone.utc).isoformat(timespec="milliseconds")
114
+
115
+
116
+ def _canonical_json(value: object) -> bytes:
117
+ return json.dumps(
118
+ value, ensure_ascii=False, sort_keys=True, separators=(",", ":"),
119
+ ).encode("utf-8")
120
+
121
+
122
+ def _text(value: object, name: str, *, maximum: int = MAX_TASK_TEXT_LENGTH) -> str:
123
+ if not isinstance(value, str) or not value.strip():
124
+ raise GraphError(f"{name} 必须是非空字符串")
125
+ if len(value) > maximum:
126
+ raise GraphError(f"{name} 过长(>{maximum})")
127
+ return value
128
+
129
+
130
+ def _string_list(
131
+ value: object, name: str, *, minimum: int = 0, maximum: int = 64,
132
+ ) -> list[str]:
133
+ if not isinstance(value, list) or len(value) < minimum or len(value) > maximum:
134
+ raise GraphError(f"{name} 必须是 {minimum}..{maximum} 项字符串数组")
135
+ result = []
136
+ for index, item in enumerate(value):
137
+ result.append(_text(item, f"{name}[{index}]"))
138
+ return result
139
+
140
+
141
+ def _safe_relative_path(value: object, name: str = "path") -> str:
142
+ if not isinstance(value, str) or not value or len(value) > 512:
143
+ raise GraphError(f"{name} 必须是非空相对路径")
144
+ if "\\" in value or "\x00" in value or ":" in value:
145
+ raise GraphError(f"{name} 格式无效")
146
+ path = PurePosixPath(value)
147
+ if path.is_absolute() or any(part in {"", ".", ".."} for part in path.parts):
148
+ raise GraphError(f"{name} 必须是规范化的项目相对路径")
149
+ if any(part in IGNORED_NAMES for part in path.parts):
150
+ raise GraphError(f"{name} 位于被排除的项目目录")
151
+ normalized = path.as_posix()
152
+ if normalized != value:
153
+ raise GraphError(f"{name} 必须是规范化的项目相对路径")
154
+ return normalized
155
+
156
+
157
+ def _normalize_task_input(arguments: Mapping[str, object]) -> dict[str, object]:
158
+ target_files = _string_list(
159
+ arguments.get("target_files"), "target_files", minimum=1,
160
+ maximum=MAX_TARGET_FILES,
161
+ )
162
+ normalized_paths = [_safe_relative_path(item, "target_files") for item in target_files]
163
+ if len(set(normalized_paths)) != len(normalized_paths):
164
+ raise GraphError("target_files 不得包含重复路径")
165
+ patch_requested = arguments.get("patch_requested", False)
166
+ if not isinstance(patch_requested, bool):
167
+ raise GraphError("patch_requested 必须是布尔值")
168
+ concurrency = arguments.get("max_concurrency", 1)
169
+ if isinstance(concurrency, bool) or not isinstance(concurrency, int):
170
+ raise GraphError("max_concurrency 必须是整数")
171
+ if not 1 <= concurrency <= MAX_CONCURRENCY:
172
+ raise GraphError(f"max_concurrency 必须位于 1..{MAX_CONCURRENCY}")
173
+ value: dict[str, object] = {
174
+ "target": _text(arguments.get("target"), "target", maximum=2048),
175
+ "goal": _text(arguments.get("goal"), "goal"),
176
+ "modifications": _string_list(arguments.get("modifications"), "modifications", minimum=1),
177
+ "invariants": _string_list(arguments.get("invariants"), "invariants", minimum=1),
178
+ "ownership_boundaries": _string_list(
179
+ arguments.get("ownership_boundaries"), "ownership_boundaries", minimum=1,
180
+ ),
181
+ "acceptance_criteria": _string_list(
182
+ arguments.get("acceptance_criteria"), "acceptance_criteria", minimum=1,
183
+ ),
184
+ "target_files": normalized_paths,
185
+ "patch_requested": patch_requested,
186
+ "max_concurrency": concurrency,
187
+ }
188
+ if len(_canonical_json(value)) > MAX_SPEC_BYTES:
189
+ raise GraphError(f"Task Spec 超过 {MAX_SPEC_BYTES} 字节")
190
+ return value
191
+
192
+
193
+ def assemble_task_prompt(
194
+ task_input: Mapping[str, object], stage: str, attempt: int,
195
+ feedback: Mapping[str, object] | None = None,
196
+ ) -> str:
197
+ """Assemble one canonical, self-contained native Task prompt.
198
+
199
+ All caller-authored lines are included verbatim. A single function is
200
+ shared by initial tasks and revision attempts so neither path silently
201
+ drops scope, invariants, ownership, or acceptance evidence.
202
+ """
203
+ if stage not in STAGE_INSTRUCTIONS:
204
+ raise GraphError(f"未知 Graph 阶段: {stage}")
205
+ sections = [
206
+ "BugX native Task",
207
+ f"Stage: {stage} (attempt {attempt}/{MAX_ATTEMPTS})",
208
+ f"Stage objective: {STAGE_INSTRUCTIONS[stage]}",
209
+ f"Target: {task_input['target']}",
210
+ f"Goal: {task_input['goal']}",
211
+ "Requested modifications (verbatim):",
212
+ *[f"- {item}" for item in task_input["modifications"]],
213
+ "Invariants (must remain true):",
214
+ *[f"- {item}" for item in task_input["invariants"]],
215
+ "Ownership boundaries:",
216
+ *[f"- {item}" for item in task_input["ownership_boundaries"]],
217
+ "Observable acceptance criteria:",
218
+ *[f"- {item}" for item in task_input["acceptance_criteria"]],
219
+ "Declared snapshot files:",
220
+ *[f"- {item}" for item in task_input["target_files"]],
221
+ "Execution boundaries:",
222
+ "- Work only in the graph's private snapshot workspace.",
223
+ "- Do not call host UI APIs or claim that a native host action occurred.",
224
+ "- Do not invent observations, test results, identities, or artifact contents.",
225
+ "- Return a checkpoint with concrete evidence and an explicit outcome.",
226
+ ]
227
+ if feedback is not None:
228
+ sections.extend([
229
+ "Revision feedback from the previous attempt (verbatim):",
230
+ f"Reason: {feedback.get('reason', '')}",
231
+ "Context:",
232
+ json.dumps(feedback.get("context", {}), ensure_ascii=False, sort_keys=True),
233
+ ])
234
+ return "\n".join(sections)
235
+
236
+
237
+ def _new_task(
238
+ state: dict[str, Any], stage: str, attempt: int,
239
+ dependencies: Sequence[str], feedback: Mapping[str, object] | None = None,
240
+ ) -> dict[str, Any]:
241
+ graph_id = state["graph_id"]
242
+ task_id = "task_" + hashlib.sha256(
243
+ f"{graph_id}:{stage}:{attempt}".encode("utf-8")
244
+ ).hexdigest()[:24]
245
+ task_input = state["task_input"]
246
+ return {
247
+ "task_id": task_id,
248
+ "stage": stage,
249
+ "attempt": attempt,
250
+ "dependencies": list(dependencies),
251
+ "status": "pending",
252
+ "native_agent_id": None,
253
+ "fencing_token": 0,
254
+ "created_at": _now(),
255
+ "started_at": None,
256
+ "finished_at": None,
257
+ "feedback": dict(feedback or {}),
258
+ "prompt": assemble_task_prompt(task_input, stage, attempt, feedback),
259
+ "check_observation": None,
260
+ "checkpoint": None,
261
+ "failure_context": None,
262
+ }
263
+
264
+
265
+ def _copy_snapshot(source: Path, destination: Path) -> dict[str, object]:
266
+ """Copy regular project files into a private workspace without following links."""
267
+ if not source.is_dir() or source.is_symlink():
268
+ raise GraphError(f"snapshot source is not a regular directory: {source}")
269
+ source = source.resolve()
270
+ destination = Path(os.path.abspath(str(destination)))
271
+ try:
272
+ destination.relative_to(source)
273
+ except ValueError:
274
+ pass
275
+ else:
276
+ raise GraphError("graph private root must be outside the source project")
277
+ destination.mkdir(mode=0o700, parents=True, exist_ok=False)
278
+ count = 0
279
+ total_bytes = 0
280
+ excluded_links: list[str] = []
281
+ try:
282
+ for current, dirs, files in os.walk(source, topdown=True, followlinks=False):
283
+ current_path = Path(current)
284
+ relative_dir = current_path.relative_to(source)
285
+ kept_dirs: list[str] = []
286
+ for name in sorted(dirs):
287
+ if name in IGNORED_NAMES:
288
+ continue
289
+ source_dir = current_path / name
290
+ if source_dir.is_symlink():
291
+ if len(excluded_links) < 1000:
292
+ excluded_links.append((relative_dir / name).as_posix())
293
+ continue
294
+ kept_dirs.append(name)
295
+ dirs[:] = kept_dirs
296
+ target_dir = destination / relative_dir
297
+ target_dir.mkdir(mode=0o700, parents=True, exist_ok=True)
298
+ for name in sorted(files):
299
+ if name in IGNORED_NAMES:
300
+ continue
301
+ source_file = current_path / name
302
+ relative = source_file.relative_to(source)
303
+ if source_file.is_symlink():
304
+ if len(excluded_links) < 1000:
305
+ excluded_links.append(relative.as_posix())
306
+ continue
307
+ try:
308
+ info = source_file.stat(follow_symlinks=False)
309
+ except OSError as exc:
310
+ raise GraphError(f"无法安全读取 snapshot 文件 {relative}: {exc}") from exc
311
+ if not source_file.is_file() or source_file.is_symlink():
312
+ continue
313
+ if info.st_size < 0 or total_bytes + info.st_size > MAX_SNAPSHOT_BYTES:
314
+ raise GraphError(f"snapshot 超过 {MAX_SNAPSHOT_BYTES} 字节")
315
+ count += 1
316
+ if count > MAX_SNAPSHOT_FILES:
317
+ raise GraphError(f"snapshot 文件数超过 {MAX_SNAPSHOT_FILES}")
318
+ target_file = destination / relative
319
+ target_file.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
320
+ flags = os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0)
321
+ source_fd: int | None = None
322
+ target_fd: int | None = None
323
+ try:
324
+ source_fd = os.open(source_file, flags)
325
+ source_stat = os.fstat(source_fd)
326
+ if not stat.S_ISREG(source_stat.st_mode):
327
+ raise GraphError(f"snapshot 仅接受普通文件: {relative}")
328
+ target_fd = os.open(
329
+ target_file,
330
+ os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, "O_NOFOLLOW", 0),
331
+ 0o600,
332
+ )
333
+ with os.fdopen(source_fd, "rb", closefd=False) as src, os.fdopen(
334
+ target_fd, "wb", closefd=False,
335
+ ) as dst:
336
+ remaining = MAX_SNAPSHOT_BYTES - total_bytes
337
+ while True:
338
+ block = src.read(min(1024 * 1024, remaining + 1))
339
+ if not block:
340
+ break
341
+ total_bytes += len(block)
342
+ if total_bytes > MAX_SNAPSHOT_BYTES:
343
+ raise GraphError(f"snapshot 超过 {MAX_SNAPSHOT_BYTES} 字节")
344
+ dst.write(block)
345
+ dst.flush()
346
+ os.fsync(dst.fileno())
347
+ try:
348
+ os.chmod(target_file, 0o700 if source_stat.st_mode & 0o111 else 0o600)
349
+ except OSError:
350
+ pass
351
+ finally:
352
+ if source_fd is not None:
353
+ os.close(source_fd)
354
+ if target_fd is not None:
355
+ os.close(target_fd)
356
+ return {
357
+ "file_count": count,
358
+ "bytes": total_bytes,
359
+ "excluded_symlinks": excluded_links,
360
+ "excluded_symlinks_truncated": len(excluded_links) >= 1000,
361
+ }
362
+ except BaseException:
363
+ shutil.rmtree(destination, ignore_errors=True)
364
+ raise
365
+
366
+
367
+ _LOCKS_GUARD = threading.Lock()
368
+ _LOCKS: dict[Path, threading.RLock] = {}
369
+
370
+
371
+ class AgentOrchestrator:
372
+ """Persist and advance one deterministic Recon→Report task graph."""
373
+
374
+ def __init__(self, private_root: Path, graph_id: str) -> None:
375
+ if not isinstance(graph_id, str) or not GRAPH_ID_RE.fullmatch(graph_id):
376
+ raise GraphError("graph_id 格式无效")
377
+ self.private_root = Path(private_root).expanduser()
378
+ self.graph_id = graph_id
379
+ self.run_dir = self.private_root / graph_id
380
+ self.state_path = self.run_dir / "graph.json"
381
+ self.lock_path = self.run_dir / "graph.lock"
382
+ self.workspace = self.run_dir / "workspace"
383
+
384
+ @classmethod
385
+ def start(
386
+ cls, source_root: Path, private_root: Path, task_input: Mapping[str, object],
387
+ ) -> tuple["AgentOrchestrator", dict[str, Any]]:
388
+ source = Path(source_root).expanduser().resolve()
389
+ private = Path(private_root).expanduser()
390
+ bugx_paths.assert_no_symlink_components(private)
391
+ private.mkdir(mode=0o700, parents=True, exist_ok=True)
392
+ try:
393
+ private_resolved = private.resolve(strict=True)
394
+ private_resolved.relative_to(source)
395
+ except ValueError:
396
+ pass
397
+ else:
398
+ raise GraphError("graph private root must be outside the source project")
399
+ if private_resolved == source:
400
+ raise GraphError("graph private root must be outside the source project")
401
+ graph_id = uuid.uuid4().hex
402
+ run_dir = private_resolved / graph_id
403
+ run_dir.mkdir(mode=0o700, parents=False, exist_ok=False)
404
+ orchestrator = cls(private_resolved, graph_id)
405
+ try:
406
+ manifest = _copy_snapshot(source, orchestrator.workspace)
407
+ for relative in task_input["target_files"]:
408
+ target_path = orchestrator.workspace / relative
409
+ if target_path.is_symlink() or not target_path.is_file():
410
+ raise GraphError(f"声明的 snapshot 文件缺失或不安全: {relative}")
411
+ first_task = _new_task({"graph_id": graph_id, "task_input": dict(task_input)}, "Recon", 1, [])
412
+ state: dict[str, Any] = {
413
+ "schema_version": SCHEMA_VERSION,
414
+ "graph_id": graph_id,
415
+ # F-RSI-20261115-144:这是【源路径字符串】的指纹,不是源内容哈希——
416
+ # 源完整性由 snapshot manifest(逐文件 sha256)承载。旧名
417
+ # source_root_sha256 会误导为内容锚;全仓无校验消费(仅报告回显),
418
+ # 破坏性改名安全。
419
+ "source_root_path_fingerprint": hashlib.sha256(
420
+ str(source).encode("utf-8")).hexdigest(),
421
+ "workspace": str(orchestrator.workspace),
422
+ "created_at": _now(),
423
+ "updated_at": _now(),
424
+ "revision": 1,
425
+ "status": "running",
426
+ "task_input": dict(task_input),
427
+ "snapshot": manifest,
428
+ "max_concurrency": int(task_input["max_concurrency"]),
429
+ "tasks": [first_task],
430
+ "events": [{"event": "graph_started", "at": _now()}],
431
+ "final_report": None,
432
+ }
433
+ with orchestrator._file_lock():
434
+ orchestrator._save_unlocked(state)
435
+ return orchestrator, first_task
436
+ except BaseException:
437
+ shutil.rmtree(run_dir, ignore_errors=True)
438
+ raise
439
+
440
+ @classmethod
441
+ def open(cls, private_root: Path, graph_id: str) -> "AgentOrchestrator":
442
+ instance = cls(private_root, graph_id)
443
+ bugx_paths.assert_no_symlink_components(instance.run_dir)
444
+ if instance.run_dir.is_symlink() or not instance.run_dir.is_dir():
445
+ raise GraphError(f"graph 不存在: {graph_id}")
446
+ return instance
447
+
448
+ @contextlib.contextmanager
449
+ def _file_lock(self) -> Iterator[None]:
450
+ bugx_paths.assert_no_symlink_components(self.run_dir)
451
+ if self.run_dir.is_symlink() or not self.run_dir.is_dir():
452
+ raise GraphError(f"graph 不存在或不安全: {self.graph_id}")
453
+ with _LOCKS_GUARD:
454
+ thread_lock = _LOCKS.setdefault(self.lock_path, threading.RLock())
455
+ with thread_lock:
456
+ flags = os.O_RDWR | os.O_CREAT | getattr(os, "O_NOFOLLOW", 0)
457
+ try:
458
+ descriptor = os.open(self.lock_path, flags, 0o600)
459
+ except OSError as exc:
460
+ raise GraphError(f"无法安全打开 graph lock: {exc}") from exc
461
+ try:
462
+ if fcntl is not None:
463
+ fcntl.flock(descriptor, fcntl.LOCK_EX)
464
+ elif msvcrt is not None:
465
+ if os.fstat(descriptor).st_size == 0:
466
+ os.write(descriptor, b"0")
467
+ os.lseek(descriptor, 0, os.SEEK_SET)
468
+ msvcrt.locking(descriptor, msvcrt.LK_LOCK, 1)
469
+ else: # pragma: no cover - unsupported platform.
470
+ raise GraphError("当前平台不支持 graph 跨进程锁")
471
+ yield
472
+ finally:
473
+ try:
474
+ if fcntl is not None:
475
+ fcntl.flock(descriptor, fcntl.LOCK_UN)
476
+ elif msvcrt is not None:
477
+ os.lseek(descriptor, 0, os.SEEK_SET)
478
+ msvcrt.locking(descriptor, msvcrt.LK_UNLCK, 1)
479
+ finally:
480
+ os.close(descriptor)
481
+
482
+ def _load_unlocked(self) -> dict[str, Any]:
483
+ if self.state_path.is_symlink() or not self.state_path.is_file():
484
+ raise GraphError("graph state 缺失或不安全")
485
+ try:
486
+ raw = self.state_path.read_bytes()
487
+ if len(raw) > 16 * 1024 * 1024:
488
+ raise GraphError("graph state 超过大小限制")
489
+ state = json.loads(raw.decode("utf-8"))
490
+ except (OSError, UnicodeError, json.JSONDecodeError) as exc:
491
+ raise GraphError(f"graph state 无法读取: {exc}") from exc
492
+ if not isinstance(state, dict) or state.get("schema_version") != SCHEMA_VERSION:
493
+ raise GraphError("graph state schema 无效")
494
+ if state.get("graph_id") != self.graph_id or not isinstance(state.get("tasks"), list):
495
+ raise GraphError("graph state 身份或任务列表无效")
496
+ return state
497
+
498
+ def _save_unlocked(self, state: dict[str, Any]) -> None:
499
+ state["revision"] = int(state.get("revision", 0)) + 1
500
+ state["updated_at"] = _now()
501
+ try:
502
+ secure_atomic.atomic_write_json(
503
+ self.state_path, state, mode=0o600, parent_mode=0o700,
504
+ )
505
+ except (OSError, ValueError, TypeError) as exc:
506
+ raise GraphError(f"graph state 写入失败: {exc}") from exc
507
+
508
+ def snapshot(self) -> dict[str, Any]:
509
+ with self._file_lock():
510
+ return self._load_unlocked()
511
+
512
+ @staticmethod
513
+ def _task(state: Mapping[str, Any], task_id: object) -> dict[str, Any]:
514
+ if not isinstance(task_id, str) or not task_id:
515
+ raise GraphError("task_id 必须是非空字符串")
516
+ for task in state["tasks"]:
517
+ if task.get("task_id") == task_id:
518
+ return task
519
+ raise GraphError(f"task 不属于当前 graph: {task_id}")
520
+
521
+ @staticmethod
522
+ def _dependencies_complete(state: Mapping[str, Any], task: Mapping[str, Any]) -> bool:
523
+ by_id = {item["task_id"]: item for item in state["tasks"]}
524
+ for dependency in task.get("dependencies", []):
525
+ parent = by_id.get(dependency)
526
+ if parent is None or parent.get("status") != "complete":
527
+ return False
528
+ return True
529
+
530
+ def next_task(self) -> dict[str, Any] | None:
531
+ with self._file_lock():
532
+ state = self._load_unlocked()
533
+ if state["status"] != "running":
534
+ return None
535
+ offered = next((
536
+ task for task in state["tasks"]
537
+ if task.get("status") == "offered"
538
+ and self._dependencies_complete(state, task)
539
+ ), None)
540
+ if offered is not None:
541
+ return dict(offered)
542
+ active = sum(task.get("status") in RESERVED_TASK_STATES for task in state["tasks"])
543
+ if active >= state["max_concurrency"]:
544
+ return None
545
+ order = {stage: index for index, stage in enumerate(STAGES)}
546
+ candidates = [
547
+ task for task in state["tasks"]
548
+ if task.get("status") == "pending" and self._dependencies_complete(state, task)
549
+ ]
550
+ if not candidates:
551
+ return None
552
+ task = min(candidates, key=lambda item: (order.get(item["stage"], 99), item["attempt"]))
553
+ task["status"] = "offered"
554
+ task["fencing_token"] = int(task.get("fencing_token", 0)) + 1
555
+ task["offered_at"] = _now()
556
+ state["events"].append({
557
+ "event": "task_offered", "task_id": task["task_id"],
558
+ "stage": task["stage"], "fencing_token": task["fencing_token"],
559
+ "at": task["offered_at"],
560
+ })
561
+ self._save_unlocked(state)
562
+ return dict(task)
563
+
564
+ def bind_agent(self, task_id: str, native_agent_id: str) -> dict[str, Any]:
565
+ if not isinstance(native_agent_id, str) or not NATIVE_AGENT_ID_RE.fullmatch(native_agent_id):
566
+ raise GraphError("native_agent_id 格式无效")
567
+ with self._file_lock():
568
+ state = self._load_unlocked()
569
+ if state["status"] != "running":
570
+ raise GraphError(f"graph 不可调度: {state['status']}")
571
+ task = self._task(state, task_id)
572
+ if task["status"] in ACTIVE_TASK_STATES:
573
+ if task.get("native_agent_id") == native_agent_id:
574
+ return dict(task)
575
+ raise GraphError("task 已绑定到其他 native_agent_id")
576
+ if task["status"] != "offered" or not self._dependencies_complete(state, task):
577
+ raise GraphError("task 尚未依赖就绪或已不可调度")
578
+ active = sum(
579
+ item.get("status") in RESERVED_TASK_STATES and item.get("task_id") != task_id
580
+ for item in state["tasks"]
581
+ )
582
+ if active >= state["max_concurrency"]:
583
+ raise GraphError("graph 并发容量已满")
584
+ if task["stage"] == "Review":
585
+ producers = {
586
+ item.get("native_agent_id") for item in state["tasks"]
587
+ if item.get("stage") in {"Recon", "Repro"}
588
+ and item.get("native_agent_id")
589
+ }
590
+ if native_agent_id in producers:
591
+ raise GraphError("Review 必须由不同于 Recon/Repro 生产者的 native_agent_id 执行")
592
+ task["native_agent_id"] = native_agent_id
593
+ task["status"] = "assigned"
594
+ task["started_at"] = _now()
595
+ state["events"].append({
596
+ "event": "agent_bound", "task_id": task_id,
597
+ "stage": task["stage"], "native_agent_id": native_agent_id,
598
+ "fencing_token": task["fencing_token"], "at": _now(),
599
+ })
600
+ self._save_unlocked(state)
601
+ return dict(task)
602
+
603
+ def _verify_worker(
604
+ self, state: Mapping[str, Any], task_id: str, native_agent_id: str,
605
+ fencing_token: int, *, require_active: bool = True,
606
+ ) -> dict[str, Any]:
607
+ if not isinstance(native_agent_id, str) or not NATIVE_AGENT_ID_RE.fullmatch(native_agent_id):
608
+ raise GraphError("native_agent_id 格式无效")
609
+ if isinstance(fencing_token, bool) or not isinstance(fencing_token, int) or fencing_token < 1:
610
+ raise GraphError("fencing_token 必须是正整数")
611
+ task = self._task(state, task_id)
612
+ if task.get("native_agent_id") != native_agent_id:
613
+ raise GraphError("Worker 身份与 Host 绑定的 native_agent_id 不匹配")
614
+ if task.get("fencing_token") != fencing_token:
615
+ raise GraphError("Worker fencing_token 已失效")
616
+ if require_active and task.get("status") not in ACTIVE_TASK_STATES:
617
+ raise GraphError(f"task 不处于可执行状态: {task.get('status')}")
618
+ return task
619
+
620
+ def _assemble_file_context(self, relative: str, data: bytes, content: str) -> str:
621
+ """Assemble Tiered Progressive Context (imports + 1-hop ego + slice) for code files."""
622
+ try:
623
+ from core.retrieval.slice_extractor import SliceExtractor
624
+ from core.retrieval.slice_normalizer import SliceNormalizer
625
+ except ImportError:
626
+ return content
627
+
628
+ try:
629
+ extractor = SliceExtractor(
630
+ project_id=self.graph_id,
631
+ snapshot_digest=hashlib.sha256(data).hexdigest(),
632
+ generation=1,
633
+ )
634
+ specs = extractor.extract(data, file=relative)
635
+ if not specs:
636
+ return content
637
+
638
+ import_lines: list[str] = []
639
+ for line in content.splitlines()[:60]:
640
+ stripped = line.strip()
641
+ if stripped.startswith(("import ", "from ")) and not stripped.startswith("from ."):
642
+ import_lines.append(stripped)
643
+
644
+ ego_graph = {
645
+ "center_node": relative,
646
+ "neighbors": {
647
+ "callers": [],
648
+ "callees": [s.symbol_name for s in specs[:5] if s.symbol_name],
649
+ },
650
+ }
651
+
652
+ assembled_parts: list[str] = []
653
+ for spec in specs[:3]:
654
+ part = SliceNormalizer.assemble_context(
655
+ spec,
656
+ imports=import_lines[:10],
657
+ ego_graph=ego_graph,
658
+ include_header=True,
659
+ )
660
+ assembled_parts.append(part)
661
+
662
+ return "\n\n---\n\n".join(assembled_parts)
663
+ except Exception as exc:
664
+ # F-RSI-20261115-148:增强失败允许降级回原文(不 fail 任务),
665
+ # 但必须 stderr 留痕——静默吞错会让 worker 拿到降级上下文而
666
+ # 挖掘质量下降零可观测(静默吞错红线系列第 5 处清零)。
667
+ print(f"[graph] ⚠ context slice 增强失败 {relative}: "
668
+ f"{type(exc).__name__}: {exc}", file=sys.stderr)
669
+ return content
670
+
671
+ def context(
672
+ self, task_id: str, native_agent_id: str, fencing_token: int,
673
+ ) -> dict[str, Any]:
674
+ with self._file_lock():
675
+ state = self._load_unlocked()
676
+ task = self._verify_worker(state, task_id, native_agent_id, fencing_token)
677
+ if task["status"] == "assigned":
678
+ task["status"] = "running"
679
+ state["events"].append({
680
+ "event": "worker_started", "task_id": task_id,
681
+ "native_agent_id": native_agent_id, "at": _now(),
682
+ })
683
+ self._save_unlocked(state)
684
+ workspace = Path(state["workspace"])
685
+ try:
686
+ workspace.resolve(strict=True).relative_to(self.run_dir.resolve(strict=True))
687
+ except (OSError, ValueError) as exc:
688
+ raise GraphError("graph workspace 不在运行副本内") from exc
689
+ files: list[dict[str, str]] = []
690
+ total = 0
691
+ for relative in state["task_input"]["target_files"]:
692
+ path = workspace / relative
693
+ try:
694
+ resolved = bugx_paths.confined_regular_file(
695
+ workspace, path, error_cls=GraphError,
696
+ )
697
+ data = resolved.read_bytes()
698
+ except (OSError, UnicodeError, GraphError) as exc:
699
+ raise GraphError(f"无法读取声明的 snapshot 文件 {relative}: {exc}") from exc
700
+ if len(data) > MAX_CONTEXT_FILE_BYTES:
701
+ raise GraphError(f"snapshot 文件超过上下文上限: {relative}")
702
+ try:
703
+ content = data.decode("utf-8")
704
+ except UnicodeDecodeError as exc:
705
+ raise GraphError(f"声明的 snapshot 文件不是 UTF-8 文本: {relative}") from exc
706
+ assembled_content = self._assemble_file_context(relative, data, content)
707
+ total += len(assembled_content.encode("utf-8"))
708
+ if total > MAX_CONTEXT_BYTES:
709
+ raise GraphError("snapshot 文件总上下文超过大小上限")
710
+ files.append({"path": relative, "content": assembled_content})
711
+ parent_artifacts = self._parent_artifacts(state, task)
712
+ total += sum(len(item.get("content_base64", "")) for item in parent_artifacts)
713
+ if total > MAX_CONTEXT_BYTES:
714
+ raise GraphError("父工件与 snapshot 总上下文超过大小上限")
715
+ return {
716
+ "graph_id": self.graph_id,
717
+ "task_id": task_id,
718
+ "stage": task["stage"],
719
+ "attempt": task["attempt"],
720
+ "native_agent_id": native_agent_id,
721
+ "fencing_token": fencing_token,
722
+ "task_spec": task["prompt"],
723
+ "files": files,
724
+ "parent_artifacts": parent_artifacts,
725
+ "snapshot": state["snapshot"],
726
+ }
727
+
728
+ def _parent_artifacts(
729
+ self, state: Mapping[str, Any], task: Mapping[str, Any],
730
+ ) -> list[dict[str, Any]]:
731
+ by_id = {item["task_id"]: item for item in state["tasks"]}
732
+ results: list[dict[str, Any]] = []
733
+ ordered: list[dict[str, Any]] = []
734
+ visited: set[str] = set()
735
+
736
+ def add_ancestors(task_id: str) -> None:
737
+ if task_id in visited:
738
+ return
739
+ visited.add(task_id)
740
+ parent = by_id.get(task_id)
741
+ if parent is None:
742
+ raise GraphError("graph dependency 引用缺失")
743
+ for dependency in parent.get("dependencies", []):
744
+ add_ancestors(dependency)
745
+ ordered.append(parent)
746
+
747
+ for dependency in task.get("dependencies", []):
748
+ add_ancestors(dependency)
749
+ for parent in ordered:
750
+ if not parent or not parent.get("checkpoint"):
751
+ continue
752
+ checkpoint_path = self.run_dir / parent["checkpoint"]["path"]
753
+ if checkpoint_path.is_symlink() or not checkpoint_path.is_file():
754
+ raise GraphError("父工件信封缺失或不安全")
755
+ try:
756
+ envelope = json.loads(checkpoint_path.read_text(encoding="utf-8"))
757
+ except (OSError, UnicodeError, json.JSONDecodeError) as exc:
758
+ raise GraphError(f"父工件信封读取失败: {exc}") from exc
759
+ for item in envelope.get("attachments", []):
760
+ digest = item.get("sha256")
761
+ if not isinstance(digest, str) or not SHA256_RE.fullmatch(digest):
762
+ raise GraphError("父工件附件哈希无效")
763
+ artifact_path = self.run_dir / "artifacts" / "sha256" / digest[:2] / digest
764
+ if artifact_path.is_symlink() or not artifact_path.is_file():
765
+ raise GraphError("父工件附件缺失或不安全")
766
+ data = artifact_path.read_bytes()
767
+ if hashlib.sha256(data).hexdigest() != digest:
768
+ raise GraphError("父工件内容寻址校验失败")
769
+ results.append({
770
+ "task_id": parent["task_id"], "stage": parent["stage"],
771
+ "filename": item["filename"], "sha256": digest,
772
+ "content_base64": base64.b64encode(data).decode("ascii"),
773
+ })
774
+ if len(results) > 50:
775
+ raise GraphError("父工件数量超过限制")
776
+ return results
777
+
778
+ @staticmethod
779
+ def _check_plan(plan: object) -> tuple[list[str], int, str]:
780
+ if not isinstance(plan, Mapping):
781
+ raise GraphError("CheckPlan 必须是对象")
782
+ if set(plan) - {"test_files", "timeout_seconds", "plan_id"}:
783
+ raise GraphError("CheckPlan 含有未支持字段")
784
+ test_files = _string_list(
785
+ plan.get("test_files"), "CheckPlan.test_files", minimum=1,
786
+ maximum=MAX_CHECK_FILES,
787
+ )
788
+ normalized = []
789
+ for item in test_files:
790
+ path = _safe_relative_path(item, "CheckPlan.test_files")
791
+ if not path.startswith("tests/") or not path.endswith(".py"):
792
+ raise GraphError("CheckPlan 仅允许 tests/ 下的 Python 测试文件")
793
+ if not PurePosixPath(path).name.startswith("test_"):
794
+ raise GraphError("CheckPlan 仅允许 test_*.py 文件")
795
+ normalized.append(path)
796
+ if len(set(normalized)) != len(normalized):
797
+ raise GraphError("CheckPlan.test_files 不得重复")
798
+ timeout = plan.get("timeout_seconds", 60)
799
+ if isinstance(timeout, bool) or not isinstance(timeout, int):
800
+ raise GraphError("CheckPlan.timeout_seconds 必须是整数")
801
+ if not 1 <= timeout <= MAX_CHECK_TIMEOUT_SECONDS:
802
+ raise GraphError(f"CheckPlan.timeout_seconds 必须位于 1..{MAX_CHECK_TIMEOUT_SECONDS}")
803
+ plan_id = _text(plan.get("plan_id", "check"), "CheckPlan.plan_id", maximum=128)
804
+ return normalized, timeout, plan_id
805
+
806
+ def run_check(
807
+ self, task_id: str, native_agent_id: str, fencing_token: int,
808
+ plan: object,
809
+ ) -> dict[str, Any]:
810
+ test_files, timeout, plan_id = self._check_plan(plan)
811
+ plan_record = {"test_files": test_files, "timeout_seconds": timeout, "plan_id": plan_id}
812
+ plan_digest = hashlib.sha256(_canonical_json(plan_record)).hexdigest()
813
+ with self._file_lock():
814
+ state = self._load_unlocked()
815
+ task = self._verify_worker(state, task_id, native_agent_id, fencing_token)
816
+ if task["stage"] != "Check":
817
+ raise GraphError("graph_run_check 仅允许 Check 阶段")
818
+ existing = task.get("check_observation")
819
+ if existing is not None:
820
+ if existing.get("plan_sha256") == plan_digest:
821
+ return dict(existing)
822
+ raise GraphError("当前 Check attempt 已执行其他 CheckPlan")
823
+ reservation = task.get("check_plan")
824
+ if reservation is not None:
825
+ if reservation.get("sha256") == plan_digest:
826
+ raise GraphError("相同 CheckPlan 正在执行")
827
+ raise GraphError("当前 Check attempt 已保留其他 CheckPlan")
828
+ workspace = Path(state["workspace"])
829
+ modules = []
830
+ for relative in test_files:
831
+ path = workspace / relative
832
+ if path.is_symlink() or not path.is_file():
833
+ raise GraphError(f"CheckPlan 测试文件缺失或不安全: {relative}")
834
+ modules.append(PurePosixPath(relative).with_suffix("").as_posix().replace("/", "."))
835
+ command = [sys.executable, "-P", "-m", "unittest", *modules]
836
+ temp_root = self.run_dir / "tmp"
837
+ temp_root.mkdir(mode=0o700, exist_ok=True)
838
+ task["check_plan"] = {"sha256": plan_digest, **plan_record}
839
+ task["check_pid"] = None
840
+ state["events"].append({
841
+ "event": "check_started", "task_id": task_id,
842
+ "plan_sha256": plan_digest, "at": _now(),
843
+ })
844
+ self._save_unlocked(state)
845
+ env = {
846
+ "PATH": os.environ.get("PATH", ""),
847
+ "PYTHONPATH": str(workspace),
848
+ "PYTHONUTF8": "1",
849
+ "PYTHONDONTWRITEBYTECODE": "1",
850
+ "HOME": str(temp_root),
851
+ "TMPDIR": str(temp_root),
852
+ "TMP": str(temp_root),
853
+ "TEMP": str(temp_root),
854
+ }
855
+ if os.name == "nt":
856
+ for name in ("SystemRoot", "WINDIR"):
857
+ if name in os.environ:
858
+ env[name] = os.environ[name]
859
+ started = time.monotonic()
860
+ timed_out = False
861
+ output = b""
862
+ error_output = b""
863
+ return_code: int | None = None
864
+ process: subprocess.Popen[bytes] | None = None
865
+ stdout_tail = bytearray()
866
+ stderr_tail = bytearray()
867
+ drain_threads: list[threading.Thread] = []
868
+
869
+ def drain(stream: Any, tail: bytearray) -> None:
870
+ while True:
871
+ block = stream.read(8192)
872
+ if not block:
873
+ return
874
+ tail.extend(block)
875
+ if len(tail) > MAX_CHECK_OUTPUT_BYTES:
876
+ del tail[:-MAX_CHECK_OUTPUT_BYTES]
877
+
878
+ try:
879
+ options: dict[str, Any] = {}
880
+ if os.name == "nt":
881
+ options["creationflags"] = getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
882
+ else:
883
+ options["start_new_session"] = True
884
+ process = subprocess.Popen(
885
+ command, cwd=workspace, env=env, stdin=subprocess.DEVNULL,
886
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False,
887
+ **options,
888
+ )
889
+ cancelled_before_registration = False
890
+ with self._file_lock():
891
+ state = self._load_unlocked()
892
+ current = self._task(state, task_id)
893
+ if (
894
+ current.get("status") not in ACTIVE_TASK_STATES
895
+ or current.get("fencing_token") != fencing_token
896
+ or current.get("check_plan", {}).get("sha256") != plan_digest
897
+ ):
898
+ cancelled_before_registration = True
899
+ else:
900
+ current["check_pid"] = process.pid
901
+ self._save_unlocked(state)
902
+ if cancelled_before_registration:
903
+ self._terminate_check_process(process.pid)
904
+ for stream, tail, name in (
905
+ (process.stdout, stdout_tail, "graph-check-stdout"),
906
+ (process.stderr, stderr_tail, "graph-check-stderr"),
907
+ ):
908
+ if stream is not None:
909
+ thread = threading.Thread(
910
+ target=drain, args=(stream, tail), name=name, daemon=True,
911
+ )
912
+ thread.start()
913
+ drain_threads.append(thread)
914
+ try:
915
+ process.wait(timeout=timeout)
916
+ except subprocess.TimeoutExpired:
917
+ timed_out = True
918
+ self._terminate_check_process(process.pid)
919
+ process.wait()
920
+ for thread in drain_threads:
921
+ thread.join(timeout=0.5)
922
+ if any(thread.is_alive() for thread in drain_threads):
923
+ self._terminate_check_process(process.pid)
924
+ for stream in (process.stdout, process.stderr):
925
+ if stream is not None:
926
+ stream.close()
927
+ for thread in drain_threads:
928
+ thread.join(timeout=0.5)
929
+ for stream in (process.stdout, process.stderr):
930
+ if stream is not None:
931
+ stream.close()
932
+ output = bytes(stdout_tail)
933
+ error_output = bytes(stderr_tail)
934
+ return_code = process.returncode
935
+ except OSError as exc:
936
+ error_output = str(exc).encode("utf-8", errors="replace")
937
+ return_code = -1
938
+ with self._file_lock():
939
+ state = self._load_unlocked()
940
+ task = self._task(state, task_id)
941
+ graph_cancelled = state.get("status") == "cancelled" or task.get("status") == "cancelled"
942
+ if graph_cancelled:
943
+ status = "cancelled"
944
+ elif timed_out:
945
+ status = "timeout"
946
+ else:
947
+ status = "passed" if return_code == 0 else "failed"
948
+ observation = {
949
+ "schema_version": 1,
950
+ "observation_id": "obs_" + uuid.uuid4().hex,
951
+ "graph_id": self.graph_id,
952
+ "task_id": task_id,
953
+ "native_agent_id": native_agent_id,
954
+ "plan_id": plan_id,
955
+ "plan_sha256": plan_digest,
956
+ "command": command,
957
+ "test_files": test_files,
958
+ "status": status,
959
+ "exit_code": return_code,
960
+ "duration_seconds": round(time.monotonic() - started, 3),
961
+ "stdout": output[-MAX_CHECK_OUTPUT_BYTES:].decode("utf-8", errors="replace"),
962
+ "stderr": error_output[-MAX_CHECK_OUTPUT_BYTES:].decode("utf-8", errors="replace"),
963
+ "timeout_seconds": timeout,
964
+ "created_at": _now(),
965
+ }
966
+ task["check_observation"] = observation
967
+ task["check_pid"] = None
968
+ state["events"].append({
969
+ "event": "check_observation", "task_id": task_id,
970
+ "observation_id": observation["observation_id"],
971
+ "status": observation["status"], "at": observation["created_at"],
972
+ })
973
+ self._save_unlocked(state)
974
+ return observation
975
+
976
+ @staticmethod
977
+ def _terminate_check_process(pid: int) -> None:
978
+ try:
979
+ if os.name == "nt":
980
+ os.kill(pid, signal.SIGTERM)
981
+ else:
982
+ os.killpg(pid, signal.SIGKILL)
983
+ except OSError:
984
+ pass
985
+
986
+ @staticmethod
987
+ def _normalize_envelope(envelope: object) -> dict[str, Any]:
988
+ if not isinstance(envelope, Mapping):
989
+ raise GraphError("artifact envelope 必须是对象")
990
+ allowed = {"outcome", "summary", "reason", "context", "retry_stage", "result"}
991
+ unknown = set(envelope) - allowed
992
+ if unknown:
993
+ raise GraphError(f"artifact envelope 含有未支持字段: {sorted(unknown)}")
994
+ outcome = envelope.get("outcome")
995
+ if not isinstance(outcome, str) or outcome not in {"complete", "needs_revision", "failed"}:
996
+ raise GraphError("artifact envelope.outcome 必须是 complete/needs_revision/failed")
997
+ summary = _text(envelope.get("summary"), "artifact envelope.summary")
998
+ reason = envelope.get("reason", "")
999
+ if reason is not None and (not isinstance(reason, str) or len(reason) > 8192):
1000
+ raise GraphError("artifact envelope.reason 无效")
1001
+ context = envelope.get("context", {})
1002
+ if not isinstance(context, Mapping):
1003
+ raise GraphError("artifact envelope.context 必须是对象")
1004
+ if len(_canonical_json(context)) > MAX_ENVELOPE_BYTES:
1005
+ raise GraphError("artifact envelope.context 超过大小上限")
1006
+ retry_stage = envelope.get("retry_stage")
1007
+ if retry_stage is not None and (
1008
+ not isinstance(retry_stage, str) or retry_stage not in {"Recon", "Repro"}
1009
+ ):
1010
+ raise GraphError("Review retry_stage 仅支持 Recon/Repro")
1011
+ result = envelope.get("result", {})
1012
+ if not isinstance(result, Mapping) or len(_canonical_json(result)) > MAX_ENVELOPE_BYTES:
1013
+ raise GraphError("artifact envelope.result 必须是有界对象")
1014
+ normalized = {
1015
+ "outcome": outcome,
1016
+ "summary": summary,
1017
+ "reason": reason or "",
1018
+ "context": dict(context),
1019
+ "result": dict(result),
1020
+ }
1021
+ if retry_stage is not None:
1022
+ normalized["retry_stage"] = retry_stage
1023
+ if len(_canonical_json(normalized)) > MAX_ENVELOPE_BYTES:
1024
+ raise GraphError("artifact envelope 超过大小上限")
1025
+ return normalized
1026
+
1027
+ @staticmethod
1028
+ def _decode_attachments(attachments: object) -> list[dict[str, Any]]:
1029
+ if not isinstance(attachments, list) or len(attachments) > 50:
1030
+ raise GraphError("attachments 必须是最多 50 项的数组")
1031
+ decoded: list[dict[str, Any]] = []
1032
+ total = 0
1033
+ for index, item in enumerate(attachments):
1034
+ if not isinstance(item, Mapping) or set(item) != {"filename", "sha256", "content_base64"}:
1035
+ raise GraphError(f"attachments[{index}] 字段无效")
1036
+ filename = _text(item["filename"], f"attachments[{index}].filename", maximum=512)
1037
+ if "/" in filename or "\\" in filename or filename in {".", ".."}:
1038
+ raise GraphError("attachment filename 必须是单个文件名")
1039
+ digest = item["sha256"]
1040
+ if not isinstance(digest, str) or not SHA256_RE.fullmatch(digest):
1041
+ raise GraphError("attachment sha256 格式无效")
1042
+ content_b64 = item["content_base64"]
1043
+ if not isinstance(content_b64, str):
1044
+ raise GraphError("attachment content_base64 必须是字符串")
1045
+ try:
1046
+ data = base64.b64decode(content_b64, validate=True)
1047
+ except (ValueError, base64.binascii.Error) as exc:
1048
+ raise GraphError("attachment base64 无效") from exc
1049
+ if len(data) > MAX_ATTACHMENT_BYTES:
1050
+ raise GraphError("单个 attachment 超过大小上限")
1051
+ total += len(data)
1052
+ if total > MAX_ATTACHMENTS_BYTES:
1053
+ raise GraphError("attachments 总大小超过上限")
1054
+ actual = hashlib.sha256(data).hexdigest()
1055
+ if actual != digest:
1056
+ raise GraphError("attachment sha256 与内容不匹配")
1057
+ decoded.append({
1058
+ "filename": filename, "sha256": digest,
1059
+ "content_base64": content_b64, "data": data,
1060
+ })
1061
+ return decoded
1062
+
1063
+ def checkpoint(
1064
+ self, task_id: str, native_agent_id: str, fencing_token: int,
1065
+ envelope: object, attachments: object = None,
1066
+ ) -> dict[str, Any]:
1067
+ normalized = self._normalize_envelope(envelope)
1068
+ decoded = self._decode_attachments([] if attachments is None else attachments)
1069
+ request_digest = hashlib.sha256(_canonical_json({
1070
+ "envelope": normalized,
1071
+ "attachments": [
1072
+ {"filename": item["filename"], "sha256": item["sha256"]}
1073
+ for item in decoded
1074
+ ],
1075
+ })).hexdigest()
1076
+ with self._file_lock():
1077
+ state = self._load_unlocked()
1078
+ task = self._verify_worker(state, task_id, native_agent_id, fencing_token, require_active=False)
1079
+ previous = task.get("checkpoint")
1080
+ if previous is not None:
1081
+ if previous.get("request_sha256") == request_digest:
1082
+ return dict(previous)
1083
+ raise GraphError("task 已有不同内容的 checkpoint,拒绝覆盖")
1084
+ if task["status"] not in ACTIVE_TASK_STATES:
1085
+ raise GraphError(f"task 不处于可 checkpoint 状态: {task.get('status')}")
1086
+ if normalized["outcome"] == "complete" and task["stage"] == "Check":
1087
+ observation = task.get("check_observation")
1088
+ if not isinstance(observation, Mapping):
1089
+ raise GraphError("Check 阶段缺少 graph_run_check Observation")
1090
+ if observation.get("status") != "passed":
1091
+ raise GraphError("Check Observation 未通过,不能 checkpoint complete")
1092
+ attachment_refs = []
1093
+ for item in decoded:
1094
+ digest = item["sha256"]
1095
+ artifact_dir = self.run_dir / "artifacts" / "sha256" / digest[:2]
1096
+ bugx_paths.assert_no_symlink_components(artifact_dir)
1097
+ artifact_dir.mkdir(mode=0o700, parents=True, exist_ok=True)
1098
+ target = artifact_dir / digest
1099
+ if target.exists():
1100
+ if target.is_symlink() or not target.is_file():
1101
+ raise GraphError("content-addressed attachment path 不安全")
1102
+ existing = target.read_bytes()
1103
+ if hashlib.sha256(existing).hexdigest() != digest:
1104
+ raise GraphError("既有 content-addressed attachment 内容损坏")
1105
+ else:
1106
+ try:
1107
+ secure_atomic.atomic_write_bytes(
1108
+ target, item["data"], mode=0o600, parent_mode=0o700,
1109
+ )
1110
+ except OSError as exc:
1111
+ raise GraphError(f"attachment 写入失败: {exc}") from exc
1112
+ attachment_refs.append({"filename": item["filename"], "sha256": digest})
1113
+ envelope_payload = {
1114
+ "schema_version": 1,
1115
+ "graph_id": self.graph_id,
1116
+ "task_id": task_id,
1117
+ "stage": task["stage"],
1118
+ "attempt": task["attempt"],
1119
+ "native_agent_id": native_agent_id,
1120
+ "fencing_token": fencing_token,
1121
+ "submitted_at": _now(),
1122
+ **normalized,
1123
+ "check_observation": task.get("check_observation"),
1124
+ "attachments": attachment_refs,
1125
+ }
1126
+ envelope_bytes = _canonical_json(envelope_payload)
1127
+ checkpoint_id = hashlib.sha256(envelope_bytes).hexdigest()
1128
+ envelope_path = self.run_dir / "checkpoints" / f"{task_id}.json"
1129
+ envelope_path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
1130
+ try:
1131
+ secure_atomic.atomic_write_bytes(
1132
+ envelope_path, envelope_bytes, mode=0o600, parent_mode=0o700,
1133
+ )
1134
+ except OSError as exc:
1135
+ raise GraphError(f"checkpoint envelope 写入失败: {exc}") from exc
1136
+ receipt = {
1137
+ "checkpoint_id": checkpoint_id,
1138
+ "request_sha256": request_digest,
1139
+ "path": str(envelope_path.relative_to(self.run_dir)),
1140
+ "envelope_sha256": checkpoint_id,
1141
+ "attachments": attachment_refs,
1142
+ }
1143
+ task["checkpoint"] = receipt
1144
+ outcome = normalized["outcome"]
1145
+ if outcome == "complete":
1146
+ task["status"] = "complete"
1147
+ task["finished_at"] = _now()
1148
+ self._ensure_successor(state, task)
1149
+ else:
1150
+ task["status"] = "needs_revision"
1151
+ task["finished_at"] = _now()
1152
+ task["failure_context"] = {
1153
+ "reason": normalized["reason"] or normalized["summary"],
1154
+ "context": normalized["context"],
1155
+ "checkpoint_id": checkpoint_id,
1156
+ }
1157
+ self._retry_or_fail(state, task, normalized)
1158
+ state["events"].append({
1159
+ "event": "task_checkpointed", "task_id": task_id,
1160
+ "stage": task["stage"], "attempt": task["attempt"],
1161
+ "outcome": outcome, "checkpoint_id": checkpoint_id, "at": _now(),
1162
+ })
1163
+ self._save_unlocked(state)
1164
+ return receipt
1165
+
1166
+ def _ensure_successor(self, state: dict[str, Any], task: Mapping[str, Any]) -> None:
1167
+ stage = task["stage"]
1168
+ if stage == "Report":
1169
+ return
1170
+ next_stage = {
1171
+ "Recon": "Repro", "Repro": "Review", "Review": (
1172
+ "Patch" if state["task_input"]["patch_requested"] else "Check"
1173
+ ), "Patch": "Check", "Check": "Report",
1174
+ }.get(stage)
1175
+ if next_stage is None:
1176
+ return
1177
+ if any(
1178
+ item.get("stage") == next_stage
1179
+ and task["task_id"] in item.get("dependencies", [])
1180
+ and item.get("status") not in {"failed", "cancelled", "superseded"}
1181
+ for item in state["tasks"]
1182
+ ):
1183
+ return
1184
+ previous = [item for item in state["tasks"] if item.get("stage") == next_stage]
1185
+ attempt = max((int(item["attempt"]) for item in previous), default=0) + 1
1186
+ if attempt > MAX_ATTEMPTS:
1187
+ state["status"] = "failed"
1188
+ state["failure_reason"] = f"{next_stage} 超过最大 attempt 次数"
1189
+ return
1190
+ state["tasks"].append(_new_task(
1191
+ state, next_stage, attempt, [str(task["task_id"])],
1192
+ feedback=task.get("feedback") if task.get("feedback") else None,
1193
+ ))
1194
+
1195
+ def _retry_or_fail(
1196
+ self, state: dict[str, Any], task: dict[str, Any], envelope: Mapping[str, Any],
1197
+ ) -> None:
1198
+ next_attempt = int(task["attempt"]) + 1
1199
+ if next_attempt > MAX_ATTEMPTS:
1200
+ task["status"] = "failed"
1201
+ state["status"] = "failed"
1202
+ state["failure_reason"] = task["failure_context"]["reason"]
1203
+ return
1204
+ if task["stage"] == "Review":
1205
+ retry_stage = envelope.get("retry_stage") or "Repro"
1206
+ producer_attempts = [
1207
+ item for item in state["tasks"] if item.get("stage") == retry_stage
1208
+ ]
1209
+ retry_number = max((int(item["attempt"]) for item in producer_attempts), default=0) + 1
1210
+ if retry_number > MAX_ATTEMPTS:
1211
+ task["status"] = "failed"
1212
+ state["status"] = "failed"
1213
+ state["failure_reason"] = f"{retry_stage} 已达到 {MAX_ATTEMPTS} 次 attempt 上限"
1214
+ return
1215
+ original = max(producer_attempts, key=lambda item: int(item["attempt"]))
1216
+ feedback = {
1217
+ "reason": envelope["reason"] or envelope["summary"],
1218
+ "context": envelope["context"],
1219
+ "from_stage": "Review",
1220
+ "from_task_id": task["task_id"],
1221
+ }
1222
+ retry = _new_task(
1223
+ state, retry_stage, retry_number,
1224
+ original.get("dependencies", []), feedback=feedback,
1225
+ )
1226
+ state["tasks"].append(retry)
1227
+ return
1228
+ retry = _new_task(
1229
+ state, task["stage"], next_attempt,
1230
+ task.get("dependencies", []),
1231
+ feedback={
1232
+ "reason": envelope["reason"] or envelope["summary"],
1233
+ "context": envelope["context"],
1234
+ "from_stage": task["stage"],
1235
+ "from_task_id": task["task_id"],
1236
+ },
1237
+ )
1238
+ state["tasks"].append(retry)
1239
+
1240
+ def cancel(self, reason: str, task_id: str | None = None) -> dict[str, Any]:
1241
+ reason = _text(reason, "reason", maximum=2048)
1242
+ process_ids: list[int] = []
1243
+ with self._file_lock():
1244
+ state = self._load_unlocked()
1245
+ if task_id is not None:
1246
+ self._task(state, task_id)
1247
+ if state["status"] in {"finalized", "cancelled"}:
1248
+ return {"graph_id": self.graph_id, "status": state["status"], "cancelled": False}
1249
+ for task in state["tasks"]:
1250
+ if task.get("status") not in TERMINAL_TASK_STATES:
1251
+ process_id = task.get("check_pid")
1252
+ if isinstance(process_id, int) and process_id > 0:
1253
+ process_ids.append(process_id)
1254
+ if task.get("status") in RESERVED_TASK_STATES:
1255
+ task["fencing_token"] = int(task.get("fencing_token", 0)) + 1
1256
+ task["status"] = "cancelled"
1257
+ task["finished_at"] = _now()
1258
+ state["status"] = "cancelled"
1259
+ state["cancel_reason"] = reason
1260
+ state["cancelled_at"] = _now()
1261
+ state["events"].append({
1262
+ "event": "graph_cancelled", "task_id": task_id,
1263
+ "reason": reason, "at": state["cancelled_at"],
1264
+ })
1265
+ self._save_unlocked(state)
1266
+ # Native agents are fenced by task state/token. The engine has no host
1267
+ # UI handle to stop them; it reclaims only the owned snapshot workspace.
1268
+ for process_id in process_ids:
1269
+ self._terminate_check_process(process_id)
1270
+ if self.workspace.exists() and not self.workspace.is_symlink():
1271
+ shutil.rmtree(self.workspace)
1272
+ return {"graph_id": self.graph_id, "status": "cancelled", "cancelled": True}
1273
+
1274
+ def finalize(self, decision: str, summary: str) -> dict[str, Any]:
1275
+ if decision not in {"accepted", "rejected", "inconclusive"}:
1276
+ raise GraphError("decision 必须是 accepted/rejected/inconclusive")
1277
+ summary = _text(summary, "summary", maximum=8192)
1278
+ with self._file_lock():
1279
+ state = self._load_unlocked()
1280
+ if state["status"] == "finalized":
1281
+ report = state.get("final_report")
1282
+ if report and report.get("decision") == decision and report.get("summary") == summary:
1283
+ return dict(report)
1284
+ raise GraphError("graph 已最终固化,不能覆盖裁决")
1285
+ if any(task.get("status") in ACTIVE_TASK_STATES for task in state["tasks"]):
1286
+ raise GraphError("仍有已绑定或执行中的 task,不能 finalize")
1287
+ if state["status"] == "running":
1288
+ report_task = next((
1289
+ item for item in state["tasks"]
1290
+ if item.get("stage") == "Report" and item.get("status") == "complete"
1291
+ ), None)
1292
+ if report_task is None:
1293
+ raise GraphError("Report 阶段未完成,不能 finalize")
1294
+ overall = "complete" if state["status"] == "running" else state["status"]
1295
+ payload = {
1296
+ "schema_version": 1,
1297
+ "graph_id": self.graph_id,
1298
+ "status": overall,
1299
+ "decision": decision,
1300
+ "summary": summary,
1301
+ "created_at": _now(),
1302
+ "source_root_path_fingerprint": state["source_root_path_fingerprint"],
1303
+ "snapshot": state["snapshot"],
1304
+ "tasks": [
1305
+ {
1306
+ "task_id": task["task_id"], "stage": task["stage"],
1307
+ "attempt": task["attempt"], "status": task["status"],
1308
+ "dependencies": task["dependencies"],
1309
+ "native_agent_id": task["native_agent_id"],
1310
+ "checkpoint": task["checkpoint"],
1311
+ "check_observation": task["check_observation"],
1312
+ "failure_context": task["failure_context"],
1313
+ }
1314
+ for task in state["tasks"]
1315
+ ],
1316
+ "events": state["events"],
1317
+ "failure_reason": state.get("failure_reason"),
1318
+ "cancel_reason": state.get("cancel_reason"),
1319
+ }
1320
+ report_path = self.run_dir / "final-report.json"
1321
+ try:
1322
+ secure_atomic.atomic_write_json(
1323
+ report_path, payload, mode=0o600, parent_mode=0o700,
1324
+ )
1325
+ except (OSError, ValueError, TypeError) as exc:
1326
+ raise GraphError(f"final report 写入失败: {exc}") from exc
1327
+ report_sha256 = hashlib.sha256(_canonical_json(payload)).hexdigest()
1328
+ receipt = {
1329
+ "graph_id": self.graph_id,
1330
+ "status": overall,
1331
+ "decision": decision,
1332
+ "summary": summary,
1333
+ "report_path": str(report_path.relative_to(self.run_dir)),
1334
+ "report_sha256": report_sha256,
1335
+ "task_count": len(state["tasks"]),
1336
+ "at": payload["created_at"],
1337
+ }
1338
+ state["status"] = "finalized"
1339
+ state["final_report"] = receipt
1340
+ state["events"].append({
1341
+ "event": "graph_finalized", "report_sha256": report_sha256,
1342
+ "decision": decision, "at": payload["created_at"],
1343
+ })
1344
+ self._save_unlocked(state)
1345
+ return receipt
1346
+
1347
+
1348
+ __all__ = [
1349
+ "AgentOrchestrator", "GraphError", "MAX_ATTEMPTS", "MAX_CHECK_TIMEOUT_SECONDS",
1350
+ "assemble_task_prompt",
1351
+ ]