bugx-cli 0.1.3 → 0.1.5

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 (167) hide show
  1. package/core/README.md +5 -3
  2. package/core/agent/agent_execution.py +7 -0
  3. package/core/assets/bugx-wechat-group.png +0 -0
  4. package/core/bugx.md +2 -2
  5. package/core/bugx_paths.py +10 -2
  6. package/core/bundled_docs/OVERVIEW.md +311 -0
  7. package/core/bundled_docs/README.md +10 -0
  8. package/core/bundled_docs/README_EN.md +278 -0
  9. package/core/bundled_docs/ai/01_AI_REFERENCE.md +838 -0
  10. package/core/bundled_docs/ai/02_AI_USAGE.md +161 -0
  11. package/core/bundled_docs/ai/03_AI_COMMANDS.md +322 -0
  12. package/core/bundled_docs/guides/01_USER_GUIDE.md +887 -0
  13. package/core/bundled_docs/guides/02_COMMANDS.md +935 -0
  14. package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +763 -0
  15. package/core/bundled_docs/guides/04_CLOUD_AUTH_AND_SYNC_COOKBOOK.md +48 -0
  16. package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +25 -0
  17. package/core/bundled_docs/guides/06_PROBES_AND_POC_COOKBOOK.md +49 -0
  18. package/core/bundled_docs/guides/07_LIFECYCLE_AND_RECOVERY_STATES.md +46 -0
  19. package/core/bundled_docs/guides/08_LESSONS_AND_PRIVACY_BOUNDARY.md +35 -0
  20. package/core/bundled_docs/hosts/bugx-claude_SKILL.md +326 -0
  21. package/core/bundled_docs/hosts/bugx-dsh_SKILL.md +229 -0
  22. package/core/bundled_docs/hosts/bugx-opencode_SKILL.md +129 -0
  23. package/core/bundled_docs/hosts/bugx-zcode_SKILL.md +459 -0
  24. package/core/bundled_docs/hosts/bugx_SKILL.md +118 -0
  25. package/core/bundled_docs/hosts/cline_bugx_SKILL.md +69 -0
  26. package/core/bundled_docs/hosts/platform_bugx_SKILL.md +50 -0
  27. package/core/bundled_docs/manifest.json +140 -0
  28. package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +422 -0
  29. package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +180 -0
  30. package/core/cli-help.txt +7 -3
  31. package/core/cloud_sync/cloud_client.py +81 -2
  32. package/core/cloud_sync/endpoint_router.py +22 -9
  33. package/core/cloud_sync/issue_uploader.py +297 -0
  34. package/core/cloud_sync/sensitive_filter.py +77 -7
  35. package/core/contracts/AGENT_GUIDE.md +3 -9
  36. package/core/contracts/README.md +1 -1
  37. package/core/contracts/bugx-runtime-contract.md +10 -20
  38. package/core/contracts/bugx-worker.md +1 -1
  39. package/core/coverage/coverage_ai_review.py +15 -11
  40. package/core/coverage/coverage_bootstrap.py +18 -13
  41. package/core/coverage/coverage_discovery.py +1 -1
  42. package/core/dev_harness/interaction_preset.py +1 -1
  43. package/core/engine-integrity.json +283 -159
  44. package/core/host_acp/README.md +4 -0
  45. package/core/host_acp/agnescode.py +128 -0
  46. package/core/host_acp/antigravity.py +153 -0
  47. package/core/host_runtime/README.md +3 -0
  48. package/core/host_runtime/adapters.py +5 -1
  49. package/core/host_runtime/antigravity.py +162 -0
  50. package/core/host_runtime/host_bootstrap.py +18 -7
  51. package/core/host_runtime/host_evaluators.py +4 -4
  52. package/core/host_runtime/host_registry.py +3 -1
  53. package/core/host_runtime/mcp_process_tracker.py +30 -3
  54. package/core/host_runtime/mcp_registry_gate.py +34 -11
  55. package/core/hosts/README.md +4 -0
  56. package/core/hosts/agnescode.py +415 -0
  57. package/core/hosts/antigravity.py +115 -0
  58. package/core/hosts/codex.py +3 -0
  59. package/core/hosts/dsh.py +42 -23
  60. package/core/hosts/minimax.py +5 -4
  61. package/core/hosts/opencode.py +11 -3
  62. package/core/i18n.py +94 -5
  63. package/core/infra/README.md +1 -1
  64. package/core/infra/build_info.py +2 -2
  65. package/core/infra/python_runtime.py +4 -1
  66. package/core/launch_phases/README.md +2 -2
  67. package/core/launch_phases/finding_confirm_phase.py +1 -1
  68. package/core/launch_phases/semantic_recon.py +3 -19
  69. package/core/launch_phases/startup_version_gate.py +2 -2
  70. package/core/launch_phases/supervisor_bridge.py +2 -0
  71. package/core/launch_phases/supervisor_degraded.py +7 -5
  72. package/core/launch_phases/verify_loop.py +3 -19
  73. package/core/ledger/README.md +1 -1
  74. package/core/ledger/finding_confirmation.py +1 -1
  75. package/core/ledger/finding_verification.py +2 -20
  76. package/core/ledger/fp_ledger.py +3 -19
  77. package/core/ledger/life_ledger.py +7 -33
  78. package/core/ledger/schema.py +1 -1
  79. package/core/locales/en-US.json +3 -3
  80. package/core/locales/zh-CN.json +3 -3
  81. package/core/mcp_handlers/supervisor_handlers.py +1 -1
  82. package/core/mcp_runtime_support/common.py +6 -0
  83. package/core/mcp_runtime_support/environment.py +88 -24
  84. package/core/metadata.txt +1 -1
  85. package/core/planning/README.md +1 -1
  86. package/core/planning/prompt_harness.py +2 -2
  87. package/core/planning/target_sandbox_manager.py +2 -0
  88. package/core/probes/codebase_memory_probe.py +43 -24
  89. package/core/probes/mobile_probe.py +1 -0
  90. package/core/probes/probe_registry.py +10 -7
  91. package/core/probes/sast_probe.py +1 -1
  92. package/core/probes/sca_scanner.py +1 -1
  93. package/core/project_profiler/constants.py +1 -1
  94. package/core/prompts/command_routing_en.md +6 -5
  95. package/core/prompts/command_routing_zh.md +6 -5
  96. package/core/repair/rsi_rounds.py +3 -0
  97. package/core/repair/self_heal.py +160 -6
  98. package/core/retrieval/README.md +1 -1
  99. package/core/retrieval/symbol_index.py +227 -52
  100. package/core/runtime/README.md +1 -1
  101. package/core/runtime/daemon_runner.py +3 -2
  102. package/core/runtime/project_init.py +1 -1
  103. package/core/runtime/scenario_eval.py +5 -1
  104. package/core/runtime/tool_install_targets.py +12 -2
  105. package/core/skills/README.md +4 -2
  106. package/core/skills/bugx_docs_cloud_sync.py +658 -0
  107. package/core/skills/bugx_docs_mcp_server.py +966 -140
  108. package/core/skills/bugx_mcp_server.py +9 -0
  109. package/core/skills/mcp_session_proof.py +3 -31
  110. package/core/supervisor/README.md +1 -1
  111. package/core/supervisor/finding_commit.py +3 -24
  112. package/core/supervisor/task_scheduler.py +5 -2
  113. package/core/supervisor/worker_execution.py +16 -3
  114. package/core/supervisor/worker_handoff.py +2 -2
  115. package/core/webui/docs_session_service.py +40 -2
  116. package/core/webui/mcp_inspector.py +6 -6
  117. package/ecosystem/integrations/cline/skills/bugx/SKILL.md +46 -46
  118. package/ecosystem/integrations/dsh/agents/bugx.md +2 -1
  119. package/ecosystem/integrations/dsh/mcp/package.json +1 -1
  120. package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +5 -5
  121. package/ecosystem/integrations/dsh/ui/package.json +1 -1
  122. package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
  123. package/ecosystem/integrations/opencode/mcp-lock.json +1 -1
  124. package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
  125. package/ecosystem/integrations/pi/skills/bugx/SKILL.md +5 -5
  126. package/ecosystem/integrations/qoder/CONNECTORS.md +11 -23
  127. package/ecosystem/integrations/qoder/connector-meta.json +1 -1
  128. package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
  129. package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +8 -7
  130. package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
  131. package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
  132. package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
  133. package/ecosystem/plugins/bugx/agents/bugx-worker.md +14 -18
  134. package/ecosystem/plugins/bugx/agents/bugx.md +45 -49
  135. package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +7 -7
  136. package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +2 -2
  137. package/interfaces/cli/bugx_cli/__init__.py +1 -1
  138. package/interfaces/cli/bugx_cli/cli.py +153 -8
  139. package/interfaces/cli/bugx_cli/commands/agent.py +376 -69
  140. package/interfaces/cli/bugx_cli/commands/audit.py +2 -1
  141. package/interfaces/cli/bugx_cli/commands/cloud.py +42 -1
  142. package/interfaces/cli/bugx_cli/commands/doctor.py +650 -223
  143. package/interfaces/cli/bugx_cli/commands/guide.py +143 -0
  144. package/interfaces/cli/bugx_cli/commands/issue.py +262 -0
  145. package/interfaces/cli/bugx_cli/commands/lifecycle.py +56 -26
  146. package/interfaces/cli/bugx_cli/commands/patch.py +5 -1
  147. package/interfaces/cli/bugx_cli/commands/plugin.py +306 -56
  148. package/interfaces/cli/bugx_cli/commands/plugin_antigravity.py +350 -0
  149. package/interfaces/cli/bugx_cli/commands/plugin_claude.py +2 -2
  150. package/interfaces/cli/bugx_cli/commands/plugin_kimi.py +154 -62
  151. package/interfaces/cli/bugx_cli/commands/plugin_minimax.py +308 -108
  152. package/interfaces/cli/bugx_cli/commands/system.py +11 -1
  153. package/interfaces/cli/bugx_cli/common.py +39 -8
  154. package/interfaces/cli/bugx_cli/host_adapters.py +46 -3
  155. package/interfaces/cli/bugx_cli/hosts/registry.py +3 -2
  156. package/interfaces/cli/bugx_cli/hosts/template_engine.py +21 -2
  157. package/interfaces/cli/bugx_cli/infra/__init__.py +4 -0
  158. package/interfaces/cli/bugx_cli/infra/ai_advisor.py +14 -12
  159. package/interfaces/cli/bugx_cli/infra/engine_installer.py +76 -10
  160. package/interfaces/cli/bugx_cli/infra/host_sync.py +66 -1
  161. package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +240 -50
  162. package/package.json +3 -2
  163. package/pyproject.toml +22 -2
  164. package/scripts/sync-version.mjs +1 -1
  165. package/skills/README.md +1 -2
  166. package/skills/platform/bugx/SKILL.md +50 -0
  167. package/skills/platform/bugx-user/SKILL.md +0 -92
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env python3
2
+ """BugX 本地/云端协同文档与操作指南检索指令 (RAG on-demand)。"""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import json
8
+ import sys
9
+ from pathlib import Path
10
+ from typing import Any
11
+
12
+ from ..common import (
13
+ _ensure_core_importable,
14
+ resolve_project_root,
15
+ )
16
+
17
+ _BUILTIN_GUIDES = [
18
+ (
19
+ {"login", "登录", "auth", "认证", "云端", "non-blocking", "verify"},
20
+ "云端登录与非阻塞认证",
21
+ "运行 `bugx auth login --root . --non-blocking` 立即获取授权链接与用户码;用户授权后运行 `bugx auth verify --root .` 保存凭据,或使用 `bugx auth set-key --api-key <KEY>` 极速鉴权。",
22
+ ),
23
+ (
24
+ {"doctor", "诊断", "环境", "repair", "修复", "missing"},
25
+ "环境诊断与依赖修复",
26
+ "运行 `bugx doctor --root .` 检查引擎、依赖与宿主配置状态;若提示资产或依赖缺失,按提示执行 `bugx doctor --repair` 或 `bugx update --repair-assets`。",
27
+ ),
28
+ (
29
+ {"sync", "同步", "经验", "错题", "lesson", "knowledge"},
30
+ "经验同步与错题检索",
31
+ "运行 `bugx cloud status --root . --scope all --json` 核对状态后使用 `bugx cloud sync --root . --scope all` 同步;查询历史错题经验运行 `bugx lesson retrieve --root . --query \"<关键词>\" --json`。",
32
+ ),
33
+ (
34
+ {"init", "初始化", "新建"},
35
+ "项目初始化规范",
36
+ "进入目标项目根目录,运行 `bugx init --root .`,系统将把精简通用 Skill 安装到 `.agents/skills/bugx/SKILL.md`,可在宿主中通过 `/bugx` 激活。",
37
+ ),
38
+ (
39
+ {"winerror", "32", "lock", "锁定"},
40
+ "文件锁定 / WinError 32 处置",
41
+ "新版 `bugx-docs` 采用不可变快照切换 + 延迟 GC,不直接覆盖正在只读占用的 SQLite 句柄;若遇残留占用,请关闭冗余宿主会话并重跑 `bugx mcp docs sync --root . --force`。",
42
+ ),
43
+ ]
44
+
45
+
46
+ def _lookup_builtin_guide(query: str) -> dict[str, str] | None:
47
+ q_low = query.lower()
48
+ for keywords, title, instruction in _BUILTIN_GUIDES:
49
+ if any(k in q_low for k in keywords):
50
+ return {"source": "builtin", "section": title, "heading_path": title, "snippet": instruction}
51
+ return None
52
+
53
+
54
+ def command_guide(args: argparse.Namespace) -> int:
55
+ """检索 BugX 官方文档与当前项目文档,返回精准章节步骤与引用。"""
56
+ root = resolve_project_root(args.root).resolve()
57
+ query = str(args.query or "").strip()
58
+ if not query:
59
+ print("[bugx guide] 错误: 查询关键词不能为空", file=sys.stderr)
60
+ return 1
61
+
62
+ limit = max(1, min(int(getattr(args, "limit", 3) or 3), 10))
63
+ as_json = bool(getattr(args, "json", False))
64
+ reindex = bool(getattr(args, "reindex", False))
65
+ offline = bool(getattr(args, "offline", False))
66
+
67
+ _ensure_core_importable()
68
+ try:
69
+ from core.skills import bugx_docs_cloud_sync as docs_sync
70
+ from core.skills import bugx_docs_mcp_server as docs_server
71
+ except ImportError as exc:
72
+ print(f"[bugx guide] 错误: 无法加载文档检索核心: {exc}", file=sys.stderr)
73
+ return 1
74
+
75
+ db_path = root / ".bugx" / "knowledge" / "docs.sqlite3"
76
+ project_id = root.name
77
+
78
+ # 1. 尝试轻量级云端官方缓存同步(尊重 1h TTL 与 120s 故障退避,阻塞不超过 1.0s)
79
+ if not offline and not docs_sync.docs_offline_disabled():
80
+ try:
81
+ docs_sync.sync_official_docs(
82
+ force=reindex, offline=offline, manifest_timeout=1.0, bundle_timeout=3.0,
83
+ )
84
+ except Exception:
85
+ pass
86
+
87
+ # 2. 按需建立/刷新当前项目私有索引;若目标目录只读 (NEG-03),静默退化,仍可读官方库
88
+ if not db_path.is_file() or reindex:
89
+ try:
90
+ docs_server.index_documents(
91
+ root, db_path, project_id=project_id, version="working-tree",
92
+ )
93
+ except Exception:
94
+ pass
95
+
96
+ results: list[dict[str, Any]] = []
97
+ try:
98
+ raw_res = docs_server.call_tool(
99
+ db_path,
100
+ "search_docs",
101
+ {"query": query, "limit": limit, "library_id": "all", "project_id": project_id},
102
+ project_id=project_id,
103
+ expected_token=None,
104
+ mode="local-only" if offline else "hybrid",
105
+ )
106
+ results = list(raw_res.get("results") or [])
107
+ except Exception as exc:
108
+ builtin = _lookup_builtin_guide(query)
109
+ if builtin:
110
+ results = [builtin]
111
+ else:
112
+ print(f"[bugx guide] 检索失败: {exc}", file=sys.stderr)
113
+ return 1
114
+
115
+ # 3. 无论本地库是否存在,只要双域均未命中即回落内置字典兜底
116
+ if not results:
117
+ builtin = _lookup_builtin_guide(query)
118
+ if builtin:
119
+ results = [builtin]
120
+
121
+ if as_json:
122
+ print(json.dumps({"query": query, "count": len(results), "results": results}, ensure_ascii=False, indent=2))
123
+ return 0
124
+
125
+ if not results:
126
+ print(f"📖 BugX 知识检索: '{query}'")
127
+ print("未检索到相关操作步骤或文档。")
128
+ print("💡 建议:尝试使用更简短的关键词,如:'云端登录'、'doctor'、'错题集'、'poc'、'WinError 32'")
129
+ return 0
130
+
131
+ print(f"📖 BugX 知识检索: '{query}' (找到 {len(results)} 条相关指引)\n")
132
+ for idx, item in enumerate(results, 1):
133
+ source = item.get("source", "unknown")
134
+ lib = item.get("library_id", "")
135
+ hpath = item.get("heading_path") or item.get("section") or ""
136
+ header = f"[{idx}] {source}" + (f" § {hpath}" if hpath else "") + (f" ({lib})" if lib else "")
137
+ snippet = str(item.get("snippet") or "").strip()
138
+ print(header)
139
+ print("─" * 60)
140
+ print(snippet)
141
+ print()
142
+
143
+ return 0
@@ -0,0 +1,262 @@
1
+ """BugX Issue Reporting & Diagnostic Feedback CLI Commands.
2
+
3
+ Provides `bugx issue report` and `bugx feedback` commands to collect conversation
4
+ history, error logs, and environment context, scrub sensitive tokens, and report
5
+ to BugX Server for diagnostics and bug resolution.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ import json
12
+ import os
13
+ import sys
14
+ from pathlib import Path
15
+ from typing import Any
16
+
17
+ from ..common import _ensure_core_importable
18
+
19
+
20
+ def register_issue_parser(target: Any) -> Any:
21
+ """注册 issue 与 feedback 命令行解析器。
22
+
23
+ 兼容两种调用形式:
24
+ 1. 传入 subparsers (_SubParsersAction, CLI 模块化集成模式): 注册 issue 与 feedback 子命令。
25
+ 2. 传入 parser (ArgumentParser, 独立测试用例模式): 注册 report/issue/feedback 子解析器。
26
+ """
27
+ if hasattr(target, "add_subparsers") and not hasattr(target, "add_parser"):
28
+ sub = target.add_subparsers(dest="issue_command")
29
+ report_parser = sub.add_parser(
30
+ "report",
31
+ help="采集最近会话现场与错误日志并上报至 BugX 服务端",
32
+ )
33
+ _add_report_arguments(report_parser)
34
+ report_parser.set_defaults(handler=command_issue)
35
+
36
+ issue_parser = sub.add_parser(
37
+ "issue",
38
+ help="问题上报与会话异常诊断(将对话现场脱敏后提交至 BugX 服务端排查)",
39
+ )
40
+ _setup_issue_subparsers(issue_parser)
41
+ issue_parser.set_defaults(handler=command_issue)
42
+
43
+ feedback_parser = sub.add_parser(
44
+ "feedback",
45
+ help="问题与会话现场快速反馈(等同于 bugx issue report)",
46
+ )
47
+ _add_report_arguments(feedback_parser)
48
+ feedback_parser.set_defaults(handler=command_feedback)
49
+
50
+ return sub
51
+
52
+ parser = target.add_parser(
53
+ "issue",
54
+ help="问题上报与会话异常诊断(将对话现场脱敏后提交至 BugX 服务端排查)",
55
+ )
56
+ _setup_issue_subparsers(parser)
57
+ parser.set_defaults(handler=command_issue)
58
+
59
+ # 别名 feedback:直接挂载为顶层快捷命令
60
+ feedback_parser = target.add_parser(
61
+ "feedback",
62
+ help="问题与会话现场快速反馈(等同于 bugx issue report)",
63
+ )
64
+ _add_report_arguments(feedback_parser)
65
+ feedback_parser.set_defaults(handler=command_feedback)
66
+
67
+ return parser
68
+
69
+
70
+ def _setup_issue_subparsers(parser: argparse.ArgumentParser) -> None:
71
+ sub = parser.add_subparsers(dest="issue_command")
72
+ report_parser = sub.add_parser(
73
+ "report",
74
+ help="采集最近会话现场与错误日志并上报至 BugX 服务端",
75
+ )
76
+ _add_report_arguments(report_parser)
77
+ report_parser.set_defaults(handler=command_issue)
78
+
79
+
80
+ def _add_report_arguments(parser: argparse.ArgumentParser) -> None:
81
+ parser.add_argument(
82
+ "--root",
83
+ type=Path,
84
+ default=None,
85
+ help="项目根路径(默认当前工作目录或 BUGX_PROJECT_ROOT)",
86
+ )
87
+ parser.add_argument(
88
+ "--session",
89
+ dest="session_id",
90
+ default=None,
91
+ help="指定上报的会话 ID;省略时自动探测最近一次发生异常的会话",
92
+ )
93
+ parser.add_argument(
94
+ "--title",
95
+ default=None,
96
+ help="问题简要标题(省略时从错误信息或交互式提示中提取)",
97
+ )
98
+ parser.add_argument(
99
+ "--desc",
100
+ default="",
101
+ help="问题详细现象或复现步骤补充说明",
102
+ )
103
+ parser.add_argument(
104
+ "--no-logs",
105
+ action="store_false",
106
+ dest="include_logs",
107
+ default=True,
108
+ help="不附带 .bugx/logs/ 核心日志切片",
109
+ )
110
+ parser.add_argument(
111
+ "--mask-source",
112
+ action="store_true",
113
+ default=False,
114
+ help="对会话中出现的源代码块强制遮蔽为 [SOURCE_CODE_REDACTED]",
115
+ )
116
+ parser.add_argument(
117
+ "--anonymous",
118
+ action="store_true",
119
+ default=False,
120
+ help="匿名上报,不携带设备指纹与账号信息",
121
+ )
122
+ parser.add_argument(
123
+ "--dry-run",
124
+ action="store_true",
125
+ default=False,
126
+ help="仅在本地提取并打印脱敏后的上报数据包,不发起网络请求",
127
+ )
128
+ parser.add_argument(
129
+ "-y",
130
+ "--yes",
131
+ action="store_true",
132
+ default=False,
133
+ help="跳过终端确认提示,直接上报",
134
+ )
135
+ parser.add_argument(
136
+ "--api-base",
137
+ default=None,
138
+ help="自定义 BugX 服务端 API 根地址 (如 https://bugx.dev)",
139
+ )
140
+
141
+
142
+ def command_feedback(args: argparse.Namespace) -> int:
143
+ """feedback 顶层别名处理器,直接转发至 command_issue。"""
144
+ return command_issue(args)
145
+
146
+
147
+ def command_issue(args: argparse.Namespace) -> int:
148
+ """执行问题现场收集与上报主流程。"""
149
+ _ensure_core_importable()
150
+ from core.cloud_sync.issue_uploader import (
151
+ build_issue_payload,
152
+ prepare_issue_gzip_package,
153
+ upload_issue,
154
+ )
155
+
156
+ project_root = args.root or Path(os.environ.get("BUGX_PROJECT_ROOT", Path.cwd()))
157
+ title = args.title
158
+
159
+ # 若未指定标题且在交互式终端中,提示用户输入简要标题
160
+ if not title and sys.stdin.isatty() and not getattr(args, "yes", False):
161
+ try:
162
+ user_input = input("请输入遇到的问题简述 (直接回车将自动提取错误首行): ").strip()
163
+ if user_input:
164
+ title = user_input
165
+ except (KeyboardInterrupt, EOFError):
166
+ print("\n已取消上报。")
167
+ return 1
168
+
169
+ print(f"[*] 正在分析与提取项目现场数据: {project_root}...")
170
+
171
+ try:
172
+ payload, redacted_categories = build_issue_payload(
173
+ project_root=project_root,
174
+ title=title or "",
175
+ desc=args.desc,
176
+ session_id=args.session_id,
177
+ include_logs=args.include_logs,
178
+ mask_source=args.mask_source,
179
+ anonymous=args.anonymous,
180
+ )
181
+ except Exception as err:
182
+ print(f"[!] 提取会话现场数据失败: {err}", file=sys.stderr)
183
+ return 1
184
+
185
+ compressed_bytes = prepare_issue_gzip_package(payload)
186
+ raw_json_str = json.dumps(payload, ensure_ascii=False)
187
+ raw_size_kb = len(raw_json_str.encode("utf-8")) / 1024.0
188
+ comp_size_kb = len(compressed_bytes) / 1024.0
189
+
190
+ session_info = payload.get("session_id") or "未关联会话 (纯日志与环境)"
191
+ error_summary = payload.get("error_message") or payload.get("title") or "无"
192
+ log_lines = len(payload.get("logs_slice") or [])
193
+
194
+ # 打印脱敏审计摘要
195
+ print("\n" + "=" * 60)
196
+ print(" 📋 BugX 会话现场诊断包信息清单 (已完成三级安全脱敏)")
197
+ print("=" * 60)
198
+ print(f" • 问题标题: {payload.get('title')}")
199
+ print(f" • 关联会话: {session_info}")
200
+ print(f" • 异常摘要: {error_summary[:80]}")
201
+ print(f" • 宿主环境: {payload.get('host')} (OS: {payload.get('environment', {}).get('os')})")
202
+ print(f" • 日志附带: {log_lines} 行")
203
+ print(f" • 数据包大小: {raw_size_kb:.1f} KB (Gzip 压缩后: {comp_size_kb:.1f} KB)")
204
+ print(f" • 隐私脱敏项: {', '.join(redacted_categories) if redacted_categories else '未检出敏感凭据 (安全)'}")
205
+ print("=" * 60)
206
+
207
+ # 提取前 2~3 条消息进行终端脱敏预览
208
+ messages = []
209
+ sess_obj = payload.get("session_data", {}).get("session") or {}
210
+ if isinstance(sess_obj, dict):
211
+ messages = sess_obj.get("messages") or []
212
+
213
+ if messages:
214
+ print("\n🔍 会话消息脱敏预览 (前 2 轮):")
215
+ for i, msg in enumerate(messages[:2], start=1):
216
+ role = msg.get("role", "unknown")
217
+ content = (msg.get("content") or "").strip().replace("\n", " ")
218
+ if len(content) > 100:
219
+ content = content[:100] + "..."
220
+ print(f" [{i}] ({role}): {content}")
221
+ print("-" * 60)
222
+
223
+ if args.dry_run:
224
+ print("\n💡 [Dry-Run 模式] 本地脱敏包生成完毕,已跳过网络请求。")
225
+ print(f"数据包预览 (JSON 截断 500 字符):\n{raw_json_str[:500]}...\n")
226
+ return 0
227
+
228
+ # 终端确认门禁
229
+ if sys.stdin.isatty() and not getattr(args, "yes", False):
230
+ try:
231
+ confirm = input("\n确认将上述脱敏后的现场诊断数据上报至 BugX 服务端?[y/N]: ").strip().lower()
232
+ if confirm not in ("y", "yes"):
233
+ print("[-] 用户取消上报。")
234
+ return 0
235
+ except (KeyboardInterrupt, EOFError):
236
+ print("\n[-] 已取消。")
237
+ return 1
238
+
239
+ print("[*] 正在通过安全通道上传现场诊断包...")
240
+ try:
241
+ res = upload_issue(
242
+ payload=payload,
243
+ api_url=args.api_base,
244
+ timeout=30.0,
245
+ )
246
+ except Exception as err:
247
+ print(f"\n[!] 上报失败: {err}", file=sys.stderr)
248
+ return 1
249
+
250
+ data = res.get("data") or {}
251
+ issue_no = data.get("issue_no") or res.get("issue_no") or "已记录"
252
+ view_url = data.get("view_url") or res.get("view_url") or ""
253
+
254
+ print("\n" + "=" * 60)
255
+ print(" 🎉 会话异常与诊断现场已成功提交至 BugX 服务端!")
256
+ print(f" • 工单编号: {issue_no}")
257
+ if view_url:
258
+ print(f" • 追踪与回放链接: {view_url}")
259
+ print(" • 处理进展: 我们的研发团队将根据会话回放与日志快速排查与修复。")
260
+ print("=" * 60 + "\n")
261
+
262
+ return 0
@@ -16,7 +16,7 @@ from typing import Any
16
16
 
17
17
  from .. import __version__
18
18
  from ..common import *
19
- from ..infra.engine_installer import refresh_i18n_after_engine_swap
19
+ from ..infra.engine_installer import _is_global_home_scope, refresh_i18n_after_engine_swap
20
20
  from ..host_adapters import ENTRY_MULTI_PATH, HOST_ADAPTERS
21
21
  from ..hosts.registry import (
22
22
  engine_host_cli_hook,
@@ -49,7 +49,6 @@ from .plugin import (
49
49
  _remove_host_mcp_entry,
50
50
  _remove_opencode_mcp_entry,
51
51
  _remove_owned_record,
52
- _remove_qoder_mcp_entry,
53
52
  _reset_active_blockers,
54
53
  _reset_confirmation,
55
54
  _reset_entries,
@@ -85,7 +84,7 @@ def _assemble_project_materials(root: Path, source: Path, layout: Any) -> None:
85
84
  from core.coverage import coverage_bootstrap
86
85
  coverage = coverage_bootstrap.inspect(root)
87
86
  if not coverage.get("ready") and not coverage.get("blocked"):
88
- coverage_bootstrap.bootstrap(root, confirmed=True)
87
+ coverage_bootstrap.bootstrap(root, confirmed=True, symbols=False)
89
88
  except Exception:
90
89
  pass
91
90
 
@@ -1844,6 +1843,9 @@ def _uninstall_guidance_flow(args: argparse.Namespace, root: Path) -> int:
1844
1843
  return command_uninstall(args)
1845
1844
 
1846
1845
 
1846
+ _SHARED_ROOT_MCP_HOSTS = frozenset({"claude", "funide", "qoder"})
1847
+
1848
+
1847
1849
  def _uninstall_dry_run_preview(
1848
1850
  root: Path,
1849
1851
  installed: list[object],
@@ -1853,6 +1855,7 @@ def _uninstall_dry_run_preview(
1853
1855
  purge_data: bool,
1854
1856
  purge_global_data: bool,
1855
1857
  force: bool = False,
1858
+ remaining_mcp_hosts: set[str],
1856
1859
  ) -> tuple[list[str], list[str]]:
1857
1860
  """Build an uninstall preview without invoking any mutating helper.
