vod-devkit 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/QUICKSTART.md +1 -1
- package/README.en.md +190 -57
- package/README.md +194 -75
- package/bin/vod-devkit +436 -426
- package/contract/tools.schema.json +78 -8
- package/integrations/codeartsdoer/host.json +11 -0
- package/package.json +4 -1
- package/plugins/vod-devkit/.codex-plugin/plugin.json +1 -1
- package/plugins/vod-devkit/build-info.json +3 -3
- package/plugins/vod-devkit/skills/vod-core/SKILL.md +12 -4
- package/plugins/vod-devkit/skills/vod-core/references/acceptance-criteria.md +9 -0
- package/plugins/vod-devkit/skills/vod-core/references/verification-method.md +29 -0
- package/plugins/vod-devkit/skills/vod-feedback-collect/SKILL.md +57 -11
- package/plugins/vod-devkit/skills/vod-feedback-collect/references/acceptance-criteria.md +28 -0
- package/plugins/vod-devkit/skills/vod-feedback-collect/references/verification-method.md +31 -0
- package/plugins/vod-devkit/skills/vod-problem-classification-rules/SKILL.md +3 -1
- package/plugins/vod-devkit/skills/vod-scoring-rules/SKILL.md +22 -1
- package/plugins/vod-devkit/vod_mcp/__init__.py +1 -1
- package/plugins/vod-devkit/vod_mcp/attribution.py +378 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/__init__.py +26 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/base.py +73 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/codearts.py +57 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/codex.py +209 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/dsh.py +176 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/generic.py +132 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/hermes.py +76 -0
- package/plugins/vod-devkit/vod_mcp/host_adapters/opencode.py +52 -0
- package/plugins/vod-devkit/vod_mcp/hosts.py +20 -0
- package/plugins/vod-devkit/vod_mcp/packs.py +3 -1
- package/plugins/vod-devkit/vod_mcp/payload.py +174 -0
- package/plugins/vod-devkit/vod_mcp/server.py +13 -1
- package/plugins/vod-devkit/vod_mcp/tools.py +385 -46
- package/plugins/vod-devkit/vod_mcp/update_check.py +31 -3
- package/skills/vod-core/SKILL.md +12 -4
- package/skills/vod-core/references/acceptance-criteria.md +9 -0
- package/skills/vod-core/references/verification-method.md +29 -0
- package/skills/vod-feedback-collect/SKILL.md +57 -11
- package/skills/vod-feedback-collect/references/acceptance-criteria.md +28 -0
- package/skills/vod-feedback-collect/references/verification-method.md +31 -0
- package/skills/vod-problem-classification-rules/SKILL.md +3 -1
- package/skills/vod-scoring-rules/SKILL.md +22 -1
- package/vod_mcp/__init__.py +1 -1
- package/vod_mcp/attribution.py +378 -0
- package/vod_mcp/host_adapters/__init__.py +26 -0
- package/vod_mcp/host_adapters/__pycache__/__init__.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/base.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/codearts.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/codex.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/dsh.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/generic.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/hermes.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/__pycache__/opencode.cpython-314.pyc +0 -0
- package/vod_mcp/host_adapters/base.py +73 -0
- package/vod_mcp/host_adapters/codearts.py +57 -0
- package/vod_mcp/host_adapters/codex.py +209 -0
- package/vod_mcp/host_adapters/dsh.py +176 -0
- package/vod_mcp/host_adapters/generic.py +132 -0
- package/vod_mcp/host_adapters/hermes.py +76 -0
- package/vod_mcp/host_adapters/opencode.py +52 -0
- package/vod_mcp/hosts.py +20 -0
- package/vod_mcp/packs.py +3 -1
- package/vod_mcp/payload.py +174 -0
- package/vod_mcp/server.py +13 -1
- package/vod_mcp/tools.py +385 -46
- package/vod_mcp/update_check.py +31 -3
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"""运行期归因(D-attrib-B,2026-11-11 负责人拍板 A/A/A/A)。
|
|
2
|
+
|
|
3
|
+
产品不再由安装/启动配置决定:从**用户原话**里解析产品名录别名,唯一命中才
|
|
4
|
+
采信;0 命中依次回落到记忆(短 TTL)与安装先验;多产品命中=歧义,一律
|
|
5
|
+
UNKNOWN 并保留全部命中片段(宁可人工归因,不可公开错归)。
|
|
6
|
+
|
|
7
|
+
本模块只做纯计算(索引/匹配/优先级链),不读写 runtime.json——持久化归
|
|
8
|
+
tools 层,便于单测零副作用。
|
|
9
|
+
|
|
10
|
+
数据源单一真源=引擎 meta(GET /external/meta):
|
|
11
|
+
productCatalog [{id,name}] 提交主键(t_vod_product)与产品名
|
|
12
|
+
products [显示名] codearts 之类的短码由显示名大写派生
|
|
13
|
+
|
|
14
|
+
**2026-11-12 变更(引擎侧 meta 契约收紧)**:
|
|
15
|
+
引擎已删除 `nameAliases` / `aliases` 两个下发字段(理由:编造数据、无消费方、
|
|
16
|
+
且掩盖主数据问题)。别名能力改为**本地派生 + 显式品牌俗称表**,不再依赖后端下发:
|
|
17
|
+
|
|
18
|
+
① 规则派生(从 productCatalog 的真实名字推导,不是编造):
|
|
19
|
+
原名 / 大小写不敏感 / 去空格("AI 开发者空间"→"AI开发者空间")/
|
|
20
|
+
括号与前缀剥离的核心词("对象存储服务 OBS"→"OBS")/
|
|
21
|
+
中文长名里的拉丁片段("软件开发生产线 CodeArts"→"CodeArts")
|
|
22
|
+
② BRAND_ALIASES(下方常量):人工确认的品牌俗称,只放**无法从表名推导**
|
|
23
|
+
且用户口语高频的词(如「码道」= CodeArts 中文品牌名)。
|
|
24
|
+
这是本地维护的已知清单,诚实标注为本地数据,不再假装来自后端。
|
|
25
|
+
|
|
26
|
+
`problemTypes` 同理:引擎改为 `?productId=` 按产品下发,不带参数时不含该键。
|
|
27
|
+
分类白名单的获取见 tools._allowed_tags(product_id)。
|
|
28
|
+
"""
|
|
29
|
+
import re
|
|
30
|
+
|
|
31
|
+
MEM_TTL = 30 * 60 # 记忆窗口:负责人拍板 P2-A(机器级 + 30 分钟)
|
|
32
|
+
|
|
33
|
+
_SNIPPET_PAD = 20
|
|
34
|
+
_SNIPPET_MAX = 80
|
|
35
|
+
_BOUNDARY = set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-")
|
|
36
|
+
_SHORT_ALIAS_MAX = 5
|
|
37
|
+
|
|
38
|
+
# 品牌俗称表(本地维护,2026-11-12 用户拍板方案 b):
|
|
39
|
+
# 目标产品名(必须能在 canvas productCatalog 里找到,大小写不敏感匹配)→ 口语俗称列表
|
|
40
|
+
# 收录标准(缺一不可):
|
|
41
|
+
# ① 无法从表内登记名通过规则派生(否则交给规则)
|
|
42
|
+
# ② 用户原话里高频真实出现(有真机语料支撑)
|
|
43
|
+
# ③ 品牌官方称谓,不是臆造简称
|
|
44
|
+
# 空表也安全:派生规则独立工作,本表只是补口语盲区。
|
|
45
|
+
BRAND_ALIASES = {
|
|
46
|
+
"CodeArts": ["码道", "华为云码道"],
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# 派生核心词时的中文尾缀噪音("对象存储服务 OBS" → 取拉丁 "OBS")
|
|
50
|
+
_LATIN_RUN = re.compile(r"[A-Za-z][A-Za-z0-9 ._-]*[A-Za-z0-9]|[A-Za-z]")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _is_ascii(text: str) -> bool:
|
|
54
|
+
return all(ord(c) < 128 for c in text)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _resolve_name(raw: str, names: list) -> str:
|
|
58
|
+
"""别名表里的枚举键(CODEARTS)→ catalog/显示名(CodeArts)。"""
|
|
59
|
+
low = str(raw or "").strip().lower()
|
|
60
|
+
for n in names:
|
|
61
|
+
if str(n).lower() == low:
|
|
62
|
+
return str(n)
|
|
63
|
+
return str(raw or "").strip()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _derive_aliases(name: str) -> list:
|
|
67
|
+
"""从单个登记名派生可用别名(全部来自真实名字,非编造)。
|
|
68
|
+
|
|
69
|
+
"AI 开发者空间" → 原名 / 去空格 "AI开发者空间" / 拉丁 "AI"(过短,弃用)
|
|
70
|
+
"对象存储服务 OBS" → 原名 / 拉丁核心 "OBS"
|
|
71
|
+
"软件开发生产线 CodeArts" → 原名 / 拉丁核心 "CodeArts"
|
|
72
|
+
"DataArts Studio" → 原名 / 去空格 / "DataArts"(拉丁首段)
|
|
73
|
+
过短(<5)的拉丁别名会被 _ascii_hits 的精确大小写规则保护,但仍可能撞词,
|
|
74
|
+
所以这里只保留长度>=3 的拉丁片段,且不做大写化(保留原样)。
|
|
75
|
+
"""
|
|
76
|
+
raw = str(name or "").strip()
|
|
77
|
+
if not raw:
|
|
78
|
+
return []
|
|
79
|
+
out = [raw]
|
|
80
|
+
compact = re.sub(r"\s+", "", raw)
|
|
81
|
+
if compact and compact != raw:
|
|
82
|
+
out.append(compact)
|
|
83
|
+
# 拉丁片段:整串是纯拉丁时取首段与全串;含中文时取最长的拉丁连续段
|
|
84
|
+
runs = [m.group(0).strip() for m in _LATIN_RUN.finditer(raw)]
|
|
85
|
+
runs = [r for r in runs if len(r) >= 3]
|
|
86
|
+
if runs:
|
|
87
|
+
out.extend(runs)
|
|
88
|
+
if " " in raw and runs[0] != raw:
|
|
89
|
+
head = runs[0].split()[0] if runs[0].split() else runs[0]
|
|
90
|
+
if len(head) >= 3:
|
|
91
|
+
out.append(head)
|
|
92
|
+
# 短拉丁名的大小写变体:表里存 "Maas"、用户写 "MaaS"(真实高频差异)。
|
|
93
|
+
# _ascii_hits 对 <5 字符的短别名走精确大小写,只靠原样会漏。
|
|
94
|
+
# 关键限制:**全大写缩写(OBS/CCE/EIP)不生成小写变体**——用户不会把小写
|
|
95
|
+
# "obs" 当产品名,而 "obs://bucket" 这类 URL/路径反会被误命中(S93 铁律)。
|
|
96
|
+
# 只对非全大写的混写名(Maas/CodeArts)补变体。
|
|
97
|
+
for run in list(runs):
|
|
98
|
+
if len(run) <= 8 and _is_ascii(run) and run != run.upper():
|
|
99
|
+
for variant in (run.lower(), run.capitalize()):
|
|
100
|
+
if variant != run:
|
|
101
|
+
out.append(variant)
|
|
102
|
+
# 去重、保序
|
|
103
|
+
seen, uniq = set(), []
|
|
104
|
+
for a in out:
|
|
105
|
+
if a and a not in seen:
|
|
106
|
+
seen.add(a)
|
|
107
|
+
uniq.append(a)
|
|
108
|
+
return uniq
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def build_alias_index(meta: dict) -> list:
|
|
112
|
+
"""meta → 别名条目列表(按别名长度降序,长别名优先)。
|
|
113
|
+
|
|
114
|
+
真机实锤的两个坑(2026-11-11 用线上 meta 实测):
|
|
115
|
+
① catalog 名与展示名不一致:t_vod_product 里 MaaS 存成 "Maas"、OBS 存成
|
|
116
|
+
"对象存储服务 OBS",而 meta.products 是展示名 "MaaS"/"OBS"——只按名字
|
|
117
|
+
对不齐会把同一产品拆成两条(一条有 id 一条没有)。
|
|
118
|
+
② 别名去重不能用大小写不敏感:短别名按大小写精确匹配,"MaaS" 会被
|
|
119
|
+
"Maas" 顶掉。
|
|
120
|
+
做法:以展示名为产品标签,用**规则派生 + BRAND_ALIASES**把多种写法桥接,
|
|
121
|
+
再按 catalog id 合并成一条;去重键保留大小写(alias 原样)。
|
|
122
|
+
|
|
123
|
+
2026-11-12:引擎已不再下发 nameAliases/aliases,改用 _derive_aliases + 本地表。
|
|
124
|
+
"""
|
|
125
|
+
meta = meta or {}
|
|
126
|
+
catalog = meta.get("catalog") or []
|
|
127
|
+
products = [str(p) for p in (meta.get("products") or []) if p]
|
|
128
|
+
id_by_lower = {}
|
|
129
|
+
for item in catalog:
|
|
130
|
+
name = str(item.get("name") or "").strip()
|
|
131
|
+
if name:
|
|
132
|
+
id_by_lower[name.lower()] = str(item.get("id")) if item.get("id") is not None else None
|
|
133
|
+
|
|
134
|
+
canon: dict[str, dict] = {} # lower(name) -> {"label","id","aliases":set(),"brand":bool}
|
|
135
|
+
|
|
136
|
+
def _slot(name, brand):
|
|
137
|
+
key = str(name).strip().lower()
|
|
138
|
+
cur = canon.get(key)
|
|
139
|
+
if cur is None:
|
|
140
|
+
canon[key] = {"label": str(name).strip(), "id": None,
|
|
141
|
+
"aliases": set(), "brand": brand, "derived": set()}
|
|
142
|
+
cur = canon[key]
|
|
143
|
+
elif brand and not cur["brand"]:
|
|
144
|
+
cur["label"], cur["brand"] = str(name).strip(), True
|
|
145
|
+
cur["aliases"].add(str(name).strip())
|
|
146
|
+
return cur
|
|
147
|
+
|
|
148
|
+
for name in products: # 展示名优先成为标签
|
|
149
|
+
_slot(name, True)
|
|
150
|
+
for item in catalog: # catalog 名补位(无展示名时用库内名)
|
|
151
|
+
if item.get("name"):
|
|
152
|
+
_slot(item["name"], False)
|
|
153
|
+
|
|
154
|
+
# ① 规则派生:每个登记名派生多种写法(去空格 / 拉丁核心词 / 大小写变体)
|
|
155
|
+
# 注意:登记名「原样」不标 caseless——它由 _ascii_hits 的短别名精确规则保护
|
|
156
|
+
# (OBS 不能因此变成小写 obs 而命中 "obs://bucket",S93 铁律)。
|
|
157
|
+
for slot in list(canon.values()):
|
|
158
|
+
raw_label = slot["label"]
|
|
159
|
+
for derived in _derive_aliases(raw_label):
|
|
160
|
+
slot["aliases"].add(derived)
|
|
161
|
+
if derived != raw_label:
|
|
162
|
+
slot["derived"].add(derived)
|
|
163
|
+
|
|
164
|
+
# ② 品牌俗称表:把无法从表名推导的口语词挂到目标产品上
|
|
165
|
+
for target_name, colloquials in (BRAND_ALIASES or {}).items():
|
|
166
|
+
slot = canon.get(str(target_name).lower())
|
|
167
|
+
if slot is None:
|
|
168
|
+
# 目标产品不在本次 catalog(引擎换库/改名):别名不落地,避免指向
|
|
169
|
+
# 不存在的 id。宁可丢俗称,也不产生错归。
|
|
170
|
+
continue
|
|
171
|
+
for word in (colloquials or []):
|
|
172
|
+
if word:
|
|
173
|
+
slot["aliases"].add(str(word).strip())
|
|
174
|
+
|
|
175
|
+
# ③ 兼容:若引擎仍下发旧字段(回滚场景),继续采纳,避免双向改造期丢能力
|
|
176
|
+
for key, aliases in (meta.get("nameAliases") or {}).items():
|
|
177
|
+
aliases = [str(a) for a in (aliases or []) if a]
|
|
178
|
+
target = canon.get(str(key).lower())
|
|
179
|
+
if target is None:
|
|
180
|
+
for a in aliases:
|
|
181
|
+
if a.lower() in canon:
|
|
182
|
+
target = canon[a.lower()]
|
|
183
|
+
break
|
|
184
|
+
if target is None:
|
|
185
|
+
target = _slot(key, True)
|
|
186
|
+
for a in aliases:
|
|
187
|
+
target["aliases"].add(a)
|
|
188
|
+
target["aliases"].add(str(key))
|
|
189
|
+
for key, target_name in (meta.get("aliases") or {}).items():
|
|
190
|
+
slot = canon.get(str(target_name).lower())
|
|
191
|
+
if slot is None: # 目录/展示名都没有该目标:按别名目标建槽,别丢别名
|
|
192
|
+
slot = _slot(target_name, False)
|
|
193
|
+
slot["aliases"].add(str(key))
|
|
194
|
+
|
|
195
|
+
for slot in canon.values(): # 名字/别名任一命中 catalog → 拿 id
|
|
196
|
+
for alias in list(slot["aliases"]) + [slot["label"]]:
|
|
197
|
+
if alias.lower() in id_by_lower:
|
|
198
|
+
slot["id"] = id_by_lower[alias.lower()]
|
|
199
|
+
break
|
|
200
|
+
|
|
201
|
+
merged: list = [] # 同 id 合并(展示名那条为准)
|
|
202
|
+
by_id: dict = {}
|
|
203
|
+
for slot in canon.values():
|
|
204
|
+
pid = slot["id"]
|
|
205
|
+
if pid is not None and pid in by_id:
|
|
206
|
+
by_id[pid]["aliases"] |= slot["aliases"]
|
|
207
|
+
continue
|
|
208
|
+
if pid is not None:
|
|
209
|
+
by_id[pid] = slot
|
|
210
|
+
merged.append(slot)
|
|
211
|
+
|
|
212
|
+
entries: list = []
|
|
213
|
+
seen: set = set()
|
|
214
|
+
for slot in merged:
|
|
215
|
+
for alias in slot["aliases"]:
|
|
216
|
+
key = (slot["label"].lower(), alias) # 大小写敏感:保留 MaaS/Maas 两种写法
|
|
217
|
+
if not alias or key in seen:
|
|
218
|
+
continue
|
|
219
|
+
seen.add(key)
|
|
220
|
+
entries.append({"product": slot["label"], "id": slot["id"], "alias": alias,
|
|
221
|
+
# 派生写法允许大小写不敏感;但**全大写缩写永不 caseless**——
|
|
222
|
+
# "对象存储服务 OBS" 派生的 OBS 曾因此命中 "obs://bucket" 与
|
|
223
|
+
# "/obs/bin"(2026-11-12 实测,S93 铁律被破)
|
|
224
|
+
"caseless": (alias in (slot.get("derived") or set())
|
|
225
|
+
and alias != alias.upper())})
|
|
226
|
+
entries.sort(key=lambda e: len(e["alias"]), reverse=True)
|
|
227
|
+
return entries
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def _ascii_hits(text: str, alias: str, caseless: bool = False) -> list:
|
|
231
|
+
"""拉丁别名:词边界 + 大小写策略(短别名精确大小写)。
|
|
232
|
+
|
|
233
|
+
caseless=True 用于**从登记名派生**的写法(如表里 "Maas" 派生的 "MaaS"):
|
|
234
|
+
这类变体本就来自同一登记名,允许大小写不敏感,否则用户写 "MaaS" 会漏。
|
|
235
|
+
手写简称(meta 下发/品牌表)仍走精确匹配,避免 obs≠OBS 之类误伤。
|
|
236
|
+
"""
|
|
237
|
+
exact_case = (not caseless) and len(alias) < _SHORT_ALIAS_MAX
|
|
238
|
+
hay = text if exact_case else text.lower()
|
|
239
|
+
needle = alias if exact_case else alias.lower()
|
|
240
|
+
out: list = []
|
|
241
|
+
start = 0
|
|
242
|
+
while True:
|
|
243
|
+
i = hay.find(needle, start)
|
|
244
|
+
if i < 0:
|
|
245
|
+
return out
|
|
246
|
+
j = i + len(needle)
|
|
247
|
+
ok_before = i == 0 or hay[i - 1] not in _BOUNDARY
|
|
248
|
+
ok_after = True
|
|
249
|
+
if j < len(hay):
|
|
250
|
+
nxt = hay[j]
|
|
251
|
+
if nxt in _BOUNDARY:
|
|
252
|
+
ok_after = False
|
|
253
|
+
elif nxt == "." and j + 1 < len(hay) and hay[j + 1].isalnum():
|
|
254
|
+
ok_after = False # codearts.yaml 这类文件名不是产品名
|
|
255
|
+
if ok_before and ok_after:
|
|
256
|
+
prev = hay[i - 1] if i else ""
|
|
257
|
+
nxt2 = hay[j] if j < len(hay) else ""
|
|
258
|
+
if prev in ("/", "\\", ".", "@") or nxt2 in (":", "/", "\\"):
|
|
259
|
+
start = i + 1
|
|
260
|
+
continue # URL/路径上下文不是产品提及:obs://bucket、/obs/bin、a@obs
|
|
261
|
+
out.append((i, j))
|
|
262
|
+
start = i + 1
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def _snippet(text: str, start: int, end: int) -> str:
|
|
266
|
+
lo = max(0, start - _SNIPPET_PAD)
|
|
267
|
+
hi = min(len(text), end + _SNIPPET_PAD)
|
|
268
|
+
frag = " ".join(text[lo:hi].split())
|
|
269
|
+
return frag[:_SNIPPET_MAX]
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def match_products(text: str, index: list) -> list:
|
|
273
|
+
"""在用户原话里找产品别名 → 命中列表(长别名优先,重叠不重复计)。
|
|
274
|
+
|
|
275
|
+
[{"product","id","alias","start","end","snippet"}]
|
|
276
|
+
"""
|
|
277
|
+
text = str(text or "")
|
|
278
|
+
if not text or not index:
|
|
279
|
+
return []
|
|
280
|
+
taken: list = []
|
|
281
|
+
hits: list = []
|
|
282
|
+
for entry in index:
|
|
283
|
+
alias = entry["alias"]
|
|
284
|
+
spans = _ascii_hits(text, alias, entry.get("caseless", False)) if _is_ascii(alias) else [
|
|
285
|
+
(m.start(), m.end()) for m in re.finditer(re.escape(alias), text)]
|
|
286
|
+
for start, end in spans:
|
|
287
|
+
if any(not (end <= s or start >= e) for s, e in taken):
|
|
288
|
+
continue # 被更长别名覆盖(「软件开发生产线 CodeArts」不吃子串)
|
|
289
|
+
taken.append((start, end))
|
|
290
|
+
hits.append({"product": entry["product"], "id": entry["id"],
|
|
291
|
+
"alias": alias, "start": start, "end": end,
|
|
292
|
+
"snippet": _snippet(text, start, end)})
|
|
293
|
+
hits.sort(key=lambda h: h["start"])
|
|
294
|
+
return hits
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def _group(hits: list) -> dict:
|
|
298
|
+
"""按产品合并(同产品多别名命中取最长片段作证据)。"""
|
|
299
|
+
grouped: dict = {}
|
|
300
|
+
for h in hits:
|
|
301
|
+
key = h["product"].lower()
|
|
302
|
+
cur = grouped.get(key)
|
|
303
|
+
if cur is None or len(h["alias"]) > len(cur["alias"]):
|
|
304
|
+
grouped[key] = dict(h)
|
|
305
|
+
return grouped
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def resolve_id(product: str, meta: dict) -> str:
|
|
309
|
+
"""产品名/短码/主键 → 提交值:目录命中给 id,否则规范名(引擎 name 兼容通道)。"""
|
|
310
|
+
product = str(product or "").strip()
|
|
311
|
+
if not product:
|
|
312
|
+
return ""
|
|
313
|
+
if product.isdigit():
|
|
314
|
+
return product
|
|
315
|
+
idx = build_alias_index(meta)
|
|
316
|
+
low = product.lower()
|
|
317
|
+
for entry in idx:
|
|
318
|
+
if entry["product"].lower() == low and entry["id"]:
|
|
319
|
+
return str(entry["id"])
|
|
320
|
+
for entry in idx:
|
|
321
|
+
if entry["alias"].lower() == low and entry["id"]:
|
|
322
|
+
return str(entry["id"])
|
|
323
|
+
return product
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def attribute(text: str, meta: dict, memory: dict | None = None,
|
|
327
|
+
binding: str | None = None, ttl: int = MEM_TTL,
|
|
328
|
+
now: float | None = None) -> dict:
|
|
329
|
+
"""归因优先级链:字面证据 > 记忆 > 安装先验 > UNKNOWN。
|
|
330
|
+
|
|
331
|
+
返回 {"product": 提交值或 None, "source": user_input|memory|install_binding|unknown,
|
|
332
|
+
"evidence": [{"product","alias","snippet","reason"?}]}
|
|
333
|
+
"""
|
|
334
|
+
import time
|
|
335
|
+
now = time.time() if now is None else now
|
|
336
|
+
hits = match_products(text, build_alias_index(meta))
|
|
337
|
+
grouped = _group(hits)
|
|
338
|
+
|
|
339
|
+
if len(grouped) == 1:
|
|
340
|
+
hit = next(iter(grouped.values()))
|
|
341
|
+
return {"product": str(hit["id"]) if hit["id"] else hit["product"],
|
|
342
|
+
"productName": hit["product"], "source": "user_input",
|
|
343
|
+
"evidence": [{"product": hit["product"], "alias": hit["alias"],
|
|
344
|
+
"snippet": hit["snippet"]}]}
|
|
345
|
+
|
|
346
|
+
if len(grouped) > 1:
|
|
347
|
+
# P1-A:歧义一律 UNKNOWN,全部命中留痕(人工归因要有上下文)
|
|
348
|
+
return {"product": None, "productName": None, "source": "unknown",
|
|
349
|
+
"evidence": [{"product": h["product"], "alias": h["alias"],
|
|
350
|
+
"snippet": h["snippet"], "reason": "ambiguous"}
|
|
351
|
+
for h in hits]}
|
|
352
|
+
|
|
353
|
+
mem = memory or {}
|
|
354
|
+
if mem.get("product") and now - float(mem.get("at") or 0) <= ttl:
|
|
355
|
+
return {"product": str(mem["product"]),
|
|
356
|
+
"productName": mem.get("productName") or None, "source": "memory",
|
|
357
|
+
"evidence": [{"product": mem.get("productName") or str(mem["product"]),
|
|
358
|
+
"alias": mem.get("alias"), "snippet": mem.get("snippet"),
|
|
359
|
+
"at": mem.get("at"), "reason": "memory"}]}
|
|
360
|
+
|
|
361
|
+
if binding:
|
|
362
|
+
return {"product": resolve_id(binding, meta), "productName": str(binding),
|
|
363
|
+
"source": "install_binding", "evidence": []}
|
|
364
|
+
|
|
365
|
+
return {"product": None, "productName": None, "source": "unknown",
|
|
366
|
+
"evidence": [{"reason": "no-evidence"}]}
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def remember_if_evidenced(result: dict) -> dict | None:
|
|
370
|
+
"""只有「字面证据唯一命中」的归因才写记忆(S100:歧义/无证据不污染)。"""
|
|
371
|
+
if result.get("source") != "user_input":
|
|
372
|
+
return None
|
|
373
|
+
ev = (result.get("evidence") or [{}])[0]
|
|
374
|
+
import time
|
|
375
|
+
return {"product": result.get("product"),
|
|
376
|
+
"productName": ev.get("product") or result.get("productName"),
|
|
377
|
+
"alias": ev.get("alias"), "snippet": ev.get("snippet"),
|
|
378
|
+
"at": int(time.time())}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""宿主适配注册表(数据驱动分派)。
|
|
2
|
+
|
|
3
|
+
加宿主 = 一个模块 + REGISTRY 一行;bin/vod-devkit 不再出现宿主分支
|
|
4
|
+
(对标 huaweicloud-devkit 的 agents/<id>.ts + switch 分派形态)。
|
|
5
|
+
|
|
6
|
+
REGISTRY 里的模块必须实现 protocol 的三件事:install / install_remote / skills_dir。
|
|
7
|
+
"""
|
|
8
|
+
from vod_mcp.host_adapters import codearts, codex, dsh, generic, hermes, opencode
|
|
9
|
+
|
|
10
|
+
REGISTRY = {
|
|
11
|
+
"hermes": hermes,
|
|
12
|
+
"opencode": opencode,
|
|
13
|
+
"codeartsdoer": codearts,
|
|
14
|
+
"codex": codex,
|
|
15
|
+
"dsh": dsh,
|
|
16
|
+
"generic": generic,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get(target: str):
|
|
21
|
+
"""未知宿主抛 KeyError(调用方给"不支持目标"提示,不许静默降级)。"""
|
|
22
|
+
return REGISTRY[target]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def modules() -> dict:
|
|
26
|
+
return dict(REGISTRY)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""宿主适配公共件:MCP server 入口、环境与 JSON 配置合并(各宿主共用)。"""
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
ROOT = Path(__file__).resolve().parent.parent.parent
|
|
8
|
+
|
|
9
|
+
# 载荷目录(bin 在 install 前用 payload.stage() 落好并 set_payload_dir 指过来)
|
|
10
|
+
_PAYLOAD_DIR = None
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def set_payload_dir(path) -> None:
|
|
14
|
+
global _PAYLOAD_DIR
|
|
15
|
+
_PAYLOAD_DIR = Path(path) if path else None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def payload_dir():
|
|
19
|
+
return _PAYLOAD_DIR
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def server_entry() -> str:
|
|
23
|
+
"""MCP server 绝对路径:优先载荷副本(npx 缓存被清也不会掉线),否则仓内。"""
|
|
24
|
+
base = _PAYLOAD_DIR or ROOT
|
|
25
|
+
return str(Path(base) / "vod_mcp" / "server.py")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def server_env(args, packs: str) -> dict:
|
|
29
|
+
# 无 key 不写空串(空串会让探针/严格解析器误当字面值;运行时空=未设置,
|
|
30
|
+
# 自动兜底 runtime.json java_key 或首提申请匿名令牌)
|
|
31
|
+
env = {"VOD_PACKS": packs,
|
|
32
|
+
"VOD_JAVA_API_BASE": args.java_api_base}
|
|
33
|
+
key = os.environ.get("VOD_JAVA_API_KEY", "")
|
|
34
|
+
if key:
|
|
35
|
+
env["VOD_JAVA_API_KEY"] = key
|
|
36
|
+
return env
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def merge_json_mcp(path: Path, entry: dict, section: str = "mcp",
|
|
40
|
+
name: str = "vod-devkit", backup: bool = True) -> str:
|
|
41
|
+
"""读写共享 JSON 配置里的 <section>.<name> 条目(保留其它键/其它 server)。
|
|
42
|
+
|
|
43
|
+
返回 created / updated / unchanged;文件不是合法 JSON 时抛 RuntimeError
|
|
44
|
+
(调用方拒绝安装,字节不动)。共享配置文件首改落 .bak。
|
|
45
|
+
"""
|
|
46
|
+
cfg = {}
|
|
47
|
+
existed = path.exists()
|
|
48
|
+
if existed:
|
|
49
|
+
raw = path.read_text(encoding="utf-8")
|
|
50
|
+
if raw.strip():
|
|
51
|
+
try:
|
|
52
|
+
parsed = json.loads(raw)
|
|
53
|
+
except json.JSONDecodeError as e:
|
|
54
|
+
raise RuntimeError(f"{path} 不是合法 JSON({e.msg}),拒绝改动") from e
|
|
55
|
+
if not isinstance(parsed, dict):
|
|
56
|
+
raise RuntimeError(f"{path} 顶层不是对象,拒绝改动")
|
|
57
|
+
cfg = parsed
|
|
58
|
+
block = cfg.get(section)
|
|
59
|
+
if block is None:
|
|
60
|
+
block = {}
|
|
61
|
+
elif not isinstance(block, dict):
|
|
62
|
+
raise RuntimeError(f"{path} 的 {section} 不是对象,拒绝改动")
|
|
63
|
+
if block.get(name) == entry:
|
|
64
|
+
return "unchanged"
|
|
65
|
+
action = "updated" if block.get(name) else "created"
|
|
66
|
+
if existed and backup:
|
|
67
|
+
shutil.copyfile(path, str(path) + ".bak")
|
|
68
|
+
block[name] = entry
|
|
69
|
+
cfg[section] = block
|
|
70
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
71
|
+
path.write_text(json.dumps(cfg, ensure_ascii=False, indent=2) + "\n",
|
|
72
|
+
encoding="utf-8")
|
|
73
|
+
return action
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""CodeArts Agent 宿主适配(实测 2026-11-11)。
|
|
2
|
+
|
|
3
|
+
CodeArts Agent 是 OpenCode 的分支(安装壳导出 SCENARIO=codeartsdoer、
|
|
4
|
+
OPENCODE_CONFIG=~/.codeartsdoer/codearts_cli.json、KERNEL_CONFIG_DIR=~/.codeartsdoer),
|
|
5
|
+
所以配置形态与 opencode 同 schema:`mcp.<name> = {type:"local", command:[...], enabled}`。
|
|
6
|
+
|
|
7
|
+
现场实测(本机 codearts 已装,286MB 二进制):
|
|
8
|
+
- 往 ~/.codeartsdoer/codearts_cli.json 写 mcp.vod-probe → `codearts mcp list`
|
|
9
|
+
输出 "● ○ vod-probe disabled / python3 -c pass" → 通道有效,已还原。
|
|
10
|
+
- `codearts mcp add` 没有任何参数(交互式向导)→ 程序化只能写 JSON,再用
|
|
11
|
+
`codearts mcp list` 冒烟。
|
|
12
|
+
- mcp_settings.json 只对**项目级** `<project>/.codeartsdoer/mcp/mcp_settings.json`
|
|
13
|
+
生效(二进制:`.${SCENARIO}/mcp/mcp_settings.json`);用户级读
|
|
14
|
+
`~/.config/opencode/mcp/mcp_settings.json` —— 写 ~/.codeartsdoer/mcp/ 无效。
|
|
15
|
+
- 技能目录 ~/.codeartsdoer/skills(二进制字符串 "codeartsdoer/skills/")。
|
|
16
|
+
"""
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
from vod_mcp import hosts as host_specs
|
|
21
|
+
from vod_mcp.host_adapters.base import merge_json_mcp, server_env, server_entry
|
|
22
|
+
|
|
23
|
+
HOST = "codeartsdoer"
|
|
24
|
+
SUPPORTS_REMOTE = True
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _spec() -> dict:
|
|
28
|
+
"""每次现读:host.json 的 ~ 相对 HOME 解析必须在调用期做(测试可重定向 HOME)。"""
|
|
29
|
+
return host_specs.load("codeartsdoer")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def skills_dir(args):
|
|
33
|
+
d = _spec().get("skillsDir")
|
|
34
|
+
return Path(d) if d else None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def install(args, packs):
|
|
38
|
+
"""写 codearts_cli.json 的 mcp.vod-devkit(无损合并,保留 provider/model 等键)。"""
|
|
39
|
+
conf = Path(_spec()["configPath"])
|
|
40
|
+
entry = {
|
|
41
|
+
"type": "local",
|
|
42
|
+
"command": [sys.executable, server_entry()],
|
|
43
|
+
"enabled": True,
|
|
44
|
+
"environment": server_env(args, packs),
|
|
45
|
+
}
|
|
46
|
+
action = merge_json_mcp(conf, entry)
|
|
47
|
+
print(f"已写入 CodeArts Agent 配置({action}):{conf}(重启 codearts 会话生效)")
|
|
48
|
+
return conf
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def install_remote(args, url, token):
|
|
52
|
+
conf = Path(_spec()["configPath"])
|
|
53
|
+
entry = {"type": "remote", "url": url, "enabled": True,
|
|
54
|
+
"headers": {"Authorization": f"Bearer {token}"}}
|
|
55
|
+
action = merge_json_mcp(conf, entry)
|
|
56
|
+
print(f"已写入 CodeArts Agent 远程 MCP({action}):{conf}(token 明文,注意文件权限)")
|
|
57
|
+
return conf
|