vod-devkit 0.5.3 → 0.5.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/CHANGELOG.md CHANGED
@@ -316,3 +316,9 @@
316
316
  - ba2901b chore(发版): 提交清单补根 skills/、hermes-plugin/、docs/decisions.md、build-info.json
317
317
  - cbbaf17 docs(技能): 补齐 0.5.2 同批文案 + 发版清单修正
318
318
 
319
+
320
+ ## v0.5.4(2026-11-12)
321
+
322
+ - c1677c2 feat(工程化): doctor 分层报告 + explain + detect + 宿主矩阵进 CI + 发版 workflow
323
+ - f9b732c fix(发版): publish_verify 不再误判 propagation 窗口(v0.5.3 实锤)
324
+
package/README.md CHANGED
@@ -278,3 +278,15 @@ install-manifest 名册对账(doctor 逐落点)+ 声明计数对账(对外
278
278
  ## 许可
279
279
 
280
280
  MIT(见 LICENSE.txt)。第三方素材见 NOTICE。
281
+
282
+ ## 诊断与识别(0.5.4 起)
283
+
284
+ ```bash
285
+ vod-devkit doctor # 分层报告:环境/载荷/配置/技能/网络/插件,每条给动作
286
+ vod-devkit explain -32010 # 解释一条错误码/错误文案:层 + 原因 + 动作
287
+ vod-devkit detect --path . # 只读识别项目语言/框架/构建(不写任何文件)
288
+ python3 scripts/host_matrix.py # 9 宿主安装矩阵:装→断言→拉起 server→卸→验干净
289
+ ```
290
+
291
+ `doctor` 的失败按层分组,不再平铺一列 `FAIL`;`explain` 与它共用同一张规则表
292
+ (`vod_mcp/diagnose.py`),所以"报告里出现的层/原因"和"解释出来的动作"永远一致。
package/bin/vod-devkit CHANGED
@@ -59,13 +59,24 @@ def build_info(strict: bool = False) -> dict:
59
59
 
60
60
  def write_build_info(strict: bool):
61
61
  info = build_info(strict)
62
+ # 隔离跑法(宿主矩阵/CI 用例)不许改真实仓的 build-info:它会被重烧成当前
63
+ # HEAD,而包内副本停在发版提交 → 结构门禁"根/包内不一致"假红(本轮实锤)。
64
+ if os.environ.get("VOD_DEVKIT_NO_BUILD_INFO"):
65
+ print("build-info.json: 跳过写入(VOD_DEVKIT_NO_BUILD_INFO)")
66
+ return
62
67
  (ROOT / "build-info.json").write_text(
63
68
  json.dumps(info, ensure_ascii=False, indent=2), encoding="utf-8")
64
69
  print("build-info.json:", json.dumps(info, ensure_ascii=False))
65
70
 
66
71
 
67
72
  def manifest_path() -> Path:
68
- return ROOT / "install-manifest.json"
73
+ """安装名册位置:默认仓根;VOD_DEVKIT_MANIFEST 可覆盖(多安装根/隔离测试)。
74
+
75
+ 契约上 manifest 落在"安装器所在的仓根"——npx 缓存下的仓被清掉时名册一起消失,
76
+ 所以 doctor/uninstall 只在同一个仓上下文里自洽;需要另置一份或多份时用该 env。
77
+ """
78
+ override = (os.environ.get("VOD_DEVKIT_MANIFEST") or "").strip()
79
+ return Path(override) if override else ROOT / "install-manifest.json"
69
80
 
70
81
 
71
82
  PRESETS = {
@@ -689,6 +700,43 @@ def _repair_dsh_patch_block(mf: dict) -> str | None:
689
700
  return str(patch)
690
701
 
691
702
 
703
+ def _render_problems(problems) -> str:
704
+ """分层报告(对表 devkit 的 doctor-report):按 环境/载荷/配置/技能/网络/插件 分组,
705
+ 每条失败给「原因」与「动作」,避免运维只看到一堆 FAIL 文案。"""
706
+ from vod_mcp import diagnose
707
+ return diagnose.render_problems(problems)
708
+
709
+
710
+ def cmd_explain(args):
711
+ """解释一条失败文案/错误码(-32010 等):给层 + 原因 + 动作。"""
712
+ from vod_mcp import diagnose
713
+ text = " ".join(args.text).strip()
714
+ if not text:
715
+ print("用法:vod-devkit explain '<错误文案或错误码>'", file=sys.stderr)
716
+ sys.exit(2)
717
+ info = diagnose.explain(text)
718
+ if not info["known"]:
719
+ print(f"未收录该问题:{text[:120]}", file=sys.stderr)
720
+ print(" 排查入口:doctor 看分层报告;仍无头绪就把这段文案连同 doctor 输出一起贴出来",
721
+ file=sys.stderr)
722
+ sys.exit(2)
723
+ print(f"层:{info['layer']}")
724
+ print(f"原因:{info['cause']}")
725
+ print(f"动作:{info['action']}")
726
+
727
+
728
+ def cmd_detect(args):
729
+ """只读识别项目语言/框架/构建(给采集端补上下文;不写任何文件)。"""
730
+ from vod_mcp import detect_framework
731
+ try:
732
+ info = detect_framework.detect(args.path or os.getcwd())
733
+ except ValueError as e:
734
+ print(str(e), file=sys.stderr)
735
+ sys.exit(2)
736
+ print(json.dumps(info, ensure_ascii=False, indent=2))
737
+ print("摘要:" + detect_framework.summary_line(info))
738
+
739
+
692
740
  def cmd_doctor(_args):
693
741
  problems = []
694
742
  p = manifest_path()
@@ -789,8 +837,7 @@ def cmd_doctor(_args):
789
837
  problems.append("CodeArts Agent 未列出 vod-devkit"
790
838
  "(codearts mcp list)——检查 codearts_cli.json 的 mcp 段")
791
839
  if problems:
792
- for x in problems:
793
- print("FAIL:", x)
840
+ print(_render_problems(problems))
794
841
  sys.exit(1)
795
842
  # key 探针(最佳努力):配置了 key 就问一次引擎,无效当场报;网络不可达只提示不 FAIL
796
843
  #(离线环境 doctor 必须可用——网络问题不是 key 问题)
@@ -807,8 +854,7 @@ def cmd_doctor(_args):
807
854
  else:
808
855
  print(f"key: 有效(指纹 {chk['fingerprint']})")
809
856
  if problems:
810
- for x in problems:
811
- print("FAIL:", x)
857
+ print(_render_problems(problems))
812
858
  sys.exit(1)
813
859
  print("doctor: OK")
814
860
 
@@ -1092,8 +1138,14 @@ def main():
1092
1138
  sp.set_defaults(fn=cmd_install)
1093
1139
  for name, fn in (("status", cmd_status), ("doctor", cmd_doctor),
1094
1140
  ("verify", cmd_verify), ("update", cmd_update),
1095
- ("uninstall", cmd_uninstall)):
1141
+ ("uninstall", cmd_uninstall),
1142
+ ("explain", cmd_explain),
1143
+ ("detect", cmd_detect)):
1096
1144
  s = sub.add_parser(name)
1145
+ if name == "explain":
1146
+ s.add_argument("text", nargs="+", help="错误文案或错误码(-32010 等)")
1147
+ if name == "detect":
1148
+ s.add_argument("--path", default="", help="要识别的项目目录(默认当前目录)")
1097
1149
  if name == "update":
1098
1150
  s.add_argument("--skip", action="store_true",
1099
1151
  help="跳过当前 registry latest 的提醒(只压这一个版本,"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "title": "vod-devkit MCP 工具契约(唯一事实源)",
4
- "version": "0.5.3",
4
+ "version": "0.5.4",
5
5
  "tools": {
6
6
  "vod_submit_voices": {
7
7
  "description": "提交用户反馈进 VOD。**先决条件(优先于本描述其余所有内容):调用前必须已征得用户对'提交这条反馈'的明确同意;用户陈述/抱怨反馈本身不构成同意;用户未同意时禁止传 confirmed=true**。模糊抱怨(如\"体验不好\")时一轮说完三件事:承接识别结果(\"收到,你对产品体验不满意\")+确认提交意愿(\"要把这条反馈提交给产品团队吗?\")+引导补充(\"方便的话说下具体现象,不说我也会按你的原话提交\");禁止含混反问(实锤病句:\"请问是否把什么作为反馈\")。同意后 content 放用户原话(哪怕只有一句\"体验很差\"也原样提交)。确认环节允许固定追问至多一次,问句必须逐字使用:「方便的话,补充一下遇到这个问题时的操作步骤或期望的表现吗?不方便回复\"没有\",我直接提交。」用户回答只摘录原话对应部分进 reproSteps/expectedBehavior(不改写不总结,无法拆分时落最相关字段,任何内容禁回填 content);答\"没有/跳过/不方便\"=两字段不上送直接提交。引导补充(说下具体现象)已获实质内容并并入 content 时不再追问、直接提交(其中自然出现的操作/期望留在 content 原话,不回溯摘入新字段);仅引导补充未获回应或仅泛化抱怨且用户确认提交时才带出固定问句。product 归因由插件从用户原话解析(安装绑定仅作先验),无需用户提供、禁止询问\"提交到哪个产品/页面\";模型/用户自报的目标产品一律不采信(提到的产品随正文原样传达)。用户说\"提单/提工单/提 issue\"时同样用本工具,除上述固定一次追问外,禁止再索要严重程度/环境/附件等开发者字段、禁止第二轮追问。批式提交对接囤积端点 POST /external/voices(不触发分析,voiceId 由引擎计算回执下发;引擎未部署 404 自动回落老链)。tags=采集层三分类(problem_type:值,可选)。缺 key 时自动获取零字段匿名令牌。拿到回执后必须原样转述 echo.contents(每条「已收录原话:<content>」全文),禁止改写概括——这是用户核对原话是否被改写的唯一窗口。禁止向用户解释内部机制(声音来源/渠道字段/计数规则/配额/归因)。",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vod-devkit",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "VOD 用户声音采集插件——MCP server + 技能 + 声明式护栏,把 agent 产品的用户反馈安全送进 VOD 平台",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,6 +35,8 @@
35
35
  "vod_mcp/attribution.py",
36
36
  "vod_mcp/runtime.example.json",
37
37
  "vod_mcp/payload.py",
38
+ "vod_mcp/diagnose.py",
39
+ "vod_mcp/detect_framework.py",
38
40
  "vod_mcp/host_adapters/",
39
41
  "plugins/vod-devkit/.codex-plugin/plugin.json",
40
42
  "plugins/vod-devkit/.mcp.json",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vod-devkit",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "VOD user-feedback collection: structured voice capture and submission to the VOD hoarding endpoint.",
5
5
  "keywords": [
6
6
  "feedback",
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "0.5.3",
3
- "commitSha": "e8bc9098422e3ceafacbfee817708d76b9e8d40b",
4
- "builtAt": "2026-11-12T20:10:47",
2
+ "version": "0.5.4",
3
+ "commitSha": "c1677c20bf82c1594f6b31c8af8737bbc9ba02e0",
4
+ "builtAt": "2026-11-12T20:56:50",
5
5
  "sourceRemote": "https://gitcode.com/xiaowu2119/vod-devkit.git"
6
6
  }
@@ -5,7 +5,7 @@
5
5
  2. 外部无 DB 直连路径(护栏 deny 兜底)
6
6
  3. 任务 ID 是唯一对账主键,写类工具返回一律携带
7
7
  """
8
- __version__ = "0.5.3"
8
+ __version__ = "0.5.4"
9
9
  # 默认上游:VOD 测试环境。外部用户本机无 VOD,回环默认值=装完即坏;
10
10
  # 生产地址定型后只改这一处(tools.py 与 bin/vod-devkit 共用本常量)。
11
11
  DEFAULT_JAVA_BASE = "https://vod-dev.topxtopx.com"
@@ -0,0 +1,160 @@
1
+ """只读项目识别:语言构成 + 框架/构建工具线索。
2
+
3
+ 对标 huaweicloud-devkit 的 detect-framework*(513 行):它做的推论比我们多
4
+ (框架 → 推荐能力),我们只需要"这是哪个语言/框架的项目"给采集端补上下文,
5
+ 所以刻意只做**确定性证据**:
6
+
7
+ - 语言:按扩展名统计文件数(跳过 vendor 目录 / node_modules / .git / 大二进制),
8
+ 取前 N 个;不做"猜测比例"。
9
+ - 框架/构建:只认标记文件与清单里的显式依赖(package.json 的 dependencies、
10
+ requirements.txt、pyproject.toml、pom.xml、go.mod、Cargo.toml、build.gradle),
11
+ 不做字符串模糊匹配——误报比不报更糟(会把运维带偏)。
12
+
13
+ 只读:本模块不写任何文件、不发网络请求。
14
+ """
15
+ import json
16
+ import os
17
+ from pathlib import Path
18
+
19
+ SKIP_DIRS = {".git", "node_modules", "vendor", "dist", "build", ".venv", "venv",
20
+ "__pycache__", ".mypy_cache", ".pytest_cache", "target", ".idea"}
21
+ MAX_FILES = 20000 # 扫描上限:大仓不做全量遍历(41s 索引卡死过 UI)
22
+ MAX_DEPTH = 12
23
+
24
+ LANG_EXT = {
25
+ ".py": "Python", ".js": "JavaScript", ".mjs": "JavaScript", ".cjs": "JavaScript",
26
+ ".ts": "TypeScript", ".tsx": "TypeScript", ".jsx": "JavaScript",
27
+ ".java": "Java", ".kt": "Kotlin", ".go": "Go", ".rs": "Rust",
28
+ ".rb": "Ruby", ".php": "PHP", ".cs": "C#", ".c": "C", ".cc": "C++",
29
+ ".cpp": "C++", ".h": "C/C++ header", ".swift": "Swift", ".scala": "Scala",
30
+ ".sh": "Shell", ".sql": "SQL", ".vue": "Vue", ".md": "Markdown",
31
+ }
32
+
33
+ # 标记文件 → (种类, 名称)
34
+ MARKERS = {
35
+ "package.json": ("node", "npm/node"),
36
+ "pnpm-lock.yaml": ("node", "pnpm"),
37
+ "yarn.lock": ("node", "yarn"),
38
+ "requirements.txt": ("python", "pip"),
39
+ "pyproject.toml": ("python", "pyproject"),
40
+ "setup.py": ("python", "setuptools"),
41
+ "Pipfile": ("python", "pipenv"),
42
+ "pom.xml": ("java", "Maven"),
43
+ "build.gradle": ("java", "Gradle"),
44
+ "build.gradle.kts": ("java", "Gradle"),
45
+ "go.mod": ("go", "Go modules"),
46
+ "Cargo.toml": ("rust", "Cargo"),
47
+ "Gemfile": ("ruby", "Bundler"),
48
+ "composer.json": ("php", "Composer"),
49
+ "Dockerfile": ("infra", "Docker"),
50
+ "docker-compose.yml": ("infra", "Docker Compose"),
51
+ "Makefile": ("infra", "Make"),
52
+ }
53
+
54
+ # 依赖名 → 框架名(只认清单里的显式依赖)
55
+ JS_FRAMEWORKS = {
56
+ "react": "React", "vue": "Vue", "next": "Next.js", "nuxt": "Nuxt",
57
+ "express": "Express", "fastify": "Fastify", "koa": "Koa", "@nestjs/core": "NestJS",
58
+ "vite": "Vite", "webpack": "Webpack", "electron": "Electron",
59
+ }
60
+ PY_FRAMEWORKS = {
61
+ "django": "Django", "flask": "Flask", "fastapi": "FastAPI",
62
+ "torch": "PyTorch", "tensorflow": "TensorFlow", "pytest": "pytest",
63
+ "sqlalchemy": "SQLAlchemy", "pydantic": "Pydantic",
64
+ }
65
+
66
+
67
+ def _iter_files(root: Path):
68
+ seen = 0
69
+ root_s = str(root)
70
+ for dirpath, dirnames, filenames in os.walk(root_s):
71
+ dirnames[:] = [d for d in dirnames if d not in SKIP_DIRS]
72
+ rel = os.path.relpath(dirpath, root_s)
73
+ depth = 0 if rel == "." else rel.count(os.sep) + 1
74
+ if depth > MAX_DEPTH:
75
+ dirnames[:] = []
76
+ continue
77
+ for name in filenames:
78
+ yield Path(dirpath) / name
79
+ seen += 1
80
+ if seen >= MAX_FILES:
81
+ return
82
+
83
+
84
+ def _read_json(path: Path) -> dict:
85
+ try:
86
+ return json.loads(path.read_text(encoding="utf-8", errors="replace"))
87
+ except Exception:
88
+ return {}
89
+
90
+
91
+ def _js_frameworks(path: Path) -> list:
92
+ data = _read_json(path)
93
+ names = set()
94
+ for section in ("dependencies", "devDependencies", "peerDependencies"):
95
+ for dep in (data.get(section) or {}):
96
+ if dep in JS_FRAMEWORKS:
97
+ names.add(JS_FRAMEWORKS[dep])
98
+ return sorted(names)
99
+
100
+
101
+ def _py_frameworks(root: Path) -> list:
102
+ names = set()
103
+ req = root / "requirements.txt"
104
+ if req.exists():
105
+ for line in req.read_text(encoding="utf-8", errors="replace").splitlines():
106
+ token = line.strip().split("==")[0].split(">=")[0].split("[")[0].lower()
107
+ if token in PY_FRAMEWORKS:
108
+ names.add(PY_FRAMEWORKS[token])
109
+ pyproj = root / "pyproject.toml"
110
+ if pyproj.exists():
111
+ text = pyproj.read_text(encoding="utf-8", errors="replace").lower()
112
+ for dep, label in PY_FRAMEWORKS.items():
113
+ if f'"{dep}"' in text or f"'{dep}'" in text:
114
+ names.add(label)
115
+ return sorted(names)
116
+
117
+
118
+ def detect(path=".") -> dict:
119
+ """返回 {root, languages[{name,files,share}], markers, frameworks, truncated}。"""
120
+ root = Path(path).expanduser().resolve()
121
+ if not root.is_dir():
122
+ raise ValueError(f"{root} 不是目录")
123
+ counts = {}
124
+ truncated = False
125
+ scanned = 0
126
+ for f in _iter_files(root):
127
+ scanned += 1
128
+ ext = f.suffix.lower()
129
+ lang = LANG_EXT.get(ext)
130
+ if lang:
131
+ counts[lang] = counts.get(lang, 0) + 1
132
+ if scanned >= MAX_FILES:
133
+ truncated = True
134
+ break
135
+ total = sum(counts.values()) or 1
136
+ languages = [{"name": n, "files": c, "share": round(c / total, 3)}
137
+ for n, c in sorted(counts.items(), key=lambda x: (-x[1], x[0]))[:8]]
138
+ markers = []
139
+ for name, (kind, label) in MARKERS.items():
140
+ if (root / name).exists():
141
+ markers.append({"file": name, "kind": kind, "label": label})
142
+ frameworks = []
143
+ pkg = root / "package.json"
144
+ if pkg.exists():
145
+ frameworks += _js_frameworks(pkg)
146
+ frameworks += _py_frameworks(root)
147
+ return {"root": str(root), "scanned": scanned, "truncated": truncated,
148
+ "languages": languages,
149
+ "markers": sorted(markers, key=lambda m: m["file"]),
150
+ "frameworks": sorted(set(frameworks))}
151
+
152
+
153
+ def summary_line(info: dict) -> str:
154
+ top = "、".join(f"{l['name']} {int(l['share'] * 100)}%" for l in info["languages"][:3])
155
+ parts = [f"主语言 {top}"] if top else ["未识别到源码文件"]
156
+ if info["frameworks"]:
157
+ parts.append("框架 " + "、".join(info["frameworks"][:4]))
158
+ if info["markers"]:
159
+ parts.append("构建 " + "、".join(m["label"] for m in info["markers"][:3]))
160
+ return ";".join(parts)
@@ -0,0 +1,102 @@
1
+ """诊断分层与错误解释(doctor 报告 + `explain` 子命令共用一张表)。
2
+
3
+ 动机(对表 huaweicloud-devkit 的 doctor-report / explain-error):我们原来的
4
+ doctor 是一条条 FAIL 平铺打印,"哪里坏了"和"下一步做什么"全靠读文案猜;
5
+ 运维在现场只会记住一句话——"doctor 报错了"。这里把**分类**和**动作**外置成数据:
6
+
7
+ - 每条检查/错误按关键词归到一个层(环境/载荷/配置/技能/网络/插件),
8
+ 输出时按层分组,一眼看出是"机器环境问题"还是"我们自己的安装问题";
9
+ - 同一张表提供 explain():给错误码或错误片段,返回 层 / 原因 / 动作。
10
+
11
+ 纪律:
12
+ - 表只描述"已知失败形态",不猜未知错误(未知就如实报"未收录"并给出排查入口)。
13
+ - 归层只按关键词匹配(确定性),不做语义推断——误归层会把运维带偏。
14
+ """
15
+ import fnmatch
16
+ import re
17
+
18
+ LAYERS = ["环境", "载荷", "配置", "技能", "网络", "插件"]
19
+
20
+ # (关键词/正则, 层, 原因, 动作)
21
+ RULES = [
22
+ (r"无 install-manifest|未 install",
23
+ "环境", "还没装(或 manifest 被删)", "运行 install --target <宿主>"),
24
+ (r"commitSHA 不一致|commitSha",
25
+ "载荷", "安装记录与当前包不是同一份构建(升版后未重装)", "重跑 install"),
26
+ (r"载荷目录缺失|载荷被改动|载荷残留",
27
+ "载荷", "MCP 入口指向的副本不在/被改", "重跑 install 重建副本"),
28
+ (r"MCP 配置文件缺失|mcpConfig",
29
+ "配置", "宿主配置文件被删或挪了位置", "重跑 install --target <宿主>"),
30
+ (r"未列出 vod-devkit|mcp list",
31
+ "配置", "宿主没读到我们的 MCP 条目", "检查宿主配置文件里的 mcp 段后重装"),
32
+ (r"skills 目录缺失|技能文件缺失|技能文件漂移|技能原生副本缺失|技能拷贝件",
33
+ "技能", "技能副本缺失或与安装指纹不符", "重跑 install 恢复"),
34
+ (r"路由插件副本落后|vod-feedback-router",
35
+ "插件", "仓内话术已更新但装机副本是旧的", "重跑 install --target hermes"),
36
+ (r"AGENTS\.md 仍含旧一代注入|vod-submit-one-liner",
37
+ "插件", "旧注入教模型跳过征询(红线失效)", "重跑 install --target codex 自动清理"),
38
+ (r"远程面|远程 MCP|探活|不可达|401",
39
+ "网络", "远程端点不可达或工具面不符", "检查网络/端点版本;设 VOD_MCP_TOKEN 再验"),
40
+ (r"key 无效|401 拒绝|指纹",
41
+ "网络", "引擎拒绝了 key", "核对/续期 key,或移除 key 走匿名档"),
42
+ (r"引擎不可达|ProbeError|timed out|Connection",
43
+ "网络", "引擎/网络不可达(不是 key 问题)", "查网络出口与引擎健康;离线可继续工作"),
44
+ (r"-32010|产品", "配置", "缺产品归属,拒绝提交", "先问用户是哪个产品,再带 product 提交"),
45
+ (r"python|node|版本", "环境", "运行时版本不满足", "按 README 的版本要求升级"),
46
+ ]
47
+
48
+ _EXPLAIN_EXTRA = {
49
+ "-32010": ("配置",
50
+ "缺少产品归属(用户没说、也追问不到),服务端拒绝写引擎",
51
+ "先用 vod_search_products 给候选问用户;用户说不清楚就不提交"),
52
+ "-32011": ("配置", "产品不在名录里", "按名录候选再确认一次;仍对不上则不提交"),
53
+ }
54
+
55
+
56
+ def classify(message: str) -> tuple:
57
+ """把一条失败/警告文案归到 (层, 原因, 动作)。未收录 → ("未分类", "", "")。"""
58
+ for pat, layer, cause, action in RULES:
59
+ if re.search(pat, message):
60
+ return layer, cause, action
61
+ return "未分类", "", ""
62
+
63
+
64
+ def explain(text: str) -> dict:
65
+ """给错误码或错误片段,返回 {layer, cause, action, known}。"""
66
+ for code, (layer, cause, action) in _EXPLAIN_EXTRA.items():
67
+ if code in text:
68
+ return {"layer": layer, "cause": cause, "action": action, "known": True}
69
+ layer, cause, action = classify(text)
70
+ return {"layer": layer, "cause": cause, "action": action,
71
+ "known": layer != "未分类"}
72
+
73
+
74
+ def group(problems: list) -> dict:
75
+ """按层分组(保持 LAYERS 顺序,未分类排最后)。"""
76
+ buckets = {l: [] for l in LAYERS}
77
+ buckets["未分类"] = []
78
+ for msg in problems:
79
+ layer, cause, action = classify(msg)
80
+ buckets[layer].append((msg, cause, action))
81
+ return {k: v for k, v in buckets.items() if v}
82
+
83
+
84
+ def render_problems(problems: list) -> str:
85
+ """把失败清单渲染成分层报告(供 doctor 输出)。"""
86
+ if not problems:
87
+ return ""
88
+ out = []
89
+ for layer, items in group(problems).items():
90
+ out.append(f"[{layer}]")
91
+ for msg, cause, action in items:
92
+ out.append(f"FAIL: {msg}")
93
+ if cause:
94
+ out.append(f" 原因:{cause}")
95
+ if action:
96
+ out.append(f" 动作:{action}")
97
+ return "\n".join(out)
98
+
99
+
100
+ def matches(message: str, pattern: str) -> bool:
101
+ """给运维手输片段做粗匹配(大小写不敏感,支持 * 通配)。"""
102
+ return fnmatch.fnmatch(message.lower(), pattern.lower())
@@ -6,7 +6,7 @@ import sys
6
6
  from pathlib import Path
7
7
 
8
8
  from vod_mcp import hosts as host_specs
9
- from vod_mcp.host_adapters.base import ROOT
9
+ from vod_mcp.host_adapters.base import ROOT, server_env, server_entry
10
10
 
11
11
  HOST = "codex"
12
12
  SUPPORTS_REMOTE = True
@@ -170,7 +170,16 @@ def install(args, packs: str) -> Path:
170
170
  mj = json.loads(Path(mcp_jsons[0]).read_text(encoding="utf-8"))
171
171
  srv = mj.get("mcpServers", {}).get("vod-devkit")
172
172
  if srv is not None:
173
- srv.setdefault("env", {})["VOD_PACKS"] = packs
173
+ # 关键修正(2026-11-12 矩阵实锤):插件自带的 .mcp.json 写的是
174
+ # command="vod-devkit" + args=["serve"] —— 依赖 PATH 上那个全局包。
175
+ # 机器上装着旧版(实测 0.4.2)时,codex 会静默跑旧副本:配置、
176
+ # 技能都是新的,工具面却是旧的。改成绝对解释器 + 载荷副本,与其它
177
+ # 宿主同一条铁律(入口不依赖 PATH / npx 缓存)。
178
+ srv["command"] = sys.executable
179
+ srv["args"] = [server_entry()]
180
+ merged = dict(srv.get("env") or {})
181
+ merged.update(server_env(args, packs))
182
+ srv["env"] = merged
174
183
  Path(mcp_jsons[0]).write_text(
175
184
  json.dumps(mj, ensure_ascii=False, indent=2) + "\n",
176
185
  encoding="utf-8")
@@ -5,7 +5,7 @@
5
5
  2. 外部无 DB 直连路径(护栏 deny 兜底)
6
6
  3. 任务 ID 是唯一对账主键,写类工具返回一律携带
7
7
  """
8
- __version__ = "0.5.3"
8
+ __version__ = "0.5.4"
9
9
  # 默认上游:VOD 测试环境。外部用户本机无 VOD,回环默认值=装完即坏;
10
10
  # 生产地址定型后只改这一处(tools.py 与 bin/vod-devkit 共用本常量)。
11
11
  DEFAULT_JAVA_BASE = "https://vod-dev.topxtopx.com"
@@ -0,0 +1,160 @@
1
+ """只读项目识别:语言构成 + 框架/构建工具线索。
2
+
3
+ 对标 huaweicloud-devkit 的 detect-framework*(513 行):它做的推论比我们多
4
+ (框架 → 推荐能力),我们只需要"这是哪个语言/框架的项目"给采集端补上下文,
5
+ 所以刻意只做**确定性证据**:
6
+
7
+ - 语言:按扩展名统计文件数(跳过 vendor 目录 / node_modules / .git / 大二进制),
8
+ 取前 N 个;不做"猜测比例"。
9
+ - 框架/构建:只认标记文件与清单里的显式依赖(package.json 的 dependencies、
10
+ requirements.txt、pyproject.toml、pom.xml、go.mod、Cargo.toml、build.gradle),
11
+ 不做字符串模糊匹配——误报比不报更糟(会把运维带偏)。
12
+
13
+ 只读:本模块不写任何文件、不发网络请求。
14
+ """
15
+ import json
16
+ import os
17
+ from pathlib import Path
18
+
19
+ SKIP_DIRS = {".git", "node_modules", "vendor", "dist", "build", ".venv", "venv",
20
+ "__pycache__", ".mypy_cache", ".pytest_cache", "target", ".idea"}
21
+ MAX_FILES = 20000 # 扫描上限:大仓不做全量遍历(41s 索引卡死过 UI)
22
+ MAX_DEPTH = 12
23
+
24
+ LANG_EXT = {
25
+ ".py": "Python", ".js": "JavaScript", ".mjs": "JavaScript", ".cjs": "JavaScript",
26
+ ".ts": "TypeScript", ".tsx": "TypeScript", ".jsx": "JavaScript",
27
+ ".java": "Java", ".kt": "Kotlin", ".go": "Go", ".rs": "Rust",
28
+ ".rb": "Ruby", ".php": "PHP", ".cs": "C#", ".c": "C", ".cc": "C++",
29
+ ".cpp": "C++", ".h": "C/C++ header", ".swift": "Swift", ".scala": "Scala",
30
+ ".sh": "Shell", ".sql": "SQL", ".vue": "Vue", ".md": "Markdown",
31
+ }
32
+
33
+ # 标记文件 → (种类, 名称)
34
+ MARKERS = {
35
+ "package.json": ("node", "npm/node"),
36
+ "pnpm-lock.yaml": ("node", "pnpm"),
37
+ "yarn.lock": ("node", "yarn"),
38
+ "requirements.txt": ("python", "pip"),
39
+ "pyproject.toml": ("python", "pyproject"),
40
+ "setup.py": ("python", "setuptools"),
41
+ "Pipfile": ("python", "pipenv"),
42
+ "pom.xml": ("java", "Maven"),
43
+ "build.gradle": ("java", "Gradle"),
44
+ "build.gradle.kts": ("java", "Gradle"),
45
+ "go.mod": ("go", "Go modules"),
46
+ "Cargo.toml": ("rust", "Cargo"),
47
+ "Gemfile": ("ruby", "Bundler"),
48
+ "composer.json": ("php", "Composer"),
49
+ "Dockerfile": ("infra", "Docker"),
50
+ "docker-compose.yml": ("infra", "Docker Compose"),
51
+ "Makefile": ("infra", "Make"),
52
+ }
53
+
54
+ # 依赖名 → 框架名(只认清单里的显式依赖)
55
+ JS_FRAMEWORKS = {
56
+ "react": "React", "vue": "Vue", "next": "Next.js", "nuxt": "Nuxt",
57
+ "express": "Express", "fastify": "Fastify", "koa": "Koa", "@nestjs/core": "NestJS",
58
+ "vite": "Vite", "webpack": "Webpack", "electron": "Electron",
59
+ }
60
+ PY_FRAMEWORKS = {
61
+ "django": "Django", "flask": "Flask", "fastapi": "FastAPI",
62
+ "torch": "PyTorch", "tensorflow": "TensorFlow", "pytest": "pytest",
63
+ "sqlalchemy": "SQLAlchemy", "pydantic": "Pydantic",
64
+ }
65
+
66
+
67
+ def _iter_files(root: Path):
68
+ seen = 0
69
+ root_s = str(root)
70
+ for dirpath, dirnames, filenames in os.walk(root_s):
71
+ dirnames[:] = [d for d in dirnames if d not in SKIP_DIRS]
72
+ rel = os.path.relpath(dirpath, root_s)
73
+ depth = 0 if rel == "." else rel.count(os.sep) + 1
74
+ if depth > MAX_DEPTH:
75
+ dirnames[:] = []
76
+ continue
77
+ for name in filenames:
78
+ yield Path(dirpath) / name
79
+ seen += 1
80
+ if seen >= MAX_FILES:
81
+ return
82
+
83
+
84
+ def _read_json(path: Path) -> dict:
85
+ try:
86
+ return json.loads(path.read_text(encoding="utf-8", errors="replace"))
87
+ except Exception:
88
+ return {}
89
+
90
+
91
+ def _js_frameworks(path: Path) -> list:
92
+ data = _read_json(path)
93
+ names = set()
94
+ for section in ("dependencies", "devDependencies", "peerDependencies"):
95
+ for dep in (data.get(section) or {}):
96
+ if dep in JS_FRAMEWORKS:
97
+ names.add(JS_FRAMEWORKS[dep])
98
+ return sorted(names)
99
+
100
+
101
+ def _py_frameworks(root: Path) -> list:
102
+ names = set()
103
+ req = root / "requirements.txt"
104
+ if req.exists():
105
+ for line in req.read_text(encoding="utf-8", errors="replace").splitlines():
106
+ token = line.strip().split("==")[0].split(">=")[0].split("[")[0].lower()
107
+ if token in PY_FRAMEWORKS:
108
+ names.add(PY_FRAMEWORKS[token])
109
+ pyproj = root / "pyproject.toml"
110
+ if pyproj.exists():
111
+ text = pyproj.read_text(encoding="utf-8", errors="replace").lower()
112
+ for dep, label in PY_FRAMEWORKS.items():
113
+ if f'"{dep}"' in text or f"'{dep}'" in text:
114
+ names.add(label)
115
+ return sorted(names)
116
+
117
+
118
+ def detect(path=".") -> dict:
119
+ """返回 {root, languages[{name,files,share}], markers, frameworks, truncated}。"""
120
+ root = Path(path).expanduser().resolve()
121
+ if not root.is_dir():
122
+ raise ValueError(f"{root} 不是目录")
123
+ counts = {}
124
+ truncated = False
125
+ scanned = 0
126
+ for f in _iter_files(root):
127
+ scanned += 1
128
+ ext = f.suffix.lower()
129
+ lang = LANG_EXT.get(ext)
130
+ if lang:
131
+ counts[lang] = counts.get(lang, 0) + 1
132
+ if scanned >= MAX_FILES:
133
+ truncated = True
134
+ break
135
+ total = sum(counts.values()) or 1
136
+ languages = [{"name": n, "files": c, "share": round(c / total, 3)}
137
+ for n, c in sorted(counts.items(), key=lambda x: (-x[1], x[0]))[:8]]
138
+ markers = []
139
+ for name, (kind, label) in MARKERS.items():
140
+ if (root / name).exists():
141
+ markers.append({"file": name, "kind": kind, "label": label})
142
+ frameworks = []
143
+ pkg = root / "package.json"
144
+ if pkg.exists():
145
+ frameworks += _js_frameworks(pkg)
146
+ frameworks += _py_frameworks(root)
147
+ return {"root": str(root), "scanned": scanned, "truncated": truncated,
148
+ "languages": languages,
149
+ "markers": sorted(markers, key=lambda m: m["file"]),
150
+ "frameworks": sorted(set(frameworks))}
151
+
152
+
153
+ def summary_line(info: dict) -> str:
154
+ top = "、".join(f"{l['name']} {int(l['share'] * 100)}%" for l in info["languages"][:3])
155
+ parts = [f"主语言 {top}"] if top else ["未识别到源码文件"]
156
+ if info["frameworks"]:
157
+ parts.append("框架 " + "、".join(info["frameworks"][:4]))
158
+ if info["markers"]:
159
+ parts.append("构建 " + "、".join(m["label"] for m in info["markers"][:3]))
160
+ return ";".join(parts)
@@ -0,0 +1,102 @@
1
+ """诊断分层与错误解释(doctor 报告 + `explain` 子命令共用一张表)。
2
+
3
+ 动机(对表 huaweicloud-devkit 的 doctor-report / explain-error):我们原来的
4
+ doctor 是一条条 FAIL 平铺打印,"哪里坏了"和"下一步做什么"全靠读文案猜;
5
+ 运维在现场只会记住一句话——"doctor 报错了"。这里把**分类**和**动作**外置成数据:
6
+
7
+ - 每条检查/错误按关键词归到一个层(环境/载荷/配置/技能/网络/插件),
8
+ 输出时按层分组,一眼看出是"机器环境问题"还是"我们自己的安装问题";
9
+ - 同一张表提供 explain():给错误码或错误片段,返回 层 / 原因 / 动作。
10
+
11
+ 纪律:
12
+ - 表只描述"已知失败形态",不猜未知错误(未知就如实报"未收录"并给出排查入口)。
13
+ - 归层只按关键词匹配(确定性),不做语义推断——误归层会把运维带偏。
14
+ """
15
+ import fnmatch
16
+ import re
17
+
18
+ LAYERS = ["环境", "载荷", "配置", "技能", "网络", "插件"]
19
+
20
+ # (关键词/正则, 层, 原因, 动作)
21
+ RULES = [
22
+ (r"无 install-manifest|未 install",
23
+ "环境", "还没装(或 manifest 被删)", "运行 install --target <宿主>"),
24
+ (r"commitSHA 不一致|commitSha",
25
+ "载荷", "安装记录与当前包不是同一份构建(升版后未重装)", "重跑 install"),
26
+ (r"载荷目录缺失|载荷被改动|载荷残留",
27
+ "载荷", "MCP 入口指向的副本不在/被改", "重跑 install 重建副本"),
28
+ (r"MCP 配置文件缺失|mcpConfig",
29
+ "配置", "宿主配置文件被删或挪了位置", "重跑 install --target <宿主>"),
30
+ (r"未列出 vod-devkit|mcp list",
31
+ "配置", "宿主没读到我们的 MCP 条目", "检查宿主配置文件里的 mcp 段后重装"),
32
+ (r"skills 目录缺失|技能文件缺失|技能文件漂移|技能原生副本缺失|技能拷贝件",
33
+ "技能", "技能副本缺失或与安装指纹不符", "重跑 install 恢复"),
34
+ (r"路由插件副本落后|vod-feedback-router",
35
+ "插件", "仓内话术已更新但装机副本是旧的", "重跑 install --target hermes"),
36
+ (r"AGENTS\.md 仍含旧一代注入|vod-submit-one-liner",
37
+ "插件", "旧注入教模型跳过征询(红线失效)", "重跑 install --target codex 自动清理"),
38
+ (r"远程面|远程 MCP|探活|不可达|401",
39
+ "网络", "远程端点不可达或工具面不符", "检查网络/端点版本;设 VOD_MCP_TOKEN 再验"),
40
+ (r"key 无效|401 拒绝|指纹",
41
+ "网络", "引擎拒绝了 key", "核对/续期 key,或移除 key 走匿名档"),
42
+ (r"引擎不可达|ProbeError|timed out|Connection",
43
+ "网络", "引擎/网络不可达(不是 key 问题)", "查网络出口与引擎健康;离线可继续工作"),
44
+ (r"-32010|产品", "配置", "缺产品归属,拒绝提交", "先问用户是哪个产品,再带 product 提交"),
45
+ (r"python|node|版本", "环境", "运行时版本不满足", "按 README 的版本要求升级"),
46
+ ]
47
+
48
+ _EXPLAIN_EXTRA = {
49
+ "-32010": ("配置",
50
+ "缺少产品归属(用户没说、也追问不到),服务端拒绝写引擎",
51
+ "先用 vod_search_products 给候选问用户;用户说不清楚就不提交"),
52
+ "-32011": ("配置", "产品不在名录里", "按名录候选再确认一次;仍对不上则不提交"),
53
+ }
54
+
55
+
56
+ def classify(message: str) -> tuple:
57
+ """把一条失败/警告文案归到 (层, 原因, 动作)。未收录 → ("未分类", "", "")。"""
58
+ for pat, layer, cause, action in RULES:
59
+ if re.search(pat, message):
60
+ return layer, cause, action
61
+ return "未分类", "", ""
62
+
63
+
64
+ def explain(text: str) -> dict:
65
+ """给错误码或错误片段,返回 {layer, cause, action, known}。"""
66
+ for code, (layer, cause, action) in _EXPLAIN_EXTRA.items():
67
+ if code in text:
68
+ return {"layer": layer, "cause": cause, "action": action, "known": True}
69
+ layer, cause, action = classify(text)
70
+ return {"layer": layer, "cause": cause, "action": action,
71
+ "known": layer != "未分类"}
72
+
73
+
74
+ def group(problems: list) -> dict:
75
+ """按层分组(保持 LAYERS 顺序,未分类排最后)。"""
76
+ buckets = {l: [] for l in LAYERS}
77
+ buckets["未分类"] = []
78
+ for msg in problems:
79
+ layer, cause, action = classify(msg)
80
+ buckets[layer].append((msg, cause, action))
81
+ return {k: v for k, v in buckets.items() if v}
82
+
83
+
84
+ def render_problems(problems: list) -> str:
85
+ """把失败清单渲染成分层报告(供 doctor 输出)。"""
86
+ if not problems:
87
+ return ""
88
+ out = []
89
+ for layer, items in group(problems).items():
90
+ out.append(f"[{layer}]")
91
+ for msg, cause, action in items:
92
+ out.append(f"FAIL: {msg}")
93
+ if cause:
94
+ out.append(f" 原因:{cause}")
95
+ if action:
96
+ out.append(f" 动作:{action}")
97
+ return "\n".join(out)
98
+
99
+
100
+ def matches(message: str, pattern: str) -> bool:
101
+ """给运维手输片段做粗匹配(大小写不敏感,支持 * 通配)。"""
102
+ return fnmatch.fnmatch(message.lower(), pattern.lower())
@@ -6,7 +6,7 @@ import sys
6
6
  from pathlib import Path
7
7
 
8
8
  from vod_mcp import hosts as host_specs
9
- from vod_mcp.host_adapters.base import ROOT
9
+ from vod_mcp.host_adapters.base import ROOT, server_env, server_entry
10
10
 
11
11
  HOST = "codex"
12
12
  SUPPORTS_REMOTE = True
@@ -170,7 +170,16 @@ def install(args, packs: str) -> Path:
170
170
  mj = json.loads(Path(mcp_jsons[0]).read_text(encoding="utf-8"))
171
171
  srv = mj.get("mcpServers", {}).get("vod-devkit")
172
172
  if srv is not None:
173
- srv.setdefault("env", {})["VOD_PACKS"] = packs
173
+ # 关键修正(2026-11-12 矩阵实锤):插件自带的 .mcp.json 写的是
174
+ # command="vod-devkit" + args=["serve"] —— 依赖 PATH 上那个全局包。
175
+ # 机器上装着旧版(实测 0.4.2)时,codex 会静默跑旧副本:配置、
176
+ # 技能都是新的,工具面却是旧的。改成绝对解释器 + 载荷副本,与其它
177
+ # 宿主同一条铁律(入口不依赖 PATH / npx 缓存)。
178
+ srv["command"] = sys.executable
179
+ srv["args"] = [server_entry()]
180
+ merged = dict(srv.get("env") or {})
181
+ merged.update(server_env(args, packs))
182
+ srv["env"] = merged
174
183
  Path(mcp_jsons[0]).write_text(
175
184
  json.dumps(mj, ensure_ascii=False, indent=2) + "\n",
176
185
  encoding="utf-8")