1858
1861
 
@@ -1943,6 +1946,9 @@ def _uninstall_dry_run_preview(
1943
1946
  continue
1944
1947
  target_path, _ = target_info
1945
1948
  if target_path.is_file() and not target_path.is_symlink():
1949
+ if mcp_host in _SHARED_ROOT_MCP_HOSTS and remaining_mcp_hosts:
1950
+ preserved.append(".mcp.json(仍有其他宿主使用 BugX MCP)")
1951
+ continue
1946
1952
  try:
1947
1953
  rel = str(target_path.relative_to(root))
1948
1954
  except ValueError:
@@ -1990,17 +1996,11 @@ def _remove_host_mcp_entries_for(
1990
1996
  preserved: list[str],
1991
1997
  *,
1992
1998
  backup_dir: Path | None = None,
1999
+ remaining_mcp_hosts: set[str],
1993
2000
  ) -> None:
1994
2001
  """清理宿主项目级 MCP 登记,含多路径宿主的 `.codebuddy` 兼容副本。"""
1995
- # Claude Code and FunIDE intentionally share the project-root `.mcp.json`
1996
- # shape. Removing FunIDE must not tear down a Claude installation that is
1997
- # still present in the same project; both hosts consume the same BugX
1998
- # servers. A FunIDE-only project has no `.claude` marker and is cleaned as
1999
- # usual.
2000
- if name == "funide" and (root / ".claude").exists():
2001
- preserved.append(
2002
- ".mcp.json(与 Claude Code 共用,卸载 FunIDE 时保留 BugX MCP)"
2003
- )
2002
+ if name in _SHARED_ROOT_MCP_HOSTS and remaining_mcp_hosts:
2003
+ preserved.append(".mcp.json(仍有其他宿主使用 BugX MCP)")
2004
2004
  else:
2005
2005
  _remove_host_mcp_entry(root, name, removed, preserved, backup_dir=backup_dir)
2006
2006
  for mcp_host in _mcp_config_host_names(name):
@@ -2049,6 +2049,11 @@ def command_uninstall(args: argparse.Namespace) -> int:
2049
2049
  choices = ", ".join(adapter.name for adapter in HOST_ADAPTERS)
2050
2050
  raise CliError(_i18n_exc("lifecycle.unknown_ai_agent", f"未知 AI Agent: {name};可选:{choices}", name=name, known=choices))
2051
2051
  selected_names = list(dict.fromkeys(known[name].name for name in raw_names))
2052
+ remaining_mcp_hosts = {
2053
+ str(item.get("name")) for item in installed if isinstance(item, dict)
2054
+ } & (_SHARED_ROOT_MCP_HOSTS - set(selected_names))
2055
+ if "funide" in selected_names and "claude" not in selected_names and (root / ".claude").exists():
2056
+ remaining_mcp_hosts.add("claude")
2052
2057
 
2053
2058
  if args.dry_run:
2054
2059
  planned, preserved = _uninstall_dry_run_preview(
@@ -2059,6 +2064,7 @@ def command_uninstall(args: argparse.Namespace) -> int:
2059
2064
  purge_data=bool(args.purge_data),
2060
2065
  purge_global_data=bool(args.purge_global_data),
2061
2066
  force=force,
2067
+ remaining_mcp_hosts=remaining_mcp_hosts,
2062
2068
  )
2063
2069
  payload = {
2064
2070
  "status": "DRY_RUN",
@@ -2148,7 +2154,10 @@ def command_uninstall(args: argparse.Namespace) -> int:
2148
2154
  ]
2149
2155
  for record in records:
2150
2156
  _remove_owned_record(root, record, name, removed, preserved, uninstall_backup_dir, force=force)
2151
- _remove_host_mcp_entries_for(root, name, removed, preserved, backup_dir=uninstall_backup_dir)
2157
+ _remove_host_mcp_entries_for(
2158
+ root, name, removed, preserved, backup_dir=uninstall_backup_dir,
2159
+ remaining_mcp_hosts=remaining_mcp_hosts,
2160
+ )
2152
2161
  if name == "chatgpt":
2153
2162
  _remove_chatgpt_marketplace_entry(root, removed, preserved, backup_dir=uninstall_backup_dir)
2154
2163
  _deregister_codex_plugin(root, removed, preserved)
@@ -2260,7 +2269,10 @@ def command_uninstall(args: argparse.Namespace) -> int:
2260
2269
  for name in selected_names:
2261
2270
  if name in recorded_names:
2262
2271
  continue
2263
- _remove_host_mcp_entries_for(root, name, removed, preserved, backup_dir=uninstall_backup_dir)
2272
+ _remove_host_mcp_entries_for(
2273
+ root, name, removed, preserved, backup_dir=uninstall_backup_dir,
2274
+ remaining_mcp_hosts=remaining_mcp_hosts,
2275
+ )
2264
2276
  if name == "chatgpt":
2265
2277
  _remove_chatgpt_marketplace_entry(root, removed, preserved, backup_dir=uninstall_backup_dir)
2266
2278
  _deregister_codex_plugin(root, removed, preserved)
@@ -2288,7 +2300,10 @@ def command_uninstall(args: argparse.Namespace) -> int:
2288
2300
  }
2289
2301
  for adapter in HOST_ADAPTERS:
2290
2302
  if adapter.name not in recorded:
2291
- _remove_host_mcp_entries_for(root, adapter.name, removed, preserved, backup_dir=uninstall_backup_dir)
2303
+ _remove_host_mcp_entries_for(
2304
+ root, adapter.name, removed, preserved, backup_dir=uninstall_backup_dir,
2305
+ remaining_mcp_hosts=remaining_mcp_hosts,
2306
+ )
2292
2307
  if (global_engine_root() / "bugx.md").is_file():
2293
2308
  _sweep_unrecorded_host_entry(root, adapter, removed, preserved, uninstall_backup_dir, force=force)
2294
2309
 
@@ -2392,12 +2407,13 @@ def _assert_writable(directory: Path, label: str) -> None:
2392
2407
  raise CliError(f"{label}不可写:{directory}: {exc}") from exc
2393
2408
 
2394
2409
 
2395
- _PROJECT_USER_SKILL = Path(".agents/skills/bugx-user/SKILL.md")
2410
+ _PROJECT_SKILL = Path(".agents/skills/bugx/SKILL.md")
2411
+ _PROJECT_USER_SKILL = _PROJECT_SKILL
2396
2412
 
2397
2413
 
2398
2414
  def _read_project_user_skill(root: Path, source: Path) -> bytes:
2399
2415
  """Validate the required bundled Skill and its project destination before init writes."""
2400
- target = root / _PROJECT_USER_SKILL
2416
+ target = root / _PROJECT_SKILL
2401
2417
  _assert_no_symlink_components(target)
2402
2418
  for parent in target.parents:
2403
2419
  if parent == root:
@@ -2407,25 +2423,35 @@ def _read_project_user_skill(root: Path, source: Path) -> bytes:
2407
2423
  if target.exists() and not target.is_file():
2408
2424
  raise CliError(f"项目 Skill 目标不是普通文件:{target}")
2409
2425
 
2410
- template = source.parent / "skills" / "platform" / "bugx-user" / "SKILL.md"
2426
+ template = source.parent / "skills" / "platform" / "bugx" / "SKILL.md"
2411
2427
  _assert_no_symlink_components(template)
2412
2428
  if not template.is_file():
2413
- raise CliError(f"安装包缺少 BugX 用户 Skill:{template}。请重新安装完整的 bugx-cli。")
2429
+ raise CliError(f"安装包缺少 BugX Skill:{template}。请重新安装完整的 bugx-cli。")
2414
2430
  try:
2415
2431
  content = template.read_bytes()
2416
2432
  except OSError as exc:
2417
- raise CliError(f"无法读取 BugX 用户 Skill:{template}: {exc}") from exc
2433
+ raise CliError(f"无法读取 BugX Skill:{template}: {exc}") from exc
2418
2434
  if not content.strip():
