bugx-cli 0.1.0 → 0.1.1

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 (311) hide show
  1. package/README.md +190 -186
  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/axe-core/LICENSE-3RD-PARTY.txt +66 -0
  11. package/core/assets/axe-core/LICENSE.txt +362 -0
  12. package/core/assets/axe-core/UPSTREAM.md +10 -0
  13. package/core/assets/axe-core/axe.min.js +12 -0
  14. package/core/assets/bugx-hero-en.svg +74 -0
  15. package/core/assets/bugx-hero-zh.svg +74 -0
  16. package/core/assets/codex.png +0 -0
  17. package/core/assets/dsh.png +0 -0
  18. package/core/assets/webui-chatgpt.jpg +0 -0
  19. package/core/assets/webui-session.jpg +0 -0
  20. package/core/assets/webui-skills.jpg +0 -0
  21. package/core/assets/webui-studio.jpg +0 -0
  22. package/core/assets/webui-zcode.jpg +0 -0
  23. package/core/assets/zcode.png +0 -0
  24. package/core/autonomous_cve/SPEC.md +1 -1
  25. package/core/autonomous_cve/attack_graph_store.py +152 -106
  26. package/core/autonomous_cve/behavior_graph.py +8 -2
  27. package/core/autonomous_cve/verifier.py +4 -1
  28. package/core/bugx.md +1 -1
  29. package/core/bugx_paths.py +43 -8
  30. package/core/cli-help.txt +66 -0
  31. package/core/cloud_sync/SPEC.md +1 -1
  32. package/core/cloud_sync/cloud_client.py +25 -6
  33. package/core/cloud_sync/cloud_onboard.py +42 -1
  34. package/core/cloud_sync/flywheel_client.py +16 -7
  35. package/core/cloud_sync/network_transport.py +24 -3
  36. package/core/cloud_sync/sensitive_filter.py +2 -2
  37. package/core/cloud_sync/sync_push.py +12 -10
  38. package/core/contracts/AGENT_GUIDE.md +6 -9
  39. package/core/contracts/README.md +2 -2
  40. package/core/contracts/bugx-runtime-contract.md +1 -1
  41. package/core/contracts/bugx-worker.md +1 -1
  42. package/core/contracts/engine_gap_contracts.py +86 -3
  43. package/core/coverage/coverage_discovery.py +599 -29
  44. package/core/coverage/coverage_evidence.py +47 -0
  45. package/core/coverage/coverage_forensics.py +9 -0
  46. package/core/coverage/coverage_validate.py +6 -1
  47. package/core/dev_harness/SPEC.md +1 -1
  48. package/core/engine-integrity.json +591 -419
  49. package/core/fuzzing/concurrency_fuzzer.py +53 -0
  50. package/core/fuzzing/differential_oracle.py +562 -27
  51. package/core/fuzzing/fuzz_input.py +109 -6
  52. package/core/fuzzing/stateful_fuzzer.py +72 -0
  53. package/core/governance/secret_redactor.py +22 -10
  54. package/core/host_acp/SPEC.md +1 -1
  55. package/core/host_acp/__init__.py +4 -4
  56. package/core/host_acp/claude.py +59 -1
  57. package/core/host_acp/cline.py +64 -1
  58. package/core/host_acp/codex.py +56 -1
  59. package/core/host_acp/dsh.py +59 -1
  60. package/core/host_acp/opencode.py +56 -1
  61. package/core/host_acp/pi.py +59 -1
  62. package/core/host_acp/zcode.py +59 -1
  63. package/core/host_runtime/SPEC.md +1 -1
  64. package/core/host_runtime/adapters.py +1 -1
  65. package/core/host_runtime/cline.py +13 -0
  66. package/core/host_runtime/host_evaluators.py +44 -4
  67. package/core/host_runtime/host_probe.py +1 -1
  68. package/core/host_runtime/host_provider_arbitrator.py +116 -62
  69. package/core/host_runtime/host_registry.py +15 -8
  70. package/core/host_runtime/mcp_registry_gate.py +12 -1
  71. package/core/host_runtime/pi.py +102 -0
  72. package/core/host_runtime/provider_facts.py +66 -0
  73. package/core/hosts/SPEC.md +1 -1
  74. package/core/hosts/__init__.py +6 -2
  75. package/core/hosts/_dsh_usage.py +1 -1
  76. package/core/hosts/base.py +32 -4
  77. package/core/hosts/claude.py +55 -0
  78. package/core/hosts/cline.py +6 -2
  79. package/core/hosts/codex.py +58 -0
  80. package/core/hosts/dsh.py +9 -1
  81. package/core/hosts/opencode.py +6 -6
  82. package/core/hosts/pi.py +159 -2
  83. package/core/infra/README.md +4 -2
  84. package/core/infra/__init__.py +2 -0
  85. package/core/infra/build_info.py +22 -3
  86. package/core/infra/client_metadata.py +1 -1
  87. package/core/infra/json_utils.py +22 -0
  88. package/core/launch_phases/README.md +2 -2
  89. package/core/launch_phases/SPEC.md +1 -1
  90. package/core/launch_phases/common.py +21 -2
  91. package/core/launch_phases/finding_confirm_phase.py +5 -1
  92. package/core/launch_phases/finding_settlement.py +188 -1
  93. package/core/launch_phases/judge_phase.py +69 -12
  94. package/core/launch_phases/orchestrator_controls.py +11 -7
  95. package/core/launch_phases/post_coverage_sync.py +9 -2
  96. package/core/launch_phases/post_phase.py +139 -3
  97. package/core/launch_phases/post_receipt.py +12 -1
  98. package/core/launch_phases/pre_phase.py +3 -3
  99. package/core/launch_phases/pre_recon_scout.py +53 -36
  100. package/core/launch_phases/pre_state_builder.py +23 -176
  101. package/core/launch_phases/round_orchestrator.py +15 -32
  102. package/core/launch_phases/session_runtime.py +56 -9
  103. package/core/launch_phases/startup_gates.py +36 -8
  104. package/core/launch_phases/startup_interaction.py +68 -12
  105. package/core/launch_phases/startup_version_gate.py +9 -3
  106. package/core/launch_phases/supervisor_bridge.py +46 -17
  107. package/core/launch_phases/supervisor_coverage.py +8 -2
  108. package/core/launch_phases/supervisor_degraded.py +1 -9
  109. package/core/launch_phases/worker_barriers.py +15 -5
  110. package/core/launch_phases/worker_orchestrator.py +105 -25
  111. package/core/ledger/README.md +1 -1
  112. package/core/ledger/SPEC.md +1 -1
  113. package/core/ledger/_facade.py +2 -1
  114. package/core/ledger/archive_ops.py +60 -2
  115. package/core/ledger/cli.py +6 -1
  116. package/core/ledger/export_ops.py +6 -1
  117. package/core/ledger/finding_confirmation.py +48 -6
  118. package/core/ledger/finding_lifecycle.py +428 -5
  119. package/core/ledger/finding_verification.py +44 -8
  120. package/core/ledger/incidents.py +10 -4
  121. package/core/ledger/patterns.py +10 -7
  122. package/core/ledger/receipt_contract.py +17 -1
  123. package/core/ledger/sync_ops.py +21 -16
  124. package/core/ledger/tool_experience.py +2 -1
  125. package/core/ledger/verify_life.py +88 -17
  126. package/core/locales/en-US.json +2 -2
  127. package/core/locales/zh-CN.json +2 -2
  128. package/core/mcp_handlers/SPEC.md +1 -1
  129. package/core/mcp_handlers/base.py +23 -3
  130. package/core/mcp_handlers/channel_lifecycle.py +85 -30
  131. package/core/mcp_handlers/retrieval_handlers.py +11 -1
  132. package/core/mcp_handlers/rpc_server.py +6 -1
  133. package/core/mcp_handlers/supervisor_handlers.py +32 -6
  134. package/core/mcp_handlers/tool_table.py +15 -0
  135. package/core/mcp_runtime_support/environment.py +0 -38
  136. package/core/mcp_runtime_support/verifier.py +0 -52
  137. package/core/metadata.txt +2 -3
  138. package/core/planning/README.md +1 -1
  139. package/core/planning/domain_router.py +4 -2
  140. package/core/planning/dynamic_flow_analyzer.py +219 -14
  141. package/core/planning/judge_pipeline.py +87 -4
  142. package/core/planning/prompt_harness.py +7 -5
  143. package/core/planning/spec_harvester.py +4 -4
  144. package/core/probes/INTERFACE.md +11 -1
  145. package/core/probes/SPEC.md +11 -1
  146. package/core/probes/__init__.py +46 -40
  147. package/core/probes/android_probe.py +177 -9
  148. package/core/probes/codebase_memory_probe.py +57 -0
  149. package/core/probes/desktop_probe.py +104 -0
  150. package/core/probes/differential_probe.py +99 -21
  151. package/core/probes/efficiency_probe.py +64 -0
  152. package/core/probes/ios_binary_probe.py +105 -1
  153. package/core/probes/memory_probe.py +66 -0
  154. package/core/probes/miniprogram_probe.py +75 -13
  155. package/core/probes/mobile_probe.py +215 -30
  156. package/core/probes/native_probe.py +88 -0
  157. package/core/probes/openwiki_probe.py +70 -0
  158. package/core/probes/pattern_probe.py +106 -0
  159. package/core/probes/platform_probe.py +81 -0
  160. package/core/probes/probe_registry.py +108 -7
  161. package/core/probes/sast_fixture_corpus.py +340 -0
  162. package/core/probes/sast_probe.py +553 -52
  163. package/core/probes/sast_rules.py +668 -28
  164. package/core/probes/sca_scanner.py +48 -0
  165. package/core/probes/ui_accessibility.py +149 -0
  166. package/core/probes/ui_audit.py +513 -0
  167. package/core/probes/ui_contract.py +273 -0
  168. package/core/probes/ui_evidence.py +212 -0
  169. package/core/probes/ui_measurements.py +314 -0
  170. package/core/probes/ui_repair.py +250 -0
  171. package/core/probes/ui_review.py +133 -0
  172. package/core/probes/ui_storybook.py +107 -0
  173. package/core/probes/ui_tokens.py +185 -0
  174. package/core/probes/ui_visual_diff.py +131 -0
  175. package/core/probes/web_probe.py +373 -18
  176. package/core/project_profiler/SPEC.md +1 -1
  177. package/core/project_profiler/arbitrator.py +6 -1
  178. package/core/project_profiler/detector.py +8 -1
  179. package/core/project_profiler/strategy.py +51 -15
  180. package/core/prompts/command_routing_en.md +2 -2
  181. package/core/prompts/command_routing_zh.md +2 -2
  182. package/core/prompts/stages/stage_repair.md +1 -1
  183. package/core/repair/README.md +1 -1
  184. package/core/repair/l7_repair_loop.py +1 -4
  185. package/core/repair/rsi_fixer.py +4 -4
  186. package/core/repair/rsi_loop.py +1 -3
  187. package/core/repair/rsi_repair.py +7 -7
  188. package/core/repair/rsi_scope.py +27 -8
  189. package/core/report_engine/SPEC.md +1 -1
  190. package/core/report_engine/attestation.py +8 -4
  191. package/core/report_engine/finding_report.py +2 -1
  192. package/core/report_engine/models.py +7 -9
  193. package/core/report_engine/sast_bridge.py +2 -2
  194. package/core/report_engine/server.py +18 -8
  195. package/core/report_engine/web-conformance.md +123 -18
  196. package/core/report_engine/web_conformance.py +21 -52
  197. package/core/retrieval/README.md +1 -1
  198. package/core/retrieval/SPEC.md +1 -1
  199. package/core/retrieval/code_analyzer.py +50 -14
  200. package/core/retrieval/context_assembler.py +7 -1
  201. package/core/retrieval/knowledge_sync.py +108 -14
  202. package/core/retrieval/symbol_index.py +25 -6
  203. package/core/retrieval/universal_code_matcher.py +234 -49
  204. package/core/runtime/README.md +1 -1
  205. package/core/runtime/bugx_logging.py +78 -7
  206. package/core/runtime/fixture_solidify.py +5 -10
  207. package/core/runtime/incident_eval.py +1 -1
  208. package/core/runtime/model_runner.py +4 -41
  209. package/core/runtime/platform_adapter.py +2 -2
  210. package/core/runtime/prep_validate.py +4 -2
  211. package/core/runtime/project_settings.py +2 -1
  212. package/core/runtime/scenario_eval.py +50 -8
  213. package/core/skills/bugx_docs_mcp_server.py +3 -1
  214. package/core/skills/bugx_mcp_server.py +29 -2
  215. package/core/skills/tools_kb.py +1 -1
  216. package/core/supervisor/README.md +1 -1
  217. package/core/supervisor/SPEC.md +1 -1
  218. package/core/supervisor/budget_governor.py +503 -9
  219. package/core/supervisor/checkpoint_pipeline.py +248 -6
  220. package/core/supervisor/checkpoint_sync.py +13 -0
  221. package/core/supervisor/claim_events.py +1 -1
  222. package/core/supervisor/finding_workflow.py +22 -5
  223. package/core/supervisor/lease_manager.py +1 -1
  224. package/core/supervisor/lifecycle_blocks.py +6 -1
  225. package/core/supervisor/rejection_remedies.py +52 -5
  226. package/core/supervisor/serial_authorization.py +48 -4
  227. package/core/supervisor/task_scheduler.py +2 -2
  228. package/core/supervisor/worker_checkpoint.py +8 -1
  229. package/core/supervisor/worker_runtime.py +8 -2
  230. package/core/supervisor_types/worker_claim.py +9 -0
  231. package/core/webui/README.md +1 -1
  232. package/core/webui/SPEC.md +2 -1
  233. package/core/webui/adapters/claude.py +5 -1
  234. package/core/webui/adapters/cline.py +10 -2
  235. package/core/webui/adapters/codex.py +5 -1
  236. package/core/webui/adapters/dsh.py +5 -1
  237. package/core/webui/docs_session_service.py +2 -2
  238. package/core/webui/mcp_inspector.py +11 -7
  239. package/core/webui/static/00-base.css +1060 -0
  240. package/core/webui/static/01-monitoring.css +802 -0
  241. package/core/webui/static/02-header-actions.css +321 -0
  242. package/core/webui/static/03-trigger-popover.css +697 -0
  243. package/core/webui/static/04-composer.css +628 -0
  244. package/core/webui/static/05-skills-center.css +878 -0
  245. package/core/webui/static/06-mcp-center.css +623 -0
  246. package/core/webui/static/07-skill-detail.css +265 -0
  247. package/core/webui/static/08-files-management.css +167 -0
  248. package/core/webui/static/09-files-center.css +386 -0
  249. package/core/webui/static/10-icons.css +105 -0
  250. package/core/webui/static/11-project-options.css +185 -0
  251. package/core/webui/static/12-profile-tab.css +383 -0
  252. package/core/webui/static/design-tokens.css +113 -0
  253. package/core/webui/static/index.html +14 -1
  254. package/core/webui/workspace_service.py +1 -1
  255. package/docs/07_distribution/01_README_NPM.md +190 -186
  256. package/ecosystem/integrations/README.md +1 -1
  257. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  258. package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
  259. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  260. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
  261. package/ecosystem/integrations/opencode/mcp-lock.json +14 -6
  262. package/ecosystem/integrations/opencode/opencode.json +23 -12
  263. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  264. package/ecosystem/integrations/qoder/connector-meta.json +1 -1
  265. package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
  266. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
  267. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
  268. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
  269. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
  270. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
  271. package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
  272. package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
  273. package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
  274. package/interfaces/bin/bugx.js +37 -0
  275. package/interfaces/cli/bugx_cli/__init__.py +4 -2
  276. package/interfaces/cli/bugx_cli/cli.py +11 -4
  277. package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
  278. package/interfaces/cli/bugx_cli/commands/agent.py +339 -73
  279. package/interfaces/cli/bugx_cli/commands/audit.py +2 -2
  280. package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
  281. package/interfaces/cli/bugx_cli/commands/cloud.py +4 -3
  282. package/interfaces/cli/bugx_cli/commands/doctor.py +449 -204
  283. package/interfaces/cli/bugx_cli/commands/interaction.py +5 -1
  284. package/interfaces/cli/bugx_cli/commands/knowledge.py +2 -0
  285. package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
  286. package/interfaces/cli/bugx_cli/commands/plugin.py +55 -20
  287. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +7 -7
  288. package/interfaces/cli/bugx_cli/commands/plugin_funide.py +2 -1
  289. package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +1 -1
  290. package/interfaces/cli/bugx_cli/commands/report.py +2 -6
  291. package/interfaces/cli/bugx_cli/commands/system.py +11 -11
  292. package/interfaces/cli/bugx_cli/common.py +15 -7
  293. package/interfaces/cli/bugx_cli/host_adapters.py +29 -54
  294. package/interfaces/cli/bugx_cli/hosts/registry.py +8 -6
  295. package/interfaces/cli/bugx_cli/infra/ai_advisor.py +157 -27
  296. package/interfaces/cli/bugx_cli/infra/engine_installer.py +18 -10
  297. package/interfaces/cli/bugx_cli/infra/host_sync.py +11 -8
  298. package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +76 -5
  299. package/interfaces/cli/bugx_cli/infra/security.py +13 -6
  300. package/package.json +2 -1
  301. package/pyproject.toml +20 -8
  302. package/scripts/ensure-python.mjs +7 -7
  303. package/scripts/sync-version.mjs +10 -21
  304. package/scripts/test-npm-wrapper.mjs +1 -1
  305. package/core/webui/static/project-settings.css +0 -6458
  306. package/docs/07_distribution/README.md +0 -16
  307. package/docs/README.md +0 -121
  308. package/interfaces/README.md +0 -143
  309. package/interfaces/bin/README.md +0 -35
  310. package/interfaces/cli/README.md +0 -90
  311. package/scripts/README.md +0 -118
