@hupan56/wlkj 2.7.12 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +1435 -1107
- package/package.json +29 -29
- package/templates/qoder/agents/insight-planning.md +1 -1
- package/templates/qoder/agents/insight-research.md +28 -15
- package/templates/qoder/commands/optional/wl-insight.md +161 -161
- package/templates/qoder/commands/optional/wl-report.md +20 -39
- package/templates/qoder/commands/optional/wl-status.md +4 -4
- package/templates/qoder/commands/wl-code.md +2 -2
- package/templates/qoder/commands/wl-design.md +6 -6
- package/templates/qoder/commands/wl-init.md +3 -3
- package/templates/qoder/commands/wl-prd.md +26 -13
- package/templates/qoder/commands/wl-req.md +43 -0
- package/templates/qoder/commands/wl-search.md +78 -47
- package/templates/qoder/commands/wl-task.md +343 -40
- package/templates/qoder/commands/wl-test.md +43 -17
- package/templates/qoder/config.yaml +52 -14
- package/templates/qoder/hooks/post-tool-use.py +181 -0
- package/templates/qoder/hooks/session-start.py +94 -23
- package/templates/qoder/hooks/stop-eval.py +207 -0
- package/templates/qoder/hooks/user-prompt-submit.py +139 -0
- package/templates/qoder/rules/wl-pipeline.md +85 -49
- package/templates/qoder/scripts/README.md +102 -0
- package/templates/qoder/scripts/capability/__init__.py +26 -0
- package/templates/qoder/scripts/capability/__main__.py +72 -0
- package/templates/qoder/scripts/capability/adapters/__init__.py +29 -0
- package/templates/qoder/scripts/capability/adapters/cli.py +316 -0
- package/templates/qoder/scripts/capability/adapters/mcp.py +334 -0
- package/templates/qoder/scripts/capability/adapters/qw.py +271 -0
- package/templates/qoder/scripts/capability/caps/__init__.py +27 -0
- package/templates/qoder/scripts/capability/caps/context.py +36 -0
- package/templates/qoder/scripts/capability/caps/cron.py +50 -0
- package/templates/qoder/scripts/capability/caps/identity.py +43 -0
- package/templates/qoder/scripts/capability/caps/memory.py +71 -0
- package/templates/qoder/scripts/capability/caps/notify.py +41 -0
- package/templates/qoder/scripts/capability/caps/present.py +48 -0
- package/templates/qoder/scripts/capability/caps/repo.py +31 -0
- package/templates/qoder/scripts/capability/caps/sandbox.py +43 -0
- package/templates/qoder/scripts/capability/chain.py +92 -0
- package/templates/qoder/scripts/capability/memory_chain.py +41 -0
- package/templates/qoder/scripts/capability/registry.py +246 -0
- package/templates/qoder/scripts/capability/registry_mcp.py +250 -0
- package/templates/qoder/scripts/capability/smoke_test.py +211 -0
- package/templates/qoder/scripts/capability/smoke_test_report.json +94 -0
- package/templates/qoder/scripts/deployment/setup/__init__.py +11 -0
- package/templates/qoder/scripts/deployment/setup/carriers.py +669 -0
- package/templates/qoder/scripts/deployment/setup/carriers_verify.py +148 -0
- package/templates/qoder/scripts/{init_doctor.py → deployment/setup/init_doctor.py} +100 -39
- package/templates/qoder/scripts/{install_qoderwork.py → deployment/setup/install_qoderwork.py} +48 -30
- package/templates/qoder/scripts/{platform_doctor.py → deployment/setup/platform_doctor.py} +271 -259
- package/templates/qoder/scripts/{repo_root.py → deployment/setup/repo_root.py} +9 -2
- package/templates/qoder/scripts/{setup.py → deployment/setup/setup.py} +143 -14
- package/templates/qoder/scripts/{setup_lanhu.py → deployment/setup/setup_lanhu.py} +979 -963
- package/templates/qoder/scripts/domain/design/__init__.py +0 -0
- package/templates/qoder/scripts/{fill_prototype.py → domain/design/fill_prototype.py} +17 -5
- package/templates/qoder/scripts/{gen_design_doc.py → domain/design/gen_design_doc.py} +406 -394
- package/templates/qoder/scripts/domain/kg/__init__.py +11 -0
- package/templates/qoder/scripts/domain/kg/build/__init__.py +0 -0
- package/templates/qoder/scripts/domain/kg/build/build_entity_registry.py +201 -0
- package/templates/qoder/scripts/domain/kg/build/build_relations.py +132 -0
- package/templates/qoder/scripts/{build_style_index.py → domain/kg/build/build_style_index.py} +50 -15
- package/templates/qoder/scripts/domain/kg/build/build_workflows.py +149 -0
- package/templates/qoder/scripts/{kg_build.py → domain/kg/build/kg_build.py} +685 -612
- package/templates/qoder/scripts/{kg_build_db.py → domain/kg/build/kg_build_db.py} +338 -327
- package/templates/qoder/scripts/{kg_incremental.py → domain/kg/build/kg_incremental.py} +425 -393
- package/templates/qoder/scripts/{learn_aggregate.py → domain/kg/build/learn_aggregate.py} +212 -201
- package/templates/qoder/scripts/domain/kg/extract/__init__.py +0 -0
- package/templates/qoder/scripts/{common → domain/kg/extract}/extract.py +430 -419
- package/templates/qoder/scripts/domain/kg/extract/test_extract.py +115 -0
- package/templates/qoder/scripts/{common → domain/kg/extract}/ts_extract.py +614 -536
- package/templates/qoder/scripts/domain/kg/graph/__init__.py +0 -0
- package/templates/qoder/scripts/{kg_link_db.py → domain/kg/graph/kg_link_db.py} +235 -224
- package/templates/qoder/scripts/domain/kg/graph/kg_semantic.py +683 -0
- package/templates/qoder/scripts/{kg.py → domain/kg/kg.py} +871 -708
- package/templates/qoder/scripts/domain/kg/kg_capabilities.py +182 -0
- package/templates/qoder/scripts/domain/kg/search/__init__.py +0 -0
- package/templates/qoder/scripts/{context_pack.py → domain/kg/search/context_pack.py} +45 -17
- package/templates/qoder/scripts/{enrich_prompt.py → domain/kg/search/enrich_prompt.py} +238 -226
- package/templates/qoder/scripts/domain/kg/search/prefetch.py +384 -0
- package/templates/qoder/scripts/{common → domain/kg/search}/search_engine.py +207 -205
- package/templates/qoder/scripts/{search_index.py → domain/kg/search/search_index.py} +210 -88
- package/templates/qoder/scripts/domain/kg/server/__init__.py +0 -0
- package/templates/qoder/scripts/domain/kg/server/kgd.py +549 -0
- package/templates/qoder/scripts/domain/kg/server/perf_bench.py +197 -0
- package/templates/qoder/scripts/domain/kg/storage/__init__.py +0 -0
- package/templates/qoder/scripts/{kg_duckdb.py → domain/kg/storage/kg_duckdb.py} +70 -45
- package/templates/qoder/scripts/domain/learning/__init__.py +0 -0
- package/templates/qoder/scripts/{learn.py → domain/learning/learn.py} +157 -146
- package/templates/qoder/scripts/domain/report/__init__.py +11 -0
- package/templates/qoder/scripts/{add_session.py → domain/report/add_session.py} +256 -244
- package/templates/qoder/scripts/{export.py → domain/report/export.py} +72 -4
- package/templates/qoder/scripts/{report.py → domain/report/report.py} +292 -281
- package/templates/qoder/scripts/domain/report/report_snapshot.py +261 -0
- package/templates/qoder/scripts/domain/report/role.py +39 -0
- package/templates/qoder/scripts/{status.py → domain/report/status.py} +737 -628
- package/templates/qoder/scripts/domain/report/status_snapshot.py +191 -0
- package/templates/qoder/scripts/domain/requirement/__init__.py +0 -0
- package/templates/qoder/scripts/{archive_prd.py → domain/requirement/archive_prd.py} +389 -377
- package/templates/qoder/scripts/domain/requirement/req.py +228 -0
- package/templates/qoder/scripts/domain/task/__init__.py +11 -0
- package/templates/qoder/scripts/{git_sync.py → domain/task/git_sync.py} +90 -50
- package/templates/qoder/scripts/{syncgate.py → domain/task/syncgate.py} +18 -7
- package/templates/qoder/scripts/domain/task/task.py +229 -0
- package/templates/qoder/scripts/domain/task/task_lifecycle.py +606 -0
- package/templates/qoder/scripts/domain/task/task_query.py +162 -0
- package/templates/qoder/scripts/domain/task/task_relations.py +425 -0
- package/templates/qoder/scripts/{team_sync.py → domain/task/team_sync.py} +101 -23
- package/templates/qoder/scripts/domain/task/zentao_sync.py +370 -0
- package/templates/qoder/scripts/foundation/__init__.py +0 -0
- package/templates/qoder/scripts/foundation/bootstrap.py +145 -0
- package/templates/qoder/scripts/foundation/core/__init__.py +0 -0
- package/templates/qoder/scripts/foundation/core/cmd_registry.py +112 -0
- package/templates/qoder/scripts/foundation/core/config.py +187 -0
- package/templates/qoder/scripts/{common → foundation/core}/paths.py +706 -400
- package/templates/qoder/scripts/foundation/data/__init__.py +0 -0
- package/templates/qoder/scripts/foundation/data/contract.py +317 -0
- package/templates/qoder/scripts/{common → foundation/data}/events.py +2 -2
- package/templates/qoder/scripts/foundation/data/result.py +223 -0
- package/templates/qoder/scripts/{common → foundation/data}/task_utils.py +427 -392
- package/templates/qoder/scripts/foundation/identity/__init__.py +0 -0
- package/templates/qoder/scripts/foundation/identity/check_publish.py +103 -0
- package/templates/qoder/scripts/{common → foundation/identity}/developer.py +239 -238
- package/templates/qoder/scripts/foundation/identity/guard.py +159 -0
- package/templates/qoder/scripts/{common → foundation/identity}/identity.py +132 -9
- package/templates/qoder/scripts/foundation/identity/roles.py +60 -0
- package/templates/qoder/scripts/foundation/integrations/__init__.py +0 -0
- package/templates/qoder/scripts/{common → foundation/integrations}/active_task.py +30 -15
- package/templates/qoder/scripts/{common → foundation/integrations}/feishu.py +11 -10
- package/templates/qoder/scripts/{common → foundation/integrations}/terms.py +3 -3
- package/templates/qoder/scripts/foundation/integrations/zentao_client.py +220 -0
- package/templates/qoder/scripts/foundation/io/__init__.py +0 -0
- package/templates/qoder/scripts/{common → foundation/io}/filelock.py +1 -1
- package/templates/qoder/scripts/{common → foundation/io}/reqid.py +1 -1
- package/templates/qoder/scripts/foundation/protocol/__init__.py +0 -0
- package/templates/qoder/scripts/foundation/protocol/duckdb_conn.py +39 -0
- package/templates/qoder/scripts/foundation/protocol/mcp_base.py +268 -0
- package/templates/qoder/scripts/foundation/utils/__init__.py +0 -0
- package/templates/qoder/scripts/{common → foundation/utils}/eval_api.py +12 -1
- package/templates/qoder/scripts/{common → foundation/utils}/pip_install.py +23 -6
- package/templates/qoder/scripts/{common → foundation/utils}/platform_guard.py +1 -1
- package/templates/qoder/scripts/orchestration/__init__.py +0 -0
- package/templates/qoder/scripts/orchestration/wlkj.py +185 -0
- package/templates/qoder/scripts/protocol/__init__.py +0 -0
- package/templates/qoder/scripts/protocol/browser/README.md +207 -0
- package/templates/qoder/scripts/protocol/browser/SKILL.md +265 -0
- package/templates/qoder/scripts/protocol/browser/config.env +9 -0
- package/templates/qoder/scripts/protocol/browser/references/cdp-api.md +110 -0
- package/templates/qoder/scripts/protocol/browser/references/migration-2.5.3.md +72 -0
- package/templates/qoder/scripts/protocol/browser/references/site-patterns/.gitkeep +0 -0
- package/templates/qoder/scripts/protocol/browser/scripts/browser-discovery.mjs +138 -0
- package/templates/qoder/scripts/protocol/browser/scripts/cdp-proxy.mjs +672 -0
- package/templates/qoder/scripts/protocol/browser/scripts/check-deps.mjs +206 -0
- package/templates/qoder/scripts/protocol/browser/scripts/find-url.mjs +253 -0
- package/templates/qoder/scripts/protocol/browser/scripts/match-site.mjs +46 -0
- package/templates/qoder/scripts/protocol/browser/templates/config.env.template +9 -0
- package/templates/qoder/scripts/protocol/mcp/__init__.py +11 -0
- package/templates/qoder/scripts/protocol/mcp/kg_mcp_server.py +478 -0
- package/templates/qoder/scripts/{lanhu_stdio_wrapper.py → protocol/mcp/lanhu_stdio_wrapper.py} +131 -119
- package/templates/qoder/scripts/protocol/mcp/mcp_doctor.py +548 -0
- package/templates/qoder/scripts/protocol/mcp/mcp_launcher.py +600 -0
- package/templates/qoder/scripts/protocol/mcp/mysql_mcp_server.py +461 -0
- package/templates/qoder/scripts/protocol/mcp/zentao_mcp_server.py +1920 -0
- package/templates/qoder/scripts/protocol/transports/__init__.py +56 -0
- package/templates/qoder/scripts/protocol/transports/base.py +87 -0
- package/templates/qoder/scripts/protocol/transports/cli.py +132 -0
- package/templates/qoder/scripts/protocol/transports/http.py +141 -0
- package/templates/qoder/scripts/protocol/transports/stdio.py +293 -0
- package/templates/qoder/scripts/run_weekly_update.bat +27 -18
- package/templates/qoder/scripts/run_weekly_update.sh +22 -13
- package/templates/qoder/scripts/validation/__init__.py +0 -0
- package/templates/qoder/scripts/validation/eval/__init__.py +0 -0
- package/templates/qoder/scripts/validation/eval/perf-report-2026-06-24.md +139 -0
- package/templates/qoder/scripts/validation/eval/qwork_harness.py +617 -0
- package/templates/qoder/scripts/validation/eval/report-commands.md +220 -0
- package/templates/qoder/scripts/validation/eval/transcript_timing.py +386 -0
- package/templates/qoder/scripts/validation/metrics/__init__.py +0 -0
- package/templates/qoder/scripts/{eval_prd.py → validation/metrics/eval_prd.py} +84 -15
- package/templates/qoder/scripts/validation/metrics/usability_score.py +750 -0
- package/templates/qoder/scripts/validation/test/__init__.py +11 -0
- package/templates/qoder/scripts/validation/test/assertion_gen.py +551 -0
- package/templates/qoder/scripts/{autotest.py → validation/test/autotest.py} +1234 -1751
- package/templates/qoder/scripts/validation/test/autotest_auth.py +109 -0
- package/templates/qoder/scripts/{autotest_batch.py → validation/test/autotest_batch.py} +255 -224
- package/templates/qoder/scripts/validation/test/autotest_data.py +680 -0
- package/templates/qoder/scripts/validation/test/autotest_opencli.py +646 -0
- package/templates/qoder/scripts/{autotest_run.py → validation/test/autotest_run.py} +323 -297
- package/templates/qoder/scripts/validation/test/autotest_webaccess.py +571 -0
- package/templates/qoder/scripts/{benchmark.py → validation/test/benchmark.py} +17 -5
- package/templates/qoder/scripts/{kg_auto_login.py → validation/test/kg_auto_login.py} +208 -196
- package/templates/qoder/scripts/{kg_test_runner.py → validation/test/kg_test_runner.py} +13 -2
- package/templates/qoder/scripts/{page_probe.py → validation/test/page_probe.py} +470 -459
- package/templates/qoder/scripts/validation/test/smoke_all_commands.py +170 -0
- package/templates/qoder/settings.json +23 -2
- package/templates/qoder/skills/design-import/SKILL.md +235 -226
- package/templates/qoder/skills/design-review/SKILL.md +91 -82
- package/templates/qoder/skills/prd-generator/SKILL.md +38 -24
- package/templates/qoder/skills/prd-review/SKILL.md +8 -6
- package/templates/qoder/skills/prototype-generator/SKILL.md +296 -247
- package/templates/qoder/skills/spec-coder/SKILL.md +24 -15
- package/templates/qoder/skills/spec-generator/SKILL.md +24 -12
- package/templates/qoder/skills/test-generator/SKILL.md +9 -7
- package/templates/qoder/skills/wl-code/SKILL.md +25 -13
- package/templates/qoder/skills/wl-commit/SKILL.md +10 -9
- package/templates/qoder/skills/wl-design/SKILL.md +7 -5
- package/templates/qoder/skills/wl-init/SKILL.md +8 -8
- package/templates/qoder/skills/wl-insight/SKILL.md +25 -12
- package/templates/qoder/skills/wl-prd-full/SKILL.md +59 -8
- package/templates/qoder/skills/wl-prd-quick/SKILL.md +7 -7
- package/templates/qoder/skills/wl-prd-review/SKILL.md +18 -6
- package/templates/qoder/skills/wl-report/SKILL.md +27 -25
- package/templates/qoder/skills/wl-search/SKILL.md +151 -80
- package/templates/qoder/skills/wl-spec/SKILL.md +9 -7
- package/templates/qoder/skills/wl-status/SKILL.md +50 -18
- package/templates/qoder/skills/wl-task/SKILL.md +94 -12
- package/templates/qoder/skills/wl-test/SKILL.md +154 -45
- package/templates/qoder/templates/prd-full-template.md +7 -0
- package/templates/root/AGENTS.md +275 -237
- package/templates/root/requirements.txt +3 -0
- package/templates/root//344/275/277/347/224/250/350/257/264/346/230/216.md +3 -3
- package/templates/root//346/226/260/346/211/213/346/214/207/345/215/227.md +2 -2
- package/templates/qoder/hooks/inject-workflow-state.py +0 -169
- package/templates/qoder/scripts/__pycache__/check_mcp_launch.cpython-39.pyc +0 -0
- package/templates/qoder/scripts/__pycache__/install_qoderwork.cpython-39.pyc +0 -0
- package/templates/qoder/scripts/__pycache__/mcp_launcher.cpython-39.pyc +0 -0
- package/templates/qoder/scripts/__pycache__/platform_doctor.cpython-39.pyc +0 -0
- package/templates/qoder/scripts/check_carriers.py +0 -238
- package/templates/qoder/scripts/check_mcp.py +0 -298
- package/templates/qoder/scripts/check_mcp_launch.py +0 -183
- package/templates/qoder/scripts/check_qoderwork_consistency.py +0 -166
- package/templates/qoder/scripts/collect_prds.py +0 -31
- package/templates/qoder/scripts/common/mentions.py +0 -134
- package/templates/qoder/scripts/common/utf8.py +0 -38
- package/templates/qoder/scripts/extract_api_params.py +0 -246
- package/templates/qoder/scripts/extract_routes.py +0 -54
- package/templates/qoder/scripts/extract_routes_tree.py +0 -78
- package/templates/qoder/scripts/handoff.py +0 -22
- package/templates/qoder/scripts/init_developer.py +0 -76
- package/templates/qoder/scripts/kg_mcp_server.py +0 -801
- package/templates/qoder/scripts/kg_semantic.py +0 -150
- package/templates/qoder/scripts/mcp_launcher.py +0 -414
- package/templates/qoder/scripts/mysql_mcp_server.py +0 -396
- package/templates/qoder/scripts/parse_prds.py +0 -33
- package/templates/qoder/scripts/role.py +0 -51
- package/templates/qoder/scripts/sync_carriers.py +0 -259
- package/templates/qoder/scripts/task.py +0 -1261
- package/templates/qoder/scripts/workspace_init.py +0 -102
- package/templates/qoder/scripts/zentao_mcp_server.py +0 -424
- package/templates/qoder/skills/prompt-enrich/SKILL.md +0 -90
- /package/templates/qoder/scripts/{common → deployment}/__init__.py +0 -0
- /package/templates/qoder/{skills/prototype-generator/SKILL.md.zcode-79180-2af4721f-f9a6-412c-88db-c0af680d211b.tmp → scripts/domain/__init__.py} +0 -0
- /package/templates/qoder/scripts/{common → domain/kg/graph}/graph_traverse.py +0 -0
- /package/templates/qoder/scripts/{common → domain/kg/server}/repowiki.py +0 -0
- /package/templates/qoder/scripts/{common → foundation/io}/atomicio.py +0 -0
- /package/templates/qoder/scripts/{secure-ls.js → validation/test/secure-ls.js} +0 -0
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""mcp_doctor.py - MCP 诊断 (Facade 外观模式)
|
|
4
|
+
|
|
5
|
+
v3.0 合并自: check_mcp(启动条件) + check_mcp_launch(实际启动)。
|
|
6
|
+
两者都是"MCP诊断"一个职责的两个阶段, 对外应是1个命令的子操作。
|
|
7
|
+
|
|
8
|
+
用法:
|
|
9
|
+
python mcp_doctor.py conditions [--fix] 启动条件检查 (依赖/配置/mcp.json)
|
|
10
|
+
python mcp_doctor.py launch 实际启动诊断 (逐个发initialize看谁黄)
|
|
11
|
+
"""
|
|
12
|
+
# v3.0 路径自举: 引导到 common/bootstrap, 统一 sys.path 逻辑
|
|
13
|
+
import os as _o, sys as _s
|
|
14
|
+
_f = _o.path.abspath(__file__)
|
|
15
|
+
for _ in range(10):
|
|
16
|
+
_f = _o.path.dirname(_f)
|
|
17
|
+
_cp = _o.path.join(_f, 'foundation')
|
|
18
|
+
if _o.path.isfile(_o.path.join(_cp, 'bootstrap.py')):
|
|
19
|
+
break
|
|
20
|
+
if _cp not in _s.path: _s.path.insert(0, _cp)
|
|
21
|
+
from bootstrap import setup; setup()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# ==================== 来自 check_mcp.py (启动条件检查) ====================
|
|
26
|
+
"""
|
|
27
|
+
check_mcp.py - MCP 启动健康检查 (验证 init/download 后全系列可用)
|
|
28
|
+
|
|
29
|
+
为什么需要它:
|
|
30
|
+
install_qoderwork.py --mcp-only 会写 mcp.json + launcher, 但"写了配置"不等于
|
|
31
|
+
"MCP 能起来"。50 人里有人 pip 没装齐、有人 .repo-root 写错、有人 lanhu venv 没建,
|
|
32
|
+
这些都要等用的时候才发现 MCP 挂了。本脚本主动验证每个 MCP 能否真正启动。
|
|
33
|
+
|
|
34
|
+
对应需求: "确保 MCP 等 init/download 后, 所有人 qoder 全系列正常运行"。
|
|
35
|
+
|
|
36
|
+
检查什么 (不真启动 server, 只验证启动条件):
|
|
37
|
+
1. mcp.json 存在 + 各 server 注册了 launcher 模式
|
|
38
|
+
2. launcher 能定位仓库根 (.repo-root 锚点 / 环境变量 / 向上找)
|
|
39
|
+
3. 各 MCP 的依赖就绪:
|
|
40
|
+
- kg: 装了 duckdb 的 Python + kg_mcp_server.py 存在
|
|
41
|
+
- mysql: 装了 pymysql 的 Python + config.yaml 有 mysql 段
|
|
42
|
+
- lanhu: venv 建了 + 当前角色 cookie 配了
|
|
43
|
+
- playwright: node 在 + cli.js / npx 可用
|
|
44
|
+
|
|
45
|
+
Usage:
|
|
46
|
+
python .qoder/scripts/check_mcp.py # 全量检查
|
|
47
|
+
python .qoder/scripts/check_mcp.py --fix # 检查 + 尝试修复 (.repo-root 等)
|
|
48
|
+
Exit: 0 = 全部就绪, 1 = 有 MCP 未就绪
|
|
49
|
+
"""
|
|
50
|
+
import json
|
|
51
|
+
import os
|
|
52
|
+
import subprocess
|
|
53
|
+
import sys
|
|
54
|
+
from pathlib import Path
|
|
55
|
+
|
|
56
|
+
if sys.platform == 'win32':
|
|
57
|
+
try:
|
|
58
|
+
sys.stdout.reconfigure(encoding='utf-8')
|
|
59
|
+
except (AttributeError, IOError):
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
63
|
+
from foundation.core.paths import get_repo_root
|
|
64
|
+
|
|
65
|
+
BASE = get_repo_root()
|
|
66
|
+
HOME = Path(os.environ.get('USERPROFILE') or os.path.expanduser('~'))
|
|
67
|
+
QODERWORK_DIR = HOME / '.qoderwork'
|
|
68
|
+
MCP_FILE = QODERWORK_DIR / 'mcp.json'
|
|
69
|
+
REPO_ROOT_ANCHOR = QODERWORK_DIR / '.repo-root'
|
|
70
|
+
|
|
71
|
+
OK_TAG = '[OK] '
|
|
72
|
+
WARN_TAG = '[WARN]'
|
|
73
|
+
MISS_TAG = '[MISS]'
|
|
74
|
+
BAD_TAG = '[BAD] '
|
|
75
|
+
|
|
76
|
+
issues = []
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def say(tag, msg):
|
|
80
|
+
print('{} {}'.format(tag, msg))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def problem(msg, hint=None):
|
|
84
|
+
issues.append(msg)
|
|
85
|
+
say(BAD_TAG, msg)
|
|
86
|
+
if hint:
|
|
87
|
+
print(' -> ' + hint)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _run(cmd, timeout=10):
|
|
91
|
+
"""跑命令, 返回 (returncode, output)。"""
|
|
92
|
+
try:
|
|
93
|
+
r = subprocess.run(cmd, capture_output=True, text=True,
|
|
94
|
+
encoding='utf-8', errors='replace', timeout=timeout)
|
|
95
|
+
return r.returncode, (r.stdout or '') + (r.stderr or '')
|
|
96
|
+
except (subprocess.TimeoutExpired, FileNotFoundError, OSError):
|
|
97
|
+
return 1, ''
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _find_python_with(mod):
|
|
101
|
+
"""找一个装了指定模块的 Python。返回路径或 None。"""
|
|
102
|
+
# 当前 Python
|
|
103
|
+
try:
|
|
104
|
+
__import__(mod)
|
|
105
|
+
return sys.executable
|
|
106
|
+
except ImportError:
|
|
107
|
+
pass
|
|
108
|
+
# 其他 Python
|
|
109
|
+
import shutil
|
|
110
|
+
for name in ('python', 'python3', 'py'):
|
|
111
|
+
p = shutil.which(name)
|
|
112
|
+
if p and p != sys.executable:
|
|
113
|
+
rc, _ = _run([p, '-c', 'import %s' % mod], timeout=8)
|
|
114
|
+
if rc == 0:
|
|
115
|
+
return p
|
|
116
|
+
return None
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
# ============================================================
|
|
120
|
+
# 检查项
|
|
121
|
+
# ============================================================
|
|
122
|
+
|
|
123
|
+
def check_mcp_json(fix=False):
|
|
124
|
+
"""1. mcp.json 存在 + launcher 模式。"""
|
|
125
|
+
print('\n--- 1. mcp.json 配置 ---')
|
|
126
|
+
if not MCP_FILE.is_file():
|
|
127
|
+
problem('mcp.json 不存在 (%s)' % MCP_FILE,
|
|
128
|
+
'跑: python .qoder/scripts/install_qoderwork.py --mcp-only')
|
|
129
|
+
return False
|
|
130
|
+
try:
|
|
131
|
+
cfg = json.loads(MCP_FILE.read_text(encoding='utf-8'))
|
|
132
|
+
except (ValueError, OSError):
|
|
133
|
+
problem('mcp.json 解析失败', '文件损坏, 重跑 install_qoderwork.py --mcp-only')
|
|
134
|
+
return False
|
|
135
|
+
servers = cfg.get('mcpServers', {})
|
|
136
|
+
if not servers:
|
|
137
|
+
problem('mcp.json 无 mcpServers', '重跑 install_qoderwork.py --mcp-only')
|
|
138
|
+
return False
|
|
139
|
+
say(OK_TAG, 'mcp.json 存在, 注册了 %d 个 server: %s' % (
|
|
140
|
+
len(servers), ', '.join(servers.keys())))
|
|
141
|
+
# 检查是否 launcher 模式 (command 用 mcp_launcher.py)
|
|
142
|
+
launcher_count = 0
|
|
143
|
+
for name, entry in servers.items():
|
|
144
|
+
args = entry.get('args', []) if isinstance(entry, dict) else []
|
|
145
|
+
if any('mcp_launcher.py' in str(a) for a in args):
|
|
146
|
+
launcher_count += 1
|
|
147
|
+
if launcher_count > 0:
|
|
148
|
+
say(OK_TAG, '%d 个 server 用 launcher 模式 (跨机器通用)' % launcher_count)
|
|
149
|
+
else:
|
|
150
|
+
say(WARN_TAG, '无 launcher 模式 server (可能写死路径), 升级: install_qoderwork.py --mcp-only')
|
|
151
|
+
return True
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def check_repo_root(fix=False):
|
|
155
|
+
"""2. launcher 能定位仓库根 (.repo-root 锚点)。"""
|
|
156
|
+
print('\n--- 2. 仓库根定位 ---')
|
|
157
|
+
if REPO_ROOT_ANCHOR.is_file():
|
|
158
|
+
try:
|
|
159
|
+
root_val = REPO_ROOT_ANCHOR.read_text(encoding='utf-8').strip()
|
|
160
|
+
if (Path(root_val) / '.qoder' / 'scripts').is_dir():
|
|
161
|
+
say(OK_TAG, '.repo-root 锚点正确: %s' % root_val)
|
|
162
|
+
return True
|
|
163
|
+
else:
|
|
164
|
+
problem('.repo-root 指向的目录不是仓库根: %s' % root_val,
|
|
165
|
+
'重跑 install_qoderwork.py --mcp-only 会用 PROJECT_ROOT 修正')
|
|
166
|
+
except OSError:
|
|
167
|
+
pass
|
|
168
|
+
# 锚点缺失或错误
|
|
169
|
+
if fix:
|
|
170
|
+
try:
|
|
171
|
+
REPO_ROOT_ANCHOR.parent.mkdir(parents=True, exist_ok=True)
|
|
172
|
+
REPO_ROOT_ANCHOR.write_text(str(BASE), encoding='utf-8')
|
|
173
|
+
say(OK_TAG, '.repo-root 锚点已修复: %s -> %s' % (REPO_ROOT_ANCHOR, BASE))
|
|
174
|
+
return True
|
|
175
|
+
except OSError as e:
|
|
176
|
+
problem('修复 .repo-root 失败: %s' % e)
|
|
177
|
+
else:
|
|
178
|
+
problem('.repo-root 锚点缺失或错误',
|
|
179
|
+
'加 --fix 自动修复, 或重跑 install_qoderwork.py --mcp-only')
|
|
180
|
+
return False
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def check_launcher_file(fix=False):
|
|
184
|
+
"""3. launcher 脚本存在于 ~/.qoderwork/。"""
|
|
185
|
+
print('\n--- 3. MCP launcher ---')
|
|
186
|
+
launcher = QODERWORK_DIR / 'mcp_launcher.py'
|
|
187
|
+
if launcher.is_file():
|
|
188
|
+
say(OK_TAG, 'launcher 存在: %s' % launcher)
|
|
189
|
+
return True
|
|
190
|
+
problem('launcher 不存在: %s' % launcher,
|
|
191
|
+
'重跑 install_qoderwork.py --mcp-only (会复制 launcher)')
|
|
192
|
+
return False
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def check_kg():
|
|
196
|
+
"""4. kg MCP: duckdb + kg_mcp_server.py。"""
|
|
197
|
+
print('\n--- 4. 知识图谱 MCP (kg) ---')
|
|
198
|
+
server = BASE / '.qoder' / 'scripts' / 'protocol' / 'mcp' / 'kg_mcp_server.py'
|
|
199
|
+
if not server.is_file():
|
|
200
|
+
problem('kg_mcp_server.py 不存在', '引擎不完整, 重跑 npx wlkj update')
|
|
201
|
+
return
|
|
202
|
+
py = _find_python_with('duckdb')
|
|
203
|
+
if py:
|
|
204
|
+
say(OK_TAG, 'kg 就绪 (python=%s, 装了 duckdb)' % py)
|
|
205
|
+
else:
|
|
206
|
+
problem('找不到装了 duckdb 的 Python',
|
|
207
|
+
'pip install duckdb 或 npx @hupan56/wlkj install-env')
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def check_mysql():
|
|
211
|
+
"""5. mysql MCP: pymysql + config.yaml mysql 段。"""
|
|
212
|
+
print('\n--- 5. MySQL MCP ---')
|
|
213
|
+
server = BASE / '.qoder' / 'scripts' / 'protocol' / 'mcp' / 'mysql_mcp_server.py'
|
|
214
|
+
if not server.is_file():
|
|
215
|
+
problem('mysql_mcp_server.py 不存在')
|
|
216
|
+
return
|
|
217
|
+
py = _find_python_with('pymysql')
|
|
218
|
+
if not py:
|
|
219
|
+
problem('找不到装了 pymysql 的 Python', 'pip install pymysql')
|
|
220
|
+
return
|
|
221
|
+
# config.yaml mysql 段
|
|
222
|
+
cfg_path = BASE / '.qoder' / 'config.yaml'
|
|
223
|
+
has_mysql = False
|
|
224
|
+
if cfg_path.is_file():
|
|
225
|
+
try:
|
|
226
|
+
import yaml
|
|
227
|
+
d = yaml.safe_load(cfg_path.read_text(encoding='utf-8')) or {}
|
|
228
|
+
has_mysql = bool(d.get('mysql', {}).get('host'))
|
|
229
|
+
except Exception:
|
|
230
|
+
pass
|
|
231
|
+
if has_mysql:
|
|
232
|
+
say(OK_TAG, 'mysql 就绪 (config.yaml 已配连接信息)')
|
|
233
|
+
else:
|
|
234
|
+
say(WARN_TAG, 'mysql 依赖就绪, 但 config.yaml 无 mysql 段 (按需配)')
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def check_zentao():
|
|
238
|
+
"""6. zentao MCP: requests + zentao_mcp_server.py + 个人凭据。"""
|
|
239
|
+
print('\n--- 6. 禅道 MCP (zentao) ---')
|
|
240
|
+
server = BASE / '.qoder' / 'scripts' / 'protocol' / 'mcp' / 'zentao_mcp_server.py'
|
|
241
|
+
if not server.is_file():
|
|
242
|
+
problem('zentao_mcp_server.py 不存在')
|
|
243
|
+
return
|
|
244
|
+
py = _find_python_with('requests')
|
|
245
|
+
if not py:
|
|
246
|
+
problem('找不到装了 requests 的 Python', 'pip install requests')
|
|
247
|
+
return
|
|
248
|
+
# 个人凭据 (每人一个禅道账号, 从 .private/secrets/zentao.env 读)
|
|
249
|
+
try:
|
|
250
|
+
from foundation.core.paths import get_developer, get_secrets_dir
|
|
251
|
+
dev = get_developer(BASE)
|
|
252
|
+
except Exception:
|
|
253
|
+
dev = None
|
|
254
|
+
if not dev:
|
|
255
|
+
say(WARN_TAG, 'zentao 依赖就绪, 但未初始化开发者 (跑 /wl-init)')
|
|
256
|
+
return
|
|
257
|
+
env_file = Path(get_secrets_dir(dev)) / 'zentao.env'
|
|
258
|
+
if env_file.is_file():
|
|
259
|
+
say(OK_TAG, 'zentao 就绪 (角色=%s, 凭据已配)' % dev)
|
|
260
|
+
else:
|
|
261
|
+
say(WARN_TAG, 'zentao 依赖就绪, 但角色 %s 的凭据未配 (%s)' % (dev, env_file))
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def check_lanhu():
|
|
265
|
+
"""7. lanhu MCP: venv + cookie。三态 (就绪/未装/未配)。"""
|
|
266
|
+
print('\n--- 7. 蓝湖 MCP (lanhu, 可选) ---')
|
|
267
|
+
venv = BASE / 'external' / 'lanhu-mcp' / '.venv'
|
|
268
|
+
server = BASE / 'external' / 'lanhu-mcp' / 'lanhu_mcp_server.py'
|
|
269
|
+
if not venv.is_dir() or not server.is_file():
|
|
270
|
+
say(WARN_TAG, 'lanhu 未安装 (团队不用蓝湖可忽略; 用的话: setup_lanhu.py)')
|
|
271
|
+
return
|
|
272
|
+
# venv python
|
|
273
|
+
venv_py = venv / ('Scripts' if sys.platform == 'win32' else 'bin') / ('python.exe' if sys.platform == 'win32' else 'python')
|
|
274
|
+
if not venv_py.is_file():
|
|
275
|
+
problem('lanhu venv python 不存在', '重装: setup_lanhu.py')
|
|
276
|
+
return
|
|
277
|
+
# 当前角色 cookie
|
|
278
|
+
try:
|
|
279
|
+
from foundation.core.paths import get_developer
|
|
280
|
+
dev = get_developer(BASE)
|
|
281
|
+
except Exception:
|
|
282
|
+
dev = None
|
|
283
|
+
if not dev:
|
|
284
|
+
say(WARN_TAG, 'lanhu venv 就绪, 但未初始化开发者 (跑 /wl-init)')
|
|
285
|
+
return
|
|
286
|
+
cookie_file = BASE / 'workspace' / 'members' / dev / '.secrets' / 'lanhu.env'
|
|
287
|
+
if cookie_file.is_file():
|
|
288
|
+
say(OK_TAG, 'lanhu 就绪 (角色=%s, cookie 已配)' % dev)
|
|
289
|
+
else:
|
|
290
|
+
say(WARN_TAG, 'lanhu venv 就绪, 但角色 %s 的 cookie 未配 (%s)' % (dev, cookie_file))
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def check_playwright():
|
|
294
|
+
"""8. playwright MCP: node + cli.js/npx。"""
|
|
295
|
+
print('\n--- 8. Playwright MCP (浏览器测试) ---')
|
|
296
|
+
import shutil
|
|
297
|
+
node = shutil.which('node')
|
|
298
|
+
if not node:
|
|
299
|
+
problem('node 未安装 (playwright MCP 需要)', '装 Node.js: npx wlkj install-env')
|
|
300
|
+
return
|
|
301
|
+
# 优先 cli.js (快), 回退 npx (慢)
|
|
302
|
+
try:
|
|
303
|
+
out = subprocess.run('npm root -g', shell=True, capture_output=True,
|
|
304
|
+
text=True, timeout=10)
|
|
305
|
+
root = out.stdout.strip()
|
|
306
|
+
cli = os.path.join(root, '@playwright', 'mcp', 'cli.js')
|
|
307
|
+
if os.path.isfile(cli):
|
|
308
|
+
say(OK_TAG, 'playwright 就绪 (node + cli.js, 快启动)')
|
|
309
|
+
return
|
|
310
|
+
except Exception:
|
|
311
|
+
pass
|
|
312
|
+
if shutil.which('npx'):
|
|
313
|
+
say(WARN_TAG, 'playwright 可用但走 npx (冷启动慢, 可能被 QoderWork 超时杀)')
|
|
314
|
+
say(WARN_TAG, ' 建议全局装: npm i -g @playwright/mcp')
|
|
315
|
+
else:
|
|
316
|
+
problem('npx 不可用', '装 Node.js')
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def main_conditions():
|
|
320
|
+
fix = '--fix' in sys.argv
|
|
321
|
+
print('=' * 56)
|
|
322
|
+
print('MCP 健康检查 (验证 init/download 后全系列可用)')
|
|
323
|
+
print('=' * 56)
|
|
324
|
+
|
|
325
|
+
check_mcp_json(fix)
|
|
326
|
+
check_repo_root(fix)
|
|
327
|
+
check_launcher_file(fix)
|
|
328
|
+
check_kg()
|
|
329
|
+
check_mysql()
|
|
330
|
+
check_zentao()
|
|
331
|
+
check_lanhu()
|
|
332
|
+
check_playwright()
|
|
333
|
+
|
|
334
|
+
print('\n' + '=' * 56)
|
|
335
|
+
if issues:
|
|
336
|
+
print('未就绪 (%d):' % len(issues))
|
|
337
|
+
for i in issues:
|
|
338
|
+
print(' - ' + i)
|
|
339
|
+
print('=' * 56)
|
|
340
|
+
print('一键修复: python .qoder/scripts/check_mcp.py --fix')
|
|
341
|
+
print('重配 MCP: python .qoder/scripts/install_qoderwork.py --mcp-only')
|
|
342
|
+
return 1
|
|
343
|
+
print('所有 MCP 就绪, Qoder 全系列可正常调用。')
|
|
344
|
+
print('=' * 56)
|
|
345
|
+
return 0
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
# ==================== 实际启动诊断 (原 check_mcp_launch.py 合并而来) ====================
|
|
351
|
+
"""
|
|
352
|
+
mcp_doctor.py - 诊断 MCP 为什么黄色
|
|
353
|
+
|
|
354
|
+
逐个模拟 mcp_launcher.py 启动每个 MCP, 发送 initialize 请求,
|
|
355
|
+
看哪个 MCP 启动失败/崩溃/不响应。输出明确的诊断结论。
|
|
356
|
+
|
|
357
|
+
用法: python .qoder/scripts/protocol/mcp/mcp_doctor.py
|
|
358
|
+
"""
|
|
359
|
+
import json
|
|
360
|
+
import os
|
|
361
|
+
import subprocess
|
|
362
|
+
import sys
|
|
363
|
+
from pathlib import Path
|
|
364
|
+
|
|
365
|
+
SCRIPTS_DIR = get_repo_root()
|
|
366
|
+
BASE = get_repo_root() # repo root (统一用 foundation 定位, 不手算 parent)
|
|
367
|
+
|
|
368
|
+
MCP_NAMES = ['kg', 'mysql', 'zentao', 'lanhu']
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def find_python_with(mod):
|
|
372
|
+
"""找一个能 import mod 的 python."""
|
|
373
|
+
for py in [sys.executable, 'python', 'python3']:
|
|
374
|
+
try:
|
|
375
|
+
r = subprocess.run([py, '-c', f'import {mod}'],
|
|
376
|
+
capture_output=True, timeout=8)
|
|
377
|
+
if r.returncode == 0:
|
|
378
|
+
return py
|
|
379
|
+
except Exception:
|
|
380
|
+
continue
|
|
381
|
+
return None
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def test_mcp(name):
|
|
385
|
+
"""测试一个 MCP 能否正常响应 initialize."""
|
|
386
|
+
launcher = SCRIPTS_DIR / 'mcp_launcher.py'
|
|
387
|
+
if not launcher.is_file():
|
|
388
|
+
return {'name': name, 'status': 'ERROR',
|
|
389
|
+
'detail': f'launcher 不存在: {launcher}'}
|
|
390
|
+
|
|
391
|
+
init_req = json.dumps({
|
|
392
|
+
'jsonrpc': '2.0', 'id': 1, 'method': 'initialize',
|
|
393
|
+
'params': {'capabilities': {}, 'protocolVersion': '2024-11-05',
|
|
394
|
+
'clientInfo': {'name': 'diag', 'version': '1.0'}}
|
|
395
|
+
}) + '\n'
|
|
396
|
+
|
|
397
|
+
try:
|
|
398
|
+
r = subprocess.run(
|
|
399
|
+
[sys.executable, str(launcher), name],
|
|
400
|
+
input=init_req,
|
|
401
|
+
capture_output=True, text=True, timeout=10,
|
|
402
|
+
cwd=str(BASE), encoding='utf-8', errors='replace'
|
|
403
|
+
)
|
|
404
|
+
except subprocess.TimeoutExpired:
|
|
405
|
+
return {'name': name, 'status': 'TIMEOUT',
|
|
406
|
+
'detail': '启动后 10s 无响应 (可能卡在等 stdin)'}
|
|
407
|
+
except Exception as e:
|
|
408
|
+
return {'name': name, 'status': 'ERROR',
|
|
409
|
+
'detail': f'启动异常: {e}'}
|
|
410
|
+
|
|
411
|
+
stdout = r.stdout or ''
|
|
412
|
+
stderr = r.stderr or ''
|
|
413
|
+
|
|
414
|
+
# 解析 stdout 找 initialize 响应
|
|
415
|
+
init_ok = False
|
|
416
|
+
disabled = False
|
|
417
|
+
reason = ''
|
|
418
|
+
for line in stdout.split('\n'):
|
|
419
|
+
line = line.strip()
|
|
420
|
+
if not line:
|
|
421
|
+
continue
|
|
422
|
+
try:
|
|
423
|
+
resp = json.loads(line)
|
|
424
|
+
if resp.get('id') == 1 and 'result' in resp:
|
|
425
|
+
init_ok = True
|
|
426
|
+
si = resp['result'].get('serverInfo', {})
|
|
427
|
+
ver = si.get('version', '')
|
|
428
|
+
if 'disabled' in ver:
|
|
429
|
+
disabled = True
|
|
430
|
+
reason = si.get('reason', '')
|
|
431
|
+
break
|
|
432
|
+
except json.JSONDecodeError:
|
|
433
|
+
continue
|
|
434
|
+
|
|
435
|
+
if init_ok and not disabled:
|
|
436
|
+
return {'name': name, 'status': 'OK',
|
|
437
|
+
'detail': '正常启动, 工具可用'}
|
|
438
|
+
elif init_ok and disabled:
|
|
439
|
+
return {'name': name, 'status': 'DISABLED',
|
|
440
|
+
'detail': f'以"未启用"模式启动 (绿但0工具): {reason}'}
|
|
441
|
+
elif r.returncode != 0:
|
|
442
|
+
# 进程崩溃了
|
|
443
|
+
return {'name': name, 'status': 'CRASHED',
|
|
444
|
+
'detail': f'进程退出(rc={r.returncode})。stderr:\n{stderr[-500:]}'}
|
|
445
|
+
else:
|
|
446
|
+
return {'name': name, 'status': 'NO_RESPONSE',
|
|
447
|
+
'detail': f'没崩溃但没响应 initialize。stdout:\n{stdout[-300:]}\nstderr:\n{stderr[-300:]}'}
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def main_launch():
|
|
451
|
+
print('=' * 56)
|
|
452
|
+
print('MCP 启动诊断')
|
|
453
|
+
print(f'仓库: {BASE}')
|
|
454
|
+
print(f'Python: {sys.executable} ({sys.version.split()[0]})')
|
|
455
|
+
print('=' * 56)
|
|
456
|
+
|
|
457
|
+
# 基础检查
|
|
458
|
+
print('\n--- 环境检查 ---')
|
|
459
|
+
for mod, label in [('duckdb', 'kg 依赖'), ('pymysql', 'mysql 依赖'),
|
|
460
|
+
('requests', 'zentao 依赖'), ('yaml', '配置解析')]:
|
|
461
|
+
try:
|
|
462
|
+
__import__(mod)
|
|
463
|
+
print(f' [OK] {mod} ({label})')
|
|
464
|
+
except ImportError:
|
|
465
|
+
py = find_python_with(mod)
|
|
466
|
+
if py:
|
|
467
|
+
print(f' [WARN] {mod} 在当前Python没有, 但 {py} 有')
|
|
468
|
+
else:
|
|
469
|
+
print(f' [MISS] {mod} ({label}) — pip install {mod}')
|
|
470
|
+
|
|
471
|
+
kg_path = BASE / 'data' / 'index' / 'kg.duckdb'
|
|
472
|
+
print(f'\n kg.duckdb: {"存在" if kg_path.is_file() else "缺失 (git pull 失败? 非管理员跑 team_sync pull)"}')
|
|
473
|
+
|
|
474
|
+
# mcp.json 检查
|
|
475
|
+
home = Path(os.environ.get('USERPROFILE') or os.path.expanduser('~'))
|
|
476
|
+
mcp_file = home / '.qoderwork' / 'mcp.json'
|
|
477
|
+
print(f'\n mcp.json: {mcp_file}')
|
|
478
|
+
if mcp_file.is_file():
|
|
479
|
+
try:
|
|
480
|
+
cfg = json.loads(mcp_file.read_text(encoding='utf-8'))
|
|
481
|
+
servers = cfg.get('mcpServers', {})
|
|
482
|
+
for srv in ['qoder-knowledge-graph', 'qoder-mysql', 'qoder-zentao', 'lanhu']:
|
|
483
|
+
entry = servers.get(srv)
|
|
484
|
+
if entry:
|
|
485
|
+
cmd = entry.get('command', '?')
|
|
486
|
+
args = entry.get('args', [])
|
|
487
|
+
has_launcher = any('mcp_launcher.py' in str(a) for a in args)
|
|
488
|
+
print(f' {srv}: command={cmd!r} launcher={"是" if has_launcher else "否(旧模式)"}')
|
|
489
|
+
else:
|
|
490
|
+
print(f' {srv}: 未注册')
|
|
491
|
+
except Exception as e:
|
|
492
|
+
print(f' [ERR] mcp.json 解析失败: {e}')
|
|
493
|
+
else:
|
|
494
|
+
print(f' [MISS] mcp.json 不存在 (跑 npx @hupan56/wlkj update)')
|
|
495
|
+
|
|
496
|
+
# 逐个测试 MCP
|
|
497
|
+
print('\n--- MCP 启动测试 (模拟 QoderWork 发 initialize) ---')
|
|
498
|
+
results = []
|
|
499
|
+
for name in MCP_NAMES:
|
|
500
|
+
print(f'\n 测试 {name}...')
|
|
501
|
+
r = test_mcp(name)
|
|
502
|
+
results.append(r)
|
|
503
|
+
icon = {'OK': '🟢', 'DISABLED': '🟢(无工具)', 'CRASHED': '🔴',
|
|
504
|
+
'TIMEOUT': '🟡', 'NO_RESPONSE': '🟡', 'ERROR': '🔴'}
|
|
505
|
+
print(f' {icon.get(r["status"], "?")} {r["status"]}: {r["name"]}')
|
|
506
|
+
if r['status'] not in ('OK', 'DISABLED'):
|
|
507
|
+
print(f' 详情: {r["detail"]}')
|
|
508
|
+
|
|
509
|
+
# 总结
|
|
510
|
+
print('\n' + '=' * 56)
|
|
511
|
+
print('诊断结论:')
|
|
512
|
+
ok = sum(1 for r in results if r['status'] in ('OK', 'DISABLED'))
|
|
513
|
+
bad = sum(1 for r in results if r['status'] not in ('OK', 'DISABLED'))
|
|
514
|
+
if bad == 0:
|
|
515
|
+
print(f' 全部 MCP 启动正常 ({ok}/{len(results)})。')
|
|
516
|
+
print(' 如果 QoderWork 仍显示黄色: 重启 QoderWork 或新建对话。')
|
|
517
|
+
print(' (mcp.json 改动需要重启才生效)')
|
|
518
|
+
else:
|
|
519
|
+
print(f' {bad} 个 MCP 启动有问题:')
|
|
520
|
+
for r in results:
|
|
521
|
+
if r['status'] not in ('OK', 'DISABLED'):
|
|
522
|
+
print(f' - {r["name"]}: {r["status"]}')
|
|
523
|
+
print('\n 常见原因:')
|
|
524
|
+
print(' CRASHED: Python 版本不兼容(如3.14) 或 脚本语法错误 → 看详情里的 stderr')
|
|
525
|
+
print(' TIMEOUT: 脚本卡住了 → 查 DuckDB 文件锁 或 网络等待')
|
|
526
|
+
print(' NO_RESPONSE: stdout 被 print 污染 → 看 stdout 里的非 JSON 内容')
|
|
527
|
+
print('=' * 56)
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
# ============================================================
|
|
533
|
+
# Facade: 统一入口分发
|
|
534
|
+
# ============================================================
|
|
535
|
+
def main():
|
|
536
|
+
cmd = sys.argv[1] if len(sys.argv) > 1 else 'conditions'
|
|
537
|
+
sys.argv = [sys.argv[0]] + sys.argv[2:] # 去掉子命令, 让各main的argparse正确解析
|
|
538
|
+
if cmd in ('conditions', 'check'):
|
|
539
|
+
sys.exit(main_conditions())
|
|
540
|
+
elif cmd == 'launch':
|
|
541
|
+
sys.exit(main_launch())
|
|
542
|
+
else:
|
|
543
|
+
print('用法: mcp_doctor.py [conditions|launch]')
|
|
544
|
+
print(' conditions [--fix] 启动条件检查')
|
|
545
|
+
print(' launch 实际启动诊断')
|
|
546
|
+
|
|
547
|
+
if __name__ == '__main__':
|
|
548
|
+
main()
|