dsh-plugin-tool-management 0.21.7 → 0.21.9
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 +33 -0
- package/docs/UPDATE.md +2 -0
- package/lib/client.js +176 -41
- package/lib/compat/host-roots.js +174 -14
- package/lib/compat/probe.js +16 -18
- package/lib/hub-lock.js +121 -0
- package/lib/index.js +5100 -4994
- package/lib/op-registry.js +2 -0
- package/lib/ops/compat.js +2 -2
- package/lib/ops/scope.js +29 -0
- package/lib/scope/intent-store.js +30 -1
- package/lib/scope/intent.js +18 -0
- package/lib/scope/store.js +29 -1
- package/lib/skills/core.js +5 -5
- package/lib/skills/official.js +101 -41
- package/lib/skills/provider-registration.js +30 -5
- package/lib/skills/service.js +32 -20
- package/lib/tools/skills.js +8 -1
- package/lib/update-check.js +199 -20
- package/package.json +54 -24
package/lib/op-registry.js
CHANGED
|
@@ -276,6 +276,8 @@ export const OP_REGISTRY = Object.freeze({
|
|
|
276
276
|
'scope-clear': { write: true },
|
|
277
277
|
// 锁开关自己不能被自己挡住,否则锁上了解不开(与 `rules-scene-lock` 同一条)。
|
|
278
278
|
'scope-lock': { write: true },
|
|
279
|
+
// 作用域侧车损坏后的显式修复:隔离现场、按空表继续。**不冻结** —— 场景锁着时也可能需要修。
|
|
280
|
+
'scope-repair': { write: true },
|
|
279
281
|
// 全局意图(`hub/scope-intent.json`):MCP 服务器 / 技能 / 技能来源三格的**全局开关**。
|
|
280
282
|
// 与 `mcpm-set-enabled` / `skill-source-enable` 同档:写全局定义、场景锁要冻结它。
|
|
281
283
|
// 会话层的 scope-set 仍不冻结(它只写租约,不改全局)。
|
package/lib/ops/compat.js
CHANGED
|
@@ -443,14 +443,14 @@ export function buildCompatOps(deps) {
|
|
|
443
443
|
'update-status': async (args) => {
|
|
444
444
|
const checker = deps.updateChecker;
|
|
445
445
|
if (!checker) {
|
|
446
|
-
return { ok: true, status: 'unknown', current: null, host: null, newest: null, bestCompatible: null, command: null, checkedAt: null, fromCache: false, error: '更新检查未接线' };
|
|
446
|
+
return { ok: true, status: 'unknown', current: null, host: null, newest: null, bestCompatible: null, source: null, command: null, checkedAt: null, fromCache: false, error: '更新检查未接线' };
|
|
447
447
|
}
|
|
448
448
|
try {
|
|
449
449
|
// `ok` 刻意放在最后覆盖:op 本身成功,答案由 `status` 表达(含 `unknown`)。
|
|
450
450
|
return { ...(await checker.check(Boolean(args && args.refresh))), ok: true };
|
|
451
451
|
}
|
|
452
452
|
catch (e) {
|
|
453
|
-
return { ok: true, status: 'unknown', current: null, host: null, newest: null, bestCompatible: null, command: null, checkedAt: null, fromCache: false, error: deps.message(e) };
|
|
453
|
+
return { ok: true, status: 'unknown', current: null, host: null, newest: null, bestCompatible: null, source: null, command: null, checkedAt: null, fromCache: false, error: deps.message(e) };
|
|
454
454
|
}
|
|
455
455
|
},
|
|
456
456
|
};
|
package/lib/ops/scope.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// scope-sessions-list 只读:当前会话区里的未归档会话(下拉框的数据源,按工作区分组)
|
|
7
7
|
// scope-lock 写:锁 / 解锁某个会话的覆盖
|
|
8
8
|
// scope-intent-set 写:MCP 服务器 / 技能来源的全局意图(on / off / blocked)
|
|
9
|
+
// scope-repair 写:隔离损坏的 scope-overrides.json / scope-intent.json(显式修复)
|
|
9
10
|
//
|
|
10
11
|
// ## 为什么这几条都不标 frozen
|
|
11
12
|
//
|
|
@@ -1193,5 +1194,33 @@ export function buildScopeOps(deps) {
|
|
|
1193
1194
|
return { ok: false, error: '保存失败: ' + res.error };
|
|
1194
1195
|
return { ok: true, sessionId, locked };
|
|
1195
1196
|
},
|
|
1197
|
+
/**
|
|
1198
|
+
* 修复损坏的作用域侧车:只把解析不了的文件改名留存,不覆盖任何健康文件。
|
|
1199
|
+
*
|
|
1200
|
+
* 这是**显式**的破坏性动作:隔离后覆盖表/意图表按空表继续,下一次对账会把意图从
|
|
1201
|
+
* 运行态反推。界面必须先确认再调用;健康的文件返回 `null`,不做任何事。
|
|
1202
|
+
*/
|
|
1203
|
+
'scope-repair': async () => {
|
|
1204
|
+
const errors = [];
|
|
1205
|
+
let scopeQuarantined = null;
|
|
1206
|
+
let intentQuarantined = null;
|
|
1207
|
+
if (deps.repairScope) {
|
|
1208
|
+
const res = await deps.repairScope();
|
|
1209
|
+
if (res.ok)
|
|
1210
|
+
scopeQuarantined = res.quarantined;
|
|
1211
|
+
else
|
|
1212
|
+
errors.push('scope-overrides.json: ' + res.error);
|
|
1213
|
+
}
|
|
1214
|
+
if (deps.repairIntent) {
|
|
1215
|
+
const res = await deps.repairIntent();
|
|
1216
|
+
if (res.ok)
|
|
1217
|
+
intentQuarantined = res.quarantined;
|
|
1218
|
+
else
|
|
1219
|
+
errors.push('scope-intent.json: ' + res.error);
|
|
1220
|
+
}
|
|
1221
|
+
if (errors.length)
|
|
1222
|
+
return { ok: false, error: errors.join(';') };
|
|
1223
|
+
return { ok: true, scopeQuarantined, intentQuarantined };
|
|
1224
|
+
},
|
|
1196
1225
|
};
|
|
1197
1226
|
}
|
|
@@ -98,9 +98,38 @@ export function createIntentStore(deps) {
|
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
+
async function repair() {
|
|
102
|
+
return deps.withWriteLock(async () => {
|
|
103
|
+
let raw;
|
|
104
|
+
try {
|
|
105
|
+
raw = await readFile(file(), 'utf8');
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
if (e?.code === 'ENOENT')
|
|
109
|
+
return { ok: true, quarantined: null };
|
|
110
|
+
return { ok: false, error: deps.message(e) };
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
normalizeScopeIntent(JSON.parse(raw));
|
|
114
|
+
return { ok: true, quarantined: null };
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
const target = file() + '.corrupt-' + Date.now();
|
|
118
|
+
try {
|
|
119
|
+
await renameWithRetry(file(), target);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
return { ok: false, error: deps.message(e) };
|
|
123
|
+
}
|
|
124
|
+
cache = null;
|
|
125
|
+
rev += 1;
|
|
126
|
+
return { ok: true, quarantined: target };
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
101
130
|
function invalidate() {
|
|
102
131
|
cache = null;
|
|
103
132
|
rev += 1;
|
|
104
133
|
}
|
|
105
|
-
return { read, snapshot, revision: () => rev, mutate, invalidate };
|
|
134
|
+
return { read, snapshot, revision: () => rev, mutate, repair, invalidate };
|
|
106
135
|
}
|
package/lib/scope/intent.js
CHANGED
|
@@ -92,6 +92,24 @@ export function withIntent(intent, domain, keys, state) {
|
|
|
92
92
|
}
|
|
93
93
|
return { ...intent, [domain]: map };
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* 只保留 `keep` 里的键(返回新对象,不改入参)。
|
|
97
|
+
*
|
|
98
|
+
* 资源被删除后它的意图要跟着消失:否则重新创建同名资源会继承旧的 off / blocked,
|
|
99
|
+
* 用户以为新资源默认能用,实际被一条已经无主的决定压着。调用方必须**先确认清单完整**:
|
|
100
|
+
* 清单读失败时传空集合会把所有意图清掉,那比不清理危险得多。
|
|
101
|
+
*/
|
|
102
|
+
export function pruneIntentKeys(intent, domain, keep) {
|
|
103
|
+
let changed = false;
|
|
104
|
+
const next = Object.create(null);
|
|
105
|
+
for (const [key, state] of Object.entries(intent[domain])) {
|
|
106
|
+
if (keep.has(key))
|
|
107
|
+
next[key] = state;
|
|
108
|
+
else
|
|
109
|
+
changed = true;
|
|
110
|
+
}
|
|
111
|
+
return changed ? { ...intent, [domain]: next } : intent;
|
|
112
|
+
}
|
|
95
113
|
/**
|
|
96
114
|
* 一台服务器 / 一个来源在某个会话里的可见性。`lower` 是会话的那三层
|
|
97
115
|
* (覆盖 → 场景层 → 基线)的并值,`undefined` = 三层都没话说。
|
package/lib/scope/store.js
CHANGED
|
@@ -235,10 +235,38 @@ export function createScopeStore(deps) {
|
|
|
235
235
|
}
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
|
+
async function repair() {
|
|
239
|
+
return deps.withWriteLock(async () => {
|
|
240
|
+
let raw;
|
|
241
|
+
try {
|
|
242
|
+
raw = await readFile(file(), 'utf8');
|
|
243
|
+
}
|
|
244
|
+
catch (e) {
|
|
245
|
+
if (e?.code === 'ENOENT')
|
|
246
|
+
return { ok: true, quarantined: null };
|
|
247
|
+
return { ok: false, error: deps.message(e) };
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
normalizeScopeOverrides(JSON.parse(raw));
|
|
251
|
+
return { ok: true, quarantined: null };
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
const target = file() + '.corrupt-' + Date.now();
|
|
255
|
+
try {
|
|
256
|
+
await renameWithRetry(file(), target);
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
return { ok: false, error: deps.message(e) };
|
|
260
|
+
}
|
|
261
|
+
cache = null;
|
|
262
|
+
return { ok: true, quarantined: target };
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
238
266
|
function invalidate() {
|
|
239
267
|
cache = null;
|
|
240
268
|
}
|
|
241
|
-
return { read, readStrict, snapshot, mode, modeSync, scopeOf, scopeOfSync, switchMode, mutate, mutateAll, clearSession, pruneDeletedSessions, invalidate };
|
|
269
|
+
return { read, readStrict, snapshot, mode, modeSync, scopeOf, scopeOfSync, switchMode, mutate, mutateAll, clearSession, pruneDeletedSessions, repair, invalidate };
|
|
242
270
|
}
|
|
243
271
|
/**
|
|
244
272
|
* 剪枝的**纯函数**部分(导出给契约测试):留下 `live` 里有的会话。
|
package/lib/skills/core.js
CHANGED
|
@@ -20,7 +20,7 @@ import { isSameOrDescendant } from "../paths.js";
|
|
|
20
20
|
// 回收站条目 id(与 hub / 记忆 / 人设 / 场景 / 提示词共用一个生成器)。不能引 `../hub.js` ——
|
|
21
21
|
// 那边引了本文件的 resolveDshHome,引回去就是环;所以生成器放在 `../trash-id.js` 这一叶上。
|
|
22
22
|
import { newTrashId } from "../trash-id.js";
|
|
23
|
-
import {
|
|
23
|
+
import { OFFICIAL_SOURCE_KEY, officeKitApplies, officialOfficeRuntimeSection, } from "./official.js";
|
|
24
24
|
import { parseSkillDoc, toKebab, unquote } from "./frontmatter.js";
|
|
25
25
|
// 拆出去的公开函数照旧挂在 core.js 上(tools/skills.ts 引 toKebab,memories/* 与 ops/memory.ts
|
|
26
26
|
// 引 parseSkillDoc / unquote,契约测试也按 lib/skills/core.js 取它们)。
|
|
@@ -1463,10 +1463,10 @@ export async function getProviderSkill(candidate, options = {}) {
|
|
|
1463
1463
|
const summary = entryOf(locator.entryName, entry.kind, entry.docPath, doc);
|
|
1464
1464
|
if (!summary.loadable || summary.declaredName !== candidate.name)
|
|
1465
1465
|
return undefined;
|
|
1466
|
-
// 官方 office
|
|
1467
|
-
// (SKILL.md 明文引用这段的 node/cli
|
|
1468
|
-
|
|
1469
|
-
|
|
1466
|
+
// 官方 office 操作技能:补上官方 provider 在 get 时追加的 LibreOffice Kit 段
|
|
1467
|
+
// (SKILL.md 明文引用这段的 node/cli 路径,见上方块注释)。按正文判断而不是按技能名,
|
|
1468
|
+
// 官方增删 / 改名操作技能时不会漏挂。
|
|
1469
|
+
const officeRuntime = locator.rootKey === OFFICIAL_SOURCE_KEY && officeKitApplies(doc.body)
|
|
1470
1470
|
? officialOfficeRuntimeSection()
|
|
1471
1471
|
: "";
|
|
1472
1472
|
return {
|
package/lib/skills/official.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 官方内置技能来源:把宿主随会话注入的内置技能物成本插件自有的真实目录(单技能可启停),
|
|
2
|
-
// 并给出 Office
|
|
2
|
+
// 并给出 Office 操作技能那段「Installed LibreOffice Kit」运行时说明。
|
|
3
3
|
//
|
|
4
4
|
// 从 core.ts 整段搬来,一行未改。这一段是本插件里唯一直接摸宿主安装形态的代码
|
|
5
5
|
// (resourcesDir / desktopPackageDir / resolvedPackageDir),单独成层后 core.ts 只管
|
|
@@ -9,15 +9,18 @@ import { createRequire } from "node:module";
|
|
|
9
9
|
import { copyFileSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
10
10
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
11
11
|
import { resolveDshHome } from "./homes.js";
|
|
12
|
+
import { clearRuntimeNote, noteRuntime } from "../compat/runtime-notes.js";
|
|
12
13
|
// ── 官方内置技能来源(随宿主注入会话上下文的内置技能)──────────────────────
|
|
13
14
|
//
|
|
14
15
|
// 宿主按形态注入不同的官方技能(官方源码逐一核对):
|
|
15
|
-
// - 桌面版
|
|
16
|
-
//
|
|
17
|
-
//
|
|
16
|
+
// - 桌面版 8 个:office 路由 + office-docx / office-pptx / office-xlsx(创作)+
|
|
17
|
+
// office-render / office-recalculate / office-export-pdf(操作)(dsh-skill-office
|
|
18
|
+
// 只在桌面宿主装配,assetRoot 指到 `<resources>/runtime/office-skills`)+
|
|
19
|
+
// diagnose-windows-sandbox-acl(dsh-sandbox-local 的门控是
|
|
20
|
+
// `process.platform === "win32"`,rank 600)。
|
|
18
21
|
// - web 版:沙盒诊断技能由宿主注入(门控只看 win32 —— 用户截图实锤,
|
|
19
22
|
// 按「web 不注入」的误判把 web 挡在门外,会让页面不显示而宿主照注);office
|
|
20
|
-
// 插件 web
|
|
23
|
+
// 插件 web 宿主不装配、不注入,但用户要求技能页照样把这七个暴露出来
|
|
21
24
|
// 统一管理(npm 包自带完整 assets,接管后可启停)。
|
|
22
25
|
//
|
|
23
26
|
// 它们或住在官方 asar 里、或由官方 provider 复制进临时目录自管,插件直接扫描/接管有两个
|
|
@@ -29,7 +32,7 @@ import { resolveDshHome } from "./homes.js";
|
|
|
29
32
|
// 整目录覆盖拷贝(与官方 provider 的「私有资源副本」同一做法),扫描、启停、overlay、
|
|
30
33
|
// 脚本执行全部落在真实文件上。599 压过宿主 provider 的 600,停用即不注入。分形态是竞态
|
|
31
34
|
// 教训:原先共用一份目录,web 启动把它解析到的沙盒技能盖进去,桌面物化好的
|
|
32
|
-
//
|
|
35
|
+
// 8 个只剩 1 个;改成各写各的子目录,互不清对方的账。共享布局的残留(旧条目
|
|
33
36
|
// 直接躺在 official-skills/ 下)按已知名单清理。
|
|
34
37
|
//
|
|
35
38
|
// - 预设参考技能(dsh-agent-preset/skills)不注入会话上下文,不列入。
|
|
@@ -86,52 +89,82 @@ function resolvedPackageDir(packageName, subpath) {
|
|
|
86
89
|
return null;
|
|
87
90
|
}
|
|
88
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* 目录里是否至少有一个带 SKILL.md 的技能子目录。
|
|
94
|
+
*
|
|
95
|
+
* 不点名校验 / 不比对固定清单:官方技能集合会变(新增 / 改名 / 重排),只要源还是
|
|
96
|
+
* 「子目录 + SKILL.md」这个形态就整目录接管;一个都没有说明这份源不完整,宁可返回
|
|
97
|
+
* false 让上层不列出,也不物化一份空壳。
|
|
98
|
+
*/
|
|
99
|
+
function hasSkillDocs(dir) {
|
|
100
|
+
try {
|
|
101
|
+
return readdirSync(dir, { withFileTypes: true }).some((entry) => entry.isDirectory() && existsSync(join(dir, entry.name, "SKILL.md")));
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
89
107
|
/**
|
|
90
108
|
* office 技能源头。桌面版由宿主挂载:运行时真实目录优先(官方 assetRoot),其次 asar
|
|
91
109
|
* 包内 assets。web 宿主不装配 office 插件(不注入),但 npm 包自带完整 assets —— 用户
|
|
92
|
-
*
|
|
110
|
+
* 要求技能页照样暴露这些技能,走宿主进程解析链取包内一份。解析不到
|
|
93
111
|
* 一律 null —— 不把拿不到真实文件的技能凭空列出来。
|
|
94
112
|
*/
|
|
95
113
|
function officialOfficeSource() {
|
|
114
|
+
// 桌面壳通过 DSH_BUNDLED_OFFICE_SKILLS 指定宿主实际使用的 assets 根,照抄最稳。
|
|
115
|
+
const bundled = process.env.DSH_BUNDLED_OFFICE_SKILLS;
|
|
116
|
+
if (bundled !== undefined && bundled !== "" && hasSkillDocs(bundled))
|
|
117
|
+
return bundled;
|
|
96
118
|
const resources = resourcesDir();
|
|
97
119
|
if (resources !== null) {
|
|
98
120
|
const runtimeDir = join(resources, "runtime", "office-skills");
|
|
99
|
-
if (
|
|
121
|
+
if (hasSkillDocs(runtimeDir))
|
|
100
122
|
return runtimeDir;
|
|
101
123
|
const asarDir = desktopPackageDir("@deepseek-ai/dsh-skill-office", "assets");
|
|
102
|
-
if (asarDir !== null &&
|
|
124
|
+
if (asarDir !== null && hasSkillDocs(asarDir))
|
|
103
125
|
return asarDir;
|
|
104
126
|
}
|
|
105
|
-
|
|
127
|
+
const resolved = resolvedPackageDir("@deepseek-ai/dsh-skill-office", "assets");
|
|
128
|
+
return resolved !== null && hasSkillDocs(resolved) ? resolved : null;
|
|
106
129
|
}
|
|
107
130
|
/** 沙盒诊断技能源头(桌面 asar 直连优先,其次宿主进程解析链;宿主门控仅看 win32,web/桌面皆注入)。 */
|
|
108
131
|
function officialSandboxSource() {
|
|
109
132
|
if (process.platform !== "win32")
|
|
110
133
|
return null;
|
|
111
|
-
|
|
112
|
-
resolvedPackageDir("@deepseek-ai/dsh-sandbox-windows-acl", "assets/diagnose-windows-sandbox-acl")
|
|
134
|
+
const source = desktopPackageDir("@deepseek-ai/dsh-sandbox-windows-acl", "assets/diagnose-windows-sandbox-acl") ??
|
|
135
|
+
resolvedPackageDir("@deepseek-ai/dsh-sandbox-windows-acl", "assets/diagnose-windows-sandbox-acl");
|
|
136
|
+
return source !== null && existsSync(join(source, "SKILL.md")) ? source : null;
|
|
113
137
|
}
|
|
114
138
|
// ── office 技能的「Installed LibreOffice Kit」段 ────────────────────────────
|
|
115
139
|
//
|
|
116
|
-
// 官方 dsh-office provider 在 get
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
//
|
|
140
|
+
// 官方 dsh-office provider 在 get 时只给三个**操作**技能(office-render /
|
|
141
|
+
// office-recalculate / office-export-pdf)的正文**追加**一段「Installed LibreOffice
|
|
142
|
+
// Kit」:SKILL.md 明文要求「使用这段提供的 libreofficeKit.node 与 .cli 绝对路径,
|
|
143
|
+
// 禁止自行搜索/猜测」。三个创作技能只产出 OOXML,不执行 LibreOffice 命令,官方不给它们
|
|
144
|
+
// 补段。我们以覆盖方式接管后官方 provider 不再被问到,这段必须由我们补上 ——
|
|
145
|
+
// 否则模型拿到的操作技能缺执行 LibreOffice 命令所需的全部路径。文案与 JSON 形状逐字取自官方
|
|
121
146
|
// dsh-skill-office lib/index.js 的 officeRuntime();node/cli 的落点按宿主形态各自核实:
|
|
122
147
|
// - 桌面:官方明确要求 packaged 应用必须给**独立 node**(electron 本体不行)。
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
148
|
+
// 桌面壳通过 `DSH_BUNDLED_OFFICE_NODE` / `DSH_BUNDLED_OFFICE_CLI` 传真实路径
|
|
149
|
+
// (运行时装在 `<resources>/runtime/primary-runtime/`,node 在其 dependencies/node/bin
|
|
150
|
+
// 下;cli 在 `app.asar.unpacked` 里 —— 独立 node 读不了 asar 内部);变量缺席时才按
|
|
151
|
+
// 形态兜底。
|
|
126
152
|
// - web:官方默认 process.execPath(宿主是普通 node 进程),cli 从宿主进程解析链取。
|
|
127
153
|
// 任一路径不是真实文件 → 用官方口径的「已停用」文案(SKILL.md 自有降级分支,模型不会
|
|
128
154
|
// 去猜路径),绝不给一个跑不起来的路径。
|
|
129
|
-
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
155
|
+
/**
|
|
156
|
+
* 一个官方技能是否需要补 LibreOffice Kit 段。
|
|
157
|
+
*
|
|
158
|
+
* 官方按写死的技能名单注入;照抄名单会在官方增删操作技能时静默漏挂或错挂。改看正文:
|
|
159
|
+
* 需要这段的技能自己会写明「使用下方提供的 Node / CLI 绝对路径」,正文里必然出现
|
|
160
|
+
* LibreOffice。三个创作技能不提它,操作技能都提 —— 官方换名字 / 加技能也照样命中。
|
|
161
|
+
*
|
|
162
|
+
* @param body SKILL.md 正文(frontmatter 之后)
|
|
163
|
+
* @returns 正文提到 LibreOffice 时为 true
|
|
164
|
+
*/
|
|
165
|
+
export function officeKitApplies(body) {
|
|
166
|
+
return /\blibreoffice\b/iu.test(body);
|
|
167
|
+
}
|
|
135
168
|
const OFFICE_RUNTIME_DISABLED = "\n\nLibreOffice Kit is disabled in this deployment.";
|
|
136
169
|
let officeRuntimeSectionCache;
|
|
137
170
|
/** 官方 provider 在 get 时追加的 LibreOffice Kit 段(每进程算一次,路径不随会话变)。 */
|
|
@@ -141,21 +174,38 @@ export function officialOfficeRuntimeSection() {
|
|
|
141
174
|
return officeRuntimeSectionCache;
|
|
142
175
|
}
|
|
143
176
|
function computeOfficeRuntimeSection() {
|
|
177
|
+
const env = process.env;
|
|
144
178
|
const resources = resourcesDir();
|
|
179
|
+
const runtimeRoot = env.DSH_PRIMARY_RUNTIME || env.DSH_BUNDLED_PRIMARY_RUNTIME || "";
|
|
180
|
+
const nodeBin = join("bin", process.platform === "win32" ? "node.exe" : "node");
|
|
145
181
|
let node;
|
|
146
182
|
let cli;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
183
|
+
// 官方 provider 的路径来源就是这几个环境变量(cordis 装配逐字核对):桌面壳会把独立
|
|
184
|
+
// node 与 unpacked 的 cli 直接传进来。优先照抄,免得按形态猜错 —— 桌面上
|
|
185
|
+
// DSH_BUNDLED_PRIMARY_RUNTIME 也在,若只看它会从解析链拿到 asar 内部的 cli,
|
|
186
|
+
// 独立 node 读不了。
|
|
187
|
+
if (env.DSH_BUNDLED_OFFICE_CLI === "")
|
|
188
|
+
return OFFICE_RUNTIME_DISABLED;
|
|
189
|
+
if (env.DSH_BUNDLED_OFFICE_CLI !== undefined) {
|
|
190
|
+
cli = env.DSH_BUNDLED_OFFICE_CLI;
|
|
191
|
+
node =
|
|
192
|
+
env.DSH_BUNDLED_OFFICE_NODE ??
|
|
193
|
+
(runtimeRoot !== ""
|
|
194
|
+
? join(resolve(runtimeRoot), "dependencies", "node", nodeBin)
|
|
195
|
+
: process.execPath);
|
|
152
196
|
}
|
|
153
197
|
else if (resources !== null) {
|
|
154
|
-
|
|
198
|
+
// 桌面兜底(壳未给 OFFICE_* 环境变量时):运行时装在 runtime/primary-runtime 下;
|
|
155
199
|
// 桌面的 cli 只认 unpacked 真实文件(独立 node 读不了 asar;electron 的 fs 补丁
|
|
156
200
|
// 会让 existsSync 对 asar 内部也返回真,所以这里不用解析链兜底)。
|
|
201
|
+
node = join(resources, "runtime", "primary-runtime", "dependencies", "node", nodeBin);
|
|
157
202
|
cli = join(resources, "app.asar.unpacked", "dsh", "node_modules", "@deepseek-ai", "libreoffice-kit", "lib", "cli.js");
|
|
158
203
|
}
|
|
204
|
+
else if (runtimeRoot !== "") {
|
|
205
|
+
// SDK / 容器部署:官方配置从运行时根推导(cordis 装配逐字核对)。
|
|
206
|
+
node = join(resolve(runtimeRoot), "dependencies", "node", nodeBin);
|
|
207
|
+
cli = resolvedPackageDir("@deepseek-ai/libreoffice-kit", "lib/cli.js");
|
|
208
|
+
}
|
|
159
209
|
else {
|
|
160
210
|
node = process.execPath;
|
|
161
211
|
cli = resolvedPackageDir("@deepseek-ai/libreoffice-kit", "lib/cli.js");
|
|
@@ -168,8 +218,21 @@ function computeOfficeRuntimeSection() {
|
|
|
168
218
|
return false;
|
|
169
219
|
}
|
|
170
220
|
};
|
|
171
|
-
if (!usable(node) || cli === null || !usable(cli))
|
|
221
|
+
if (!usable(node) || cli === null || !usable(cli)) {
|
|
222
|
+
// 可用的路径不存在时不把跑不起来的路径写进正文;同时留一条界面可见的降级,
|
|
223
|
+
// 否则用户只会看到技能「少了那段说明」,不知道该修哪。
|
|
224
|
+
noteRuntime({
|
|
225
|
+
id: "office-kit",
|
|
226
|
+
label: "LibreOffice Kit 路径",
|
|
227
|
+
kind: "read",
|
|
228
|
+
fallback: "inform-only",
|
|
229
|
+
detail: "未找到可用的独立 Node 或 LibreOffice CLI,office 操作技能本轮使用官方的「已停用」文案。请检查 DSH 安装的 runtime 是否完整。",
|
|
230
|
+
detailKey: "office-kit",
|
|
231
|
+
params: { node, cli: cli ?? "" },
|
|
232
|
+
});
|
|
172
233
|
return OFFICE_RUNTIME_DISABLED;
|
|
234
|
+
}
|
|
235
|
+
clearRuntimeNote("office-kit");
|
|
173
236
|
return `\n\n## Installed LibreOffice Kit\n\nUse these absolute paths for every LibreOffice Kit command. Pass the CLI entry as the first argument to Node.\n\n${JSON.stringify({ libreofficeKit: { node, cli } }, null, 2)}`;
|
|
174
237
|
}
|
|
175
238
|
function copyDirectorySync(from, to) {
|
|
@@ -254,15 +317,12 @@ export function officialSkillRoot() {
|
|
|
254
317
|
localeKey: "official",
|
|
255
318
|
mutable: false,
|
|
256
319
|
deletable: false,
|
|
257
|
-
//
|
|
258
|
-
// provider 的 600,脚本从物化副本的真实路径执行。
|
|
320
|
+
// 来源层无开关(同默认来源),单个技能可启停;脚本从物化副本的真实路径执行。
|
|
259
321
|
//
|
|
260
|
-
//
|
|
261
|
-
//
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
// 能提前发现,doctor 也查不了(要枚举官方 provider 的注册参数)。所以记为**已知
|
|
265
|
-
// 假设**,列进 CHANGELOG 的宿主适配矩阵,官方更新时人工核对这一处。
|
|
322
|
+
// rank 只决定**本 provider 内部**同名候选的先后(官方 599 排在 hub / dsh / agents
|
|
323
|
+
// 之后,被用户自己的同名技能盖住)。对宿主官方 provider 的接管不靠数字:
|
|
324
|
+
// 全局层由宿主自己提供官方技能,我们只在每个 agent 的 scoped 层里注册同一份候选,
|
|
325
|
+
// 层优先级「最近一层胜出」直接压过全局层 —— 官方改 rank 常量不会让接管失效。
|
|
266
326
|
toggleable: true,
|
|
267
327
|
native: false,
|
|
268
328
|
scope: "user",
|
|
@@ -4,10 +4,19 @@
|
|
|
4
4
|
// 从 skills/service.ts 整段搬来,一行未改。invalidators 由调用方注入,本层不持有状态 ——
|
|
5
5
|
// 它是官方 provider 通道的使用方,不改官方包、也不 monkey-patch。
|
|
6
6
|
import { getProviderSkill, listProviderCandidates } from './core.js';
|
|
7
|
+
import { OFFICIAL_SOURCE_KEY } from './official.js';
|
|
8
|
+
import { noteRuntime } from '../compat/runtime-notes.js';
|
|
7
9
|
const PROVIDER_NAME = 'dsh-plugin-tool-management-external';
|
|
8
10
|
const message = (e) => String((e && e.message) || e);
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
+
/**
|
|
12
|
+
* manager provider:以 core 的候选/正文接口接管四个外部来源(含启停策略)。
|
|
13
|
+
*
|
|
14
|
+
* @param scope `global` 时**不**返回官方内置技能的候选。那一家由宿主自己的 provider 在
|
|
15
|
+
* 全局层提供;我们在每个 agent 的 scoped 层里再注册一份,靠「最近一层胜出」接管它,
|
|
16
|
+
* 不再依赖数字 rank 与宿主内部常量对齐。全局层若也放一份同名候选,等于把 rank 假设
|
|
17
|
+
* 重新引回来 —— 官方改档位时接管会静默失效。
|
|
18
|
+
*/
|
|
19
|
+
export function externalSkillProvider(control, invalidators, scope = 'agent') {
|
|
11
20
|
if (control && typeof control.invalidate === 'function')
|
|
12
21
|
invalidators.add(control.invalidate);
|
|
13
22
|
if (control && control.signal && typeof control.signal.addEventListener === 'function') {
|
|
@@ -15,7 +24,12 @@ export function externalSkillProvider(control, invalidators) {
|
|
|
15
24
|
}
|
|
16
25
|
return {
|
|
17
26
|
name: PROVIDER_NAME,
|
|
18
|
-
list: async (options) =>
|
|
27
|
+
list: async (options) => {
|
|
28
|
+
const candidates = await listProviderCandidates(options);
|
|
29
|
+
return scope === 'global'
|
|
30
|
+
? candidates.filter((candidate) => candidate?.locator?.rootKey !== OFFICIAL_SOURCE_KEY)
|
|
31
|
+
: candidates;
|
|
32
|
+
},
|
|
19
33
|
get: async (candidate, options) => getProviderSkill(candidate, options),
|
|
20
34
|
};
|
|
21
35
|
}
|
|
@@ -43,11 +57,22 @@ export function registerAgentSkillProviders(ctx, invalidators) {
|
|
|
43
57
|
if (!skills)
|
|
44
58
|
return;
|
|
45
59
|
try {
|
|
46
|
-
const dispose = skills.registerProvider((control) => externalSkillProvider(control, invalidators));
|
|
60
|
+
const dispose = skills.registerProvider((control) => externalSkillProvider(control, invalidators, 'agent'));
|
|
47
61
|
registrations.set(agent.id, typeof dispose === 'function' ? dispose : () => { });
|
|
48
62
|
}
|
|
49
63
|
catch (e) {
|
|
50
|
-
console.error('[dsh-plugin-tool-management] agent-scoped skills provider
|
|
64
|
+
console.error('[dsh-plugin-tool-management] agent-scoped skills provider setup failed:', message(e));
|
|
65
|
+
// 这一层没挂上时,官方内置技能仍由宿主注入,但我们的启停不再生效 ——
|
|
66
|
+
// 界面上看不出差别,留一条降级让兼容页说清。
|
|
67
|
+
noteRuntime({
|
|
68
|
+
id: 'skills-agent-provider',
|
|
69
|
+
label: '技能作用域接管',
|
|
70
|
+
kind: 'read',
|
|
71
|
+
fallback: 'inform-only',
|
|
72
|
+
detail: 'agent 作用域的技能 provider 未挂上(' + message(e) + '):官方内置技能这一轮由宿主直接注入,启停开关不生效。',
|
|
73
|
+
detailKey: 'skills-agent-provider',
|
|
74
|
+
params: { reason: message(e) },
|
|
75
|
+
});
|
|
51
76
|
}
|
|
52
77
|
};
|
|
53
78
|
const uninstall = (agent) => {
|
package/lib/skills/service.js
CHANGED
|
@@ -136,8 +136,13 @@ export function pluginLog() {
|
|
|
136
136
|
/** 技能域服务门面:来源枚举、清单扫描、启停与新建 / 更新。 */
|
|
137
137
|
export function createSkillsService(ctx) {
|
|
138
138
|
const log = pluginLog();
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
// 根系**按需推导**:`userRoots()` 会物化官方内置技能(同步拷贝宿主安装里的文件)。
|
|
140
|
+
// 放在构造期等于让宿主启动路径去读宿主目录;首次取用(列技能、装 watcher、越界校验)
|
|
141
|
+
// 时再算,失败也不影响宿主启动。
|
|
142
|
+
let rootsCache = null;
|
|
143
|
+
const roots = () => (rootsCache ??= userRoots());
|
|
144
|
+
let rootByKeyCache = null;
|
|
145
|
+
const rootByKey = () => (rootByKeyCache ??= Object.fromEntries(roots().map((root) => [root.key, root])));
|
|
141
146
|
/** op 入参里的 `sessionId`(空串 / 非字符串 → undefined = 全局口径)。 */
|
|
142
147
|
const sessionIdOfArgs = (args) => {
|
|
143
148
|
const raw = args && typeof args.sessionId === 'string' ? args.sessionId.trim() : '';
|
|
@@ -159,8 +164,9 @@ export function createSkillsService(ctx) {
|
|
|
159
164
|
return { projectCwds: own === null ? activeSessionCwds(ctx) : own };
|
|
160
165
|
};
|
|
161
166
|
const requestRoot = async (key) => {
|
|
162
|
-
|
|
163
|
-
|
|
167
|
+
const known = rootByKey();
|
|
168
|
+
if (known[key])
|
|
169
|
+
return known[key];
|
|
164
170
|
// 自定义来源不在静态 root 表里:从状态文件的 customRoots 解析 definition。
|
|
165
171
|
try {
|
|
166
172
|
const policy = await readManagerState();
|
|
@@ -302,7 +308,7 @@ export function createSkillsService(ctx) {
|
|
|
302
308
|
disposers.push(dispose);
|
|
303
309
|
};
|
|
304
310
|
try {
|
|
305
|
-
const dispose = ctx.skills.registerProvider((control) => externalSkillProvider(control, providerInvalidators));
|
|
311
|
+
const dispose = ctx.skills.registerProvider((control) => externalSkillProvider(control, providerInvalidators, 'global'));
|
|
306
312
|
if (typeof dispose === 'function')
|
|
307
313
|
add(dispose);
|
|
308
314
|
}
|
|
@@ -315,8 +321,13 @@ export function createSkillsService(ctx) {
|
|
|
315
321
|
catch (e) {
|
|
316
322
|
console.error('[dsh-plugin-tool-management] agent-scoped provider setup failed:', message(e));
|
|
317
323
|
}
|
|
318
|
-
|
|
319
|
-
|
|
324
|
+
// 静态来源的 watcher 与状态文件都**推迟到装配之后**:`roots()` 会物化官方内置技能
|
|
325
|
+
// (同步拷贝宿主安装里的文件),apply 里调用等于让宿主启动路径读宿主目录。
|
|
326
|
+
void Promise.resolve()
|
|
327
|
+
.then(() => {
|
|
328
|
+
if (disposed)
|
|
329
|
+
return null;
|
|
330
|
+
const watchPaths = roots()
|
|
320
331
|
// 官方内置来源是宿主启动时物化的只读副本,不会中途变化,不起 watcher。
|
|
321
332
|
.filter((root) => root.key !== 'official')
|
|
322
333
|
.map((root) => String((root && root.path) || ''))
|
|
@@ -324,19 +335,20 @@ export function createSkillsService(ctx) {
|
|
|
324
335
|
add(watchDirectories(watchPaths, invalidateSkills));
|
|
325
336
|
// 自定义目录在状态文件里,注册时读取一次并一并监听(后添加的目录由
|
|
326
337
|
// provider 首次 list 天然覆盖,等插件重载后才有 watcher)。
|
|
327
|
-
readManagerState()
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
+
return readManagerState();
|
|
339
|
+
})
|
|
340
|
+
.then((current) => {
|
|
341
|
+
if (current === null)
|
|
342
|
+
return;
|
|
343
|
+
const customPaths = customRootsFromState(current.state)
|
|
344
|
+
.map((root) => String((root && root.path) || ''))
|
|
345
|
+
.filter(Boolean);
|
|
346
|
+
if (customPaths.length)
|
|
347
|
+
add(watchDirectories(customPaths, invalidateSkills));
|
|
348
|
+
})
|
|
349
|
+
.catch((e) => {
|
|
338
350
|
console.error('[dsh-plugin-tool-management] skill watcher setup failed:', message(e));
|
|
339
|
-
}
|
|
351
|
+
});
|
|
340
352
|
return () => {
|
|
341
353
|
disposed = true;
|
|
342
354
|
for (const dispose of disposers) {
|
|
@@ -560,7 +572,7 @@ export function createSkillsService(ctx) {
|
|
|
560
572
|
* 静态根(`userRoots`)+ 状态文件里的自定义根 + 当前活动工作区的项目来源。
|
|
561
573
|
*/
|
|
562
574
|
async function isInsideKnownSkillRoot(abs) {
|
|
563
|
-
const dirs = roots.map((r) => String((r && r.path) || '')).filter(Boolean);
|
|
575
|
+
const dirs = roots().map((r) => String((r && r.path) || '')).filter(Boolean);
|
|
564
576
|
try {
|
|
565
577
|
for (const r of customRootsFromState((await readManagerState()).state)) {
|
|
566
578
|
if (r && r.path)
|
package/lib/tools/skills.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// (先读一次 `skill-state`)。改的分支走新加的 `skill-update` op,它只认本插件可写的两个根
|
|
6
6
|
// (hub = 导入落点 / dsh = 新建默认落点)里的胜出者。
|
|
7
7
|
import { toKebab } from '../skills/core.js';
|
|
8
|
+
import { OFFICIAL_SOURCE_KEY, officeKitApplies, officialOfficeRuntimeSection } from '../skills/official.js';
|
|
8
9
|
import { effectiveScope, existingNote, globalActionNote, globalUnchangedNote, isolationOffNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text } from './deps.js';
|
|
9
10
|
/** 注册技能域的 model 工具(列表 / 启停 / 新建或更新)。 */
|
|
10
11
|
export function buildSkillTools(deps) {
|
|
@@ -242,7 +243,13 @@ export function buildSkillTools(deps) {
|
|
|
242
243
|
// 注入边界:正文读进来就永久留在这一轮的 transcript 里,压制型预设下目录也可能不在 ——
|
|
243
244
|
// 与 skill_manager_list 同一句说明,别让模型以为"读过就等于技能开着"。
|
|
244
245
|
const notice = await deps.reachNoticeForAgent(deps.presetRoster(), exec && exec.agent && exec.agent.ctx, deps.injectNoticeOptions());
|
|
245
|
-
|
|
246
|
+
// 官方 office 操作技能:provider 的 get 会补 LibreOffice Kit 段,这里读到的正文
|
|
247
|
+
// 必须与真正注入的一致,否则模型按少了 node/cli 路径的正文去猜。判据同 get:看正文。
|
|
248
|
+
const body = String(detail.body || '');
|
|
249
|
+
const officeRuntime = picked.rootKey === OFFICIAL_SOURCE_KEY && officeKitApplies(body)
|
|
250
|
+
? officialOfficeRuntimeSection()
|
|
251
|
+
: '';
|
|
252
|
+
return header + body.trim() + officeRuntime + notice;
|
|
246
253
|
},
|
|
247
254
|
}));
|
|
248
255
|
register(defineTool({
|