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.
Files changed (82) hide show
  1. package/README.md +13 -9
  2. package/core/README.md +1 -1
  3. package/core/assets/README.md +3 -2
  4. package/core/assets/bugx-social-preview.svg +71 -0
  5. package/core/assets/bugx-wechat-group.png +0 -0
  6. package/core/audit_packs/README.md +2 -0
  7. package/core/audit_packs/pitfalls/auth_crypto.json +64 -0
  8. package/core/audit_packs/pitfalls/file_ssrf_cmd.json +64 -0
  9. package/core/audit_packs/pitfalls/go_backend.json +66 -0
  10. package/core/audit_packs/pitfalls/java_spring.json +64 -0
  11. package/core/audit_packs/pitfalls/js_ts_web.json +67 -0
  12. package/core/audit_packs/pitfalls/python_web.json +82 -0
  13. package/core/bugx.md +1 -1
  14. package/core/bugx_paths.py +2 -2
  15. package/core/cloud_sync/cloud_client.py +56 -5
  16. package/core/cloud_sync/consent.py +33 -3
  17. package/core/cloud_sync/flywheel_client.py +186 -24
  18. package/core/contracts/README.md +1 -1
  19. package/core/contracts/bugx-runtime-contract.md +1 -1
  20. package/core/contracts/bugx-worker.md +1 -1
  21. package/core/engine-integrity.json +122 -66
  22. package/core/infra/README.md +1 -1
  23. package/core/infra/build_info.py +2 -2
  24. package/core/launch_phases/README.md +6 -3
  25. package/core/launch_phases/finding_confirm_phase.py +168 -7
  26. package/core/launch_phases/post_phase.py +5 -5
  27. package/core/launch_phases/pre_recon_scout.py +13 -0
  28. package/core/launch_phases/report_sharing.py +3 -7
  29. package/core/launch_phases/round_orchestrator.py +114 -26
  30. package/core/launch_phases/semantic_recon.py +545 -0
  31. package/core/launch_phases/startup_version_gate.py +6 -2
  32. package/core/launch_phases/verify_loop.py +767 -0
  33. package/core/launch_phases/worker_prior.py +115 -0
  34. package/core/ledger/README.md +2 -1
  35. package/core/ledger/finding_verification.py +511 -2
  36. package/core/ledger/fp_ledger.py +255 -0
  37. package/core/metadata.txt +2 -2
  38. package/core/planning/README.md +2 -1
  39. package/core/planning/prompt_harness.py +50 -10
  40. package/core/planning/prompt_policy_engine.py +386 -0
  41. package/core/prompts/README.md +4 -2
  42. package/core/prompts/policies/prompt_policies.json +101 -0
  43. package/core/prompts/stages/stage_verify.defensive.md +42 -0
  44. package/core/prompts/stages/stage_verify.md +44 -0
  45. package/core/report_engine/report_share.py +0 -8
  46. package/core/retrieval/README.md +2 -1
  47. package/core/retrieval/pitfall_packs.py +277 -0
  48. package/core/runtime/README.md +1 -1
  49. package/core/runtime/global_telemetry.py +20 -0
  50. package/core/runtime/scenario_eval.py +1 -1
  51. package/core/supervisor/README.md +1 -1
  52. package/docs/07_distribution/01_README_NPM.md +13 -9
  53. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  54. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  55. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +1 -1
  56. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  57. package/ecosystem/integrations/qoder/connector-meta.json +1 -1
  58. package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
  59. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
  60. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
  61. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
  62. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
  63. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
  64. package/interfaces/bin/bugx.js +7 -7
  65. package/interfaces/cli/bugx_cli/__init__.py +2 -2
  66. package/interfaces/cli/bugx_cli/cli.py +163 -67
  67. package/interfaces/cli/bugx_cli/commands/agent.py +122 -61
  68. package/interfaces/cli/bugx_cli/commands/audit.py +8 -7
  69. package/interfaces/cli/bugx_cli/commands/cloud.py +27 -19
  70. package/interfaces/cli/bugx_cli/commands/knowledge.py +3 -4
  71. package/interfaces/cli/bugx_cli/commands/plugin.py +3 -3
  72. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +2 -2
  73. package/interfaces/cli/bugx_cli/commands/project.py +6 -13
  74. package/interfaces/cli/bugx_cli/commands/system.py +513 -158
  75. package/interfaces/cli/bugx_cli/common.py +6 -8
  76. package/interfaces/cli/bugx_cli/infra/engine_installer.py +21 -10
  77. package/interfaces/cli/bugx_cli/infra/host_sync.py +1 -1
  78. package/package.json +29 -15
  79. package/pyproject.toml +40 -1
  80. package/scripts/sync-version.mjs +1 -1
  81. package/core/assets/bugx-hero-cn.png +0 -0
  82. package/core/assets/bugx-hero-en.png +0 -0
@@ -50,6 +50,7 @@ from ..host_adapters import (
50
50
  ENTRY_SKILL_PAYLOAD,
51
51
  ENTRY_USER_REGISTRATION,
52
52
  HOST_ADAPTERS,
53
+ HostAdapter,
53
54
  HOST_NAME_CLAUDE,
54
55
  HOST_NAME_FUNIDE,
55
56
  HOST_NAME_QODER,
@@ -124,32 +125,54 @@ class _CliProgress:
124
125
  # Backward-compatible test/import name; the renderer is shared by all long CLI commands.
125
126
  _InstallProgress = _CliProgress
126
127
 
127
- #: **未迁移**宿主的安装面基线(逐宿主切片时删除对应项)。已迁移宿主的目录由
128
- #: ``HOST_ADAPTERS.managed_surfaces()``(插件 marker 投影)自动追加。
129
- #: **未迁移**宿主的用户级可见位置提示;已迁移宿主用 ``全局 <label> 可见``。
128
+ #: 安装事务始终保护的共享运行面。宿主目录由本次选中的适配器按需追加,
129
+ #: 避免安装一个宿主时因为另一个宿主的用户自定义链接而提前失败。
130
+ #: 宿主用户级注册后的「在哪里可见」提示。
130
131
  _USER_AGENT_VISIBILITY_HINTS = {
131
132
  "funide": "FunIDE 设置 → 智能体可见",
132
133
  }
133
134
 
134
135
 
135
136
  def _user_agent_visibility(host_name: str) -> str:
136
- """用户级注册后的「在哪里可见」提示(未迁移宿主走基线表)。"""
137
+ """返回用户级注册后的「在哪里可见」提示。"""
137
138
 
138
139
  hint = _USER_AGENT_VISIBILITY_HINTS.get(host_name)
139
140
  return hint or f"全局 {engine_host_label(host_name)} 可见"
140
141
 
141
142
 
142
- _BASE_AGENT_INSTALL_SURFACES = (
143
- ".bugx", ".opencode", ".claude", ".zcode", ".pi", ".agents",
144
- ".workbuddy", ".codebuddy", ".qoder", ".github",
145
- ".dsh", "plugins", CONFIG_NAME,
146
- )
147
- _AGENT_INSTALL_SURFACES = tuple(
148
- dict.fromkeys(
149
- list(_BASE_AGENT_INSTALL_SURFACES)
150
- + [surface for adapter in HOST_ADAPTERS for surface in adapter.managed_surfaces()]
151
- )
152
- )
143
+ _BASE_AGENT_INSTALL_SURFACES = (".bugx",)
144
+
145
+
146
+ def _agent_install_surfaces(
147
+ selected_adapters: tuple[HostAdapter, ...] | None = None,
148
+ ) -> tuple[str, ...]:
149
+ """Return the project surfaces that this transaction may write.
150
+
151
+ ``None`` preserves the complete registry projection for direct in-process
152
+ callers. The CLI install path passes the selected adapters so an unrelated
153
+ host directory cannot veto the transaction.
154
+ """
155
+ adapters = HOST_ADAPTERS if selected_adapters is None else selected_adapters
156
+ surfaces = list(_BASE_AGENT_INSTALL_SURFACES)
157
+ plugins = {
158
+ str(plugin.identity.name): plugin
159
+ for plugin in engine_host_plugins()
160
+ if getattr(plugin, "identity", None) is not None
161
+ }
162
+ for adapter in adapters:
163
+ surfaces.extend(adapter.managed_surfaces())
164
+ if adapter.supports(CAP_PROJECT_MCP_CONFIG):
165
+ surfaces.append(CONFIG_NAME)
166
+ plugin = plugins.get(adapter.name)
167
+ if plugin is not None:
168
+ for relative in plugin.install.mcp_relpaths:
169
+ path = Path(relative)
170
+ if not path.is_absolute() and path.parts:
171
+ surfaces.append(path.parts[0])
172
+ return tuple(dict.fromkeys(surfaces))
173
+
174
+
175
+ _AGENT_INSTALL_SURFACES = _agent_install_surfaces()
153
176
 
154
177
  # The transaction protects only BugX-owned files that the install path can
155
178
  # write. It must never copy an entire host directory: user-level installs
@@ -328,8 +351,12 @@ def command_agent(args: argparse.Namespace) -> int:
328
351
  progress = _CliProgress(args)
329
352
  progress.update(0, "准备安装")
330
353
  root = args.root.resolve()
354
+ _ensure_core_importable()
355
+ selected_adapters = _select_install_adapters(
356
+ args, root, discover_hosts(root),
357
+ )
331
358
  try:
332
- staging, existed = _agent_install_snapshot(root)
359
+ staging, existed = _agent_install_snapshot(root, selected_adapters)
333
360
  except (OSError, shutil.Error) as exc:
334
361
  raise CliError(_i18n_exc(
335
362
  "agent.install_snapshot_failed",
@@ -339,7 +366,11 @@ def command_agent(args: argparse.Namespace) -> int:
339
366
  token = _GLOBAL_TX.set(staging)
340
367
  preserve_staging = False
341
368
  try:
342
- return _command_agent_impl(args, progress=progress)
369
+ return _command_agent_impl(
370
+ args,
371
+ progress=progress,
372
+ selected_adapters=selected_adapters,
373
+ )
343
374
  except BaseException as install_error:
344
375
  progress.fail()
345
376
  rollback_errors: list[str] = []
@@ -391,7 +422,10 @@ def _ignore_install_snapshot_entries(directory: str, names: list[str]) -> list[s
391
422
  return [name for name in names if _is_special_install_entry(Path(directory) / name)]
392
423
 
393
424
 
394
- def _agent_install_snapshot(root: Path) -> tuple[Path, dict[str, bool]]:
425
+ def _agent_install_snapshot(
426
+ root: Path,
427
+ selected_adapters: tuple[HostAdapter, ...] | None = None,
428
+ ) -> tuple[Path, dict[str, bool]]:
395
429
  """Stage only BugX-owned files before a host install.
396
430
 
397
431
  Installation touches shared runtime files as well as one or more host
@@ -403,7 +437,7 @@ def _agent_install_snapshot(root: Path) -> tuple[Path, dict[str, bool]]:
403
437
  staging = Path(tempfile.mkdtemp(prefix="bugx-install-transaction-")).resolve()
404
438
  existed: dict[str, bool] = {}
405
439
  try:
406
- for relative in _AGENT_INSTALL_SURFACES:
440
+ for relative in _agent_install_surfaces(selected_adapters):
407
441
  target = root / relative
408
442
  existed[relative] = target.exists() or _is_reparse_point(target)
409
443
  if not existed[relative]:
@@ -736,34 +770,14 @@ def _installed_engine_build_id() -> int:
736
770
  pass
737
771
  return get_build_id() or 1
738
772
 
739
- def _command_agent_impl(
740
- args: argparse.Namespace, *, progress: _CliProgress | None = None,
741
- ) -> int:
742
- """发现并安装到宿主 AI;不启动宿主,也不执行审计。"""
743
- root = args.root.resolve()
744
- command = getattr(args, "agent_command", "install")
745
- _ensure_core_importable()
746
- import core.i18n as i18n
747
- deployment_locale = i18n.resolve_locale().resolved_locale
748
- if getattr(args, "locale", None):
749
- norm = i18n.normalize_locale(args.locale)
750
- if not norm:
751
- raise CliError(_i18n_exc("common.invalid_locale", f"不支持的 locale: {args.locale};可选:zh-CN, en-US", locale=args.locale))
752
- deployment_locale = norm
753
- hosts = discover_hosts(root)
754
- if command == "discover":
755
- payload = {"root": str(root), "hosts": hosts, "execution": "none"}
756
- if args.json:
757
- print(json.dumps(payload, ensure_ascii=False, indent=2))
758
- else:
759
- for item in hosts:
760
- state = "FOUND" if item["installed"] else "NOT_FOUND"
761
- executable = item["executable"] or item.get("app_path") or "-"
762
- print(f"{item['name']}\t{state}\t{executable}\t{item['install_path']}")
763
- return 0
764
- if command != "install":
765
- raise CliError(_i18n_exc("agent.unknown_agent_command", f"未知 Agent 命令: {command}", command=command))
766
- raw_requested = []
773
+
774
+ def _select_install_adapters(
775
+ args: argparse.Namespace,
776
+ root: Path,
777
+ hosts: list[dict[str, object]],
778
+ ) -> tuple[HostAdapter, ...]:
779
+ """Resolve and validate the requested hosts before opening the transaction."""
780
+ raw_requested: list[str] = []
767
781
  for item in getattr(args, "agent", []):
768
782
  for sub in str(item).split(","):
769
783
  sub = sub.strip()
@@ -772,32 +786,37 @@ def _command_agent_impl(
772
786
  requested = list(dict.fromkeys(raw_requested))
773
787
  if not requested:
774
788
  if args.non_interactive:
775
- raise CliError(_i18n_exc("agent.non_interactive_agent_required", "非交互安装必须显式提供 --agent opencode/dsh/codex/cline/claude/zcode/workbuddy/pi/chatgpt/qoder/trea/funide"))
789
+ raise CliError(_i18n_exc(
790
+ "agent.non_interactive_agent_required",
791
+ "非交互安装必须显式提供 --agent opencode/dsh/codex/cline/claude/zcode/workbuddy/pi/chatgpt/qoder/trea/funide",
792
+ ))
776
793
  if not sys.stdin.isatty():
777
- raise CliError(_i18n_exc("agent.non_tty_agent_required", "当前不是交互终端;请显式提供 --agent"))
794
+ raise CliError(_i18n_exc(
795
+ "agent.non_tty_agent_required",
796
+ "当前不是交互终端;请显式提供 --agent",
797
+ ))
778
798
  requested = _prompt_for_hosts(hosts, root)
779
799
  if "all" in requested:
780
800
  available_names = [str(item["name"]) for item in hosts if item["installed"]]
781
801
  if not available_names and not args.allow_missing:
782
802
  raise CliError(_i18n_exc(
783
803
  "plugin.no_agent_detected",
784
- "没有检测到已安装的 AI Agent;请安装 OpenCode/Codex/Claude/ZCode/Pi/ChatGPT,"
785
- "或显式指定 --agent",
804
+ "没有检测到已安装的 AI Agent;请安装 OpenCode/Codex/Claude/ZCode/Pi/ChatGPT,或显式指定 --agent",
786
805
  ))
787
806
  if not available_names and args.allow_missing:
788
807
  available_names = [str(item["name"]) for item in hosts]
789
- expanded = []
808
+ expanded: list[str] = []
790
809
  for name in requested:
791
810
  if name == "all":
792
- for av in available_names:
793
- if av not in expanded:
794
- expanded.append(av)
795
- else:
796
- if name not in expanded:
797
- expanded.append(name)
811
+ for available in available_names:
812
+ if available not in expanded:
813
+ expanded.append(available)
814
+ elif name not in expanded:
815
+ expanded.append(name)
798
816
  requested = expanded
799
- selected = []
800
- seen_adapters = set()
817
+
818
+ selected: list[HostAdapter] = []
819
+ seen_adapters: set[str] = set()
801
820
  for name in requested:
802
821
  try:
803
822
  adapter = get_adapter(name)
@@ -808,8 +827,50 @@ def _command_agent_impl(
808
827
  seen_adapters.add(adapter.name)
809
828
  detected = next(item for item in hosts if item["name"] == adapter.name)
810
829
  if not detected["installed"] and not args.allow_missing:
811
- raise CliError(_i18n_exc("agent.adapter_missing_allow_missing", f"未检测到 {adapter.label};如仍要写入项目入口,请加 --allow-missing", label=adapter.label))
830
+ raise CliError(_i18n_exc(
831
+ "agent.adapter_missing_allow_missing",
832
+ f"未检测到 {adapter.label};如仍要写入项目入口,请加 --allow-missing",
833
+ label=adapter.label,
834
+ ))
812
835
  selected.append(adapter)
836
+ return tuple(selected)
837
+
838
+
839
+ def _command_agent_impl(
840
+ args: argparse.Namespace,
841
+ *,
842
+ progress: _CliProgress | None = None,
843
+ selected_adapters: tuple[HostAdapter, ...] | None = None,
844
+ ) -> int:
845
+ """发现并安装到宿主 AI;不启动宿主,也不执行审计。"""
846
+ root = args.root.resolve()
847
+ command = getattr(args, "agent_command", "install")
848
+ _ensure_core_importable()
849
+ import core.i18n as i18n
850
+ deployment_locale = i18n.resolve_locale().resolved_locale
851
+ if getattr(args, "locale", None):
852
+ norm = i18n.normalize_locale(args.locale)
853
+ if not norm:
854
+ raise CliError(_i18n_exc("common.invalid_locale", f"不支持的 locale: {args.locale};可选:zh-CN, en-US", locale=args.locale))
855
+ deployment_locale = norm
856
+ hosts = discover_hosts(root)
857
+ if command == "discover":
858
+ payload = {"root": str(root), "hosts": hosts, "execution": "none"}
859
+ if args.json:
860
+ print(json.dumps(payload, ensure_ascii=False, indent=2))
861
+ else:
862
+ for item in hosts:
863
+ state = "FOUND" if item["installed"] else "NOT_FOUND"
864
+ executable = item["executable"] or item.get("app_path") or "-"
865
+ print(f"{item['name']}\t{state}\t{executable}\t{item['install_path']}")
866
+ return 0
867
+ if command != "install":
868
+ raise CliError(_i18n_exc("agent.unknown_agent_command", f"未知 Agent 命令: {command}", command=command))
869
+ selected = list(
870
+ _select_install_adapters(args, root, hosts)
871
+ if selected_adapters is None
872
+ else selected_adapters
873
+ )
813
874
  if progress is not None:
814
875
  progress.update(10, "已确认安装目标")
815
876
 
@@ -618,15 +618,16 @@ def _command_audit_penetration(args: argparse.Namespace) -> int:
618
618
 
619
619
 
620
620
  def command_audit(args: argparse.Namespace) -> int:
621
- """bugx audit 统一调度入口:根据参数自适应分发到原生图编排或全息攻防渗透流水线。"""
622
- is_penetration = bool(
623
- getattr(args, "deep", False)
624
- or getattr(args, "out", None)
621
+ """Select the existing deep route only when explicitly requested."""
622
+ if getattr(args, "deep", False):
623
+ return _command_audit_penetration(args)
624
+ if (
625
+ getattr(args, "out", None)
625
626
  or getattr(args, "format", "all") != "all"
626
627
  or getattr(args, "concurrency", 6) != 6
627
628
  or getattr(args, "min_kill_rate", 0.85) != 0.85
628
629
  or getattr(args, "open_browser", False)
629
- )
630
- if is_penetration:
631
- return _command_audit_penetration(args)
630
+ ):
631
+ print("[bugx audit] 当前模式不接受这些选项。请查阅 bugx audit --help。", file=sys.stderr)
632
+ return 2
632
633
  return _command_audit_graph(args)
@@ -145,10 +145,10 @@ def confirm_data_sharing(args: argparse.Namespace) -> bool:
145
145
  # ``sharing_revoked()``),所以非交互时**不落盘**、按默认允许处理。
146
146
  return True
147
147
  try:
148
- answer = input("允许 BugX 上传脱敏后的攻防数据用于改进平台?[y/N] ").strip().lower()
148
+ answer = input("允许 BugX 上传脱敏后的攻防数据用于改进平台?[Y/n] ").strip().lower()
149
149
  except (EOFError, OSError):
150
- answer = "n"
151
- allowed = answer in {"y", "yes"}
150
+ answer = ""
151
+ allowed = answer not in {"n", "no"}
152
152
  _save_data_sharing(allowed)
153
153
  return allowed
154
154
 
@@ -158,7 +158,7 @@ def command_telemetry(args: argparse.Namespace) -> int:
158
158
  try:
159
159
  _ensure_core_importable()
160
160
  from core.cloud_sync.flywheel_client import FlywheelUploader
161
- uploader = FlywheelUploader(data_sharing=True)
161
+ uploader = FlywheelUploader()
162
162
  action = getattr(args, "telemetry_command", "inspect")
163
163
  if action == "inspect":
164
164
  result = uploader.inspect(latest=bool(getattr(args, "latest", False)))
@@ -169,10 +169,14 @@ def command_telemetry(args: argparse.Namespace) -> int:
169
169
  print(json.dumps(entry, ensure_ascii=False))
170
170
  return 0
171
171
  if action in {"flush", "upload"}:
172
+ if not uploader.data_sharing:
173
+ print("[telemetry] 遥测已关闭,未执行网络上传。")
174
+ return 0
172
175
  batch_size = int(getattr(args, "batch_size", 20) or 20)
173
176
  flushed = uploader.flush(batch_size=batch_size)
174
177
  sent = flushed.get("sent", flushed) if isinstance(flushed, dict) else flushed
175
- print(f"[telemetry] 已推送并清空本地 Outbox:{sent} 条事件")
178
+ remaining = flushed.get("remaining", "unknown") if isinstance(flushed, dict) else "unknown"
179
+ print(f"[telemetry] 本次推送:{sent} 条事件;本地 Outbox 剩余:{remaining}")
176
180
  return 0
177
181
  output = uploader.export_bundle(
178
182
  getattr(args, "out"),
@@ -198,7 +202,7 @@ def command_telemetry_config(args: argparse.Namespace) -> int:
198
202
  if not enabled:
199
203
  _ensure_core_importable()
200
204
  from core.cloud_sync.flywheel_client import FlywheelUploader
201
- cleared = FlywheelUploader(data_sharing=True).clear_outbox()
205
+ cleared = FlywheelUploader().clear_outbox()
202
206
  print(f"[config] telemetry.data_sharing=false;已清空 {cleared} 条飞轮记录")
203
207
  print("[config] 云端同步已停用:撤销态下 sync_layers/auto_sync 拒绝所有 push/pull")
204
208
  else:
@@ -346,6 +350,21 @@ def command_cloud(args: argparse.Namespace) -> int:
346
350
  print(message)
347
351
  return 0
348
352
 
353
+ scope = None
354
+ if act == "sync":
355
+ scope = getattr(args, "sync_scope", None)
356
+ if scope is None:
357
+ try:
358
+ from core.cloud_sync.cloud_client import load_cloud_config
359
+
360
+ scope = load_cloud_config().get("sync_scope_default", "project")
361
+ except (OSError, TypeError, ValueError, CliError) as exc:
362
+ print(f"[cloud] 无法读取同步范围:{exc}", file=sys.stderr)
363
+ return 2
364
+ if scope not in ("project", "global", "all"):
365
+ print("[cloud] 同步范围无效,请使用 --scope project、global 或 all。", file=sys.stderr)
366
+ return 2
367
+
349
368
  try:
350
369
  client = CloudClient()
351
370
  except ValueError as exc:
@@ -1195,17 +1214,7 @@ def command_cloud(args: argparse.Namespace) -> int:
1195
1214
  return 2
1196
1215
 
1197
1216
  if act == "sync":
1198
- # DOC-211:--scope 缺省时读用户级 sync_scope_default(默认 all);
1199
- # onboard-on(:1216)刻意传显式 "all",不受配置收窄。
1200
- try:
1201
- from core.cloud_sync.cloud_client import load_cloud_config
1202
- sync_default_scope = load_cloud_config().get("sync_scope_default") or "all"
1203
- except Exception: # noqa: BLE001
1204
- sync_default_scope = "all"
1205
- if getattr(args, "sync_scope", None) is None and sync_default_scope != "all":
1206
- print(f"[cloud] sync_scope_default={sync_default_scope}(配置生效;显式 --scope 可覆盖)")
1207
- return _cloud_sync_command(args, client, root, get_device_id,
1208
- default_scope=sync_default_scope)
1217
+ return _cloud_sync_command(args, client, root, get_device_id, scope=scope)
1209
1218
 
1210
1219
  if act == "projects":
1211
1220
  sub = getattr(args, "cloud_project_action", "list")
@@ -1290,10 +1299,9 @@ def command_cloud(args: argparse.Namespace) -> int:
1290
1299
  print("[cloud] 已开启云端同步,立即同步 global + project…")
1291
1300
  sync_args = argparse.Namespace(
1292
1301
  project_slug=args.project_slug,
1293
- sync_scope="all",
1294
1302
  detail_mode=None,
1295
1303
  )
1296
- return _cloud_sync_command(sync_args, client, root, get_device_id)
1304
+ return _cloud_sync_command(sync_args, client, root, get_device_id, scope="all")
1297
1305
 
1298
1306
  return 2
1299
1307
 
@@ -446,18 +446,17 @@ def _cloud_project_slug(root: Path, requested: str | None = None) -> str:
446
446
 
447
447
 
448
448
  def _cloud_sync_command(args: argparse.Namespace, client: Any, root: Path,
449
- get_device_id, *, default_scope: str = "all") -> int:
449
+ get_device_id, *, scope: str) -> int:
450
450
  """执行一次确定性的云端同步,不把同步流程交给宿主 AI 编排。
451
451
 
452
452
  ``cloud sync`` 和 ``cloud onboard on`` 共用这条路径,保证登录、设备登记、
453
- 401 重授权、项目绑定、scope 收敛以及 onboarding 状态落地完全一致。显式
454
- 同步默认覆盖 global + project;调用方仍可用 ``--scope`` 缩小范围。
453
+ 401 重授权、项目绑定、scope 收敛以及 onboarding 状态落地完全一致。
454
+ 调用方在进入流程前必须确定同步范围。
455
455
  """
456
456
  from .agent import _CliProgress
457
457
 
458
458
  progress = _CliProgress(args)
459
459
  progress.update(0, "准备云端同步")
460
- scope = getattr(args, "sync_scope", None) or default_scope
461
460
  onboard_project = scope in {"project", "all"}
462
461
  onboarding = None
463
462
  if onboard_project:
@@ -294,7 +294,7 @@ def _remove_owned_record(
294
294
  backup_dir: Path | None = None,
295
295
  force: bool = False,
296
296
  ) -> None:
297
- """Remove a file only when its current bytes match BugX's recorded bytes (or force=True)."""
297
+ """Remove only recorded files unless the caller enables forced cleanup."""
298
298
  if not isinstance(record, dict):
299
299
  return
300
300
  relative = record.get("path")
@@ -377,7 +377,7 @@ def _sweep_unrecorded_host_entry(
377
377
  项目卸载的语义是"任何受支持的 IDE 进来都像新项目"。对 hosts.json
378
378
  没有记录的宿主(旧版本安装或登记丢失),入口文件内容与当前模板渲染
379
379
  逐字一致才认定为 BugX 自有并删除;有出入一律保留并报告,不冒充归属。
380
- 若 force=True,则对已识别的目标进行强制备份并删除。
380
+ 启用 `--force` 后,才对已识别但内容已变化的目标进行强制备份并删除。
381
381
  """
382
382
  if adapter.name not in _SWEEPABLE_SKILL_ADAPTERS:
383
383
  return
@@ -2281,7 +2281,7 @@ def _remove_dsh_project_files(
2281
2281
  - 有记录但内容已被用户修改:保留文件并记入 preserved,不强行覆盖/删除;
2282
2282
  - 无记录:没有所有权证明,保留文件并记入 preserved;调用方若要清理必须
2283
2283
  先提供当前安装记录,禁止按文件名猜测归属。
2284
- - force=True:强制清理已备份的文件。
2284
+ - `--force`:强制清理已备份的文件。
2285
2285
  """
2286
2286
  if not records and not force:
2287
2287
  for candidate in (
@@ -249,7 +249,7 @@ _DEFAULT_CLAUDE_SKILL_CONTENT = """---
249
249
  name: bugx
250
250
  description: 专注于代码质量与安全的自主审查智能体。专为深层缺陷排查而生——在功能写完、提 PR 或排查疑难 Bug 时,它能深入分析代码逻辑,自动编写测试用例,挖掘、复现Bug和漏洞,生成经过验证的修复补丁。随时为您的代码质量和代码安全把关。
251
251
  metadata:
252
- bugx_version: "0.1.1"
252
+ bugx_version: "0.1.2"
253
253
  ---
254
254
  <!-- bugx-locale: zh-CN -->
255
255
 
@@ -257,7 +257,7 @@ metadata:
257
257
 
258
258
  BugX Claude Skill 镜像。执行前用 `bugx engine path --name AGENT_GUIDE.md` 和 `bugx engine path --name bugx.md` 读取全局协议;项目 `.bugx/` 只保存状态与配置。
259
259
 
260
- 协议镜像版本:0.1.1
260
+ 协议镜像版本:0.1.2
261
261
 
262
262
  ## Claude 原生交互适配(强制)
263
263
 
@@ -129,19 +129,12 @@ def command_project(args: argparse.Namespace) -> int:
129
129
  cached = None
130
130
 
131
131
  if cached is None:
132
- # 就地自愈:画像未持久化时自动执行首次全景分析并持久化,开箱即用直接展示
133
- try:
134
- print(f"[bugx project] 首次运行,正在自动分析并生成项目画像...", file=sys.stderr)
135
- cached = project_profile.detect_project_profile(root)
136
- cached = project_profile.save_project_profile(
137
- ledger_path, cached, producer_version=__version__,
138
- )
139
- except Exception as exc:
140
- if as_json:
141
- print(json.dumps({"status": "not_found", "message": f"未找到本地画像且自动生成失败: {exc}"}, ensure_ascii=False, indent=2))
142
- else:
143
- print(f"[bugx project] ✗ 自动生成项目画像失败: {exc}")
144
- return 1
132
+ message = "当前项目没有可读取的缓存画像。请先运行 bugx project analyze。"
133
+ if as_json:
134
+ print(json.dumps({"status": "not_found", "message": message}, ensure_ascii=False))
135
+ else:
136
+ print(f"[bugx project] ✗ {message}", file=sys.stderr)
137
+ return 1
145
138
 
146
139
  profile = cached
147
140