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,1005 @@
1
+ #!/usr/bin/env python3
2
+ """core/ledger/incidents.py - 事故故障卡模型、签名检索、复盘反馈与证据消费审计 (DOC-072)。"""
3
+
4
+ from __future__ import annotations
5
+
6
+ import datetime as dt
7
+ import hashlib
8
+ import json
9
+ import math
10
+ import os
11
+ import re
12
+ import sqlite3
13
+ from pathlib import Path
14
+ from typing import Any, Iterable, Mapping
15
+
16
+ from .patterns import (
17
+ decode_routing_tags,
18
+ estimate_tokens,
19
+ extract_routing_tags,
20
+ insert_pattern,
21
+ lesson_id,
22
+ normalize_pattern,
23
+ pattern_value,
24
+ patterns_are_equal,
25
+ routing_match,
26
+ with_project_profile_defaults,
27
+ )
28
+ from .schema import (
29
+ DEFAULT_LEDGER,
30
+ INCIDENT_STATUSES,
31
+ PATTERN_OUTCOMES,
32
+ ROUTING_TAG_KEYS,
33
+ FP_REGEX,
34
+ ID_REGEX,
35
+ INCIDENT_ID_REGEX,
36
+ LessonLedgerError,
37
+ canonical_bytes,
38
+ connect_ledger,
39
+ record_event,
40
+ parse_json_list,
41
+ normalize_id,
42
+ now_iso,
43
+ refresh_materialized_views,
44
+ sanitize_text,
45
+ sanitize_text_long,
46
+ sanitize_text_opt,
47
+ ledger_transaction,
48
+ validate_pattern,
49
+ database_path,
50
+ )
51
+
52
+ _INCIDENT_FINGERPRINT_RE = re.compile(r"^sha256:[0-9a-f]{64}$")
53
+
54
+
55
+ def now_datetime() -> dt.datetime:
56
+ return dt.datetime.now(dt.timezone.utc)
57
+
58
+
59
+ def _text_long_or_empty(value: Any, field: str, max_len: int = 65536) -> str:
60
+ """DOC-203: allow empty evidence fields while retaining type/size checks."""
61
+ if value is None or (isinstance(value, str) and not value.strip()):
62
+ return ""
63
+ return sanitize_text_long(value, field, max_len)
64
+
65
+
66
+ def normalize_signature(value: Any) -> str:
67
+ """Stable error-signature key: case/whitespace-insensitive, punctuation kept."""
68
+ raw = sanitize_text(value, "signature")
69
+ return normalize_id(raw)
70
+
71
+
72
+ def incident_id(
73
+ signature: str, summary: str, commit_ref: str | None, *,
74
+ finding_fingerprint: str | None = None,
75
+ ) -> str:
76
+ parts = [normalize_signature(signature), normalize_id(summary), normalize_id(commit_ref or "")]
77
+ if finding_fingerprint:
78
+ parts.append(normalize_id(finding_fingerprint))
79
+ raw = "\0".join(parts)
80
+ return "I-" + hashlib.sha256(raw.encode()).hexdigest()[:12]
81
+
82
+
83
+ def normalize_finding_fingerprint(value: Any) -> str:
84
+ val = sanitize_text(value, "finding_fingerprint")
85
+ if not FP_REGEX.fullmatch(val):
86
+ raise LessonLedgerError("finding_fingerprint 格式无效")
87
+ return val
88
+
89
+
90
+ def _incident_fingerprint(value: Any) -> str:
91
+ val = sanitize_text(value, "finding_fingerprint")
92
+ if not _INCIDENT_FINGERPRINT_RE.fullmatch(val):
93
+ raise LessonLedgerError("finding_fingerprint 必须是 sha256:<64 位小写十六进制>")
94
+ return val
95
+
96
+
97
+ def normalize_duration(value: Any) -> int | float:
98
+ if not isinstance(value, (int, float)) or isinstance(value, bool) \
99
+ or not math.isfinite(value) or value < 0:
100
+ raise LessonLedgerError("incident duration_seconds 必须是非负有限数字")
101
+ normalized = float(value)
102
+ return int(normalized) if normalized.is_integer() else normalized
103
+
104
+
105
+ def incident_content(item: Mapping[str, Any]) -> dict[str, Any]:
106
+ content = {
107
+ "signature": item["signature"], "summary": item["summary"],
108
+ "context": item["context"], "before_snippet": item["before_snippet"],
109
+ "after_snippet": item["after_snippet"], "diff_ref": item.get("diff_ref"),
110
+ "commit_ref": item.get("commit_ref"), "decision": item["decision"],
111
+ "duration_seconds": normalize_duration(item.get("duration_seconds", 0)),
112
+ "lifecycle_id": item.get("lifecycle_id"), "round": item.get("round"),
113
+ "pattern_id": item.get("pattern_id"),
114
+ "routing_tags": extract_routing_tags(item),
115
+ }
116
+ fingerprint = item.get("finding_fingerprint")
117
+ if fingerprint is not None:
118
+ content["finding_fingerprint"] = _incident_fingerprint(fingerprint)
119
+ return content
120
+
121
+
122
+ def incident_content_hash(item: Mapping[str, Any]) -> str:
123
+ return hashlib.sha256(canonical_bytes(incident_content(item))).hexdigest()
124
+
125
+
126
+ def normalize_incident(payload: Mapping[str, Any], now: str | None = None) -> dict[str, Any]:
127
+ signature = normalize_signature(payload.get("signature"))
128
+ summary = sanitize_text(payload.get("summary"), "summary")
129
+ context = sanitize_text_long(payload.get("context"), "context")
130
+ before = _text_long_or_empty(payload.get("before_snippet"), "before_snippet")
131
+ after = _text_long_or_empty(payload.get("after_snippet"), "after_snippet")
132
+ decision = _text_long_or_empty(payload.get("decision"), "decision", max_len=16384)
133
+ status = payload.get("status", "candidate")
134
+ if status not in INCIDENT_STATUSES:
135
+ raise LessonLedgerError("incident status 无效")
136
+ if status in {"active", "retired", "revoked"}:
137
+ raise LessonLedgerError("Agent 新增 incident 只能是 candidate;治理流程才能变更状态")
138
+ diff_ref = sanitize_text(payload.get("diff_ref"), "diff_ref") if payload.get("diff_ref") else None
139
+ commit_ref = sanitize_text(payload.get("commit_ref"), "commit_ref") if payload.get("commit_ref") else None
140
+ lifecycle = sanitize_text(payload.get("lifecycle_id"), "lifecycle_id") if payload.get("lifecycle_id") else None
141
+ rnd = payload.get("round")
142
+ if rnd is not None and (not isinstance(rnd, int) or isinstance(rnd, bool) or rnd < 1):
143
+ raise LessonLedgerError("incident round 必须是正整数或 null")
144
+ duration = normalize_duration(payload.get("duration_seconds", 0))
145
+ routing_tags = extract_routing_tags(payload)
146
+ pattern_id = payload.get("pattern_id")
147
+ if pattern_id is not None and not ID_REGEX.fullmatch(str(pattern_id)):
148
+ raise LessonLedgerError("incident pattern_id 格式无效")
149
+ raw_fingerprint = payload.get("finding_fingerprint")
150
+ finding_fingerprint = (
151
+ _incident_fingerprint(raw_fingerprint) if raw_fingerprint is not None else None
152
+ )
153
+ key = payload.get("incident_id") or incident_id(
154
+ signature, summary, commit_ref,
155
+ finding_fingerprint=finding_fingerprint,
156
+ )
157
+ key = sanitize_text(key, "incident_id")
158
+ if not INCIDENT_ID_REGEX.fullmatch(key):
159
+ raise LessonLedgerError("incident_id 格式无效")
160
+ timestamp = now or now_iso()
161
+ content = incident_content({
162
+ "signature": signature, "summary": summary, "context": context,
163
+ "before_snippet": before, "after_snippet": after,
164
+ "diff_ref": diff_ref, "commit_ref": commit_ref, "decision": decision,
165
+ "duration_seconds": duration, "lifecycle_id": lifecycle, "round": rnd,
166
+ "pattern_id": pattern_id, "routing_tags": routing_tags,
167
+ "finding_fingerprint": finding_fingerprint,
168
+ })
169
+ incident = {
170
+ **content,
171
+ "incident_id": key, "status": status,
172
+ "created_at": str(payload.get("created_at") or timestamp),
173
+ "updated_at": str(payload.get("updated_at") or timestamp),
174
+ "content_hash": incident_content_hash(content),
175
+ }
176
+ if finding_fingerprint is not None:
177
+ incident["finding_fingerprint"] = finding_fingerprint
178
+ return incident
179
+
180
+
181
+ _INCIDENT_INSERT_COLUMNS = (
182
+ "incident_id", "pattern_id", "signature", "summary", "context",
183
+ "before_snippet", "after_snippet", "diff_ref", "commit_ref", "decision",
184
+ "duration_seconds", "lifecycle_id", "round", "status", "created_at",
185
+ "updated_at", "content_hash", "routing_tags", "finding_fingerprint",
186
+ )
187
+
188
+
189
+ def insert_incident(c: sqlite3.Connection, item: Mapping[str, Any]) -> None:
190
+ """Insert an incident with an explicit schema mapping, including local fingerprint."""
191
+ columns = ",".join(_INCIDENT_INSERT_COLUMNS)
192
+ placeholders = ",".join("?" for _ in _INCIDENT_INSERT_COLUMNS)
193
+ values = tuple(
194
+ json.dumps(item.get(name) or {}, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
195
+ if name == "routing_tags" else item.get(name)
196
+ for name in _INCIDENT_INSERT_COLUMNS
197
+ )
198
+ c.execute(f"INSERT INTO incidents ({columns}) VALUES ({placeholders})", values)
199
+
200
+
201
+ def add_incident(path: str | os.PathLike[str], payload: Mapping[str, Any]) -> dict[str, Any]:
202
+ if payload.get("actor", "supervisor") != "supervisor":
203
+ raise LessonLedgerError("incident 写入必须由 Supervisor 提交")
204
+ item = normalize_incident(with_project_profile_defaults(path, payload))
205
+
206
+ def go(c):
207
+ if item["pattern_id"] is not None and not c.execute(
208
+ "SELECT 1 FROM patterns WHERE pattern_id=?", (item["pattern_id"],)
209
+ ).fetchone():
210
+ raise LessonLedgerError(
211
+ f"incident 关联的 pattern 不存在: {item['pattern_id']}"
212
+ )
213
+ row = c.execute("SELECT content_hash FROM incidents WHERE incident_id=?", (item["incident_id"],)).fetchone()
214
+ if row:
215
+ if row[0] != item["content_hash"]:
216
+ raise LessonLedgerError(
217
+ f"incident_id 已存在但内容不一致,拒绝覆盖: {item['incident_id']}"
218
+ )
219
+ return {
220
+ "status": "duplicate", "incident": incident_value(c, item["incident_id"]),
221
+ "revision": c.execute("SELECT COUNT(*) FROM events").fetchone()[0],
222
+ }
223
+ insert_incident(c, item)
224
+ record_event(c, "incident-created", {"incident": item})
225
+ return {
226
+ "status": "created", "incident": incident_value(c, item["incident_id"]),
227
+ "revision": c.execute("SELECT COUNT(*) FROM events").fetchone()[0],
228
+ }
229
+
230
+ return ledger_transaction(path, go)
231
+
232
+
233
+ def activate_incident(path: str | os.PathLike[str], incident_key: str, *,
234
+ evidence_receipt_id: str, actor: str = "supervisor") -> dict[str, Any]:
235
+ if actor != "supervisor":
236
+ raise LessonLedgerError("incident 激活必须由 Supervisor 提交")
237
+ key = sanitize_text(incident_key, "incident_id")
238
+ receipt = sanitize_text(evidence_receipt_id, "evidence_receipt_id")
239
+
240
+ def go(c):
241
+ value = incident_value(c, key)
242
+ if value["status"] != "candidate":
243
+ raise LessonLedgerError("只有 candidate incident 可以激活")
244
+ receipt_row = c.execute(
245
+ "SELECT subject_type,subject_id,lifecycle_id,round,run_id,artifact_hash "
246
+ "FROM evidence_receipts WHERE receipt_id=?", (receipt,),
247
+ ).fetchone()
248
+ if not receipt_row:
249
+ raise LessonLedgerError("incident 激活缺少 evidence receipt")
250
+ if receipt_row[0] != "incident" or receipt_row[1] != key:
251
+ raise LessonLedgerError("evidence receipt 未绑定当前 incident")
252
+ if value["lifecycle_id"] is not None \
253
+ and receipt_row[2] != value["lifecycle_id"]:
254
+ raise LessonLedgerError("evidence receipt lifecycle 与 incident 不匹配")
255
+ if value["round"] is not None and int(receipt_row[3]) != int(value["round"]):
256
+ raise LessonLedgerError("evidence receipt round 与 incident 不匹配")
257
+ from .sync_ops import require_verified_incident_evidence
258
+ require_verified_incident_evidence(path, value, {
259
+ "subject_type": receipt_row[0], "subject_id": receipt_row[1],
260
+ "lifecycle_id": receipt_row[2], "round": receipt_row[3],
261
+ "run_id": receipt_row[4], "artifact_hash": receipt_row[5],
262
+ })
263
+ if value["pattern_id"]:
264
+ parent = c.execute("SELECT status FROM patterns WHERE pattern_id=?", (value["pattern_id"],)).fetchone()
265
+ if not parent or parent[0] != "active":
266
+ raise LessonLedgerError("incident 关联的 Pattern 未 active")
267
+ stamp = now_iso()
268
+ c.execute("UPDATE incidents SET status='active',updated_at=? WHERE incident_id=?", (stamp, key))
269
+ record_event(c, "incident-activated", {"incident_id": key, "evidence_receipt_id": receipt})
270
+ return {"status": "active", "incident_id": key, "evidence_receipt_id": receipt}
271
+
272
+ return ledger_transaction(path, go)
273
+
274
+
275
+ def fetch_incident_tools(c: sqlite3.Connection, lifecycle_id: str | None,
276
+ round_no: int | None) -> tuple[str, str]:
277
+ if not lifecycle_id or round_no is None:
278
+ return "", ""
279
+ rows = c.execute(
280
+ "SELECT tool_name, category, outcome FROM tool_usage "
281
+ "WHERE lifecycle_id=? AND round=? ORDER BY created_at, rowid",
282
+ (lifecycle_id, round_no),
283
+ ).fetchall()
284
+ if not rows:
285
+ return "", ""
286
+ tools: list[str] = []
287
+ attempts: list[dict[str, Any]] = []
288
+ for tool_name, category, outcome in rows:
289
+ name = str(tool_name)
290
+ if name not in tools:
291
+ tools.append(name)
292
+ attempts.append({
293
+ "seq": len(attempts) + 1, "tool": name, "action": str(category or ""),
294
+ "outcome": str(outcome or ""), "note": "",
295
+ })
296
+ try:
297
+ payload = json.dumps(attempts, ensure_ascii=False)
298
+ except (TypeError, ValueError):
299
+ payload = ""
300
+ return ",".join(tools), payload
301
+
302
+
303
+ def incident_value(c: sqlite3.Connection, key: str) -> dict[str, Any]:
304
+ row = c.execute(
305
+ "SELECT incident_id,pattern_id,signature,summary,context,before_snippet,after_snippet,diff_ref,commit_ref,decision,duration_seconds,lifecycle_id,round,status,created_at,updated_at,content_hash,routing_tags,finding_fingerprint FROM incidents WHERE incident_id=?",
306
+ (key,),
307
+ ).fetchone()
308
+ if not row:
309
+ raise LessonLedgerError(f"incident_id 不存在: {key}")
310
+ item = {
311
+ "incident_id": row[0], "pattern_id": row[1], "signature": row[2],
312
+ "summary": row[3], "context": row[4], "before_snippet": row[5],
313
+ "after_snippet": row[6], "diff_ref": row[7], "commit_ref": row[8],
314
+ "decision": row[9], "duration_seconds": row[10], "lifecycle_id": row[11],
315
+ "round": row[12], "status": row[13], "created_at": row[14],
316
+ "updated_at": row[15], "content_hash": row[16],
317
+ "routing_tags": decode_routing_tags(row[17]),
318
+ "finding_fingerprint": (
319
+ _incident_fingerprint(row[18]) if row[18] is not None else None
320
+ ),
321
+ }
322
+ item["tools_used"], item["tool_attempts"] = fetch_incident_tools(
323
+ c, item["lifecycle_id"], item["round"],
324
+ )
325
+ raw_oracle = ""
326
+ if "复现:" in item.get("context", ""):
327
+ tail = item["context"].split("复现:", 1)[1]
328
+ if "confirmed finding" not in tail:
329
+ raw_oracle = tail.strip()
330
+ item["repro_oracle"] = raw_oracle[:300].strip()
331
+ return item
332
+
333
+
334
+ def lookup_incidents(
335
+ path: str | os.PathLike[str],
336
+ *,
337
+ query: str = "",
338
+ signatures: Iterable[str] = (),
339
+ pattern_id: str | None = None,
340
+ limit: int = 2,
341
+ token_budget: int | None = 3072,
342
+ byte_budget: int | None = 20480,
343
+ runtime_only: bool = False,
344
+ routing_tags: Mapping[str, Iterable[str]] | None = None,
345
+ ) -> list[dict[str, Any]]:
346
+ from .sync_ops import validate_pattern
347
+ if not isinstance(limit, int) or isinstance(limit, bool) or not 1 <= limit <= 10:
348
+ raise LessonLedgerError("limit 必须在 1..10")
349
+ signature_fingerprints: set[str] = set()
350
+ wanted: list[str] = []
351
+ for raw_signature in signatures:
352
+ if isinstance(raw_signature, str) and raw_signature.lstrip().casefold().startswith("sig-v"):
353
+ match = re.fullmatch(r"sig-v1:sha256:([0-9a-f]{64})", raw_signature)
354
+ if not match:
355
+ raise LessonLedgerError("versioned signature 格式无效")
356
+ signature_fingerprints.add(f"sha256:{match.group(1)}")
357
+ else:
358
+ wanted.append(normalize_signature(raw_signature))
359
+ tokens = [normalize_id(x) for x in re.findall(r"[\w-]+", query, re.UNICODE)]
360
+ requested_tags = {
361
+ key: [str(value).casefold() for value in values]
362
+ for key, values in (routing_tags or {}).items()
363
+ if key in ROUTING_TAG_KEYS
364
+ }
365
+ db = database_path(path)
366
+ with connect_ledger(db, readonly=True) as c:
367
+ validate_pattern(c, db)
368
+ identity_ids: set[str] = set()
369
+ for fingerprint in sorted(signature_fingerprints):
370
+ identity_ids.update(
371
+ str(row[0])
372
+ for row in c.execute(
373
+ "SELECT incident_id FROM incidents "
374
+ "INDEXED BY idx_incidents_finding_fingerprint "
375
+ "WHERE finding_fingerprint=?",
376
+ (fingerprint,),
377
+ )
378
+ )
379
+ rows = []
380
+ for row in c.execute(
381
+ "SELECT i.incident_id,i.status FROM incidents i "
382
+ "LEFT JOIN patterns p ON p.pattern_id=i.pattern_id "
383
+ "WHERE i.status IN ('candidate','active')"
384
+ ):
385
+ item = incident_value(c, row[0])
386
+ # DOC-203: candidate incidents are runtime-eligible only with an
387
+ # executable reproduction oracle; placeholder prose is insufficient.
388
+ has_valid_oracle = bool(
389
+ item.get("repro_oracle")
390
+ or ("复现:" in item.get("context", "")
391
+ and "confirmed finding" not in item.get("context", ""))
392
+ )
393
+ identity_exact_hit = item["incident_id"] in identity_ids
394
+ if runtime_only and item["status"] != "active":
395
+ if not (has_valid_oracle and len(item.get("context", "")) >= 15):
396
+ continue
397
+ if runtime_only and item["pattern_id"]:
398
+ parent = c.execute("SELECT status FROM patterns WHERE pattern_id=?", (item["pattern_id"],)).fetchone()
399
+ if parent and parent[0] not in {"active", "candidate"}:
400
+ continue
401
+ if pattern_id and item["pattern_id"] != pattern_id:
402
+ continue
403
+ exact = any(item["signature"] == value for value in wanted)
404
+ partial = sum(w in item["signature"] or item["signature"] in w for w in wanted)
405
+ clean_snippets = [
406
+ s for s in (item.get("before_snippet", ""),
407
+ item.get("after_snippet", ""), item.get("decision", ""))
408
+ if s and "未提供" not in s and "自动沉淀" not in s
409
+ ]
410
+ hay = normalize_id(" ".join([
411
+ item["signature"], item["summary"], item["context"], *clean_snippets,
412
+ ]))
413
+ matches = sum(t in hay for t in tokens)
414
+ score = (
415
+ (100 if exact else 0)
416
+ + (35 if not exact and partial else 0)
417
+ + matches * 8
418
+ )
419
+ routing_score, match_reasons = routing_match(item, requested_tags)
420
+ score += routing_score
421
+ if has_valid_oracle:
422
+ score += 25
423
+ match_reasons.append("has_repro_oracle")
424
+ if not identity_exact_hit and not exact and tokens and not matches:
425
+ continue
426
+ candidate = {
427
+ **item,
428
+ "lesson_id": item["pattern_id"] or item["incident_id"],
429
+ "match_score": score,
430
+ "match_reasons": match_reasons,
431
+ }
432
+ # The index result and text scan are joined by Incident ID. The identity
433
+ # flag is computed once from that union, equivalent to OR-ing both origins.
434
+ rows.append((identity_exact_hit, candidate))
435
+ rows.sort(key=lambda pair: (
436
+ not pair[0], -pair[1]["match_score"], pair[1]["incident_id"],
437
+ ))
438
+ result = []
439
+ total_b = total_t = 0
440
+ for _identity_exact_hit, row in rows:
441
+ data = canonical_bytes(row)
442
+ size = len(data)
443
+ toks, _ = estimate_tokens(data)
444
+ # F-RSI-20261115-127:identity 精确命中是调用方显式 signatures 的
445
+ # 查询意图本体,不得被预算挤掉——context 合法上限 64KB 可超
446
+ # byte_budget 20480,被 continue 跳过后低分 text 行反被塞入,
447
+ # 显式签名查询静默落空。预算只约束文本扫描的加分行;limit 硬顶
448
+ # 对全部行仍生效。
449
+ if not _identity_exact_hit:
450
+ if byte_budget is not None and total_b + size > byte_budget:
451
+ continue
452
+ if token_budget is not None and total_t + toks > token_budget:
453
+ continue
454
+ result.append(row)
455
+ total_b += size
456
+ total_t += toks
457
+ if len(result) >= limit:
458
+ break
459
+ return result
460
+
461
+
462
+ def confirmed_finding_digest(item: Mapping[str, Any]) -> str:
463
+ finding = item.get("finding")
464
+ if not isinstance(finding, Mapping):
465
+ raise LessonLedgerError("hit feedback 必须包含已确认的 finding 对象")
466
+ try:
467
+ from . import finding_confirmation
468
+ normalized = dict(finding)
469
+ if not finding_confirmation.is_confirmed(normalized):
470
+ raise LessonLedgerError("hit feedback 的 finding 尚未通过真实 Bug 确认门禁")
471
+ except LessonLedgerError:
472
+ raise
473
+ except (ImportError, TypeError, ValueError) as exc:
474
+ raise LessonLedgerError(f"hit feedback 的 finding 确认协议无效: {exc}") from exc
475
+ return hashlib.sha256(canonical_bytes(normalized)).hexdigest()
476
+
477
+
478
+ def apply_review(path: str | os.PathLike[str], payload: Mapping[str, Any]) -> dict[str, Any]:
479
+ actor = payload.get("actor", "supervisor")
480
+ if actor != "supervisor":
481
+ raise LessonLedgerError("复盘写入必须由 Supervisor 提交")
482
+ life = sanitize_text(payload.get("lifecycle_id"), "lifecycle_id")
483
+ rnd = payload.get("round")
484
+ if not isinstance(rnd, int) or rnd < 1:
485
+ raise LessonLedgerError("round 必须是正整数")
486
+ finding = int(payload.get("finding_count", 0))
487
+ credited = int(payload.get("credited_count", 0))
488
+ if finding < 0 or credited < 0 or credited > finding:
489
+ raise LessonLedgerError("finding_count/credited_count 无效")
490
+ ids = parse_json_list(payload.get("pattern_ids", payload.get("lesson_ids", [])), "lesson_ids", False)
491
+ fps = [normalize_finding_fingerprint(x) for x in payload.get("finding_fingerprints", [])]
492
+ if len(fps) != credited:
493
+ raise LessonLedgerError("finding_fingerprints 数量必须等于 credited_count")
494
+ if len(fps) != len(set(fps)):
495
+ raise LessonLedgerError("finding_fingerprints 不得重复")
496
+ new = payload.get("new_patterns", payload.get("new_lessons", []))
497
+ reason = payload.get("no_new_lesson_reason")
498
+ feedback_items = payload.get("feedback", [])
499
+ if not isinstance(feedback_items, list) or any(not isinstance(item, Mapping) for item in feedback_items):
500
+ raise LessonLedgerError("feedback 必须是对象数组")
501
+ if not isinstance(new, list) or (not new and (not isinstance(reason, str) or not reason.strip())):
502
+ raise LessonLedgerError("没有新增经验时必须提供非空 no_new_lesson_reason")
503
+ supersede = payload.get("supersede", False)
504
+ if not isinstance(supersede, bool):
505
+ raise LessonLedgerError("supersede 必须是布尔值")
506
+ # R6 复盘 S4:三张复盘表主键含 polling_id('' 表示遗留行/未提供)。
507
+ # 缺省 '' 保持旧调用方(外部 Supervisor CLI)的写入语义不变。
508
+ polling = sanitize_text_opt(payload.get("polling_id"), "polling_id", 200)
509
+
510
+ def go(c):
511
+ old = c.execute(
512
+ "SELECT finding_count,credited_count,reason,created_at "
513
+ "FROM reviews WHERE polling_id=? AND lifecycle_id=? AND round=?",
514
+ (polling, life, rnd),
515
+ ).fetchone()
516
+ if old:
517
+ if not supersede:
518
+ raise LessonLedgerError("同一 polling + lifecycle_id + round 不得重复提交 cycle-review")
519
+ # 显式替换(supersede)通道:reviews/review_patterns/review_findings/
520
+ # feedback 都是派生态,旧 review 可在删除后重录;events 哈希链只追加,
521
+ # 旧 cycle-review 事件保留,另落一条 cycle-review-superseded 审计事件。
522
+ # polling_id 维度加入后,替换只在**同一 polling 作用域**内生效;
523
+ # 跨 polling 的同号复盘是独立行,无需替换即可共存。
524
+ old_patterns = [
525
+ {"pattern_id": row[0], "relation": row[1]}
526
+ for row in c.execute(
527
+ "SELECT pattern_id,relation FROM review_patterns "
528
+ "WHERE polling_id=? AND lifecycle_id=? AND round=? "
529
+ "ORDER BY pattern_id",
530
+ (polling, life, rnd),
531
+ ).fetchall()
532
+ ]
533
+ old_findings = [
534
+ row[0] for row in c.execute(
535
+ "SELECT fingerprint FROM review_findings "
536
+ "WHERE polling_id=? AND lifecycle_id=? AND round=? "
537
+ "ORDER BY fingerprint",
538
+ (polling, life, rnd),
539
+ ).fetchall()
540
+ ]
541
+ old_feedback = [
542
+ {"pattern_id": row[0], "fingerprint": row[1]}
543
+ for row in c.execute(
544
+ "SELECT pattern_id,fingerprint FROM feedback "
545
+ "WHERE lifecycle_id=? AND round=? ORDER BY pattern_id,fingerprint",
546
+ (life, rnd),
547
+ ).fetchall()
548
+ ]
549
+ stamp = now_iso()
550
+ # 'reused' 的 use_count 是旧 review 造成的增量,替换时回滚;
551
+ # 'created' 的 pattern 是真实知识产物,保留且不动 patterns 表。
552
+ for item in old_patterns:
553
+ if item["relation"] == "reused":
554
+ c.execute(
555
+ "UPDATE patterns SET use_count=MAX(use_count-1,0),updated_at=? "
556
+ "WHERE pattern_id=?",
557
+ (stamp, item["pattern_id"]),
558
+ )
559
+ # feedback 行与其消费事件一并清除:supersede 重录时同
560
+ # (pattern_id, fingerprint) 会撞 feedback 主键与 consumption_events
561
+ # event_id。patterns 上的 hit_count 等质量计数保持单调,不回滚。
562
+ for item in old_feedback:
563
+ c.execute(
564
+ "DELETE FROM consumption_events WHERE event_id=?",
565
+ (f"feedback:{life}:{rnd}:{item['pattern_id']}:{item['fingerprint']}",),
566
+ )
567
+ c.execute("DELETE FROM feedback WHERE lifecycle_id=? AND round=?", (life, rnd))
568
+ c.execute(
569
+ "DELETE FROM review_findings WHERE polling_id=? AND lifecycle_id=? AND round=?",
570
+ (polling, life, rnd),
571
+ )
572
+ c.execute(
573
+ "DELETE FROM review_patterns WHERE polling_id=? AND lifecycle_id=? AND round=?",
574
+ (polling, life, rnd),
575
+ )
576
+ c.execute(
577
+ "DELETE FROM reviews WHERE polling_id=? AND lifecycle_id=? AND round=?",
578
+ (polling, life, rnd),
579
+ )
580
+ record_event(c, "cycle-review-superseded", {
581
+ "polling_id": polling, "lifecycle_id": life, "round": rnd,
582
+ "superseded": {
583
+ "finding_count": old[0], "credited_count": old[1],
584
+ "reason": old[2], "created_at": old[3],
585
+ "patterns": old_patterns, "finding_fingerprints": old_findings,
586
+ "feedback": old_feedback,
587
+ },
588
+ "superseded_by": {
589
+ "finding_count": finding, "credited_count": credited,
590
+ "finding_fingerprints": fps,
591
+ },
592
+ })
593
+ created = []
594
+ for raw in new:
595
+ p = normalize_pattern(raw)
596
+ row = c.execute("SELECT 1 FROM patterns WHERE pattern_id=?", (p["pattern_id"],)).fetchone()
597
+ if p["status"] != "candidate":
598
+ raise LessonLedgerError("复盘新增经验只能是 candidate;状态晋级必须经过独立治理流程")
599
+ if row:
600
+ if not patterns_are_equal(pattern_value(c, p["pattern_id"]), p):
601
+ raise LessonLedgerError("新增 pattern 内容冲突")
602
+ else:
603
+ insert_pattern(c, p)
604
+ created.append(p["pattern_id"])
605
+ for key in ids:
606
+ if not c.execute("SELECT 1 FROM patterns WHERE pattern_id=?", (key,)).fetchone():
607
+ raise LessonLedgerError("复盘引用不存在的 pattern_id: " + key)
608
+ stamp = now_iso()
609
+ c.execute(
610
+ "INSERT INTO reviews VALUES (?,?,?,?,?,?,?)",
611
+ (polling, life, rnd, finding, credited,
612
+ reason.strip() if isinstance(reason, str) else None, stamp),
613
+ )
614
+ for key in ids:
615
+ c.execute(
616
+ "INSERT INTO review_patterns VALUES (?,?,?,?,?)",
617
+ (polling, life, rnd, key, "reused"),
618
+ )
619
+ c.execute("UPDATE patterns SET use_count=use_count+1,last_used_at=?,updated_at=? WHERE pattern_id=?", (stamp, stamp, key))
620
+ for key in created:
621
+ c.execute(
622
+ "INSERT INTO review_patterns VALUES (?,?,?,?,?)",
623
+ (polling, life, rnd, key, "created"),
624
+ )
625
+ c.executemany(
626
+ "INSERT INTO review_findings VALUES (?,?,?,?)",
627
+ [(polling, life, rnd, x) for x in fps],
628
+ )
629
+ review = {
630
+ "polling_id": polling,
631
+ "lifecycle_id": life, "round": rnd, "finding_count": finding, "credited_count": credited,
632
+ "lesson_ids": ids, "pattern_ids": ids, "new_lesson_ids": created, "new_pattern_ids": created,
633
+ "finding_fingerprints": fps, "no_new_lesson_reason": reason.strip() if isinstance(reason, str) else None,
634
+ "feedback_count": len(feedback_items),
635
+ }
636
+ record_event(c, "cycle-review", review)
637
+ feedback_results = []
638
+ for item in feedback_items:
639
+ key = sanitize_text(item.get("pattern_id") or item.get("lesson_id"), "pattern_id")
640
+ outcome = sanitize_text(item.get("outcome"), "outcome")
641
+ digest = confirmed_finding_digest(item) if outcome == "hit" else None
642
+ feedback_results.append(record_feedback_tx(
643
+ c, life, rnd, key, normalize_finding_fingerprint(item.get("finding_fingerprint")),
644
+ outcome, digest, item.get("signature"), item.get("run_id"),
645
+ ))
646
+ result = {
647
+ "status": "recorded", "review": review, "feedback": feedback_results,
648
+ "revision": c.execute("SELECT COUNT(*) FROM events").fetchone()[0],
649
+ }
650
+ if old:
651
+ result["replaced_review"] = {
652
+ "polling_id": polling, "lifecycle_id": life, "round": rnd,
653
+ "finding_count": old[0], "credited_count": old[1],
654
+ "reason": old[2], "created_at": old[3],
655
+ }
656
+ return result
657
+
658
+ return ledger_transaction(path, go)
659
+
660
+
661
+ def record_feedback_tx(
662
+ c: sqlite3.Connection, life: str, rnd: int, key: str, fp: str,
663
+ outcome: str, confirmation_digest: str | None = None,
664
+ signature: str | None = None, run_id: str | None = None,
665
+ ) -> dict[str, Any]:
666
+ if outcome not in PATTERN_OUTCOMES:
667
+ raise LessonLedgerError("feedback 参数无效")
668
+ if not c.execute("SELECT 1 FROM review_patterns WHERE lifecycle_id=? AND round=? AND pattern_id=?", (life, rnd, key)).fetchone():
669
+ raise LessonLedgerError("反馈的 pattern_id 未在对应 cycle-review 中复用或新增")
670
+ if not c.execute("SELECT 1 FROM review_findings WHERE lifecycle_id=? AND round=? AND fingerprint=?", (life, rnd, fp)).fetchone():
671
+ raise LessonLedgerError("反馈的 finding_fingerprint 未在对应 cycle-review 中声明")
672
+ normalized_signature = normalize_signature(signature) if signature else None
673
+ try:
674
+ c.execute(
675
+ "INSERT INTO feedback(lifecycle_id,round,pattern_id,fingerprint,outcome,created_at,signature) "
676
+ "VALUES (?,?,?,?,?,?,?)",
677
+ (life, rnd, key, fp, outcome, now_iso(), normalized_signature),
678
+ )
679
+ except sqlite3.IntegrityError as exc:
680
+ raise LessonLedgerError("同一反馈不得重复提交") from exc
681
+ stamp = now_iso()
682
+ field = {
683
+ "hit": "hit_count", "miss": "miss_count",
684
+ "false_positive": "false_positive_count",
685
+ "rejected": "rejected_count",
686
+ }.get(outcome)
687
+ if field:
688
+ c.execute(
689
+ f"UPDATE patterns SET {field}={field}+1,updated_at=? WHERE pattern_id=?",
690
+ (stamp, key),
691
+ )
692
+ c.execute("INSERT OR IGNORE INTO occurrences VALUES (?,?,?)", (key, fp, stamp))
693
+ promoted = outcome == "hit" and c.execute("SELECT status FROM patterns WHERE pattern_id=?", (key,)).fetchone()[0] == "candidate" and c.execute("SELECT COUNT(DISTINCT lifecycle_id) FROM feedback WHERE pattern_id=? AND outcome='hit'", (key,)).fetchone()[0] >= 2
694
+ if promoted:
695
+ c.execute("UPDATE patterns SET status='active',updated_at=? WHERE pattern_id=? AND status='candidate'", (stamp, key))
696
+ refresh_materialized_views(c, key)
697
+ event = {
698
+ "lifecycle_id": life, "round": rnd, "pattern_id": key,
699
+ "lesson_id": key, "finding_fingerprint": fp, "outcome": outcome,
700
+ }
701
+ if confirmation_digest:
702
+ event["confirmation_digest"] = confirmation_digest
703
+ if normalized_signature:
704
+ event["signature"] = normalized_signature
705
+ if outcome == "hit" and normalized_signature and c.execute(
706
+ "SELECT 1 FROM feedback WHERE pattern_id=? AND outcome='miss' "
707
+ "AND signature=? AND lifecycle_id<>? LIMIT 1",
708
+ (key, normalized_signature, life),
709
+ ).fetchone():
710
+ event["delayed_hit"] = True
711
+ record_event(c, "pattern-delayed-hit", {
712
+ "pattern_id": key, "lesson_id": key, "lifecycle_id": life,
713
+ "round": rnd, "signature": normalized_signature,
714
+ })
715
+ record_event(c, "pattern-feedback", event)
716
+ record_consumption_event_tx(c, {
717
+ "event_id": f"feedback:{life}:{rnd}:{key}:{fp}",
718
+ "subject_type": "pattern", "subject_id": key, "event_type": "feedback",
719
+ "lifecycle_id": life, "run_id": str(run_id or ""),
720
+ "created_at": now_iso(),
721
+ })
722
+ if promoted:
723
+ record_event(c, "pattern-promoted", {"pattern_id": key, "lesson_id": key, "reason": "two independent lifecycle hits"})
724
+ return {"status": "recorded", "lesson_id": key, "pattern_id": key, "outcome": outcome}
725
+
726
+
727
+ def record_feedback(path: str | os.PathLike[str], payload: Mapping[str, Any]) -> dict[str, Any]:
728
+ if payload.get("actor", "supervisor") != "supervisor":
729
+ raise LessonLedgerError("反馈写入必须由 Supervisor 提交")
730
+ life = sanitize_text(payload.get("lifecycle_id"), "lifecycle_id")
731
+ rnd = payload.get("round")
732
+ key = sanitize_text(payload.get("pattern_id") or payload.get("lesson_id"), "pattern_id")
733
+ outcome = sanitize_text(payload.get("outcome"), "outcome")
734
+ fp = normalize_finding_fingerprint(payload.get("finding_fingerprint"))
735
+ if not isinstance(rnd, int) or rnd < 1:
736
+ raise LessonLedgerError("feedback 参数无效")
737
+ confirmation_digest = confirmed_finding_digest(payload) if outcome == "hit" else None
738
+ signature = payload.get("signature")
739
+ run_id = payload.get("run_id")
740
+
741
+ def go(c):
742
+ result = record_feedback_tx(
743
+ c, life, rnd, key, fp, outcome, confirmation_digest, signature, run_id,
744
+ )
745
+ result["revision"] = c.execute("SELECT COUNT(*) FROM events").fetchone()[0]
746
+ return result
747
+
748
+ return ledger_transaction(path, go)
749
+
750
+
751
+ def feedback_outcomes(path: str | os.PathLike[str] = DEFAULT_LEDGER, *,
752
+ lifecycle_id: str | None = None,
753
+ limit: int = 100) -> list[dict[str, Any]]:
754
+ from .sync_ops import validate_pattern
755
+ if not isinstance(limit, int) or isinstance(limit, bool) or not 1 <= limit <= 100:
756
+ raise LessonLedgerError("limit 必须在 1..100")
757
+ uploadable = {"hit": "hit", "miss": "miss", "false_positive": "false_positive", "rejected": "rejected"}
758
+ db = database_path(path)
759
+ with connect_ledger(db, readonly=True) as c:
760
+ validate_pattern(c, db)
761
+ sql = "SELECT pattern_id, outcome FROM feedback "
762
+ args: list[Any] = []
763
+ if lifecycle_id:
764
+ sql += "WHERE lifecycle_id=? "
765
+ args.append(lifecycle_id)
766
+ sql += "GROUP BY pattern_id, outcome ORDER BY MAX(created_at) DESC"
767
+ rows = c.execute(sql, args).fetchall()
768
+ items: list[dict[str, Any]] = []
769
+ seen: set[tuple[str, str]] = set()
770
+ for pattern_id, outcome in rows:
771
+ mapped = uploadable.get(str(outcome))
772
+ if not mapped:
773
+ continue
774
+ key = (str(pattern_id), mapped)
775
+ if key in seen:
776
+ continue
777
+ seen.add(key)
778
+ items.append({"lesson_id": key[0], "outcome": mapped})
779
+ if len(items) >= limit:
780
+ break
781
+ return items
782
+
783
+
784
+ def list_incidents(path: str | os.PathLike[str], *, pattern_id: str | None = None,
785
+ limit: int = 1000, offset: int = 0) -> list[dict[str, Any]]:
786
+ from .sync_ops import validate_pattern
787
+ if not isinstance(limit, int) or isinstance(limit, bool) or not 1 <= limit <= 5000:
788
+ raise LessonLedgerError("limit 必须在 1..5000")
789
+ if not isinstance(offset, int) or isinstance(offset, bool) or offset < 0:
790
+ raise LessonLedgerError("offset 必须是非负整数")
791
+ db = database_path(path)
792
+ with connect_ledger(db, readonly=True) as c:
793
+ validate_pattern(c, db)
794
+ if pattern_id:
795
+ rows = c.execute(
796
+ "SELECT incident_id FROM incidents WHERE pattern_id=? "
797
+ "ORDER BY incident_id LIMIT ? OFFSET ?",
798
+ (pattern_id, limit, offset),
799
+ )
800
+ else:
801
+ rows = c.execute(
802
+ "SELECT incident_id FROM incidents ORDER BY incident_id LIMIT ? OFFSET ?",
803
+ (limit, offset),
804
+ )
805
+ result = []
806
+ for row in rows:
807
+ value = incident_value(c, row[0])
808
+ result.append(value)
809
+ return result
810
+
811
+
812
+ def archive_incidents(path: str | os.PathLike[str], *, older_than_days: int = 90,
813
+ max_archive: int = 50) -> dict[str, Any]:
814
+ if not isinstance(older_than_days, int) or isinstance(older_than_days, bool) \
815
+ or older_than_days < 1:
816
+ raise LessonLedgerError("older_than_days 必须是正整数")
817
+ if not isinstance(max_archive, int) or isinstance(max_archive, bool) or max_archive < 1:
818
+ raise LessonLedgerError("max_archive 必须是正整数")
819
+ cutoff = (now_datetime() - dt.timedelta(days=older_than_days)).isoformat(timespec="seconds")
820
+
821
+ def go(c):
822
+ archived: list[dict[str, Any]] = []
823
+ marker = "archived-sha256:"
824
+ for row in c.execute(
825
+ "SELECT incident_id,updated_at,content_hash FROM incidents "
826
+ "WHERE updated_at < ? ORDER BY updated_at LIMIT ?",
827
+ (cutoff, max_archive),
828
+ ).fetchall():
829
+ incident_id, updated_at, original_hash = row[0], row[1], row[2]
830
+ current = incident_value(c, incident_id)
831
+ if str(current["before_snippet"]).startswith(marker):
832
+ continue
833
+ stamp = now_iso()
834
+ current["before_snippet"] = f"{marker}{original_hash}:before_snippet"
835
+ current["after_snippet"] = f"{marker}{original_hash}:after_snippet"
836
+ current["decision"] = f"{marker}{original_hash}:decision"
837
+ new_hash = incident_content_hash(current)
838
+ c.execute(
839
+ "UPDATE incidents SET before_snippet=?,after_snippet=?,decision=?,"
840
+ "updated_at=?,content_hash=? WHERE incident_id=?",
841
+ (current["before_snippet"], current["after_snippet"],
842
+ current["decision"], stamp, new_hash, incident_id),
843
+ )
844
+ archived.append({
845
+ "incident_id": incident_id, "content_hash": new_hash,
846
+ "archived_from_content_hash": original_hash,
847
+ "archived_from_updated_at": updated_at,
848
+ })
849
+ if archived:
850
+ record_event(c, "incidents-archived", {
851
+ "older_than_days": older_than_days,
852
+ "archived": archived,
853
+ })
854
+ return {
855
+ "status": "archived" if archived else "no-op",
856
+ "archived": len(archived),
857
+ "incidents": archived,
858
+ "older_than_days": older_than_days,
859
+ }
860
+
861
+ return ledger_transaction(path, go)
862
+
863
+
864
+ def revoke_incident(path: str | os.PathLike[str], incident_key: str, reason: str, *,
865
+ actor: str = "supervisor") -> dict[str, Any]:
866
+ if actor != "supervisor":
867
+ raise LessonLedgerError("incident 撤销必须由 Supervisor 提交")
868
+ key = sanitize_text(incident_key, "incident_id")
869
+ why = sanitize_text(reason, "reason")
870
+
871
+ def go(c):
872
+ value = incident_value(c, key)
873
+ if value["status"] == "revoked":
874
+ raise LessonLedgerError("incident 已撤销")
875
+ stamp = now_iso()
876
+ c.execute("UPDATE incidents SET status='revoked',updated_at=? WHERE incident_id=?", (stamp, key))
877
+ record_event(c, "incident-revoked", {"incident_id": key, "reason": why})
878
+ return {"status": "revoked", "incident_id": key}
879
+
880
+ return ledger_transaction(path, go)
881
+
882
+
883
+ def record_consumption_event(path: str | os.PathLike[str], event: Mapping[str, Any]) -> dict[str, Any]:
884
+ for field in ("event_id", "subject_type", "subject_id", "event_type"):
885
+ sanitize_text(event.get(field), field)
886
+ if event["event_type"] not in {"selected", "retrieved", "feedback"}:
887
+ raise LessonLedgerError("event_type 必须是 selected/retrieved/feedback")
888
+ item = {k: str(event.get(k) or "") for k in ("event_id", "subject_type", "subject_id", "event_type", "lifecycle_id", "run_id")}
889
+ item["created_at"] = str(event.get("created_at") or now_iso())
890
+
891
+ def go(c):
892
+ return record_consumption_event_tx(c, item)
893
+
894
+ return ledger_transaction(path, go)
895
+
896
+
897
+ def record_consumption_event_tx(c: sqlite3.Connection, item: Mapping[str, Any]) -> dict[str, Any]:
898
+ value = dict(item)
899
+ value["content_hash"] = hashlib.sha256(canonical_bytes(value)).hexdigest()
900
+ old = c.execute(
901
+ "SELECT subject_type,subject_id,event_type,lifecycle_id,run_id,created_at,content_hash "
902
+ "FROM consumption_events WHERE event_id=?",
903
+ (value["event_id"],),
904
+ ).fetchone()
905
+ if old:
906
+ # event_id is the retry/idempotency key. A retry normally gets a new
907
+ # wall-clock timestamp, so created_at cannot participate in the
908
+ # semantic conflict check. All other fields still must match: reusing
909
+ # one id for another subject/event remains fail-closed.
910
+ stored_semantics = tuple(old[index] for index in (0, 1, 2, 3, 4))
911
+ incoming_semantics = tuple(value[key] for key in (
912
+ "subject_type", "subject_id", "event_type", "lifecycle_id", "run_id",
913
+ ))
914
+ if stored_semantics != incoming_semantics:
915
+ raise LessonLedgerError("consumption event_id 内容冲突")
916
+ return {"status": "duplicate", "event_id": value["event_id"]}
917
+ c.execute(
918
+ "INSERT INTO consumption_events VALUES (?,?,?,?,?,?,?,?)",
919
+ tuple(value[x] for x in (
920
+ "event_id", "subject_type", "subject_id", "event_type",
921
+ "lifecycle_id", "run_id", "created_at", "content_hash",
922
+ )),
923
+ )
924
+ record_event(c, "knowledge-consumed", {
925
+ k: value[k] for k in value if k != "content_hash"
926
+ })
927
+ return {"status": "recorded", "event_id": value["event_id"]}
928
+
929
+
930
+ def export_consumption_events(
931
+ path: str | os.PathLike[str], *, limit: int = 500,
932
+ ) -> list[dict[str, Any]]:
933
+ """Export bounded, body-free consumption facts for V2 cloud sync."""
934
+ if not isinstance(limit, int) or isinstance(limit, bool) or not 1 <= limit <= 5000:
935
+ raise LessonLedgerError("consumption event limit 必须在 1..5000")
936
+ db = database_path(path)
937
+ with connect_ledger(db, readonly=True) as c:
938
+ validate_pattern(c, db)
939
+ rows = c.execute(
940
+ "SELECT event_id,subject_type,subject_id,event_type,lifecycle_id,run_id,created_at "
941
+ "FROM consumption_events ORDER BY created_at,event_id LIMIT ?", (limit,),
942
+ ).fetchall()
943
+ return [dict(row) for row in rows]
944
+
945
+
946
+ def review_exists(path: str | os.PathLike[str], lifecycle_id: str, round_no: int,
947
+ polling_id: str | None = None) -> bool:
948
+ """检查 cycle-review 是否存在。
949
+
950
+ polling_id 传入时精确匹配该 polling 作用域;None/''(旧调用方语义)
951
+ 只匹配 polling_id='' 的遗留行。
952
+ """
953
+ db = database_path(path)
954
+ scope = polling_id or ""
955
+ with connect_ledger(db, readonly=True) as c:
956
+ validate_pattern(c, db)
957
+ return c.execute(
958
+ "SELECT 1 FROM reviews WHERE polling_id=? AND lifecycle_id=? AND round=?",
959
+ (scope, lifecycle_id, round_no),
960
+ ).fetchone() is not None
961
+
962
+
963
+ def review_details(path: str | os.PathLike[str], lifecycle_id: str,
964
+ round_no: int, polling_id: str | None = None) -> dict[str, Any] | None:
965
+ """读取可验证的复盘内容,供宿主结算门禁使用。
966
+
967
+ polling_id 传入时精确匹配该 polling 作用域;None/''(旧调用方语义)
968
+ 只读取 polling_id='' 的遗留行。
969
+ """
970
+ db = database_path(path)
971
+ scope = polling_id or ""
972
+ with connect_ledger(db, readonly=True) as c:
973
+ validate_pattern(c, db)
974
+ row = c.execute(
975
+ "SELECT lifecycle_id,round,finding_count,credited_count,reason,created_at "
976
+ "FROM reviews WHERE polling_id=? AND lifecycle_id=? AND round=?",
977
+ (scope, lifecycle_id, round_no),
978
+ ).fetchone()
979
+ if not row:
980
+ return None
981
+ details = dict(row)
982
+ details["polling_id"] = scope
983
+ details["finding_fingerprints"] = [
984
+ str(item[0]) for item in c.execute(
985
+ "SELECT fingerprint FROM review_findings "
986
+ "WHERE polling_id=? AND lifecycle_id=? AND round=? "
987
+ "ORDER BY fingerprint",
988
+ (scope, lifecycle_id, round_no),
989
+ ).fetchall()
990
+ ]
991
+ details["pattern_ids"] = [
992
+ str(item[0]) for item in c.execute(
993
+ "SELECT pattern_id FROM review_patterns "
994
+ "WHERE polling_id=? AND lifecycle_id=? AND round=? "
995
+ "ORDER BY pattern_id",
996
+ (scope, lifecycle_id, round_no),
997
+ ).fetchall()
998
+ ]
999
+ # feedback 表没有 polling 维度(主键 (lifecycle_id, round, pattern_id,
1000
+ # fingerprint)),计数保持跨 polling 聚合的旧口径。
1001
+ details["feedback_count"] = int(c.execute(
1002
+ "SELECT COUNT(*) FROM feedback WHERE lifecycle_id=? AND round=?",
1003
+ (lifecycle_id, round_no),
1004
+ ).fetchone()[0])
1005
+ return details