bugx-cli 0.1.1 → 0.1.3

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 (131) hide show
  1. package/README.md +36 -35
  2. package/core/README.md +1 -1
  3. package/core/agent/agent_orchestrator.py +3 -0
  4. package/core/agent/agent_workspace.py +14 -2
  5. package/core/assets/README.md +3 -2
  6. package/core/assets/bugx-social-preview.svg +71 -0
  7. package/core/assets/bugx-wechat-group.png +0 -0
  8. package/core/assets/twitter_promo_art.jpg +0 -0
  9. package/core/assets/twitter_promo_card.svg +166 -0
  10. package/core/assets/twitter_promo_clean.jpg +0 -0
  11. package/core/assets/twitter_terminal_real.png +0 -0
  12. package/core/audit_packs/README.md +2 -0
  13. package/core/audit_packs/pitfalls/auth_crypto.json +64 -0
  14. package/core/audit_packs/pitfalls/file_ssrf_cmd.json +64 -0
  15. package/core/audit_packs/pitfalls/go_backend.json +66 -0
  16. package/core/audit_packs/pitfalls/java_spring.json +64 -0
  17. package/core/audit_packs/pitfalls/js_ts_web.json +67 -0
  18. package/core/audit_packs/pitfalls/python_web.json +82 -0
  19. package/core/bugx.md +2 -2
  20. package/core/bugx_paths.py +2 -2
  21. package/core/cli-help.txt +1 -1
  22. package/core/cloud_sync/cloud_client.py +56 -5
  23. package/core/cloud_sync/consent.py +33 -3
  24. package/core/cloud_sync/flywheel_client.py +186 -24
  25. package/core/contracts/README.md +1 -1
  26. package/core/contracts/bugx-opencode.md +1 -1
  27. package/core/contracts/bugx-runtime-contract.md +1 -1
  28. package/core/contracts/bugx-worker.md +1 -1
  29. package/core/engine-integrity.json +191 -95
  30. package/core/host_acp/kimi.py +175 -0
  31. package/core/host_acp/minimax.py +28 -0
  32. package/core/host_runtime/host_registry.py +23 -3
  33. package/core/hosts/dsh.py +1 -1
  34. package/core/hosts/kimi.py +293 -0
  35. package/core/hosts/minimax.py +248 -0
  36. package/core/hosts/zcode.py +5 -0
  37. package/core/infra/README.md +1 -1
  38. package/core/infra/build_info.py +30 -5
  39. package/core/launch_phases/README.md +6 -3
  40. package/core/launch_phases/finding_confirm_phase.py +168 -7
  41. package/core/launch_phases/post_phase.py +5 -5
  42. package/core/launch_phases/pre_recon_scout.py +13 -0
  43. package/core/launch_phases/report_sharing.py +3 -7
  44. package/core/launch_phases/round_orchestrator.py +114 -26
  45. package/core/launch_phases/semantic_recon.py +545 -0
  46. package/core/launch_phases/startup_version_gate.py +6 -2
  47. package/core/launch_phases/supervisor_bridge.py +14 -23
  48. package/core/launch_phases/verify_loop.py +767 -0
  49. package/core/launch_phases/worker_prior.py +115 -0
  50. package/core/ledger/README.md +2 -1
  51. package/core/ledger/finding_verification.py +511 -2
  52. package/core/ledger/fp_ledger.py +255 -0
  53. package/core/metadata.txt +2 -2
  54. package/core/planning/README.md +2 -1
  55. package/core/planning/prompt_harness.py +50 -10
  56. package/core/planning/prompt_policy_engine.py +386 -0
  57. package/core/prompts/README.md +4 -2
  58. package/core/prompts/policies/prompt_policies.json +101 -0
  59. package/core/prompts/stages/stage_verify.defensive.md +42 -0
  60. package/core/prompts/stages/stage_verify.md +44 -0
  61. package/core/report_engine/report_share.py +0 -8
  62. package/core/retrieval/README.md +2 -1
  63. package/core/retrieval/pitfall_packs.py +277 -0
  64. package/core/runtime/README.md +1 -1
  65. package/core/runtime/global_telemetry.py +20 -0
  66. package/core/runtime/scenario_eval.py +1 -1
  67. package/core/runtime/setup_ui_env.py +4 -7
  68. package/core/supervisor/README.md +1 -1
  69. package/core/supervisor/cli.py +2 -2
  70. package/core/webui/mcp_inspector.py +6 -0
  71. package/core/webui/static/index.html +51 -3
  72. package/core/webui/static/manifest.webmanifest +1 -1
  73. package/core/webui/static/project-settings.js +18 -3
  74. package/core/webui/static/robots.txt +36 -0
  75. package/core/webui/static/sitemap.xml +15 -0
  76. package/docs/07_distribution/01_README_NPM.md +36 -35
  77. package/ecosystem/integrations/cline/skills/bugx/SKILL.md +1 -1
  78. package/ecosystem/integrations/dsh/agents/bugx.md +1 -1
  79. package/ecosystem/integrations/dsh/dsh-patch.yml +2 -2
  80. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  81. package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +1 -1
  82. package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
  83. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  84. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +1 -1
  85. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  86. package/ecosystem/integrations/pi/skills/bugx/SKILL.md +1 -1
  87. package/ecosystem/integrations/qoder/connector-meta.json +9 -9
  88. package/ecosystem/integrations/workbuddy/connector-meta.json +9 -9
  89. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +2 -2
  90. package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +2 -2
  91. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +2 -2
  92. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +4 -4
  93. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +2 -2
  94. package/ecosystem/plugins/bugx/agents/bugx-worker.md +1 -1
  95. package/ecosystem/plugins/bugx/agents/bugx.md +1 -1
  96. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +3 -3
  97. package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +1 -1
  98. package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
  99. package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
  100. package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
  101. package/interfaces/bin/bugx.js +9 -7
  102. package/interfaces/cli/bugx_cli/__init__.py +2 -2
  103. package/interfaces/cli/bugx_cli/cli.py +178 -67
  104. package/interfaces/cli/bugx_cli/commands/agent.py +313 -127
  105. package/interfaces/cli/bugx_cli/commands/audit.py +8 -7
  106. package/interfaces/cli/bugx_cli/commands/cloud.py +27 -19
  107. package/interfaces/cli/bugx_cli/commands/doctor.py +18 -0
  108. package/interfaces/cli/bugx_cli/commands/knowledge.py +3 -4
  109. package/interfaces/cli/bugx_cli/commands/lifecycle.py +54 -47
  110. package/interfaces/cli/bugx_cli/commands/plugin.py +9 -9
  111. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +27 -13
  112. package/interfaces/cli/bugx_cli/commands/plugin_kimi.py +348 -0
  113. package/interfaces/cli/bugx_cli/commands/plugin_minimax.py +322 -0
  114. package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +3 -4
  115. package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +4 -5
  116. package/interfaces/cli/bugx_cli/commands/project.py +6 -13
  117. package/interfaces/cli/bugx_cli/commands/system.py +577 -162
  118. package/interfaces/cli/bugx_cli/common.py +102 -15
  119. package/interfaces/cli/bugx_cli/host_adapters.py +150 -4
  120. package/interfaces/cli/bugx_cli/hosts/registry.py +4 -2
  121. package/interfaces/cli/bugx_cli/hosts/template_engine.py +10 -9
  122. package/interfaces/cli/bugx_cli/infra/engine_installer.py +21 -10
  123. package/interfaces/cli/bugx_cli/infra/host_sync.py +1 -1
  124. package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +2 -2
  125. package/package.json +54 -16
  126. package/pyproject.toml +64 -1
  127. package/scripts/sync-version.mjs +1 -1
  128. package/skills/README.md +25 -0
  129. package/skills/platform/bugx-user/SKILL.md +92 -0
  130. package/core/assets/bugx-hero-cn.png +0 -0
  131. package/core/assets/bugx-hero-en.png +0 -0