2419
- raise CliError(f"安装包中的 BugX 用户 Skill 为空:{template}。请重新安装完整的 bugx-cli。")
2435
+ raise CliError(f"安装包中的 BugX Skill 为空:{template}。请重新安装完整的 bugx-cli。")
2420
2436
  return content
2421
2437
 
2422
2438
 
2423
2439
  def _install_project_user_skill(root: Path, content: bytes, *, force: bool) -> Path | None:
2424
- target = root / _PROJECT_USER_SKILL
2440
+ # 迁移/清理旧版 bugx-user
2441
+ legacy_user_skill = root / ".agents" / "skills" / "bugx-user" / "SKILL.md"
2442
+ if legacy_user_skill.is_file():
2443
+ try:
2444
+ legacy_user_skill.unlink()
2445
+ if legacy_user_skill.parent.is_dir():
2446
+ legacy_user_skill.parent.rmdir()
2447
+ except OSError:
2448
+ pass
2449
+
2450
+ target = root / _PROJECT_SKILL
2425
2451
  _assert_no_symlink_components(target)
2426
2452
  if target.is_file() and not force:
2427
2453
  return None
2428
- _, _, backup = _write_host_resource(root, target, content, "bugx-user")
2454
+ _, _, backup = _write_host_resource(root, target, content, "bugx")
2429
2455
  return backup
2430
2456
 
2431
2457
 
@@ -2466,7 +2492,7 @@ def _plan_cloud_onboarding(
2466
2492
  # been initialized. Probing sync here can otherwise make first-time
2467
2493
  # ``init --cloud-sync sync`` fail before it creates the very ledger that
2468
2494
  # sync requires.
2469
- if not had_onboarding and cloud_sync_explicit and cloud_sync_choice in {"local", "sync"}:
2495
+ if cloud_sync_explicit and cloud_sync_choice in {"local", "sync"}:
2470
2496
  action = "enable_sync" if cloud_sync_choice == "sync" else "set_local"
2471
2497
  return {"action": action}, 0
2472
2498
  if not had_onboarding:
@@ -2551,6 +2577,10 @@ def _commit_with_self_heal(commit, *, retries: int = 1):
2551
2577
 
2552
2578
  def command_init(args: argparse.Namespace) -> int:
2553
2579
  root = args.root.resolve()
2580
+ if _is_global_home_scope(root):
2581
+ raise CliError(
2582
+ "不能将用户主目录 (~) 作为被测项目初始化;请在具体项目目录执行 `bugx init --root <PROJECT>`,或运行 `bugx install` 执行用户全局安装。"
2583
+ )
2554
2584
  preset_data = {}
2555
2585
  try:
2556
2586
  _ensure_core_importable()
@@ -2686,9 +2716,9 @@ def command_init(args: argparse.Namespace) -> int:
2686
2716
  if removed_legacy_core:
2687
2717
  print(f" 已直接删除旧项目引擎入口:{removed_legacy_core}")
2688
2718
  print(f" 运行目录:{layout.root}")
2689
- print(f" 用户 Skill:{_PROJECT_USER_SKILL.as_posix()}")
2719
+ print(f" 标准 Skill:{_PROJECT_SKILL.as_posix()}")
2690
2720
  if committed["skill_backup"] is not None:
2691
- print(f" 用户 Skill 备份:{committed['skill_backup']}")
2721
+ print(f" 标准 Skill 备份:{committed['skill_backup']}")
2692
2722
  print(f" 写入 {copied} 个文件,保留 {skipped} 个已有文件")
2693
2723
  if life_created:
2694
2724
  print(" 已创建 .bugx 当前生命周期生命状态(1 条初始寿命)")
@@ -732,7 +732,11 @@ def _run_sandbox_script(
732
732
  if script_path.suffix == ".py":
733
733
  cmd = [sys.executable, str(script_path)]
734
734
  elif script_path.suffix == ".sh":
735
- cmd = ["/bin/bash", str(script_path)]
735
+ import shutil as _shutil
736
+ bash_exe = _shutil.which("bash") or ("/bin/bash" if os.name != "nt" else None)
737
+ if not bash_exe:
738
+ return -1, "当前系统缺少 bash,无法执行 .sh 脚本"
739
+ cmd = [bash_exe, str(script_path)]
736
740
  else:
737
741
  cmd = [str(script_path)]
738
742