dsh-plugin-tool-management 0.22.1 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/README.md +8 -7
- package/README_EN.md +8 -7
- package/docs/UPDATE.md +1 -0
- package/lib/client.js +647 -206
- package/lib/compat/capability-specs.js +400 -1
- package/lib/compat/host-contracts.js +334 -3
- package/lib/compat/host-probe.js +40 -0
- package/lib/compat/host-roots.js +23 -8
- package/lib/compat/manual-review.js +55 -0
- package/lib/compat/probe.js +448 -25
- package/lib/desktop-cookie-prune.js +19 -3
- package/lib/index.js +100 -19
- package/lib/mcp/manager.js +2 -1
- package/lib/mcp/prompt-shadow.js +128 -0
- package/lib/mcp/tool-visibility.js +18 -6
- package/lib/memories/service.js +18 -5
- package/lib/op-registry.js +1 -1
- package/lib/ops/compat.js +31 -0
- package/lib/ops/scope.js +9 -9
- package/lib/scene-linkage.js +16 -1
- package/lib/scope/intent.js +1 -1
- package/lib/tool-table-switch.js +2 -2
- package/package.json +1 -1
package/lib/compat/probe.js
CHANGED
|
@@ -20,18 +20,20 @@
|
|
|
20
20
|
* 结论按**能力**逐项报告,不压成一个布尔值:调用方可以只降级失去支持的那一项,其余照常。
|
|
21
21
|
*/
|
|
22
22
|
import { createRequire } from 'node:module';
|
|
23
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
23
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
24
24
|
import { dirname, join } from 'node:path';
|
|
25
25
|
import { fileURLToPath } from 'node:url';
|
|
26
|
+
import * as semver from 'semver';
|
|
26
27
|
import { CAPABILITY_SPECS } from './capability-specs.js';
|
|
27
|
-
import { BARE_HOST_MODULE_CONTRACTS } from './host-contracts.js';
|
|
28
|
-
import {
|
|
28
|
+
import { BARE_HOST_MODULE_CONTRACTS, HOST_BEHAVIOR_CONTRACTS, HOST_CLIENT_UI_CONTRACTS } from './host-contracts.js';
|
|
29
|
+
import { manualReviewItems } from './manual-review.js';
|
|
30
|
+
import { isAsarPath, isFn, OWNER_CLASSES, packageRootOf, realPathWithReason, referencePrototypes, provideHostRootCandidates, safeResolve, textMatchOf, versionOf, versionOfPackageAt, } from './host-probe.js';
|
|
29
31
|
// 宿主安装根的发现与「该走哪条恢复路」的判定 整段搬到 ./host-roots.js,正文一字
|
|
30
32
|
// 未改(moved-verify 逐字对拍)。probe.js 的公开面照旧:搬走的那 12 件全部从这里再出口 ——
|
|
31
33
|
// index.ts / ops/compat.ts / sessions/bridge.ts 都按 ./compat/probe.js 引它们,少一件 equiv
|
|
32
34
|
// 对拍就报「导出面丢失」。
|
|
33
35
|
export { asarHostPackageRoot, findingsById, globalNpmHostPackageDirs, hostPackageDirsFromPath, hostRootCandidates, hostVersionOf, IDENTITY_PACKAGES, looksLikeHostPackageDir, npxCacheHostRoots, OPERATION_ROUTES, recoveryFor, refusalsFor, routeFor, VERIFIED_HOST_VERSION, } from './host-roots.js';
|
|
34
|
-
import { hostRootCandidates, IDENTITY_PACKAGES, looksLikeHostPackageDir, routeFor, VERIFIED_HOST_VERSION } from './host-roots.js';
|
|
36
|
+
import { hostRootCandidates, hostVersionOf, IDENTITY_PACKAGES, looksLikeHostPackageDir, routeFor, VERIFIED_HOST_VERSION } from './host-roots.js';
|
|
35
37
|
// 「宿主在哪」这份口径只有一份(host-roots.ts 的 hostRootCandidates)。静态能力表里有条目要
|
|
36
38
|
// 按宿主侧解析结果决定**这一轮能不能查**(`staticWhen`,见 connection.admit 那条),而
|
|
37
39
|
// capability-specs.ts 不能反向 import 本文件(probe → specs → probe 成环)。所以在这里把
|
|
@@ -95,6 +97,71 @@ export const EXPECTED_PEER_RANGE = '>=0.2.2-rc.1 <0.2.3';
|
|
|
95
97
|
* doctor 与外部脚本可能仍在读;语义仍是"最早支持哪一代",只是现在只有一代。
|
|
96
98
|
*/
|
|
97
99
|
export const EXPECTED_MIN_HOST_VERSION = EXPECTED_PEER_RANGE.match(/(\d+\.\d+\.\d+(?:-rc\.\d+)?)/)?.[1] ?? VERIFIED_HOST_VERSION;
|
|
100
|
+
/**
|
|
101
|
+
* 逐包版本基准:cordis 与 11 个 `@deepseek-ai/dsh-*` peer。
|
|
102
|
+
*
|
|
103
|
+
* 官方发版时这些包通常同代;逐包列出来是为了升级后能看见**哪一个包先变了**。
|
|
104
|
+
* 新增 / 撤掉 peer 时这里要同步增删,否则版本表会漏报或多报一个包;某个包独立发版时
|
|
105
|
+
* 直接改对应条目的 `baselineVersion`。宿主与插件两侧的版本在 {@link assessHost} 里逐包现读。
|
|
106
|
+
*/
|
|
107
|
+
const DSH_PEER_PACKAGES = [
|
|
108
|
+
'@deepseek-ai/dsh-agent-preset-registry',
|
|
109
|
+
'@deepseek-ai/dsh-llm',
|
|
110
|
+
'@deepseek-ai/dsh-session',
|
|
111
|
+
'@deepseek-ai/dsh-session-projection-cache',
|
|
112
|
+
'@deepseek-ai/dsh-settings',
|
|
113
|
+
'@deepseek-ai/dsh-spill-local',
|
|
114
|
+
'@deepseek-ai/dsh-storage-domain',
|
|
115
|
+
'@deepseek-ai/dsh-subagent-fork-in-process',
|
|
116
|
+
'@deepseek-ai/dsh-subagent-spawn-in-process',
|
|
117
|
+
'@deepseek-ai/dsh-tools',
|
|
118
|
+
'@deepseek-ai/dsh-workspace',
|
|
119
|
+
];
|
|
120
|
+
/** 可选 peer:宿主不提供时由插件自带副本或按需挂载,缺席不是安装故障。 */
|
|
121
|
+
const OPTIONAL_PEER_PACKAGES = new Set([
|
|
122
|
+
'@deepseek-ai/dsh-subagent-fork-in-process',
|
|
123
|
+
'@deepseek-ai/dsh-subagent-spawn-in-process',
|
|
124
|
+
]);
|
|
125
|
+
/**
|
|
126
|
+
* 非 peer、但运行时契约与插件绑定的官方包:只观测宿主版本是否偏离适配基准,不判 peer 范围。
|
|
127
|
+
*
|
|
128
|
+
* 为什么不能省:peer 范围只覆盖 11 个 `dsh-*`;宿主可以只升级 `dsh-system-prompt` /
|
|
129
|
+
* `dsh-mcp-client` 这类「宿主不要求插件依赖」的包 —— 这时 peer 全部在范围内,插件却可能
|
|
130
|
+
* 已经按旧契约在跑。逐包列出宿主版本,至少让"这一代没验证过"在页面上有据可查。
|
|
131
|
+
*/
|
|
132
|
+
const OBSERVED_HOST_PACKAGES = [
|
|
133
|
+
'@deepseek-ai/dsh-agent',
|
|
134
|
+
'@deepseek-ai/dsh-host-plugin-inventory',
|
|
135
|
+
'@deepseek-ai/dsh-host-webserver',
|
|
136
|
+
'@deepseek-ai/dsh-mcp-client',
|
|
137
|
+
'@deepseek-ai/dsh-mcp-resources',
|
|
138
|
+
'@deepseek-ai/dsh-persona',
|
|
139
|
+
'@deepseek-ai/dsh-sandbox-policy',
|
|
140
|
+
'@deepseek-ai/dsh-session-persistence-jsonl',
|
|
141
|
+
'@deepseek-ai/dsh-skill',
|
|
142
|
+
'@deepseek-ai/dsh-skill-office',
|
|
143
|
+
'@deepseek-ai/dsh-sandbox-windows-acl',
|
|
144
|
+
'@deepseek-ai/dsh-subagent',
|
|
145
|
+
'@deepseek-ai/dsh-system-prompt',
|
|
146
|
+
'@deepseek-ai/dsh-tool-skill',
|
|
147
|
+
];
|
|
148
|
+
export const HOST_PACKAGE_BASELINES = [
|
|
149
|
+
{ name: '@deepseek-ai/cordis', peerRange: '^4.0.2', baselineVersion: '4.1.0' },
|
|
150
|
+
...DSH_PEER_PACKAGES.map((name) => ({
|
|
151
|
+
name,
|
|
152
|
+
peerRange: EXPECTED_PEER_RANGE,
|
|
153
|
+
baselineVersion: VERIFIED_HOST_VERSION,
|
|
154
|
+
...(OPTIONAL_PEER_PACKAGES.has(name) ? { optional: true } : {}),
|
|
155
|
+
})),
|
|
156
|
+
...OBSERVED_HOST_PACKAGES.map((name) => ({
|
|
157
|
+
name,
|
|
158
|
+
peerRange: null,
|
|
159
|
+
baselineVersion: VERIFIED_HOST_VERSION,
|
|
160
|
+
observed: true,
|
|
161
|
+
})),
|
|
162
|
+
// LibreOffice Kit 跟着宿主运行时走,但版本号与 DSH 不同步(0.1.x)。
|
|
163
|
+
{ name: '@deepseek-ai/libreoffice-kit', peerRange: null, baselineVersion: '0.1.5', observed: true },
|
|
164
|
+
];
|
|
98
165
|
/**
|
|
99
166
|
* 单项能力的结论。
|
|
100
167
|
*
|
|
@@ -257,6 +324,9 @@ export function assessHost(ctx) {
|
|
|
257
324
|
// 与**子代理 scope 里**的那个(restrict 在子 scope 上才作用于该子代理,run-provider.ts
|
|
258
325
|
// 就是 `childAgent.ctx.get('tools')` 取的)。探测只能看宿主平面那一层 —— 子 scope 还没建。
|
|
259
326
|
const tools = unwrap(ctx.tools !== undefined ? ctx.tools : get('tools'));
|
|
327
|
+
// 系统提示词服务:插件在 agent 作用域里用同名段遮蔽官方 MCP 段;这里从宿主平面取一份
|
|
328
|
+
// 只读视图,核对 MCP_SERVERS 排序位仍在(状态页与 doctor 都不该等隔离失效才发现)。
|
|
329
|
+
const systemPrompt = unwrap(get('systemPrompt'));
|
|
260
330
|
// agent 作用域:探测对象是 agent 自己的 ctx(`on` 挂在它上面)。这里没有活的 agent 可看,
|
|
261
331
|
// 所以拿宿主平面的 ctx 代答 —— 同一个类实例链上的成员存在性,`on` 改名时两边一起改。
|
|
262
332
|
// 局限如实标注:探得到"on 在不在",探不到"agent/created 是否仍串行"。
|
|
@@ -268,6 +338,17 @@ export function assessHost(ctx) {
|
|
|
268
338
|
const roster = unwrap(get('agentPresets'));
|
|
269
339
|
// fs 走 ctx 属性优先(它在插件 inject 清单里),与 settings 同一条取法。
|
|
270
340
|
const fsService = unwrap(ctx.fs !== undefined ? ctx.fs : get('fs'));
|
|
341
|
+
// 三个不在 inject 清单里的宿主服务:只能用 ctx.get 软取(属性访问在未声明时会抛)。
|
|
342
|
+
const subagents = unwrap(get('subagents'));
|
|
343
|
+
const llm = unwrap(get('llm'));
|
|
344
|
+
const approval = unwrap(get('approval'));
|
|
345
|
+
// 技能 / agent 清单 / Loader 条目:插件按 scope 注册 provider 与等待 loader 时需要它们。
|
|
346
|
+
const skills = unwrap(get('skills'));
|
|
347
|
+
const agents = unwrap(get('agents'));
|
|
348
|
+
const pluginInventory = unwrap(get('pluginInventory'));
|
|
349
|
+
// webServer / sandboxPolicy 在 inject 清单里:属性优先,取不到再按服务名软取。
|
|
350
|
+
const webServer = unwrap(ctx.webServer !== undefined ? ctx.webServer : get('webServer'));
|
|
351
|
+
const sandboxPolicy = unwrap(ctx.sandboxPolicy !== undefined ? ctx.sandboxPolicy : get('sandboxPolicy'));
|
|
271
352
|
const references = referencePrototypes();
|
|
272
353
|
const targets = {
|
|
273
354
|
workspace: { target: registry, reference: references.workspace },
|
|
@@ -278,13 +359,18 @@ export function assessHost(ctx) {
|
|
|
278
359
|
presetRoster: { target: roster, reference: references.roster },
|
|
279
360
|
fs: { target: fsService, reference: undefined },
|
|
280
361
|
tools: { target: tools, reference: references.tools },
|
|
362
|
+
systemPrompt: { target: systemPrompt, reference: undefined },
|
|
281
363
|
agentContext: { target: agentContext, reference: undefined },
|
|
282
364
|
connection: { target: connection, reference: references.connection },
|
|
365
|
+
subagents: { target: subagents, reference: undefined },
|
|
366
|
+
llm: { target: llm, reference: undefined },
|
|
367
|
+
approval: { target: approval, reference: undefined },
|
|
368
|
+
skills: { target: skills, reference: undefined },
|
|
369
|
+
agents: { target: agents, reference: undefined },
|
|
370
|
+
pluginInventory: { target: pluginInventory, reference: undefined },
|
|
371
|
+
webServer: { target: webServer, reference: undefined },
|
|
372
|
+
sandboxPolicy: { target: sandboxPolicy, reference: undefined },
|
|
283
373
|
};
|
|
284
|
-
const findings = CAPABILITY_SPECS.map((spec) => {
|
|
285
|
-
const slot = targets[spec.owner];
|
|
286
|
-
return inspectCapability(spec, slot.target, slot.reference);
|
|
287
|
-
});
|
|
288
374
|
// 身份:插件加载的是不是宿主正在跑的那几个物理模块?
|
|
289
375
|
const modules = {};
|
|
290
376
|
const sameAsHost = {};
|
|
@@ -301,8 +387,29 @@ export function assessHost(ctx) {
|
|
|
301
387
|
let pluginRealpathNote = null;
|
|
302
388
|
let asarHostVersion = null;
|
|
303
389
|
let asarPluginVersion = null;
|
|
304
|
-
//
|
|
305
|
-
|
|
390
|
+
// 宿主版本优先读宿主应用自己的清单;读不到再退回插件解析到的 workspace 版本。
|
|
391
|
+
// 只读 workspace 会在「插件与宿主两份拷贝」时把插件侧版本当成宿主版本。
|
|
392
|
+
const hostVersion = (hostRoot === null ? null : hostVersionOf(hostRoot)) ?? versionOf('@deepseek-ai/dsh-workspace') ?? 'unknown';
|
|
393
|
+
// 宿主契约只跟"宿主装在哪"有关,与下面那个逐包 identity 循环无关,先各量一次。
|
|
394
|
+
const contracts = hostContractStatus(hostRoot, BARE_HOST_MODULE_CONTRACTS);
|
|
395
|
+
const behaviors = hostContractStatus(hostRoot, HOST_BEHAVIOR_CONTRACTS);
|
|
396
|
+
// 客户端 UI 契约:服务端看不见浏览器,只能核对宿主客户端 bundle 里的模块加载器 / 插槽名。
|
|
397
|
+
const clientUi = hostContractStatus(hostRoot, HOST_CLIENT_UI_CONTRACTS);
|
|
398
|
+
// 只能人工核对的项:能力表 + 三份契约清单里的 `manual` 说明。随诊断 JSON 返回,
|
|
399
|
+
// 页面不展示 —— 保留给排障时逐项核对。
|
|
400
|
+
const manualChecks = manualReviewItems([
|
|
401
|
+
...BARE_HOST_MODULE_CONTRACTS,
|
|
402
|
+
...HOST_BEHAVIOR_CONTRACTS,
|
|
403
|
+
...HOST_CLIENT_UI_CONTRACTS,
|
|
404
|
+
]);
|
|
405
|
+
// 配置 schema 这类"导出对象上的字段名":canary 只能证明字符串还在,读一次 JSON 表示才能
|
|
406
|
+
// 确认插件写出的键仍被官方接受。解析不到就不出结论(契约清单会报包缺失)。
|
|
407
|
+
const schemaFindings = inspectHostSchemaContracts(hostRoot);
|
|
408
|
+
const assetFindings = inspectOfficialSkillAssets(hostRoot);
|
|
409
|
+
const findings = CAPABILITY_SPECS.map((spec) => {
|
|
410
|
+
const slot = targets[spec.owner];
|
|
411
|
+
return inspectCapability(spec, slot.target, slot.reference);
|
|
412
|
+
}).concat(schemaFindings, assetFindings);
|
|
306
413
|
for (const name of IDENTITY_PACKAGES) {
|
|
307
414
|
const resolved = safeResolve(name);
|
|
308
415
|
modules[name] = resolved;
|
|
@@ -394,6 +501,16 @@ export function assessHost(ctx) {
|
|
|
394
501
|
packages: asarHostPackages,
|
|
395
502
|
});
|
|
396
503
|
}
|
|
504
|
+
// 逐包版本审计:升级宿主后「哪个包先变了、还在不在适配范围」在这里一次答完。
|
|
505
|
+
const packages = hostPackageStatuses(hostRoot, sameAsHost);
|
|
506
|
+
const outOfRange = packages.filter((item) => item.inPeerRange === false);
|
|
507
|
+
if (outOfRange.length > 0) {
|
|
508
|
+
// 装得上不等于适配:peer 的范围只在安装期校验一次,宿主原地升级后运行时会照跑。
|
|
509
|
+
// 这条阻塞项把「跑着但版本对不上」摆到页头,而不是等某个动作失败才发现。
|
|
510
|
+
blockers.push(`这些官方包的版本超出本插件声明的 peer 范围(${EXPECTED_PEER_RANGE}):`
|
|
511
|
+
+ `${outOfRange.map((item) => `${item.name}(宿主 ${item.hostVersion ?? '?'} / 插件 ${item.pluginVersion ?? '?'})`).join('、')}。`
|
|
512
|
+
+ '请安装与本机 DSH 匹配的插件版本。');
|
|
513
|
+
}
|
|
397
514
|
// 降级 = 确实用不了。可选槽位不算:它们缺席只是选中适配器路线,功能照常可用;
|
|
398
515
|
// 列进降级会让用户以为好用的功能坏了(再配上"不可用"的措辞,还会以为按钮被禁掉)。
|
|
399
516
|
const degraded = findings.filter((finding) => finding.state !== 'ok' && finding.optional !== true);
|
|
@@ -404,9 +521,10 @@ export function assessHost(ctx) {
|
|
|
404
521
|
const delta = routeFor({ findings }, 'delete').via !== 'none';
|
|
405
522
|
return {
|
|
406
523
|
identity: {
|
|
407
|
-
version:
|
|
524
|
+
version: hostVersion,
|
|
408
525
|
modules,
|
|
409
526
|
sameAsHost,
|
|
527
|
+
packages,
|
|
410
528
|
blockers,
|
|
411
529
|
unverified,
|
|
412
530
|
notes,
|
|
@@ -416,25 +534,299 @@ export function assessHost(ctx) {
|
|
|
416
534
|
mayDelete: delta,
|
|
417
535
|
generatedAt: Date.now(),
|
|
418
536
|
...(contracts === null ? {} : { contracts }),
|
|
537
|
+
...(behaviors === null ? {} : { behaviors }),
|
|
538
|
+
...(clientUi === null ? {} : { clientUi }),
|
|
539
|
+
manualChecks,
|
|
419
540
|
};
|
|
420
541
|
}
|
|
421
542
|
/**
|
|
422
|
-
*
|
|
423
|
-
*
|
|
543
|
+
* 宿主某份官方包的版本;宿主不暴露该包时为 null。
|
|
544
|
+
*
|
|
545
|
+
* 从宿主自己的解析锚点量,而不是插件侧:插件可能是另一份拷贝,或者根本没有这个包
|
|
546
|
+
* (可选 peer / 宿主专属包)。
|
|
547
|
+
*/
|
|
548
|
+
function hostPackageVersion(hostRoot, name) {
|
|
549
|
+
if (hostRoot === null)
|
|
550
|
+
return null;
|
|
551
|
+
try {
|
|
552
|
+
const resolved = createRequire(join(dirname(hostRoot), 'package.json')).resolve(name);
|
|
553
|
+
return versionOfPackageAt(resolved);
|
|
554
|
+
}
|
|
555
|
+
catch {
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* 逐包版本审计:宿主实际装的是哪一版、插件解析到哪一版、是否仍在 peer 范围内。
|
|
561
|
+
*
|
|
562
|
+
* `inPeerRange` 对**两侧都判定**:任一侧解析到且超出范围就是 false。宿主升级后插件
|
|
563
|
+
* 自己的副本通常没变,只看插件版本会把「宿主已经超出范围」藏起来;反过来插件装了一份
|
|
564
|
+
* 越界的私副本时,只看宿主版本同样会漏。
|
|
565
|
+
*/
|
|
566
|
+
function hostPackageStatuses(hostRoot, sameAsHost) {
|
|
567
|
+
return HOST_PACKAGE_BASELINES.map((baseline) => {
|
|
568
|
+
const pluginVersion = versionOf(baseline.name) ?? null;
|
|
569
|
+
const hostVersion = hostPackageVersion(hostRoot, baseline.name);
|
|
570
|
+
const satisfiesRange = (version) => {
|
|
571
|
+
if (version === null || baseline.peerRange === null)
|
|
572
|
+
return null;
|
|
573
|
+
try {
|
|
574
|
+
return semver.satisfies(version, baseline.peerRange);
|
|
575
|
+
}
|
|
576
|
+
catch {
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
const pluginInPeerRange = satisfiesRange(pluginVersion);
|
|
581
|
+
const hostInPeerRange = satisfiesRange(hostVersion);
|
|
582
|
+
const inPeerRange = pluginInPeerRange === false || hostInPeerRange === false
|
|
583
|
+
? false
|
|
584
|
+
: (pluginInPeerRange === true || hostInPeerRange === true ? true : null);
|
|
585
|
+
return {
|
|
586
|
+
name: baseline.name,
|
|
587
|
+
peerRange: baseline.peerRange,
|
|
588
|
+
baselineVersion: baseline.baselineVersion,
|
|
589
|
+
pluginVersion,
|
|
590
|
+
hostVersion,
|
|
591
|
+
sameModule: sameAsHost[baseline.name] ?? null,
|
|
592
|
+
inPeerRange,
|
|
593
|
+
versionDrift: (hostVersion !== null && hostVersion !== baseline.baselineVersion)
|
|
594
|
+
|| (pluginVersion !== null && pluginVersion !== baseline.baselineVersion),
|
|
595
|
+
...(baseline.optional === true ? { optional: true } : {}),
|
|
596
|
+
...(baseline.observed === true ? { observed: true } : {}),
|
|
597
|
+
};
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* 官方技能资产:技能页把宿主安装里的 office / sandbox 技能整目录物化到插件自家目录。
|
|
602
|
+
* 包还在、`assets/<技能>/SKILL.md` 的形态变了,技能页只会少几个来源(或来源为空),
|
|
603
|
+
* 而能力表全绿 —— 所以单独探测一次。
|
|
604
|
+
*
|
|
605
|
+
* 两个来源分开报:office 与 sandbox 是不同包、不同宿主形态(sandbox 只在 win32 注入),
|
|
606
|
+
* 合成一行会让「其中一个没了」看起来像「整个技能页坏了」。
|
|
607
|
+
*
|
|
608
|
+
* @param hostRoot - `.../node_modules/@deepseek-ai` 或 `null`。
|
|
609
|
+
*/
|
|
610
|
+
function inspectOfficialSkillAssets(hostRoot) {
|
|
611
|
+
if (hostRoot === null)
|
|
612
|
+
return [];
|
|
613
|
+
const requireFromHost = createRequire(join(dirname(hostRoot), 'package.json'));
|
|
614
|
+
const resolvePackage = (name) => {
|
|
615
|
+
try {
|
|
616
|
+
return packageRootOf(requireFromHost.resolve(name));
|
|
617
|
+
}
|
|
618
|
+
catch {
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
const out = [];
|
|
623
|
+
const officeRoot = resolvePackage('@deepseek-ai/dsh-skill-office');
|
|
624
|
+
if (officeRoot === null) {
|
|
625
|
+
out.push({
|
|
626
|
+
id: 'official-skill-assets', label: '官方 office 技能资产', kind: 'read',
|
|
627
|
+
owner: 'plugin', fallback: 'inform-only', state: 'not-available', missing: [], optional: true,
|
|
628
|
+
detail: '宿主未安装 office 技能资源包:技能页不会出现官方 office 技能(本部署形态,不是故障)',
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
const assets = join(officeRoot, 'assets');
|
|
633
|
+
let names = [];
|
|
634
|
+
try {
|
|
635
|
+
names = readdirSync(assets, { withFileTypes: true })
|
|
636
|
+
.filter((entry) => entry.isDirectory() && existsSync(join(assets, entry.name, 'SKILL.md')))
|
|
637
|
+
.map((entry) => entry.name);
|
|
638
|
+
}
|
|
639
|
+
catch {
|
|
640
|
+
names = [];
|
|
641
|
+
}
|
|
642
|
+
if (names.length === 0) {
|
|
643
|
+
out.push({
|
|
644
|
+
id: 'official-skill-assets', label: '官方 office 技能资产', kind: 'read',
|
|
645
|
+
owner: 'plugin', fallback: 'inform-only', state: 'shape-mismatch', missing: ['assets/*/SKILL.md'],
|
|
646
|
+
detail: 'office 技能包还在,但 assets 下找不到任何带 SKILL.md 的技能目录:技能页这一来源会是空的。',
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
out.push({
|
|
651
|
+
id: 'official-skill-assets', label: '官方 office 技能资产', kind: 'read',
|
|
652
|
+
owner: 'plugin', fallback: 'inform-only', state: 'ok', missing: [],
|
|
653
|
+
detail: `office 技能源在位(${names.length} 个技能目录)`,
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
const sandboxRoot = resolvePackage('@deepseek-ai/dsh-sandbox-windows-acl');
|
|
658
|
+
if (sandboxRoot === null) {
|
|
659
|
+
out.push({
|
|
660
|
+
id: 'official-sandbox-asset', label: '官方沙盒诊断技能资产', kind: 'read',
|
|
661
|
+
owner: 'plugin', fallback: 'inform-only', state: 'not-available', missing: [], optional: true,
|
|
662
|
+
detail: process.platform === 'win32'
|
|
663
|
+
? '宿主未安装 Windows ACL 沙盒包:技能页不会出现沙盒诊断技能(宿主可能使用其他沙盒后端)'
|
|
664
|
+
: '非 Windows 宿主不注入沙盒诊断技能(本部署形态,不是故障)',
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
else {
|
|
668
|
+
// 技能正文会指引模型执行这个脚本;只查 SKILL.md 会漏掉「文档在、脚本被裁掉」。
|
|
669
|
+
const assetDir = 'assets/diagnose-windows-sandbox-acl';
|
|
670
|
+
const required = ['SKILL.md', 'scripts/diagnose-windows-sandbox-acl.ps1'];
|
|
671
|
+
const missing = required
|
|
672
|
+
.filter((rel) => !existsSync(join(sandboxRoot, assetDir, rel)))
|
|
673
|
+
.map((rel) => `${assetDir}/${rel}`);
|
|
674
|
+
out.push(missing.length === 0
|
|
675
|
+
? {
|
|
676
|
+
id: 'official-sandbox-asset', label: '官方沙盒诊断技能资产', kind: 'read',
|
|
677
|
+
owner: 'plugin', fallback: 'inform-only', state: 'ok', missing: [],
|
|
678
|
+
detail: '沙盒诊断技能源在位(SKILL.md 与 PowerShell 脚本都可读)',
|
|
679
|
+
}
|
|
680
|
+
: {
|
|
681
|
+
id: 'official-sandbox-asset', label: '官方沙盒诊断技能资产', kind: 'read',
|
|
682
|
+
owner: 'plugin', fallback: 'inform-only', state: 'shape-mismatch', missing,
|
|
683
|
+
detail: `沙盒包还在,但 ${missing.join('、')} 不存在:技能页即使列出该技能也跑不起来。`,
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
return out;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* 供 CLI(doctor)复用同一份官方技能资产判定。
|
|
690
|
+
*
|
|
691
|
+
* @param hostRoot - `.../node_modules/@deepseek-ai` 或 `null`。
|
|
692
|
+
*/
|
|
693
|
+
export function inspectStaticSkillAssets(hostRoot) {
|
|
694
|
+
return inspectOfficialSkillAssets(hostRoot);
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* 官方包**导出的 schema 对象**上的字段名:canary 只能证明字符串还在,读一次 JSON 表示
|
|
698
|
+
* 才能确认插件写出的键仍被宿主接受。目前只有 MCP 客户端配置一份(插件写补丁的唯一出口)。
|
|
699
|
+
*
|
|
700
|
+
* 解析不到包 / 没有 `Config` 导出时不返回结论 —— 那是契约清单(`BARE_HOST_MODULE_CONTRACTS`)
|
|
701
|
+
* 的职责,不在这里重复报一次。
|
|
702
|
+
*
|
|
703
|
+
* @param hostRoot - `.../node_modules/@deepseek-ai` 或 `null`。
|
|
704
|
+
*/
|
|
705
|
+
function inspectHostSchemaContracts(hostRoot) {
|
|
706
|
+
if (hostRoot === null)
|
|
707
|
+
return [];
|
|
708
|
+
const finding = inspectMcpClientConfig(hostRoot);
|
|
709
|
+
return finding === null ? [] : [finding];
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* 供 CLI(doctor)复用同一份 schema 契约判定:页面在活宿主里跑 `assessHost`,没有活宿主时
|
|
713
|
+
* 只能由这里读宿主安装的导出对象。行为与页面完全同源。
|
|
714
|
+
*
|
|
715
|
+
* @param hostRoot - `.../node_modules/@deepseek-ai` 或 `null`。
|
|
716
|
+
*/
|
|
717
|
+
export function inspectStaticSchemaContracts(hostRoot) {
|
|
718
|
+
return inspectHostSchemaContracts(hostRoot);
|
|
719
|
+
}
|
|
720
|
+
/** 插件写 MCP 补丁时用到的全部配置键(`patch-yaml.ts` 的 buildInsertBlock)。 */
|
|
721
|
+
const MCP_CLIENT_CONFIG_KEYS = [
|
|
722
|
+
'transport', 'serverName', 'command', 'args', 'env', 'headers', 'url', 'toolCallTimeoutMs',
|
|
723
|
+
];
|
|
724
|
+
/**
|
|
725
|
+
* 从宿主安装锚点 require `dsh-mcp-client` 的 `Config`,收集 schema JSON 里所有对象字段名,
|
|
726
|
+
* 核对插件写出的键还在不在。
|
|
727
|
+
*
|
|
728
|
+
* 为什么读 `Config.toJSON()` 而不是拿样例跑一遍:schemastery 对未知键是"原样保留",
|
|
729
|
+
* 改名后的旧键会作为未知字段留在结果里 —— 样例校验会给出假绿;schema 的 `dict` 键表
|
|
730
|
+
* 才是权威字段名。
|
|
731
|
+
*/
|
|
732
|
+
function inspectMcpClientConfig(hostRoot) {
|
|
733
|
+
let mod;
|
|
734
|
+
try {
|
|
735
|
+
mod = createRequire(join(dirname(hostRoot), 'package.json'))('@deepseek-ai/dsh-mcp-client');
|
|
736
|
+
}
|
|
737
|
+
catch {
|
|
738
|
+
return null;
|
|
739
|
+
}
|
|
740
|
+
const Config = mod.Config;
|
|
741
|
+
if (Config === undefined || typeof Config.toJSON !== 'function')
|
|
742
|
+
return null;
|
|
743
|
+
let json;
|
|
744
|
+
try {
|
|
745
|
+
json = Config.toJSON();
|
|
746
|
+
}
|
|
747
|
+
catch (error) {
|
|
748
|
+
return {
|
|
749
|
+
id: 'mcp-client.config-schema',
|
|
750
|
+
label: 'MCP 客户端配置 schema',
|
|
751
|
+
kind: 'read',
|
|
752
|
+
owner: 'plugin',
|
|
753
|
+
fallback: 'inform-only',
|
|
754
|
+
state: 'not-available',
|
|
755
|
+
missing: [],
|
|
756
|
+
detail: `无法读取 dsh-mcp-client 的 Config.toJSON():${String(error?.message ?? error)}`,
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
const keys = new Set();
|
|
760
|
+
collectSchemaDictKeys(json, keys, new Set(), 0);
|
|
761
|
+
if (keys.size === 0) {
|
|
762
|
+
return {
|
|
763
|
+
id: 'mcp-client.config-schema',
|
|
764
|
+
label: 'MCP 客户端配置 schema',
|
|
765
|
+
kind: 'read',
|
|
766
|
+
owner: 'plugin',
|
|
767
|
+
fallback: 'inform-only',
|
|
768
|
+
state: 'not-available',
|
|
769
|
+
missing: [],
|
|
770
|
+
detail: '无法从 Config 的 JSON 表示里读出字段名:官方换了 schema 的表示方式,MCP 配置键需要人工复核',
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
const missing = MCP_CLIENT_CONFIG_KEYS.filter((key) => !keys.has(key));
|
|
774
|
+
if (missing.length > 0) {
|
|
775
|
+
return {
|
|
776
|
+
id: 'mcp-client.config-schema',
|
|
777
|
+
label: 'MCP 客户端配置 schema',
|
|
778
|
+
kind: 'read',
|
|
779
|
+
owner: 'plugin',
|
|
780
|
+
fallback: 'inform-only',
|
|
781
|
+
state: 'shape-mismatch',
|
|
782
|
+
missing,
|
|
783
|
+
detail: `官方 MCP 客户端 schema 里找不到配置键 ${missing.join('、')}:插件写出的补丁会被宿主忽略,MCP 页仍会显示「已配置」`,
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
return {
|
|
787
|
+
id: 'mcp-client.config-schema',
|
|
788
|
+
label: 'MCP 客户端配置 schema',
|
|
789
|
+
kind: 'read',
|
|
790
|
+
owner: 'plugin',
|
|
791
|
+
fallback: 'inform-only',
|
|
792
|
+
state: 'ok',
|
|
793
|
+
missing: [],
|
|
794
|
+
detail: `插件写出的 ${MCP_CLIENT_CONFIG_KEYS.length} 个配置键都在官方 schema 里`,
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
/** 递归收集 schema JSON 里 `dict` 的键(对象字段名);限深并防环。 */
|
|
798
|
+
function collectSchemaDictKeys(node, out, seen, depth) {
|
|
799
|
+
if (depth > 12 || node === null || typeof node !== 'object')
|
|
800
|
+
return;
|
|
801
|
+
if (seen.has(node))
|
|
802
|
+
return;
|
|
803
|
+
seen.add(node);
|
|
804
|
+
const record = node;
|
|
805
|
+
const dict = record.dict;
|
|
806
|
+
if (dict !== null && typeof dict === 'object') {
|
|
807
|
+
for (const key of Object.keys(dict))
|
|
808
|
+
out.add(key);
|
|
809
|
+
}
|
|
810
|
+
for (const value of Object.values(record))
|
|
811
|
+
collectSchemaDictKeys(value, out, seen, depth + 1);
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* 一组宿主契约的实况:插件依赖的官方包还暴不暴露、入口里那几条 canary 还在不在。
|
|
424
815
|
*
|
|
425
816
|
* 为什么在探测里量而不是只在 doctor 里量:doctor 是"没有活宿主"的静态视图,而兼容页看到的是
|
|
426
|
-
* 正在跑的宿主。升级 DSH 后第一眼该看见的正是这一块 ——
|
|
427
|
-
*
|
|
817
|
+
* 正在跑的宿主。升级 DSH 后第一眼该看见的正是这一块 —— 官方撤掉某个包 / 改掉一个事件名时
|
|
818
|
+
* **不抛错**,功能只是少一半,除此之外没有任何信号。
|
|
428
819
|
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
820
|
+
* 口径统一从宿主安装锚点解析(不是插件侧):这一块回答的是「宿主这一份现在怎样」,
|
|
821
|
+
* 而插件可能是另一份拷贝;宿主专属包从插件侧解析更只会得到一律"解析不到",那不是结论。
|
|
431
822
|
*
|
|
432
823
|
* @param hostRoot - `.../node_modules/@deepseek-ai` 或 `null`(找不到宿主)。
|
|
824
|
+
* @param contracts - 要检查的契约清单(裸模块 / 行为契约各一份)。
|
|
433
825
|
*/
|
|
434
|
-
function hostContractStatus(hostRoot) {
|
|
826
|
+
export function hostContractStatus(hostRoot, contracts) {
|
|
435
827
|
if (hostRoot === null)
|
|
436
828
|
return null;
|
|
437
|
-
const packages =
|
|
829
|
+
const packages = contracts.map((contract) => {
|
|
438
830
|
let resolved = null;
|
|
439
831
|
try {
|
|
440
832
|
resolved = createRequire(join(dirname(hostRoot), 'package.json')).resolve(contract.package);
|
|
@@ -443,14 +835,45 @@ function hostContractStatus(hostRoot) {
|
|
|
443
835
|
resolved = null;
|
|
444
836
|
}
|
|
445
837
|
let missingMarkers = [];
|
|
838
|
+
let missingMarkerNotes = [];
|
|
446
839
|
if (resolved !== null && contract.markers.length > 0) {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
840
|
+
const root = packageRootOf(resolved);
|
|
841
|
+
const cache = new Map();
|
|
842
|
+
const read = (file) => {
|
|
843
|
+
const key = file ?? '';
|
|
844
|
+
if (cache.has(key))
|
|
845
|
+
return cache.get(key) ?? null;
|
|
846
|
+
let source = null;
|
|
847
|
+
try {
|
|
848
|
+
const target = file === undefined ? resolved : (root === null ? null : join(root, ...file.split('/')));
|
|
849
|
+
source = target === null ? null : readFileSync(target, 'utf8');
|
|
850
|
+
}
|
|
851
|
+
catch {
|
|
852
|
+
source = null;
|
|
853
|
+
}
|
|
854
|
+
cache.set(key, source);
|
|
855
|
+
return source;
|
|
856
|
+
};
|
|
857
|
+
const missing = contract.markers.filter((marker) => {
|
|
858
|
+
const source = read(marker.file);
|
|
859
|
+
return source === null || !source.includes(marker.needle);
|
|
860
|
+
});
|
|
861
|
+
missingMarkers = missing.map((marker) => marker.needle);
|
|
862
|
+
missingMarkerNotes = missing.map((marker) => ({
|
|
863
|
+
needle: marker.needle,
|
|
864
|
+
why: marker.why,
|
|
865
|
+
...(marker.file === undefined ? {} : { file: marker.file }),
|
|
866
|
+
}));
|
|
452
867
|
}
|
|
453
|
-
return {
|
|
868
|
+
return {
|
|
869
|
+
package: contract.package,
|
|
870
|
+
feature: contract.feature,
|
|
871
|
+
...(contract.impact === undefined ? {} : { impact: contract.impact }),
|
|
872
|
+
...(contract.optional === true ? { optional: true } : {}),
|
|
873
|
+
resolved,
|
|
874
|
+
missingMarkers,
|
|
875
|
+
missingMarkerNotes,
|
|
876
|
+
};
|
|
454
877
|
});
|
|
455
878
|
return {
|
|
456
879
|
packages,
|
|
@@ -29,6 +29,17 @@ const DESKTOP_APP_DIR = '@deepseek-ai/dsh-desktop';
|
|
|
29
29
|
const AUTH_COOKIE_PREFIX = 'dsh-auth-';
|
|
30
30
|
/** 这条 cookie 只在 `http://127.0.0.1:<port>/` 上有效,别的主机名一律不碰。 */
|
|
31
31
|
const AUTH_COOKIE_HOST = '127.0.0.1';
|
|
32
|
+
/**
|
|
33
|
+
* 只清理**创建于这个时长之前**的条目。
|
|
34
|
+
*
|
|
35
|
+
* 为什么需要时间下限:本模块的初衷是"清掉历次启动留下的旧条目",但整类 DELETE 会连
|
|
36
|
+
* 当前这次启动刚换到的凭证一起删掉 —— 只要 apply 跑在桌面壳握手之后(热重载、同机第二个
|
|
37
|
+
* 宿主实例),用户当场就会重新撞上「Web authentication failed」。按创建时间切一刀之后,
|
|
38
|
+
* 本次的凭证永远在保留侧,堆积仍然会被清掉(一次启动最多留几条)。
|
|
39
|
+
*/
|
|
40
|
+
const MIN_AGE_MS = 10 * 60 * 1000;
|
|
41
|
+
/** Chromium 的 `cookies.creation_utc` 是「1601-01-01 起的微秒」。 */
|
|
42
|
+
const CHROME_EPOCH_OFFSET_US = 11_644_473_600_000_000;
|
|
32
43
|
/**
|
|
33
44
|
* 值得留一行日志的条数阈值。正常情况下每次启动罐里只有上一轮留下的 1 条,
|
|
34
45
|
* 明显多于这个数说明曾经堆积过 —— 那种情况写一行日志,便于下次复盘。
|
|
@@ -54,9 +65,10 @@ export function desktopCookieStorePath(platform = process.platform, env = proces
|
|
|
54
65
|
}
|
|
55
66
|
let done = false;
|
|
56
67
|
/**
|
|
57
|
-
*
|
|
68
|
+
* 清掉回环地址上**历次启动**留下的 `dsh-auth-*`(创建时间早于 `MIN_AGE_MS`)。
|
|
58
69
|
*
|
|
59
|
-
*
|
|
70
|
+
* 不整类清空:apply 也可能跑在握手之后(热重载、同机第二个宿主实例),那时这次启动
|
|
71
|
+
* 刚换到的凭证就在库里,删掉它等于当场把用户踢下线。按创建时间切一刀两头都照顾到。
|
|
60
72
|
* 进程内只跑一次:热重载再调也只返回空结果,避免反复去抢 Electron 正开着的库。
|
|
61
73
|
*
|
|
62
74
|
* @returns 本次调用的结果;`opened: false` 表示没有可清理的对象或环境不支持
|
|
@@ -75,7 +87,11 @@ export function pruneDesktopAuthCookies() {
|
|
|
75
87
|
if (typeof Ctor !== 'function')
|
|
76
88
|
return { opened: false, removed: 0 };
|
|
77
89
|
db = new Ctor(file);
|
|
78
|
-
|
|
90
|
+
// 时间下限见 MIN_AGE_MS:删的是"以前启动留下的",不是"这一次正在用的"。
|
|
91
|
+
// 表里没有 creation_utc(非 Chromium 库 / 结构又变了)时这条会抛,走下面的 catch
|
|
92
|
+
// —— 最坏结果是"本次不清",不会误删。
|
|
93
|
+
const createdBefore = (Date.now() - MIN_AGE_MS) * 1000 + CHROME_EPOCH_OFFSET_US;
|
|
94
|
+
const info = db.prepare('DELETE FROM cookies WHERE host_key = ? AND name LIKE ? AND creation_utc < ?').run(AUTH_COOKIE_HOST, `${AUTH_COOKIE_PREFIX}%`, createdBefore);
|
|
79
95
|
const removed = Number(info?.changes ?? 0);
|
|
80
96
|
if (removed > NOISY_COUNT) {
|
|
81
97
|
console.warn(`[dsh-plugin-tool-management] 清掉了 ${removed} 条桌面壳鉴权 cookie(宿主不清理,堆多了会导致启动握手被拒)。`);
|