@@ -11,7 +11,6 @@ import json
11
11
  import math
12
12
  import os
13
13
  import re
14
- import sys
15
14
  import time
16
15
  from pathlib import Path
17
16
  from typing import Any, Mapping
@@ -43,6 +42,7 @@ from core.launch_phases.common import (
43
42
  bugx_paths,
44
43
  )
45
44
  from core.launch_phases.session_runtime import (
45
+ baseline_json,
46
46
  set_review_mode,
47
47
  set_polling_policy,
48
48
  set_commit_policy,
@@ -64,192 +64,39 @@ from core.launch_phases.supervisor_bridge import (
64
64
  )
65
65
  from core.launch_phases.report_sharing import normalize_report_policy
66
66
  from core.launch_phases.startup_gates import (
67
- compile_strategy_plan as _orig_compile_strategy_plan,
68
- strategy_plan_gate as _orig_strategy_plan_gate,
69
- report_policy_startup_gate as _orig_report_policy_startup_gate,
70
67
  aborted_session_gate,
71
68
  check_global_budget_gate,
72
69
  check_stage_prompts_integrity,
73
70
  coverage_startup_gate,
71
+ detect_startup_environment,
74
72
  mark_strategy_customized,
75
73
  refresh_startup_todo,
76
74
  )
75
+ from core.launch_phases.startup_interaction import (
76
+ compile_strategy_plan,
77
+ report_policy_startup_gate,
78
+ strategy_plan_gate,
79
+ )
77
80
 
78
81
  #: 运行态 ``report_policy_source`` 的「用户已决策」取值集合。
79
82
  #: 命中即表示交互三选一门禁已有答案,不再重复询问;``default`` /
80
83
  #: ``autonomous`` 是系统兜底,不算用户决策。
81
84
  _REPORT_POLICY_DECIDED_SOURCES = frozenset({"cli", "profile", "config", "gate"})
82
85
 
83
- def compile_strategy_plan(*args, **kwargs):
84
- pp = _pp()
85
- if pp and hasattr(pp, "compile_strategy_plan"):
86
- fn = getattr(pp, "compile_strategy_plan")
87
- if fn is not compile_strategy_plan:
88
- return fn(*args, **kwargs)
89
- return _orig_compile_strategy_plan(*args, **kwargs)
90
-
91
- def strategy_plan_gate(*args, **kwargs):
92
- pp = _pp()
93
- if pp and hasattr(pp, "strategy_plan_gate"):
94
- fn = getattr(pp, "strategy_plan_gate")
95
- if fn is not strategy_plan_gate:
96
- return fn(*args, **kwargs)
97
- return _orig_strategy_plan_gate(*args, **kwargs)
98
-
99
- def report_policy_startup_gate(*args, **kwargs):
100
- pp = _pp()
101
- if pp and hasattr(pp, "report_policy_startup_gate"):
102
- fn = getattr(pp, "report_policy_startup_gate")
103
- if fn is not report_policy_startup_gate:
104
- return fn(*args, **kwargs)
105
- return _orig_report_policy_startup_gate(*args, **kwargs)
106
-
107
- def startup_policy_explicit_keys(*args, **kwargs):
108
- pp = _pp()
109
- if pp and hasattr(pp, "startup_policy_explicit_keys"):
110
- fn = getattr(pp, "startup_policy_explicit_keys")
111
- if fn is not startup_policy_explicit_keys:
112
- return fn(*args, **kwargs)
113
- return frozenset()
114
-
115
-
116
- def baseline_json(*args, **kwargs):
117
- pp = _pp()
118
- if pp and hasattr(pp, "baseline_json"):
119
- fn = getattr(pp, "baseline_json")
120
- if fn is not baseline_json:
121
- return fn(*args, **kwargs)
122
- from core.launch_phases.session_runtime import baseline_json as real
123
- return real(*args, **kwargs)
124
-
125
- def _startup_policy_config(*args, **kwargs):
126
- pp = _pp()
127
- if pp and hasattr(pp, "_startup_policy_config"):
128
- fn = getattr(pp, "_startup_policy_config")
129
- if fn is not _startup_policy_config:
130
- return fn(*args, **kwargs)
131
- raise RuntimeError("pre_phase._startup_policy_config not available")
132
-
133
- def resolve_project_root(*args, **kwargs):
134
- pp = _pp()
135
- if pp and hasattr(pp, "resolve_project_root"):
136
- fn = getattr(pp, "resolve_project_root")
137
- if fn is not resolve_project_root:
138
- return fn(*args, **kwargs)
139
- from core.launch_phases.common import resolve_project_root as real
140
- return real(*args, **kwargs)
141
-
142
- def load_runtime(*args, **kwargs):
143
- pp = _pp()
144
- if pp and hasattr(pp, "load_runtime"):
145
- fn = getattr(pp, "load_runtime")
146
- if fn is not load_runtime:
147
- return fn(*args, **kwargs)
148
- from core.launch_phases.session_runtime import load_runtime as real
149
- return real(*args, **kwargs)
150
-
151
- def save_runtime(*args, **kwargs):
152
- pp = _pp()
153
- if pp and hasattr(pp, "save_runtime"):
154
- fn = getattr(pp, "save_runtime")
155
- if fn is not save_runtime:
156
- return fn(*args, **kwargs)
157
- from core.launch_phases.session_runtime import save_runtime as real
158
- return real(*args, **kwargs)
159
-
160
-
161
- def detect_startup_environment(*args, **kwargs):
162
- pp = _pp()
163
- if pp and hasattr(pp, "detect_startup_environment"):
164
- fn = getattr(pp, "detect_startup_environment")
165
- if fn is not detect_startup_environment:
166
- return fn(*args, **kwargs)
167
- try:
168
- from core.launch_phases.startup_gates import detect_startup_environment as real
169
- return real(*args, **kwargs)
170
- except Exception:
171
- return "terminal"
172
-
173
- def run_tools_kb(*args, **kwargs):
174
- pp = _pp()
175
- if pp and hasattr(pp, "run_tools_kb"):
176
- fn = getattr(pp, "run_tools_kb")
177
- if fn is not run_tools_kb:
178
- return fn(*args, **kwargs)
179
- from core.launch_phases.supervisor_bridge import run_tools_kb as real
180
- return real(*args, **kwargs)
181
-
182
- def run_preflight_probes(*args, **kwargs):
183
- pp = _pp()
184
- if pp and hasattr(pp, "run_preflight_probes"):
185
- fn = getattr(pp, "run_preflight_probes")
186
- if fn is not run_preflight_probes:
187
- return fn(*args, **kwargs)
188
- from core.launch_phases.supervisor_bridge import run_preflight_probes as real
189
- return real(*args, **kwargs)
190
-
191
- def report_degraded_probes(*args, **kwargs):
192
- pp = _pp()
193
- if pp and hasattr(pp, "report_degraded_probes"):
194
- fn = getattr(pp, "report_degraded_probes")
195
- if fn is not report_degraded_probes:
196
- return fn(*args, **kwargs)
197
- from core.launch_phases.supervisor_bridge import report_degraded_probes as real
198
- return real(*args, **kwargs)
199
-
200
- def auto_provision_accelerators(*args, **kwargs):
201
- pp = _pp()
202
- if pp and hasattr(pp, "auto_provision_accelerators"):
203
- fn = getattr(pp, "auto_provision_accelerators")
204
- if fn is not auto_provision_accelerators:
205
- return fn(*args, **kwargs)
206
- from core.launch_phases.supervisor_bridge import auto_provision_accelerators as real
207
- return real(*args, **kwargs)
208
-
209
- def degraded_gate(*args, **kwargs):
210
- pp = _pp()
211
- if pp and hasattr(pp, "degraded_gate"):
212
- fn = getattr(pp, "degraded_gate")
213
- if fn is not degraded_gate:
214
- return fn(*args, **kwargs)
215
- from core.launch_phases.supervisor_bridge import degraded_gate as real
216
- return real(*args, **kwargs)
217
-
218
- def run_verify_life(*args, **kwargs):
219
- pp = _pp()
220
- if pp and hasattr(pp, "run_verify_life"):
221
- fn = getattr(pp, "run_verify_life")
222
- if fn is not run_verify_life:
223
- return fn(*args, **kwargs)
224
- from core.launch_phases.common import run_verify_life as real
225
- return real(*args, **kwargs)
226
-
227
- def refresh_startup_todo(*args, **kwargs):
228
- pp = _pp()
229
- if pp and hasattr(pp, "refresh_startup_todo"):
230
- fn = getattr(pp, "refresh_startup_todo")
231
- if fn is not refresh_startup_todo:
232
- return fn(*args, **kwargs)
233
- from core.launch_phases.startup_gates import refresh_startup_todo as real
234
- return real(*args, **kwargs)
235
-
236
- def uses_project_layout(*args, **kwargs):
237
- pp = _pp()
238
- if pp and hasattr(pp, "uses_project_layout"):
239
- fn = getattr(pp, "uses_project_layout")
240
- if fn is not uses_project_layout:
241
- return fn(*args, **kwargs)
242
- from core.launch_phases.common import uses_project_layout as real
243
- return real(*args, **kwargs)
244
-
245
- def _pp():
246
- return sys.modules.get("core.launch_phases.pre_phase") or sys.modules.get("launch_phases.pre_phase")
247
-
248
- def _get_pp_attr(name: str, fallback=None):
249
- pp = _pp()
250
- if pp and hasattr(pp, name):
251
- return getattr(pp, name)
252
- return fallback
86
+ def _startup_policy_config(
87
+ root: Path, cli_overrides: dict[str, Any] | None = None,
88
+ ) -> dict[str, str]:
89
+ """Load the pre-phase policy resolver without a module-level import cycle."""
90
+ from core.launch_phases.pre_phase import startup_policy_config as resolve_policy
91
+
92
+ return resolve_policy(root, cli_overrides)
93
+
94
+
95
+ def startup_policy_explicit_keys(root: Path) -> frozenset[str]:
96
+ """Load the pre-phase explicit-policy reader without dynamic dispatch."""
97
+ from core.launch_phases.pre_phase import startup_policy_explicit_keys as read_keys
98
+
99
+ return read_keys(root)
253
100
 
254
101
  def begin_new_session(
255
102
  bootstrap_coverage: bool = False, *, autonomous: bool = False,
@@ -713,7 +560,7 @@ def run_preflight_budget_gates(st: "_PreState") -> int:
713
560
  原 ``pre()`` 476-496 逐字迁移。"""
714
561
  ignore_global_budget = st.ignore_global_budget
715
562
  # DOC-034 阶段 3:阶段提示词加载完整性防偷懒门禁(缺失立即阻断,不静默继续)
716
- check_prompts_fn = _get_pp_attr("check_stage_prompts_integrity", check_stage_prompts_integrity)
563
+ check_prompts_fn = check_stage_prompts_integrity
717
564
  prompts_ok, prompts_err = check_prompts_fn()
718
565
  if not prompts_ok:
719
566
  err = f"[launch_bugx] ✗ 阶段提示词章节缺失/加载失败: {prompts_err}(防偷懒门禁阻断)"
@@ -723,7 +570,7 @@ def run_preflight_budget_gates(st: "_PreState") -> int:
723
570
  return 1
724
571
 
725
572
  # DOC-049 全局每日预算与配额熔断门禁(超限立即阻断,防止 API 账单穿透)
726
- check_budget_fn = _get_pp_attr("check_global_budget_gate", check_global_budget_gate)
573
+ check_budget_fn = check_global_budget_gate
727
574
  budget_ok, budget_err = check_budget_fn(ignore_budget=ignore_global_budget)
728
575
  if not budget_ok:
729
576
  err = f"[launch_bugx] ✗ 全局预算熔断阻断: {budget_err}"
@@ -60,6 +60,8 @@ from core.launch_phases.common import (
60
60
  diagnostic_logger,
61
61
  run_verify_life,
62
62
  format_duration,
63
+ option_value as _option_value,
64
+ require_project_layout as _require_project_layout,
63
65
  isolated_runtime_scope,
64
66
  bugx_paths,
65
67
  bugx_logging,
@@ -277,19 +279,6 @@ def run_in_process(
277
279
  )
278
280
 
279
281
 
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
282
  def _resume_ticket_handoff(
294
283
  project_root: Path, resume_ticket_module, ticket: dict[str, Any],
295
284
  ) -> int | None:
@@ -456,13 +445,16 @@ _ci_detection_report = ci_detection_report
456
445
  _legacy_supervisor_state = legacy_supervisor_state
457
446
  _print_help = print_help
458
447
 
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
448
+ #: engine 子命令单一真值源(F-RSI-20261112-083):main() 的 argv 归一化与
449
+ #: _main_impl() 的重复归一化共用同一清单——历史双份手抄已漂移一次(F-020
450
+ #: 只补了 main() 侧的 coverage)。dispatch 链新增子命令时只改这里。
451
+ _KNOWN_CMDS = frozenset({
452
+ "pre", "post", "status", "polling", "heartbeat", "pause", "resume",
453
+ "abort", "bootstrap-coverage", "fix-review", "audit", "control",
454
+ "workers", "judge", "findings-confirm", "revalidate-candidates", "prompt", "daemon", "help", "--help", "-h",
455
+ "coverage",
456
+ })
457
+
466
458
 
467
459
  def _reject_legacy_share_policy(argv: list[str]) -> int | None:
468
460
  """Reject the removed pre flag before any project/runtime side effect."""
@@ -481,12 +473,7 @@ def _reject_legacy_share_policy(argv: list[str]) -> int | None:
481
473
  def main(argv: list[str]) -> int:
482
474
  """Bind one context-local attempt around CLI post dispatch."""
483
475
  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
- }
476
+ known = _KNOWN_CMDS
490
477
  if values and (values[0] in known or values[0].startswith("-")):
491
478
  values = ["launch_bugx.py", *values]
492
479
  legacy_share_policy = _reject_legacy_share_policy(values)
@@ -525,11 +512,6 @@ def main(argv: list[str]) -> int:
525
512
  def _main_impl(
526
513
  argv: list[str], *, _post_attempt_token: object | None = None,
527
514
  ) -> 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
515
  if argv and (argv[0] in _KNOWN_CMDS or argv[0].startswith("-")):
534
516
  argv = ["launch_bugx.py"] + list(argv)
535
517
  cmd = argv[1] if len(argv) > 1 else "status"
@@ -1034,7 +1016,8 @@ def _main_impl(
1034
1016
  print(
1035
1017
  f"[launch_bugx] 未知命令: {cmd}"
1036
1018
  "(可选 pre/post/status/polling/heartbeat/pause/resume/abort/"
1037
- "bootstrap-coverage/fix-review/revalidate-candidates/audit/control/workers/prompt/daemon)"
1019
+ "bootstrap-coverage/fix-review/revalidate-candidates/audit/control/workers/"
1020
+ "judge/findings-confirm/coverage/prompt/daemon)"
1038
1021
  )
1039
1022
  result = 2
1040
1023
  except BudgetExhausted as exc:
@@ -7,6 +7,7 @@ import datetime as dt
7
7
  import json
8
8
  import math
9
9
  import os
10
+ import sys
10
11
  import time
11
12
  import contextvars
12
13
  from contextlib import contextmanager
@@ -313,7 +314,10 @@ def _default_runtime() -> dict:
313
314
  "host": None,
314
315
  "autonomous_mode": False,
315
316
  "execute": False,
316
- "workers": 0,
317
+ # F-RSI-20261112-077 后继(轮 77):校验层已统一正整数口径(0 拒绝),
318
+ # 默认态的「未声明」必须用 None 表达(与 worker_capacity 同构)——
319
+ # 默认值产 0 会让缺文件回退/reconcile 路径被自家校验炸掉。
320
+ "workers": None,
317
321
  "worker_capacity": None,
318
322
  "subagent_type": "bugx-worker",
319
323
  "stagger_seconds": 0.0,
@@ -528,8 +532,14 @@ def _reconcile_orphaned_state_locked(state: dict, now: float | None = None) -> b
528
532
  operation="lifecycle", gate="owner_cancelled",
529
533
  reason="宿主取消 agent:owner 进程死亡而心跳仍新鲜(D27 取消回传)",
530
534
  )
531
- except Exception: # noqa: BLE001 - 回传失败不阻断 ownership 释放
532
- pass
535
+ except Exception as exc: # noqa: BLE001 - 回传失败不阻断 ownership 释放
536
+ # F-RSI-20261113-106:不阻断但必须留痕——D27 取消回传是宿主
537
+ # 取消信号的引擎侧落账,静默丢失会让「宿主为何释放所有权」
538
+ # 在 supervisor 权威链上无迹可查(与 F-104 同款可观测性守卫)。
539
+ print(
540
+ f"[launch_bugx] ⚠ D27 owner_cancelled 回传失败(ownership 释放不受影响): {exc}",
541
+ file=sys.stderr,
542
+ )
533
543
  return True
534
544
 
535
545
  if not is_dead:
@@ -702,6 +712,11 @@ def _read_runtime_state() -> dict:
702
712
  "total_elapsed_seconds"):
703
713
  if not is_number(state.get(key)) or state[key] < 0:
704
714
  raise ValueError(f"运行计时文件 {key} 无效")
715
+ # F-RSI-20261112-087:segment_started_epoch 允许 None(默认/非运行态),
716
+ # 但出现必须是数字——垃圾值直通会在 orphan 恢复链的 _accrue 中裸崩。
717
+ seg = state.get("segment_started_epoch")
718
+ if seg is not None and (isinstance(seg, bool) or not is_number(seg)):
719
+ raise ValueError("运行计时文件 segment_started_epoch 无效(必须是数字或 null)")
705
720
  if not isinstance(state.get("sessions_completed"), int) \
706
721
  or isinstance(state["sessions_completed"], bool) \
707
722
  or state["sessions_completed"] < 0:
@@ -738,10 +753,22 @@ def _read_runtime_state() -> dict:
738
753
  raise ValueError("运行计时文件 execute 无效")
739
754
  for key in ("workers", "worker_capacity"):
740
755
  value = state.get(key)
741
- if value is not None and (
742
- not isinstance(value, int) or isinstance(value, bool) or value < 0
743
- ):
744
- raise ValueError(f"运行计时文件 {key} 无效")
756
+ if value is None:
757
+ continue
758
+ # F-RSI-20261112-077 后继(轮 77):0 是旧默认态泄漏(_default_runtime
759
+ # 曾产 0 并被 reconcile 落盘;消费侧历来把 0 当未声明吞掉)——归一为
760
+ # None 自动迁移存量项目,而非拒绝造成 engine 命令全面 Unhandled
761
+ # exception。拒绝保留给负数/布尔/非整数等真实非法值。
762
+ if not isinstance(value, int) or isinstance(value, bool):
763
+ raise ValueError(f"运行计时文件 {key} 无效(必须是正整数或未声明)")
764
+ if value == 0:
765
+ state[key] = None
766
+ print(
767
+ f"[bugx] ⚠️ 运行计时文件 {key}=0 为旧默认态残留,已归一为未声明(下次保存落盘)"
768
+ )
769
+ continue
770
+ if value < 0:
771
+ raise ValueError(f"运行计时文件 {key} 无效(必须是正整数或未声明)")
745
772
  subagent_type = state.get("subagent_type")
746
773
  if not isinstance(subagent_type, str) or not subagent_type.strip():
747
774
  raise ValueError("运行计时文件 subagent_type 无效")
@@ -1044,9 +1071,21 @@ def append_runtime_event(state: dict, event: str, now: float,
1044
1071
  def _accrue_running_segment(state: dict, now: float) -> None:
1045
1072
  if state.get("state") != "running":
1046
1073
  return
1047
- started = float(state["segment_started_epoch"])
1074
+ started = state.get("segment_started_epoch")
1075
+ # F-RSI-20261112-087:默认态该键为 None,schema 校验此前也不覆盖它——
1076
+ # orphan 恢复链(进程死亡后重入)里 running+null 组合会让裸
1077
+ # float(state[...]) 抛 TypeError,中断会话无法恢复。无可累计起点时
1078
+ # 跳过累计并留痕,起点从下一次 reset_segment_timer 重建。
1079
+ if isinstance(started, bool) or not isinstance(started, (int, float)):
1080
+ print(
1081
+ "[launch_bugx] ⚠ segment_started_epoch 缺失或非法,跳过本段时长累计"
1082
+ f"(值={started!r});起点将由下次会话活动重建",
1083
+ file=sys.stderr,
1084
+ )
1085
+ state["segment_started_epoch"] = now
1086
+ return
1048
1087
  state["session_elapsed_seconds"] = round(
1049
- float(state["session_elapsed_seconds"]) + max(0.0, now - started), 3
1088
+ float(state["session_elapsed_seconds"]) + max(0.0, now - float(started)), 3
1050
1089
  )
1051
1090
  state["segment_started_epoch"] = now
1052
1091
 
@@ -1301,6 +1340,14 @@ def runtime_summary(now: float | None = None) -> dict:
1301
1340
 
1302
1341
  def close_runtime(outcome: str, now: float | None = None,
1303
1342
  reason: str | None = None) -> tuple[dict, bool]:
1343
+ # F-RSI-20261112-088:close_runtime 是公共 API 且 save_runtime 不做
1344
+ # schema 校验——非法 outcome 会直接落盘为非法 state 值,下次
1345
+ # load_runtime 必然抛「state 无效」,运行态整体变砖(只能手工修文件)。
1346
+ # close 的合法终态只有 completed/aborted,入口 fail-fast。
1347
+ if outcome not in ("completed", "aborted"):
1348
+ raise ValueError(
1349
+ f"close_runtime outcome 必须是 completed/aborted,收到 {outcome!r}"
1350
+ )
1304
1351
  with runtime_lock():
1305
1352
  state = load_runtime()
1306
1353
  if not state["active"]:
@@ -584,6 +584,23 @@ _report_policy_startup_gate = report_policy_startup_gate
584
584
  _interactive_startup_decisions = interactive_startup_decisions
585
585
 
586
586
 
587
+ def _map_coverage_bootstrap_answer(value: str | None) -> bool | None:
588
+ """coverage_bootstrap 选择值→动作映射单一真源(TTY / 信箱两通道共用)。
589
+
590
+ TTY 文本菜单经 ``ask_interaction`` 返回选项序号("1"/"2");信箱通道
591
+ (``bugx interaction answer coverage_bootstrap``)经 ``take_answer`` 返回
592
+ 结构化门禁的语义 value("bootstrap"/"later")。两通道必须落到同一动作,
593
+ 否则语义答案会在 ask 内被消费(consumed_at 已置位)却被映射丢弃,
594
+ 门禁无限重发。
595
+ """
596
+ low = (value or "").strip().lower()
597
+ if low in {"1", "bootstrap"}:
598
+ return True
599
+ if low in {"2", "later"}:
600
+ return False
601
+ return None
602
+
603
+
587
604
  def _ask_coverage_bootstrap() -> bool | None:
588
605
  """通过统一组件询问是否创建覆盖清单。"""
589
606
  result = ask_interaction(
@@ -593,12 +610,7 @@ def _ask_coverage_bootstrap() -> bool | None:
593
610
  ],
594
611
  default=0,
595
612
  )
596
- value = answered_value(result)
597
- if value == "1":
598
- return True
599
- if value == "2":
600
- return False
601
- return None
613
+ return _map_coverage_bootstrap_answer(answered_value(result))
602
614
 
603
615
  #: 显式审计范围入口(`autonomous --coverage-manifest` / 手工 ``BUGX_COVERAGE_MANIFEST``)。
604
616
  #:
@@ -826,6 +838,23 @@ def coverage_startup_gate(
826
838
  )
827
839
  return 0
828
840
 
841
+ def _map_aborted_session_answer(value: str | None) -> str | None:
842
+ """aborted_session 选择值→动作映射单一真源(TTY / 信箱两通道共用)。
843
+
844
+ TTY 文本菜单经 ``ask_interaction`` 返回选项序号("1"/"2");信箱通道
845
+ (``bugx interaction answer aborted_session``)经 ``take_answer`` 返回
846
+ 结构化门禁的语义 value("resume"/"new")。两通道必须落到同一动作,
847
+ 否则语义答案会在 ask 内被消费(consumed_at 已置位)却被映射丢弃,
848
+ 门禁无限重发。
849
+ """
850
+ low = (value or "").strip().lower()
851
+ if low in {"1", "resume"}:
852
+ return "resume"
853
+ if low in {"2", "new"}:
854
+ return "new"
855
+ return None
856
+
857
+
829
858
  def _ask_aborted_session_choice() -> str | None:
830
859
  """通过统一组件询问已中断会话的显式去向:恢复或新建。"""
831
860
  result = ask_interaction(
@@ -835,8 +864,7 @@ def _ask_aborted_session_choice() -> str | None:
835
864
  ],
836
865
  default=0,
837
866
  )
838
- value = answered_value(result)
839
- return {"1": "resume", "2": "new"}.get(value or "")
867
+ return _map_aborted_session_answer(answered_value(result))
840
868
 
841
869
  def aborted_session_gate(
842
870
  previous_runtime: dict, explicit_choice: str | None = None, *,
@@ -483,6 +483,53 @@ def save_strategy_draft(plan: dict[str, Any]) -> None:
483
483
  secure_atomic.atomic_write_json(draft_file, plan, mode=0o600, parent_mode=0o700)
484
484
  print(f"[launch_bugx] 作战方案已暂存至 {draft_file},本轮启动停止。")
485
485
 
486
+ def _apply_strategy_choice(
487
+ choice: str | None, plan: dict[str, Any], *, cli_fix_mode: str | None = None,
488
+ ) -> tuple[int, str | None] | None:
489
+ """把 strategy_plan 选择值映射为统一动作(flag / TTY / 信箱三通道共用)。
490
+
491
+ 返回 ``(code, decision)``;不匹配任何合法值时返回 ``None``(调用方继续
492
+ 走发问路径)。值集与三个历史通道逐字保持一致,禁止在调用方再写第二份。
493
+ """
494
+ choice = (choice or "").strip().lower()
495
+ if choice in {"approve", "approve_and_start", "1"}:
496
+ target = _get_sg_attr("_apply_approved_strategy") or _apply_approved_strategy
497
+ target(plan, cli_fix_mode=cli_fix_mode)
498
+ return 0, "approved"
499
+ if choice in {"customize", "custom", "2"}:
500
+ target = _get_sg_attr("mark_strategy_customized") or mark_strategy_customized
501
+ target(plan)
502
+ return 0, "customized"
503
+ if choice in {"later", "save_and_later", "save", "3"}:
504
+ target = _get_sg_attr("_save_strategy_draft") or _save_strategy_draft
505
+ target(plan)
506
+ return POLLING_DECISION_REQUIRED, "later"
507
+ return None
508
+
509
+
510
+ def _startup_mailbox_answer(gate: str) -> str | None:
511
+ """消费一条启动门禁的信箱答案(与 ``interaction.ask()`` 通道对称)。
512
+
513
+ 仅 ``ANSWERED`` 返回 value;``NONE``/``INVALID``/``CANCELLED`` 一律返回
514
+ ``None``(INVALID 不消费、宿主可重新提交正确取值;CANCELLED 视为未回答,
515
+ 门禁照常重发——契约是「停留在当前 gate」)。统一交互组件不可用时静默
516
+ 返回 ``None``,不得抛错阻断启动。
517
+ """
518
+ try:
519
+ from core.runtime import interaction_store
520
+ except (ImportError, OSError, RuntimeError, ValueError):
521
+ return None
522
+ if not interaction_store.is_available():
523
+ return None
524
+ try:
525
+ lookup = interaction_store.take_answer(gate, "startup")
526
+ except (OSError, ValueError, RuntimeError):
527
+ return None
528
+ if lookup.status == interaction_store.ANSWERED and isinstance(lookup.value, str):
529
+ return lookup.value
530
+ return None
531
+
532
+
486
533
  def strategy_plan_gate(
487
534
  strategy_choice: str | None = None,
488
535
  environment=None,
@@ -498,18 +545,9 @@ def strategy_plan_gate(
498
545
  plan = plan_data or compile_strategy_plan(root)
499
546
 
500
547
  choice = (strategy_choice or "").strip().lower()
501
- if choice in {"approve", "approve_and_start", "1"}:
502
- target = _get_sg_attr("_apply_approved_strategy") or _apply_approved_strategy
503
- target(plan, cli_fix_mode=cli_fix_mode)
504
- return 0, "approved"
505
- if choice in {"customize", "custom", "2"}:
506
- target = _get_sg_attr("mark_strategy_customized") or mark_strategy_customized
507
- target(plan)
508
- return 0, "customized"
509
- if choice in {"later", "save_and_later", "save", "3"}:
510
- target = _get_sg_attr("_save_strategy_draft") or _save_strategy_draft
511
- target(plan)
512
- return POLLING_DECISION_REQUIRED, "later"
548
+ applied = _apply_strategy_choice(choice, plan, cli_fix_mode=cli_fix_mode)
549
+ if applied is not None:
550
+ return applied
513
551
 
514
552
  runtime = load_runtime()
515
553
  saved_status = (runtime.get("strategy_plan") or {}).get("status")
@@ -561,6 +599,18 @@ def strategy_plan_gate(
561
599
  return POLLING_DECISION_REQUIRED, "later"
562
600
  return POLLING_DECISION_REQUIRED, None
563
601
 
602
+ # 信箱回灌(F-RSI-20261118-001):无 TTY 宿主经 ``bugx interaction answer
603
+ # strategy_plan --value <v>`` 回灌的答案此前在 emit_startup_gate 直发路径上
604
+ # 永远无人消费(真机实证 consumed_at=null,宿主被迫用 --strategy-plan flag
605
+ # 绕过)。在此消费并复用与 flag/TTY 完全相同的值映射;非法值不消费
606
+ # (take_answer 契约),门禁照常重发(fail-closed)。
607
+ mailbox_value = _startup_mailbox_answer("strategy_plan")
608
+ if mailbox_value is not None:
609
+ mailbox_applied = _apply_strategy_choice(
610
+ mailbox_value, plan, cli_fix_mode=cli_fix_mode,
611
+ )
612
+ if mailbox_applied is not None:
613
+ return mailbox_applied
564
614
  emit_startup_gate(
565
615
  "strategy_plan",
566
616
  plan["summary"],
@@ -838,6 +888,12 @@ def report_policy_startup_gate(
838
888
  if policy is None:
839
889
  return POLLING_DECISION_REQUIRED, None
840
890
  return 0, policy
891
+ # 信箱回灌(F-RSI-20261118-001,与 strategy_plan 同型):仅在非 blocked 的
892
+ # 非 TTY 路径消费——blocked 环境维持 F-RSI-20261110-004 的 local 最小权限
893
+ # 默认(report_policy 是隐私出口,陈旧信箱 submit 不得在无交互环境放大外发)。
894
+ mailbox_value = _startup_mailbox_answer("report_policy")
895
+ if mailbox_value in {"none", "local", "submit"}:
896
+ return 0, mailbox_value
841
897
  emit_startup_gate(
842
898
  "report_policy",
843
899
  "审计报告如何处置?",
@@ -167,7 +167,7 @@ def normalize_cli_version(value: str) -> str | None:
167
167
  """Normalize a BugX/Python version to the compatibility contract version.
168
168
 
169
169
  委托 :func:`bugx_paths.contract_version`(唯一实现)。历史缺陷:此处曾把
170
- ``+build`` 保留在 base 组里,于是 ``1.0.0+2`` 与 ``1.0.0`` 被判为不一致并
170
+ ``+build`` 保留在 base 组里,于是 ``0.1.1+2`` 与 ``0.1.1`` 被判为不一致并
171
171
  **拒绝启动**,而 ``bugx doctor`` 用另一套规则判为"一致"——同一份清单、两个
172
172
  相反结论。归一化规则只能有一处,否则两边必然再次漂移。
173
173
  """
@@ -234,9 +234,15 @@ def version_marker(path: Path) -> str | None:
234
234
  return None
235
235
  match = re.search(
236
236
  r"(?:bugx_version[\"']?\s*:\s*[\"']?|^version:\s*)"
237
- r"([0-9]+\.[0-9]+\.[0-9]+(?:\+[0-9A-Za-z.-]+)?)", text, re.MULTILINE,
237
+ r"([0-9]+\.[0-9]+\.[0-9]+(?:\+[0-9A-Za-z.-]+)?|\$\{BUGX_VERSION\})",
238
+ text, re.MULTILINE,
238
239
  )
239
- return match.group(1) if match else None
240
+ if not match:
241
+ return None
242
+ value = match.group(1)
243
+ if value == "0.1.1":
244
+ value = os.environ.get("BUGX_VERSION", "0.1.1")
245
+ return value
240
246
 
241
247
  def startup_release_version(value: object) -> tuple[int, int, int] | None:
242
248
  """Parse the strict x.y.z release format used by the update endpoint."""