@@ -12,6 +12,14 @@ import sys
12
12
  import typing
13
13
  from pathlib import Path
14
14
 
15
+ # 确保在管道重定向或非 UTF-8 环境(如 Windows GBK/cp936 控制台)下输出非 ASCII 符号(如 ✓、✗)不触发 UnicodeEncodeError
16
+ for _stream in (sys.stdout, sys.stderr):
17
+ if hasattr(_stream, "reconfigure"):
18
+ try:
19
+ _stream.reconfigure(encoding="utf-8", errors="replace")
20
+ except Exception:
21
+ pass
22
+
15
23
  # 兼容低版本启动环境:若当前解释器 < 3.11,优先尝试全系统多源自举重拉
16
24
  if sys.version_info < (3, 11):
17
25
  try:
@@ -47,6 +55,13 @@ class _CloudSyncExplicitAction(argparse.Action):
47
55
  setattr(namespace, self.dest, values)
48
56
  setattr(namespace, "cloud_sync_explicit", True)
49
57
 
58
+
59
+ class _UniqueRootAction(argparse.Action):
60
+ def __call__(self, parser, namespace, values, option_string=None):
61
+ if getattr(namespace, self.dest, None) is not None:
62
+ parser.error("重复指定 --root,请保留一个项目路径。")
63
+ setattr(namespace, self.dest, values)
64
+
50
65
  # 将各领域子模块的符号(含公共工具与测试挂载点)全量导出到顶层 cli 命名空间
