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
@@ -9,6 +9,7 @@ import os
9
9
  import re
10
10
  import shutil
11
11
  import stat
12
+ import struct
12
13
  import subprocess
13
14
  import sys
14
15
  import tempfile
@@ -282,17 +283,17 @@ def _warn_engine_version_drift(
282
283
  if replaced is True:
283
284
  remedy = (
284
285
  "本次安装已把共享引擎回退到该 CLI 自带的版本,可能影响依赖新引擎的其他项目;"
285
- "请升级 CLI 后重跑(例如 'uv tool install --reinstall bugx-agent')。"
286
+ "请升级 CLI 后重跑(例如 'uv tool install --reinstall bugx-cli')。"
286
287
  )
287
288
  elif replaced is False:
288
289
  remedy = (
289
290
  "已跳过引擎替换以避免回退所有项目共享的引擎;"
290
- "请升级 CLI 后重跑(例如 'uv tool install --reinstall bugx-agent'),"
291
+ "请升级 CLI 后重跑(例如 'uv tool install --reinstall bugx-cli'),"
291
292
  "确需回退请追加 '--force'。"
292
293
  )
293
294
  else:
294
295
  remedy = (
295
- "请升级 CLI 后重跑(例如 'uv tool install --reinstall bugx-agent');"
296
+ "请升级 CLI 后重跑(例如 'uv tool install --reinstall bugx-cli');"
296
297
  "确需回退请追加 '--force'。"
297
298
  )
298
299
  else:
@@ -1505,7 +1506,7 @@ def _command_agent_impl(
1505
1506
  print(f" Claude Desktop 独立安装包:已生成 bugx.plugin 与 bugx.skill({packages_res['dist']})")
1506
1507
  plugins_res = claude_user_agents.get("plugins")
1507
1508
  if isinstance(plugins_res, dict) and plugins_res.get("registered"):
1508
- print(f" Claude Desktop 插件系统:已就绪并启用 bugx@bugx(版本 1.0.0)")
1509
+ print(f" Claude Desktop 插件系统:已就绪并启用 bugx@bugx(版本 {__version__})")
1509
1510
  if (qoder_user_agents := user_agents_by_host.get(HOST_NAME_QODER)) is not None:
1510
1511
  reported_user_agents.add(HOST_NAME_QODER)
1511
1512
  changed = [
@@ -1940,7 +1941,7 @@ def _ensure_dsh_patch(root: Path) -> tuple[str, dict[str, object] | None]:
1940
1941
  # MCP」——修好调用却报告缺失,是更难排查的破窗。
1941
1942
  if patch_path.is_file():
1942
1943
  project_patch = patch_path.read_text(encoding="utf-8")
1943
- with_overlay = _ensure_official_mcp_overlay(project_patch)
1944
+ with_overlay = _ensure_official_mcp_overlay(project_patch, root)
1944
1945
  if with_overlay != project_patch:
1945
1946
  _atomic_write_global_file_tx(patch_path, with_overlay.encode("utf-8"))
1946
1947
  patched = True
@@ -1948,7 +1949,7 @@ def _ensure_dsh_patch(root: Path) -> tuple[str, dict[str, object] | None]:
1948
1949
  # Deploy BugX's agent preset and the browser UI bundle to their native
1949
1950
  # DSH user-level locations.
1950
1951
  try:
1951
- _deploy_dsh_preset()
1952
+ _deploy_dsh_preset(root)
1952
1953
  ui_plugin = _deploy_dsh_ui_plugin()
1953
1954
  except (CliError, OSError) as exc:
1954
1955
  raise CliError(_i18n_exc("agent.dsh_preset_write_failed", f"写入 dsh 全局预设失败:{exc}", exc=exc)) from exc
@@ -1958,7 +1959,7 @@ def _ensure_dsh_patch(root: Path) -> tuple[str, dict[str, object] | None]:
1958
1959
  return ("unchanged", ui_plugin)
1959
1960
 
1960
1961
 
1961
- def _deploy_dsh_preset() -> None:
1962
+ def _deploy_dsh_preset(root: Path) -> None:
1962
1963
  """Deploy the BugX preset cleanly to ~/.dsh/.agent-presets/bugx/.
1963
1964
 
1964
1965
  Reads the installed standard preset, replaces the persona text with BugX's
@@ -1973,62 +1974,31 @@ def _deploy_dsh_preset() -> None:
1973
1974
  standard_preset = next((p for p in candidates if p.is_file()), None)
1974
1975
 
1975
1976
  composition_path = preset_dir / "agent.cordis.yml"
1977
+ # F-RSI-20261119-011/013/014:插件名与行集合都必须跟随**每个 dsh home
1978
+ # 实际使用的运行时**。CLI dsh 0.1.1-rc.2 只有 worker-thread;DSH Desktop
1979
+ # 0.14+ 随 app.asar 内置 dsh 0.2.2(只认 workflow-ptc,且启动校验会把
1980
+ # worker-thread 判为 blocking 错误)。desktop home 直接使用 Desktop 自带
1981
+ # 的官方 standard preset 模板(dsh-web-app/presets/standard.patch.yml),
1982
+ # CLI home 继续用 CLI dsh 包内模板——两侧都与其运行时自洽。
1976
1983
  if standard_preset and standard_preset.is_file():
1977
1984
  lines = standard_preset.read_text(encoding="utf-8").splitlines()
1978
- out_lines = []
1979
- i = 0
1980
- while i < len(lines):
1981
- line = lines[i]
1982
- if line.strip() == "- id: persona":
1983
- # Emit a single persona entry with the BugX persona text.
1984
- out_lines.append("- id: persona")
1985
- out_lines.append(" name: '@deepseek-ai/dsh-persona'")
1986
- out_lines.append(" config:")
1987
- out_lines.append(" prefix: >-")
1988
- out_lines.append(" You are BugX, an autonomous adversarial code-audit agent. Before")
1989
- out_lines.append(" any exploration, first run bugx engine path --name bugx-quick.md (the L0 protocol card), then consult the global AGENT_GUIDE.md and bugx.md sections on demand, and")
1990
- out_lines.append(" follow the life-ledger, supervisor lease, evidence and report protocol. The DSH package checkout and DSH_HOME are not the project root; use the active Session cwd for every project path and run pwd when paths are ambiguous.")
1991
- # Skip every remaining line of the original persona entry.
1992
- i += 1
1993
- while i < len(lines) and not lines[i].strip().startswith("- id:"):
1994
- i += 1
1995
- continue
1996
- if line.strip() == "- id: workflow-worker-thread":
1997
- indent = len(line) - len(line.lstrip())
1998
- line = (" " * indent) + "- id: workflow-ptc"
1999
- elif "@deepseek-ai/dsh-workflow-worker-thread" in line:
2000
- indent = len(line) - len(line.lstrip())
2001
- line = (" " * indent) + "name: '@deepseek-ai/dsh-workflow-ptc'"
2002
- out_lines.append(line)
2003
- i += 1
1985
+ out_lines = _apply_bugx_persona(lines)
2004
1986
  else:
2005
1987
  # Fallback: minimal viable preset composition when the installed dsh
2006
1988
  # standard template is not discoverable (e.g. isolated test HOME).
2007
- out_lines = [
1989
+ out_lines = _apply_bugx_persona([
2008
1990
  "# BugX minimal preset composition (fallback).",
2009
1991
  "- id: persona",
2010
1992
  " name: '@deepseek-ai/dsh-persona'",
2011
1993
  " config:",
2012
- " prefix: >-",
2013
- " You are BugX, an autonomous adversarial code-audit agent. Before",
2014
- " any exploration, first run bugx engine path --name bugx-quick.md (L0 card), then consult the global AGENT_GUIDE.md and bugx.md sections on demand,",
2015
- " and follow the life-ledger, supervisor lease, evidence protocol. The DSH package checkout and DSH_HOME are not the project root; use the active Session cwd for every project path and run pwd when paths are ambiguous.",
1994
+ " prefix: placeholder",
2016
1995
  "- id: skill-filesystem",
2017
1996
  " name: '@deepseek-ai/dsh-skill-filesystem'",
2018
- ]
1997
+ ])
2019
1998
 
2020
1999
  # Native DSH questions are an agent capability, not merely a skill
2021
- # instruction. Older standard presets and the isolated fallback may not
2022
- # include the model-facing tool, so make the registration idempotently
2023
- # explicit. The Web/TUI answerer remains host-owned and is not mounted
2024
- # into the agent preset.
2025
- if "@deepseek-ai/dsh-tool-ask-user" not in "\n".join(out_lines):
2026
- out_lines.extend([
2027
- "",
2028
- "# ── BugX native question interaction ───────────────────────────────────",
2029
- "- id: tool-ask-user",
2030
- " name: '@deepseek-ai/dsh-tool-ask-user'",
2031
- ])
2000
+ # instruction; the check below runs on the final per-home composition
2001
+ # inside the write loop (Desktop's official template already carries it).
2032
2002
 
2033
2003
  # 预设层**不再**注入 MCP client。三条通道(supervisor / supervisor-worker /
2034
2004
  # docs)由 ``core/hosts/dsh.py::_mcp_insert_block`` 以官方
@@ -2049,9 +2019,31 @@ def _deploy_dsh_preset() -> None:
2049
2019
  "适合在项目提测发版前、安全合规体检或排查疑难缺陷时开启;日常开发与普通交流不打扰。"
2050
2020
  )
2051
2021
  preset_order = 0
2052
- composition_text = "\n".join(out_lines) + "\n"
2053
2022
 
2054
2023
  for home in _all_dsh_homes():
2024
+ preset_plugin, workflow_plugin = _dsh_runtime_plugin_names(home)
2025
+ if "dsh-desktop" in home.parts:
2026
+ # F-RSI-20261119-014:desktop home 使用 Desktop 自带的官方
2027
+ # standard preset 模板——CLI 0.1.1 模板里的 0.1.x 专属行
2028
+ # (tool-ralph、tool-subagent-codex/claude-code/list-agents)在
2029
+ # 0.2.x 官方 preset 中已被移除,其激活在 0.2.x 运行时上会失败,
2030
+ # registry 据此把整个 preset 判为 broken(UI 显示「加载失败」)。
2031
+ desktop_template = _dsh_desktop_standard_template()
2032
+ base_lines = (
2033
+ _apply_bugx_persona(_dsh_desktop_preset_rows(desktop_template))
2034
+ if desktop_template else out_lines
2035
+ )
2036
+ else:
2037
+ base_lines = out_lines
2038
+ composition_lines = _rewrite_dsh_workflow_plugin(base_lines, workflow_plugin)
2039
+ if "@deepseek-ai/dsh-tool-ask-user" not in "\n".join(composition_lines):
2040
+ composition_lines.extend([
2041
+ "",
2042
+ "# ── BugX native question interaction ───────────────────────────────────",
2043
+ "- id: tool-ask-user",
2044
+ " name: '@deepseek-ai/dsh-tool-ask-user'",
2045
+ ])
2046
+ composition_text = "\n".join(composition_lines) + "\n"
2055
2047
  p_dir = home / ".agent-presets" / "bugx"
2056
2048
  _assert_no_symlink_components(p_dir)
2057
2049
  p_dir.mkdir(parents=True, exist_ok=True)
@@ -2074,15 +2066,248 @@ def _deploy_dsh_preset() -> None:
2074
2066
  name=preset_name,
2075
2067
  description=preset_desc.replace("\n", " "),
2076
2068
  order=preset_order,
2069
+ preset_plugin_name=preset_plugin,
2070
+ root=root,
2077
2071
  )
2078
2072
 
2079
2073
 
2074
+ _DSH_LEGACY_WORKFLOW_PLUGIN = "@deepseek-ai/dsh-workflow-worker-thread"
2075
+ _DSH_PTC_WORKFLOW_PLUGIN = "@deepseek-ai/dsh-workflow-ptc"
2076
+
2077
+
2078
+ def _dsh_desktop_asar_candidates() -> list[Path]:
2079
+ """Return DSH Desktop ``app.asar`` paths that may carry the bundled runtime."""
2080
+ resources = Path("Contents", "Resources", "app.asar")
2081
+ return [
2082
+ Path.home().resolve() / "Applications" / "DSH Desktop.app" / resources,
2083
+ Path("/Applications") / "DSH Desktop.app" / resources,
2084
+ ]
2085
+
2086
+
2087
+ def _asar_lists_bundled_package(asar: Path, package: str) -> bool:
2088
+ """Check an Electron ``app.asar`` header for ``node_modules/@deepseek-ai/<package>``.
2089
+
2090
+ DSH Desktop bundles its entire dsh runtime inside app.asar instead of the
2091
+ harness profile, so probing the profile's node_modules tells us what the
2092
+ *CLI* installed there, not what the Desktop runtime resolves at launch.
2093
+ Only the asar header is read; file payloads are never touched.
2094
+ """
2095
+ try:
2096
+ with asar.open("rb") as handle:
2097
+ head = handle.read(8)
2098
+ if len(head) < 8:
2099
+ return False
2100
+ header_size = struct.unpack("<I", head[4:8])[0]
2101
+ if header_size <= 0 or header_size > 64 * 1024 * 1024:
2102
+ return False
2103
+ header = handle.read(header_size)
2104
+ except OSError:
2105
+ return False
2106
+ # The asar header is a nested file tree, so the package path never appears
2107
+ # as one contiguous byte string; parse the JSON and walk the "files" maps.
2108
+ start = header.find(b'{"files":')
2109
+ if start < 0:
2110
+ return False
2111
+ try:
2112
+ tree, _ = json.JSONDecoder().raw_decode(
2113
+ header[start:].decode("utf-8", "ignore"),
2114
+ )
2115
+ except (UnicodeDecodeError, json.JSONDecodeError):
2116
+ return False
2117
+ node: Any = tree
2118
+ for part in ("files", "node_modules", "files", "@deepseek-ai", "files", package):
2119
+ if not isinstance(node, dict):
2120
+ return False
2121
+ node = node.get(part)
2122
+ return isinstance(node, dict)
2123
+
2124
+
2125
+ def _dsh_desktop_runtime_names() -> tuple[str, str] | None:
2126
+ """Detect the preset/workflow plugin names DSH Desktop's bundled runtime accepts.
2127
+
2128
+ DSH Desktop 0.14 bundles dsh 0.2.2: ``@deepseek-ai/dsh-agent-preset``
2129
+ (singular) and ``@deepseek-ai/dsh-workflow-ptc``. Older Desktop builds
2130
+ bundled the 0.1.x names (plural preset plugin + worker-thread). The
2131
+ bundled app.asar is the only authoritative source for the desktop home.
2132
+ """
2133
+ for asar in _dsh_desktop_asar_candidates():
2134
+ if not asar.is_file():
2135
+ continue
2136
+ if _asar_lists_bundled_package(asar, "dsh-workflow-ptc"):
2137
+ return ("@deepseek-ai/dsh-agent-preset", _DSH_PTC_WORKFLOW_PLUGIN)
2138
+ if _asar_lists_bundled_package(asar, "dsh-workflow-worker-thread"):
2139
+ return ("@deepseek-ai/dsh-agent-presets", _DSH_LEGACY_WORKFLOW_PLUGIN)
2140
+ return None
2141
+
2142
+
2143
+ def _dsh_runtime_plugin_names(home: Path) -> tuple[str, str]:
2144
+ """Return ``(preset_plugin_name, workflow_plugin_name)`` for one dsh home.
2145
+
2146
+ F-RSI-20261119-012/013:包名随 dsh 版本变化——0.1.1-rc.2 是
2147
+ 复数 ``dsh-agent-presets`` + ``dsh-workflow-worker-thread``;0.2.x 是
2148
+ 单数 ``dsh-agent-preset`` + ``dsh-workflow-ptc``。DSH Desktop 的运行时
2149
+ 内置在 app.asar 中,必须先探测 asar;其余 home 以
2150
+ ``profiles/node_modules`` 为准(那是其插件解析根)。
2151
+ """
2152
+ if "dsh-desktop" in home.parts:
2153
+ detected = _dsh_desktop_runtime_names()
2154
+ if detected is not None:
2155
+ return detected
2156
+ base = home / "profiles" / "node_modules" / "@deepseek-ai"
2157
+ if (base / "dsh-agent-preset").is_dir():
2158
+ preset_plugin = "@deepseek-ai/dsh-agent-preset"
2159
+ else:
2160
+ preset_plugin = "@deepseek-ai/dsh-agent-presets"
2161
+ if (base / "dsh-workflow-ptc").is_dir():
2162
+ workflow_plugin = _DSH_PTC_WORKFLOW_PLUGIN
2163
+ else:
2164
+ workflow_plugin = _DSH_LEGACY_WORKFLOW_PLUGIN
2165
+ return preset_plugin, workflow_plugin
2166
+
2167
+
2168
+ def _rewrite_dsh_workflow_plugin(
2169
+ lines: list[str], workflow_plugin: str,
2170
+ ) -> list[str]:
2171
+ """Rewrite the template's worker-thread row to the home's workflow plugin."""
2172
+ if workflow_plugin == _DSH_LEGACY_WORKFLOW_PLUGIN:
2173
+ return list(lines)
2174
+ out: list[str] = []
2175
+ for line in lines:
2176
+ stripped = line.strip()
2177
+ indent = len(line) - len(line.lstrip())
2178
+ if stripped == "- id: workflow-worker-thread":
2179
+ line = (" " * indent) + "- id: workflow-ptc"
2180
+ elif _DSH_LEGACY_WORKFLOW_PLUGIN in line:
2181
+ line = (" " * indent) + f"name: '{_DSH_PTC_WORKFLOW_PLUGIN}'"
2182
+ out.append(line)
2183
+ return out
2184
+
2185
+
2186
+ _BUGX_PERSONA_TEXT = (
2187
+ "You are BugX, an autonomous adversarial code-audit agent. Before any "
2188
+ "exploration, first run bugx engine path --name bugx-quick.md (the L0 "
2189
+ "protocol card), then consult the global AGENT_GUIDE.md and bugx.md "
2190
+ "sections on demand, and follow the life-ledger, supervisor lease, "
2191
+ "evidence and report protocol. The DSH package checkout and DSH_HOME are "
2192
+ "not the project root; use the active Session cwd for every project path "
2193
+ "and run pwd when paths are ambiguous."
2194
+ )
2195
+
2196
+
2197
+ def _persona_block_lines(indent: str) -> list[str]:
2198
+ """One persona entry with the BugX persona text at ``indent`` (may be empty)."""
2199
+ lines = [
2200
+ f"{indent}- id: persona",
2201
+ f"{indent} name: '@deepseek-ai/dsh-persona'",
2202
+ f"{indent} config:",
2203
+ f"{indent} prefix: >-",
2204
+ ]
2205
+ # Folded scalar (>-): line breaks fold into spaces, so wrapping is cosmetic.
2206
+ words = _BUGX_PERSONA_TEXT.split(" ")
2207
+ row: list[str] = []
2208
+ for word in words:
2209
+ row.append(word)
2210
+ if len(" ".join(row)) >= 96:
2211
+ lines.append(f"{indent} {' '.join(row)}")
2212
+ row = []
2213
+ if row:
2214
+ lines.append(f"{indent} {' '.join(row)}")
2215
+ return lines
2216
+
2217
+
2218
+ def _apply_bugx_persona(lines: list[str]) -> list[str]:
2219
+ """Replace the template's persona entry with BugX's, preserving indentation."""
2220
+ out: list[str] = []
2221
+ i = 0
2222
+ while i < len(lines):
2223
+ line = lines[i]
2224
+ if line.strip() == "- id: persona":
2225
+ indent = " " * (len(line) - len(line.lstrip()))
2226
+ out.extend(_persona_block_lines(indent))
2227
+ # Skip every remaining line of the original persona entry.
2228
+ i += 1
2229
+ while i < len(lines) and not lines[i].strip().startswith("- id:"):
2230
+ i += 1
2231
+ continue
2232
+ out.append(line)
2233
+ i += 1
2234
+ return out
2235
+
2236
+
2237
+ def _asar_read_text(asar: Path, member: str) -> str | None:
2238
+ """Read one UTF-8 file out of an Electron ``app.asar`` by archive path."""
2239
+ try:
2240
+ with asar.open("rb") as handle:
2241
+ head = handle.read(8)
2242
+ if len(head) < 8:
2243
+ return None
2244
+ header_size = struct.unpack("<I", head[4:8])[0]
2245
+ if header_size <= 0 or header_size > 64 * 1024 * 1024:
2246
+ return None
2247
+ header = handle.read(header_size)
2248
+ start = header.find(b'{"files":')
2249
+ if start < 0:
2250
+ return None
2251
+ tree, _ = json.JSONDecoder().raw_decode(
2252
+ header[start:].decode("utf-8", "ignore"),
2253
+ )
2254
+ node: Any = tree
2255
+ for part in member.split("/"):
2256
+ if not isinstance(node, dict):
2257
+ return None
2258
+ node = node.get("files", {}).get(part) if "files" in node else node.get(part)
2259
+ if node is None:
2260
+ return None
2261
+ if not isinstance(node, dict) or "offset" not in node:
2262
+ return None
2263
+ handle.seek(int(node["offset"]) + 8 + header_size)
2264
+ return handle.read(int(node["size"])).decode("utf-8")
2265
+ except (OSError, UnicodeDecodeError, json.JSONDecodeError):
2266
+ return None
2267
+
2268
+
2269
+ _DSH_DESKTOP_STANDARD_PRESET_MEMBER = (
2270
+ "node_modules/@deepseek-ai/dsh-web-app/presets/standard.patch.yml"
2271
+ )
2272
+
2273
+
2274
+ def _dsh_desktop_standard_template() -> str | None:
2275
+ """DSH Desktop 自带的官方 standard preset 组态(0.2.x 行集合)。
2276
+
2277
+ F-RSI-20261119-014:desktop home 的 preset 行集合必须与其内置运行时
2278
+ 同代。CLI dsh 包内模板是 0.1.x 行集合(tool-ralph 等),在 0.2.x 上
2279
+ 激活失败会让 registry 把 preset 判 broken;Desktop 随包分发的
2280
+ ``dsh-web-app/presets/standard.patch.yml`` 是唯一与其运行时自洽的
2281
+ 官方行集合来源。旧版 Desktop 没有该文件时返回 None(回退 CLI 模板)。
2282
+ """
2283
+ for asar in _dsh_desktop_asar_candidates():
2284
+ if not asar.is_file():
2285
+ continue
2286
+ text = _asar_read_text(asar, _DSH_DESKTOP_STANDARD_PRESET_MEMBER)
2287
+ if text:
2288
+ return text
2289
+ return None
2290
+
2291
+
2292
+ def _dsh_desktop_preset_rows(template_text: str) -> list[str]:
2293
+ """Extract the plugin rows under the official template's ``plugins:`` key."""
2294
+ lines = template_text.splitlines()
2295
+ for idx, line in enumerate(lines):
2296
+ if line.strip() == "plugins:":
2297
+ rows = lines[idx + 1:]
2298
+ while rows and not rows[-1].strip():
2299
+ rows.pop()
2300
+ return rows
2301
+ return []
2302
+
2303
+
2080
2304
  def _format_dsh_preset_patch(
2081
2305
  preset_id: str,
2082
2306
  composition_text: str,
2083
2307
  name: str,
2084
2308
  description: str,
2085
2309
  order: int = 0,
2310
+ preset_plugin_name: str = "@deepseek-ai/dsh-agent-presets",
2086
2311
  ) -> str:
2087
2312
  """Format an agent-preset patch block for DSH profile cordis.patch.yml."""
2088
2313
  fields = [f" id: {preset_id}"]
@@ -2092,13 +2317,15 @@ def _format_dsh_preset_patch(
2092
2317
  fields.append(f" order: {order}")
2093
2318
 
2094
2319
  rows = []
2095
- for line in composition_text.strip().splitlines():
2320
+ # rstrip(而非 strip):desktop 官方模板的组态首行自带缩进,strip 会把
2321
+ # 首行缩进剥掉,产出错位的 patch 块(YAML 解析失败 → preset broken)。
2322
+ for line in composition_text.rstrip("\n").splitlines():
2096
2323
  rows.append(f" {line}" if line.strip() else "")
2097
2324
 
2098
2325
  header = (
2099
2326
  f"- insert:\n"
2100
2327
  f" - id: preset-{preset_id}\n"
2101
- f" name: '@deepseek-ai/dsh-agent-preset'\n"
2328
+ f" name: '{preset_plugin_name}'\n"
2102
2329
  f" config:"
2103
2330
  )
2104
2331
  return (
@@ -2116,17 +2343,40 @@ def _sync_dsh_profile_patch(
2116
2343
  name: str,
2117
2344
  description: str,
2118
2345
  order: int = 0,
2346
+ preset_plugin_name: str = "@deepseek-ai/dsh-agent-presets",
2347
+ root: Path | None = None,
2119
2348
  ) -> None:
2120
- """Ensure profiles/web/cordis.patch.yml carries the latest preset patch block."""
2121
- profile_dir = home / "profiles" / "web"
2122
- if not profile_dir.is_dir():
2123
- return
2349
+ """Ensure profiles/{web,desktop}/cordis.patch.yml carry the latest preset block.
2350
+
2351
+ F-RSI-20261119-012:DSH Desktop 的会话实际读 ``profiles/desktop`` 的
2352
+ legacy preset 块;此前只同步 ``profiles/web``,导致 desktop 侧残留旧
2353
+ preset(错误插件名)并使「自定义 agent 加载失败」。
2354
+ """
2355
+ patch_block = _format_dsh_preset_patch(
2356
+ preset_id, composition_text, name, description, order,
2357
+ preset_plugin_name=preset_plugin_name,
2358
+ )
2359
+ for profile_name in ("web", "desktop"):
2360
+ profile_dir = home / "profiles" / profile_name
2361
+ if not profile_dir.is_dir():
2362
+ continue
2363
+ _sync_one_profile_patch(
2364
+ profile_dir, profile_name, preset_id, patch_block, root=root,
2365
+ )
2366
+
2367
+
2368
+ def _sync_one_profile_patch(
2369
+ profile_dir: Path,
2370
+ profile_name: str,
2371
+ preset_id: str,
2372
+ patch_block: str,
2373
+ root: Path | None = None,
2374
+ ) -> None:
2375
+ """把 preset 块写入/替换到单个 profile 的 cordis.patch.yml。"""
2124
2376
  patch_path = profile_dir / "cordis.patch.yml"
2125
2377
  _assert_no_symlink_components(patch_path)
2126
- patch_block = _format_dsh_preset_patch(preset_id, composition_text, name, description, order)
2127
-
2128
2378
  if not patch_path.is_file():
2129
- content = f"# Web profile user patch layer\n\n{patch_block}\n"
2379
+ content = f"# {profile_name.capitalize()} profile user patch layer\n\n{patch_block}\n"
2130
2380
  _atomic_write_global_file_tx(patch_path, content.encode("utf-8"))
2131
2381
  return
2132
2382
 
@@ -2150,7 +2400,9 @@ def _sync_dsh_profile_patch(
2150
2400
  else:
2151
2401
  updated = f"{content.rstrip()}\n\n{patch_block}\n"
2152
2402
 
2153
- updated = _ensure_official_mcp_overlay(updated)
2403
+ if root is None:
2404
+ raise CliError("_sync_one_profile_patch 需要 root 以绝对化 MCP --root/--db(F-RSI-20261119-015)")
2405
+ updated = _ensure_official_mcp_overlay(updated, root)
2154
2406
 
2155
2407
  if updated != content:
2156
2408
  _atomic_write_global_file_tx(patch_path, updated.encode("utf-8"))
@@ -2160,17 +2412,28 @@ def _sync_dsh_profile_patch(
2160
2412
  _OFFICIAL_MCP_CLIENT = "@deepseek-ai/dsh-mcp-client"
2161
2413
  #: 三条受控通道;serverName 必须唯一,且与 core/hosts/dsh.py 的声明一致。
2162
2414
  _OFFICIAL_MCP_SERVERS = (
2163
- ("bugx-supervisor", ["mcp", "serve", "--root", "."]),
2164
- ("bugx-supervisor-worker", ["mcp", "serve", "--root", ".", "--role", "worker"]),
2165
- ("bugx-docs", ["mcp", "docs", "serve", "--root", ".", "--db",
2166
- ".bugx/knowledge/docs.sqlite3"]),
2415
+ # F-RSI-20261119-015:与 core/hosts/dsh.py::_MCP_SERVERS 同一契约——
2416
+ # dsh 的 MCP server 由宿主进程 spawn,cwd 不是工作区,``--root .`` 会解析
2417
+ # 到宿主自己的 cwd(实测报「缺少有效的 .bugx 项目运行布局」)。因此这里
2418
+ # 与 install 侧一样使用 {ROOT} 占位,由 overlay 以**绝对项目根**替换。
2419
+ # 修改任一侧时必须同步另一侧,两处常量必须逐字一致。
2420
+ ("bugx-supervisor", ["mcp", "serve", "--root", "{ROOT}"]),
2421
+ ("bugx-supervisor-worker", ["mcp", "serve", "--root", "{ROOT}", "--role", "worker"]),
2422
+ ("bugx-docs", ["mcp", "docs", "serve", "--root", "{ROOT}", "--db",
2423
+ "{ROOT}/.bugx/knowledge/docs.sqlite3"]),
2167
2424
  )
2168
2425
  _OFFICIAL_MCP_MARKER = "# BugX MCP overlay — official dsh-mcp-client (stdio)"
2169
2426
 
2170
2427
 
2171
- def _ensure_official_mcp_overlay(content: str) -> str:
2428
+ def _ensure_official_mcp_overlay(content: str, root: Path) -> str:
2172
2429
  """向 profile patch 追加/更新官方 MCP 三通道 ``- insert:`` 块。
2173
2430
 
2431
+ ``root`` 是安装时项目根:``--root``/``--db`` 必须随根绝对化(契约见
2432
+ core/hosts/dsh.py::_MCP_SERVERS 注释——宿主进程 spawn 的 MCP server cwd
2433
+ 不是工作区,相对路径会解析到宿主 cwd)。此前这里写死 ``--root .``,与
2434
+ install 侧的绝对根互相覆盖:install 写对、deploy 又改回相对路径,两条
2435
+ 路径产物永不相等(F-RSI-20261119-015)。
2436
+
2174
2437
  为什么必须由 install 自己写:``bugx install --agent dsh`` 之后
2175
2438
  ``bugx doctor`` 的「DeepSeek Harness MCP 配置」会扫项目 patch 与全局预设,
2176
2439
  确认 supervisor 通道存在。此前这份内容由预设层的第三方
@@ -2180,6 +2443,7 @@ def _ensure_official_mcp_overlay(content: str) -> str:
2180
2443
  不再承载 MCP,若 install 也不写,doctor 就会判定「缺少 bugx-supervisor
2181
2444
  MCP」,形成「修好调用却报告缺失」的新破窗。
2182
2445
  """
2446
+ root_text = str(Path(root).resolve())
2183
2447
  lines = [_OFFICIAL_MCP_MARKER, "- insert:"]
2184
2448
  for server_name, argv in _OFFICIAL_MCP_SERVERS:
2185
2449
  lines.extend([
@@ -2191,7 +2455,9 @@ def _ensure_official_mcp_overlay(content: str) -> str:
2191
2455
  " command: bugx",
2192
2456
  " args:",
2193
2457
  ])
2194
- lines.extend(f" - '{arg}'" for arg in argv)
2458
+ lines.extend(
2459
+ f" - '{arg.replace('{ROOT}', root_text)}'" for arg in argv
2460
+ )
2195
2461
  block = "\n".join(lines) + "\n"
2196
2462
 
2197
2463
  # 归一算法(2026-11-08 实测重写,两次迭代):按**条目 id** 识别受控块,
@@ -2539,8 +2805,8 @@ def _unlink_global_pi_skill(root: Path, removed: list[str], preserved: list[str]
2539
2805
  def _sync_workbuddy_private_venv(
2540
2806
  source: Path, *, target_version: str | None = None,
2541
2807
  ) -> tuple[bool, str]:
2542
- """探测并同步 WorkBuddy 私有 Python 虚拟环境中的 bugx-agent 包 (DOC-181)。"""
2543
- from bugx_cli.host_adapters import workbuddy_cli_venv
2808
+ """探测并同步 WorkBuddy 私有 Python 虚拟环境中的 bugx-cli 包 (DOC-181)。"""
2809
+ from ..host_adapters import workbuddy_cli_venv
2544
2810
  venv = workbuddy_cli_venv()
2545
2811
  if not venv:
2546
2812
  return False, "未检测到 WorkBuddy 私有虚拟环境"
@@ -2556,7 +2822,7 @@ def _sync_workbuddy_private_venv(
2556
2822
  if is_source:
2557
2823
  cmd = [str(py_exe), "-m", "pip", "install", "-e", str(source.resolve()), "--no-deps"]
2558
2824
  else:
2559
- pkg = f"bugx-agent=={target_version}" if target_version else "bugx-agent"
2825
+ pkg = f"bugx-cli=={target_version}" if target_version else "bugx-cli"
2560
2826
  cmd = [str(py_exe), "-m", "pip", "install", "--upgrade", pkg, "--no-deps"]
2561
2827
  try:
2562
2828
  proc = subprocess.run(
@@ -2879,7 +3145,7 @@ def _ensure_workbuddy_custom_expert(
2879
3145
  # 3. Plugin manifest
2880
3146
  plugin_meta = {
2881
3147
  "name": "bugx",
2882
- "version": "1.0.0",
3148
+ "version": __version__,
2883
3149
  "expertType": "agent",
2884
3150
  "displayName": {
2885
3151
  "zh": "BugX",
@@ -3500,7 +3766,7 @@ def _check_host_mcp_config(root: Path, host_name: str, *, repair: bool = False)
3500
3766
  return False, "缺少 .agents/plugins/marketplace.json;请运行 bugx install --agent chatgpt"
3501
3767
 
3502
3768
  if host_name == "workbuddy":
3503
- from bugx_cli.host_adapters import WORKBUDDY_PROJECT_PATHS
3769
+ from ..host_adapters import WORKBUDDY_PROJECT_PATHS
3504
3770
 
3505
3771
  missing = [relative for relative in WORKBUDDY_PROJECT_PATHS
3506
3772
  if not (root / relative).is_file()]
@@ -3527,7 +3793,7 @@ def _check_host_mcp_config(root: Path, host_name: str, *, repair: bool = False)
3527
3793
  return False, user_detail
3528
3794
 
3529
3795
  # DOC-181 方案 2:WorkBuddy 沙箱 Python 运行态一致性检查与自愈
3530
- from bugx_cli.host_adapters import workbuddy_cli_venv, workbuddy_cli_venv_version
3796
+ from ..host_adapters import workbuddy_cli_venv, workbuddy_cli_venv_version
3531
3797
  venv = workbuddy_cli_venv()
3532
3798
  venv_detail = ""
3533
3799
  if venv is not None:
@@ -230,7 +230,7 @@ def _command_audit_graph(args: argparse.Namespace) -> int:
230
230
  result: dict[str, object] | None = None
231
231
  exit_code = 1
232
232
  try:
233
- from bugx_cli.infra.security import _find_repo_root
233
+ from ..infra.security import _find_repo_root
234
234
  repo_root = _find_repo_root(Path(__file__))
235
235
  workspace_module, targets_module, orchestrator_module = _engine_modules(repo_root)
236
236
  runtime_root = _private_runtime_root()
@@ -327,7 +327,7 @@ def _command_audit_penetration(args: argparse.Namespace) -> int:
327
327
 
328
328
  try:
329
329
  _ensure_core_importable()
330
- from bugx_cli.infra.security import _find_repo_root
330
+ from ..infra.security import _find_repo_root
331
331
  repo_root = _find_repo_root(Path(__file__))
332
332
  core_root = repo_root / "core"
333
333
  scripts_root = repo_root / "scripts"
@@ -47,7 +47,7 @@ def _estimate_complexity_baseline(root: Path, manifest_path: Path | None = None)
47
47
 
48
48
  def _install_host(root: Path, host: str, *, timeout: float = 180.0) -> dict[str, object]:
49
49
  """Repair the selected host entry before starting the no-prompt run."""
50
- from bugx_cli.infra.security import _find_repo_root
50
+ from ..infra.security import _find_repo_root
51
51
  repo = _find_repo_root(Path(__file__))
52
52
  source_cli = repo / "interfaces" / "cli" / "bugx_cli" / "cli.py"
53
53
  if not source_cli.is_file():
@@ -378,12 +378,13 @@ def command_cloud(args: argparse.Namespace) -> int:
378
378
  if act == "upload":
379
379
  try:
380
380
  bundle = _read_sync_bundle(Path(args.input).expanduser().absolute())
381
- # DOC-211:upload 与 sync 同吃一档敏感策略(配置缺省 allow 透传)。
381
+ # DOC-211:upload 与 sync 同吃一档敏感策略;配置缺失/非法取
382
+ # 安全默认 redact(F-025:原样出网必须显式 allow)。
382
383
  try:
383
384
  from core.cloud_sync.cloud_client import load_cloud_config
384
- upload_policy = load_cloud_config().get("sensitive_policy") or "allow"
385
+ upload_policy = load_cloud_config().get("sensitive_policy") or "redact"
385
386
  except Exception: # noqa: BLE001
386
- upload_policy = "allow"
387
+ upload_policy = "redact"
387
388
  result = client.import_knowledge_bundle(
388
389
  bundle, mode=args.mode, sensitive_policy=upload_policy)
389
390
  except (OSError, ValueError, RuntimeError) as exc: