bugx-cli 0.1.1 → 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.
- package/README.md +13 -9
- package/core/README.md +1 -1
- package/core/assets/README.md +3 -2
- package/core/assets/bugx-social-preview.svg +71 -0
- package/core/assets/bugx-wechat-group.png +0 -0
- package/core/audit_packs/README.md +2 -0
- package/core/audit_packs/pitfalls/auth_crypto.json +64 -0
- package/core/audit_packs/pitfalls/file_ssrf_cmd.json +64 -0
- package/core/audit_packs/pitfalls/go_backend.json +66 -0
- package/core/audit_packs/pitfalls/java_spring.json +64 -0
- package/core/audit_packs/pitfalls/js_ts_web.json +67 -0
- package/core/audit_packs/pitfalls/python_web.json +82 -0
- package/core/bugx.md +1 -1
- package/core/bugx_paths.py +2 -2
- package/core/cloud_sync/cloud_client.py +56 -5
- package/core/cloud_sync/consent.py +33 -3
- package/core/cloud_sync/flywheel_client.py +186 -24
- package/core/contracts/README.md +1 -1
- package/core/contracts/bugx-runtime-contract.md +1 -1
- package/core/contracts/bugx-worker.md +1 -1
- package/core/engine-integrity.json +122 -66
- package/core/infra/README.md +1 -1
- package/core/infra/build_info.py +2 -2
- package/core/launch_phases/README.md +6 -3
- package/core/launch_phases/finding_confirm_phase.py +168 -7
- package/core/launch_phases/post_phase.py +5 -5
- package/core/launch_phases/pre_recon_scout.py +13 -0
- package/core/launch_phases/report_sharing.py +3 -7
- package/core/launch_phases/round_orchestrator.py +114 -26
- package/core/launch_phases/semantic_recon.py +545 -0
- package/core/launch_phases/startup_version_gate.py +6 -2
- package/core/launch_phases/verify_loop.py +767 -0
- package/core/launch_phases/worker_prior.py +115 -0
- package/core/ledger/README.md +2 -1
- package/core/ledger/finding_verification.py +511 -2
- package/core/ledger/fp_ledger.py +255 -0
- package/core/metadata.txt +2 -2
- package/core/planning/README.md +2 -1
- package/core/planning/prompt_harness.py +50 -10
- package/core/planning/prompt_policy_engine.py +386 -0
- package/core/prompts/README.md +4 -2
- package/core/prompts/policies/prompt_policies.json +101 -0
- package/core/prompts/stages/stage_verify.defensive.md +42 -0
- package/core/prompts/stages/stage_verify.md +44 -0
- package/core/report_engine/report_share.py +0 -8
- package/core/retrieval/README.md +2 -1
- package/core/retrieval/pitfall_packs.py +277 -0
- package/core/runtime/README.md +1 -1
- package/core/runtime/global_telemetry.py +20 -0
- package/core/runtime/scenario_eval.py +1 -1
- package/core/supervisor/README.md +1 -1
- package/docs/07_distribution/01_README_NPM.md +13 -9
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +1 -1
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/qoder/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
- package/interfaces/bin/bugx.js +7 -7
- package/interfaces/cli/bugx_cli/__init__.py +2 -2
- package/interfaces/cli/bugx_cli/cli.py +163 -67
- package/interfaces/cli/bugx_cli/commands/agent.py +122 -61
- package/interfaces/cli/bugx_cli/commands/audit.py +8 -7
- package/interfaces/cli/bugx_cli/commands/cloud.py +27 -19
- package/interfaces/cli/bugx_cli/commands/knowledge.py +3 -4
- package/interfaces/cli/bugx_cli/commands/plugin.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +2 -2
- package/interfaces/cli/bugx_cli/commands/project.py +6 -13
- package/interfaces/cli/bugx_cli/commands/system.py +513 -158
- package/interfaces/cli/bugx_cli/common.py +6 -8
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +21 -10
- package/interfaces/cli/bugx_cli/infra/host_sync.py +1 -1
- package/package.json +29 -15
- package/pyproject.toml +40 -1
- package/scripts/sync-version.mjs +1 -1
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
|
@@ -47,6 +47,13 @@ class _CloudSyncExplicitAction(argparse.Action):
|
|
|
47
47
|
setattr(namespace, self.dest, values)
|
|
48
48
|
setattr(namespace, "cloud_sync_explicit", True)
|
|
49
49
|
|
|
50
|
+
|
|
51
|
+
class _UniqueRootAction(argparse.Action):
|
|
52
|
+
def __call__(self, parser, namespace, values, option_string=None):
|
|
53
|
+
if getattr(namespace, self.dest, None) is not None:
|
|
54
|
+
parser.error("重复指定 --root,请保留一个项目路径。")
|
|
55
|
+
setattr(namespace, self.dest, values)
|
|
56
|
+
|
|
50
57
|
# 将各领域子模块的符号(含公共工具与测试挂载点)全量导出到顶层 cli 命名空间
|
|
51
58
|
for _mod in (
|
|
52
59
|
common, plugin, lifecycle, agent, doctor, knowledge, cloud, system, stats,
|
|
@@ -117,6 +124,62 @@ _INTENT_SYNONYMS: dict[str, str] = {
|
|
|
117
124
|
class _BugXArgumentParser(argparse.ArgumentParser):
|
|
118
125
|
"""带 AI 意图理解与智能模糊纠错的增强参数解析器。"""
|
|
119
126
|
|
|
127
|
+
def __init__(self, *args, **kwargs):
|
|
128
|
+
kwargs.setdefault("allow_abbrev", False)
|
|
129
|
+
super().__init__(*args, **kwargs)
|
|
130
|
+
|
|
131
|
+
@staticmethod
|
|
132
|
+
def _is_switch(action: argparse.Action | None) -> bool:
|
|
133
|
+
return isinstance(action, (
|
|
134
|
+
argparse._StoreTrueAction, argparse._StoreFalseAction,
|
|
135
|
+
argparse.BooleanOptionalAction,
|
|
136
|
+
))
|
|
137
|
+
|
|
138
|
+
def _switch_error(self, option: str, value: str, action: argparse.Action) -> typing.NoReturn:
|
|
139
|
+
negative = isinstance(action, argparse._StoreFalseAction) or (
|
|
140
|
+
isinstance(action, argparse.BooleanOptionalAction) and option.startswith("--no-")
|
|
141
|
+
)
|
|
142
|
+
if (value.casefold() == "true") != negative:
|
|
143
|
+
guidance = f"直接使用 {option}。"
|
|
144
|
+
elif isinstance(action, argparse.BooleanOptionalAction):
|
|
145
|
+
opposite = option.removeprefix("--no-") if negative else option.removeprefix("--")
|
|
146
|
+
prefix = "--" if negative else "--no-"
|
|
147
|
+
guidance = f"改用 {prefix}{opposite}。"
|
|
148
|
+
else:
|
|
149
|
+
guidance = f"省略 {option},使用命令默认值。"
|
|
150
|
+
super().error(f"布尔开关 {option} 不接受值。{guidance}")
|
|
151
|
+
|
|
152
|
+
def parse_args(self, args=None, namespace=None):
|
|
153
|
+
parsed, extras = self.parse_known_args(args, namespace)
|
|
154
|
+
current = self
|
|
155
|
+
active_options = dict(current._option_string_actions)
|
|
156
|
+
while True:
|
|
157
|
+
group = next((a for a in current._actions if isinstance(a, argparse._SubParsersAction)), None)
|
|
158
|
+
if group is None:
|
|
159
|
+
break
|
|
160
|
+
child = group.choices.get(getattr(parsed, group.dest, None))
|
|
161
|
+
if child is None:
|
|
162
|
+
break
|
|
163
|
+
current = child
|
|
164
|
+
active_options.update(current._option_string_actions)
|
|
165
|
+
for token in extras:
|
|
166
|
+
match = re.fullmatch(r"([A-Za-z][\w-]*)=(true|false)", token, re.IGNORECASE)
|
|
167
|
+
if match:
|
|
168
|
+
option = "--" + match[1]
|
|
169
|
+
action = active_options.get(option)
|
|
170
|
+
if self._is_switch(action):
|
|
171
|
+
self._switch_error(option, match[2], action)
|
|
172
|
+
if extras:
|
|
173
|
+
self.error("unrecognized arguments: " + " ".join(extras))
|
|
174
|
+
parent_root = vars(parsed).pop("_parent_root", None)
|
|
175
|
+
if parent_root is not None:
|
|
176
|
+
if getattr(parsed, "root", None) is not None:
|
|
177
|
+
self.error("重复指定 --root,请保留一个项目路径。")
|
|
178
|
+
parsed.root = parent_root
|
|
179
|
+
elif getattr(parsed, "command", None) in {"project", "report"} and not hasattr(parsed, "root"):
|
|
180
|
+
parsed.root = Path.cwd() if parsed.command == "project" else None
|
|
181
|
+
return parsed
|
|
182
|
+
|
|
120
183
|
def error(self, message: str) -> typing.NoReturn:
|
|
121
184
|
match = re.search(r"argument command: invalid choice: '([^']+)'", message)
|
|
122
185
|
if match:
|
|
@@ -143,6 +206,17 @@ class _BugXArgumentParser(argparse.ArgumentParser):
|
|
|
143
206
|
print("\n".join(err_output), file=sys.stderr)
|
|
144
207
|
sys.exit(2)
|
|
145
208
|
|
|
209
|
+
explicit_bool = re.fullmatch(
|
|
210
|
+
r"argument (\S+): ignored explicit argument ['\"](true|false)['\"]",
|
|
211
|
+
message,
|
|
212
|
+
flags=re.IGNORECASE,
|
|
213
|
+
)
|
|
214
|
+
if explicit_bool:
|
|
215
|
+
option = explicit_bool[1].split("/", 1)[0]
|
|
216
|
+
action = self._option_string_actions.get(option)
|
|
217
|
+
if self._is_switch(action):
|
|
218
|
+
self._switch_error(option, explicit_bool[2], action)
|
|
219
|
+
|
|
146
220
|
match_arg = re.search(r"unrecognized arguments:\s*(.+)", message)
|
|
147
221
|
if match_arg:
|
|
148
222
|
bad_args = match_arg.group(1).strip()
|
|
@@ -305,6 +379,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
305
379
|
reset.add_argument("--force", action="store_true", help="强制重置(忽略活跃状态检查;执行前依然创建外部备份)")
|
|
306
380
|
reset.add_argument(
|
|
307
381
|
"--no-backup", "--skip-backup", action="store_true", dest="no_backup",
|
|
382
|
+
default=argparse.SUPPRESS,
|
|
308
383
|
help="跳过执行前自动创建的外部备份归档",
|
|
309
384
|
)
|
|
310
385
|
reset.add_argument("--json", action="store_true")
|
|
@@ -337,6 +412,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
337
412
|
uninstall.add_argument("--yes", action="store_true", help="确认不可逆数据清理")
|
|
338
413
|
uninstall.add_argument(
|
|
339
414
|
"--no-backup", "--skip-backup", action="store_true", dest="no_backup",
|
|
415
|
+
default=argparse.SUPPRESS,
|
|
340
416
|
help="跳过执行前自动创建的外部备份归档",
|
|
341
417
|
)
|
|
342
418
|
uninstall.add_argument("--json", action="store_true")
|
|
@@ -692,7 +768,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
692
768
|
"engine", help="从全局引擎运行生命周期命令(项目不再提供 .bugx/core 入口)",
|
|
693
769
|
)
|
|
694
770
|
engine.add_argument(
|
|
695
|
-
"--root", type=Path, default=None,
|
|
771
|
+
"--root", type=Path, default=None, action=_UniqueRootAction,
|
|
696
772
|
help="项目根目录;缺省时依次读 BUGX_PROJECT_ROOT / 宿主工作区环境变量,最后才用 cwd",
|
|
697
773
|
)
|
|
698
774
|
engine.add_argument(
|
|
@@ -787,7 +863,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
787
863
|
"sync", help="立即执行云端同步;未登录时自动打开授权页",
|
|
788
864
|
))
|
|
789
865
|
p_sync.add_argument("--scope", dest="sync_scope", choices=("project", "global", "all"), default=None,
|
|
790
|
-
help="
|
|
866
|
+
help="同步范围;省略时读云端配置,未配置时仅同步当前项目")
|
|
791
867
|
p_sync.add_argument("--detail-mode", choices=("full", "summary"), default=None,
|
|
792
868
|
help="私有同步详情粒度;缺省读 cloud-config.json sync_detail_mode(默认 full),summary 仅上传摘要/计数/状态")
|
|
793
869
|
p_sync.add_argument("--calibrate", action="store_true",
|
|
@@ -1032,14 +1108,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
1032
1108
|
)
|
|
1033
1109
|
sup.add_argument(
|
|
1034
1110
|
"supervisor_command",
|
|
1035
|
-
choices=
|
|
1036
|
-
"install", "status", "rpc",
|
|
1037
|
-
# 带外动作白名单由 commands.system 单一真源派生(恢复 + 数据修复):
|
|
1038
|
-
# 此处不再复制枚举,避免「帮助列出但 dispatch 拒绝」的静默漂移。
|
|
1039
|
-
*system.SUPERVISOR_PASSTHROUGH_ACTIONS,
|
|
1040
|
-
),
|
|
1111
|
+
choices=system.SUPERVISOR_COMMANDS,
|
|
1041
1112
|
)
|
|
1042
|
-
sup.add_argument("--root", type=Path, default=
|
|
1113
|
+
sup.add_argument("--root", type=Path, default=None, action=_UniqueRootAction)
|
|
1043
1114
|
sup.add_argument("supervisor_args", nargs=argparse.REMAINDER, default=[])
|
|
1044
1115
|
sup.set_defaults(handler=command_supervisor)
|
|
1045
1116
|
|
|
@@ -1206,55 +1277,63 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
1206
1277
|
project_sub = project_parser.add_subparsers(dest="project_action")
|
|
1207
1278
|
|
|
1208
1279
|
p_analyze = project_sub.add_parser("analyze", help="全景扫描并分析当前或指定工程的代码体量与画像")
|
|
1209
|
-
p_analyze.add_argument("--root", type=Path, default=
|
|
1210
|
-
|
|
1280
|
+
p_analyze.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
|
|
1281
|
+
help="项目根目录(默认当前目录)")
|
|
1282
|
+
p_analyze.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
|
|
1211
1283
|
p_analyze.set_defaults(handler=command_project)
|
|
1212
1284
|
|
|
1213
1285
|
p_show = project_sub.add_parser("show", help="查看已缓存的项目画像与度量")
|
|
1214
|
-
p_show.add_argument("--root", type=Path, default=
|
|
1215
|
-
|
|
1286
|
+
p_show.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
|
|
1287
|
+
help="项目根目录(默认当前目录)")
|
|
1288
|
+
p_show.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
|
|
1216
1289
|
p_show.set_defaults(handler=command_project)
|
|
1217
1290
|
|
|
1218
1291
|
p_sync = project_sub.add_parser("sync", help="将项目画像与代码指标同步至云端看板")
|
|
1219
|
-
p_sync.add_argument("--root", type=Path, default=
|
|
1220
|
-
|
|
1292
|
+
p_sync.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
|
|
1293
|
+
help="项目根目录(默认当前目录)")
|
|
1294
|
+
p_sync.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
|
|
1221
1295
|
p_sync.set_defaults(handler=command_project)
|
|
1222
1296
|
|
|
1223
1297
|
p_list = project_sub.add_parser("list", help="查看全局所有受管工程列表 (~/.bugx/projects.json)")
|
|
1224
|
-
p_list.add_argument("--root", type=Path, default=
|
|
1225
|
-
|
|
1298
|
+
p_list.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
|
|
1299
|
+
help="项目根目录(默认当前目录)")
|
|
1300
|
+
p_list.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
|
|
1226
1301
|
p_list.set_defaults(handler=command_project)
|
|
1227
1302
|
|
|
1228
1303
|
p_refresh = project_sub.add_parser("refresh", help="全量扫描并刷新全局受管工程列表 (~/.bugx/projects.json)")
|
|
1229
|
-
p_refresh.add_argument("--root", type=Path, default=
|
|
1230
|
-
|
|
1304
|
+
p_refresh.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
|
|
1305
|
+
help="项目根目录(默认当前目录)")
|
|
1306
|
+
p_refresh.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
|
|
1231
1307
|
p_refresh.set_defaults(handler=command_project)
|
|
1232
1308
|
|
|
1233
1309
|
p_rebind = project_sub.add_parser(
|
|
1234
1310
|
"rebind",
|
|
1235
1311
|
help="诊断或迁移 .bugx 的项目身份(项目目录搬移/改名后使用)",
|
|
1236
1312
|
)
|
|
1237
|
-
p_rebind.add_argument("--root", type=Path, default=
|
|
1313
|
+
p_rebind.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
|
|
1314
|
+
help="项目根目录(默认当前目录)")
|
|
1238
1315
|
p_rebind.add_argument(
|
|
1239
1316
|
"--migrate", action="store_true",
|
|
1240
1317
|
help="把盘上 project_id 重写为当前路径指纹并保留 project_uid(确认是搬移而非误用他人布局)",
|
|
1241
1318
|
)
|
|
1242
|
-
p_rebind.add_argument("--json", action="store_true", help="以结构化 JSON 输出")
|
|
1319
|
+
p_rebind.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
|
|
1243
1320
|
p_rebind.set_defaults(handler=command_project)
|
|
1244
1321
|
|
|
1245
1322
|
p_settings = project_sub.add_parser("settings", help="查看或修改项目的门禁配置、挖掘情报、MCP 与 Skill")
|
|
1246
1323
|
p_settings.add_argument("target", nargs="?", default=None, help="目标工程路径或工程 Hash(默认当前工作区)")
|
|
1247
|
-
p_settings.add_argument("--root", type=Path, default=
|
|
1324
|
+
p_settings.add_argument("--root", type=Path, default=argparse.SUPPRESS, action=_UniqueRootAction,
|
|
1325
|
+
help="项目根目录(默认当前目录)")
|
|
1248
1326
|
p_settings.add_argument("--set-cloud-sync", choices=["on", "off"], default=None, help="设置是否开启云端同步")
|
|
1249
1327
|
p_settings.add_argument("--set-review", choices=["auto", "interactive", "off"], default=None, help="设置审查执行模式")
|
|
1250
1328
|
p_settings.add_argument("--set-polling", choices=["auto", "manual", "off"], default=None, help="设置漏洞轮询策略")
|
|
1251
1329
|
p_settings.add_argument("--set-auto-fix", choices=["on", "off", "confirm"], default=None, help="设置是否自动修改代码")
|
|
1252
1330
|
p_settings.add_argument("--set-commit", choices=["round", "task", "off"], default=None, help="设置代码自动提交策略")
|
|
1253
|
-
p_settings.add_argument("--json", action="store_true", help="以结构化 JSON 输出")
|
|
1331
|
+
p_settings.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="以结构化 JSON 输出")
|
|
1254
1332
|
p_settings.set_defaults(handler=command_project)
|
|
1255
1333
|
|
|
1256
1334
|
project_parser.set_defaults(project_action="analyze", handler=command_project)
|
|
1257
|
-
project_parser.add_argument("--root",
|
|
1335
|
+
project_parser.add_argument("--root", dest="_parent_root", metavar="ROOT", type=Path,
|
|
1336
|
+
action=_UniqueRootAction, help="项目根目录(默认当前目录)")
|
|
1258
1337
|
project_parser.add_argument("--json", action="store_true", help="以结构化 JSON 输出")
|
|
1259
1338
|
|
|
1260
1339
|
# ── view:安全查看源文件切片与视窗(DOC-225,具越界自愈与沙箱隔离)──
|
|
@@ -1398,34 +1477,35 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
1398
1477
|
"eval=--eval-dir 下的引擎自测收据;auto=优先项目运行态、不可用时退回收据"
|
|
1399
1478
|
)
|
|
1400
1479
|
|
|
1401
|
-
def _add_report_source_args(p: Any) -> None:
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1480
|
+
def _add_report_source_args(p: Any, *, nested: bool = False) -> None:
|
|
1481
|
+
def add(name: str, *, default: Any = None, **kwargs: Any) -> None:
|
|
1482
|
+
p.add_argument(name, default=argparse.SUPPRESS if nested else default, **kwargs)
|
|
1483
|
+
|
|
1484
|
+
add("--source", choices=("project", "eval", "auto"), default="project", help=report_source_help)
|
|
1485
|
+
add("--root", metavar="ROOT", dest="root" if nested else "_parent_root",
|
|
1486
|
+
type=Path, action=_UniqueRootAction, help="项目根目录 (默认当前工作目录)")
|
|
1487
|
+
add("--eval-dir", type=Path, help="审计收据目录 (默认 verification/evals/oss)")
|
|
1488
|
+
add("--out", type=Path, help="报告输出目录 (默认与 eval-dir 相同)")
|
|
1489
|
+
add("--format", choices=("html", "md", "pdf", "both"), default="both", help="文件格式 (默认 both)")
|
|
1490
|
+
add("--title", help="自定义报告主标题")
|
|
1491
|
+
add("--json", action="store_true", default=False, help="以 JSON 输出报告元数据与生成清单")
|
|
1410
1492
|
|
|
1411
1493
|
for sub_name in ("formal", "visual", "both"):
|
|
1412
1494
|
p = rep_sub.add_parser(sub_name, help=f"生成 {sub_name} 格式安全报告")
|
|
1413
|
-
_add_report_source_args(p)
|
|
1495
|
+
_add_report_source_args(p, nested=True)
|
|
1414
1496
|
p.set_defaults(handler=command_report)
|
|
1415
1497
|
|
|
1416
1498
|
serve_parser = rep_sub.add_parser("serve", help="启动双轨报告本地实时 Web 预览服务")
|
|
1417
1499
|
serve_parser.add_argument("--host", default="127.0.0.1", help="服务监听地址 (默认 127.0.0.1)")
|
|
1418
1500
|
serve_parser.add_argument("--port", type=int, default=8080, help="服务监听端口 (默认 8080)")
|
|
1419
|
-
_add_report_source_args(serve_parser)
|
|
1501
|
+
_add_report_source_args(serve_parser, nested=True)
|
|
1420
1502
|
serve_parser.add_argument("--once", action="store_true", help="单次请求后退出 (测试模式)")
|
|
1421
1503
|
serve_parser.set_defaults(handler=command_report)
|
|
1422
1504
|
|
|
1423
1505
|
_add_report_source_args(rep_parser)
|
|
1424
1506
|
rep_parser.set_defaults(handler=command_report)
|
|
1425
1507
|
|
|
1426
|
-
completion.set_defaults(
|
|
1427
|
-
completion_commands=tuple(sorted(subparsers.choices)),
|
|
1428
|
-
)
|
|
1508
|
+
completion.set_defaults(completion_tree=system.completion_tree(parser))
|
|
1429
1509
|
|
|
1430
1510
|
return parser
|
|
1431
1511
|
|
|
@@ -1460,15 +1540,40 @@ def _route_engine_help_tokens(tokens: list[str], engine_index: int) -> list[str]
|
|
|
1460
1540
|
return rewritten
|
|
1461
1541
|
|
|
1462
1542
|
|
|
1543
|
+
def _maybe_report_installation(command: str) -> None:
|
|
1544
|
+
"""Best-effort daily install/heartbeat reporting for normal CLI commands.
|
|
1545
|
+
|
|
1546
|
+
Privacy/configuration commands are intentionally excluded so a user can
|
|
1547
|
+
disable telemetry without the control command itself causing another
|
|
1548
|
+
outbound request. The reporter has its own gate and never propagates a
|
|
1549
|
+
network or local-state error into the requested CLI command.
|
|
1550
|
+
"""
|
|
1551
|
+
if command in {"completion", "config", "cloud", "auth", "telemetry", "update", "stats", "view", "log"}:
|
|
1552
|
+
return
|
|
1553
|
+
try:
|
|
1554
|
+
from core.cloud_sync.flywheel_client import maybe_report_installation
|
|
1555
|
+
|
|
1556
|
+
maybe_report_installation()
|
|
1557
|
+
except Exception:
|
|
1558
|
+
pass
|
|
1559
|
+
|
|
1560
|
+
|
|
1463
1561
|
def main(argv: list[str] | None = None) -> int:
|
|
1464
1562
|
from . import common as _common_ns
|
|
1465
1563
|
_common_ns._ACTIVE_TRACE_ID = None # placeholder replaced below
|
|
1466
1564
|
|
|
1467
1565
|
raw_tokens = list(sys.argv[1:] if argv is None else argv)
|
|
1566
|
+
parser = build_parser()
|
|
1468
1567
|
first_cmd = None
|
|
1469
1568
|
first_cmd_index = 0
|
|
1569
|
+
skip_value = False
|
|
1470
1570
|
for index, token in enumerate(raw_tokens):
|
|
1571
|
+
if skip_value:
|
|
1572
|
+
skip_value = False
|
|
1573
|
+
continue
|
|
1471
1574
|
if token.startswith("-"):
|
|
1575
|
+
action = parser._option_string_actions.get(token)
|
|
1576
|
+
skip_value = action is not None and action.nargs != 0
|
|
1472
1577
|
continue
|
|
1473
1578
|
first_cmd = token
|
|
1474
1579
|
first_cmd_index = index
|
|
@@ -1513,7 +1618,6 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
1513
1618
|
)
|
|
1514
1619
|
return 2
|
|
1515
1620
|
|
|
1516
|
-
parser = build_parser()
|
|
1517
1621
|
parse_tokens = argv
|
|
1518
1622
|
if first_cmd == "engine":
|
|
1519
1623
|
routed = _route_engine_help_tokens(raw_tokens, first_cmd_index)
|
|
@@ -1526,7 +1630,21 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
1526
1630
|
return 0
|
|
1527
1631
|
if args.command == "help":
|
|
1528
1632
|
return command_help(parser, args)
|
|
1529
|
-
|
|
1633
|
+
try:
|
|
1634
|
+
if args.command == "engine":
|
|
1635
|
+
system.normalize_engine_target(args)
|
|
1636
|
+
if system.forwarded_help(args.engine_args):
|
|
1637
|
+
return system.command_engine(args)
|
|
1638
|
+
args.root = resolve_project_root(args.root)
|
|
1639
|
+
if args.command == "supervisor":
|
|
1640
|
+
if system.forwarded_help(args.supervisor_args):
|
|
1641
|
+
return system.supervisor_help(args.supervisor_command)
|
|
1642
|
+
system.normalize_supervisor_target(args)
|
|
1643
|
+
except CliError as exc:
|
|
1644
|
+
parser.error(str(exc))
|
|
1645
|
+
root = Path(getattr(args, "root", None) or Path.cwd()).expanduser().resolve()
|
|
1646
|
+
if getattr(args, "root", None) is not None:
|
|
1647
|
+
args.root = root
|
|
1530
1648
|
defer_logging = _defer_command_logging_until_authorized(args)
|
|
1531
1649
|
logger = None if defer_logging else _configure_logging(
|
|
1532
1650
|
root, getattr(args, "command", "unknown"), args.log_level,
|
|
@@ -1550,13 +1668,9 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
1550
1668
|
)
|
|
1551
1669
|
if (args.command != "completion" and not read_only_version_check
|
|
1552
1670
|
and not installation_only_diagnosis):
|
|
1553
|
-
#
|
|
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.
|
|
1671
|
+
# Installation-only doctor remains available when assets are broken.
|
|
1559
1672
|
_ensure_core_importable()
|
|
1673
|
+
_maybe_report_installation(args.command)
|
|
1560
1674
|
if args.command == "probe":
|
|
1561
1675
|
probe_args = getattr(args, "probe_args", [])
|
|
1562
1676
|
result = int(command_probe(args, probe_args))
|
|
@@ -1571,31 +1685,13 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
1571
1685
|
exit_code=result)
|
|
1572
1686
|
return result
|
|
1573
1687
|
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
1688
|
if logger is not None and args.command != "reset":
|
|
1595
1689
|
logging_module.log_event(logger, "command_failed", str(exc),
|
|
1596
1690
|
level=40, command=args.command,
|
|
1597
1691
|
failure_kind="agent_assets_missing")
|
|
1598
1692
|
print(f"[bugx] ✗ {exc}", file=sys.stderr)
|
|
1693
|
+
if exc.repairable:
|
|
1694
|
+
print(" 可显式运行 bugx update --repair-assets 修复安装资源。", file=sys.stderr)
|
|
1599
1695
|
advice = _generate_ai_exception_advice(exc, getattr(args, "command", None))
|
|
1600
1696
|
if advice:
|
|
1601
1697
|
print(f" 💡 AI 解决建议: {advice}", file=sys.stderr)
|
|
@@ -1603,7 +1699,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
1603
1699
|
except CliError as exc:
|
|
1604
1700
|
from .infra.ai_advisor import RuntimeSelfHealInterceptor
|
|
1605
1701
|
interceptor = RuntimeSelfHealInterceptor(root)
|
|
1606
|
-
if interceptor.can_heal(exc, command=args.command):
|
|
1702
|
+
if not defer_logging and interceptor.can_heal(exc, command=args.command):
|
|
1607
1703
|
print(f"[bugx] ⚠️ 检测到命令 '{args.command}' 执行中断: {exc}", file=sys.stderr)
|
|
1608
1704
|
heal_ok, heal_detail = interceptor.try_heal(exc, command=args.command)
|
|
1609
1705
|
if heal_ok:
|