51
66
  for _mod in (
52
67
  common, plugin, lifecycle, agent, doctor, knowledge, cloud, system, stats,
@@ -117,6 +132,62 @@ _INTENT_SYNONYMS: dict[str, str] = {
117
132
  class _BugXArgumentParser(argparse.ArgumentParser):
118
133
  """带 AI 意图理解与智能模糊纠错的增强参数解析器。"""
119
134
 
135
+ def __init__(self, *args, **kwargs):
136
+ kwargs.setdefault("allow_abbrev", False)
137
+ super().__init__(*args, **kwargs)
138
+
139
+ @staticmethod
140
+ def _is_switch(action: argparse.Action | None) -> bool:
141
+ return isinstance(action, (
142
+ argparse._StoreTrueAction, argparse._StoreFalseAction,
143
+ argparse.BooleanOptionalAction,
144
+ ))
145
+
146
+ def _switch_error(self, option: str, value: str, action: argparse.Action) -> typing.NoReturn:
147
+ negative = isinstance(action, argparse._StoreFalseAction) or (
148
+ isinstance(action, argparse.BooleanOptionalAction) and option.startswith("--no-")
149
+ )
150
+ if (value.casefold() == "true") != negative:
151
+ guidance = f"直接使用 {option}。"
152
+ elif isinstance(action, argparse.BooleanOptionalAction):
153
+ opposite = option.removeprefix("--no-") if negative else option.removeprefix("--")
154
+ prefix = "--" if negative else "--no-"
155
+ guidance = f"改用 {prefix}{opposite}。"
156
+ else:
157
+ guidance = f"省略 {option},使用命令默认值。"
158
+ super().error(f"布尔开关 {option} 不接受值。{guidance}")
159
+
160
+ def parse_args(self, args=None, namespace=None):
161
+ parsed, extras = self.parse_known_args(args, namespace)
162
+ current = self
163
+ active_options = dict(current._option_string_actions)
164
+ while True:
165
+ group = next((a for a in current._actions if isinstance(a, argparse._SubParsersAction)), None)
166
+ if group is None:
167
+ break
168
+ child = group.choices.get(getattr(parsed, group.dest, None))
169
+ if child is None:
170
+ break
171
+ current = child
172
+ active_options.update(current._option_string_actions)
173
+ for token in extras:
174
+ match = re.fullmatch(r"([A-Za-z][\w-]*)=(true|false)", token, re.IGNORECASE)
175
+ if match:
176
+ option = "--" + match[1]
177
+ action = active_options.get(option)
178
+ if self._is_switch(action):
179
+ self._switch_error(option, match[2], action)
180
+ if extras:
181
+ self.error("unrecognized arguments: " + " ".join(extras))
182
+ parent_root = vars(parsed).pop("_parent_root", None)
183
+ if parent_root is not None:
184
+ if getattr(parsed, "root", None) is not None:
185
+ self.error("重复指定 --root,请保留一个项目路径。")
186
+ parsed.root = parent_root
187
+ elif getattr(parsed, "command", None) in {"project", "report"} and not hasattr(parsed, "root"):
188
+ parsed.root = Path.cwd() if parsed.command == "project" else None
189
+ return parsed
190
+
120
191
  def error(self, message: str) -> typing.NoReturn:
121
192
  match = re.search(r"argument command: invalid choice: '([^']+)'", message)
122
193
  if match:
@@ -143,6 +214,17 @@ class _BugXArgumentParser(argparse.ArgumentParser):
143
214
  print("\n".join(err_output), file=sys.stderr)
144
215
  sys.exit(2)
145
216
 
217
+ explicit_bool = re.fullmatch(
218
+ r"argument (\S+): ignored explicit argument ['\"](true|false)['\"]",
219
+ message,
220
+ flags=re.IGNORECASE,
221
+ )
222
+ if explicit_bool:
223
+ option = explicit_bool[1].split("/", 1)[0]
224
+ action = self._option_string_actions.get(option)
225
+ if self._is_switch(action):
226
+ self._switch_error(option, explicit_bool[2], action)
227
+
146
228
  match_arg = re.search(r"unrecognized arguments:\s*(.+)", message)
147
229
  if match_arg:
148
230
  bad_args = match_arg.group(1).strip()
@@ -305,6 +387,7 @@ def build_parser() -> argparse.ArgumentParser:
305
387
  reset.add_argument("--force", action="store_true", help="强制重置(忽略活跃状态检查;执行前依然创建外部备份)")
306
388
  reset.add_argument(
307
389
  "--no-backup", "--skip-backup", action="store_true", dest="no_backup",
390
+ default=argparse.SUPPRESS,
308
391
  help="跳过执行前自动创建的外部备份归档",
309
392
  )
310
393
  reset.add_argument("--json", action="store_true")
@@ -337,6 +420,7 @@ def build_parser() -> argparse.ArgumentParser:
337
420
  uninstall.add_argument("--yes", action="store_true", help="确认不可逆数据清理")
338
421
  uninstall.add_argument(
339
422
  "--no-backup", "--skip-backup", action="store_true", dest="no_backup",
423
+ default=argparse.SUPPRESS,
340
424
  help="跳过执行前自动创建的外部备份归档",
341
425
  )
342
426
  uninstall.add_argument("--json", action="store_true")
@@ -642,6 +726,13 @@ def build_parser() -> argparse.ArgumentParser:
642
726
  )
643
727
  probe.add_argument("--root", type=Path, default=Path.cwd(),
644
728
  help="项目根(默认当前目录)")
729
+ probe.add_argument(
730
+ "--timeout-seconds", type=_parse_probe_timeout, default=None,
731
+ help=(
732
+ "BugX 外层探针看护超时(默认 120 秒,最大 1800 秒;"
733
+ "可放在探针类型前或后)"
734
+ ),
735
+ )
645
736
  probe.add_argument("probe_args", nargs=argparse.REMAINDER,
646
737
  help="透传给探针的参数(如 check --json --strict)")
647
738
 
@@ -692,7 +783,7 @@ def build_parser() -> argparse.ArgumentParser:
692
783
  "engine", help="从全局引擎运行生命周期命令(项目不再提供 .bugx/core 入口)",
693
784
  )
694
785
  engine.add_argument(
695
- "--root", type=Path, default=None,
786
+ "--root", type=Path, default=None, action=_UniqueRootAction,
696
787
  help="项目根目录;缺省时依次读 BUGX_PROJECT_ROOT / 宿主工作区环境变量,最后才用 cwd",
697
788
  )
698
789
  engine.add_argument(
@@ -787,7 +878,7 @@ def build_parser() -> argparse.ArgumentParser:
787
878
  "sync", help="立即执行云端同步;未登录时自动打开授权页",
788
879
  ))
789
880
  p_sync.add_argument("--scope", dest="sync_scope", choices=("project", "global", "all"), default=None,
790
- help="显式授权同步范围;缺省读 cloud-config.json sync_scope_default(默认 all)")
881
+ help="同步范围;省略时读云端配置,未配置时仅同步当前项目")
791
882
  p_sync.add_argument("--detail-mode", choices=("full", "summary"), default=None,
792
883
  help="私有同步详情粒度;缺省读 cloud-config.json sync_detail_mode(默认 full),summary 仅上传摘要/计数/状态")
793
884
  p_sync.add_argument("--calibrate", action="store_true",
@@ -1032,14 +1123,9 @@ def build_parser() -> argparse.ArgumentParser:
1032
1123
  )
1033
1124
  sup.add_argument(
1034
1125
  "supervisor_command",
1035
- choices=(
1036
- "install", "status", "rpc",
1037
- # 带外动作白名单由 commands.system 单一真源派生(恢复 + 数据修复):
1038
- # 此处不再复制枚举,避免「帮助列出但 dispatch 拒绝」的静默漂移。
1039
- *system.SUPERVISOR_PASSTHROUGH_ACTIONS,
1040
- ),
1126
+ choices=system.SUPERVISOR_COMMANDS,
1041
1127
  )
1042
- sup.add_argument("--root", type=Path, default=Path.cwd())
1128
+ sup.add_argument("--root", type=Path, default=None, action=_UniqueRootAction)
1043
1129
  sup.add_argument("supervisor_args", nargs=argparse.REMAINDER, default=[])
1044
1130
  sup.set_defaults(handler=command_supervisor)
1045
1131
 
@@ -1206,55 +1292,63 @@ def build_parser() -> argparse.ArgumentParser:
1206
1292
  project_sub = project_parser.add_subparsers(dest="project_action")
1207
1293
 
1208
1294
  p_analyze = project_sub.add_parser("analyze", help="全景扫描并分析当前或指定工程的代码体量与画像")
1209
- p_analyze.add_argument("--root", type=Path, default=Path.cwd(), help="项目根目录(默认当前目录)")
1210
- p_analyze.add_argument("--json", action="store_true", help="以结构化 JSON 输出")
1295
+ p_analyze.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
1296
+ help="项目根目录(默认当前目录)")
1297
+ p_analyze.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
1211
1298
  p_analyze.set_defaults(handler=command_project)
1212
1299
 
1213
1300
  p_show = project_sub.add_parser("show", help="查看已缓存的项目画像与度量")
1214
- p_show.add_argument("--root", type=Path, default=Path.cwd(), help="项目根目录(默认当前目录)")
1215
- p_show.add_argument("--json", action="store_true", help="以结构化 JSON 输出")
1301
+ p_show.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
1302
+ help="项目根目录(默认当前目录)")
1303
+ p_show.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
1216
1304
  p_show.set_defaults(handler=command_project)
1217
1305
 
1218
1306
  p_sync = project_sub.add_parser("sync", help="将项目画像与代码指标同步至云端看板")
1219
- p_sync.add_argument("--root", type=Path, default=Path.cwd(), help="项目根目录(默认当前目录)")
1220
- p_sync.add_argument("--json", action="store_true", help="以结构化 JSON 输出")
1307
+ p_sync.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
1308
+ help="项目根目录(默认当前目录)")
1309
+ p_sync.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
1221
1310
  p_sync.set_defaults(handler=command_project)
1222
1311
 
1223
1312
  p_list = project_sub.add_parser("list", help="查看全局所有受管工程列表 (~/.bugx/projects.json)")
1224
- p_list.add_argument("--root", type=Path, default=Path.cwd(), help="当前工作区根目录")
1225
- p_list.add_argument("--json", action="store_true", help="以结构化 JSON 输出")
1313
+ p_list.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
1314
+ help="项目根目录(默认当前目录)")
1315
+ p_list.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
1226
1316
  p_list.set_defaults(handler=command_project)
1227
1317
 
1228
1318
  p_refresh = project_sub.add_parser("refresh", help="全量扫描并刷新全局受管工程列表 (~/.bugx/projects.json)")
1229
- p_refresh.add_argument("--root", type=Path, default=Path.cwd(), help="当前工作区根目录")
1230
- p_refresh.add_argument("--json", action="store_true", help="以结构化 JSON 输出")
1319
+ p_refresh.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
1320
+ help="项目根目录(默认当前目录)")
1321
+ p_refresh.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
1231
1322
  p_refresh.set_defaults(handler=command_project)
1232
1323
 
1233
1324
  p_rebind = project_sub.add_parser(
1234
1325
  "rebind",
1235
1326
  help="诊断或迁移 .bugx 的项目身份(项目目录搬移/改名后使用)",
1236
1327
  )
1237
- p_rebind.add_argument("--root", type=Path, default=Path.cwd(), help="项目根目录(默认当前目录)")
1328
+ p_rebind.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
1329
+ help="项目根目录(默认当前目录)")
1238
1330
  p_rebind.add_argument(
1239
1331
  "--migrate", action="store_true",
1240
1332
  help="把盘上 project_id 重写为当前路径指纹并保留 project_uid(确认是搬移而非误用他人布局)",
1241
1333
  )
