bugx-cli 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -29
- package/core/README.md +5 -3
- package/core/agent/agent_orchestrator.py +3 -0
- package/core/agent/agent_workspace.py +14 -2
- package/core/assets/bugx-wechat-group.png +0 -0
- package/core/assets/twitter_promo_art.jpg +0 -0
- package/core/assets/twitter_promo_card.svg +166 -0
- package/core/assets/twitter_promo_clean.jpg +0 -0
- package/core/assets/twitter_terminal_real.png +0 -0
- package/core/bugx.md +3 -3
- package/core/bugx_paths.py +10 -2
- package/core/bundled_docs/OVERVIEW.md +310 -0
- package/core/bundled_docs/README.md +10 -0
- package/core/bundled_docs/README_EN.md +278 -0
- package/core/bundled_docs/ai/01_AI_REFERENCE.md +833 -0
- package/core/bundled_docs/ai/02_AI_USAGE.md +161 -0
- package/core/bundled_docs/ai/03_AI_COMMANDS.md +322 -0
- package/core/bundled_docs/guides/01_USER_GUIDE.md +887 -0
- package/core/bundled_docs/guides/02_COMMANDS.md +935 -0
- package/core/bundled_docs/guides/03_TROUBLESHOOTING.md +763 -0
- package/core/bundled_docs/guides/04_CLOUD_AUTH_AND_SYNC_COOKBOOK.md +48 -0
- package/core/bundled_docs/guides/05_HOST_MATRIX_AND_DISPATCH.md +23 -0
- package/core/bundled_docs/guides/06_PROBES_AND_POC_COOKBOOK.md +49 -0
- package/core/bundled_docs/guides/07_LIFECYCLE_AND_RECOVERY_STATES.md +46 -0
- package/core/bundled_docs/guides/08_LESSONS_AND_PRIVACY_BOUNDARY.md +35 -0
- package/core/bundled_docs/hosts/bugx-claude_SKILL.md +326 -0
- package/core/bundled_docs/hosts/bugx-dsh_SKILL.md +229 -0
- package/core/bundled_docs/hosts/bugx-opencode_SKILL.md +129 -0
- package/core/bundled_docs/hosts/bugx-zcode_SKILL.md +459 -0
- package/core/bundled_docs/hosts/bugx_SKILL.md +118 -0
- package/core/bundled_docs/hosts/cline_bugx_SKILL.md +69 -0
- package/core/bundled_docs/hosts/platform_bugx_SKILL.md +50 -0
- package/core/bundled_docs/manifest.json +140 -0
- package/core/bundled_docs/reference/01_ENVIRONMENT_VARIABLES.md +421 -0
- package/core/bundled_docs/reference/04_REPOSITORY_TOPOLOGY.md +180 -0
- package/core/cli-help.txt +7 -3
- package/core/cloud_sync/cloud_client.py +81 -2
- package/core/cloud_sync/endpoint_router.py +22 -9
- package/core/cloud_sync/issue_uploader.py +297 -0
- package/core/cloud_sync/sensitive_filter.py +77 -7
- package/core/contracts/AGENT_GUIDE.md +3 -9
- package/core/contracts/README.md +1 -1
- package/core/contracts/bugx-opencode.md +1 -1
- package/core/contracts/bugx-runtime-contract.md +10 -20
- package/core/contracts/bugx-worker.md +1 -1
- package/core/engine-integrity.json +267 -111
- package/core/host_acp/antigravity.py +153 -0
- package/core/host_acp/kimi.py +175 -0
- package/core/host_acp/minimax.py +28 -0
- package/core/host_runtime/adapters.py +5 -1
- package/core/host_runtime/antigravity.py +162 -0
- package/core/host_runtime/host_bootstrap.py +18 -7
- package/core/host_runtime/host_evaluators.py +4 -4
- package/core/host_runtime/host_registry.py +25 -4
- package/core/host_runtime/mcp_process_tracker.py +30 -3
- package/core/host_runtime/mcp_registry_gate.py +34 -11
- package/core/hosts/antigravity.py +115 -0
- package/core/hosts/codex.py +3 -0
- package/core/hosts/dsh.py +43 -24
- package/core/hosts/kimi.py +293 -0
- package/core/hosts/minimax.py +249 -0
- package/core/hosts/zcode.py +5 -0
- package/core/i18n.py +94 -5
- package/core/infra/README.md +1 -1
- package/core/infra/build_info.py +30 -5
- package/core/launch_phases/README.md +2 -2
- package/core/launch_phases/startup_version_gate.py +2 -2
- package/core/launch_phases/supervisor_bridge.py +16 -23
- package/core/launch_phases/supervisor_degraded.py +7 -5
- package/core/ledger/README.md +1 -1
- package/core/locales/en-US.json +3 -3
- package/core/locales/zh-CN.json +3 -3
- package/core/mcp_runtime_support/environment.py +6 -1
- package/core/metadata.txt +2 -2
- package/core/planning/README.md +1 -1
- package/core/planning/prompt_harness.py +2 -2
- package/core/probes/codebase_memory_probe.py +43 -24
- package/core/probes/probe_registry.py +10 -7
- package/core/prompts/command_routing_en.md +6 -5
- package/core/prompts/command_routing_zh.md +6 -5
- package/core/repair/rsi_rounds.py +3 -0
- package/core/repair/self_heal.py +160 -6
- package/core/retrieval/README.md +1 -1
- package/core/runtime/README.md +1 -1
- package/core/runtime/scenario_eval.py +5 -1
- package/core/runtime/setup_ui_env.py +4 -7
- package/core/runtime/tool_install_targets.py +12 -2
- package/core/skills/README.md +4 -2
- package/core/skills/bugx_docs_cloud_sync.py +658 -0
- package/core/skills/bugx_docs_mcp_server.py +966 -140
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/cli.py +2 -2
- package/core/supervisor/worker_execution.py +16 -3
- package/core/webui/docs_session_service.py +40 -2
- package/core/webui/mcp_inspector.py +12 -6
- package/core/webui/static/index.html +51 -3
- package/core/webui/static/manifest.webmanifest +1 -1
- package/core/webui/static/project-settings.js +18 -3
- package/core/webui/static/robots.txt +36 -0
- package/core/webui/static/sitemap.xml +15 -0
- package/docs/07_distribution/01_README_NPM.md +26 -29
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +46 -46
- package/ecosystem/integrations/dsh/agents/bugx.md +2 -1
- package/ecosystem/integrations/dsh/dsh-patch.yml +2 -2
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +6 -6
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +2 -2
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +6 -6
- package/ecosystem/integrations/qoder/CONNECTORS.md +11 -23
- package/ecosystem/integrations/qoder/connector-meta.json +9 -9
- package/ecosystem/integrations/workbuddy/connector-meta.json +9 -9
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +8 -7
- package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +2 -2
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +2 -2
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +4 -4
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +2 -2
- package/ecosystem/plugins/bugx/agents/bugx-worker.md +14 -18
- package/ecosystem/plugins/bugx/agents/bugx.md +45 -49
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +8 -8
- package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +3 -3
- package/interfaces/bin/bugx.js +2 -0
- package/interfaces/cli/bugx_cli/__init__.py +2 -2
- package/interfaces/cli/bugx_cli/cli.py +153 -8
- package/interfaces/cli/bugx_cli/commands/agent.py +568 -136
- package/interfaces/cli/bugx_cli/commands/cloud.py +42 -1
- package/interfaces/cli/bugx_cli/commands/doctor.py +668 -223
- package/interfaces/cli/bugx_cli/commands/guide.py +143 -0
- package/interfaces/cli/bugx_cli/commands/issue.py +262 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +99 -62
- package/interfaces/cli/bugx_cli/commands/plugin.py +301 -60
- package/interfaces/cli/bugx_cli/commands/plugin_antigravity.py +350 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +27 -13
- package/interfaces/cli/bugx_cli/commands/plugin_kimi.py +440 -0
- package/interfaces/cli/bugx_cli/commands/plugin_minimax.py +522 -0
- package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +3 -4
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +4 -5
- package/interfaces/cli/bugx_cli/commands/system.py +75 -5
- package/interfaces/cli/bugx_cli/common.py +135 -15
- package/interfaces/cli/bugx_cli/host_adapters.py +190 -7
- package/interfaces/cli/bugx_cli/hosts/registry.py +6 -3
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +31 -11
- package/interfaces/cli/bugx_cli/infra/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +14 -12
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +76 -10
- package/interfaces/cli/bugx_cli/infra/host_sync.py +66 -1
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +242 -52
- package/package.json +38 -13
- package/pyproject.toml +57 -13
- package/scripts/sync-version.mjs +1 -1
- package/skills/README.md +24 -0
- package/skills/platform/bugx/SKILL.md +50 -0
|
@@ -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
|