dsh-vod-devkit 0.4.4 → 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/README.md +9 -8
- package/lib/index.js +380 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,28 +8,29 @@ VOD 用户声音采集插件 —— DeepSeek Harness (dsh) 薄壳。
|
|
|
8
8
|
- 插件=引擎客户端,只走 HTTPS(VOD external API),不 import 任何引擎模块
|
|
9
9
|
- 与 vod-devkit(MCP 形态,同仓 `../vod_mcp`)语义对齐:
|
|
10
10
|
- voiceId = f(source, content, 调用级 nonce):同调用幂等、跨调用保声量
|
|
11
|
-
-
|
|
12
|
-
|
|
11
|
+
- 归因=运行期从用户原话解析(引擎产品名录别名,含中文/长别名),唯一命中才采信;
|
|
12
|
+
优先级:字面证据 > 记忆(30 分钟)> 配置 product 先验 > 未知(引擎 UNKNOWN 池)
|
|
13
|
+
- 多产品命中=歧义 → 不带 product 上送(宁可人工归因,不可错归;与 vod_mcp 同口径)
|
|
13
14
|
- 无 key/401 → POST /external/token 零字段匿名令牌 → 本地落盘 → 重试一次
|
|
14
15
|
- 本地账本 data/runtime.json(cap 200 环形,读改写只动目标键)
|
|
15
16
|
|
|
16
17
|
## 安装
|
|
17
18
|
|
|
18
19
|
```
|
|
19
|
-
npx --yes vod-devkit install --target dsh --profile <name> --product <产品> #
|
|
20
|
+
npx --yes vod-devkit install --target dsh --profile <name> [--product <产品>] # 推荐(--product 可选先验;给了即硬校验)
|
|
20
21
|
```
|
|
21
22
|
|
|
22
23
|
> ⚠️ 不要用 `dsh plugin add dsh-vod-devkit` 裸装:只装插件本体不写配置——
|
|
23
|
-
>
|
|
24
|
-
>
|
|
25
|
-
>
|
|
24
|
+
> apiBase/uiBase 缺失时工具半不可用、UI 提交会发往 dsh 同源(404 → 本地暂存
|
|
25
|
+
> 发不出去,嵌入方真机实锤)。裸装后补救:跑一次上面的 npx 命令即可(幂等)。
|
|
26
|
+
> product 不再是必填:归因默认从用户原话解析,配置值只是无证据时的先验。
|
|
26
27
|
|
|
27
28
|
装后配置落在 profile 的 cordis.patch.yml(npx 包装命令自动写入):
|
|
28
29
|
|
|
29
30
|
```yaml
|
|
30
31
|
- id: vod-devkit
|
|
31
32
|
config:
|
|
32
|
-
product:
|
|
33
|
+
product: '' # 可选先验(无字面证据且无记忆时兜底);归因主路径=用户原话解析
|
|
33
34
|
# apiBase: https://vod-dev.topxtopx.com # 工具半(Node 服务端)用,缺省即此
|
|
34
35
|
# uiBase: https://vod-dev.topxtopx.com # 浏览器半(反馈按钮)直连用,缺省即此
|
|
35
36
|
```
|
|
@@ -49,7 +50,7 @@ npx --yes vod-devkit install --target dsh --profile <name> --product <产品>
|
|
|
49
50
|
| apiBase | https://vod-dev.topxtopx.com | VOD external API 基址(工具半/服务端用) |
|
|
50
51
|
| uiBase | 同 apiBase | 浏览器半(反馈按钮)直连基址;同源代理形态可留空 |
|
|
51
52
|
| apiKey | (空) | 缺省走零字段匿名令牌;灰度期可用运营签发 key |
|
|
52
|
-
| product | (空) |
|
|
53
|
+
| product | (空) | 可选归因先验(如 codearts):仅在无字面证据且无记忆时生效;空=完全靠原话解析,歧义落 UNKNOWN |
|
|
53
54
|
| confirmWrites | true | 写操作走 dsh 审批通道(tools/pre-execute → ask) |
|
|
54
55
|
| timeoutSec | 30 | HTTP 超时 |
|
|
55
56
|
|
package/lib/index.js
CHANGED
|
@@ -13,19 +13,24 @@ import z from '@deepseek-ai/schemastery';
|
|
|
13
13
|
import { createHash, randomUUID } from 'node:crypto';
|
|
14
14
|
import { fileURLToPath } from 'node:url';
|
|
15
15
|
import { dirname, join } from 'node:path';
|
|
16
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
16
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync } from 'node:fs';
|
|
17
|
+
import { homedir } from 'node:os';
|
|
17
18
|
|
|
18
19
|
export const name = 'vod-devkit';
|
|
19
20
|
export const inject = ['tools'];
|
|
20
21
|
|
|
21
22
|
const PKG_DIR = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
22
23
|
const DATA_DIR = join(PKG_DIR, 'data');
|
|
23
|
-
|
|
24
|
+
// 运行时状态路径可用 VOD_DSH_RUNTIME 覆盖(测试隔离/企业数据驻留用;
|
|
25
|
+
// 2026-11-11 实锤:dsh/test 直写仓内 dsh/data/runtime.json,本地账本被测试
|
|
26
|
+
// 灌到 128 条——测试必须能指到 tmp,不能再共用真实账本)
|
|
27
|
+
const RUNTIME = process.env.VOD_DSH_RUNTIME || join(DATA_DIR, 'runtime.json');
|
|
24
28
|
const API_PREFIX = '/rest/developer/manager/hdvodmngservice/v1';
|
|
25
29
|
const HOARD_PATH = `${API_PREFIX}/external/voices`; // V16 囤积端点(批量/不触发 LLM/结构化回执)
|
|
26
30
|
const SUBMIT_PATH = `${API_PREFIX}/external/voice/submit`; // 旧单条端点:仅 404 回落使用 // V16 已切换:主路径 HOARD_PATH(囤积),本路径仅 404 回落(见 docs/decisions.md D-dsh-4)
|
|
27
31
|
const TOKEN_PATH = `${API_PREFIX}/external/token`;
|
|
28
32
|
const LEDGER_CAP = 200;
|
|
33
|
+
const PKG_VERSION = JSON.parse(readFileSync(join(PKG_DIR, 'package.json'), 'utf8')).version;
|
|
29
34
|
|
|
30
35
|
export const Config = z.object({
|
|
31
36
|
apiBase: z.string().default('https://vod-dev.topxtopx.com').volatile(),
|
|
@@ -122,25 +127,229 @@ async function http(method, path, body, { base, key, timeoutSec, signal }) {
|
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
129
|
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
//
|
|
130
|
+
// ── 归因(D-attrib-B,2026-11-11 负责人拍板 A/A/A/A):与 vod_mcp/attribution.py
|
|
131
|
+
// 同一口径——用户原话字面证据 > 记忆(TTL 30 分钟)> 部署 config 先验 > 未知。
|
|
132
|
+
// 唯一命中才采信;多产品命中=歧义 → 不上送 product(引擎 UNKNOWN 池);
|
|
133
|
+
// 模型自报参数不存在(本壳工具面无 product 入参)。
|
|
129
134
|
const META_PATH = `${API_PREFIX}/external/meta`;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
const META_TTL_MS = 24 * 3600 * 1000;
|
|
136
|
+
const ATTR_MEM_TTL = 30 * 60; // 秒(与 Python 侧 MEM_TTL 对齐)
|
|
137
|
+
const ATTR_SHORT_ALIAS = 5; // <5 字符短别名只认大小写精确(obs/maas)
|
|
138
|
+
const ATTR_BOUNDARY = /[A-Za-z0-9_-]/;
|
|
139
|
+
const ATTR_HISTORY_CAP = 10;
|
|
140
|
+
let _metaCache = null; // {at, data}
|
|
141
|
+
|
|
142
|
+
function emptyMeta() {
|
|
143
|
+
return { products: [], catalog: [], aliases: {}, nameAliases: {} };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function loadMeta(cfg, signal) {
|
|
147
|
+
if (_metaCache && Date.now() - _metaCache.at < META_TTL_MS) return _metaCache.data;
|
|
133
148
|
try {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
149
|
+
const out = await http('GET', META_PATH, undefined, { ...cfg, signal });
|
|
150
|
+
const d = out?.data?.data || out?.data || {};
|
|
151
|
+
const meta = {
|
|
152
|
+
products: Array.isArray(d.products) ? d.products : [],
|
|
153
|
+
catalog: Array.isArray(d.productCatalog) ? d.productCatalog : [],
|
|
154
|
+
aliases: d.aliases && typeof d.aliases === 'object' ? d.aliases : {},
|
|
155
|
+
nameAliases: d.nameAliases && typeof d.nameAliases === 'object' ? d.nameAliases : {},
|
|
156
|
+
};
|
|
157
|
+
if (meta.products.length) {
|
|
158
|
+
_metaCache = { at: Date.now(), data: meta };
|
|
159
|
+
return meta;
|
|
160
|
+
}
|
|
161
|
+
} catch (e) { /* 名录不可用 → 快照空:短码都拿不到,宁可 UNKNOWN 不猜 */ }
|
|
162
|
+
return _metaCache?.data || emptyMeta();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function buildAliasIndex(meta = {}) {
|
|
166
|
+
const products = (meta.products || []).map(String).filter(Boolean);
|
|
167
|
+
const catalog = meta.catalog || [];
|
|
168
|
+
const idByLower = new Map();
|
|
169
|
+
for (const it of catalog) {
|
|
170
|
+
const name = String(it?.name || '').trim();
|
|
171
|
+
if (name) idByLower.set(name.toLowerCase(), it.id != null ? String(it.id) : null);
|
|
172
|
+
}
|
|
173
|
+
const canon = new Map(); // lower(name) -> {label,id,aliases:Set,brand}
|
|
174
|
+
const slot = (nm, brand) => {
|
|
175
|
+
const key = String(nm).trim().toLowerCase();
|
|
176
|
+
let cur = canon.get(key);
|
|
177
|
+
if (!cur) {
|
|
178
|
+
cur = { label: String(nm).trim(), id: null, aliases: new Set(), brand: !!brand };
|
|
179
|
+
canon.set(key, cur);
|
|
180
|
+
} else if (brand && !cur.brand) {
|
|
181
|
+
cur.label = String(nm).trim();
|
|
182
|
+
cur.brand = true;
|
|
183
|
+
}
|
|
184
|
+
cur.aliases.add(String(nm).trim());
|
|
185
|
+
return cur;
|
|
186
|
+
};
|
|
187
|
+
products.forEach((p) => slot(p, true)); // 展示名优先成标签
|
|
188
|
+
catalog.forEach((it) => { if (it?.name) slot(it.name, false); });
|
|
189
|
+
for (const [key, list] of Object.entries(meta.nameAliases || {})) {
|
|
190
|
+
const aliases = (list || []).map(String).filter(Boolean);
|
|
191
|
+
let target = canon.get(String(key).toLowerCase());
|
|
192
|
+
if (!target) {
|
|
193
|
+
for (const a of aliases) {
|
|
194
|
+
const s = canon.get(a.toLowerCase());
|
|
195
|
+
if (s) { target = s; break; }
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (!target) target = slot(key, true);
|
|
199
|
+
aliases.forEach((a) => target.aliases.add(a));
|
|
200
|
+
target.aliases.add(String(key));
|
|
201
|
+
}
|
|
202
|
+
for (const [key, targetName] of Object.entries(meta.aliases || {})) {
|
|
203
|
+
let s = canon.get(String(targetName).toLowerCase());
|
|
204
|
+
if (!s) s = slot(targetName, false); // 目标不在名录也不丢别名
|
|
205
|
+
s.aliases.add(String(key));
|
|
206
|
+
}
|
|
207
|
+
for (const s of canon.values()) { // 名字/别名任一命中 catalog → 拿 id
|
|
208
|
+
for (const a of [s.label, ...s.aliases]) {
|
|
209
|
+
if (idByLower.has(a.toLowerCase())) {
|
|
210
|
+
const id = idByLower.get(a.toLowerCase());
|
|
211
|
+
if (id != null) { s.id = id; break; }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const merged = [];
|
|
216
|
+
const byId = new Map(); // 同 id 合并(展示名那条为准)
|
|
217
|
+
for (const s of canon.values()) {
|
|
218
|
+
if (s.id != null && byId.has(s.id)) {
|
|
219
|
+
const keep = byId.get(s.id);
|
|
220
|
+
s.aliases.forEach((a) => keep.aliases.add(a));
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (s.id != null) byId.set(s.id, s);
|
|
224
|
+
merged.push(s);
|
|
225
|
+
}
|
|
226
|
+
const entries = [];
|
|
227
|
+
const seen = new Set();
|
|
228
|
+
for (const s of merged) {
|
|
229
|
+
for (const alias of s.aliases) {
|
|
230
|
+
const key = `${s.label.toLowerCase()}\u0000${alias}`; // 大小写敏感:留住 MaaS/Maas
|
|
231
|
+
if (!alias || seen.has(key)) continue;
|
|
232
|
+
seen.add(key);
|
|
233
|
+
entries.push({ product: s.label, id: s.id, alias });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
entries.sort((a, b) => b.alias.length - a.alias.length);
|
|
237
|
+
return entries;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function snippetOf(text, start, end) {
|
|
241
|
+
const lo = Math.max(0, start - 20);
|
|
242
|
+
const hi = Math.min(text.length, end + 20);
|
|
243
|
+
return text.slice(lo, hi).replace(/\s+/g, ' ').slice(0, 80);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function matchProducts(text, index) {
|
|
247
|
+
const t = String(text || '');
|
|
248
|
+
if (!t || !Array.isArray(index) || !index.length) return [];
|
|
249
|
+
const taken = [];
|
|
250
|
+
const hits = [];
|
|
251
|
+
const isAscii = (s) => [...s].every((c) => c.charCodeAt(0) < 128);
|
|
252
|
+
for (const e of index) {
|
|
253
|
+
const alias = String(e.alias || '');
|
|
254
|
+
if (!alias) continue;
|
|
255
|
+
const spans = [];
|
|
256
|
+
if (!isAscii(alias)) {
|
|
257
|
+
let i = 0;
|
|
258
|
+
while ((i = t.indexOf(alias, i)) >= 0) { spans.push([i, i + alias.length]); i += 1; }
|
|
259
|
+
} else {
|
|
260
|
+
const exact = alias.length < ATTR_SHORT_ALIAS;
|
|
261
|
+
const hay = exact ? t : t.toLowerCase();
|
|
262
|
+
const needle = exact ? alias : alias.toLowerCase();
|
|
263
|
+
let i = 0;
|
|
264
|
+
while ((i = hay.indexOf(needle, i)) >= 0) {
|
|
265
|
+
const j = i + needle.length;
|
|
266
|
+
const beforeOk = i === 0 || !ATTR_BOUNDARY.test(hay[i - 1]);
|
|
267
|
+
let afterOk = true;
|
|
268
|
+
if (j < hay.length) {
|
|
269
|
+
const n = hay[j];
|
|
270
|
+
if (ATTR_BOUNDARY.test(n)) afterOk = false;
|
|
271
|
+
else if (n === '.' && j + 1 < hay.length && /[A-Za-z0-9]/.test(hay[j + 1])) afterOk = false;
|
|
272
|
+
}
|
|
273
|
+
if (beforeOk && afterOk) spans.push([i, j]);
|
|
274
|
+
i += 1;
|
|
275
|
+
}
|
|
138
276
|
}
|
|
139
|
-
const
|
|
140
|
-
(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
277
|
+
for (const [s, en] of spans) {
|
|
278
|
+
if (taken.some(([ts, te]) => !(en <= ts || s >= te))) continue; // 长别名优先
|
|
279
|
+
taken.push([s, en]);
|
|
280
|
+
hits.push({ product: e.product, id: e.id, alias, start: s, end: en, snippet: snippetOf(t, s, en) });
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
hits.sort((a, b) => a.start - b.start);
|
|
284
|
+
return hits;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function resolveSubmitValue(product, meta) {
|
|
288
|
+
const p = String(product || '').trim();
|
|
289
|
+
if (!p) return '';
|
|
290
|
+
if (/^\d+$/.test(p)) return p;
|
|
291
|
+
const idx = buildAliasIndex(meta || {});
|
|
292
|
+
const low = p.toLowerCase();
|
|
293
|
+
for (const e of idx) {
|
|
294
|
+
if (String(e.product).toLowerCase() === low && e.id != null) return String(e.id);
|
|
295
|
+
}
|
|
296
|
+
for (const e of idx) {
|
|
297
|
+
if (String(e.alias).toLowerCase() === low && e.id != null) return String(e.id);
|
|
298
|
+
}
|
|
299
|
+
return p;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function attributeProduct(text, meta, opts = {}) {
|
|
303
|
+
const nowSec = opts.now ?? Math.floor(Date.now() / 1000);
|
|
304
|
+
const ttl = opts.ttl ?? ATTR_MEM_TTL;
|
|
305
|
+
const hits = matchProducts(text, buildAliasIndex(meta || {}));
|
|
306
|
+
const groups = new Map();
|
|
307
|
+
for (const h of hits) {
|
|
308
|
+
const k = String(h.product).toLowerCase();
|
|
309
|
+
const cur = groups.get(k);
|
|
310
|
+
if (!cur || h.alias.length > cur.alias.length) groups.set(k, h);
|
|
311
|
+
}
|
|
312
|
+
if (groups.size === 1) {
|
|
313
|
+
const h = [...groups.values()][0];
|
|
314
|
+
return { product: h.id != null ? String(h.id) : h.product, productName: h.product,
|
|
315
|
+
source: 'user_input',
|
|
316
|
+
evidence: [{ product: h.product, alias: h.alias, snippet: h.snippet }] };
|
|
317
|
+
}
|
|
318
|
+
if (groups.size > 1) {
|
|
319
|
+
return { product: null, productName: null, source: 'unknown',
|
|
320
|
+
evidence: hits.map((h) => ({ product: h.product, alias: h.alias,
|
|
321
|
+
snippet: h.snippet, reason: 'ambiguous' })) };
|
|
322
|
+
}
|
|
323
|
+
const mem = opts.memory || {};
|
|
324
|
+
if (mem.product && nowSec - Number(mem.at || 0) <= ttl) {
|
|
325
|
+
return { product: String(mem.product), productName: mem.productName || null,
|
|
326
|
+
source: 'memory',
|
|
327
|
+
evidence: [{ product: mem.productName || String(mem.product), alias: mem.alias,
|
|
328
|
+
snippet: mem.snippet, at: mem.at, reason: 'memory' }] };
|
|
329
|
+
}
|
|
330
|
+
const binding = String(opts.binding || '').trim();
|
|
331
|
+
if (binding) {
|
|
332
|
+
return { product: resolveSubmitValue(binding, meta), productName: binding,
|
|
333
|
+
source: 'install_binding', evidence: [] };
|
|
334
|
+
}
|
|
335
|
+
return { product: null, productName: null, source: 'unknown',
|
|
336
|
+
evidence: [{ reason: 'no-evidence' }] };
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// 记忆:只记「字面证据唯一命中」;覆盖时旧条目进 attribution_history(cap 10)
|
|
340
|
+
function rememberAttribution(attr) {
|
|
341
|
+
if (attr?.source !== 'user_input') return;
|
|
342
|
+
const ev = (attr.evidence || [])[0] || {};
|
|
343
|
+
const mem = { product: attr.product, productName: ev.product || attr.productName || null,
|
|
344
|
+
alias: ev.alias, snippet: ev.snippet, at: Math.floor(Date.now() / 1000) };
|
|
345
|
+
const rt = loadRuntime();
|
|
346
|
+
const prev = rt.attribution_memory || {};
|
|
347
|
+
if (prev.product) {
|
|
348
|
+
const hist = (Array.isArray(rt.attribution_history) ? rt.attribution_history : [])
|
|
349
|
+
.concat([{ ...prev, replacedAt: mem.at }]).slice(-ATTR_HISTORY_CAP);
|
|
350
|
+
saveRuntime({ attribution_history: hist });
|
|
351
|
+
}
|
|
352
|
+
saveRuntime({ attribution_memory: mem });
|
|
144
353
|
}
|
|
145
354
|
|
|
146
355
|
async function fetchAnonToken(cfg) {
|
|
@@ -151,15 +360,6 @@ async function fetchAnonToken(cfg) {
|
|
|
151
360
|
return null;
|
|
152
361
|
}
|
|
153
362
|
|
|
154
|
-
const PRODUCT_MAP = { // 引擎枚举归一(实测:小写 codearts → 400 空响应;Python 侧同款映射)
|
|
155
|
-
// 已知差距(M2/M3 不适用于 dsh 形态):本表硬编码,不拉 GET /external/meta——
|
|
156
|
-
// 引擎 VodExternalProducts 变更时需同步此表(含 kb-query-auth 合入后的 AISHELL/nameAliases)。
|
|
157
|
-
// 详见 docs/decisions.md D-dsh-3。
|
|
158
|
-
agentarts: 'AgentArts', codearts: 'CodeArts', dataarts: 'DataArts',
|
|
159
|
-
maas: 'MaaS', obs: 'OBS', officeclaw: 'OfficeClaw',
|
|
160
|
-
modelarts: 'MaaS',
|
|
161
|
-
};
|
|
162
|
-
|
|
163
363
|
function voiceId(source, content, nonce) {
|
|
164
364
|
const h = createHash('sha1').update(content + nonce).digest('hex').slice(0, 12);
|
|
165
365
|
return `ext_${source}_${h}`;
|
|
@@ -294,6 +494,47 @@ export function apply(ctx, config) {
|
|
|
294
494
|
? readCfg(config?.receiptGuard, 'report') : 'report',
|
|
295
495
|
});
|
|
296
496
|
|
|
497
|
+
// ── 技能披露 + 版本提醒(与 Python 侧同口径的只读面)──────────────────
|
|
498
|
+
// 为什么 dsh 必须有这两个:dsh 是本插件唯一没有 MCP 的宿主,规则/话术
|
|
499
|
+
// 全靠落盘技能;而 2026-11-11 前安装器根本没给 dsh 落技能(已修)。
|
|
500
|
+
// 披露让"技能文本=server data",改规则不必碰宿主拷贝。
|
|
501
|
+
const SKILLS_DIR = process.env.VOD_SKILLS_DIR || join(homedir(), '.dsh', 'skills');
|
|
502
|
+
const SKILL_RE = /^[a-z0-9][a-z0-9-]{2,63}$/;
|
|
503
|
+
const SKILL_CAP = 12000;
|
|
504
|
+
const UPDATE_TTL_MS = 24 * 3600 * 1000;
|
|
505
|
+
const DISMISS_DAYS = 3;
|
|
506
|
+
|
|
507
|
+
function skillDirs() {
|
|
508
|
+
try {
|
|
509
|
+
return readdirSync(SKILLS_DIR, { withFileTypes: true })
|
|
510
|
+
.filter((e) => e.isDirectory())
|
|
511
|
+
.map((e) => e.name)
|
|
512
|
+
.filter((n) => existsSync(join(SKILLS_DIR, n, 'SKILL.md')))
|
|
513
|
+
.sort();
|
|
514
|
+
} catch {
|
|
515
|
+
return [];
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function skillDescription(text) {
|
|
520
|
+
const m = /^description:\s*(.+)$/m.exec(text || '');
|
|
521
|
+
return m ? m[1].trim().replace(/^['"]|['"]$/g, '') : '';
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function versionTuple(v) {
|
|
525
|
+
const core = String(v || '').split('-')[0].split('+')[0];
|
|
526
|
+
return core.split('.').slice(0, 3).map((x) => Number.parseInt(x, 10) || 0)
|
|
527
|
+
.concat([0, 0]).slice(0, 3);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function cmpVersion(a, b) {
|
|
531
|
+
const x = versionTuple(a), y = versionTuple(b);
|
|
532
|
+
for (let i = 0; i < 3; i += 1) {
|
|
533
|
+
if (x[i] !== y[i]) return x[i] > y[i] ? 1 : -1;
|
|
534
|
+
}
|
|
535
|
+
return 0;
|
|
536
|
+
}
|
|
537
|
+
|
|
297
538
|
const tools = [
|
|
298
539
|
{
|
|
299
540
|
name: 'vod_submit_voices',
|
|
@@ -312,7 +553,7 @@ export function apply(ctx, config) {
|
|
|
312
553
|
+ 'content MUST be a faithful transcription of the user\'s own words - '
|
|
313
554
|
+ 'NEVER invent sentiment (e.g. 体验不好) or fabricate content the user did not say. '
|
|
314
555
|
+ 'A bare product name or a question is NOT feedback - ask what the user wants to report. ' +
|
|
315
|
-
'
|
|
556
|
+
'Attribution comes from the user\'s own words; config product is only a fallback. NEVER ask or invent a product. ' +
|
|
316
557
|
'Fixed one-time follow-up at confirmation, verbatim: 「方便的话,补充一下遇到这个问题时的操作步骤或期望的表现吗?不方便回复"没有",我直接提交。」' +
|
|
317
558
|
'Answer → reproSteps/expectedBehavior verbatim excerpt, never into content; "没有/跳过"=omit both. ' +
|
|
318
559
|
'Batch ≤50. Returns voiceIds (reconciliation key) + taskIds.',
|
|
@@ -330,12 +571,15 @@ export function apply(ctx, config) {
|
|
|
330
571
|
const voices = Array.isArray(args.voices) ? args.voices : [];
|
|
331
572
|
if (!voices.length) return textResult({ error: 'voices 为空', code: -32001 });
|
|
332
573
|
if (voices.length > 50) return textResult({ error: '单批上限 50 条', code: -32001 });
|
|
333
|
-
// 归因(D-attrib-
|
|
334
|
-
//
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
574
|
+
// 归因(D-attrib-B,对齐 vod_mcp/attribution.py):从用户原话解析,
|
|
575
|
+
// 部署 config.product 只是「无字面证据且无记忆」时的先验
|
|
576
|
+
const meta = await loadMeta(c, exec?.signal);
|
|
577
|
+
const attrText = voices.map((v) => String(v?.content ?? '')).join('\n');
|
|
578
|
+
const attr = attributeProduct(attrText, meta, {
|
|
579
|
+
memory: loadRuntime().attribution_memory,
|
|
580
|
+
binding: String(c.product || ''),
|
|
581
|
+
});
|
|
582
|
+
const product = attr.product || '';
|
|
339
583
|
const source = 'dsh';
|
|
340
584
|
// D-rguard-1:原文比对(whitelist 通道=会话日志 user 轮)。enforce 档
|
|
341
585
|
// mismatch/unavailable 拒收;report(默认)只标注;off 全跳过。
|
|
@@ -375,14 +619,15 @@ export function apply(ctx, config) {
|
|
|
375
619
|
hoard.push(hv);
|
|
376
620
|
}
|
|
377
621
|
if (hoard.length) {
|
|
378
|
-
|
|
622
|
+
const hoardBody = { voices: hoard, ...(product ? { product } : {}) };
|
|
623
|
+
let out = await http('POST', HOARD_PATH, hoardBody,
|
|
379
624
|
{ ...c, key, signal: exec?.signal });
|
|
380
625
|
if (out.status === 401 && i0Anon(c)) {
|
|
381
626
|
const token = await fetchAnonToken({ ...c, key: '', signal: exec?.signal });
|
|
382
627
|
if (token) {
|
|
383
628
|
key = token;
|
|
384
629
|
saveRuntime({ java_key: token, token_tier: 'anonymous' });
|
|
385
|
-
out = await http('POST', HOARD_PATH,
|
|
630
|
+
out = await http('POST', HOARD_PATH, hoardBody,
|
|
386
631
|
{ ...c, key, signal: exec?.signal });
|
|
387
632
|
} else {
|
|
388
633
|
return textResult({
|
|
@@ -404,14 +649,18 @@ export function apply(ctx, config) {
|
|
|
404
649
|
taskIds.push(null); // 囤积语义:无即时任务
|
|
405
650
|
}
|
|
406
651
|
const now = new Date().toISOString().replace('T', ' ').slice(0, 19);
|
|
652
|
+
rememberAttribution(attr); // 只记有字面证据的唯一命中
|
|
407
653
|
ledgerAppend(hoard.map((h, i) => ({
|
|
408
654
|
voiceId: ids[i] || '', taskId: null,
|
|
409
655
|
title: h.title.slice(0, 40), product,
|
|
656
|
+
productSource: attr.source, productEvidence: attr.evidence,
|
|
410
657
|
at: now, status: sts[i] === 'skipped' ? 'accepted' : 'accepted',
|
|
411
658
|
})));
|
|
412
659
|
return textResult({
|
|
413
660
|
accepted: accepted.length, voiceIds: accepted,
|
|
414
661
|
taskIds, rejected, path: 'hoarding',
|
|
662
|
+
productSource: attr.source,
|
|
663
|
+
...(attr.evidence && attr.evidence.length ? { productEvidence: attr.evidence } : {}),
|
|
415
664
|
...(rgMode !== 'off' ? { receiptGuard: rgGuardSummary(rgVerdict, hoard.length) } : {}),
|
|
416
665
|
...(d.productRegistered !== undefined ? { productRegistered: d.productRegistered } : {}),
|
|
417
666
|
});
|
|
@@ -431,7 +680,7 @@ export function apply(ctx, config) {
|
|
|
431
680
|
voiceId: vid,
|
|
432
681
|
title: content.slice(0, 128), // R3:title=用户原文(分析消费),模板只允许出现在 description
|
|
433
682
|
description: desc,
|
|
434
|
-
product,
|
|
683
|
+
...(product ? { product } : {}), // 无证据/歧义 → 不带 product(引擎 UNKNOWN 池)
|
|
435
684
|
source,
|
|
436
685
|
...(v.userType ? { customer: v.userType } : {}),
|
|
437
686
|
};
|
|
@@ -462,12 +711,16 @@ export function apply(ctx, config) {
|
|
|
462
711
|
}
|
|
463
712
|
}
|
|
464
713
|
const now = new Date().toISOString().replace('T', ' ').slice(0, 19);
|
|
714
|
+
if (accepted.length) rememberAttribution(attr);
|
|
465
715
|
ledgerAppend(accepted.map((vid, i) => ({
|
|
466
716
|
voiceId: vid, taskId: taskIds[i],
|
|
467
717
|
title: String((voices[i] || {}).content ?? '').slice(0, 40),
|
|
468
|
-
product,
|
|
718
|
+
product, productSource: attr.source, productEvidence: attr.evidence,
|
|
719
|
+
at: now,
|
|
469
720
|
})));
|
|
470
721
|
return textResult({ accepted: accepted.length, voiceIds: accepted, taskIds, rejected,
|
|
722
|
+
productSource: attr.source,
|
|
723
|
+
...(attr.evidence && attr.evidence.length ? { productEvidence: attr.evidence } : {}),
|
|
471
724
|
...(rgMode !== 'off' ? { receiptGuard: rgGuardSummary(rgVerdict, voices.length) } : {}) });
|
|
472
725
|
},
|
|
473
726
|
},
|
|
@@ -514,6 +767,95 @@ export function apply(ctx, config) {
|
|
|
514
767
|
});
|
|
515
768
|
},
|
|
516
769
|
},
|
|
770
|
+
{
|
|
771
|
+
name: 'vod_list_skills',
|
|
772
|
+
description: '[VOD-unique] Read-only: list skills available on this machine (name/pack/description). '
|
|
773
|
+
+ 'Use before routing a rules question (分类/评分/话术) or before vod_retrieve_skill.',
|
|
774
|
+
parameters: buildParameters({}),
|
|
775
|
+
output: { schema: { type: 'object', additionalProperties: true }, render: renderText },
|
|
776
|
+
async execute() {
|
|
777
|
+
const skills = skillDirs().map((n) => {
|
|
778
|
+
let text = '';
|
|
779
|
+
try { text = readFileSync(join(SKILLS_DIR, n, 'SKILL.md'), 'utf8'); } catch { /* 忽略 */ }
|
|
780
|
+
const pack = ['vod-core', 'vod-feedback-collect'].includes(n) ? 'core' : 'knowledge';
|
|
781
|
+
return { name: n, pack, native: true, description: skillDescription(text) };
|
|
782
|
+
});
|
|
783
|
+
return textResult({ skills, skillsDir: SKILLS_DIR });
|
|
784
|
+
},
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
name: 'vod_retrieve_skill',
|
|
788
|
+
description: '[VOD-unique] Read-only: read one skill verbatim (SKILL.md). '
|
|
789
|
+
+ 'Use when this machine\'s copy is missing or you need the rules text without a native skill loader. '
|
|
790
|
+
+ 'Unknown names return the available list.',
|
|
791
|
+
parameters: buildParameters({
|
|
792
|
+
name: { type: 'string', description: 'skill name from vod_list_skills' },
|
|
793
|
+
}),
|
|
794
|
+
output: { schema: { type: 'object', additionalProperties: true }, render: renderText },
|
|
795
|
+
async execute(args) {
|
|
796
|
+
const nm = String(args.name || '').trim();
|
|
797
|
+
if (!SKILL_RE.test(nm)) {
|
|
798
|
+
return textResult({ error: 'bad-name', available: skillDirs() });
|
|
799
|
+
}
|
|
800
|
+
try {
|
|
801
|
+
let content = readFileSync(join(SKILLS_DIR, nm, 'SKILL.md'), 'utf8');
|
|
802
|
+
const truncated = content.length > SKILL_CAP;
|
|
803
|
+
if (truncated) content = content.slice(0, SKILL_CAP);
|
|
804
|
+
return textResult({ name: nm, chars: content.length, truncated, content });
|
|
805
|
+
} catch {
|
|
806
|
+
return textResult({ error: 'not-found', name: nm, available: skillDirs() });
|
|
807
|
+
}
|
|
808
|
+
},
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
name: 'vod_check_update',
|
|
812
|
+
description: '[VOD-unique] Read-only: is this plugin behind npm latest? 24h cache, silent on failure. '
|
|
813
|
+
+ 'Reports only - never self-upgrades (upgrade = rerun the install command). '
|
|
814
|
+
+ 'Pass dismiss=true after the user asks to stop the reminders (3-day cooldown).',
|
|
815
|
+
parameters: buildParameters({
|
|
816
|
+
dismiss: { type: 'boolean', description: 'user asked to stop reminders (3-day cooldown)' },
|
|
817
|
+
}),
|
|
818
|
+
output: { schema: { type: 'object', additionalProperties: true }, render: renderText },
|
|
819
|
+
async execute(args) {
|
|
820
|
+
const state = loadRuntime().update_check || {};
|
|
821
|
+
const now = Date.now();
|
|
822
|
+
const today = new Date(now).toISOString().slice(0, 10);
|
|
823
|
+
if (args.dismiss === true) {
|
|
824
|
+
const until = new Date(now + DISMISS_DAYS * 86400e3).toISOString().slice(0, 10);
|
|
825
|
+
saveRuntime({ update_check: { ...state, dismissedUntil: until } });
|
|
826
|
+
return textResult({ dismissedUntil: until, updateAvailable: false });
|
|
827
|
+
}
|
|
828
|
+
if (state.dismissedUntil && today < state.dismissedUntil) {
|
|
829
|
+
return textResult({ updateAvailable: false, dismissedUntil: state.dismissedUntil });
|
|
830
|
+
}
|
|
831
|
+
const fresh = state.checkedAt && (now - Date.parse(state.checkedAt)) < UPDATE_TTL_MS;
|
|
832
|
+
let latest = fresh ? state.latestVersion : null;
|
|
833
|
+
if (!latest) {
|
|
834
|
+
try {
|
|
835
|
+
const ctl = new AbortController();
|
|
836
|
+
const timer = setTimeout(() => ctl.abort(), 3000);
|
|
837
|
+
const res = await fetch('https://registry.npmjs.org/dsh-vod-devkit/latest',
|
|
838
|
+
{ signal: ctl.signal });
|
|
839
|
+
clearTimeout(timer);
|
|
840
|
+
const body = await res.json();
|
|
841
|
+
latest = body?.version ? String(body.version) : null;
|
|
842
|
+
} catch { latest = null; }
|
|
843
|
+
if (latest) {
|
|
844
|
+
saveRuntime({ update_check: { ...state, checkedAt: new Date(now).toISOString(),
|
|
845
|
+
latestVersion: latest } });
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
if (!latest) {
|
|
849
|
+
return textResult({ currentVersion: PKG_VERSION, latestVersion: null,
|
|
850
|
+
updateAvailable: false, checked: false,
|
|
851
|
+
note: '版本检查不可达(离线/内网正常),不影响采集。' });
|
|
852
|
+
}
|
|
853
|
+
const newer = cmpVersion(latest, PKG_VERSION) > 0;
|
|
854
|
+
return textResult({ currentVersion: PKG_VERSION, latestVersion: latest,
|
|
855
|
+
updateAvailable: newer, checked: true,
|
|
856
|
+
...(newer ? { upgradeCommand: '重跑 install(同一行装命令)' } : {}) });
|
|
857
|
+
},
|
|
858
|
+
},
|
|
517
859
|
];
|
|
518
860
|
|
|
519
861
|
for (const t of tools) ctx.tools.register(t);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-vod-devkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "VOD user-voice collection tools for DeepSeek Harness (dsh). Thin shell over the VOD external HTTP API — mirrors vod-devkit (MCP) collect semantics.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|