1242
- p_rebind.add_argument("--json", action="store_true", help="以结构化 JSON 输出")
1334
+ p_rebind.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
1243
1335
  p_rebind.set_defaults(handler=command_project)
1244
1336
 
1245
1337
  p_settings = project_sub.add_parser("settings", help="查看或修改项目的门禁配置、挖掘情报、MCP 与 Skill")
1246
1338
  p_settings.add_argument("target", nargs="?", default=None, help="目标工程路径或工程 Hash(默认当前工作区)")
1247
- p_settings.add_argument("--root", type=Path, default=Path.cwd(), help="当前工作区根目录")
1339
+ p_settings.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
1340
+ help="项目根目录(默认当前目录)")
1248
1341
  p_settings.add_argument("--set-cloud-sync", choices=["on", "off"], default=None, help="设置是否开启云端同步")
1249
1342
  p_settings.add_argument("--set-review", choices=["auto", "interactive", "off"], default=None, help="设置审查执行模式")
1250
1343
  p_settings.add_argument("--set-polling", choices=["auto", "manual", "off"], default=None, help="设置漏洞轮询策略")
1251
1344
  p_settings.add_argument("--set-auto-fix", choices=["on", "off", "confirm"], default=None, help="设置是否自动修改代码")
1252
1345
  p_settings.add_argument("--set-commit", choices=["round", "task", "off"], default=None, help="设置代码自动提交策略")
1253
- p_settings.add_argument("--json", action="store_true", help="以结构化 JSON 输出")
1346
+ p_settings.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
1254
1347
  p_settings.set_defaults(handler=command_project)
1255
1348
 
1256
1349
  project_parser.set_defaults(project_action="analyze", handler=command_project)
1257
- project_parser.add_argument("--root", type=Path, default=Path.cwd(), help="项目根目录(默认当前目录)")
1350
+ project_parser.add_argument("--root", dest="_parent_root", metavar="ROOT", type=Path,
1351
+ action=_UniqueRootAction, help="项目根目录(默认当前目录)")
1258
1352
  project_parser.add_argument("--json", action="store_true", help="以结构化 JSON 输出")
1259
1353
 
1260
1354
  # ── view:安全查看源文件切片与视窗(DOC-225,具越界自愈与沙箱隔离)──
@@ -1398,34 +1492,35 @@ def build_parser() -> argparse.ArgumentParser:
1398
1492
  "eval=--eval-dir 下的引擎自测收据;auto=优先项目运行态、不可用时退回收据"
1399
1493
  )
1400
1494
 
1401
- def _add_report_source_args(p: Any) -> None:
1402
- p.add_argument("--source", choices=("project", "eval", "auto"), default="project",
1403
- help=report_source_help)
1404
- p.add_argument("--root", type=Path, help="项目根目录 (默认当前工作目录)")
1405
- p.add_argument("--eval-dir", type=Path, help="审计收据目录 (默认 verification/evals/oss)")
1406
- p.add_argument("--out", type=Path, help="报告输出目录 (默认与 eval-dir 相同)")
1407
- p.add_argument("--format", choices=("html", "md", "pdf", "both"), default="both", help="文件格式 (默认 both)")
1408
- p.add_argument("--title", help="自定义报告主标题")
1409
- p.add_argument("--json", action="store_true", help="以 JSON 输出报告元数据与生成清单")
1495
+ def _add_report_source_args(p: Any, *, nested: bool = False) -> None:
1496
+ def add(name: str, *, default: Any = None, **kwargs: Any) -> None:
1497
+ p.add_argument(name, default=argparse.SUPPRESS if nested else default, **kwargs)
1498
+
1499
+ add("--source", choices=("project", "eval", "auto"), default="project", help=report_source_help)
1500
+ add("--root", metavar="ROOT", dest="root" if nested else "_parent_root",
1501
+ type=Path, action=_UniqueRootAction, help="项目根目录 (默认当前工作目录)")
1502
+ add("--eval-dir", type=Path, help="审计收据目录 (默认 verification/evals/oss)")
1503
+ add("--out", type=Path, help="报告输出目录 (默认与 eval-dir 相同)")
1504
+ add("--format", choices=("html", "md", "pdf", "both"), default="both", help="文件格式 (默认 both)")
1505
+ add("--title", help="自定义报告主标题")
1506
+ add("--json", action="store_true", default=False, help="以 JSON 输出报告元数据与生成清单")
1410
1507
 
1411
1508
  for sub_name in ("formal", "visual", "both"):
1412
1509
  p = rep_sub.add_parser(sub_name, help=f"生成 {sub_name} 格式安全报告")
1413
- _add_report_source_args(p)
1510
+ _add_report_source_args(p, nested=True)
1414
1511
  p.set_defaults(handler=command_report)
1415
1512
 
1416
1513
  serve_parser = rep_sub.add_parser("serve", help="启动双轨报告本地实时 Web 预览服务")
1417
1514
  serve_parser.add_argument("--host", default="127.0.0.1", help="服务监听地址 (默认 127.0.0.1)")
1418
1515
  serve_parser.add_argument("--port", type=int, default=8080, help="服务监听端口 (默认 8080)")
1419
- _add_report_source_args(serve_parser)
1516
+ _add_report_source_args(serve_parser, nested=True)
1420
1517
  serve_parser.add_argument("--once", action="store_true", help="单次请求后退出 (测试模式)")
1421
1518
  serve_parser.set_defaults(handler=command_report)
1422
1519
 
1423
1520
  _add_report_source_args(rep_parser)
1424
1521
  rep_parser.set_defaults(handler=command_report)
1425
1522
 
1426
- completion.set_defaults(
1427
- completion_commands=tuple(sorted(subparsers.choices)),
1428
- )
1523
+ completion.set_defaults(completion_tree=system.completion_tree(parser))
1429
1524
 
1430
1525
  return parser
1431
1526
 
@@ -1460,15 +1555,40 @@ def _route_engine_help_tokens(tokens: list[str], engine_index: int) -> list[str]
1460
1555
  return rewritten
1461
1556
 
1462
1557
 
1558
+ def _maybe_report_installation(command: str) -> None:
1559
+ """Best-effort daily install/heartbeat reporting for normal CLI commands.
1560
+
1561
+ Privacy/configuration commands are intentionally excluded so a user can
1562
+ disable telemetry without the control command itself causing another
1563
+ outbound request. The reporter has its own gate and never propagates a
1564
+ network or local-state error into the requested CLI command.
1565
+ """
1566
+ if command in {"completion", "config", "cloud", "auth", "telemetry", "update", "stats", "view", "log"}:
1567
+ return
1568
+ try:
1569
+ from core.cloud_sync.flywheel_client import maybe_report_installation
1570
+
1571
+ maybe_report_installation()
1572
+ except Exception:
1573
+ pass
1574
+
1575
+
1463
1576
  def main(argv: list[str] | None = None) -> int:
1464
1577
  from . import common as _common_ns
1465
1578
  _common_ns._ACTIVE_TRACE_ID = None # placeholder replaced below
1466
1579
 
1467
1580
  raw_tokens = list(sys.argv[1:] if argv is None else argv)
1581
+ parser = build_parser()
1468
1582
  first_cmd = None
1469
1583
  first_cmd_index = 0
1584
+ skip_value = False
1470
1585
  for index, token in enumerate(raw_tokens):
1586
+ if skip_value:
1587
+ skip_value = False
1588
+ continue
1471
1589
  if token.startswith("-"):
1590
+ action = parser._option_string_actions.get(token)
1591
+ skip_value = action is not None and action.nargs != 0
1472
1592
  continue
1473
1593
  first_cmd = token
1474
1594
  first_cmd_index = index
@@ -1513,7 +1633,6 @@ def main(argv: list[str] | None = None) -> int:
1513
1633
  )
1514
1634
  return 2
1515
1635
 
1516
- parser = build_parser()
1517
1636
  parse_tokens = argv
1518
1637
  if first_cmd == "engine":
1519
1638
  routed = _route_engine_help_tokens(raw_tokens, first_cmd_index)
@@ -1526,7 +1645,21 @@ def main(argv: list[str] | None = None) -> int:
1526
1645
  return 0
1527
1646
  if args.command == "help":
1528
1647
  return command_help(parser, args)
1529
- root = Path(getattr(args, "root", None) or Path.cwd()).resolve()
1648
+ try:
1649
+ if args.command == "engine":
1650
+ system.normalize_engine_target(args)
1651
+ if system.forwarded_help(args.engine_args):
1652
+ return system.command_engine(args)
1653
+ args.root = resolve_project_root(args.root)
1654
+ if args.command == "supervisor":
1655
+ if system.forwarded_help(args.supervisor_args):
1656
+ return system.supervisor_help(args.supervisor_command)
1657
+ system.normalize_supervisor_target(args)
1658
+ except CliError as exc:
1659
+ parser.error(str(exc))
1660
+ root = Path(getattr(args, "root", None) or Path.cwd()).expanduser().resolve()
1661
+ if getattr(args, "root", None) is not None:
1662
+ args.root = root
1530
1663
  defer_logging = _defer_command_logging_until_authorized(args)
1531
1664
  logger = None if defer_logging else _configure_logging(
1532
1665
  root, getattr(args, "command", "unknown"), args.log_level,
@@ -1550,13 +1683,9 @@ def main(argv: list[str] | None = None) -> int:
1550
1683
  )
1551
1684
  if (args.command != "completion" and not read_only_version_check
1552
1685
  and not installation_only_diagnosis):
1553
- # Centralize the installation-resource gate so command handlers
1554
- # cannot swallow a missing asset error and accidentally skip the
1555
- # one-shot CLI recovery path.
1556
- # Installation-only doctor is the diagnostic escape hatch: it
1557
- # reports broken assets itself and must remain runnable when the
1558
- # central resource gate cannot import the engine.
1686
+ # Installation-only doctor remains available when assets are broken.
1559
1687
  _ensure_core_importable()
1688
+ _maybe_report_installation(args.command)
1560
1689
  if args.command == "probe":
1561
1690
  probe_args = getattr(args, "probe_args", [])
1562
1691
  result = int(command_probe(args, probe_args))
@@ -1571,31 +1700,13 @@ def main(argv: list[str] | None = None) -> int:
1571
1700
  exit_code=result)
1572
1701
  return result
1573
1702
  except MissingAgentAssetError as exc:
1574
- if (argv is None and exc.repairable and not read_only_version_check
1575
- and os.environ.get(_ASSET_REPAIR_ATTEMPT_ENV) != "1"):
1576
- try:
1577
- detail = repair_cli_agent_assets(channel="stable", root=root)
1578
- print(f"[bugx] {detail};正在重启原命令以加载新安装...", file=sys.stderr)
1579
- restart_cli_after_asset_repair()
1580
- except Exception as repair_exc: # noqa: BLE001
1581
- if logger is not None and args.command != "reset":
1582
- logging_module.log_event(
1583
- logger, "asset_repair_failed", str(repair_exc), level=40,
1584
- command=args.command, failure_kind=type(repair_exc).__name__,
1585
- )
1586
- print(f"[bugx] ✗ {exc}", file=sys.stderr)
1587
- print(f"[bugx] ✗ 安全自愈未完成:{repair_exc}", file=sys.stderr)
1588
- print(
1589
- " 可在发布服务恢复后重试,或先安装经过校验的 bugx-cli wheel。",
1590
- file=sys.stderr,
1591
- )
1592
- return 2
1593
-
1594
1703
  if logger is not None and args.command != "reset":
1595
1704
  logging_module.log_event(logger, "command_failed", str(exc),
1596
1705
  level=40, command=args.command,
1597
1706
  failure_kind="agent_assets_missing")
1598
1707
  print(f"[bugx] ✗ {exc}", file=sys.stderr)
1708
+ if exc.repairable:
1709
+ print(" 可显式运行 bugx update --repair-assets 修复安装资源。", file=sys.stderr)
1599
1710
  advice = _generate_ai_exception_advice(exc, getattr(args, "command", None))
1600
1711
  if advice:
1601
1712
  print(f" 💡 AI 解决建议: {advice}", file=sys.stderr)
@@ -1603,7 +1714,7 @@ def main(argv: list[str] | None = None) -> int:
1603
1714
  except CliError as exc:
1604
1715
  from .infra.ai_advisor import RuntimeSelfHealInterceptor
1605
1716
  interceptor = RuntimeSelfHealInterceptor(root)
1606
- if interceptor.can_heal(exc, command=args.command):
1717
+ if not defer_logging and interceptor.can_heal(exc, command=args.command):
1607
1718
  print(f"[bugx] ⚠️ 检测到命令 '{args.command}' 执行中断: {exc}", file=sys.stderr)
1608
1719
  heal_ok, heal_detail = interceptor.try_heal(exc, command=args.command)
1609
1720
  if heal_ok: