bugx-cli 0.1.0 → 0.1.2

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 (338) hide show
  1. package/README.md +193 -185
  2. package/core/README.md +2 -2
  3. package/core/agent/README.md +2 -1
  4. package/core/agent/agent_artifacts.py +8 -6
  5. package/core/agent/agent_eval.py +136 -54
  6. package/core/agent/agent_execution.py +218 -52
  7. package/core/agent/agent_orchestrator.py +14 -8
  8. package/core/agent/agent_targets.py +8 -2
  9. package/core/agent/feature_baseline.py +150 -0
  10. package/core/assets/README.md +3 -2
  11. package/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
  12. package/core/assets/axe-core/LICENSE.txt +362 -0
  13. package/core/assets/axe-core/UPSTREAM.md +10 -0
  14. package/core/assets/axe-core/axe.min.js +12 -0
  15. package/core/assets/bugx-hero-en.svg +74 -0
  16. package/core/assets/bugx-hero-zh.svg +74 -0
  17. package/core/assets/bugx-social-preview.svg +71 -0
  18. package/core/assets/bugx-wechat-group.png +0 -0
  19. package/core/assets/codex.png +0 -0
  20. package/core/assets/dsh.png +0 -0
  21. package/core/assets/webui-chatgpt.jpg +0 -0
  22. package/core/assets/webui-session.jpg +0 -0
  23. package/core/assets/webui-skills.jpg +0 -0
  24. package/core/assets/webui-studio.jpg +0 -0
  25. package/core/assets/webui-zcode.jpg +0 -0
  26. package/core/assets/zcode.png +0 -0
  27. package/core/audit_packs/README.md +2 -0
  28. package/core/audit_packs/pitfalls/auth_crypto.json +64 -0
  29. package/core/audit_packs/pitfalls/file_ssrf_cmd.json +64 -0
  30. package/core/audit_packs/pitfalls/go_backend.json +66 -0
  31. package/core/audit_packs/pitfalls/java_spring.json +64 -0
  32. package/core/audit_packs/pitfalls/js_ts_web.json +67 -0
  33. package/core/audit_packs/pitfalls/python_web.json +82 -0
  34. package/core/autonomous_cve/SPEC.md +1 -1
  35. package/core/autonomous_cve/attack_graph_store.py +152 -106
  36. package/core/autonomous_cve/behavior_graph.py +8 -2
  37. package/core/autonomous_cve/verifier.py +4 -1
  38. package/core/bugx.md +1 -1
  39. package/core/bugx_paths.py +43 -8
  40. package/core/cli-help.txt +66 -0
  41. package/core/cloud_sync/SPEC.md +1 -1
  42. package/core/cloud_sync/cloud_client.py +81 -11
  43. package/core/cloud_sync/cloud_onboard.py +42 -1
  44. package/core/cloud_sync/consent.py +33 -3
  45. package/core/cloud_sync/flywheel_client.py +186 -15
  46. package/core/cloud_sync/network_transport.py +24 -3
  47. package/core/cloud_sync/sensitive_filter.py +2 -2
  48. package/core/cloud_sync/sync_push.py +12 -10
  49. package/core/contracts/AGENT_GUIDE.md +6 -9
  50. package/core/contracts/README.md +2 -2
  51. package/core/contracts/bugx-runtime-contract.md +1 -1
  52. package/core/contracts/bugx-worker.md +1 -1
  53. package/core/contracts/engine_gap_contracts.py +86 -3
  54. package/core/coverage/coverage_discovery.py +599 -29
  55. package/core/coverage/coverage_evidence.py +47 -0
  56. package/core/coverage/coverage_forensics.py +9 -0
  57. package/core/coverage/coverage_validate.py +6 -1
  58. package/core/dev_harness/SPEC.md +1 -1
  59. package/core/engine-integrity.json +670 -442
  60. package/core/fuzzing/concurrency_fuzzer.py +53 -0
  61. package/core/fuzzing/differential_oracle.py +562 -27
  62. package/core/fuzzing/fuzz_input.py +109 -6
  63. package/core/fuzzing/stateful_fuzzer.py +72 -0
  64. package/core/governance/secret_redactor.py +22 -10
  65. package/core/host_acp/SPEC.md +1 -1
  66. package/core/host_acp/__init__.py +4 -4
  67. package/core/host_acp/claude.py +59 -1
  68. package/core/host_acp/cline.py +64 -1
  69. package/core/host_acp/codex.py +56 -1
  70. package/core/host_acp/dsh.py +59 -1
  71. package/core/host_acp/opencode.py +56 -1
  72. package/core/host_acp/pi.py +59 -1
  73. package/core/host_acp/zcode.py +59 -1
  74. package/core/host_runtime/SPEC.md +1 -1
  75. package/core/host_runtime/adapters.py +1 -1
  76. package/core/host_runtime/cline.py +13 -0
  77. package/core/host_runtime/host_evaluators.py +44 -4
  78. package/core/host_runtime/host_probe.py +1 -1
  79. package/core/host_runtime/host_provider_arbitrator.py +116 -62
  80. package/core/host_runtime/host_registry.py +15 -8
  81. package/core/host_runtime/mcp_registry_gate.py +12 -1
  82. package/core/host_runtime/pi.py +102 -0
  83. package/core/host_runtime/provider_facts.py +66 -0
  84. package/core/hosts/SPEC.md +1 -1
  85. package/core/hosts/__init__.py +6 -2
  86. package/core/hosts/_dsh_usage.py +1 -1
  87. package/core/hosts/base.py +32 -4
  88. package/core/hosts/claude.py +55 -0
  89. package/core/hosts/cline.py +6 -2
  90. package/core/hosts/codex.py +58 -0
  91. package/core/hosts/dsh.py +9 -1
  92. package/core/hosts/opencode.py +6 -6
  93. package/core/hosts/pi.py +159 -2
  94. package/core/infra/README.md +4 -2
  95. package/core/infra/__init__.py +2 -0
  96. package/core/infra/build_info.py +22 -3
  97. package/core/infra/client_metadata.py +1 -1
  98. package/core/infra/json_utils.py +22 -0
  99. package/core/launch_phases/README.md +6 -3
  100. package/core/launch_phases/SPEC.md +1 -1
  101. package/core/launch_phases/common.py +21 -2
  102. package/core/launch_phases/finding_confirm_phase.py +170 -5
  103. package/core/launch_phases/finding_settlement.py +188 -1
  104. package/core/launch_phases/judge_phase.py +69 -12
  105. package/core/launch_phases/orchestrator_controls.py +11 -7
  106. package/core/launch_phases/post_coverage_sync.py +9 -2
  107. package/core/launch_phases/post_phase.py +144 -8
  108. package/core/launch_phases/post_receipt.py +12 -1
  109. package/core/launch_phases/pre_phase.py +3 -3
  110. package/core/launch_phases/pre_recon_scout.py +66 -36
  111. package/core/launch_phases/pre_state_builder.py +23 -176
  112. package/core/launch_phases/report_sharing.py +3 -7
  113. package/core/launch_phases/round_orchestrator.py +129 -58
  114. package/core/launch_phases/semantic_recon.py +545 -0
  115. package/core/launch_phases/session_runtime.py +56 -9
  116. package/core/launch_phases/startup_gates.py +36 -8
  117. package/core/launch_phases/startup_interaction.py +68 -12
  118. package/core/launch_phases/startup_version_gate.py +13 -3
  119. package/core/launch_phases/supervisor_bridge.py +46 -17
  120. package/core/launch_phases/supervisor_coverage.py +8 -2
  121. package/core/launch_phases/supervisor_degraded.py +1 -9
  122. package/core/launch_phases/verify_loop.py +767 -0
  123. package/core/launch_phases/worker_barriers.py +15 -5
  124. package/core/launch_phases/worker_orchestrator.py +105 -25
  125. package/core/launch_phases/worker_prior.py +115 -0
  126. package/core/ledger/README.md +2 -1
  127. package/core/ledger/SPEC.md +1 -1
  128. package/core/ledger/_facade.py +2 -1
  129. package/core/ledger/archive_ops.py +60 -2
  130. package/core/ledger/cli.py +6 -1
  131. package/core/ledger/export_ops.py +6 -1
  132. package/core/ledger/finding_confirmation.py +48 -6
  133. package/core/ledger/finding_lifecycle.py +428 -5
  134. package/core/ledger/finding_verification.py +555 -10
  135. package/core/ledger/fp_ledger.py +255 -0
  136. package/core/ledger/incidents.py +10 -4
  137. package/core/ledger/patterns.py +10 -7
  138. package/core/ledger/receipt_contract.py +17 -1
  139. package/core/ledger/sync_ops.py +21 -16
  140. package/core/ledger/tool_experience.py +2 -1
  141. package/core/ledger/verify_life.py +88 -17
  142. package/core/locales/en-US.json +2 -2
  143. package/core/locales/zh-CN.json +2 -2
  144. package/core/mcp_handlers/SPEC.md +1 -1
  145. package/core/mcp_handlers/base.py +23 -3
  146. package/core/mcp_handlers/channel_lifecycle.py +85 -30
  147. package/core/mcp_handlers/retrieval_handlers.py +11 -1
  148. package/core/mcp_handlers/rpc_server.py +6 -1
  149. package/core/mcp_handlers/supervisor_handlers.py +32 -6
  150. package/core/mcp_handlers/tool_table.py +15 -0
  151. package/core/mcp_runtime_support/environment.py +0 -38
  152. package/core/mcp_runtime_support/verifier.py +0 -52
  153. package/core/metadata.txt +2 -3
  154. package/core/planning/README.md +2 -1
  155. package/core/planning/domain_router.py +4 -2
  156. package/core/planning/dynamic_flow_analyzer.py +219 -14
  157. package/core/planning/judge_pipeline.py +87 -4
  158. package/core/planning/prompt_harness.py +57 -15
  159. package/core/planning/prompt_policy_engine.py +386 -0
  160. package/core/planning/spec_harvester.py +4 -4
  161. package/core/probes/INTERFACE.md +11 -1
  162. package/core/probes/SPEC.md +11 -1
  163. package/core/probes/__init__.py +46 -40
  164. package/core/probes/android_probe.py +177 -9
  165. package/core/probes/codebase_memory_probe.py +57 -0
  166. package/core/probes/desktop_probe.py +104 -0
  167. package/core/probes/differential_probe.py +99 -21
  168. package/core/probes/efficiency_probe.py +64 -0
  169. package/core/probes/ios_binary_probe.py +105 -1
  170. package/core/probes/memory_probe.py +66 -0
  171. package/core/probes/miniprogram_probe.py +75 -13
  172. package/core/probes/mobile_probe.py +215 -30
  173. package/core/probes/native_probe.py +88 -0
  174. package/core/probes/openwiki_probe.py +70 -0
  175. package/core/probes/pattern_probe.py +106 -0
  176. package/core/probes/platform_probe.py +81 -0
  177. package/core/probes/probe_registry.py +108 -7
  178. package/core/probes/sast_fixture_corpus.py +340 -0
  179. package/core/probes/sast_probe.py +553 -52
  180. package/core/probes/sast_rules.py +668 -28
  181. package/core/probes/sca_scanner.py +48 -0
  182. package/core/probes/ui_accessibility.py +149 -0
  183. package/core/probes/ui_audit.py +513 -0
  184. package/core/probes/ui_contract.py +273 -0
  185. package/core/probes/ui_evidence.py +212 -0
  186. package/core/probes/ui_measurements.py +314 -0
  187. package/core/probes/ui_repair.py +250 -0
  188. package/core/probes/ui_review.py +133 -0
  189. package/core/probes/ui_storybook.py +107 -0
  190. package/core/probes/ui_tokens.py +185 -0
  191. package/core/probes/ui_visual_diff.py +131 -0
  192. package/core/probes/web_probe.py +373 -18
  193. package/core/project_profiler/SPEC.md +1 -1
  194. package/core/project_profiler/arbitrator.py +6 -1
  195. package/core/project_profiler/detector.py +8 -1
  196. package/core/project_profiler/strategy.py +51 -15
  197. package/core/prompts/README.md +4 -2
  198. package/core/prompts/command_routing_en.md +2 -2
  199. package/core/prompts/command_routing_zh.md +2 -2
  200. package/core/prompts/policies/prompt_policies.json +101 -0
  201. package/core/prompts/stages/stage_repair.md +1 -1
  202. package/core/prompts/stages/stage_verify.defensive.md +42 -0
  203. package/core/prompts/stages/stage_verify.md +44 -0
  204. package/core/repair/README.md +1 -1
  205. package/core/repair/l7_repair_loop.py +1 -4
  206. package/core/repair/rsi_fixer.py +4 -4
  207. package/core/repair/rsi_loop.py +1 -3
  208. package/core/repair/rsi_repair.py +7 -7
  209. package/core/repair/rsi_scope.py +27 -8
  210. package/core/report_engine/SPEC.md +1 -1
  211. package/core/report_engine/attestation.py +8 -4
  212. package/core/report_engine/finding_report.py +2 -1
  213. package/core/report_engine/models.py +7 -9
  214. package/core/report_engine/report_share.py +0 -8
  215. package/core/report_engine/sast_bridge.py +2 -2
  216. package/core/report_engine/server.py +18 -8
  217. package/core/report_engine/web-conformance.md +123 -18
  218. package/core/report_engine/web_conformance.py +21 -52
  219. package/core/retrieval/README.md +2 -1
  220. package/core/retrieval/SPEC.md +1 -1
  221. package/core/retrieval/code_analyzer.py +50 -14
  222. package/core/retrieval/context_assembler.py +7 -1
  223. package/core/retrieval/knowledge_sync.py +108 -14
  224. package/core/retrieval/pitfall_packs.py +277 -0
  225. package/core/retrieval/symbol_index.py +25 -6
  226. package/core/retrieval/universal_code_matcher.py +234 -49
  227. package/core/runtime/README.md +1 -1
  228. package/core/runtime/bugx_logging.py +78 -7
  229. package/core/runtime/fixture_solidify.py +5 -10
  230. package/core/runtime/global_telemetry.py +20 -0
  231. package/core/runtime/incident_eval.py +1 -1
  232. package/core/runtime/model_runner.py +4 -41
  233. package/core/runtime/platform_adapter.py +2 -2
  234. package/core/runtime/prep_validate.py +4 -2
  235. package/core/runtime/project_settings.py +2 -1
  236. package/core/runtime/scenario_eval.py +50 -8
  237. package/core/skills/bugx_docs_mcp_server.py +3 -1
  238. package/core/skills/bugx_mcp_server.py +29 -2
  239. package/core/skills/tools_kb.py +1 -1
  240. package/core/supervisor/README.md +1 -1
  241. package/core/supervisor/SPEC.md +1 -1
  242. package/core/supervisor/budget_governor.py +503 -9
  243. package/core/supervisor/checkpoint_pipeline.py +248 -6
  244. package/core/supervisor/checkpoint_sync.py +13 -0
  245. package/core/supervisor/claim_events.py +1 -1
  246. package/core/supervisor/finding_workflow.py +22 -5
  247. package/core/supervisor/lease_manager.py +1 -1
  248. package/core/supervisor/lifecycle_blocks.py +6 -1
  249. package/core/supervisor/rejection_remedies.py +52 -5
  250. package/core/supervisor/serial_authorization.py +48 -4
  251. package/core/supervisor/task_scheduler.py +2 -2
  252. package/core/supervisor/worker_checkpoint.py +8 -1
  253. package/core/supervisor/worker_runtime.py +8 -2
  254. package/core/supervisor_types/worker_claim.py +9 -0
  255. package/core/webui/README.md +1 -1
  256. package/core/webui/SPEC.md +2 -1
  257. package/core/webui/adapters/claude.py +5 -1
  258. package/core/webui/adapters/cline.py +10 -2
  259. package/core/webui/adapters/codex.py +5 -1
  260. package/core/webui/adapters/dsh.py +5 -1
  261. package/core/webui/docs_session_service.py +2 -2
  262. package/core/webui/mcp_inspector.py +11 -7
  263. package/core/webui/static/00-base.css +1060 -0
  264. package/core/webui/static/01-monitoring.css +802 -0
  265. package/core/webui/static/02-header-actions.css +321 -0
  266. package/core/webui/static/03-trigger-popover.css +697 -0
  267. package/core/webui/static/04-composer.css +628 -0
  268. package/core/webui/static/05-skills-center.css +878 -0
  269. package/core/webui/static/06-mcp-center.css +623 -0
  270. package/core/webui/static/07-skill-detail.css +265 -0
  271. package/core/webui/static/08-files-management.css +167 -0
  272. package/core/webui/static/09-files-center.css +386 -0
  273. package/core/webui/static/10-icons.css +105 -0
  274. package/core/webui/static/11-project-options.css +185 -0
  275. package/core/webui/static/12-profile-tab.css +383 -0
  276. package/core/webui/static/design-tokens.css +113 -0
  277. package/core/webui/static/index.html +14 -1
  278. package/core/webui/workspace_service.py +1 -1
  279. package/docs/07_distribution/01_README_NPM.md +193 -185
  280. package/ecosystem/integrations/README.md +1 -1
  281. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  282. package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
  283. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  284. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
  285. package/ecosystem/integrations/opencode/mcp-lock.json +14 -6
  286. package/ecosystem/integrations/opencode/opencode.json +23 -12
  287. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  288. package/ecosystem/integrations/qoder/connector-meta.json +1 -1
  289. package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
  290. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
  291. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
  292. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
  293. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
  294. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
  295. package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
  296. package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
  297. package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
  298. package/interfaces/bin/bugx.js +37 -0
  299. package/interfaces/cli/bugx_cli/__init__.py +4 -2
  300. package/interfaces/cli/bugx_cli/cli.py +172 -69
  301. package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
  302. package/interfaces/cli/bugx_cli/commands/agent.py +461 -134
  303. package/interfaces/cli/bugx_cli/commands/audit.py +10 -9
  304. package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
  305. package/interfaces/cli/bugx_cli/commands/cloud.py +31 -22
  306. package/interfaces/cli/bugx_cli/commands/doctor.py +449 -204
  307. package/interfaces/cli/bugx_cli/commands/interaction.py +5 -1
  308. package/interfaces/cli/bugx_cli/commands/knowledge.py +5 -4
  309. package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
  310. package/interfaces/cli/bugx_cli/commands/plugin.py +58 -23
  311. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +7 -7
  312. package/interfaces/cli/bugx_cli/commands/plugin_funide.py +2 -1
  313. package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +1 -1
  314. package/interfaces/cli/bugx_cli/commands/project.py +6 -13
  315. package/interfaces/cli/bugx_cli/commands/report.py +2 -6
  316. package/interfaces/cli/bugx_cli/commands/system.py +524 -169
  317. package/interfaces/cli/bugx_cli/common.py +21 -15
  318. package/interfaces/cli/bugx_cli/host_adapters.py +29 -54
  319. package/interfaces/cli/bugx_cli/hosts/registry.py +8 -6
  320. package/interfaces/cli/bugx_cli/infra/ai_advisor.py +157 -27
  321. package/interfaces/cli/bugx_cli/infra/engine_installer.py +35 -16
  322. package/interfaces/cli/bugx_cli/infra/host_sync.py +11 -8
  323. package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +76 -5
  324. package/interfaces/cli/bugx_cli/infra/security.py +13 -6
  325. package/package.json +30 -15
  326. package/pyproject.toml +60 -9
  327. package/scripts/ensure-python.mjs +7 -7
  328. package/scripts/sync-version.mjs +10 -21
  329. package/scripts/test-npm-wrapper.mjs +1 -1
  330. package/core/assets/bugx-hero-cn.png +0 -0
  331. package/core/assets/bugx-hero-en.png +0 -0
  332. package/core/webui/static/project-settings.css +0 -6458
  333. package/docs/07_distribution/README.md +0 -16
  334. package/docs/README.md +0 -121
  335. package/interfaces/README.md +0 -143
  336. package/interfaces/bin/README.md +0 -35
  337. package/interfaces/cli/README.md +0 -90
  338. package/scripts/README.md +0 -118
@@ -170,8 +170,8 @@ def replay_share_pending(*, force: bool = False) -> None:
170
170
 
171
171
  ``submit`` 是自动重放授权;``local`` 的 share_pending 是**事后**通道——
172
172
  旧实现对 ``local`` 硬短路,导致队列永不补偿(2026-11-09 复盘 4.3-2)。
173
- 现在 ``--replay-share-pending`` 显式授权(``force=True``)即可在 ``local``
174
- 下重放;``none`` 仍是硬禁止(本轮不参与共享),只有显式把策略改为
173
+ 现在使用 ``--replay-share-pending`` 显式授权即可在 ``local`` 下重放;
174
+ ``none`` 仍是硬禁止(本轮不参与共享),只有显式把策略改为
175
175
  ``local``/``submit`` 才能清账。
176
176
  """
177
177
  report_policy = _runtime_report_policy({})
@@ -312,7 +312,7 @@ def _maybe_enqueue_flywheel(runtime: dict, lifecycle: dict) -> None:
312
312
  pass
313
313
 
314
314
 
315
- def maybe_share_lifecycle(runtime: dict, lifecycle: dict, share: str | None) -> str:
315
+ def maybe_share_lifecycle(runtime: dict, lifecycle: dict) -> str:
316
316
  """按已持久化 ``report_policy`` 处理封存报告,不再通过旧 flag 交互。
317
317
 
318
318
  DOC-236 C6:若 L1 已采集并持久化 `report_policy`,则**按它执行且不再交互**
@@ -320,10 +320,6 @@ def maybe_share_lifecycle(runtime: dict, lifecycle: dict, share: str | None) ->
320
320
  `submit` 直接无交互提交(私有)。
321
321
  """
322
322
  report_policy = _runtime_report_policy(runtime)
323
- if share is not None:
324
- raise RuntimeError(
325
- "旧的 share/--no-share 参数已移除;请在 L1 使用 report_policy=none|local|submit"
326
- )
327
323
  if report_policy == "none":
328
324
  print(" (report_policy=none:本轮不参与结论共享与知识飞轮)")
329
325
  return "completed"
@@ -3,6 +3,7 @@
3
3
 
4
4
  from __future__ import annotations
5
5
 
6
+ import argparse
6
7
  import contextlib
7
8
  import difflib
8
9
  import hashlib
@@ -60,6 +61,8 @@ from core.launch_phases.common import (
60
61
  diagnostic_logger,
61
62
  run_verify_life,
62
63
  format_duration,
64
+ option_value as _option_value,
65
+ require_project_layout as _require_project_layout,
63
66
  isolated_runtime_scope,
64
67
  bugx_paths,
65
68
  bugx_logging,
@@ -277,19 +280,6 @@ def run_in_process(
277
280
  )
278
281
 
279
282
 
280
- def _require_project_layout() -> bool:
281
- """Refuse stateful commands when the project runtime scope is unavailable."""
282
- if uses_project_layout():
283
- return True
284
- if os.environ.get("BUGX_AIR_GAP") == "1":
285
- return True
286
- print(
287
- "[launch_bugx] ✗ 缺少有效的 .bugx 项目运行布局;"
288
- "拒绝向全局引擎写入运行态。请先在项目根执行 `bugx init`。"
289
- )
290
- return False
291
-
292
-
293
283
  def _resume_ticket_handoff(
294
284
  project_root: Path, resume_ticket_module, ticket: dict[str, Any],
295
285
  ) -> int | None:
@@ -456,13 +446,76 @@ _ci_detection_report = ci_detection_report
456
446
  _legacy_supervisor_state = legacy_supervisor_state
457
447
  _print_help = print_help
458
448
 
459
- def _option_value(args: list[str], option: str) -> str | None:
460
- for i, arg in enumerate(args):
461
- if arg == option:
462
- return args[i + 1] if i + 1 < len(args) else None
463
- if arg.startswith(f"{option}="):
464
- return arg.split("=", 1)[1]
465
- return None
449
+ #: engine 子命令单一真值源(F-RSI-20261112-083):main() 的 argv 归一化与
450
+ #: _main_impl() 的重复归一化共用同一清单——历史双份手抄已漂移一次(F-020
451
+ #: 只补了 main() 侧的 coverage)。dispatch 链新增子命令时只改这里。
452
+ _KNOWN_CMDS = frozenset({
453
+ "pre", "post", "status", "polling", "heartbeat", "pause", "resume",
454
+ "abort", "bootstrap-coverage", "fix-review", "audit", "control",
455
+ "workers", "judge", "findings-confirm", "revalidate-candidates", "prompt", "daemon", "help", "--help", "-h",
456
+ "coverage",
457
+ })
458
+
459
+ # The manual dispatchers use these argument shapes before opening a project.
460
+ # Other actions delegate argument parsing to their owning module.
461
+ _MANUAL_OPTIONS = {
462
+ "abort": ((), ("reason",)),
463
+ "bootstrap-coverage": (("confirm", "fresh-coverage"), ()),
464
+ "heartbeat": ((), ()),
465
+ "pause": ((), ()),
466
+ "polling": ((), ()),
467
+ "prompt": ((), ("stage",)),
468
+ "resume": ((), ()),
469
+ "workers": (
470
+ ("execute", "dry-run", "brief"),
471
+ ("count", "strategy", "provider", "model", "executable", "host",
472
+ "subagent-type", "max-workers", "stagger-seconds"),
473
+ ),
474
+ }
475
+ _STARTUP_OPTIONS = (
476
+ ("allow-serial", "approve-strategy", "autonomous", "bootstrap-coverage",
477
+ "ignore-global-budget", "json", "refresh-probes", "replay-share-pending"),
478
+ ("cloud-sync", "commit-policy", "fix-mode", "host", "lesson-category", "lesson-query",
479
+ "life-kind", "max-round-wall-seconds", "polling", "profile", "report-policy",
480
+ "review-mode", "serial-reason", "session-recovery", "startup-action",
481
+ "startup-interaction", "strategy-plan", "tooling-choice"),
482
+ )
483
+
484
+
485
+ def _manual_action_parser(command: str) -> argparse.ArgumentParser | None:
486
+ parser = argparse.ArgumentParser(prog=f"bugx engine {command}", allow_abbrev=False)
487
+ if command == "post":
488
+ parser.epilog = "结论共享由启动时设置的 --report-policy 控制。"
489
+ modes = parser.add_mutually_exclusive_group()
490
+ modes.add_argument("--dry-run", action="store_true", help="只评估结算快照")
491
+ modes.add_argument("--final", action="store_true", help="最终结算")
492
+ parser.add_argument("--allow-incomplete", action="store_true")
493
+ parser.add_argument("--allow-serial", action="store_true")
494
+ elif command in {"status", "control"}:
495
+ if command == "control":
496
+ parser.add_argument("action", nargs="?", default="status",
497
+ choices=("pause", "resume", "abort", "status"))
498
+ parser.add_argument("--reason")
499
+ parser.add_argument("--json", action="store_true")
500
+ else:
501
+ if command in {"pre", "audit"}:
502
+ switches, values = _STARTUP_OPTIONS
503
+ # [BEGIN DEV_ONLY: DEV_MODE_CLI_VALIDATION]
504
+ parser.add_argument("--dev", action="store_true")
505
+ # [END DEV_ONLY: DEV_MODE_CLI_VALIDATION]
506
+ elif command in _MANUAL_OPTIONS:
507
+ switches, values = _MANUAL_OPTIONS[command]
508
+ else:
509
+ return None
510
+ for name in switches:
511
+ parser.add_argument(f"--{name}", action="store_true")
512
+ number_types = {"count": int, "max-workers": int, "stagger-seconds": float} if command == "workers" else {}
513
+ for name in values:
514
+ parser.add_argument(f"--{name}", type=number_types.get(name, str))
515
+ if command == "polling":
516
+ parser.add_argument("policy", nargs="?", choices=("status", "auto", "manual"))
517
+ return parser
518
+
466
519
 
467
520
  def _reject_legacy_share_policy(argv: list[str]) -> int | None:
468
521
  """Reject the removed pre flag before any project/runtime side effect."""
@@ -481,20 +534,54 @@ def _reject_legacy_share_policy(argv: list[str]) -> int | None:
481
534
  def main(argv: list[str]) -> int:
482
535
  """Bind one context-local attempt around CLI post dispatch."""
483
536
  values = list(argv)
484
- known = {
485
- "pre", "post", "status", "polling", "heartbeat", "pause", "resume",
486
- "abort", "bootstrap-coverage", "fix-review", "audit", "control",
487
- "workers", "judge", "findings-confirm", "revalidate-candidates", "prompt", "daemon", "help", "--help", "-h",
488
- "coverage",
489
- }
537
+ known = _KNOWN_CMDS
490
538
  if values and (values[0] in known or values[0].startswith("-")):
491
539
  values = ["launch_bugx.py", *values]
492
540
  legacy_share_policy = _reject_legacy_share_policy(values)
493
541
  if legacy_share_policy is not None:
494
542
  return legacy_share_policy
495
543
  command = values[1] if len(values) > 1 else "status"
496
- if command != "post" or "--dry-run" in values[2:]:
497
- return _main_impl(values)
544
+ tail = values[2:]
545
+ if command in {"help", "--help", "-h"}:
546
+ if len(tail) > 1 or (tail and tail[0] not in _KNOWN_CMDS):
547
+ print("[launch_bugx] 未知帮助主题。", file=sys.stderr)
548
+ return 2
549
+ if tail and tail[0] not in {"help", "--help", "-h"}:
550
+ return main([values[0], tail[0], "--help"])
551
+ return _print_help()
552
+ if tail == ["help"]:
553
+ tail = ["--help"]
554
+ values[2:] = tail
555
+ options = None
556
+ if command in {"pre", "audit"} and "--allow-degraded" in tail and not {"-h", "--help"}.intersection(tail):
557
+ print("[launch_bugx] --allow-degraded 已移除。请修复缺失的安装或配置。", file=sys.stderr)
558
+ return 2
559
+ parser = _manual_action_parser(command)
560
+ if parser is not None:
561
+ if command in {"pre", "audit"} and {"-h", "--help"}.intersection(tail):
562
+ return _print_help()
563
+ removed_share = any(t.split("=", 1)[0] in {"--share", "--no-share"} for t in tail)
564
+ if command == "post" and removed_share and not {"-h", "--help"}.intersection(tail):
565
+ print("[launch_bugx] post 的共享选项已移除。请使用启动时的 --report-policy。", file=sys.stderr)
566
+ return 2
567
+ try:
568
+ options = parser.parse_args(tail)
569
+ except SystemExit as exc:
570
+ return int(exc.code)
571
+ if command == "control":
572
+ if options.reason is not None and options.action != "abort":
573
+ print("[launch_bugx] --reason 仅用于 control abort。", file=sys.stderr)
574
+ return 2
575
+ if options.json and options.action != "status":
576
+ print("[launch_bugx] --json 仅用于 control status。", file=sys.stderr)
577
+ return 2
578
+ if command == "post" and options.dry_run:
579
+ if options.allow_incomplete or options.allow_serial:
580
+ print("[launch_bugx] --dry-run 不接受结算授权选项。", file=sys.stderr)
581
+ return 2
582
+ return _post_dry_run_cli()
583
+ if command != "post":
584
+ return _main_impl(values, _options=options)
498
585
  from core.launch_phases.post_observability import (
499
586
  attempt_scope, current_attempt, log_attempt_finished,
500
587
  record_unhandled_exception,
@@ -502,7 +589,7 @@ def main(argv: list[str]) -> int:
502
589
  with attempt_scope("dispatcher") as attempt:
503
590
  try:
504
591
  result = _main_impl(
505
- values, _post_attempt_token=attempt.attempt_token,
592
+ values, _post_attempt_token=attempt.attempt_token, _options=options,
506
593
  )
507
594
  except BaseException as exc:
508
595
  exit_code = 130 if isinstance(exc, KeyboardInterrupt) else 1
@@ -524,12 +611,8 @@ def main(argv: list[str]) -> int:
524
611
 
525
612
  def _main_impl(
526
613
  argv: list[str], *, _post_attempt_token: object | None = None,
614
+ _options: argparse.Namespace | None = None,
527
615
  ) -> int:
528
- _KNOWN_CMDS = {
529
- "pre", "post", "status", "polling", "heartbeat", "pause", "resume",
530
- "abort", "bootstrap-coverage", "fix-review", "audit", "control",
531
- "workers", "judge", "findings-confirm", "revalidate-candidates", "prompt", "daemon", "help", "--help", "-h",
532
- }
533
616
  if argv and (argv[0] in _KNOWN_CMDS or argv[0].startswith("-")):
534
617
  argv = ["launch_bugx.py"] + list(argv)
535
618
  cmd = argv[1] if len(argv) > 1 else "status"
@@ -537,7 +620,7 @@ def _main_impl(
537
620
  if legacy_share_policy is not None:
538
621
  return legacy_share_policy
539
622
  _HELP_TOKENS = {"help", "--help", "-h"}
540
- if cmd in _HELP_TOKENS or any(token in _HELP_TOKENS for token in argv[2:]):
623
+ if cmd in _HELP_TOKENS or any(token in {"--help", "-h"} for token in argv[2:]):
541
624
  # 帮助契约要求三种写法都只读:`pre help` / `pre -h` 若不在这里截住,
542
625
  # 会落进真实 pre 相位并写启动态,违反文档承诺。
543
626
  return _print_help()
@@ -548,21 +631,13 @@ def _main_impl(
548
631
  from core.runtime import project_init
549
632
 
550
633
  if project_init.is_uninitialized_project(resolve_project_root()):
551
- return status(as_json="--json" in argv[2:])
634
+ return status(as_json=_options.json)
552
635
  except (OSError, ValueError, RuntimeError) as exc:
553
- if "--json" in argv[2:]:
636
+ if _options.json:
554
637
  print(json.dumps({"status": "BLOCKED", "reason": str(exc)}, ensure_ascii=False))
555
638
  else:
556
639
  print(f"[launch_bugx] ✗ 项目状态检查失败:{exc}")
557
640
  return 1
558
- if cmd in {"pre", "audit"} and "--allow-degraded" in argv[2:]:
559
- # DOC-236 C1(A4):降级放行已废除。守卫必须位于**所有** pre/audit 出口
560
- # 之前——放在尾部 dispatch 会被前置硬门禁(交互/版本/云/策略门禁)提前
561
- # 返回绕过,从而变成"静默忽略"而不是"显式拒绝"。
562
- print("[launch_bugx] ✗ --allow-degraded 已废除(DOC-236 C1 不允许降级):"
563
- "请先自愈安装/配置;确无自动安装器的专有工具,"
564
- "在 .bugx/config.json 的 tooling_exemptions 中显式豁免。")
565
- return 1
566
641
  # DOC-236 C5:只做轻量布局/config/fingerprint 准备;宿主、交互、Git、
567
642
  # 版本与云门禁全部通过后才进入完整画像/探针/coverage pipeline。
568
643
  # DOC-174 的 pending ticket 只做一次廉价恢复,不重新启动昂贵初始化。
@@ -605,8 +680,6 @@ def _main_impl(
605
680
  except (OSError, ValueError, RuntimeError, subprocess.SubprocessError) as exc:
606
681
  print(f"[launch_bugx] ✗ 项目初始化/续做失败:{exc}")
607
682
  return 1
608
- if cmd == "post" and "--dry-run" in argv[2:]:
609
- return _post_dry_run_cli()
610
683
  logger = None
611
684
  if cmd == "post":
612
685
  # Set up diagnostics before layout/version/runtime-path gates can reject.
@@ -842,8 +915,6 @@ def _main_impl(
842
915
  try:
843
916
  result: int
844
917
  if cmd == "post":
845
- _share = "share" if "--share" in argv[2:] else (
846
- "no-share" if "--no-share" in argv[2:] else None)
847
918
  post_started = time.monotonic()
848
919
  phase_status = "failed"
849
920
  try:
@@ -855,9 +926,9 @@ def _main_impl(
855
926
  ) as tracker:
856
927
  try:
857
928
  result = post(
858
- final="--final" in argv[2:], share=_share,
859
- allow_incomplete="--allow-incomplete" in argv[2:],
860
- allow_serial="--allow-serial" in argv[2:],
929
+ final=_options.final,
930
+ allow_incomplete=_options.allow_incomplete,
931
+ allow_serial=_options.allow_serial,
861
932
  _post_attempt_token=_post_attempt_token,
862
933
  )
863
934
  phase_status = "ok" if result == 0 else "failed"
@@ -892,7 +963,7 @@ def _main_impl(
892
963
  duration_seconds=round(phase_duration, 3),
893
964
  )
894
965
  elif cmd == "status":
895
- result = status(as_json="--json" in argv[2:])
966
+ result = status(as_json=_options.json)
896
967
  elif cmd == "polling":
897
968
  value = argv[2] if len(argv) > 2 else None
898
969
  result = polling(value)
@@ -910,7 +981,6 @@ def _main_impl(
910
981
  fresh_coverage="--fresh-coverage" in argv[2:],
911
982
  )
912
983
  elif cmd in {"pre", "audit"}:
913
- # `--allow-degraded` 已在 `_main_impl` 入口统一拒绝(A4),此处不再重复判定。
914
984
  pre_args = argv[2:]
915
985
  is_dev = dev_mode_requested
916
986
  strategy_plan_val = None
@@ -959,15 +1029,15 @@ def _main_impl(
959
1029
  host=_option_value(pre_args, "--host"),
960
1030
  )
961
1031
  elif cmd == "control":
962
- sub = argv[2] if len(argv) > 2 else "status"
1032
+ sub = _options.action
963
1033
  if sub == "pause":
964
1034
  result = pause()
965
1035
  elif sub == "resume":
966
1036
  result = resume()
967
1037
  elif sub == "abort":
968
- result = abort(_option_value(argv[3:], "--reason"))
1038
+ result = abort(_options.reason)
969
1039
  else:
970
- result = status(as_json="--json" in argv[2:])
1040
+ result = status(as_json=_options.json)
971
1041
  elif cmd == "findings-confirm":
972
1042
  from core.launch_phases import finding_confirm_phase
973
1043
  result = finding_confirm_phase.main(argv[2:])
@@ -1034,7 +1104,8 @@ def _main_impl(
1034
1104
  print(
1035
1105
  f"[launch_bugx] 未知命令: {cmd}"
1036
1106
  "(可选 pre/post/status/polling/heartbeat/pause/resume/abort/"
1037
- "bootstrap-coverage/fix-review/revalidate-candidates/audit/control/workers/prompt/daemon)"
1107
+ "bootstrap-coverage/fix-review/revalidate-candidates/audit/control/workers/"
1108
+ "judge/findings-confirm/coverage/prompt/daemon)"
1038
1109
  )
1039
1110
  result = 2
1040
1111
  except BudgetExhausted as exc: